Author |
Message |
jirko

Joined: Dec 15, 2009 Posts: 59
|
Posted: Mon Mar 15, 2010 12:07 pm Post subject:
Midi Clock |
 |
|
I'm working on a midi clock to control Ableton but I can figured out how to send the start and stop msg for controlling the sequencer.
Can someone help me out? |
|
Back to top
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Wed Mar 17, 2010 4:25 am Post subject:
|
 |
|
The sad answer is that ChucK really only supports 3 byte messages. I've been able to use 2 byte messages (bank change, etc) send from ChucK by simply not setting the 3rd byte. You may be able to sneak through your 1 byte messages... but that might depend on the OS. It's all quite annoying.
Where did you get stuck? _________________ Kassen |
|
Back to top
|
|
 |
jirko

Joined: Dec 15, 2009 Posts: 59
|
Posted: Wed Mar 17, 2010 4:41 am Post subject:
|
 |
|
I'm not a midi expert, so the problem is that I don't now wich msg do I have to send to get the slave sequencer running? |
|
Back to top
|
|
 |
Antimon
Joined: Jan 18, 2005 Posts: 4145 Location: Sweden
Audio files: 371
G2 patch files: 100
|
Posted: Wed Mar 17, 2010 5:53 am Post subject:
|
 |
|
I found a MIDI spec here:
http://www.midi.org/techspecs/midimessages.php
Check under the heading "System Real-Time Messages ", look for messages called "Start", "Stop" etc. It's a bit hardcore to list the messages in binary - in hex, start is FA, continue is FB and Stop is FC, I think.
/Stefan _________________ Antimon's Window
@soundcloud @Flattr home - you can't explain music |
|
Back to top
|
|
 |
jirko

Joined: Dec 15, 2009 Posts: 59
|
Posted: Wed Mar 17, 2010 7:14 am Post subject:
|
 |
|
thanks Stefan. this link was useful. I have added a few lines to your code from another post..
Is there a way to send the "sendStop();" function when the user exits the thread?
Quote: |
//-------------------Mid Clock----------------------//
125 => float bpm;
((1 / bpm) * 4.0)::minute => dur bar;
bar - (now % bar) => now;//sync to bar
(1.0/16.0)::bar => dur tick;
2 => int MIDI_DEVICE_AMOUNT;
[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 >>>;
}
}
//sending start msg
fun void sendStart(){
MidiMsg midiMsg;
250 => midiMsg.data1;
0 => midiMsg.data2;
0 => midiMsg.data3;
for (0 => int i; i < ACTIVE_DEVICES.cap(); i++) {
midiOuts[ACTIVE_DEVICES[i]].send(midiMsg);}
}
//sending stop msg
fun void sendStop(){
MidiMsg midiMsg;
252 => midiMsg.data1;
0 => midiMsg.data2;
0 => midiMsg.data3;
for (0 => int i; i < ACTIVE_DEVICES.cap(); i++) {
midiOuts[ACTIVE_DEVICES[i]].send(midiMsg);}
}
//the midi clock
fun void sendMidiClockTick() {
while (true) {
tick/6 => now;
MidiMsg midiMsg;
248 => midiMsg.data1;
0 => midiMsg.data2;
0 => midiMsg.data3;
for (0 => int i; i < ACTIVE_DEVICES.cap(); i++) {
midiOuts[ACTIVE_DEVICES[i]].send(midiMsg);
}
}
}
//test code
spork ~ sendMidiClockTick();
2::second=>now;
sendStart();
8::second=>now;
sendStop();
1::second=>now;
|
|
|
Back to top
|
|
 |
Antimon
Joined: Jan 18, 2005 Posts: 4145 Location: Sweden
Audio files: 371
G2 patch files: 100
|
Posted: Wed Mar 17, 2010 7:35 am Post subject:
|
 |
|
Hey look, my old code! I've been looking for that!
What do you mean with "the user exits the thread"? If you mean when you kill the main ChucK program shred (I prefer to call it "shred", there are some crucial differences between threads and shreds that may cause confusion if the terms are treated as equivalents of each other) then I don't know actually - i don't think ChucK has that kind of shutdown hook mechanism.
You'll probably need to implement some interface event to call sendStop() (and probably close the app at the same time) - listen for a keypress, MIDI CC or something else.
/Stefan _________________ Antimon's Window
@soundcloud @Flattr home - you can't explain music |
|
Back to top
|
|
 |
|