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;
int repeatVolta;
bool brandNew;
bool hasMusicSequence;
VLSheetWindow * sheetWin;
VLLogWindow * logWin;
VLPDFWindow * pdfWin;

View File

@ -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

View File

@ -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;
}
}

View File

@ -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;