How to increase freq with a keyPressed func over than mouseMoved

import ddf.minim.*;
import ddf.minim.ugens.*;

Minim       minim;
AudioOutput out;
Oscil       wave;

void setup()
{
  size(512, 200, P3D);
  
  minim = new Minim(this);
  
  // use the getLineOut method of the Minim object to get an AudioOutput object
  out = minim.getLineOut();
  
  // create a sine wave Oscil, set to 440 Hz, at 0.5 amplitude
  wave = new Oscil( 440, 0.5f, Waves.SINE );
  // patch the Oscil to the output
  wave.patch( out );
}

void draw()
{
  background(0);
  stroke(255);
  strokeWeight(1);
  
  // draw the waveform of the output
  for(int i = 0; i < out.bufferSize() - 1; i++)
  {
    line( i, 50  - out.left.get(i)*50,  i+1, 50  - out.left.get(i+1)*50 );
    line( i, 150 - out.right.get(i)*50, i+1, 150 - out.right.get(i+1)*50 );
  }

  // draw the waveform we are using in the oscillator
  stroke( 128, 0, 0 );
  strokeWeight(4);
  for( int i = 0; i < width-1; ++i )
  {
    point( i, height/2 - (height*0.49) * wave.getWaveform().value( (float)i / width ) );
  }
}

void mouseMoved()
{
  // usually when setting the amplitude and frequency of an Oscil
  // you will want to patch something to the amplitude and frequency inputs
  // but this is a quick and easy way to turn the screen into
  // an x-y control for them.
  
  float amp = map( mouseY, 0, height, 1, 0 );
  wave.setAmplitude( amp );
  
  float freq = map( mouseX, 0, width, 110, 880 );
  wave.setFrequency( freq );
}
}

sorry, your posted code is not functional:

  • -a- there seems to be “}” too much at the end
  • -b- because you posted it as pasted text some good things seems to be deleted
import ddf.minim.*;
import ddf.minim.ugens.*;

show in your posting:

import ddf.minim.;
import ddf.minim.ugens.;

so i only see errors.

  • -c- why you not just say that you used the example of
    [File][Example][Contributed Libraries][Minim][Basics][SynthsizedSound]
    where you deleted the header explanation and the
    very existing
void keyPressed()
{ 
//...
}

now we know that you talk about the well known
mouse Theremin

// ok, lets start:
if you want to keep the existing mouse operation mouseX
but use the keyboard additionally you need some changes:

  • need a global freq variable
  • need to use that for the mouse
  • and use a keyboard action also to add / sub something from it.
float myfreq = 440;

// ...

//  float freq = map( mouseX, 0, width, 110, 880 );
//  wave.setFrequency( freq );
  myfreq = map( mouseX, 0, width, 110, 880 );
  wave.setFrequency( myfreq );

// ...

void keyPressed()
{ 
  // using the UP DOWN ARROW KEY to change the frequency
  if ( keyCode == UP )
  { 
    println("UP");
    wave.setFrequency( myfreq += 10 );
  }
  if ( keyCode == DOWN )
  { 
    println("DOWN");
    wave.setFrequency( myfreq -= 10 );
  }
}