Skip to content

Commit

Permalink
added presets to Tone engine, added sub-oscillator
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisppaul committed Dec 6, 2024
1 parent 732f317 commit 4b5ad39
Show file tree
Hide file tree
Showing 47 changed files with 1,040 additions and 519 deletions.
Binary file modified lib/wellen.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import wellen.*;
import wellen.dsp.*;

/*
* this example demonstrates how to play *musical notes*.
* this example demonstrates how to play *musical notes*. notes are played when mouse
* is pressed. keys 1–4 change the presets.
*/
void settings() {
size(640, 480);
Expand All @@ -15,9 +16,22 @@ void draw() {
ellipse(width * 0.5f, height * 0.5f, Tone.is_playing() ? 100 : 5, Tone.is_playing() ? 100 : 5);
}
void mousePressed() {
int mNote = 45 + (int) random(0, 12);
Tone.note_on(mNote, 100);
Tone.note_on(Note.NOTE_C3, 100);
}
void mouseReleased() {
Tone.note_off();
}
void keyPressed() {
if (key == '1') {
Tone.preset(Wellen.INSTRUMENT_PRESET_SIMPLE);
}
if (key == '2') {
Tone.preset(Wellen.INSTRUMENT_PRESET_SUB_SINE);
}
if (key == '3') {
Tone.preset(Wellen.INSTRUMENT_PRESET_FAT);
}
if (key == '4') {
Tone.preset(Wellen.INSTRUMENT_PRESET_NOISE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,32 @@ import wellen.dsp.*;
* this example demonstrates how to use *musical scales*. a selection of predefined scales is available in `Scale`,
* however custom scales can also be created.
*/
int mNote;
int mNote;
int[] mScale;
int mStep;
int mStep;
void settings() {
size(640, 480);
}
void setup() {
mScale = Scale.HALF_TONE;
mNote = Note.NOTE_C4;
Tone.preset(Wellen.INSTRUMENT_PRESET_SUB_SINE);
mScale = Scale.CHORD_MINOR_7TH;
mNote = Note.NOTE_C4;
fill(0);
}
void draw() {
background(255);
float mDiameter = map(mNote, Note.NOTE_C4, Note.NOTE_C5, height * 0.1f, height * 0.8f);
float mDiameter = map(mNote, Note.NOTE_C3, Note.NOTE_C4, height * 0.1f, height * 0.8f);
ellipse(width * 0.5f, height * 0.5f, mDiameter, mDiameter);
}
void keyPressed() {
if (key == ' ') {
mStep++;
mStep %= mScale.length + 1;
mNote = Scale.get_note(mScale, Note.NOTE_C4, mStep);
mNote = Scale.get_note(mScale, Note.NOTE_C3, mStep);
/*
* note that this variant of `note_on` takes three parameters where the third parameter defines the
* duration of the note in seconds. a `note_off` is automatically triggered after the duration.
*/
Tone.note_on(mNote, 100, 0.25f);
}
if (key == '1') {
Expand All @@ -35,6 +40,17 @@ void keyPressed() {
mScale = Scale.CHORD_MINOR_7TH;
}
if (key == '3') {
mScale = Scale.MINOR_PENTATONIC;
}
if (key == '4') {
mScale = new int[]{0, 2, 3, 6, 7, 8, 11}; // Nawa Athar
}
}
// Try retrieving the native window ID
long windowID = Native.getWindowID(frame);
System.out.println("Native Window ID: " + windowID);
if (windowID == 0) {
throw new IllegalStateException("Failed to retrieve native window ID.");
}
PApplet.main(ExampleBasics02Scales.class.getName());
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@ import wellen.dsp.*;
* this example demonstrates how to use a *beat*. once started the method `beat(int)` is called at a speed defined
* in *beats per minute* (bpm) ( i.e quarter notes per minute ).
*/
int mBeatCount;
final int[] mNotes = {Note.NOTE_C3, Note.NOTE_C4, Note.NOTE_A2, Note.NOTE_A3};
int mBeatCount;
/* define a bass line of 8 notes */
final int[] mNotes = {Note.NOTE_C3, Note.NOTE_C4,
Note.NOTE_A2, Note.NOTE_A3,
Note.NOTE_C3 + 3, Note.NOTE_C4 + 3,
Note.NOTE_C3 + 2, Note.NOTE_C4 + 2};
void settings() {
size(640, 480);
}
void setup() {
noStroke();
fill(0);
Tone.preset(Wellen.INSTRUMENT_PRESET_FAT);
/* it is advised to start the beat at the very end of the `setup` method */
Beat.start(this, 120);
Beat.start(this, 160);
}
void draw() {
background(255);
noStroke();
fill(0);
float mScale = (mBeatCount % 2) * 0.25f + 0.25f;
ellipse(width * 0.5f, height * 0.5f, width * mScale, width * mScale);
}
void beat(int beatCount) {
mBeatCount = beatCount;
int mNote = mNotes[mBeatCount % mNotes.length];
Tone.note_on(mNote, 100);
int mNote = mNotes[mBeatCount % mNotes.length]; /* loop through notes */
Tone.note_on(mNote, 100, 0.25f);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ void settings() {
size(640, 480);
}
void setup() {
Tone.preset(Wellen.INSTRUMENT_PRESET_SIMPLE);
}
void draw() {
background(255);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ import wellen.dsp.*;
* this example demonstrates how to use a beat triggered by an external MIDI beat clock ( e.g generated by an
* external MIDI device or an internal MIDI application ).
*/
/*
* steps to enable MIDI clock in ableton live:
*
* 1. connect your MIDI device:
* - ensure your MIDI interface or hardware device is connected to your computer.
* 2. open ableton live preferences:
* - go to `Live > Settings…` (macOS) or `Options > Preferences` (Windows).
* - navigate to `Link/Tempo/MIDI` tab.
* 3. set up MIDI clock output:
* - in the `MIDI Ports` section, locate the output port for your connected MIDI device.
* - enable `Sync` for the relevant output port.
* 4. activate MIDI clock:
* - close the preferences window.
* - ensure `Options > External Sync` it is toggled off.
* 5. start playback:
* - hit play in ableton live, and the MIDI clock will start transmitting, syncing any connected hardware or software.
*/
BeatMIDI mBeatMIDI;
int mColor;
void settings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ import wellen.dsp.*;
*
* note that this functionality is not implemented for MIDI and OSC.
*/
boolean mEnableAmplitudeLFO = false;
boolean mEnableFrequencyLFO = false;
boolean mEnableAmplitudeLFO = false;
boolean mEnableFrequencyLFO = true;
boolean mToggleLFOParameterSelect = true;
void settings() {
size(640, 480);
}
void setup() {
Tone.start();
Tone.instrument().set_frequency_LFO_amplitude(2.0f);
Tone.instrument().set_frequency_LFO_frequency(11.0f);
Tone.instrument().enable_frequency_LFO(true);
}
void draw() {
background(255);
Expand All @@ -40,9 +43,13 @@ void mouseDragged() {
if (mToggleLFOParameterSelect) {
Tone.instrument().set_frequency_LFO_amplitude(map(mouseY, 0, height, 0.0f, 50.0f));
Tone.instrument().set_frequency_LFO_frequency(map(mouseX, 0, width, 0.0f, 50.0f));
println("LFO_amplitude: " + Tone.instrument().get_frequency_LFO_amplitude());
println("LFO_frequency: " + Tone.instrument().get_frequency_LFO_frequency());
} else {
Tone.instrument().set_amplitude_LFO_amplitude(map(mouseY, 0, height, 0.0f, 1.0f));
Tone.instrument().set_amplitude_LFO_frequency(map(mouseX, 0, width, 0.0f, 50.0f));
println("LFO_amplitude: " + Tone.instrument().get_amplitude_LFO_amplitude());
println("LFO_frequency: " + Tone.instrument().get_amplitude_LFO_frequency());
}
}
void keyPressed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ static class CustomInstrumentDetunedOscillatorsStereo extends InstrumentDSP {
CustomInstrumentDetunedOscillatorsStereo(int pID) {
super(pID);
set_channels(2);
set_detune(0.01f);
this.set_sub_ratio(0.01f);
set_spread(0.5f);
Wavetable.fill(fVCO.get_wavetable(), Wellen.WAVEFORM_SINE);
mVCOSecond = new Wavetable(DEFAULT_WAVETABLE_SIZE);
mVCOSecond.set_interpolation(Wellen.WAVESHAPE_INTERPOLATE_LINEAR);
Wavetable.fill(mVCOSecond.get_wavetable(), Wellen.WAVEFORM_SINE);
}
float get_detune() {
float get_sub_ratio() {
return mDetune;
}
void set_detune(float pDetune) {
mDetune = pDetune;
void set_sub_ratio(float frequency_ratio) {
mDetune = frequency_ratio;
}
float get_spread() {
return mSpread;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,18 @@ static class CustomInstrumentDetunedOscillatorsStereo extends InstrumentDSP {
CustomInstrumentDetunedOscillatorsStereo(int pID) {
super(pID);
set_channels(2);
set_detune(0.01f);
this.set_sub_ratio(0.01f);
set_spread(0.5f);
Wavetable.fill(fVCO.get_wavetable(), Wellen.WAVEFORM_TRIANGLE);
mVCOSecond = new Wavetable(DEFAULT_WAVETABLE_SIZE);
mVCOSecond.set_interpolation(Wellen.WAVESHAPE_INTERPOLATE_LINEAR);
Wavetable.fill(mVCOSecond.get_wavetable(), Wellen.WAVEFORM_TRIANGLE);
}
float get_detune() {
float get_sub_ratio() {
return mDetune;
}
void set_detune(float pDetune) {
mDetune = pDetune;
void set_sub_ratio(float frequency_ratio) {
mDetune = frequency_ratio;
}
float get_spread() {
return mSpread;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ void settings() {
}
void setup() {
Tone.instrument(0).set_oscillator_type(Wellen.WAVEFORM_SAWTOOTH);
Tone.instrument(0).enable_detune(true);
Tone.instrument(0).set_detune(1.02f);
Tone.instrument(0).set_detune_amplitude(0.8f);
Tone.instrument(0).set_detune_oscillator_type(Wellen.WAVEFORM_SAWTOOTH);
Tone.instrument(0).enable_sub_oscillator(true);
Tone.instrument(0).set_sub_ratio(1.02f);
Tone.instrument(0).set_sub_amplitude(0.8f);
Tone.instrument(0).set_sub_oscillator_type(Wellen.WAVEFORM_SAWTOOTH);
}
void draw() {
background(255);
Expand All @@ -28,26 +28,27 @@ void mouseReleased() {
Tone.note_off();
}
void mouseDragged() {
Tone.instrument(0).set_detune_amplitude(map(mouseX, 0, width, 0.1f, 1.0f));
Tone.instrument(0).set_detune(map(mouseY, 0, height, 0.9f, 1.1f));
Tone.instrument(0).set_sub_amplitude(map(mouseX, 0, width, 0.1f, 1.0f));
Tone.instrument(0).set_sub_ratio(map(mouseY, 0, height, 0.1f, 2.1f));
}
void keyPressed() {
Tone.instrument(0).set_detune_amplitude(0.8f);
switch (key) {
case '1':
Tone.instrument(0).set_detune(1.0f); // no detune
Tone.instrument(0).set_sub_ratio(1.0f); // no detune
break;
case '2':
Tone.instrument(0).set_detune(1.25f); // Große Terz
Tone.instrument(0).set_sub_ratio(1.25f); // Große Terz
break;
case '3':
Tone.instrument(0).set_detune(1.33f); // Quarte
Tone.instrument(0).set_sub_ratio(1.33f); // Quarte
break;
case '4':
Tone.instrument(0).set_detune(1.5f); // Quinte
Tone.instrument(0).set_sub_ratio(1.5f); // Quinte
break;
case '5':
Tone.instrument(0).set_detune(2.0f); // Oktave
Tone.instrument(0).set_sub_ratio(2.0f); // Oktave
break;
default:
Tone.instrument(0).set_sub_amplitude(0.8f);
}
}
Binary file modified processing-library/wellen/library/wellen.jar
Binary file not shown.
Loading

0 comments on commit 4b5ad39

Please sign in to comment.