diff --git a/Sources/VLDocument.h b/Sources/VLDocument.h index 2f0e416..11b18b4 100644 --- a/Sources/VLDocument.h +++ b/Sources/VLDocument.h @@ -45,6 +45,7 @@ enum { NSMutableDictionary*validTmpFiles; int repeatVolta; bool brandNew; + bool hasMusicSequence; VLSheetWindow * sheetWin; VLLogWindow * logWin; VLPDFWindow * pdfWin; diff --git a/Sources/VLDocument.mm b/Sources/VLDocument.mm index d3e8087..385dca9 100644 --- a/Sources/VLDocument.mm +++ b/Sources/VLDocument.mm @@ -91,6 +91,7 @@ vcsWrapper = nil; repeatVolta = 2; brandNew = true; + hasMusicSequence = false; playRate = 1.0; observers = [[NSMutableArray alloc] init]; validTmpFiles = [[NSMutableDictionary alloc] initWithCapacity:10]; @@ -112,6 +113,7 @@ - (void)updateChangeCount:(NSDocumentChangeType)changeType { + hasMusicSequence = true; [validTmpFiles removeAllObjects]; [super updateChangeCount:changeType]; } @@ -495,30 +497,35 @@ - (IBAction) play:(id)sender { - [self createTmpFileWithExtension:@"mid" ofType:@"VLMIDIType"]; + if (hasMusicSequence) { + VLSoundOut::Instance()->PlaySequence(NULL); + } else { + [self createTmpFileWithExtension:@"mid" ofType:@"VLMIDIType"]; - MusicSequence music; - NewMusicSequence(&music); + MusicSequence music; + NewMusicSequence(&music); - FSRef fsRef; - CFURLGetFSRef((CFURLRef)[self fileURLWithExtension:@"mid"], &fsRef); + FSRef fsRef; + CFURLGetFSRef((CFURLRef)[self fileURLWithExtension:@"mid"], &fsRef); - MusicSequenceLoadSMFWithFlags(music, &fsRef, - kMusicSequenceLoadSMF_ChannelsToTracks); + MusicSequenceLoadSMFWithFlags(music, &fsRef, + kMusicSequenceLoadSMF_ChannelsToTracks); - size_t countIn = 0; - if (playElements & kVLPlayCountIn) - switch ([[self songTime] intValue]) { - case 0x404: - case 0x304: - case 0x608: - countIn = 2; - } - VLMIDIWriter annotate(music, countIn); - annotate.Visit(*song); + size_t countIn = 0; + if (playElements & kVLPlayCountIn) + switch ([[self songTime] intValue]) { + case 0x404: + case 0x304: + case 0x608: + countIn = 2; + } + VLMIDIWriter annotate(music, countIn); + annotate.Visit(*song); - [sheetWin willPlaySequence:music]; - VLSoundOut::Instance()->PlaySequence(music); + hasMusicSequence = true; + [sheetWin willPlaySequence:music]; + VLSoundOut::Instance()->PlaySequence(music); + } } - (void) playWithGroove:(NSString *)groove inSections:(NSRange)sections diff --git a/Sources/VLSoundOut.cpp b/Sources/VLSoundOut.cpp index e0d43c1..ef0052c 100644 --- a/Sources/VLSoundOut.cpp +++ b/Sources/VLSoundOut.cpp @@ -27,7 +27,7 @@ public: virtual void PlayNote(const VLNote & note); virtual void PlayChord(const VLChord & chord); virtual void PlaySequence(MusicSequence music); - virtual void Stop(); + virtual void Stop(bool pause); virtual bool Playing(); virtual void SetPlayRate(float rate); virtual void SetTime(MusicTimeStamp time); @@ -125,7 +125,7 @@ VLAUSoundOut::VLAUSoundOut(bool) VLAUSoundOut::~VLAUSoundOut() { DisposeMusicPlayer(fPlayer); - Stop(); + Stop(false); DisposeAUGraph(fGraph); } @@ -189,13 +189,15 @@ void VLAUSoundOut::SetupOutput(AUNode) void VLAUSoundOut::PlaySequence(MusicSequence music) { - Stop(); + if (music) { + Stop(false); + + fMusic = music; + fMusicLength = SequenceLength(music); - fMusic = music; - fMusicLength = SequenceLength(music); - - R(MusicSequenceSetAUGraph(fMusic, fGraph)); - R(MusicPlayerSetSequence(fPlayer, fMusic)); + R(MusicSequenceSetAUGraph(fMusic, fGraph)); + R(MusicPlayerSetSequence(fPlayer, fMusic)); + } R(MusicPlayerStart(fPlayer)); fRunning = true; @@ -220,16 +222,14 @@ void VLAUSoundOut::SetTime(MusicTimeStamp time) MusicPlayerSetTime(fPlayer, time); } -void VLAUSoundOut::Stop() +void VLAUSoundOut::Stop(bool pause) { MusicPlayerStop(fPlayer); - if (fRunning) { - fRunning = false; - if (fMusic) { - MusicPlayerSetSequence(fPlayer, NULL); - DisposeMusicSequence(fMusic); - fMusic = 0; - } + fRunning = false; + if (!pause && fMusic) { + MusicPlayerSetSequence(fPlayer, NULL); + DisposeMusicSequence(fMusic); + fMusic = 0; } } diff --git a/Sources/VLSoundOut.h b/Sources/VLSoundOut.h index 02039ce..88571e2 100644 --- a/Sources/VLSoundOut.h +++ b/Sources/VLSoundOut.h @@ -39,7 +39,7 @@ public: virtual void PlayChord(const VLChord & chord) = 0; void PlayFile(CFDataRef file); virtual void PlaySequence(MusicSequence music) = 0; - virtual void Stop() = 0; + virtual void Stop(bool pause=true) = 0; virtual bool Playing() = 0; virtual void SetPlayRate(float rate) = 0; virtual void SetTime(MusicTimeStamp time) = 0;