From a558998efcb5e007776dad64d9ec50cb727bd82b Mon Sep 17 00:00:00 2001 From: Jakob Bak Date: Sat, 25 Aug 2012 17:24:03 +0200 Subject: [PATCH] Moved arduino code to new Arduino folder under software and created a processing fodler as well with the IACMidi2Serial sketch --- .DS_Store | Bin 6148 -> 6148 bytes Software/{ => Arduino}/CFO/.DS_Store | Bin Software/{ => Arduino}/CFO/CFOMidi.h | 0 Software/{ => Arduino}/CFO/CFOMusic.cpp | 0 Software/{ => Arduino}/CFO/CFOMusic.h | 0 Software/{ => Arduino}/CFO/CFOWavetable.h | 0 Software/{ => Arduino}/CFO/CFOmidi.cpp | 0 .../Example code/Basic_MIDI/Basic_MIDI.ino | 0 .../MUSIC_LIBRARY_DOCUMENTATION.ino | 0 .../Example code/Minimal/Minimal.ino | 0 .../Repeating_note_with_envelope.ino | 0 .../Spaghetti_tones/Spaghetti_tones.ino | 0 .../Example code/Up_and_down/Up_and_down.ino | 0 .../sketch_jun26c/sketch_jun26c.ino | 0 .../Up_and_down__square.ino | 0 Software/Arduino/README | 9 ++ .../IACMidi2Serial/IACMidi2Serial.pde | 142 ++++++++++++++++++ Software/README | 12 +- 18 files changed, 160 insertions(+), 3 deletions(-) rename Software/{ => Arduino}/CFO/.DS_Store (100%) rename Software/{ => Arduino}/CFO/CFOMidi.h (100%) rename Software/{ => Arduino}/CFO/CFOMusic.cpp (100%) rename Software/{ => Arduino}/CFO/CFOMusic.h (100%) rename Software/{ => Arduino}/CFO/CFOWavetable.h (100%) rename Software/{ => Arduino}/CFO/CFOmidi.cpp (100%) rename Software/{ => Arduino}/Example code/Basic_MIDI/Basic_MIDI.ino (100%) rename Software/{ => Arduino}/Example code/MUSIC_LIBRARY_DOCUMENTATION/MUSIC_LIBRARY_DOCUMENTATION.ino (100%) rename Software/{ => Arduino}/Example code/Minimal/Minimal.ino (100%) rename Software/{ => Arduino}/Example code/Repeating_note_with_envelope/Repeating_note_with_envelope.ino (100%) rename Software/{ => Arduino}/Example code/Spaghetti_tones/Spaghetti_tones.ino (100%) rename Software/{ => Arduino}/Example code/Up_and_down/Up_and_down.ino (100%) rename Software/{ => Arduino}/Example code/Up_and_down/sketch_jun26c/sketch_jun26c.ino (100%) rename Software/{ => Arduino}/Example code/Up_and_down__square/Up_and_down__square.ino (100%) create mode 100644 Software/Arduino/README create mode 100644 Software/Processing/IACMidi2Serial/IACMidi2Serial.pde diff --git a/.DS_Store b/.DS_Store index 5b7b9747a153d09f0495aed02b0cd7e24f25792e..ed2944b15b256607d9c2c806b4b7421086a33790 100644 GIT binary patch delta 57 zcmZoMXffE}!Njf}!c;?M$+)HMMp14U=y&$ul-h{>db>S&{h} N%ftrW&Fmb1`2iEf6A1tS delta 84 zcmZoMXffE}!Nj;>vL{oru4Hw!nW?dkf}ycNt&T#qp@EsXj)J*?S#2#RCkLm%0S-|m oJsXdZ#M-+0hQ`S^nB*CoC;woQVPxE_$o!0DVgvVPc8 0) { + //int val = port0.read(); + //float val = float(port0.read()); + int val = port0.read(); + println(val); + } + + +} + +void keyPressed() { + + if(key=='b' || key=='B') { + sendNoteOn(byte(defaultMidiChannel), (byte)36, (byte)0x7F); + } + if(key=='s' || key=='S') { + sendNoteOn(byte(defaultMidiChannel), (byte)38, (byte)0x7F); + } + if(key=='i' || key=='I') { + sendNoteOn(byte(defaultMidiChannel), (byte)42, (byte)0x7F); + } + if(key=='o' || key=='O') { + sendNoteOn(byte(defaultMidiChannel), (byte)44, (byte)0x7F); + } + +} + +void keyReleased() { + + if(key=='b' || key=='B') { + sendNoteOff(byte(defaultMidiChannel), (byte)0x00, (byte)0x7F); + } + if(key=='s' || key=='S') { + sendNoteOff(byte(defaultMidiChannel), (byte)0x01, (byte)0x7F); + } + if(key=='i' || key=='I') { + sendNoteOff(byte(defaultMidiChannel), (byte)0x02, (byte)0x7F); + } + if(key=='o' || key=='O') { + sendNoteOff(byte(defaultMidiChannel), (byte)0x03, (byte)0x7F); + } +} + +void noteOnReceived(Note note) { + + byte channel = byte(note.getChannel()); + byte pitch = byte(note.getPitch()); + byte velocity = byte(note.getVelocity()); + + sendNoteOn(channel, pitch, velocity); + +} + +void noteOffReceived(Note note) { + + byte channel = byte(note.getChannel()); + byte pitch = byte(note.getPitch()); + byte velocity = byte(note.getVelocity()); + + sendNoteOff(channel, pitch, velocity); + +} + +void controllerChangeReceived(Controller controller) { + + byte channel = byte(controller.getChannel()); + byte CC = byte(controller.getCC()); + byte value = byte(controller.getValue()); + + sendControlChange(channel, CC, value); +} + +void sendNoteOn(byte channel, byte pitch, byte velocity) { + + byte noteOn = byte(0x90 | channel); + byte endMessage = byte(0xFF); // not standard midi!!!! + + port0.write(noteOn); + port0.write(pitch); + port0.write(velocity); + port0.write(endMessage); + println('\n' + hex(noteOn) + " " + hex(pitch) + " " + hex(velocity) + " " + hex(endMessage)); + +} + +void sendNoteOff(byte channel, byte pitch, byte velocity) { + + byte noteOff = byte(0x80 | channel); + byte endMessage = byte(0xFF); // not standard midi!!!! + + port0.write(noteOff); + port0.write(pitch); + port0.write(velocity); + port0.write(endMessage); + println('\n' + hex(noteOff) + " " + hex(pitch) + " " + hex(velocity) + " " + hex(endMessage)); + +} + +void sendControlChange(byte channel, byte CC, byte value) { + + byte controlChange = byte(0xB0 | channel); + byte endMessage = byte(0xFF); // Not standard MIDI!!!! + + port0.write(controlChange); + port0.write(CC); + port0.write(value); + port0.write(endMessage); + println('\n' + hex(controlChange) + " " + hex(CC) + " " + hex(value) + " " + hex(endMessage)); + +} diff --git a/Software/README b/Software/README index 6a7eb77..b59924a 100644 --- a/Software/README +++ b/Software/README @@ -1,9 +1,15 @@ -CFO Music and MIDI library +Libraries and sketches for using and running the CFO synth and MIDI library for Arduino. Work in progress -Copy whole CFO folder to your "libraries" folder in your Arduino sketch folder. +From the Arduino folder here, copy whole CFO folder to your "libraries" folder in your Arduino sketch folder. +(on Mac it's typically ~/Documents/Arduino/Libraries/) -See example code in examples folder for utilizing the library. +See example code in the Arduino/examples folder for utilizing the library. + +In order to use MIDI you should use the IACMidi2Serial sketch in the processing folder (To get this to run you need to install Ruin & Wesen's MIDI library for processing. Look for RWMidi here: http://ruinwesen.com/files). + +Once the sketch is running you should be able to send note and controller messages from your DAW of choice to the IAC MIDI driver. The IACMidi2Serial sketch only listens to port 1 (the first instance of the IAC driver) but you can modify that in the sketch yourself. +The sketch then sends that MIDI data (slightly formatted) to the serial port which the (mini)CFO will read and act upon :) I am not 100% everything will work with the insects yet, but we'll see soon enough. \ No newline at end of file