Re: Playing dynamically generated MIDI notes
Re: Playing dynamically generated MIDI notes
- Subject: Re: Playing dynamically generated MIDI notes
- From: Alexander Griekspoor <email@hidden>
- Date: Tue, 2 May 2006 19:16:00 +0200
I recently created a cocoa plugin to do the same for our PianoChords
widget, based on this example from the QuickTime documentation:
http://developer.apple.com/documentation/QuickTime/RM/MusicAndAudio/
qtma/C-Chapter/chapter_1000_section_4.html
Here are the relevant methods I ended up with and that worked for me.
If you want it to work in Universal binaries you have to keep
endianess in mind as I found out (as shown below).
Hope this helps,
Alex
#import <QuickTime/QuickTime.h>
NoteAllocator na;
NoteChannel nc;
NoteRequest nr;
- (void)openChannel {
ComponentResult thisError;
na = 0;
nc = 0;
// Open up the note allocator.
na = OpenDefaultComponent(kNoteAllocatorComponentType, 0);
if (!na)
NSLog(@"Error initializing QuickTime Component");
BigEndianShort s = (BigEndianShort){EndianS16_NtoB(8)};
BigEndianFixed f = (BigEndianFixed){EndianS16_NtoB(0x00010000)};
// Fill out a NoteRequest using NAStuffToneDescription to help, and
// allocate a NoteChannel.
nr.info.flags = 0;
nr.info.polyphony = s; // simultaneous tones
nr.info.typicalPolyphony = f; // usually just one note
thisError = NAStuffToneDescription(na, 1, &nr.tone); // 1 is piano
thisError = NANewNoteChannel(na, &nr, &nc);
}
- (void) playChord:(NSString *)str {
NSArray *notes = [str componentsSeparatedByString: @","]; // I
input a chord like @"1,4,6"
long t, i;
NSString *note;
NSEnumerator *e = [notes objectEnumerator];
while(note = [e nextObject]){
int the_note = 60 + [note intValue] - 13; // middle C == 60
NAPlayNote(na, nc, the_note, 80); // note at velocity 80
}
Delay(60, &t);
e = [notes objectEnumerator];
while(note = [e nextObject]){
int the_note = 60 + [note intValue] - 13;
NAPlayNote(na, nc, the_note, 0); // note at velocity 80
}
}
- (void)closeChannel {
if (nc)
NADisposeNoteChannel(na, nc);
if (na)
CloseComponent(na);
}
FROM : themacuser
DATE : Tue May 02 15:22:43 2006
In some code I am working on, I would like to play certain MIDI notes
that are programatically specified, and dynamically change depending
on the input of the code. I have googled for any information on doing
this, and can't seem to find anything. I can find plenty of
information on playing/generating MIDI files, but not on playing a
specified MIDI note live.
Anyone know how to achieve this?
Thanks in advance.
themacuser
***********************************
Mek (Alexander Griekspoor)
MekenTosj.com
Web: http://www.mekentosj.com
Mail: email@hidden
***********************************
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden