diff --git a/Sources/VLDocument.mm b/Sources/VLDocument.mm index b76c5e7..dd98dfc 100644 --- a/Sources/VLDocument.mm +++ b/Sources/VLDocument.mm @@ -292,10 +292,17 @@ - (void)setPlayElements:(int)elements { + [self willChangeValueForKey:@"playElements"]; playElements = elements; - [validTmpFiles removeObjectForKey:@"mma"]; - [validTmpFiles removeObjectForKey:@"mid"]; - hasMusicSequence = false; + if (!(playElements & (kVLPlayMelody|kVLPlayAccompaniment))) + playElements |= kVLPlayAccompaniment; + if ((playElements & (kVLPlayMelody|kVLPlayGroovePreview)) != kVLPlayMelody) + VLSoundOut::Instance()->SetMelodyState(VLSoundOut::kMelodyMute); + else if (!(playElements & (kVLPlayAccompaniment|kVLPlayGroovePreview))) + VLSoundOut::Instance()->SetMelodyState(VLSoundOut::kMelodySolo); + else + VLSoundOut::Instance()->SetMelodyState(VLSoundOut::kMelodyRegular); + [self didChangeValueForKey:@"playElements"]; } - (int) repeatVolta @@ -476,7 +483,7 @@ NewMusicSequence(&music); MusicSequenceFileLoad(music, (CFURLRef)[self fileURLWithExtension:@"mid"], - 0, kMusicSequenceLoadSMF_ChannelsToTracks); + 0, 0); size_t countIn = 0; if (playElements & kVLPlayCountIn) @@ -494,7 +501,8 @@ baseTempo = songTempo; VLSoundOut::Instance()->SetPlayRate(playRate); VLSoundOut::Instance()->PlaySequence(music); - } + } + [self setPlayElements:[self playElements]]; } - (void) playWithGroove:(NSString *)groove inSections:(NSRange)sections diff --git a/Sources/VLGrooveController.mm b/Sources/VLGrooveController.mm index a55f683..c0db1e2 100644 --- a/Sources/VLGrooveController.mm +++ b/Sources/VLGrooveController.mm @@ -24,7 +24,7 @@ @"!(SELF matches[c] '.*(Intro|End)\\\\d*$')"] retain]; fView = view; - fSheetWin = (VLSheetWindow *)[view window]; + fSheetWin = [[view window] windowController]; [NSApp beginSheet: [self window] modalForWindow: [view window] diff --git a/Sources/VLMMADocument.mm b/Sources/VLMMADocument.mm index b004f1d..4d4b451 100644 --- a/Sources/VLMMADocument.mm +++ b/Sources/VLMMADocument.mm @@ -49,12 +49,7 @@ // Can't handle these yet break; } - if (!(playElements & kVLPlayAccompaniment)) - mmaFile += "AllTracks Off\nSolo On\n"; - if (playElements & kVLPlayMelody) - mmaFile += "Solo Voice AltoSax\nSolo Volume fff\n"; - else - mmaFile += "Solo Off\n"; + mmaFile += "Solo Voice AltoSax\nSolo Volume fff\n"; } mmaFile += '\n'+writer.Measures(); diff --git a/Sources/VLSheetViewSelection.mm b/Sources/VLSheetViewSelection.mm index cc5ac11..1f0deab 100644 --- a/Sources/VLSheetViewSelection.mm +++ b/Sources/VLSheetViewSelection.mm @@ -30,7 +30,7 @@ } - (VLPlaybackEditable *)initWithView:(VLSheetView *)view; -- (void) userEvent:(NSValue *)event; +- (void) userEvent:(const VLMIDIUserEvent *)event; - (void) highlightCursor; @end @@ -47,9 +47,8 @@ return self; } -- (void) userEvent:(NSValue *)ev +- (void) userEvent:(const VLMIDIUserEvent *) event { - VLMIDIUserEvent * event = (VLMIDIUserEvent *)[ev pointerValue]; if (event->fPitch) { fNoteMeasure = event->fMeasure; fNoteAt = event->fAt; @@ -103,9 +102,9 @@ VLSequenceCallback( MusicTimeStamp inEventTime, const MusicEventUserData *inEventData, MusicTimeStamp inStartSliceBeat, MusicTimeStamp inEndSliceBeat) { - [(id)inClientData performSelectorOnMainThread:@selector(userEvent:) - withObject:[NSValue valueWithPointer:inEventData] - waitUntilDone:NO]; + dispatch_async(dispatch_get_main_queue(), ^{ + [(id)inClientData userEvent:(const VLMIDIUserEvent *)inEventData]; + }); } @implementation VLSheetView (Selection) diff --git a/Sources/VLSoundOut.cpp b/Sources/VLSoundOut.cpp index 18f508e..8542594 100644 --- a/Sources/VLSoundOut.cpp +++ b/Sources/VLSoundOut.cpp @@ -37,7 +37,8 @@ public: virtual void SetPlayRate(float rate); virtual void Fwd(); virtual void Bck(); - + virtual void SetMelodyState(MelodyState state); + virtual ~VLAUSoundOut(); void PollMusic(); protected: @@ -67,6 +68,7 @@ public: protected: virtual void SetupOutput(AUNode outputNode); virtual void PlaySequence(MusicSequence music); + virtual void SetMelodyState(MelodyState state) {} private: AudioUnit fOutput; CFURLRef fFile; @@ -111,8 +113,7 @@ void VLSoundOut::PlayFile(CFDataRef file) MusicSequence music; NewMusicSequence(&music); - MusicSequenceFileLoadData(music, file, 0, - kMusicSequenceLoadSMF_ChannelsToTracks); + MusicSequenceFileLoadData(music, file, 0, 0); PlaySequence(music); } @@ -222,6 +223,21 @@ void VLAUSoundOut::PlaySequence(MusicSequence music) dispatch_source_set_timer(fMusicPoll, DISPATCH_TIME_NOW, 500*NSEC_PER_MSEC, 200*NSEC_PER_MSEC); } +void VLAUSoundOut::SetMelodyState(VLSoundOut::MelodyState state) +{ + if (fMusic) { + UInt32 numTracks; + MusicTrack curTrack; + MusicSequenceGetTrackCount(fMusic, &numTracks); + MusicSequenceGetIndTrack(fMusic, numTracks-2, &curTrack); + + Boolean mute = state==kMelodyMute; + Boolean solo = state==kMelodySolo; + + MusicTrackSetProperty(curTrack, kSequenceTrackProperty_MuteStatus, &mute, sizeof(mute)); + MusicTrackSetProperty(curTrack, kSequenceTrackProperty_SoloStatus, &solo, sizeof(solo)); + } +} void VLAUSoundOut::SetPlayRate(float rate) { if ((rate < 0) != fForward) { diff --git a/Sources/VLSoundOut.h b/Sources/VLSoundOut.h index 45f1a0a..6ca7783 100644 --- a/Sources/VLSoundOut.h +++ b/Sources/VLSoundOut.h @@ -48,6 +48,12 @@ public: virtual void SetPlayRate(float rate) = 0; virtual void Fwd() = 0; virtual void Bck() = 0; + enum MelodyState { + kMelodyMute, + kMelodyRegular, + kMelodySolo + }; + virtual void SetMelodyState(MelodyState state) = 0; virtual ~VLSoundOut(); };