I’m using the Wellen audio library to create sounds for my second ever Processing project, so apologies if this is an easy question - I’m still a novice programmer. The library was updated in January to include a small but useful selection of DSP instruments - such as InstrumentInternalLibrary.BELL - and I can’t figure out how to use these to play sounds. So if you are also using Wellen and know how to do this I’d be really grateful if you could share the code here. Thanks.
Hi,
Welcome to the forum!
I’ve never used the library myself but quoting the reference :
public class InstrumentInternalLibrary extends java.lang.Object
a collection of DSP instruments.
these instruments can be used to replace the default instrument ( i.e
InstrumentInternal
) e.g by using the methodTone.replace_instrument(InstrumentInternal)
.all instruments are extended from
InstrumentInternal
, however some the original functionality is extended, changed or even removed.note that these instruments only work with the internal tone engine. however, due to the modular nature of the library these instruments can also be integrated into
DSP
applications.
So taking the basic example from the examples folder :
package wellen.examples.basics;
import processing.core.PApplet;
import wellen.Tone;
// Import the required class
import wellen.InstrumentInternalLibrary;
public class ExampleBasics05Instruments extends PApplet {
/*
* this example demonstrates how to use *instruments* to play multiple notes at the same time.
*/
public void settings() {
size(640, 480);
}
public void setup() {
// Use the BELL instrument since it's a static class
Tone.replace_instrument(InstrumentInternalLibrary.BELL);
}
public void draw() {
background(255);
fill(0);
ellipse(width * 0.5f, height * 0.5f, Tone.is_playing() ? 100 : 5, Tone.is_playing() ? 100 : 5);
}
public void mousePressed() {
int mNote = 45 + (int) random(0, 12);
Tone.instrument(0);
Tone.instrument().set_pan(0.0f);
Tone.note_on(mNote, 80);
Tone.instrument(1);
Tone.instrument().set_pan(0.2f);
Tone.note_on(mNote + 7, 80);
Tone.instrument(2);
Tone.instrument().set_pan(-0.2f);
Tone.note_on(mNote - 5, 80);
}
public void mouseReleased() {
Tone.instrument(0);
Tone.note_off();
Tone.instrument(1);
Tone.note_off();
Tone.instrument(2);
Tone.note_off();
}
public static void main(String[] args) {
PApplet.main(ExampleBasics05Instruments.class.getName());
}
}
I didn’t tested this but it should work just by looking at the documentation.
Thanks josephh - I’d got pretty much as far as that myself looking at the examples, but using your code ran into the same error at setup() where it tells me “InstrumentInternalLibrary.BELL cannot be resolved to a variable”. Dennis P Paul, who created Wellen, is very active with updates so I’m hoping the next release will include more examples that explain these latest features!
Hi again,
My bad I think that it’s not the right import statement, rather use :
// To import all the static instrument classes (discouraged)
import wellen.InstrumentInternalLibrary.*;
// or
// To import only the BELL static class (preferable)
import wellen.InstrumentInternalLibrary.BELL;
Then use it :
Tone.replace_instrument(BELL);
Also if the author doesn’t provide not much information, feel free to send him a message or open an issue on the GitHub repo!
Hope it helps