Implement (Rudimentary) MIDI playing

This commit is contained in:
Matthias Neeracher 2006-11-13 04:26:09 +00:00
parent f4c1d7b591
commit ff05955b00
8 changed files with 35 additions and 2 deletions

View File

@ -30,7 +30,7 @@
{
CLASS = VLSheetWindow;
LANGUAGE = ObjC;
OUTLETS = {logToolItem = id; outputToolItem = id; runToolItem = id; };
OUTLETS = {logToolItem = id; outputToolItem = id; playToolItem = id; runToolItem = id; };
SUPERCLASS = NSWindowController;
}
);

View File

@ -12,6 +12,6 @@
<integer>5</integer>
</array>
<key>IBSystem Version</key>
<string>9A294</string>
<string>9A300</string>
</dict>
</plist>

Binary file not shown.

View File

@ -14,6 +14,7 @@
#import "VLPDFWindow.h"
#import "VLLogWindow.h"
#import "VLSheetWindow.h"
#import "VLSoundOut.h"
@implementation VLDocument
@ -281,6 +282,16 @@
}
}
- (IBAction) play:(id)sender
{
NSError * err;
[self writeToURL:[self fileURLWithExtension:@"mid"]
ofType:@"VLMIDIType" error:&err];
VLSoundOut::Instance()->PlayFile(
CFDataRef([NSData dataWithContentsOfURL:
[self fileURLWithExtension:@"mid"]]));
}
- (IBAction) showOutput:(id)sender
{
[[self pdfWin] showWindow:sender];

View File

@ -27,6 +27,7 @@
IBOutlet id runToolItem;
IBOutlet id outputToolItem;
IBOutlet id logToolItem;
IBOutlet id playToolItem;
}
- (VLEditable *) editTarget;

View File

@ -46,6 +46,7 @@ static NSString* sInputToolbarIdentifier = @"Vocalese Sheet Window Toolbar Id
static NSString* sOutputToolbarItemIdentifier = @"Output Toolbar Item Identifier";
static NSString* sLogToolbarItemIdentifier = @"Log Toolbar Item Identifier";
static NSString* sRunToolbarItemIdentifier = @"Run Toolbar Item Identifier";
static NSString* sPlayToolbarItemIdentifier = @"Play Toolbar Item Identifier";
- (id)initWithWindow:(NSWindow *)window
{
@ -87,6 +88,8 @@ static NSString* sRunToolbarItemIdentifier = @"Run Toolbar Item Identifier";
prototype = logToolItem;
else if ([itemIdent isEqual: sRunToolbarItemIdentifier])
prototype = runToolItem;
else if ([itemIdent isEqual: sPlayToolbarItemIdentifier])
prototype = playToolItem;
if (prototype) {
toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
@ -106,6 +109,7 @@ static NSString* sRunToolbarItemIdentifier = @"Run Toolbar Item Identifier";
- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar {
return [NSArray arrayWithObjects:
sRunToolbarItemIdentifier,
sPlayToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
sOutputToolbarItemIdentifier,
sLogToolbarItemIdentifier, nil];
@ -114,6 +118,7 @@ static NSString* sRunToolbarItemIdentifier = @"Run Toolbar Item Identifier";
- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar {
return [NSArray arrayWithObjects:
sRunToolbarItemIdentifier,
sPlayToolbarItemIdentifier,
sOutputToolbarItemIdentifier,
sLogToolbarItemIdentifier,
NSToolbarCustomizeToolbarItemIdentifier,

View File

@ -21,6 +21,7 @@ public:
virtual void PlayNote(const VLNote & note);
virtual void PlayChord(const VLChord & chord);
virtual void PlayFile(CFDataRef file);
virtual ~VLAUSoundOut();
@ -169,3 +170,16 @@ void VLAUSoundOut::Play(const int8_t * note, size_t numNotes)
PlaySequence(music);
}
void VLAUSoundOut::PlayFile(CFDataRef file)
{
MusicSequence music;
MusicTrack track;
NewMusicSequence(&music);
MusicSequenceNewTrack(music, &track);
MusicSequenceLoadSMFDataWithFlags(music, file,
kMusicSequenceLoadSMF_ChannelsToTracks);
PlaySequence(music);
}

View File

@ -8,6 +8,7 @@
*/
#include "VLModel.h"
#import <CoreFoundation/CoreFoundation.h>
class VLSoundEvent {
protected:
@ -32,6 +33,7 @@ public:
virtual void PlayNote(const VLNote & note) = 0;
virtual void PlayChord(const VLChord & chord) = 0;
virtual void PlayFile(CFDataRef file) = 0;
virtual ~VLSoundOut();
};