electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
Midi Clock
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [6 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
jirko



Joined: Dec 15, 2009
Posts: 59

PostPosted: Mon Mar 15, 2010 12:07 pm    Post subject: Midi Clock Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Wed Mar 17, 2010 4:25 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Send e-mail Visit poster's website
jirko



Joined: Dec 15, 2009
Posts: 59

PostPosted: Wed Mar 17, 2010 4:41 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 4146
Location: Sweden
Audio files: 371
G2 patch files: 100

PostPosted: Wed Mar 17, 2010 5:53 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Visit poster's website
jirko



Joined: Dec 15, 2009
Posts: 59

PostPosted: Wed Mar 17, 2010 7:14 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 4146
Location: Sweden
Audio files: 371
G2 patch files: 100

PostPosted: Wed Mar 17, 2010 7:35 am    Post subject: Reply with quote  Mark this post and the followings unread

Hey look, my old code! Smile 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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [6 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use