1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-13 14:13:32 +02:00

Extensive changes to improve NoteTrack display and (some) editing, NoteTrack playback via MIDI, and Midi-to-Audio alignment.

This commit is contained in:
rbdannenberg
2010-09-18 21:02:36 +00:00
parent f6327602e8
commit a1f0e5ed5b
96 changed files with 5679 additions and 3566 deletions

View File

@@ -17,14 +17,14 @@
#if defined(USE_MIDI)
//#include "allegro.h"
//#include "strparse.h"
//#include "mfmidi.h"
#include "../Internat.h"
#include "../NoteTrack.h"
#include "ImportMIDI.h"
#include "allegro.h"
#include "strparse.h"
#include "mfmidi.h"
bool ImportMIDI(wxString fName, NoteTrack * dest)
{
if (fName.Length() <= 4){
@@ -46,7 +46,8 @@ bool ImportMIDI(wxString fName, NoteTrack * dest)
return false;
}
Alg_seq_ptr new_seq = new Alg_seq(fName.mb_str(), is_midi);
double offset = 0.0;
Alg_seq_ptr new_seq = new Alg_seq(fName.mb_str(), is_midi, &offset);
//Should we also check if(seq->tracks() == 0) ?
if(new_seq->get_read_error() == alg_error_open){
@@ -56,7 +57,30 @@ bool ImportMIDI(wxString fName, NoteTrack * dest)
}
dest->SetSequence(new_seq);
dest->SetOffset(offset);
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(new_seq, false);
iterator.begin();
// for every event
Alg_event_ptr evt;
int note_count = 0;
int pitch_sum = 0;
while (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);
return true;
}