Implement Stop/Restart

This commit is contained in:
Matthias Neeracher 2008-07-05 13:56:51 +00:00
parent 4ba648dcd8
commit c8e8a6eb4f
4 changed files with 44 additions and 36 deletions

View File

@ -45,6 +45,7 @@ enum {
NSMutableDictionary*validTmpFiles; NSMutableDictionary*validTmpFiles;
int repeatVolta; int repeatVolta;
bool brandNew; bool brandNew;
bool hasMusicSequence;
VLSheetWindow * sheetWin; VLSheetWindow * sheetWin;
VLLogWindow * logWin; VLLogWindow * logWin;
VLPDFWindow * pdfWin; VLPDFWindow * pdfWin;

View File

@ -91,6 +91,7 @@
vcsWrapper = nil; vcsWrapper = nil;
repeatVolta = 2; repeatVolta = 2;
brandNew = true; brandNew = true;
hasMusicSequence = false;
playRate = 1.0; playRate = 1.0;
observers = [[NSMutableArray alloc] init]; observers = [[NSMutableArray alloc] init];
validTmpFiles = [[NSMutableDictionary alloc] initWithCapacity:10]; validTmpFiles = [[NSMutableDictionary alloc] initWithCapacity:10];
@ -112,6 +113,7 @@
- (void)updateChangeCount:(NSDocumentChangeType)changeType - (void)updateChangeCount:(NSDocumentChangeType)changeType
{ {
hasMusicSequence = true;
[validTmpFiles removeAllObjects]; [validTmpFiles removeAllObjects];
[super updateChangeCount:changeType]; [super updateChangeCount:changeType];
} }
@ -495,6 +497,9 @@
- (IBAction) play:(id)sender - (IBAction) play:(id)sender
{ {
if (hasMusicSequence) {
VLSoundOut::Instance()->PlaySequence(NULL);
} else {
[self createTmpFileWithExtension:@"mid" ofType:@"VLMIDIType"]; [self createTmpFileWithExtension:@"mid" ofType:@"VLMIDIType"];
MusicSequence music; MusicSequence music;
@ -517,9 +522,11 @@
VLMIDIWriter annotate(music, countIn); VLMIDIWriter annotate(music, countIn);
annotate.Visit(*song); annotate.Visit(*song);
hasMusicSequence = true;
[sheetWin willPlaySequence:music]; [sheetWin willPlaySequence:music];
VLSoundOut::Instance()->PlaySequence(music); VLSoundOut::Instance()->PlaySequence(music);
} }
}
- (void) playWithGroove:(NSString *)groove inSections:(NSRange)sections - (void) playWithGroove:(NSString *)groove inSections:(NSRange)sections
{ {

View File

@ -27,7 +27,7 @@ public:
virtual void PlayNote(const VLNote & note); virtual void PlayNote(const VLNote & note);
virtual void PlayChord(const VLChord & chord); virtual void PlayChord(const VLChord & chord);
virtual void PlaySequence(MusicSequence music); virtual void PlaySequence(MusicSequence music);
virtual void Stop(); virtual void Stop(bool pause);
virtual bool Playing(); virtual bool Playing();
virtual void SetPlayRate(float rate); virtual void SetPlayRate(float rate);
virtual void SetTime(MusicTimeStamp time); virtual void SetTime(MusicTimeStamp time);
@ -125,7 +125,7 @@ VLAUSoundOut::VLAUSoundOut(bool)
VLAUSoundOut::~VLAUSoundOut() VLAUSoundOut::~VLAUSoundOut()
{ {
DisposeMusicPlayer(fPlayer); DisposeMusicPlayer(fPlayer);
Stop(); Stop(false);
DisposeAUGraph(fGraph); DisposeAUGraph(fGraph);
} }
@ -189,13 +189,15 @@ void VLAUSoundOut::SetupOutput(AUNode)
void VLAUSoundOut::PlaySequence(MusicSequence music) void VLAUSoundOut::PlaySequence(MusicSequence music)
{ {
Stop(); if (music) {
Stop(false);
fMusic = music; fMusic = music;
fMusicLength = SequenceLength(music); fMusicLength = SequenceLength(music);
R(MusicSequenceSetAUGraph(fMusic, fGraph)); R(MusicSequenceSetAUGraph(fMusic, fGraph));
R(MusicPlayerSetSequence(fPlayer, fMusic)); R(MusicPlayerSetSequence(fPlayer, fMusic));
}
R(MusicPlayerStart(fPlayer)); R(MusicPlayerStart(fPlayer));
fRunning = true; fRunning = true;
@ -220,18 +222,16 @@ void VLAUSoundOut::SetTime(MusicTimeStamp time)
MusicPlayerSetTime(fPlayer, time); MusicPlayerSetTime(fPlayer, time);
} }
void VLAUSoundOut::Stop() void VLAUSoundOut::Stop(bool pause)
{ {
MusicPlayerStop(fPlayer); MusicPlayerStop(fPlayer);
if (fRunning) {
fRunning = false; fRunning = false;
if (fMusic) { if (!pause && fMusic) {
MusicPlayerSetSequence(fPlayer, NULL); MusicPlayerSetSequence(fPlayer, NULL);
DisposeMusicSequence(fMusic); DisposeMusicSequence(fMusic);
fMusic = 0; fMusic = 0;
} }
} }
}
bool VLAUSoundOut::Playing() bool VLAUSoundOut::Playing()
{ {

View File

@ -39,7 +39,7 @@ public:
virtual void PlayChord(const VLChord & chord) = 0; virtual void PlayChord(const VLChord & chord) = 0;
void PlayFile(CFDataRef file); void PlayFile(CFDataRef file);
virtual void PlaySequence(MusicSequence music) = 0; virtual void PlaySequence(MusicSequence music) = 0;
virtual void Stop() = 0; virtual void Stop(bool pause=true) = 0;
virtual bool Playing() = 0; virtual bool Playing() = 0;
virtual void SetPlayRate(float rate) = 0; virtual void SetPlayRate(float rate) = 0;
virtual void SetTime(MusicTimeStamp time) = 0; virtual void SetTime(MusicTimeStamp time) = 0;