17 [](
NoteTrack&){
return std::make_unique<NoteTrackRange>(); }
22 auto &mutTrack =
const_cast<NoteTrack&
>(track);
24 mutTrack.NoteTrackAttachments::Get(
key));
31 return std::make_unique<NoteTrackRange>(*
this);
42 auto attr = pair.first;
43 auto value = pair.second;
45 if (attr ==
"bottomnote" && value.TryGet(nValue)) {
49 if (attr ==
"topnote" && value.TryGet(nValue)) {
90 if (note2 < note1) {
std::swap(note1, note2); }
107void NoteTrackRange::StartVScroll()
112void NoteTrackRange::VScroll(
int start,
int end)
114 int ph = GetPitchHeight();
115 int delta = ((
end - start) + ph / 2) / ph;
122 Alg_iterator iterator(pSeq,
false);
127 bool hasNotes =
false;
131 while (
nullptr != (evt = iterator.next())) {
132 if (evt->is_note()) {
133 int pitch = (int) evt->get_pitch();
135 if (pitch < minPitch)
137 if (pitch > maxPitch)
152 const NoteTrack &track,
const wxRect &rect)
157 auto span = data.GetTopNote() - data.GetBottomNote() + 1;
159 mMargin =
std::min((
int) (rect.height / (
float)(span)) / 2, rect.height / 4);
162 int numC = 0, numF = 0;
163 auto botOctave = data.GetBottomNote() / 12, botNote = data.GetBottomNote() % 12;
164 auto topOctave = data.GetTopNote() / 12, topNote = data.GetTopNote() % 12;
165 if (topOctave == botOctave)
167 if (botNote == 0) numC = 1;
168 if (topNote <= 5) numF = 1;
172 numC = topOctave - botOctave;
173 numF = topOctave - botOctave - 1;
174 if (botNote == 0) numC++;
175 if (botNote <= 5) numF++;
176 if (topOctave <= 5) numF++;
179 auto effectiveHeight = rect.height - (2 * (
mMargin + 1)) - numC - numF;
212 int extent = data.GetTopNote() - data.GetBottomNote() + 1;
213 int newExtent = (int) (extent / multiplier);
220 position = extent / (clickedPitch - data.GetBottomNote());
222 int newBottomNote = clickedPitch - (newExtent * position);
223 int newTopNote = clickedPitch + (newExtent * (1 - position));
224 data.SetNoteRange(newBottomNote, newTopNote);
229 wxRect trackRect(0,
mRect.GetY(), 1,
mRect.GetHeight());
232 if (pitch1 == pitch2) {
234 Zoom(start, 1,
true);
static NoteTrackAttachments::RegisteredFactory key
std::pair< std::string_view, XMLAttributeValueView > Attribute
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
int GetPitchHeight(int factor) const
int GetNotePos(int p) const
void Zoom(int y, float multiplier, bool center)
NoteTrackDisplayData(const NoteTrack &track, const wxRect &r)
int GetOctaveHeight() const
static const float ZoomStep
int GetNoteMargin() const
void ZoomTo(int start, int end)
int YToIPitch(int y) const
int IPitchToY(int p) const
A Track that is used for Midi notes. (Somewhat old code).
Persistent data for display of a note track.
void WriteXML(XMLWriter &xmlFile) const override
Default implementation does nothing.
std::unique_ptr< NoteTrackAttachment > Clone() const override
static NoteTrackRange & Get(const NoteTrack &track)
Allow mutative access to attached data of a const track.
void ZoomAllNotes(Alg_seq *pSeq)
Zooms so that all notes are visible.
void SetBottomNote(int note)
Sets the bottom note (a pitch), making sure that it is never greater than the top note.
void ShiftNoteRange(int offset)
Shifts all notes vertically by the given pitch.
void SetNoteRange(int note1, int note2)
Sets the top and bottom note (both pitches) automatically, swapping them if needed.
~NoteTrackRange() override
void SetTopNote(int note)
Sets the top note (a pitch), making sure that it is never less than the bottom note.
bool HandleAttribute(const Attribute &attribute) override
Return whether the attribute was used; default returns false.
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
void WriteAttr(const wxString &name, const Identifier &value)
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
const char * end(const char *str) noexcept