We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey! So I have been trying to code a polyphonic synthesizer that is controlled by a MIDI keyboard using themidibus library and beads. I found this code that supposedly calls new Waveplayer files every time a note is played so that multiple sounds are outputted, but whenever I try to run this code, I get the error:
"AudioContext : no AudioIO specified, using default => beads.JavaSoundAudioIO. JavaSoundAudioIO: Chosen mixer is Default Audio Device. "
It might be for something dumb, since I sort of don't know what I'm doing, but I'm fairly lost and am just wonder if anyone knows a way to make a polyphonic synthesizer thats controlled by a MIDI controller, before I invest a lot of time into trying to do this.
// MIDI_SYNTH_01.pde
// this example builds a simple midi synthesizer
// for each incoming midi note, we create a new set of beads
// (encapsulated by a class)
// these beads are stored in a vector
// and destroyed when we get a corresponding note-off message
// Import the MidiBus library
import themidibus.*;
// import the beads library
import beads.*;
// our parent MidiBus object
MidiBus busA;
AudioContext ac;
Gain MasterGain;
ArrayList synthNotes = null;
void setup()
{
size(600, 400);
background(0);
// the MidiBus constructor takes four arguments
// 1 - the calling program (this)
// 2 - the input device
// 3 - the output device
// 4 - the bus name
// in this case, we just use the defaults
busA = new MidiBus(this, 0, 0, "busA");
synthNotes = new ArrayList();
ac = new AudioContext();
MasterGain = new Gain(ac, 1, 0.5);
ac.out.addInput(MasterGain);
ac.start();
background(0);
text("This program will not do anything if you do not have a MIDI device", 100, 100);
text("connected to your computer.", 100, 112);
text("This program plays sine waves in response to Note-On messages.", 100, 124);
}
void draw()
{
for( int i = 0; i < synthNotes.size(); i++ )
{
SimpleSynth s = (SimpleSynth)synthNotes.get(i);
// if this bead has been killed
if( s.g.isDeleted() )
{
// destroy the synth (set things to null so that memory
// cleanup can occur)
s.destroy();
// then remove the parent synth
synthNotes.remove(s);
}
}
}
// respond to MIDI note-on messages
void noteOn(int channel, int pitch, int velocity, String bus_name) {
background(50);
stroke(255); fill(255);
text("Note On:", 100, 100);
text("Channel:" + channel, 100, 120);
text("Pitch:" + pitch, 100, 140);
text("Velocity:" + velocity, 100, 160);
text("Recieved on Bus:" + bus_name, 100, 180);
synthNotes.add(new SimpleSynth(pitch));
}
// respond to MIDI note-off messages
void noteOff(int channel, int pitch, int velocity, String bus_name){
background(0);
stroke(255); fill(255);
text("Note Off:", 100, 100);
text("Channel:" + channel, 100, 120);
text("Pitch:" + pitch, 100, 140);
text("Velocity:" + velocity, 100, 160);
text("Recieved on Bus:" + bus_name, 100, 180);
for( int i = 0; i < synthNotes.size(); i++ )
{
SimpleSynth s = (SimpleSynth)synthNotes.get(i);
if( s.pitch == pitch )
{
s.kill();
synthNotes.remove(s);
break;
}
}
}
// this is our simple synthesizer object
class SimpleSynth
{
public WavePlayer wp = null;
public Envelope e = null;
public Gain g = null;
public int pitch = -1;
// the constructor for our sine wave synthesizer
SimpleSynth(int midiPitch)
{
pitch = midiPitch;
// set up the new WavePlayer, convert the MidiPitch to a
// frequency
wp = new WavePlayer(ac,
440.0 * pow(2, ((float)midiPitch -
59.0)/12.0),
Buffer.SINE);
e = new Envelope(ac, 0.0);
g = new Gain(ac, 1, e);
g.addInput(wp);
MasterGain.addInput(g);
e.addSegment(0.5, 300);
}
// when this note is killed, ramp the amplitude down to 0
// over 300ms
public void kill()
{
e.addSegment(0.0, 300, new KillTrigger(g));
}
// destroy the component beads so that they can be cleaned
// up by the java virtual machine
public void destroy()
{
wp.kill();
e.kill();
g.kill();
wp = null;
e = null;
g = null;
}
}
Answers
busA = new MidiBus(this, 0, 0, "busA");
You've selected 0 for input and output device, this may be a reason why you're getting that error. useMidiBus.list()
to get the list of available devices and change constructor accordingly. You may want to refer to Javadoc as well.