<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with playnote() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=playnote%28%29</link>
      <pubDate>Sun, 08 Aug 2021 18:14:51 +0000</pubDate>
         <description>Tagged with playnote() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedplaynote%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>How can I stop Minim BitCrush creates noise out of speaker?</title>
      <link>https://forum.processing.org/two/discussion/27730/how-can-i-stop-minim-bitcrush-creates-noise-out-of-speaker</link>
      <pubDate>Tue, 10 Apr 2018 03:31:03 +0000</pubDate>
      <dc:creator>TuangPing</dc:creator>
      <guid isPermaLink="false">27730@/two/discussions</guid>
      <description><![CDATA[<p>I have worked on a piece of code that generates notes and beats from tweets. And, I am struggling with a beat part where I use an example code called bitCrushBeatExample as a drum sound for this sound project. I found out that after running this for a long time, like an hour, the speaker produces noise and keeps itself open for signal. Please click <a rel="nofollow" href="https://www.dropbox.com/s/9bnr5q169q1nd9p/Video%20Apr%2009%2C%207%2054%2033%20PM.mov?dl=0">here to see the video</a>. 
You can hear the noise at the 10th second.</p>

<p>As I tried several ways to turn it off, right now the bitCrush.unpatch(out) works for me. I use bitCrush.patch(out) again when the program run into a scene to generate sound again. However, the noise from the speaker will come back and play along with the other note and beat sounds.</p>

<p>Here is a rewritten shorten code. <strong>This code will runs fine without noise when the note is off after the 16 sec.</strong> But, I put it here because the actual code (a very long one) is similar to this.</p>

<pre><code>// bitCrushBeatExample

import ddf.minim.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*; // for BandPass

Minim minim;

Summer sum;

BitCrush bitCrush;

Line bitRateLine;

AudioOutput out;
AudioPlayer player;
AudioSample player_copy;
Timer time;

int scene=0;
int round=0;
boolean soundOn= true;
void setup()
{
  // initialize the drawing window
  size( 512, 200, P2D );

  // initialize the minim and out objects
  minim = new Minim( this );
  out = minim.getLineOut( Minim.MONO );

  player=minim.loadFile("dialupSound.mp3");
  player_copy=minim.loadSample("dialupSound.mp3");

  // make our summer and bit crush ugens
  sum = new Summer();                                                                          
  bitCrush = new BitCrush(16.f, out.sampleRate());

  // we're going to do 4 measures of 120 bpm, so that's 8 seconds.
  // we'll just ramp from half the sample rate to 100  Hz  
  bitRateLine = new Line(8.f, out.sampleRate()*0.25f, 100 );

  // connect the line to the bit crush resolution
  bitRateLine.patch( bitCrush.bitRate );
  // set up our signal chain
  sum.patch( bitCrush ).patch( out );

  // pause time when adding a bunch of notes at once
  out.pauseNotes();

  // we set the tempo of the output so that the time and duration arguments
  // of playNote now are expressed in beats
  out.setTempo( 60.f );

  println(round+"------------time is reset-----------");
  time = new Timer (24000);
  scene=1;
}

// draw is run many times
void draw()
{
  textAlign(CENTER);
  background( 0 );
  fill(255);
  switch(scene) {
  case 1: 
    text("This is scene 1", width/2, (height/2)-30);
    text("click anywhere to go to scene 2", width/2, height/2);
    break;
  case 2:
    text("This is scene 2", width/2, (height/2)-30);
    text ("play.isPlaying(), at the end will go to scene 3 then, play_loadSample", width/2, height/2);
    text("no mouse click", width/2, (height/2)+30);
    if (!player.isPlaying()) {
      if ( !soundOn) {
        bitCrush.patch(out);
        playDrum();
        soundOn=true;
      }
      player=minim.loadFile("dialupSound_effect.mp3");
      player.play();
      scene++;
      time.reset();
    }
    break;
  case 3:
    text("This is scene 3", width/2, (height/2)-30);
    text ("click here to pause/play beat", (width/2)-100, height/2);
    text ("click here to go to scene 1", (width/2)+100, height/2);
    // draw using a white stroke
    stroke( 255 );
    // draw the waveforms
    for ( int i = 0; i &lt; out.bufferSize() - 1; i++ )
    {
      // find the x position of each buffer value
      float x1  =  map( i, 0, out.bufferSize(), 0, width );
      float x2  =  map( i+1, 0, out.bufferSize(), 0, width );
      // draw a line from one buffer position to the next for both channels
      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);
    }  
    if ( time.isDone()) {
      //out.pauseNotes();
      playDrum();
      time.reset();
      round++;
      println(round+"------------time is reset-----------");
    }
    text(time.getCurrentTime(), 20, 30);
    time.update();
    break;
  }
}


void playDrum() {
  float kickDur = 0.8;
  float snareDur = 0.2;
  out.pauseNotes();
  for (int i = 0; i &lt; 4; i++)
  {
    out.setNoteOffset( i * 4 );
    // we set the note offset so that each loop we are queuing up a new measure
    out.playNote( 0, kickDur, new KickInstrument( sum ) );
    println("note 1");
    out.playNote( 1, snareDur, new SnareInstrument( sum ) );
    out.playNote( 1.5, kickDur, new KickInstrument( sum ) );
    println("note 2");
    out.playNote( 2.5, kickDur, new KickInstrument( sum ) );
    println("note 3");
    out.playNote( 3, snareDur, new SnareInstrument( sum ) );
    out.playNote( 3.5, snareDur, new SnareInstrument( sum ) );
    out.playNote( 2.5, kickDur, new KickInstrument( sum ) );
    println("note 4");
    // every other measure give a little kick at the end
    if ( i % 2 == 1 )
    {
      out.playNote( 3.75, 0.1, new KickInstrument( sum ) );
      println("little kick");
    }
  }

  // activate the line and unpause the output!
  bitRateLine.activate();
  out.resumeNotes();
  //out.pauseNotes();
}

void mousePressed() {
  switch(scene) {
  case 1:
    player.play();
    scene++;
    break;
  case 3:
    if (mouseX &lt;= width/2) {
      if (soundOn) { // play and puase 
        println("pause");
        bitCrush.unpatch(out);
        soundOn=false;
      } else {
        println("play");
        time.reset();
        bitCrush.patch(out);
        playDrum();
        soundOn=true;
      }
    } else { // go back to scene 1 (home)
      println("go back");
      player=minim.loadFile("dialupSound.mp3");
      player.pause();
      player.rewind();
      bitCrush.unpatch(out);
      out.close();
      soundOn=false;
      scene=1;
      time.reset();
    }
    break;
  }
}

void stop()
{
  // always close Minim audio classes when you are done with them
  out.close();
  player.close();
  minim.stop();
  super.stop();
}

class KickInstrument implements Instrument {}
class SnareInstrument implements Instrument {}  
class Timer {}
</code></pre>

<p>To explain a bit more: this piece of code has 3 scenes. At the 3 scene the sound should be produced. So, when going back to scene 1 the sound should be removed. In this whole project, there are other classes as well, which are SineInstrument, Gain, but they are not listed below. The SineInstrument has no problem at this time. I use out.pauseNote(); to stop it. In all Kick, and Sine class of instrument at void notenf(){} I add the any oscill class a .reset(); into the function.</p>

<p>like this:
    <code>void noteOn(float dur) {
    // patch our oscil to the summer we were given and start the line
    sineOsc.reset();
    freqLine.activate();
    sineOsc.patch(gain2).patch(out);
    }</code></p>

<p><strong>Is there a way to I stop the noise when it is not playing anything!?</strong>
<strong>Is it possible that if you change .setTempo() it might be the one causing this problem?</strong>  (In my code, tempo has been changed over time.)</p>
]]></description>
   </item>
   <item>
      <title>SoundCipher and identifying pitches</title>
      <link>https://forum.processing.org/two/discussion/23362/soundcipher-and-identifying-pitches</link>
      <pubDate>Sat, 08 Jul 2017 01:33:29 +0000</pubDate>
      <dc:creator>germaine</dc:creator>
      <guid isPermaLink="false">23362@/two/discussions</guid>
      <description><![CDATA[<p>Hello! I'm trying to use SoundCipher functions like playNote() and playChord() in my project. How can I tell which pitch values are equivalent to which musical notes? Sorry if this is a silly question -- I don't really know how music works. :)</p>

<p>Thanks for your help!</p>
]]></description>
   </item>
   <item>
      <title>Fix echoes on my NoteSheet Player</title>
      <link>https://forum.processing.org/two/discussion/21137/fix-echoes-on-my-notesheet-player</link>
      <pubDate>Fri, 03 Mar 2017 19:59:34 +0000</pubDate>
      <dc:creator>xxMrPHDxx</dc:creator>
      <guid isPermaLink="false">21137@/two/discussions</guid>
      <description><![CDATA[<p>I was working on a music notes player loaded through .csv file. Is there any way to reduce that echo when the play speed increase or perhaps smooth out the playback? Here's my current code:-</p>

<pre><code>import ddf.minim.ugens.*;
import ddf.minim.*;

Minim minim;
AudioOutput out;

Track t1;

void setup() {
  size(600, 600);
  frameRate(8);

  minim = new Minim(this);
  out = minim.getLineOut();

  t1 = new Track("CanonRock.csv");
}

void draw() {
  background(51);
  t1.play();
}

class ToneInstrument implements Instrument{
  Oscil toneOsc;
  ADSR adsr;
  AudioOutput out;

  ToneInstrument( String note, float amplitude, Waveform wave, AudioOutput output ){
    out = output;

    float frequency = Frequency.ofPitch( note ).asHz();

    toneOsc = new Oscil( frequency, amplitude, wave );
    adsr = new ADSR( 1.0, 0.04, 0.01, 1.0, 0.1 );

    toneOsc.patch( adsr );
  }

  void noteOn( float dur ){
    adsr.noteOn();
    adsr.patch( out );
  }

  void noteOff(){
    adsr.noteOff();
    adsr.unpatchAfterRelease( out );
  }
}

class Track{
  ArrayList&lt;String&gt; type;
  ArrayList&lt;String&gt; chords;
  int current = 0;
  boolean stop = false;

  float vol = 0.45;
  Waveform disWave = Waves.sawh( 4 );

  Track(String csv){
    type = new ArrayList&lt;String&gt;();
    chords = new ArrayList&lt;String&gt;();

    String[] notes = loadStrings(csv);
    for(int i=0;i&lt;notes.length;i++){
      String[] delims = notes[i].split(";");
      type.add(delims[0]);
      chords.add(delims[1]);
    }
  }

  void addChord(String chord){
    chords.add(chord);
  }

  void addChords(ArrayList&lt;String&gt; chord){
    chords.addAll(chord);
  }

  void play(){
    if(chords.size() == 0 || stop)return;

    out.playNote( 1.0, 1.0, new ToneInstrument(chords.get(current), vol, disWave, out ) );

    textSize(72);
    text(chords.get(current),40,vol* 200);

    int wait = 0;
    switch(type.get(current)){
      case "Minim":
        wait = 2; // 8 / 2
        break;
      case "Crochet":
        wait = 4;
        break;
    }
    float sleep = (wait == 0) ? 0 : 8.0 / (wait * wait / 3);

    if(wait != 0)delay((int)(200 * sleep));

    current++;
    if(current &gt;= chords.size()){
      current = 0;  //Enable repeat
      //stop = true;
      //stop();
    }
  }

  void stop(){
    vol = 0;
  }
}
</code></pre>

<p>You can get the "CanonRock.csv" file <a rel="nofollow" href="https://www.dropbox.com/s/io2xcu88ovrujiu/CanonRock.csv?dl=1">here</a></p>

<p><strong>Reference:-</strong>
<em><a href="https://www.jellynote.com/en/sheet-music-tabs/jerryc/canon-rock/5076e948d2235a7374cdd6c1#tabs:A" target="_blank" rel="nofollow">https://www.jellynote.com/en/sheet-music-tabs/jerryc/canon-rock/5076e948d2235a7374cdd6c1#tabs:A</a></em></p>
]]></description>
   </item>
   <item>
      <title>How to play a midi sound from soundcipher i.e a string sound and prolong this sound</title>
      <link>https://forum.processing.org/two/discussion/19853/how-to-play-a-midi-sound-from-soundcipher-i-e-a-string-sound-and-prolong-this-sound</link>
      <pubDate>Tue, 20 Dec 2016 18:48:22 +0000</pubDate>
      <dc:creator>thiagomarcondes</dc:creator>
      <guid isPermaLink="false">19853@/two/discussions</guid>
      <description><![CDATA[<p>Hello there!
I have a question: when i play a string sound pressing a key using soundcipher the sound has a lenght and after a while it starts to glitching. how can i play longer notes , string sound notes, and have them stop when i just release the sound key, but keeping the quality of the string sound without glitches?</p>
]]></description>
   </item>
   <item>
      <title>Making a basic music sequencer with minim</title>
      <link>https://forum.processing.org/two/discussion/19217/making-a-basic-music-sequencer-with-minim</link>
      <pubDate>Tue, 22 Nov 2016 13:14:25 +0000</pubDate>
      <dc:creator>calmoo</dc:creator>
      <guid isPermaLink="false">19217@/two/discussions</guid>
      <description><![CDATA[<p>I've started on a project to create a music sequencer with minim using instrument classes and playNote functions etc. I've got a sequence of notes working ok, but I have no way of looping them. Here's the main code:</p>

<pre><code>import ddf.minim.*;
import ddf.minim.ugens.*;

Minim       minim;
AudioOutput out;
Delay myDelay;
int i;
int endSeq;

public void settings() {
  size(800, 300, P2D);
}

void setup() {

  minim = new Minim(this);
  out = minim.getLineOut();
  myDelay = new Delay(1.5,0.5, false,false);
  bassSeq(); // starts bass sequence function
  chordSeq(); // starts chord sequence function
}

void draw() {
}
</code></pre>

<p>And here's the bassSeq function which describes the whole bass sequence:</p>

<pre><code>void bassSeq(){
float[] stepArray = {0.00, 0.75, 2.00, 2.5, 2.75, 3.5, 4, 4.5};
float[] decayArray = {1.0, 0.5, 0.5, 0.5, 0.5, 0.2, 0.5, 1.0};
float[] noteArray = {C2, F2, E2, G2, B2, C2, C2, B2};

for (i = 0; i &lt;= 7; i++){

  out.pauseNotes();
  out.setTempo(125);
  out.playNote(stepArray[i], decayArray[i], new BassInstr(noteArray[i], 0.5, out ) );
  out.resumeNotes();

}
}
</code></pre>

<p>The problem is, if I put these functions in setup, they only play once. What ideally I'd want to do is iterate back to the start of i=0 so it gives the instruments the sequence from the start of the array after it is finished one loop. If I put the sequence functions in the draw loop, it sends the instrument notes incredibly fast (prob around 60fps if that's the default for draw). I've put a delay() function in the draw loop which does actually loop the music after the time but there's no way of giving delay a number that is totally accurate so it loops accurately.</p>

<p>Some help would be appreciated.</p>
]]></description>
   </item>
   <item>
      <title>Minim Ugens AudioOutput, playNote only once</title>
      <link>https://forum.processing.org/two/discussion/18486/minim-ugens-audiooutput-playnote-only-once</link>
      <pubDate>Mon, 10 Oct 2016 17:04:24 +0000</pubDate>
      <dc:creator>AlfieChillar</dc:creator>
      <guid isPermaLink="false">18486@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I am working on a sketch that recognises faces and plays notes depending on the location/size of said faces. However, currently the playNote function just repeatedly plays the same note over and over, as opposed to just once.</p>

<p>I realise that the problem currently is that the only way I could find to use the parameters of the face detection rects is to put the playNote in the same brackets as them. Meaning that of course, as the rects are being permanently drawn, so are the notes being permanently created.</p>

<p>How can I have a playNote function that runs on the faces[i] parameters but doesn't have to be in the same 'for' brackets?</p>

<p>All help is greatly appreciated, here is my code currently</p>

<pre><code>import gab.opencv.*;
import processing.video.*;
import java.awt.*;

// audio bits
import ddf.minim.*;
import ddf.minim.ugens.*;
AudioOutput out;

Capture video;
OpenCV opencv;

void setup() {
  size(640, 480);
  video = new Capture(this, 640/2, 480/2);
  opencv = new OpenCV(this, 640/2, 480/2);
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  

  video.start();

  Minim minim = new Minim(this);
  out = minim.getLineOut();
}

void draw() {
  scale(2);
  opencv.loadImage(video);

  image(video, 0, 0 );

  noFill();
  stroke(0, 255, 0);
  strokeWeight(3);
  Rectangle[] faces = opencv.detect();
  println(faces.length);

  for (int i = 0; i &lt; faces.length; i++) {
    println(faces[i].x + "," + faces[i].y);
    out.playNote(0, 1, (faces[i].width*2));
    rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);     
  }
}

void captureEvent(Capture c) {
  c.read();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Changing the instrument with Minim</title>
      <link>https://forum.processing.org/two/discussion/18434/changing-the-instrument-with-minim</link>
      <pubDate>Thu, 06 Oct 2016 17:12:18 +0000</pubDate>
      <dc:creator>Jose_Aparecido</dc:creator>
      <guid isPermaLink="false">18434@/two/discussions</guid>
      <description><![CDATA[<p>Hello guys,</p>

<p>How could I change the type of instrument using the Minim library?</p>

<p>For example, like to switch Piano Violin, etc ...</p>

<p>I managed to do this with the soundcipher library, but some things have to do with Minim, I would have a fft and sinusoidal signal ... below is the sample code.</p>

<pre><code>import ddf.minim.*;
import ddf.minim.ugens.*;

Minim minim;
AudioOutput out;
ToneInstrument myNote;

int note = 150;

void setup(){
  size(512, 200, P2D);

  minim = new Minim(this);
  out = minim.getLineOut(Minim.STEREO, 1024);

  //myNote = new ToneInstrument( 200.f, 0.3, 0.5f, 1.0f );
  //out.playNote(0.f, 8.f, myNote );
}

void draw(){
  background( 0 );
  stroke( 255 );
  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);
  }  
}

void mousePressed(){
  //out.instrument(0); //??
  out.playNote(0.f, 1, note );  
}

void keyPressed(){
  if (key == 'M' || key == 'm') note++;
  else if (key == 'N' || key == 'n') note--;
}

class ToneInstrument implements Instrument{
  Oscil sineOsc, lFOOsc;
  Balance balance;

  ToneInstrument(float frequency, float amplitude, float lfoFrequency, float lfoAmplitude){
    sineOsc = new Oscil(frequency, amplitude, Waves.SINE);
    lFOOsc = new Oscil(lfoFrequency, lfoAmplitude, Waves.SINE);
    balance = new Balance( 0.5 );
    lFOOsc.patch( balance.balance );

    sineOsc.patch( balance );
  }
  void noteOn(float dur){
    balance.patch(out);
  }

  // every instrument must have a noteOff() method
  void noteOff(){
    balance.unpatch(out);
  }
}
</code></pre>

<p>Thanks for listening</p>
]]></description>
   </item>
   <item>
      <title>How to modulate the frequency of samples</title>
      <link>https://forum.processing.org/two/discussion/16337/how-to-modulate-the-frequency-of-samples</link>
      <pubDate>Fri, 29 Apr 2016 08:13:47 +0000</pubDate>
      <dc:creator>BaAhl777</dc:creator>
      <guid isPermaLink="false">16337@/two/discussions</guid>
      <description><![CDATA[<p>Hi! I'm making a synthesizer by using Minim on processing, I'd like to play notes by changing the frequency of a sample
found on freewavesamples.com. Actually i only can play notes with the playNote() function. There's is many examples showing how to modulate the "default sound' of Minim but I don't know how to do this with a sample...</p>
]]></description>
   </item>
   </channel>
</rss>