Antimon
Joined: Jan 18, 2005 Posts: 4145 Location: Sweden
Audio files: 371
G2 patch files: 100
|
Posted: Wed Mar 13, 2013 12:37 pm Post subject:
Hex Synth Subject description: For playing around with guitar hex -> MIDI |
|
|
I've been meaning to do this for some time, finally got around to it. Others have probably done this already.
Anyway, this is a synth that sets up six voices that listens to midi channel 1, 2, 3, 4, 5, and 6 respectively. The idea is to hook this up to something like a Roland VG99 sending MIDI data over six channels, or some other device that translates guitar hex pickup data to MIDI, with one channel for each string.
Have a look at the HexVoice class - you can replace the BlitSaw setup with whatever you want to make your sound. If the Envelope solution doesn't work for you (like if you want to use ChucK's STK instruments or some more advanced construction), the noteOn() and noteOff() methods are called whenever something happens for that voice.
You will probably want to change the MIDI_DEVICE constant to whatever device you get your MIDI from (run chuck --probe to see what ids your MIDI devices have).
If you don't want to use MIDI channels starting at 1, change BASE_CHANNEL to whatever number you want to start at (it's zero-based, so if you want to start at MIDI channel #3 you set 2 => BASE_CHANNEL )
If you try it out and wonder about something or just want to give a shout, write a comment here in the thread!
Code: |
// Hex Synth by Stefan Blixt
// Synth setup to be used with a guitar hex pickup/MIDI converter.
// It receives MIDI note messages on six different channels.
// One voice is assigned to each channel respectively.
// Run chuck --probe to see what MIDI device number to put here
4 => int MIDI_DEVICE;
// Hex Synth will listen to midi channels BASE_CHANNEL, BASE_CHANNEL+1, BASE_CHANNEĆ+2, ... , BASE_CHANNEL+5
// So for BASE_CHANNEL == 0, the midi channels will be 0, 1, 2, 3, 4, 5
0 => int BASE_CHANNEL;
Gain mixer => dac;
class HexVoice {
// Put your sound-making stuff here, and route it to mixer
BlitSaw osc => Envelope env => mixer;
0.1 => osc.gain;
5 => osc.harmonics;
int channel;
// This gets called whenever a note on is received for the channel assigned to this voice
fun void noteOn(int note, int velocity) {
<<< "Channel ", channel, note >>>;
Std.mtof( note + 12 ) => osc.freq;
env.keyOn();
}
// This gets called whenever a note off is received for the channel assigned to this voice
fun void noteOff() {
env.keyOff();
}
// this will be called if control messages are received on this channel
fun void controlMessage(int control, int value) {
}
}
HexVoice voices[6];
MidiIn midiIn;
fun void setup() {
for (0 => int i; i <voices> voices[i].channel;
}
if (midiIn.open(MIDI_DEVICE)) {
<<< "Opened device: ", midiIn.name() >>>;
} else {
<<< "Couldn't open device #", MIDI_DEVICE >>>;
}
}
fun HexVoice getVoice(int channel) {
for (0 => int i; i <voices> now;
while (midiIn.recv(midiMsg)) {
// <<< "Received midi: ", midiMsg.data1, midiMsg.data2, midiMsg.data3 >>>;
(midiMsg.data1 & 0xf0) / 16 => int message;
midiMsg.data1 & 0x0f => int channel;
getVoice(channel) @=> HexVoice @ voice;
if (voice != null) {
if (message == 0x0b) {
voice.controlMessage(midiMsg.data2, midiMsg.data3);
} else if (message == 0x09) {
midiMsg.data3 => int velocity;
if (velocity == 0) {
voice.noteOff();
} else {
voice.noteOn(midiMsg.data2, velocity);
}
} else if (message == 0x08) {
voice.noteOff();
}
}
}
}
}
setup();
spork ~ listener();
1::week => now;
|
Description: |
|
Download |
Filename: |
hexsynth.ck |
Filesize: |
2.33 KB |
Downloaded: |
228 Time(s) |
_________________ Antimon's Window
@soundcloud @Flattr home - you can't explain music |
|