Skip to content

Commit

Permalink
added instrument creation and replacing, added application for visual…
Browse files Browse the repository at this point in the history
… model, refined applications, updated lib + doc
  • Loading branch information
dennisppaul committed Nov 23, 2020
1 parent 5034b77 commit 4486d4a
Show file tree
Hide file tree
Showing 173 changed files with 11,203 additions and 1,617 deletions.
Binary file modified lib/ton.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,8 @@ void settings() {
}

void setup() {
background(255);
/* set ADSR parameters for current instrument */
Instrument mInstrument = Ton.instrument();
mInstrument.attack(0.01f);
mInstrument.decay(0.1f);
mInstrument.sustain(0.0f);
mInstrument.release(0.01f);
mInstrument.osc_type(Instrument.TRIANGLE);
Ton.instrument().osc_type(Instrument.TRIANGLE);
Beat.start(this, 120 * 4);
Ton.instrument().osc_type(Instrument.SAWTOOTH);
}

void draw() {
Expand All @@ -41,13 +33,13 @@ void beat(int pBeat) {
if (pBeat % 32 == 0) {
Ton.note_on(Note.NOTE_A4, 80);
} else if (pBeat % 8 == 0) {
Ton.note_on(Note.NOTE_A3, 100);
Ton.note_on(Note.NOTE_A3, 110);
} else if (pBeat % 2 == 0) {
Ton.note_on(Note.NOTE_A2 + (pBeat % 4) * 3, 120);
} else if (pBeat % 11 == 0) {
Ton.note_on(Note.NOTE_C4, 100);
Ton.note_on(Note.NOTE_C4, 90, 0.05f);
} else if (pBeat % 13 == 0) {
Ton.note_on(Note.NOTE_C5, 100);
Ton.note_on(Note.NOTE_C5, 100, 0.1f);
} else {
mPlaying = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void settings() {
}

void setup() {
noStroke();
mBeatA = BeatEvent.create(120);
mBeatB = BeatEvent.create(140);
mBeatC = BeatEvent.create(160);
Expand All @@ -35,7 +36,6 @@ void setup() {

void draw() {
background(255);
noStroke();
fill(0);
if (mLoopA.playing) {
ellipse(width * 0.25f, height * 0.5f, width * 0.15f, width * 0.15f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,117 @@ import netP5.*;
import oscP5.*;
import ddf.minim.*;
import com.jsyn.unitgen.*;
//@todo(record from mic)
//@todo(position circle)

final ArrayList<CircleController> mControllers = new ArrayList<CircleController>();

final int NUM_OF_CONTROLLERS = 1;

void settings() {
size(640, 480);
}

void setup() {
for (int i = 0; i < NUM_OF_CONTROLLERS; i++) {
CircleController c = new CircleController();
c.position.set(random(width), random(height));
c.radius = random(20, 120);
c.speed = random(0, 5);
mControllers.add(c);
}
DSP.dumpAudioDevices();
DSP.start(this);
}

void draw() {
background(255);
final float mDelta = 1.0f / frameRate;
noFill();
stroke(0);
DSP.draw_buffer(g, width, height);
for (CircleController c : mControllers) {
c.draw();
c.update(mDelta);
}
}

void mouseDragged() {
CircleController c = getCircleController();
if (c != null) {
c.position.set(mouseX, mouseY);
}
}

void keyPressed() {
CircleController c = getCircleController();
if (c != null) {
switch (key) {
case '+':
c.radius += 10;
break;
case '-':
c.radius -= 10;
c.radius = c.radius < 10 ? 10 : c.radius;
break;
case '.':
c.speed += 0.5f;
break;
case ',':
c.speed -= 0.5f;
break;
}
}
}

CircleController getCircleController() {
for (CircleController c : mControllers) {
if (PVector.dist(c.position, new PVector().set(mouseX, mouseY)) - 10 < c.radius) {
return c;
}
}
return null;
}

void audioblock(float[] pOutputSamples) {
for (int i = 0; i < pOutputSamples.length; i++) {
for (CircleController c : mControllers) {
pOutputSamples[i] += c.process();
}
pOutputSamples[i] /= mControllers.size();
pOutputSamples[i] = Ton.clamp(pOutputSamples[i], -1.0f, 1.0f);
}
}

class CircleController {
final PVector position = new PVector();
final PVector pointer = new PVector();
float radius = 100.0f;
float counter = 0.0f;
float speed = 3.0f;

final Sampler mSampler;
CircleController() {
byte[] mData = SampleDataSNARE.data;
mSampler = new Sampler();
mSampler.load(mData);
mSampler.loop(true);
mSampler.set_speed(1);
}
float process() {
return mSampler.process();
}
void update(float pDelta) {
counter += pDelta * speed;
pointer.x = sin(counter) * radius + position.x;
pointer.y = cos(counter) * radius + position.y;
mSampler.set_speed(map(pointer.x, 0, width, 0, 32));
mSampler.set_amplitude(map(pointer.y, 0, height, 0.0f, 0.9f));
}
void draw() {
noFill();
stroke(0);
ellipse(position.x, position.y, radius * 2, radius * 2);
noStroke();
fill(0);
ellipse(pointer.x, pointer.y, 10, 10);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import ddf.minim.*;
import com.jsyn.unitgen.*;

final String mInput = "RADIO, LIVE TRANSMISSION.\n" +
"RADIO, LIVE TRANSMISSION.\n" +
"LISTEN TO THE SILENCE, LET IT RING ON.\n" +
"EYES, DARK GREY LENSES FRIGHTENED OF THE SUN.\n" +
"WE WOULD HAVE A FINE TIME LIVING IN THE NIGHT,\n" +
"LEFT TO BLIND DESTRUCTION,\n" +
"WAITING FOR OUR SIGHT.";
"RADIO, LIVE TRANSMISSION.\n" +
"LISTEN TO THE SILENCE, LET IT RING ON.\n" +
"EYES, DARK GREY LENSES FRIGHTENED OF THE SUN.\n" +
"WE WOULD HAVE A FINE TIME LIVING IN THE NIGHT,\n" +
"LEFT TO BLIND DESTRUCTION,\n" +
"WAITING FOR OUR SIGHT.";

final int mBaseNote = Note.NOTE_C3;

Expand All @@ -35,9 +35,10 @@ void settings() {
}

void setup() {
Beat.start(this, 240);
textFont(createFont("Helvetica-Bold", 10));
Ton.instrument(1).osc_type(Instrument.TRIANGLE);
Ton.instrument(1).osc_type(Instrument.SAWTOOTH);
Ton.instrument(2).osc_type(Instrument.SINE);
Beat.start(this, 240);
}

void draw() {
Expand Down Expand Up @@ -65,7 +66,9 @@ void beat(int pBeatCount) {
Ton.note_off();
}
Ton.instrument(1);
Ton.note_on(Note.NOTE_C3, 75, 0.3f);
Ton.note_on(Note.NOTE_C2, 15, 0.05f);
Ton.instrument(2);
Ton.note_on(Note.NOTE_C2, 100, 0.15f);
}

void grammar(char c) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ static final int INSTRUMENT_FLUTE = 1;
static final int INSTRUMENT_NOISE = 2;

final int[] mBaseSequence = {0, O, X, 0,
X, X, 0, X,
X, 0, X, X,
7, O, X, 12};
X, X, 0, X,
X, 0, X, X,
7, O, X, 12};

float mTime;

Expand All @@ -30,8 +30,7 @@ void setup() {
Beat.start(this, 240);
Ton.instrument(INSTRUMENT_BASE).osc_type(Instrument.TRIANGLE);
Ton.instrument(INSTRUMENT_FLUTE).osc_type(Instrument.SAWTOOTH);
ArrayList<Instrument> m = (ArrayList<Instrument>) Ton.instruments();
m.set(INSTRUMENT_NOISE, new InstrumentJSynOscillator((ToneEngineJSyn) Ton.instance(), INSTRUMENT_NOISE));
Ton.replace_instrument(InstrumentJSynOscillator.class, INSTRUMENT_NOISE);
Ton.instrument(INSTRUMENT_NOISE).osc_type(Instrument.NOISE);
Ton.instrument(INSTRUMENT_NOISE).note_on(1, 127);
Ton.instrument(INSTRUMENT_NOISE).sustain(1.0f);
Expand All @@ -46,10 +45,18 @@ void draw() {

void beat(int pBeatCount) {
playBaseSequence(pBeatCount);
if (pBeatCount % 2 == 0) {
playMelody(pBeatCount / 2 - 1, 1.0f);
playMelodyWithEcho(pBeatCount);
}

void playMelodyWithEcho(int pBeatCount) {
if (pBeatCount % 4 == 0) {
playMelody(pBeatCount / 4, 1.0f);
} else if (pBeatCount % 4 == 1) {
playMelody(pBeatCount / 4, 0.5f);
} else if (pBeatCount % 4 == 2) {
playMelody(pBeatCount / 4, 0.25f);
} else {
playMelody(pBeatCount / 2, 0.33f);
playMelody(pBeatCount / 4, 0.125f);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.jsyn.unitgen.*;

final float mFreq = 220.0f;

AudioFormula mFormula = new AudioFormulaMouse();
AudioFormula mFormula = new MAudioFormulaAwayAndAway();

int mCounter = 0;

Expand Down Expand Up @@ -35,12 +35,9 @@ void draw() {
void keyPressed() {
switch (key) {
case '1':
mFormula = new AudioFormulaMouse();
break;
case '2':
mFormula = new AudioFormulaKnisterKnister();
break;
case '3':
case '2':
mFormula = new MAudioFormulaAwayAndAway();
break;
}
Expand All @@ -54,16 +51,6 @@ void audioblock(float[] pOutputSamples) {
interface AudioFormula {
float render(int pCounter);
}
class AudioFormulaMouse implements AudioFormula {

float render(int pCounter) {
float mFreqMouse = mFreq + map(mouseX, 0, width, 0, mFreq);
float mAmpMouse = map(mouseY, 0, height, 0, 0.75f);
float mSample = sin(2 * PI * mFreqMouse * pCounter / DSP.sample_rate());
mSample *= mAmpMouse;
return mSample;
}
}
class AudioFormulaKnisterKnister implements AudioFormula {

float render(int pCounter) {
Expand Down
Binary file modified processing-library/ton/library/ton.jar
Binary file not shown.
20 changes: 12 additions & 8 deletions processing-library/ton/reference/allclasses-frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@
<h1 class="bar">All&nbsp;Classes</h1>
<div class="indexContainer">
<ul>
<li><a href="de/hfkbremen/ton/applications/AppAlgorithmicCompositionLoops.html" title="class in de.hfkbremen.ton.applications" target="classFrame">AppAlgorithmicCompositionLoops</a></li>
<li><a href="de/hfkbremen/ton/applications/AppAlgorithmicCompositionModulo.html" title="class in de.hfkbremen.ton.applications" target="classFrame">AppAlgorithmicCompositionModulo</a></li>
<li><a href="de/hfkbremen/ton/applications/AppDSPFormulaGymnastics.html" title="class in de.hfkbremen.ton.applications" target="classFrame">AppDSPFormulaGymnastics</a></li>
<li><a href="de/hfkbremen/ton/applications/AppAlgorithmicComposition00Modulo.html" title="class in de.hfkbremen.ton.applications" target="classFrame">AppAlgorithmicComposition00Modulo</a></li>
<li><a href="de/hfkbremen/ton/applications/AppAlgorithmicComposition01Loops.html" title="class in de.hfkbremen.ton.applications" target="classFrame">AppAlgorithmicComposition01Loops</a></li>
<li><a href="de/hfkbremen/ton/applications/AppAlgorithmicComposition02VisualModel.html" title="class in de.hfkbremen.ton.applications" target="classFrame">AppAlgorithmicComposition02VisualModel</a></li>
<li><a href="de/hfkbremen/ton/applications/AppAlgorithmicComposition03Grammar.html" title="class in de.hfkbremen.ton.applications" target="classFrame">AppAlgorithmicComposition03Grammar</a></li>
<li><a href="de/hfkbremen/ton/applications/AppAlgorithmicComposition04FunctionSineWaves.html" title="class in de.hfkbremen.ton.applications" target="classFrame">AppAlgorithmicComposition04FunctionSineWaves</a></li>
<li><a href="de/hfkbremen/ton/applications/AppAlgorithmicComposition05FunctionDSPFormula.html" title="class in de.hfkbremen.ton.applications" target="classFrame">AppAlgorithmicComposition05FunctionDSPFormula</a></li>
<li><a href="de/hfkbremen/ton/applications/AppDSPwithJSynToneEngine.html" title="class in de.hfkbremen.ton.applications" target="classFrame">AppDSPwithJSynToneEngine</a></li>
<li><a href="de/hfkbremen/ton/applications/AppImageScannerSequencer.html" title="class in de.hfkbremen.ton.applications" target="classFrame">AppImageScannerSequencer</a></li>
<li><a href="de/hfkbremen/ton/applications/AppNeuralNetworkSequencer.html" title="class in de.hfkbremen.ton.applications" target="classFrame">AppNeuralNetworkSequencer</a></li>
<li><a href="de/hfkbremen/ton/applications/AppOscJibberish.html" title="class in de.hfkbremen.ton.applications" target="classFrame">AppOscJibberish</a></li>
<li><a href="de/hfkbremen/ton/applications/AppPercussiveSynth.html" title="class in de.hfkbremen.ton.applications" target="classFrame">AppPercussiveSynth</a></li>
<li><a href="de/hfkbremen/ton/applications/AppSequenceRecorder.html" title="class in de.hfkbremen.ton.applications" target="classFrame">AppSequenceRecorder</a></li>
<li><a href="de/hfkbremen/ton/applications/AppSixteenStepSequencer.html" title="class in de.hfkbremen.ton.applications" target="classFrame">AppSixteenStepSequencer</a></li>
<li><a href="de/hfkbremen/ton/applications/AppStepSequencerRandom.html" title="class in de.hfkbremen.ton.applications" target="classFrame">AppStepSequencerRandom</a></li>
<li><a href="de/hfkbremen/ton/Arpeggiator.html" title="class in de.hfkbremen.ton" target="classFrame">Arpeggiator</a></li>
<li><a href="de/hfkbremen/ton/AudioBufferManager.html" title="class in de.hfkbremen.ton" target="classFrame">AudioBufferManager</a></li>
<li><a href="de/hfkbremen/ton/AudioBufferRenderer.html" title="interface in de.hfkbremen.ton" target="classFrame"><span class="interfaceName">AudioBufferRenderer</span></a></li>
Expand All @@ -42,9 +44,9 @@ <h1 class="bar">All&nbsp;Classes</h1>
<li><a href="de/hfkbremen/ton/MidiIn.html" title="class in de.hfkbremen.ton" target="classFrame">MidiIn</a></li>
<li><a href="de/hfkbremen/ton/MidiInListener.html" title="interface in de.hfkbremen.ton" target="classFrame"><span class="interfaceName">MidiInListener</span></a></li>
<li><a href="de/hfkbremen/ton/MidiOut.html" title="class in de.hfkbremen.ton" target="classFrame">MidiOut</a></li>
<li><a href="de/hfkbremen/ton/MidiTimerNoteOffTask.html" title="class in de.hfkbremen.ton" target="classFrame">MidiTimerNoteOffTask</a></li>
<li><a href="de/hfkbremen/ton/MidiTimerNoteOnTask.html" title="class in de.hfkbremen.ton" target="classFrame">MidiTimerNoteOnTask</a></li>
<li><a href="de/hfkbremen/ton/Note.html" title="class in de.hfkbremen.ton" target="classFrame">Note</a></li>
<li><a href="de/hfkbremen/ton/SampleDataSNARE.html" title="interface in de.hfkbremen.ton" target="classFrame"><span class="interfaceName">SampleDataSNARE</span></a></li>
<li><a href="de/hfkbremen/ton/Sampler.html" title="class in de.hfkbremen.ton" target="classFrame">Sampler</a></li>
<li><a href="de/hfkbremen/ton/Scale.html" title="class in de.hfkbremen.ton" target="classFrame">Scale</a></li>
<li><a href="de/hfkbremen/ton/Sequencer.html" title="class in de.hfkbremen.ton" target="classFrame">Sequencer</a></li>
<li><a href="de/hfkbremen/ton/examples/SketchExampleBasics01Notes.html" title="class in de.hfkbremen.ton.examples" target="classFrame">SketchExampleBasics01Notes</a></li>
Expand All @@ -57,6 +59,7 @@ <h1 class="bar">All&nbsp;Classes</h1>
<li><a href="de/hfkbremen/ton/examples_ext/SketchExampleDSP03Echo.html" title="class in de.hfkbremen.ton.examples_ext" target="classFrame">SketchExampleDSP03Echo</a></li>
<li><a href="de/hfkbremen/ton/examples_ext/SketchExampleDSP04LowPassFilter.html" title="class in de.hfkbremen.ton.examples_ext" target="classFrame">SketchExampleDSP04LowPassFilter</a></li>
<li><a href="de/hfkbremen/ton/examples_ext/SketchExampleDSP05Wavetable.html" title="class in de.hfkbremen.ton.examples_ext" target="classFrame">SketchExampleDSP05Wavetable</a></li>
<li><a href="de/hfkbremen/ton/examples_ext/SketchExampleDSP06Sample.html" title="class in de.hfkbremen.ton.examples_ext" target="classFrame">SketchExampleDSP06Sample</a></li>
<li><a href="de/hfkbremen/ton/examples_ext/SketchExampleEvent01ReceiveMIDIandOSC.html" title="class in de.hfkbremen.ton.examples_ext" target="classFrame">SketchExampleEvent01ReceiveMIDIandOSC</a></li>
<li><a href="de/hfkbremen/ton/examples_ext/SketchExampleEvent02MIDIClock.html" title="class in de.hfkbremen.ton.examples_ext" target="classFrame">SketchExampleEvent02MIDIClock</a></li>
<li><a href="de/hfkbremen/ton/examples_ext/SketchExampleEvent03MIDIExternalKeyboard.html" title="class in de.hfkbremen.ton.examples_ext" target="classFrame">SketchExampleEvent03MIDIExternalKeyboard</a></li>
Expand All @@ -68,6 +71,8 @@ <h1 class="bar">All&nbsp;Classes</h1>
<li><a href="de/hfkbremen/ton/examples_ext/SketchExampleInstruments06PitchBend.html" title="class in de.hfkbremen.ton.examples_ext" target="classFrame">SketchExampleInstruments06PitchBend</a></li>
<li><a href="de/hfkbremen/ton/examples_ext/SketchExampleInstruments07InstrumentJSynCustom.html" title="class in de.hfkbremen.ton.examples_ext" target="classFrame">SketchExampleInstruments07InstrumentJSynCustom</a></li>
<li><a href="de/hfkbremen/ton/examples_ext/SketchExampleInstruments08InstrumentWithGUI.html" title="class in de.hfkbremen.ton.examples_ext" target="classFrame">SketchExampleInstruments08InstrumentWithGUI</a></li>
<li><a href="de/hfkbremen/ton/examples_ext/SketchExampleInstruments09PercussiveInstruments.html" title="class in de.hfkbremen.ton.examples_ext" target="classFrame">SketchExampleInstruments09PercussiveInstruments</a></li>
<li><a href="de/hfkbremen/ton/examples_ext/SketchExampleInstruments16Voices.html" title="class in de.hfkbremen.ton.examples_ext" target="classFrame">SketchExampleInstruments16Voices</a></li>
<li><a href="de/hfkbremen/ton/examples_ext/SketchExampleSpeechSynthesis.html" title="class in de.hfkbremen.ton.examples_ext" target="classFrame">SketchExampleSpeechSynthesis</a></li>
<li><a href="de/hfkbremen/ton/examples_ext/SketchExampleTechnique01Sequencer.html" title="class in de.hfkbremen.ton.examples_ext" target="classFrame">SketchExampleTechnique01Sequencer</a></li>
<li><a href="de/hfkbremen/ton/examples_ext/SketchExampleTechnique02Arpeggiator.html" title="class in de.hfkbremen.ton.examples_ext" target="classFrame">SketchExampleTechnique02Arpeggiator</a></li>
Expand All @@ -79,7 +84,6 @@ <h1 class="bar">All&nbsp;Classes</h1>
<li><a href="de/hfkbremen/ton/ToneEngineMinim.html" title="class in de.hfkbremen.ton" target="classFrame">ToneEngineMinim</a></li>
<li><a href="de/hfkbremen/ton/ToneEngineOSC.html" title="class in de.hfkbremen.ton" target="classFrame">ToneEngineOSC</a></li>
<li><a href="de/hfkbremen/ton/TonEvent.html" title="interface in de.hfkbremen.ton" target="classFrame"><span class="interfaceName">TonEvent</span></a></li>
<li><a href="de/hfkbremen/ton/tools/ToolWaveTableGenerator.html" title="class in de.hfkbremen.ton.tools" target="classFrame">ToolWaveTableGenerator</a></li>
<li><a href="de/hfkbremen/ton/Wavetable.html" title="class in de.hfkbremen.ton" target="classFrame">Wavetable</a></li>
</ul>
</div>
Expand Down
Loading

0 comments on commit 4486d4a

Please sign in to comment.