ZG  "1.00
 All Classes Namespaces Files Functions Variables Enumerator Friends Macros Pages
ChoirWindow.h
Go to the documentation of this file.
1 #ifndef ChoirWindow_h
2 #define ChoirWindow_h
3 
4 #include <QMainWindow>
5 #include <QThread>
6 
7 #include "qtsupport/QMessageTransceiverThread.h"
8 
9 #include "ChoirNameSpace.h"
10 #include "ChoirProtocol.h"
11 #include "ChoirThread.h"
12 
13 #include "MusicData.h"
14 #include "MusicSheetPlayer.h"
15 #include "NoteAssignmentsMap.h"
16 #include "Quasimodo.h"
17 
18 class QBoxLayout;
19 class QComboBox;
20 class QLabel;
21 class QScrollBar;
22 class QSlider;
23 class QToolButton;
24 
25 namespace choir {
26 
27 class MusicSheetWidget;
28 class RosterWidget;
29 
31 class ChoirWindow : public QMainWindow
32 {
33 Q_OBJECT
34 
35 public:
37  ChoirWindow();
38 
40  virtual ~ChoirWindow();
41 
43  virtual void resizeEvent(QResizeEvent *);
44 
46  virtual void keyPressEvent(QKeyEvent *);
47 
48 signals:
50  void SetupTheBells();
51 
57  void RequestBells(quint64 bellChord, bool localNotesOnly);
58 
62  void LocalNoteAssignmentsChanged(quint64 localNotesChord);
63 
65  void DestroyTheBells();
66 
68  void SetupTimer();
69 
73  void SendMusicSheetToPlayer(const choir::ConstMusicSheetRef & newMusicSheet);
74 
78  void SendPlaybackStateToPlayer(const choir::PlaybackState & newPlaybackState);
79 
81  void DestroyTimer();
82 
83 private slots:
84  void MessageReceivedFromServer(const MessageRef & msg, const String & sessionID);
85  void UpdateButtons();
86  void NotePositionClicked(uint32 chordIdx, int noteIdx);
87  void SeekRequested(uint32 chordIdx);
88  void PlayButtonClicked() {SendTransportCommand(CHOIR_COMMAND_PLAY, NULL);}
89  void PauseButtonClicked() {SendTransportCommand(CHOIR_COMMAND_PAUSE, NULL);}
90  void StopButtonClicked() {const uint32 topIdx = 0; SendTransportCommand(CHOIR_COMMAND_PAUSE, &topIdx);}
91  void LoopButtonClicked();
92  void LoopMenuItemSelected();
93  void SendUpdatedMusicSheetToPlayer();
94  void SendUpdatedPlaybackStateToPlayer();
95  void ClearSong();
96  void OpenSong();
97  void SaveSong();
98  void CloneWindow();
99  void UpdateHorizontalScrollBarSettings();
100  void UpdateVerticalScrollBarSettings();
101  void UserBeganDraggingTempoSlider();
102  void TempoChangeRequested(int sliderVal);
103  void UserStoppedDraggingTempoSlider();
104  void UpdateTempoValueLabel();
105  void UpdateTempoSliderFromPlaybackState();
106  void RosterBellPositionClicked(const zg::ZGPeerID & peerID, uint32 noteIdx);
107  void RosterWheelTurned(int deltaY);
108  void UserRequestedStrategyChange(int newStrategy);
109  void AutoScrollMusicSheetWidget(int pixelsToTheRight);
110  void DeleteChord();
111  void InsertChord();
112  void SetAutomaticBellAssignment() {UserRequestedStrategyChange(ASSIGNMENT_STRATEGY_AUTOMATIC);}
113  void SetAssistedBellAssignment() {UserRequestedStrategyChange(ASSIGNMENT_STRATEGY_ASSISTED);}
114  void SetManualBellAssignment() {UserRequestedStrategyChange(ASSIGNMENT_STRATEGY_MANUAL);}
115 
116 private:
117  QToolButton * CreateButton(const QString & resourcePath, const char * slotName, bool isToggleButton, QBoxLayout * layout);
118  status_t UploadMusicSheet(const MusicSheet & musicSheet);
119  void SendTransportCommand(uint32 what, const uint32 * optSeekToChordIdx);
120  void MusicSheetUpdated();
121  void NoteAssignmentsUpdated();
122  QString GetLocalPeerNickname() const;
123  const ZGPeerID & GetLocalPeerID() const;
124  QString GetStrategyName(uint32 whichStrategy) const;
125  QAction * CreateMenuItem(QMenu * menu, const QString & label, QObject * target, const char * slotName, const QString & optShortcut = QString::null, bool isCheckable = false);
126 
127  void ScheduleSendUpdatedMusicSheetToPlayer();
128  void ScheduleSendUpdatedPlaybackStateToPlayer();
129 
130  ChoirThread _serverThread;
131 
132  MusicSheet _musicSheet;
133  MusicSheetWidget * _musicSheetWidget;
134  QScrollBar * _horizontalScrollBar;
135 
136  NoteAssignmentsMap _assigns;
137  RosterWidget * _rosterWidget;
138  QScrollBar * _verticalScrollBar;
139  QWidget * _padRightWidget;
140 
141  QToolButton * _clearButton;
142 
143  QToolButton * _openButton;
144  QToolButton * _saveButton;
145 
146  QToolButton * _deleteButton;
147  QToolButton * _insertButton;
148 
149  QToolButton * _playButton;
150  QToolButton * _pauseButton;
151  QToolButton * _stopButton;
152 
153  QToolButton * _loopButton;
154 
155  QAction * _openMenuItem;
156  QAction * _saveMenuItem;
157  QAction * _clearMenuItem;
158  QAction * _deleteMenuItem;
159  QAction * _insertMenuItem;
160  QAction * _playMenuItem;
161  QAction * _pauseMenuItem;
162  QAction * _stopMenuItem;
163  QAction * _loopMenuItem;
164  QAction * _automaticMenuItem;
165  QAction * _assistedMenuItem;
166  QAction * _manualMenuItem;
167  QAction * _cloneMenuItem;
168 
169  QComboBox * _strategyComboBox;
170 
171  QSlider * _tempoSlider;
172  bool _userIsDraggingTempoSlider;
173  QLabel * _tempoValueLabel;
174 
175  QToolButton * _cloneWindowButton;
176 
177  PlaybackState _playbackState;
178 
179  QThread _quasimodoThread;
180  Quasimodo _quasimodo;
181 
182  QThread _musicPlayerThread;
183  MusicSheetPlayer _musicPlayer;
184 
185  bool _sendPlaybackStateToPlayerPending;
186  bool _sendMusicSheetToPlayerPending;
187 };
188 
189 }; // end namespace choir
190 
191 #endif
This object is in charge of actually ringing the local bells (using QAudioOutput and a mixer algorith...
Definition: Quasimodo.h:16
virtual void resizeEvent(QResizeEvent *)
Called when the ZGChoir window is resized.
This object holds the state of how the currently-in-memory Music sheet should be performed over time...
Definition: PlaybackState.h:9
void SendPlaybackStateToPlayer(const choir::PlaybackState &newPlaybackState)
This signal is emitted when our PlaybackState changes, in order to send the new PlaybackState to the ...
void SetupTheBells()
This signal is emitted at startup to tell the Quasimodo thread to do his setup (start timers...
void LocalNoteAssignmentsChanged(quint64 localNotesChord)
This signal is emitted when the set of bells assigned to us changed, to let Quasimodo know which bell...
void DestroyTheBells()
This signal is emitted at shutdown to tell the Quasimodo thread to free his resources in preparation ...
This class contains the MUSCLE network I/O thread that has our ChoirSession inside it...
Definition: ChoirThread.h:11
This widget displays a page of our MusicSheet.
virtual void keyPressEvent(QKeyEvent *)
Called when the user presses a key while the ZGChoir has the focus.
A ZGPeerID is a 128-bit integer that uniquely represents a particular peer in a ZG system...
Definition: ZGPeerID.h:18
void RequestBells(quint64 bellChord, bool localNotesOnly)
This signal is emitted at startup to tell the Quasimodo thread to ring some bells now...
virtual ~ChoirWindow()
Destructor.
ChoirWindow()
Default constructor.
The choir namespace contains the code specific to the ZGChoir demonstration application.
Definition: ChoirNameSpace.h:7
void DestroyTimer()
This signal is emitted at shutdown to tell the music-player thread to free his resources in preparati...
void SendMusicSheetToPlayer(const choir::ConstMusicSheetRef &newMusicSheet)
This signal is emitted when our MusicSheet changes, in order to send the new MusicSheet to the music-...
void SetupTimer()
This signal is emitted at startup to tell the music-sheet-player thread to do his setup...
This object is in charge of reading the music sheet and telling Quasimodo when to ring the bells...
This object is the in-memory representation of a song, as a collection of notes over time...
Definition: MusicSheet.h:9
This widget displays the current table of note assignments, as contained in our NoteAssignmentsMap.
Definition: RosterWidget.h:15
This object specifies which peers should be playing which notes.
This is the main window of the ZGChoir application.
Definition: ChoirWindow.h:31