Pages: 1 ... 6 7 [8] 9 10 11   Go Down
Author Topic: works: MIDI-IN: code + schematics  (Read 37518 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for your help! I guess if that doesn't work, i might just have to get a professional interface.
Logged

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What's your interface? Are you sure that you plug it correctly?
(out interface>in keyboard, out keyboard>in interface,
check MIDI thru if it exist on it.)
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Midi out port from keyboard to midi in schematic which connects to RX which connects to S2MIDI, which forwards it as a midi out. It also has options for parity, data bits, and stop bits. Parity is set to None. Data Bits is set to 8. Stop Bits is set to 1.

Oh I noticed that the Com port relating to arduino is set in device manager to have a 9600 Baud rate. Should I change this?
« Last Edit: October 28, 2009, 01:49:06 pm by Iteo » Logged

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I meant without using the Arduino but your interface. (because as I explained above you had a baudrate problem in the software)
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

oh well i received data from the interface that i purchased, but it reversed the note on and note off commands, so a note would play until I played the next note
« Last Edit: October 28, 2009, 04:47:02 pm by Iteo » Logged

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How did you reverse that? I'm sorry but you're not very clear...


...and we're off topic. You should perhaps look at the bar...
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When I plugged in the midi interface that I bought it was already dysfunctional. I would play a note on the keyboard, and the computer would play a note only after I released a key. When I checked the midi commends that were being received by the purchased interface, it was giving a note off command when I pressed a key. I was never able to fix that. Well it doesn't seem like there is anything to try other then play with the baud rate. But thank you very much for all of you help. I appreciate it.
Logged

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you should look at the settings of your keyboard instead of the interface. The keyboard sends commands, the interface is just a translator, not an interpreter.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So I got this working and now modified the code to play a sound of the arduino, but I only get a quick beep and that's it.  

If I hold a key down on my controller I don't get a continuos sound.  I've   simply changed the code to have a playsound routine that is played when a 'note on' command arrives.  I assume midi doesn't keep sending a 'note on' command so it only makes it though that part of the if statement once, no matter how long I hold down the key.

I've tried a while loop with a statement to keep playing unless a 'note off' (128) is received with a serial.read inside the loop but then it never kick out off it

Suggestions? or am I missing something stupid because it was late at night?
Logged

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

SUYC !

(=show us your code)
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is what I have right now, I know it's ridiculously simple, just trying to get out a square wave.  

It's hacked out of some other code I have.

With this code it'll sound one note and then just stick on it


Code:


//variables setup

byte incomingByte;
byte note;
byte velocity;


int statusLed = 13;   // select the pin for the LED

int action=2; //0 =note off ; 1=note on ; 2= nada


//setup: declaring iputs and outputs and begin serial
void setup() {
  pinMode(statusLed,OUTPUT);   // declare the LED's pin as output


  //start serial with midi baudrate 31250 or 38400 for debugging
  Serial.begin(31250);        
  digitalWrite(statusLed,HIGH);  
}

//loop: wait for serial data, and interpret the message
void loop () {
  if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();

    // wait for as status-byte, channel 1, note on or off
    if (incomingByte== 144){ // note on message starting starting
      action=1;
    }
    else if (incomingByte== 128){ // note off message starting
      action=0;
    }
  
    else if ( (action==0)&&(note==0) ){ // if we received a "note off", we wait for which note (databyte)
      note=incomingByte;

      note=0;
      velocity=0;
      action=2;
    }
    else if ( (action==1)&&(note==0) ){ // if we received a "note on", we wait for the note (databyte)
      note=incomingByte;

    }
    else if ( (action==1)&&(note!=0) ){ // ...and then the velocity
      velocity=incomingByte;
      while (incomingByte!=128)
      {
        freqout(note);
        incomingByte = Serial.read();

      }
      note=0;
      //velocity=0;
      action=0;
    }
    else{
      //nada
    }
  }
}


void freqout(int freq)
{
  int hperiod;
  hperiod = (500000 / freq);
  analogWrite(12, (255));
  delayMicroseconds(hperiod);
  digitalWrite(12,LOW);
  delayMicroseconds(hperiod - 1);

}



« Last Edit: November 18, 2009, 07:18:24 pm by Starfire » Logged

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Code:
else if ( (action==0)&&(note==0) ){ // if we received a "note off", we wait for which note (databyte)
      note=incomingByte;
Here, you do not read the new incoming byte, you have to put
incomingByte = Serial.read();
somewhere again to have to new incoming byte in incomingByte. Do you get it ?
Idem for the velocity.

I think you should rater have a
Code:
status = Serial.read();
command = Serial.read();
value = Serial.read();
after the Serial.available(), it would be clearer smiley-wink

Tell me if I'm not clear enough!
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think I understand.  separating each byte into a different variable?  Does MIDI commands always come in 3 byte chunks?  That would make it easer to break up the commands then having to use the if statement.
Logged

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, most MIDI commands are in 3 bytes.
To be sure, just in case, read the status byte to know if it is in 3 bytes by type.
I suggest you to look here to better understand how all the protocol works and the possibilities: http://www.blitter.com/~russtopia/MIDI/~jglatt/tech/midispec.htm  smiley-wink
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can get it to play a note, but I can't get it to hold a note when I hold a key down.  I only get a quick note when I first press and then again when I release the key.
Logged

Pages: 1 ... 6 7 [8] 9 10 11   Go Up
Jump to: