mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-13 14:13:32 +02:00
Add support for zooming to show all notes, separate from max zoom
This is now the behavior of Zoom Reset, with Max Zoom being given the previous behavior. Shift+Right-Click alternates between the two -- it zooms to all notes, unless it currently is zoomed to all notes in which case it performs a max zoom. This fixes Bug 2093. It also fixes Bug 1815, by performing the all-notes zoom when importing a track.
This commit is contained in:
@@ -69,27 +69,8 @@ bool ImportMIDI(const FilePath &fName, NoteTrack * dest)
|
||||
wxString trackNameBase = fName.AfterLast(wxFILE_SEP_PATH).BeforeLast('.');
|
||||
dest->SetName(trackNameBase);
|
||||
mf.Close();
|
||||
// the mean pitch should be somewhere in the middle of the display
|
||||
Alg_iterator iterator( &dest->GetSeq(), false );
|
||||
iterator.begin();
|
||||
// for every event
|
||||
Alg_event_ptr evt;
|
||||
int note_count = 0;
|
||||
int pitch_sum = 0;
|
||||
while (NULL != (evt = iterator.next())) {
|
||||
// if the event is a note
|
||||
if (evt->get_type() == 'n') {
|
||||
Alg_note_ptr note = (Alg_note_ptr) evt;
|
||||
pitch_sum += (int) note->pitch;
|
||||
note_count++;
|
||||
}
|
||||
}
|
||||
int mean_pitch = (note_count > 0 ? pitch_sum / note_count : 60);
|
||||
// initial track is about 27 half-steps high; if bottom note is C,
|
||||
// then middle pitch class is D. Round mean_pitch to the nearest D:
|
||||
int mid_pitch = ((mean_pitch - 2 + 6) / 12) * 12 + 2;
|
||||
dest->SetBottomNote(mid_pitch - 14);
|
||||
dest->SetTopNote(mid_pitch + 13);
|
||||
|
||||
dest->ZoomAllNotes();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user