processing / processing-sound

Audio library for Processing built with JSyn
https://processing.org/reference/libraries/sound/
GNU Lesser General Public License v2.1
149 stars 50 forks source link

Where is JSynOscillator.java? #57

Closed uheinema closed 4 years ago

uheinema commented 4 years ago

In Oscillator.java (12):

protected JSynOscillator oscillator;

I assume it shoild be com.jsyn.unitgen.UnitOscillator ???

The sources are incomplete inconsistent?

uheinema commented 4 years ago

Ok, got it... public abstract class Oscillator<JSynOscillator extends UnitOscillator> extends SoundObject { Creates a local class...but why not use UnitOscilator??? Ahbah.

kevinstadler commented 4 years ago

All the library classes named JSyn* are just thin wrappers around the respective JSyn classes to allow for nicer usage of Java generics in the Sound library, the point of this library-internal quirk is to shield Processing users from having to worry about casting. Basic users should not need access to the underlying JSyn objects, although I suppose we could actually expose them using an undocumented method for advanced users....what exactly was your use case for wanting to access the underlying oscillator/unit?

uheinema commented 4 years ago

Thanks for replying!

I thought I could create a simple synth like

with the LFO/ADSR optionaly controlling the frequency of VCO and VCF - 1970s style synthi sounds. (Just as a demo for https://github.com/uheinema/forU , have a look at UI_09_menu_synth there).

After some hacking around, I gave it up as a bad job - everything useful is private or protected, and the simple beauty of jsyn is hidden - it is just not designed for this. Or I am just to stupid to get it?

I tend to leave it at that, and create my own library, just encapsulating the ugly parts in Engine/JsynAndroidDeviveManager and leave the rest to jsyn, where It belongs.

EG.like this (working code!)

import forU.I.*;

import com.jsyn.*;

import soundx.Engine;

import com.jsyn.unitgen.*;

import com.jsyn.ports.*;

Engine j;

float freq=400.0f;

UnitSlider us;
UnitBar bar;

void setup() {
  fullScreen(P3D);
  textSize(32);
  new UI(this, 64);

  j = Engine.create(this);

  UnitOscillator osc=new TriangleOscillator();
  UnitOscillator lfo=new SineOscillator();

  us=new UnitSlider("lfo #  "); 
  bar=new UnitBar("#     ");

  us.range(0.1, 10, 0).set(2);
  us.logarithmic=true;
  us.connect(lfo.frequency);
  us.act();

  MultiplyAdd fr=new MultiplyAdd(); // a*b+c
  fr.inputB.set(10.0);
  fr.inputC.set(440.0);
  fr.output.connect(osc.frequency);

  lfo.output.connect(bar);
  bar.connect(fr.inputA);

  j
    .add(lfo)
    .add(osc)
    .play(osc);

  //UI.label("").br();
  UI
    .add(us).nl()
    .add(bar);
}

class UnitSlider extends Slider 
  implements ConnectableOutput, ConnectableInput
{
  MultiplyAdd multiplyAdd;

  /* pass through for interface */
  void connect(ConnectableInput other) {
    multiplyAdd.output.connect(other);
  }

  void disconnect(ConnectableInput other) {
    multiplyAdd.output.disconnect(other);
  }

  void connect(ConnectableOutput other) {
    other.connect(multiplyAdd.inputA);
  }

  void disconnect(ConnectableOutput other) {
    other.disconnect(multiplyAdd.inputA);
  }

  PortBlockPart getPortBlockPart() {
    return multiplyAdd.inputA. getPortBlockPart();
  }

  void pullData(long frameCount, int start, int limit) {
    multiplyAdd.inputA. pullData(frameCount, start, limit);
  }

  UnitSlider(String t) {
    super(t, null, 0.0f);
    range(0, 1, 0);
    multiplyAdd =new MultiplyAdd();
    multiplyAdd .inputA.set(1.0);
    multiplyAdd .inputB.set(1.0);
    multiplyAdd .inputC.set(0.0); 
    Engine.get().add(multiplyAdd); // destroy???
  }

  @Override 
    void drag() {
    super.drag();
    act();
  }

  @Override
    boolean act() {
    multiplyAdd .inputB.set(value);
    return true;
  }
}

void draw() {
  background(frameCount);
}

class UnitBar extends UnitSlider {
  UnitBar(String t) {
    super(t);
    range(-1, 1, 0);
  }

  void draw() {
    value=(float)multiplyAdd.output.get();
    //super.draw();
    pushStyle();
    rect(x, y, map(value, -1, 1, 0, w), h);
    stroke(255);
    noFill();
    rect(x, y, w, h);
    popStyle();
  }
}

Note how the user interface elements are tied into the jsyn unit mesh.

Tnx for your fantastic work, would never have figured out how to connect jsyn to android audio.

Just started this 2 days ago, we'll see how far i will push it. (processing.jsyn.? Rather not, but forU.jsyn., probably).

Best regards, and excuse the tone of my first post.