Can't construct inside of a class

I have a class that I would like to have an envelop class created with it and only for it. I keep trying to construct an envelop inside it but can’t because new Env(this); won’t work and gives a Constructor doesn’t exist error. Thoughts?

Here is the class code. SinOsc also doesn’t work so this doesn’t even run without the Env

import processing.sound.*;

class Biker {
  Env env = new Env(this);
  
  int xPos;
  int yPos;
  int xCord;
  int yCord;

  int diameter = 20; 

  //Chord frequency Ratio 1:1.2:1.5
  float lowChord;
  float midChord;
  float highChord;

  SinOsc[] chord = new SinOsc[3];


  float attackTime = 0.001;
  float sustainTime = 0.004;
  float sustainLevel = 0.3;
  float releaseTime = 0.4;

  Biker(int xPosition, int yPosition, int index) {
    xCord = xPosition;
    yCord = yPosition;

    //A1 base + (index * note offset)
    lowChord = 55 * pow(1.059463094359, index);
    midChord = 55 * pow(1.059463094359, index+3);
    highChord = 55 * pow(1.059463094359, index+7);

    print(this);

    chord[0].freq(lowChord);
    chord[0].amp(0.2);
    chord[1].freq(midChord);
    chord[1].amp(0.2);
    chord[2].freq(highChord);
    chord[2].amp(0.2);
  }

  void display() {
    int xSpacing = width/sideLength;
    int ySpacing = height/sideLength;

    xPos = xCord*xSpacing+(xSpacing/2);
    yPos = yCord*ySpacing+(ySpacing/2);

    ellipse(xPos, yPos, diameter, diameter);
  }

  void playChord() {
    for (int i = 0; i < 3; i++) {
      chord[i].play();
      // env.play(chord[i], attackTime, sustainTime, sustainLevel, releaseTime);
    }
  }
}
1 Like

the Env object is part of processing sound library.

The constructor is expecting a PApplet as an argument. You are calling it with your own class as an argument so the constructor really does not exist.

In order to achieve what you want to do, you need to create a Biker constructor that take the PApplet as an argument.

Something like this:

class Biker {
  Env env;

  Biker(PApplet papplet) {
    env = new Env(papplet);
  }

  ...
}

And in your main code you simply do:

void setup() {
  Biker biker = new Biker(this);
}
3 Likes