Shop OBEX P1 Docs P2 Docs Learn Events
MIDI In with Basic Stamp II (drumbot) — Parallax Forums

MIDI In with Basic Stamp II (drumbot)

Tom2.0Tom2.0 Posts: 2
edited 2007-05-29 23:54 in BASIC Stamp
I'm making an automated drum machine for my senior design project and so far I have it set up to simply play off a loop of high/low commands programmed onto the stamp...

http://vids.myspace.com/index.cfm?fuseaction=vids.individual&videoid=2025416436

I want it to be able to read from a midi file (each drum component can be on a separate channel) and play the drums accordingly. ·I'm trying to use the m-audio Uno USB to MIDI cable, which has an LED that seems to trigger in concordance with beats on midi files, but I'm having trouble translating that to my solenoids.

Here's my questions:
1) Can I simply stick wires into the female MIDI (5 pin DIN) port when connecting it to my optoisolator circuit or is there some barrier·there that I'm not seeing?
2) I'm new to BASIC and found some code online and altered it to this...
snare   con     1 
bass    con     2 
hihat   con     3 
crash   con     4 
midiString var byte(3) 
 
main: 
serin 8, 12, [noparse][[/noparse]midiString] 
if midiString(0) = 144 then pos1 
if midiString(0) = 145 then pos2 
if midiString(0) = 146 then pos3 
if midiString(0) = 147 then pos4 
goto main 
 
pos1: 
high snare 
pause 10 
low snare 
goto main 
pos2: 
high bass 
pause 10 
low bass 
goto main 
pos3: 
high hihat 
pause 10 
low hihat 
goto main 
pos4: 
high crash 
pause 10 
low crash 
goto main



it seems to make sense...for all I know. ·However, this isn't working for me...should it?

I can't wait to get all this working and throw some LED rope lights onto my drums (connected in the solenoid firing circuit) and rock out in a calculated and efficient manner.

any help would be great. ·Thanks.
-Tom

Comments

  • TechnoRobboTechnoRobbo Posts: 323
    edited 2007-05-06 17:43
    Try reading 2 bytes instead of 3 (command and note message) - midi's baud rate is rather high for the stamp to react.

    A few other points:

    Midi uses channel 10 as the drum but you're using different channels for different drum sounds.

    For instance channel 10 note 36 ($99,·$24)·is the kick and channel 10 note 38 ($99,·$26) is a snare.

    Polyphony is almost out of the question (stamp has no buffer). your going to have to use notes representing multiple drum hits such as 39=high hat +Kick

    All that being said can you post your circuit for the optocoupled midi input so we can review it?

    Here's one design

    http://www.troikaranch.org/misc/midi_schem.gif



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Have Fun


    TR

    Post Edited (TechnoRobbo) : 5/6/2007 10:23:16 PM GMT
  • hitswarehitsware Posts: 156
    edited 2007-05-07 00:09
    >midi's baud rate is rather high for the stamp to react.

    32 kHz right ?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-07 01:26
    31.25 kbps is the baud rate for MIDI.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • hitswarehitsware Posts: 156
    edited 2007-05-07 12:43
    >Polyphony is almost out of the question (stamp has no buffer). your going to have to use notes representing multiple drum hits such as 39=high hat +Kick

    I think you could use the serin, then convert the midi to binary and use the parallel out commands for polyphony.
    I.E.
    0001 cymbal
    0010 snare
    0100 kick
    1000 tom
    1111 all
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2007-05-08 00:09
    Since Tom 2.0's serin command used a Baud Mode of 12 this tells me he is using a·BS2, BS2e, or BS2pe. Not a propeller. I wouldn't even begin to give him the impression that polyphony is possible with the BS2 and a midi data stream. At 31,250 baud and 1 stop bit, the stamp is very unreliable. This baud rate is non-negotiable.

    To quote Tracey Allens indispensible website (http://www.emesystems.com/BS2rs232.htm#SERIN):
    There is no trouble when sending from stamp to stamp, because of the extra padding on the serout end. But when serin has to receive the data at 9600 or above from a device that sends the 9600 full tilt, with only one stop bit and no extra, the data may come out jumbled, or the instruction may lock up.

    Polyphony would require the Stamp to receive the following datastream for the cymbal/snare/kick/tom combo which comes at the stamp at random times (no handshaking no requests):

    Note on events

    $99,$31,$7F,$99,$26,$7F,$99,$28,$7F,$99,$2B,$7F

    follow by note off events

    $89,$31,$00,$89,$26,$00,$89,$28,$00,$89,$2B,$00

    That's 24 bytes - 12 per polyphonic·event. BS2 has 26 bytes.

    Tom's only hope with MIDI is to send a single event and hope he captures the note byte or (like his code implies)·use the channel number as the drum number.

    The way I see it. His best bet though is to use DATA and READ statments to create a Piano Roll type drum machine, load drum patterns·into EEPROM·memory from the debug port and ditch the midi file idea.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Have Fun


    TR
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2007-05-17 01:11
    Sorry this took so long and I hope you have Microsoft Excel. Here's a spreadsheet I wrote that will break down a MIDI file and play the individual tracks (Load a file - click on "Track1 and press play).

    You can easily substitute the midiOutShortMsg command with a serout (MSComm1.Output = x)command and send the stamp 1 byte concatenating 8 instruments for up to 8 solenoids to be fired by the stamp simultaneously. This should solve most timing issues.

    This is the file:

    http://home.comcast.net/~technorobbo/MIDI.xls

    and here's a website to get test files from.

    http://www.mididrumfiles.com/free/

    I hope this helps and I hope I'm not too late for you to finish your project.


    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Have Fun


    TR

    Post Edited (TechnoRobbo) : 5/18/2007 10:54:16 AM GMT
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2007-05-20 02:04
    Here's the fully ported version for BS2 8 Bit output to solenoid.
    Assign bits to drums on the CommSettings Tab
    Baud Rate and Comm Port too.

    http://home.comcast.net/~technorobbo/MIDItoBS2.xls

    Here's the BS2 Code:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    'MIDI to BS2
    MIDI· VAR Byte
    CRT· VAR Byte
    DIRL=255

    DO
    · SERIN 16, 16780, [noparse][[/noparse]MIDI] '2400 Baud
    · OUTL =MIDI
    · PAUSE·10
    · MIDI =0
    · OUTL =MIDI
    LOOP
    END

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Have Fun


    TR

    Post Edited (TechnoRobbo) : 5/20/2007 8:50:49 PM GMT
  • Tom2.0Tom2.0 Posts: 2
    edited 2007-05-29 00:35
    sorry to everybody else...but TechnoRobbo is the smartest man in the world.· Robbo, the code worked perfectly and does everything I needed it to do; I'm naming the robot after you (either that or Max Weinborg).· We'll be demo-ing soon and it is guaranteed to be a hit.

    thanks for all the help,
    Tom
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2007-05-29 23:54
    No prob and Max sounds better.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Have Fun


    TR
Sign In or Register to comment.