Shop OBEX P1 Docs P2 Docs Learn Events
MIDI to LED — Parallax Forums

MIDI to LED

Fenta7Fenta7 Posts: 8
edited 2010-07-23 19:58 in Propeller 1
Can someone·help me with a midi project I am working on? I would like to take the note on and the velocity bytes and send a on time to and output pin. For example if·D# has a velocity of 64 the output of one of the pins on the propeller board will have 250 milliseconds or if it had a velocity of 127 the on time would be 500 millisectonds.

I would like to have at least 16 different velocities·that would have 16 different pulse times per note. I would also like to do this for at least eight notes D# to A#.

Basically each note would send a pulse to an output pin. the length of the pulse is determined by the note's "velocity".
It can be look at like Midi in to an LED and base on the velocity of the MIDI the LED would stay a short time of if the velocity was at 127 it would be on longer.

Thank you very much
Brad
313-663-2321

Comments

  • T ChapT Chap Posts: 4,223
    edited 2010-07-18 17:44
    What exactly are you asking? What stage are you at right now, do you have any aspect of reading midi handled and just need to add the LED part? It would help get some better responses if you clarified your need. If you are already reading the midi in and have that under control, then turning on an LED could be easily handled with CASE statements, 16 statements determine hold different durations for the LED to stay on base on velocity per key. Likewise, doing something like sending out a PWM to the LED would allow you to vary the intensity of the LED based on velocity as well.
  • Fenta7Fenta7 Posts: 8
    edited 2010-07-18 18:16
    I would like to be abel to take the MIDI channel, MIDInote-on and the MIDI velocity output of a MIDI signal an decode it in the propeller chip to send the pulse to output pin on the propeller chip then to a LED. I want to control the output pulse based on the input of the MIDI signal. I am just starting the project and I don't know where to begin coding the propeller.

    Thank you
  • hover1hover1 Posts: 1,929
    edited 2010-07-18 18:33
    Sounds like a neat project. I can't be of much help right now, as I am on the road, but a couple things to check out:

    There are two MIDI In objects in the OBEX:

    ·http://obex.parallax.com/objects/229/

    ·http://obex.parallax.com/objects/323/

    Also a Google search : "MIDI In propeller" brings up a lot of potential sites, (and a few in the Parallax forums).

    The search in the forum software, (upper right), does bring up a few if you limit it to Propeller for the last year. Some circuit diagrams, also.

    Jim
  • AribaAriba Posts: 2,690
    edited 2010-07-18 21:04
    Hello Brad and welcome to the forum

    Because we do not know, what you have already and what you know about Spin and the Propeller, I made a little
    Example code to show you how I would make it. This code is not tested, but compiles.
    The code expects contiguous output pins.

    The MIDI input is at Pin31 you may have to change this. Do you have already a MIDI in hardware?

    CON
      _clkmode      = xtal1 + pll16x
      _xinfreq      = 5_000_000
    
      CHANNEL       = 0       'MIDI channel 0..15
      NOTES         = 8       'number of notes
      FIRST_NOTE    = 60      'C3
      FIRST_PIN     = 0
            
    VAR
      long puls[noparse][[/noparse]NOTES]
      long stack[noparse][[/noparse]20]
      
    OBJ
      midi  : "FullDuplexSerial"                      'serial driver for MIDI
    
    PUB Main  | status, note, vel
      midi.start(31,30,0,31250)                       'MIDI input on P31
      cognew(pulsout,@stack)                          'start 2nd Cog for pulses
    
      repeat
        status := midi.rx
        if status == $90+CHANNEL                      'Note On? (on right channel)
          note := midi.rx
          vel := midi.rx
          if vel > 0                                  'no NoteOff?
            note -= FIRST_NOTE
            if note => 0 and note < NOTES             'in range?
              puls[noparse][[/noparse]note] := vel                       'write to puls array
          
    PUB pulsout | i                                   'generate pulses according puls array
      dira[noparse][[/noparse]FIRST_PIN+NOTES-1..FIRST_PIN] := TRUE      'set pins to output
      repeat
        repeat i from 0 to NOTES-1                    'check every puls array item
          if puls[noparse][[/noparse] i ] > 0
            outa[noparse][[/noparse]FIRST_PIN+i] := 1                    'set pin to high
            puls[noparse][[/noparse] i ]--                               'count cycles (until puls[noparse][[/noparse] i]==0)
          else
            outa[noparse][[/noparse]FIRST_PIN+i] := 0                    'clear Pin if no puls
        waitcnt(clkfreq/250 + cnt)                    'wait 4ms (4ms*128=512ms max)
    
    



    Andy

    Post Edited (Ariba) : 7/19/2010 1:15:43 AM GMT
  • Fenta7Fenta7 Posts: 8
    edited 2010-07-19 00:45
    Hi Andy
    I will work with this. This is great. I really appreciate it.

    Where do I set the on time for the velocities?
    For example 1-8 would be 10ms, 9-16 woudl be 20ms, 17-24 would be 30ms 25-32would be 40ms, 33-40would be 50ms,
    41-48 would be 60ms, 49-64 woudl be 70ms, 65-72 would be 80ms, 73-80 would be 90ms, 81-88would be 100ms,
    89-94 would be 110ms, 95-102 woudl be 120ms, 103-110 would be 130ms, 111-118 would be 140ms,
    119-127 mswould be 150ms on one to the propellers output pins to the LED.

    Can I make each note have its own llist on velocity output times
    For example C would have 1-8 would be 10ms, but C# would havebe have 1-8 would be 15ms.

    Thank you
    Brad





    Does each note have 16 different output times on each pin

    Brad
  • AribaAriba Posts: 2,690
    edited 2010-07-19 01:24
    Brad

    The puls times have 127 different values, one for each possible velocity value.
    The time is now: velocity_value * 4ms, but you can change the 4ms in the waitcnt line (last line). Now it is 1s / 250 = 4ms.
    If you really need only 16 steps this would be easy, as long at it's linear you don't need a table.

    I have edited the code again, the line:
    puls[noparse][[/noparse]note] := vel 'write to puls array
    was not indented correctly

    As for different puls scales for different notes and non linear tables, these is all possible, but I think first must the simple version work.

    Andy
  • Fenta7Fenta7 Posts: 8
    edited 2010-07-19 02:19
    Andy,

    Thank you. I will start working on this week.

    Brad
  • Fenta7Fenta7 Posts: 8
    edited 2010-07-23 02:49
    Andy,

    This works great. I can't thank you enough.

    Brad
  • AribaAriba Posts: 2,690
    edited 2010-07-23 04:51
    Glad to hear smile.gif
  • Fenta7Fenta7 Posts: 8
    edited 2010-07-23 12:48
    The only problem it that it is not polyphonic, which means that when I hit two notes on the keyboard at the same time only one of the note signals gets through. This would be nice if it was polyphonic, but other than that it is really nice. Thank you

    Brad
  • AribaAriba Posts: 2,690
    edited 2010-07-23 17:39
    It should be polyphonic. Perhaps your keyboard uses "running status" then the status byte is not sent, if it's the same as for the previous Midi event.

    Try to replace the Main methode with this code:
    PUB Main  | status, note, vel, d
      midi.start(31,30,0,31250)                       'MIDI input on P31
      cognew(pulsout,@stack)                          'start 2nd Cog for pulses
    
      repeat
        d := midi.rx
        if d > $7F
          status := d
        if status == $90+CHANNEL                      'Note On? (on right channel)
          if d > $7F
            note := midi.rx
          else
            note := d
          vel := midi.rx
          if vel > 0                                  'no NoteOff?
            note -= FIRST_NOTE
            if note => 0 and note < NOTES             'in range?
              puls[noparse][[/noparse]note] := vel                       'write to puls array
    
    



    Andy
  • Fenta7Fenta7 Posts: 8
    edited 2010-07-23 19:58
    Andy

    Thank you very much. I will try it this weekend.

    Brad
Sign In or Register to comment.