We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › why variable return isn't working
Page Index Toggle Pages: 1
why variable return isn't working (Read 486 times)
why variable return isn't working
May 2nd, 2010, 8:49pm
 
I'm trying to pass the data in array "baseNote" from the "generateVerse" function to the "generateNotes" function; the return is working, but the data does not show up in the second function. simplified code:

Code:
Chord currentChord;

int Key = int(random(0,11));
int [] baseNote = new int[4];
int duration = 2400;
int KeyNote;

import ddf.minim.*;
import ddf.minim.signals.*;

Minim minim;
AudioOutput out;
Vector sines;


void setup()
{
 println ("Key:" + Key);

}

void draw()
{
 setupAudio();
}
void setupAudio()
{
 print("setting up audio...");
 minim = new Minim(this);
 // get a line out from Minim, default bufferSize is 1024, default sample rate is 44100, bit depth is 16
 out = minim.getLineOut(Minim.STEREO);

 sines = new Vector();

 Chord currentChord = new Chord(KeyNote);

 for (int i = 0; i < currentChord.notes.size(); i++)
 {
   Note n = (Note)currentChord.notes.elementAt(i);

   int noteNum = n.noteNum;
   float freq = 440.0 * pow(2, (noteNum - 69)/12.0);
   SineWave s = new SineWave(freq, 0.25, out.sampleRate());
   sines.add(s);
   out.addSignal(s);
 }
 generateVerse();
 generateNotes(baseNote);
}
int[] generateVerse()

{
 Chord currentChord = new Chord(KeyNote);

  int [] baseNote = {1, 6, 8, 1};
  return baseNote;
 
}

void generateNotes(int [] baseNote)
{
  println("baseNotes:" + baseNote[0] + baseNote[1] + baseNote[2] + baseNote[3]);
 for (int j = 0; j < 3; j++)
 {
   KeyNote = baseNote[j] + Key + 59;
   println("baseNote[0]: " + baseNote[1]);
   println("KeyNote:" + KeyNote);

   for (int l = 0; l < 3; l++)
   {
     Chord newChord = new Chord(KeyNote);

     Note n = (Note)newChord.notes.elementAt(l);

     int noteNum = n.noteNum;

     // print("noteNum: " + noteNum);

     float freq = 440.0 * pow(2, (noteNum - 69)/12.0);

     //print(" freq: " + freq + " ");

     SineWave s = (SineWave)sines.elementAt(j);
     s.setFreq(freq);
   }
 }
 println();
 delay(duration);
}

void stop()
{
 out.close();
 minim.stop();
 super.stop();

}


any thoughts? help is much appreciated.
Re: why variable return isn't working
Reply #1 - May 2nd, 2010, 11:08pm
 
It might have something to do with the fact that you've got baseNote defined at the global scope:

int [] baseNote = new int[4];

But also redefine it (and then return it) from your function.
To avoid confusion, I'd suggest using different names for your local variables and global ones.
Page Index Toggle Pages: 1