1

I'm trying to create algorithmic music in netBeans using jFugue and have an integer array with the notes from one octave of the c major scale:

String scaleNotesC[] = {"[60]", "[62]", "[64]", "[65]", "[67]", "[69]", "[71]", "[72]"};  

When I run the code below to try to get it to play C nothing happens.

Player playerOne = new Player();  
playerOne.play("scaleNotesC[0]");  

I have tried using an integer array but that didn't work either.
Is there any way to get jFugue to play a random note from a set in an array?
EDIT:
I changed the player code above to this to try and play multiple notes from the array but it won't work

playerOne.play(scaleNotesC[2] scaleNotesC[3] scaleNotesC[2]);
TheStuka
  • 83
  • 2
  • 10
  • Remove the quotes: `playerOne.play(scaleNotesC[0]);` – BackSlash Jan 02 '15 at 10:48
  • Thanks! @BackSlash, also when i try and play it with multiple notes (exemplified above in my edit) it doesn't work yet if i have just one it still works – TheStuka Jan 03 '15 at 11:08

1 Answers1

1

In your first example,

playerOne.play("scaleNotesC[0]");

You are trying to pass a Java expression as a string. However, the string itself is not evaluated as a Java expression. Instead, JFugue tries to parse "scaleNotesC[0]" itself as a music string, which it is not, so you hear no music. If you remove the quotes, Java will evaluate scaleNotesC[0] to "[60]", and JFugue will successfully parse "[60]" as a Middle-C and play it.

The version of JFugue you are currently using does not have a play() method that takes a list of strings as a parameter (an upcoming release will have this capability). Might I suggest:

Pattern pattern = new Pattern();
pattern.add(scaleNotesC[2], scaleNotesC[3], scaleNotesC[2]);
Player playerOne = new Player();
playerOne.play(pattern);
David Koelle
  • 20,726
  • 23
  • 93
  • 130
  • Update for JFugue v5.0 and higher: Square brackets are no longer used for numeric notes, so you would now say: `String scaleNotesC[] = {"60", "62", "64", "65", "67", "69", "71", "72"};` (Square brackets remain used to indicate strings that are keys into a dictionary, such as `"T[Adagio]"` for a tempo) – David Koelle Apr 23 '17 at 01:55