electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
Hex Synth
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [1 Post]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 371
G2 patch files: 100

PostPosted: Wed Mar 13, 2013 12:37 pm    Post subject: Hex Synth
Subject description: For playing around with guitar hex -> MIDI
Reply with quote  Mark this post and the followings unread

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;



hexsynth.ck
 Description:

Download
 Filename:  hexsynth.ck
 Filesize:  2.33 KB
 Downloaded:  228 Time(s)


_________________
Antimon's Window
@soundcloud @Flattr home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [1 Post]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use