ZG  "1.00
 All Classes Namespaces Files Functions Variables Enumerator Friends Macros Pages
MusicSheetWidget.h
Go to the documentation of this file.
1 #ifndef MusicSheetWidget_h
2 #define MusicSheetWidget_h
3 
4 #include <QPixmap>
5 #include <QWidget>
6 #include <QTimer>
7 
9 #include "MusicSheet.h"
10 #include "PlaybackState.h"
11 
12 namespace choir {
13 
15 class MusicSheetWidget : public QWidget
16 {
17 Q_OBJECT
18 
19 public:
21  MusicSheetWidget(const INetworkTimeProvider * networkTimeProvider, QWidget * parent = NULL);
22 
25 
27  void SetMusicSheet(const ConstMusicSheetRef & musicSheetRef);
28 
30  virtual void paintEvent(QPaintEvent *);
31 
33  virtual void mousePressEvent(QMouseEvent *);
34 
36  virtual void mouseMoveEvent(QMouseEvent *);
37 
39  virtual void mouseReleaseEvent(QMouseEvent *);
40 
42  virtual void leaveEvent(QEvent *);
43 
45  void SetPlaybackState(const PlaybackState & newPlaybackState);
46 
50  int GetSongWidthPixels() const;
51 
53  int GetHorizontalScrollOffset() const {return _scrollOffsetX;}
54 
56  void FullyAttached();
57 
62  void SetNoteAssignments(uint64 localNotes, uint64 allAssignedNotes);
63 
67  void MoveSeekPosition(int delta);
68 
70  uint32 GetSeekPointChordIndex() const {return GetChordIndexForX(GetSeekPointX());}
71 
72 signals:
77  void NotePositionClicked(uint32 chordIdx, int note);
78 
82  void SeekRequested(uint32 chordIdx);
83 
85  void SongWidthChanged();
86 
90  void AutoScrollMusicSheetWidget(int pixelsToTheRight);
91 
92 public slots:
96  void SetHorizontalScrollOffset(int offsetPixels);
97 
98 private slots:
99  void UpdateWhilePlaying();
100 
101 private:
102  int GetStemDirectionForNoteIndex(uint32 noteIdx) const {return (noteIdx<=CHOIR_NOTE_B4)?STEM_DIRECTION_DOWN:STEM_DIRECTION_UP;}
103  int GetStemDirectionForChord(uint64 chordVal) const;
104 
105  int GetYForNote(uint32 noteIdx) const;
106  uint32 GetNoteForY(int y) const;
107 
108  int GetXForChordIndex(uint32 chordIdx, bool useLoopingLogic) const;
109  uint32 GetChordIndexForX(int x) const;
110 
111  int GetXForMicrosecondsOffset(int64 microsecondsOffset) const;
112 
113  int DrawChord(QPainter & p, uint32 chordIdx, uint64 chordVal, bool chooseNoteColor, int stemDirection, qreal optForceOpacity = -1.0) const;
114  int DrawNote(QPainter & p, uint32 chordIdx, uint32 noteIdx, bool chooseNoteColor, int stemDirection, qreal optForceOpacity = -1.0) const;
115  void DrawNoteLine(QPainter & p, uint32 chordIdx, uint32 noteIdx, qreal optForceOpacity = -1.0) const;
116  void DrawNoteLines(QPainter & p, uint32 chordIdx, uint32 firstNoteIdx, uint32 afterLastNoteIdx, qreal optForceOpacity = -1.0) const;
117  int GetSeekPointX() const;
118  void EnsureXIsVisible(int x);
119 
120  const QPixmap & GetPixmapForNote(uint32 noteIdx, int stemDirection, bool chooseColor, qreal & retOpacity) const;
121 
122  const INetworkTimeProvider * _networkTimeProvider;
123 
124  ConstMusicSheetRef _musicSheet;
125  PlaybackState _playbackState;
126 
127  QTimer _animationTimer;
128 
129  enum {
130  STEM_DIRECTION_UP = 0,
131  STEM_DIRECTION_DOWN,
132  NUM_STEM_DIRECTIONS
133  };
134 
135  enum {
136  NOTE_TYPE_REGULAR = 0,
137  NOTE_TYPE_LOCAL,
138  NOTE_TYPE_ORPHAN,
139  NUM_NOTE_TYPES
140  };
141 
142  QPixmap _notePixmaps[NUM_NOTE_TYPES][NUM_STEM_DIRECTIONS];
143 
144  uint32 _ghostChordIndex;
145  uint32 _ghostNoteIndex;
146 
147  int _scrollOffsetX;
148 
149  bool _isFullyAttached;
150 
151  uint64 _localNotes; // bit-chord of notes that we will be playing locally
152  uint64 _allAssignedNotes; // bit-chord of notes that somebody will be playing
153 
154  uint32 _seekDraggingIndex; // MUSCLE_NO_LIMIT when not dragging on the seek-bar
155 
156  uint64 _notesBelowStaff; // bit-chord of notes in the white area below the horizontal lines
157  uint64 _notesAboveStaff; // bit-chord of notes in the white area above the horizontal lines
158 };
159 
160 }; // end namespace choir
161 
162 #endif
This is an abstract interface for an object that can provide us with network-clock-time values...
MusicSheetWidget(const INetworkTimeProvider *networkTimeProvider, QWidget *parent=NULL)
Constructor.
void FullyAttached()
Should be called when we've become fully attached to the ZG system.
~MusicSheetWidget()
Destructor.
This object holds the state of how the currently-in-memory Music sheet should be performed over time...
Definition: PlaybackState.h:9
virtual void mouseMoveEvent(QMouseEvent *)
Called whenever the user moves the mouse across this MusicSheetWidget.
int GetHorizontalScrollOffset() const
Returns the number of pixels from the left edge of the song that we have scrolled.
virtual void leaveEvent(QEvent *)
Called whenever the mouse pointer leaves the region of the screen occupied by this MusicSheetWidget...
void AutoScrollMusicSheetWidget(int pixelsToTheRight)
Emitted when it's time to scroll them music sheet by a relative amount.
This widget displays a page of our MusicSheet.
void SeekRequested(uint32 chordIdx)
Emitted when the user clicks on the seek-row at the top of the music sheet.
void SetNoteAssignments(uint64 localNotes, uint64 allAssignedNotes)
Sets the bit-chord of notes that we are meant to play, and the bit-chord of all notes in the song...
uint32 GetSeekPointChordIndex() const
Returns the chord-index that the play-position-indicator (i.e.
void SetPlaybackState(const PlaybackState &newPlaybackState)
Sets the PlaybackState that we should use to animate the red bar.
void SetHorizontalScrollOffset(int offsetPixels)
Sets the horizontal-scroll-offset of this widget.
The choir namespace contains the code specific to the ZGChoir demonstration application.
Definition: ChoirNameSpace.h:7
int GetSongWidthPixels() const
Returns the total number of pixels our song should take up horizontally on screen (including a bit of...
virtual void mousePressEvent(QMouseEvent *)
Called whenever the user presses a mouse button down while the mouse is over this MusicSheetWidget...
void MoveSeekPosition(int delta)
Called when we want to move the play-position-indicator (vertical red bar) left or right...
void SongWidthChanged()
Emitted whenever the length of the song (in notes) may have changed.
virtual void paintEvent(QPaintEvent *)
Called whenever it's time to redraw this MusicSheetWidget.
void SetMusicSheet(const ConstMusicSheetRef &musicSheetRef)
Sets the MusicSheet object that we should consult to find out where to draw notes at...
void NotePositionClicked(uint32 chordIdx, int note)
Emitted when the user clicks on a note-position in the music sheet.
virtual void mouseReleaseEvent(QMouseEvent *)
Called whenever the user releases a mouse button while the mouse is over this MusicSheetWidget.