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
Need help with this Chuck program
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [3 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
JeEA



Joined: Sep 27, 2015
Posts: 27
Location: Denmark

PostPosted: Fri Apr 21, 2017 8:46 am    Post subject: Need help with this Chuck program Reply with quote  Mark this post and the followings unread

How does this program work?
I am using a usb hub and 2 waldorf rockets.
I know it is for 4 units, but i have made a prg for 2 units
My problem is that nothing happens. I don't know what is wrong.

//===================================================================

// call setupOut(midi device, midi channel, true enables CC messages input)
//
// for all devices that receive MIDI data. Run chuck --probe to find device IDs

Rocket rockets[4];
rockets[0].setupOut(3, 1, false); // Rocket #1
rockets[1].setupOut(4, 2, true); // Rocket #2
rockets[2].setupOut(5, 3, true); // Rocket #3
rockets[3].setupOut(6, 4, true); // Rocket #4

// call setupIn(midi device, midi channel)

// for all device that send MIDI data. If you include a device that you also
// ran setupOut for here, and it sends MIDI CC data, you must set the third
// argument for it above to false.

Master master1;
master1.setupIn(3, 1); // Rocket #1

Master master2;
master2.setupIn(2, 0); // Keyboard

//===================================================================

class Rocket {
MidiOut midiOut;
int midiDevice;
int midiChannel;
int acceptMidiCC;

-1 => int noteOn;

MidiMsg midiMsg;

fun void setupOut(int device, int channel, int acceptCC) {
device => midiDevice;
channel => midiChannel;
acceptCC => acceptMidiCC;
if (midiOut.open(device)) {
<<< "Opened MIDI output ", midiOut.name() >>>;
} else {
<<< "Couldn't open MIDI output #", device, " Sad" >>>;
}
}

fun int sendMidi(int data1, int data2, int data3, int force) {
0 => int sendIt;
// <<< "Got msg ", data1, data2, data3, " state=", noteOn, force, sendIt >>>;
if (isNoteOn(data1, data3)) {
if (noteOn == -1 || force) {
if (noteOn > -1) {
// Send note off to prevent lingering notes on the Rocket
(data1 & 0xf0) + midiChannel => midiMsg.data1;
0x80 + noteOn => midiMsg.data2;
0 => midiMsg.data3;
midiOut.send(midiMsg);
}
data2 => noteOn;
1 => sendIt;
}
} else if (isNoteOff(data1, data3)) {
if (data2 == noteOn) {
-1 => noteOn;
1 => sendIt;
}
} else if (acceptMidiCC) {
1 => sendIt;
}
if (sendIt) {
(data1 & 0xf0) + midiChannel => midiMsg.data1;
data2 => midiMsg.data2;
data3 => midiMsg.data3;
midiOut.send(midiMsg);
return true;
} else {
return false;
}
}
}

class Master {
int midiDevice;
int midiChannel;

0 => int nextRocket;

fun void setupIn(int device, int channel) {
device => midiDevice;
channel => midiChannel;
spork ~ listener();
}

fun int rocketIsMe(int rocket) {
return rockets[rocket].midiDevice == midiDevice && rockets[rocket].midiChannel == midiChannel;
}

fun void findRocketAndSend(int data1, int data2, int data3) {
isNoteOn(data1, data3) || isNoteOff(data1, data3) => int isNoteMessage;
0 => int midiSent;
for (0 => int i; i <rockets> int rocket;
if (!rocketIsMe(rocket) && rockets[rocket].sendMidi(data1, data2, data3, false)) {
1 => midiSent;
if (isNoteMessage) {
if (isNoteOn(data1, data2)) {
(rocket + 1) % rockets.size() => nextRocket;
}
break;
}
}
}
if (!midiSent && isNoteOn(data1, data3)) {
rockets[nextRocket].sendMidi(data1, data2, data3, true);
(nextRocket + 1) % rockets.size() => nextRocket;
}
}

fun void listener() {
MidiIn midiIn;
MidiMsg midiMsg;

if (midiIn.open(midiDevice)) {
<<< "Opened MIDI input ", midiIn.name() >>>;
} else {
<<< "Couldn't open MIDI input #" + midiDevice + " Sad" >>>;
}

while (true) {
midiIn => now;
while (midiIn.recv(midiMsg)) {
// <<< "Received midi: ", midiMsg.data1, midiMsg.data2, midiMsg.data3, (midiMsg.data1 & 0x0f) >>>;
if ((midiMsg.data1 & 0x0f) == midiChannel) {
findRocketAndSend(midiMsg.data1, midiMsg.data2, midiMsg.data3);
}
}
}
}
}

fun int isNoteOn(int noteOnOff, int velocity) {
return (noteOnOff & 0xf0) == 0x90 && velocity > 0;
}

fun int isNoteOff(int noteOnOff, int velocity) {
return (noteOnOff & 0xf0) == 0x80 || (noteOnOff & 0xf0) == 0x90 && velocity == 0;
}


while (true) {
1::week => now;
}
Back to top
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 4009
Location: Sweden
Audio files: 334
G2 patch files: 100

PostPosted: Wed Apr 26, 2017 7:56 am    Post subject: Reply with quote  Mark this post and the followings unread

Hi!

Could you please repost your program within code brackets (click the "Code" button when editing your post), and also click "Disable HTML in this post" and "Disable Smilies in this post"? It's difficult to read the code otherwise. Smile

_________________
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
JeEA



Joined: Sep 27, 2015
Posts: 27
Location: Denmark

PostPosted: Thu Apr 27, 2017 9:40 am    Post subject: Reply with quote  Mark this post and the followings unread

I'll give it a try
I do not know anything about Chuck programming.
The program should rute midi input data to 4 different waldorf rockets
synths.
How does the computer know where to send the midi data. They are on a usb hub and the keyboard on a usb - midi interface

Cheers
Will get back with the program asap
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [3 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
e-m mkii

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


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