Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You haven't posted any code regarding your while statement. From what you describe it sounds like what you is simple:</p> <ul> <li>if the mouse is pressed sound is played and updated(notes changed based on melody/etc.)</li> <li>otherwise there is no sound (no updated, no output)</li> </ul> <p>Which from my point of view is a simple <code>if/else</code> so it would a matter of registering for mouse events like <code>mousePressed</code> and <code>mouseReleased</code> (as a click is a essentially a pair made of a press followed by a release) to toggle sound updating. I'm not an expert on sound/notes/melodies but here's a modified version of the Minim SineWaveSignal Processing sample:</p> <pre><code>import ddf.minim.*; import ddf.minim.signals.*; Minim minim; AudioOutput out; SineWave sine; float freq = 60; void setup() { size(512, 200, P2D); minim = new Minim(this); out = minim.getLineOut(Minim.STEREO); sine = new SineWave(440, 0.5, out.sampleRate()); sine.portamento(200); sine.setAmp(0); out.addSignal(sine); } void draw() { background(0); stroke(255); //update sound only if mouse is pressed if(mousePressed){ freq += 10;//in this case I'm updating the frequency if(freq &gt; 1500) freq = 60;//change melody according to time delays/etc. here sine.setFreq(freq); } // draw the waveforms for(int i = 0; i &lt; out.bufferSize() - 1; i++) { float x1 = map(i, 0, out.bufferSize(), 0, width); float x2 = map(i+1, 0, out.bufferSize(), 0, width); line(x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50); line(x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50); } } //updated sound "while" mouse is clicked (press+release) void mousePressed(){ sine.setAmp(.75); } void mouseReleased(){//reset, kill volume/amp and reset freq, in your case return to 1st note of melody for example freq = 60; sine.setAmp(0); } void stop() { out.close(); minim.stop(); super.stop(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload