# How to increase sive wave with keypress rather than moving the mouse

**URL:** <https://discourse.processing.org/t/how-to-increase-sive-wave-with-keypress-rather-than-moving-the-mouse/5299>\
**Category:** Libraries\
**Created:** [November 7, 2018, 9:39am UTC](https://discourse.processing.org/t/how-to-increase-sive-wave-with-keypress-rather-than-moving-the-mouse/5299 "2018-11-07T09:39:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![admbdr](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@admbdr](https://discourse.processing.org/u/admbdr)\
**Post date:** [November 7, 2018, 9:39am UTC](https://discourse.processing.org/t/how-to-increase-sive-wave-with-keypress-rather-than-moving-the-mouse/5299/1 "2018-11-07T09:39:51Z")

</div>

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 );  
}

void keyPressed()  
{  
switch( key )  
{  
case ‘1’:  
wave.setWaveform( Waves.SINE );  
break;

```
case '2':
  wave.setWaveform( Waves.TRIANGLE );
  break;

case '3':
  wave.setWaveform( Waves.SAW );
  break;

case '4':
  wave.setWaveform( Waves.SQUARE );
  break;

case '5':
  wave.setWaveform( Waves.QUARTERPULSE );
  break;

default: break; 

```

}  
}

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 7, 2018, 9:45am UTC](https://discourse.processing.org/t/how-to-increase-sive-wave-with-keypress-rather-than-moving-the-mouse/5299/2 "2018-11-07T09:45:41Z")

</div>

Please post in the right cathegory.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 7, 2018, 11:44am UTC](https://discourse.processing.org/t/how-to-increase-sive-wave-with-keypress-rather-than-moving-the-mouse/5299/3 "2018-11-07T11:44:56Z")

</div>

you already have the code for keypressed and switch,  
you want add more keys there? changing amp and freq instead with mouse position?

```auto

float amp=0.5;
float freq=440;

void draw() {
  // amp = map( mouseY, 0, height, 1, 0 );
  // freq = map( mouseX, 0, width, 110, 880 );

  println(" amp "+nf(amp, 1, 2)+" freq "+nf(freq, 1, 1));
}

void keyPressed()
{
  switch( key )
  {
  case '1':
    //
    break;
    //...
    // add
  case 'A':
    amp += 0.01;
    break;
  case 'a':
    amp -= 0.01;
    break;
  case 'F':
    freq += 10;
    break;
  case 'f':
    freq -= 10;
    break;

  default: 
    break;
  }
}

```

but actually i just play with a other “primitiv (NoGUI) slider” concept  
what is promising.

use the mouse wheel for SLIDING and keypressed to assign different jobs to it

```auto

float amp=0.5;
float freq=440;

void setup(){
 println("use key [a] amp or [f] freq plus mouse wheel "); 
}

void draw() {
  // amp = map( mouseY, 0, height, 1, 0 );
  // freq = map( mouseX, 0, width, 110, 880 );

  println(" amp "+nf(amp, 1, 2)+" freq "+nf(freq, 1, 1));
}

/*
void keyPressed()
{
  switch( key )
  {
  case '1':
    //
    break;
    //...
    // add
  case 'A':
    amp += 0.01;
    break;
  case 'a':
    amp -= 0.01;
    break;
  case 'F':
    freq += 10;
    break;
  case 'f':
    freq -= 10;
    break;

  default: 
    break;
  }
}

*/

void mouseWheel(MouseEvent event) {
  if (keyPressed) {
    if (key == 'a') {
      amp += event.getCount()/100.0; 
      amp = constrain(amp,0,1);
    } else
    if (key == 'f') {
      freq += event.getCount()*10.0; 
      freq = constrain(freq,110,880);
    } 
  } else { // no key pressed
// default slider
  }

}

```

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 7, 2018, 12:37pm UTC](https://discourse.processing.org/t/how-to-increase-sive-wave-with-keypress-rather-than-moving-the-mouse/5299/4 "2018-11-07T12:37:49Z")

</div>

I don’t know, i think he had the concept and just wanted to post it, but that should go in the Gallery cathegory… at least thats what i thought…

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 7, 2018, 12:41pm UTC](https://discourse.processing.org/t/how-to-increase-sive-wave-with-keypress-rather-than-moving-the-mouse/5299/5 "2018-11-07T12:41:28Z")

</div>

so i miss-understand the TITLE?

> How to increase sive wave with keypress rather than moving the mouse

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 7, 2018, 12:43pm UTC](https://discourse.processing.org/t/how-to-increase-sive-wave-with-keypress-rather-than-moving-the-mouse/5299/6 "2018-11-07T12:43:44Z")

</div>

Yeah, maybe… it’s not explained very well, but the sentence makes sense in both cases, question and explanation. For example, Question : “How to get good at math?” Or Tutorial : “How to get good at Math”  
Same sentence, just without question mark, and if i’m not wrong, then he already got a method for mouse input… but there i might be wrong…

I mean this part.

```auto
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 );
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 7, 2018, 12:52pm UTC](https://discourse.processing.org/t/how-to-increase-sive-wave-with-keypress-rather-than-moving-the-mouse/5299/7 "2018-11-07T12:52:38Z")

</div>

exactly  
should sound terrible,  
like my mouse X Y “THEREMIN” [https://en.wikipedia.org/wiki/Theremin](https://en.wikipedia.org/wiki/Theremin)  
( unless that operation concept is wanted )

already a mouseDragged ( mouse pressed and moved ) instead  
might have helped not to have constant changing settings
