[dorkbotpdx-blabber] (2nd try) Programming Help Needed Please
Hans Lindauer
armatronix at sbcglobal.net
Sun Apr 5 14:07:26 EDT 2009
Let's try this again, without the attachments. You can find them at the provided link.
----- Forwarded Message ----
From: Hans Lindauer <armatronix at sbcglobal.net>
To: dorkbotpdx-blabber at dorkbot.org
Sent: Sunday, April 5, 2009 10:41:47 AM
Subject: Programming Help Needed Please
OK, I have (hopefully) one line to program to finish my re-write of my MIDI lights firmware. It's the line that modifies the MIDI library so that it passes any incoming bytes to the THRU port.
In my old program, I just did a Serial.read follower by a Serial.print, as follows:
void loop () {
if (Serial.available() > 0) {
newbyte = Serial.read(); // read the incoming byte
Serial.print(newbyte); // echo the incoming byte
...
I tried that again here, but with no luck. Then I looked at how they send data to the serial port for MIDI OUT in the library, and saw that they use a slightly different syntax: serial_.print (b, TYPE). So I tried adding that instead, as follows. I've included an extra snippet that shows how they're doing it, for context. My line is the one with the asterisks. I assumed that I could ignore the type argument, since I'm just passing the (int) variable c straight thru. (I also tried it as INT and BYTE types):
// Try to read data at serial port & pass anything read to processing function
void Midi::poll(void)
{
int c;
// Just keep sucking data from serial port until it runs out, processing
// MIDI messages as we go
while((c = serial_.read()) != -1) {
recvByte(c);
serial_.print(c); // ***** pass MIDI data THRU *****
}
}
// Send Midi NOTE OFF message to a given channel, with note 0-127 and velocity 0-127
void Midi::sendNoteOff(unsigned int channel, unsigned int note, unsigned int velocity)
{
int status = STATUS_EVENT_NOTE_OFF | ((channel - 1) & 0x0f);
if (sendFullCommands_ || (lastStatusSent_ != status)) {
serial_.print(status, BYTE);
}
serial_.print(note & 0x7f, BYTE);
serial_.print(velocity & 0x7f, BYTE);
}
If it helps to see the full library code from http://timothytwillman.com/?page_id=240, it's attached (this snippet is in midi.cpp). Please let me know if you have any ideas. By the way, this MIDI library seems to work pretty well otherwise (with only one light).
Thanks,
-Hans
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://music.columbia.edu/pipermail/dorkbotpdx-blabber/attachments/20090405/ff81dd69/attachment.html
More information about the dorkbotpdx-blabber
mailing list