Author |
Message |
djdaphalgan
Joined: Jul 19, 2007 Posts: 20 Location: Belgium
|
Posted: Wed Aug 08, 2007 7:41 am Post subject:
Midi Clock |
|
|
Is it posible to make a midi clock in Chuck. I want to use Chuck to control Reason. I use MidiYoke for this. I want to make a midi clock in Chuck, so that Reason can sync to this clock (Reason can only run as a slave). How does a midi clock work? I guess it send some pulse or something? |
|
Back to top
|
|
|
Kassen
Janitor
Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Wed Aug 08, 2007 8:07 am Post subject:
|
|
|
MIDI clock is a one-byte message so it's quite simple. Unfortunately, right now ChucK asumes all MIDI messages to be three bytes which means no clock. I'll add it to the wish-list on the Wiki right now because this has been talked about many times by many people. _________________ Kassen |
|
Back to top
|
|
|
blue hell
Site Admin
Joined: Apr 03, 2004 Posts: 24083 Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320
|
Posted: Wed Aug 08, 2007 8:13 am Post subject:
|
|
|
Kassen wrote: | Unfortunately, right now ChucK asumes all MIDI messages to be three bytes which means no clock. |
Would dummy bytes be possible ? _________________ Jan
also .. could someone please turn down the thermostat a bit.
|
|
Back to top
|
|
|
Kassen
Janitor
Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Wed Aug 08, 2007 8:29 am Post subject:
|
|
|
That's a good question.
I was able to get two-byte messages to work so *maybe*. I don't think anyone got it to work yet but I'm not sure wether anyone tried very hard.
A larger issue is that in ChucK MIDI is hard to use and basically requires you to keep the MIDI specs at hand and send out bytes as raw numbers. A more readable and easier to use interface for anything that's not sysex would be better. _________________ Kassen |
|
Back to top
|
|
|
Acoustic Interloper
Joined: Jul 07, 2007 Posts: 2067 Location: Berks County, PA
Audio files: 89
|
Posted: Wed Aug 08, 2007 12:33 pm Post subject:
|
|
|
Kassen wrote: | That's a good question.
I was able to get two-byte messages to work so *maybe*. I don't think anyone got it to work yet but I'm not sure wether anyone tried very hard.
A larger issue is that in ChucK MIDI is hard to use and basically requires you to keep the MIDI specs at hand and send out bytes as raw numbers. A more readable and easier to use interface for anything that's not sysex would be better. |
I don't know about OSX or Linux, but the low level windows midi api always takes a 32 bit integer, so everything I send is just 4 bytes, with zeros stuffed into the upper bits. X86 is litte endian, so the first byte out is the least significant byte. Make sure to zero unused bytes, since midi command bytes have the top bit ON and data bytes have the top bit off; you don't want unused bytes to look like commands, so zero them. I'd be sadly amazed if this doesn't work.
As I recall, ChucK doesn't support include files yet, but you can alway use midi command names as numeric constants that are assigned at the top of your chuck source file. Including would avoid copying this file into the top of your sourse file; it would do that automatically.
My favorite midi reference, by the way, is at http://www.borg.com/~jglatt/tech/midispec.htm beneath http://www.borg.com/~jglatt/ . _________________ When the stream is deep
my wild little dog frolics,
when shallow, she drinks. |
|
Back to top
|
|
|
Kassen
Janitor
Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Wed Aug 08, 2007 2:33 pm Post subject:
|
|
|
Acoustic Interloper wrote: |
I don't know about OSX or Linux, but the low level windows midi api always takes a 32 bit integer, so everything I send is just 4 bytes, with zeros stuffed into the upper bits. X86 is litte endian, so the first byte out is the least significant byte. Make sure to zero unused bytes, since midi command bytes have the top bit ON and data bytes have the top bit off; you don't want unused bytes to look like commands, so zero them. I'd be sadly amazed if this doesn't work.
|
Fortunately that is all shielded off in ChucK and you only have to define what's in the byte to be send and this can be in hex if you'd like.
Quote: | As I recall, ChucK doesn't support include files yet, but you can alway use midi command names as numeric constants that are assigned at the top of your chuck source file. Including would avoid copying this file into the top of your sourse file; it would do that automatically. |
That's a good method. A alternative would be writing a few functions called something like "sendCC( int chan, int cc, int value)". Even better would be having Bruce Murphy do this for you :¬);
http://www.rattus.net/~packrat/audio/ChucK/
...would be better with a real "include" but you can always paste it to the bottom of the file.
The issue, as I see it, (aside from not even Bruce getting clock to work) is that this looks quite scary to new users and it's less then convenient. I think something like what Bruce did with some extras should be a part of the midi in&out objects as those are quite inportant in intergrating ChucK with a larger setup so that should ideally be accessible and easy to use.
Bookmarked! I had that one as a bookmark but lost it and now had another one that's less structured. Thanks! _________________ Kassen |
|
Back to top
|
|
|
Antimon
Joined: Jan 18, 2005 Posts: 4145 Location: Sweden
Audio files: 371
G2 patch files: 100
|
Posted: Fri Jan 04, 2008 4:26 pm Post subject:
|
|
|
I've being trying out MIDI clock to ChucK lately (thought there was a more recent thread about it here, but I can't find it), whithout result. I made a little Java app that accepts MIDI clock from some external source and converts it to an OSC message that got sent to my ChucK sequencer. Unfortunately this only worked as long as I didn't turn the sample select dial on my Electribe SX, upon which the clock died a bit and lost sync completely. So I gave up.
Then, just for kicks, when someone asked if I had MIDI beat in a sequencer I posted on the monome forum (here if anyone's interested: http://post.monome.org/comments.php?DiscussionID=469&page=1#Comment_4753), I figured I'd try to see if I can send MIDI clock from my ChucK sequencer. I didn't think of this first, since my understanding is that the thumb rule is: never clock software -> hardware, always the other way round.
Admittedly, I haven't tried this out for very long, but haven't lost sync yet. ChucK doesn't filter out MIDI clock messages on the way out, only on the way in. Here's the clock code (my sequencer does "tick => now" between each step, and this way I seem to get a 120 BPM tempo):
Code: |
6 => int MIDI_DEVICE_AMOUNT;
//[1, 3, 5] @=> int ACTIVE_DEVICES[];
[0] @=> int ACTIVE_DEVICES[];
MidiOut midiOuts[MIDI_DEVICE_AMOUNT];
for ( 0 => int i; i < MIDI_DEVICE_AMOUNT; i++) {
if (midiOuts[i].open(i)) {
<<< "Opened MIDI device #", i, ": ", midiOuts[i].name() >>>;
} else {
<<< "Could not open MIDI device ", i >>>;
}
}
0.5::second / 4 => dur tick;
fun void sendMidiClockTick() {
while (true) {
tick/6 => now;
MidiMsg midiMsg;
0xf8 => midiMsg.data1; // MIDI clock
0 => midiMsg.data2; // Not used
0 => midiMsg.data3; // Not used
for (0 => int i; i < ACTIVE_DEVICES.cap(); i++) {
midiOuts[ACTIVE_DEVICES[i]].send(midiMsg);
}
}
}
spork ~ sendMidiClockTick();
while (true) { 1::second => now; }
|
/Stefan _________________ Antimon's Window
@soundcloud @Flattr home - you can't explain music |
|
Back to top
|
|
|
|