Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/AHHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ void AHHost::LoadMidiFile(const std::string midiFile)
midiPlayer_.LoadMidiFile(midiFile);
}

void AHHost::CreateOneNote(int noteNumber, float duration, int velocity)
{
midiPlayer_.CreateOneNote(noteNumber, duration, velocity);
}

// Most was copy-pasted from PlaySequence example
void AHHost::Play()
{
Expand Down Expand Up @@ -335,15 +340,11 @@ vector< list< vector<float> > > AHHost::RenderToBuffer()//CAStreamBasicDescripti
{
vector<float> data_temp(bufferSize_);
AudioBuffer ab = abl->mBuffers[i];

// TODO : if my understanding is correct, since we assume that we are using the genericOutput, we also assume that 32-bit little-endian float, deinterleaved
// are coming from AudioUnitRender
memcpy(&(data_temp[0]), ab.mData, ab.mDataByteSize);
data[i].push_back(data_temp);

//for(int j=0; j<10; j++)
// printf("%.5f ", data_temp[j]);
//printf("\n");
}

midiPlayer_.GetTime( &currentTime );
Expand Down
2 changes: 2 additions & 0 deletions src/AHHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class AHHost


void LoadMidiFile(const string midiFile);
void CreateOneNote(int noteNumnber, float duration, int velocity);

// void LoadInstrument( const string& instrument, UInt32 busIndex = 0 );

vector< list< vector<float> > > Bounce();
Expand Down
58 changes: 58 additions & 0 deletions src/AHMidiPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,64 @@ void AHMidiPlayer::Stop()
PrintIfErr( MusicPlayerStop( musicPlayer_ ) );
}

void AHMidiPlayer::CreateOneNote(int noteNumber, float duration, int velocity)
{
// new music stuff
MusicPlayer temp_musicPlayer;
MusicSequence temp_musicSequence;
PrintIfErr( NewMusicPlayer(&temp_musicPlayer));
PrintIfErr( NewMusicSequence(&temp_musicSequence) );
PrintIfErr( MusicPlayerSetSequence(temp_musicPlayer, temp_musicSequence) );


// Disposing old music stuff
MusicTrack track;
UInt32 ntracks = GetTrackCount();
for( UInt32 trackIndex = 0; trackIndex < ntracks; ++trackIndex )
{
PrintIfErr( MusicSequenceGetIndTrack( musicSequence_, 0, &track ) );// 0 because we always delete the first one
PrintIfErr( MusicSequenceDisposeTrack(musicSequence_, track) );
}
PrintIfErr( DisposeMusicPlayer(musicPlayer_) );
PrintIfErr( DisposeMusicSequence(musicSequence_) );

// Create a MusicSequence with one track, one note called temp_musicSequence
PrintIfErr(MusicSequenceNewTrack(temp_musicSequence, &track));
MusicTimeStamp beat = 1.0;
MIDINoteMessage mess;
mess.channel = 0;
mess.note = noteNumber;
mess.velocity = velocity;
mess.releaseVelocity = 0;
mess.duration = duration;
PrintIfErr(MusicTrackNewMIDINoteEvent(track, beat, &mess));

musicPlayer_ = temp_musicPlayer;
musicSequence_ = temp_musicSequence;

PrintIfErr( MusicSequenceSetAUGraph(musicSequence_, graph_->GetAUGraph()) );


// // figure out sequence length, and add 8 beats to the end of the file to take decay etc. into account
MusicTimeStamp trackLength;
UInt32 propsize = sizeof( MusicTimeStamp );

ntracks = GetTrackCount();
//CAShow(musicSequence_);
musicSequenceLength_ = 0;
for( UInt32 trackIndex = 0; trackIndex < ntracks; ++trackIndex )
{
PrintIfErr( MusicSequenceGetIndTrack( musicSequence_, trackIndex, &track ) );
PrintIfErr( MusicTrackGetProperty( track, kSequenceTrackProperty_TrackLength, &trackLength, &propsize ) );

if ( trackLength > musicSequenceLength_ ) musicSequenceLength_ = trackLength;
}
musicSequenceLength_ += 8;

SetupMidiChannelMapping();

}

void AHMidiPlayer::LoadMidiFile( const string& midiFilePath )
{
// new music stuff
Expand Down
2 changes: 2 additions & 0 deletions src/AHMidiPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class AHMidiPlayer
~AHMidiPlayer();

void LoadMidiFile( const std::string& midiFile );
void CreateOneNote(int noteNumber, float duration, int velocity);

void GetTime( MusicTimeStamp* currentTime );
MusicTimeStamp GetSequenceLength() { return musicSequenceLength_; }
MusicSequence GetMusicSequence() { return musicSequence_; }
Expand Down