Audacity 3.2.0
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
NoteTrackRange Class Referencefinal

Persistent data for display of a note track. More...

#include <NoteTrackDisplayData.h>

Inheritance diagram for NoteTrackRange:
[legend]
Collaboration diagram for NoteTrackRange:
[legend]

Public Types

enum  { MinPitch = 0 , MaxPitch = 127 }
 

Public Member Functions

 ~NoteTrackRange () override
 
std::unique_ptr< NoteTrackAttachmentClone () const override
 
void WriteXML (XMLWriter &xmlFile) const override
 Default implementation does nothing. More...
 
bool HandleAttribute (const Attribute &attribute) override
 Return whether the attribute was used; default returns false. More...
 
int GetBottomNote () const
 Gets the current bottom note (a pitch) More...
 
int GetTopNote () const
 Gets the current top note (a pitch) More...
 
void SetBottomNote (int note)
 Sets the bottom note (a pitch), making sure that it is never greater than the top note. More...
 
void SetTopNote (int note)
 Sets the top note (a pitch), making sure that it is never less than the bottom note. More...
 
void SetNoteRange (int note1, int note2)
 Sets the top and bottom note (both pitches) automatically, swapping them if needed. More...
 
void ShiftNoteRange (int offset)
 Shifts all notes vertically by the given pitch. More...
 
void ZoomAllNotes (Alg_seq *pSeq)
 Zooms so that all notes are visible. More...
 
void ZoomMaxExtent ()
 Zooms so that the entire track is visible. More...
 
- Public Member Functions inherited from NoteTrackAttachment
 ~NoteTrackAttachment () override
 
virtual void WriteXML (XMLWriter &xmlFile) const
 Default implementation does nothing. More...
 
virtual bool HandleAttribute (const Attribute &attribute)
 Return whether the attribute was used; default returns false. More...
 

Static Public Member Functions

static NoteTrackRangeGet (const NoteTrack &track)
 Allow mutative access to attached data of a const track. More...
 

Private Attributes

int mBottomNote { MinPitch }
 
int mTopNote { MaxPitch }
 

Detailed Description

Persistent data for display of a note track.

Definition at line 22 of file NoteTrackDisplayData.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
MinPitch 
MaxPitch 

Definition at line 34 of file NoteTrackDisplayData.h.

Constructor & Destructor Documentation

◆ ~NoteTrackRange()

NoteTrackRange::~NoteTrackRange ( )
overridedefault

Member Function Documentation

◆ Clone()

std::unique_ptr< NoteTrackAttachment > NoteTrackRange::Clone ( ) const
override

Definition at line 29 of file NoteTrackDisplayData.cpp.

30{
31 return std::make_unique<NoteTrackRange>(*this);
32}

◆ Get()

NoteTrackRange & NoteTrackRange::Get ( const NoteTrack track)
static

Allow mutative access to attached data of a const track.

Definition at line 20 of file NoteTrackDisplayData.cpp.

21{
22 auto &mutTrack = const_cast<NoteTrack&>(track);
23 return static_cast<NoteTrackRange&>(
24 mutTrack.NoteTrackAttachments::Get(key));
25}
static NoteTrackAttachments::RegisteredFactory key
A Track that is used for Midi notes. (Somewhat old code).
Definition: NoteTrack.h:86
Persistent data for display of a note track.

References key.

Referenced by NoteTrackVRulerControls::HandleWheelRotation(), anonymous_namespace{ImportMIDI.cpp}::ImportMIDI(), NoteTrackDisplayData::NoteTrackDisplayData(), NoteTrackMenuTable::OnChangeOctave(), NoteTrackVRulerMenuTable::OnZoom(), NoteTrackVZoomHandle::Release(), NoteTrackDisplayData::Zoom(), and NoteTrackDisplayData::ZoomTo().

Here is the caller graph for this function:

◆ GetBottomNote()

int NoteTrackRange::GetBottomNote ( ) const
inline

Gets the current bottom note (a pitch)

Definition at line 37 of file NoteTrackDisplayData.h.

37{ return mBottomNote; }

◆ GetTopNote()

int NoteTrackRange::GetTopNote ( ) const
inline

Gets the current top note (a pitch)

Definition at line 39 of file NoteTrackDisplayData.h.

39{ return mTopNote; }

◆ HandleAttribute()

bool NoteTrackRange::HandleAttribute ( const Attribute attribute)
overridevirtual

Return whether the attribute was used; default returns false.

Reimplemented from NoteTrackAttachment.

Definition at line 40 of file NoteTrackDisplayData.cpp.

41{
42 auto attr = pair.first;
43 auto value = pair.second;
44 long nValue{};
45 if (attr == "bottomnote" && value.TryGet(nValue)) {
46 SetBottomNote(nValue);
47 return true;
48 }
49 if (attr == "topnote" && value.TryGet(nValue)) {
50 SetTopNote(nValue);
51 return true;
52 }
53 return false;
54}
void SetBottomNote(int note)
Sets the bottom note (a pitch), making sure that it is never greater than the top note.
void SetTopNote(int note)
Sets the top note (a pitch), making sure that it is never less than the bottom note.

References SetBottomNote(), and SetTopNote().

Here is the call graph for this function:

◆ SetBottomNote()

void NoteTrackRange::SetBottomNote ( int  note)

Sets the bottom note (a pitch), making sure that it is never greater than the top note.

Definition at line 56 of file NoteTrackDisplayData.cpp.

57{
58 if (note < MinPitch)
59 note = MinPitch;
60 else if (note > 96)
61 note = 96;
62
63 wxCHECK(note <= mTopNote, );
64
65 mBottomNote = note;
66}

References mBottomNote, MinPitch, and mTopNote.

Referenced by HandleAttribute().

Here is the caller graph for this function:

◆ SetNoteRange()

void NoteTrackRange::SetNoteRange ( int  note1,
int  note2 
)

Sets the top and bottom note (both pitches) automatically, swapping them if needed.

Definition at line 78 of file NoteTrackDisplayData.cpp.

79{
80 // Bounds check
81 if (note1 > MaxPitch)
82 note1 = MaxPitch;
83 else if (note1 < MinPitch)
84 note1 = MinPitch;
85 if (note2 > MaxPitch)
86 note2 = MaxPitch;
87 else if (note2 < MinPitch)
88 note2 = MinPitch;
89 // Swap to ensure ordering
90 if (note2 < note1) { std::swap(note1, note2); }
91
92 mBottomNote = note1;
93 mTopNote = note2;
94}
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:645

References MaxPitch, mBottomNote, MinPitch, mTopNote, and anonymous_namespace{NoteTrack.cpp}::swap().

Referenced by ZoomAllNotes(), and NoteTrackDisplayData::ZoomTo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetTopNote()

void NoteTrackRange::SetTopNote ( int  note)

Sets the top note (a pitch), making sure that it is never less than the bottom note.

Definition at line 68 of file NoteTrackDisplayData.cpp.

69{
70 if (note > MaxPitch)
71 note = MaxPitch;
72
73 wxCHECK(note >= mBottomNote, );
74
75 mTopNote = note;
76}

References MaxPitch, mBottomNote, and mTopNote.

Referenced by HandleAttribute().

Here is the caller graph for this function:

◆ ShiftNoteRange()

void NoteTrackRange::ShiftNoteRange ( int  offset)

Shifts all notes vertically by the given pitch.

Definition at line 96 of file NoteTrackDisplayData.cpp.

97{
98 // Ensure everything stays in bounds
99 if (mBottomNote + offset < MinPitch || mTopNote + offset > MaxPitch)
100 return;
101
102 mBottomNote += offset;
103 mTopNote += offset;
104}

References MaxPitch, mBottomNote, and mTopNote.

Referenced by NoteTrackVRulerControls::HandleWheelRotation(), and NoteTrackMenuTable::OnChangeOctave().

Here is the caller graph for this function:

◆ WriteXML()

void NoteTrackRange::WriteXML ( XMLWriter xmlFile) const
overridevirtual

Default implementation does nothing.

Reimplemented from NoteTrackAttachment.

Definition at line 34 of file NoteTrackDisplayData.cpp.

35{
36 xmlFile.WriteAttr(wxT("bottomnote"), mBottomNote);
37 xmlFile.WriteAttr(wxT("topnote"), mTopNote);
38}
wxT("CloseDown"))
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:36

References mBottomNote, mTopNote, XMLWriter::WriteAttr(), and wxT().

Here is the call graph for this function:

◆ ZoomAllNotes()

void NoteTrackRange::ZoomAllNotes ( Alg_seq *  pSeq)

Zooms so that all notes are visible.

Definition at line 120 of file NoteTrackDisplayData.cpp.

121{
122 Alg_iterator iterator(pSeq, false);
123 iterator.begin();
124 Alg_event_ptr evt;
125
126 // Go through all of the notes, finding the minimum and maximum value pitches.
127 bool hasNotes = false;
128 int minPitch = MaxPitch;
129 int maxPitch = MinPitch;
130
131 while (nullptr != (evt = iterator.next())) {
132 if (evt->is_note()) {
133 int pitch = (int) evt->get_pitch();
134 hasNotes = true;
135 if (pitch < minPitch)
136 minPitch = pitch;
137 if (pitch > maxPitch)
138 maxPitch = pitch;
139 }
140 }
141
142 if (!hasNotes) {
143 // Semi-arbitrary default values:
144 minPitch = 48;
145 maxPitch = 72;
146 }
147
148 SetNoteRange(minPitch, maxPitch);
149}
void SetNoteRange(int note1, int note2)
Sets the top and bottom note (both pitches) automatically, swapping them if needed.

References MaxPitch, MinPitch, and SetNoteRange().

Referenced by anonymous_namespace{ImportMIDI.cpp}::ImportMIDI().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ZoomMaxExtent()

void NoteTrackRange::ZoomMaxExtent ( )
inline

Zooms so that the entire track is visible.

Definition at line 54 of file NoteTrackDisplayData.h.

Member Data Documentation

◆ mBottomNote

int NoteTrackRange::mBottomNote { MinPitch }
private

◆ mTopNote

int NoteTrackRange::mTopNote { MaxPitch }
private

The documentation for this class was generated from the following files: