Permalink
Browse files

Updated synth, bass, and progression methods

  • Loading branch information...
1 parent c985e9c commit b0f359f767a3efd65499fe9dd6e34335ba4286b6 Joseph Betz committed Mar 1, 2012
Showing with 47 additions and 17 deletions.
  1. +47 −17 java/TwitterMelodyGenerator/src/edu/uiuc/sigmusic/twittersounds/MelodyGenerator.java
@@ -33,7 +33,7 @@
* Mood Attributes
*/
- public int happiness = 0; // Happiness parameter, from 0 to 100, 0 =
+ public int happiness = 100; // Happiness parameter, from 0 to 100, 0 =
// depressed, 100 = elated
public int excitement = 0; // Excitement parameter, from 0 to 100, 0 =
// bored, 100 = excited
@@ -305,7 +305,7 @@ public void generateProgression() {
} else if (happiness > 33) {
chordProgression[0] = 0; // Always start with the root
scaleType[0] = 0;
- for (int i = 1; i < 4; i++) {
+ for (int i = 1; i < 3; i++) {
double chordPicker = Math.random() * 100;
if (chordPicker < 25) {
chordProgression[i] = 2;
@@ -327,6 +327,7 @@ public void generateProgression() {
scaleType[i] = 0;
}
}
+ scaleType[3] = scaleType[0];
} else {
for (int i = 0; i < 4; i++) {
double chordPicker = Math.random() * 100;
@@ -377,7 +378,8 @@ public void generateSynth() {
// time, unless things get really confusing
if (Math.random() < .75) {
synth[0] = 0;
- } else {
+ }
+ else {
if (Math.random() > .5)
synth[0] = 2;
else
@@ -471,12 +473,12 @@ else if(noteChooser < .80){
else if(noteChooser < .90){
synth[i] = 6;
}
- else{
+ else {
synth[i] = 7;
}
}
- else{
- synth[i] = -1;
+ else {
+ synth[i] = -1;
}
}
else{ // Sad tier of notes
@@ -571,20 +573,47 @@ else if(noteChooser < .90){
}
}
- for(int i = 0; i < 48; i++){
+ for(int i = 0; i < 32; i++){
synth[i + 16] = synth[i % 16];
if(Math.random() < .2 && synth[i + 16] != -1){
noteChooser = Math.random();
if(noteChooser < .3 && synth[i + 16] <= 5){
synth[i + 16] += 2;
}
- else if(noteChooser < .6 && synth[i + 16] >=2){
+ else if (noteChooser < .6 && synth[i + 16] >=2){
synth[i + 16] -= 2;
}
}
}
+
+ for (int i = 4; i < 60; i++) { // Randomly elongates each note of the melody
+ if (synth[i] == -1) {
+ double frequencyModifier = .0;
+ if (synth[i + 1] == -1 && synth[i- 1] == -1)
+ frequencyModifier += 0.1;
+ if (synth[i + 2] == -1 && synth[i - 2] == -1 && frequencyModifier > 0)
+ frequencyModifier += 0.1;
+ if (synth[i + 3] == -1 && synth[i - 3] == -1 && frequencyModifier > 0)
+ frequencyModifier += 0.1;
+ if (Math.random() > .7 - frequencyModifier && synth[i] == -1) {
+ if (synth[i - 1] != -1)
+ synth[i] = synth[i - 1];
+ else if (synth[i - 2] != -1)
+ synth[i] = synth[i - 2];
+ else if (synth[i - 3] != -1)
+ synth[i] = synth[i - 3];
+ else if (synth[i - 4] != -1)
+ synth[i] = synth[i - 4];
+ }
+ }
+ }
+ for (int i = 0; i < 15; i++){ // Last measure mirrors the first, offset by one beat to the left
+ synth[i + 48] = synth[14 - i];
+ }
+
}
+ }
/*
//>>>>>>> Fully working synth, bass, and drum generation, read the README in the java project
}
@@ -630,7 +659,6 @@ else if (noteChooser > .66)
}
}
*/
- }
/**
@@ -662,11 +690,11 @@ public void generateBass() {
bass[i] = synth[i];
}
else{
- if(Math.random() < .5 && synth[i] <= 5){
- bass[i] = synth[i] + 2;
- }
- else if(synth[i] >= 2){
- bass[i] = synth[i] - 2;
+ if(Math.random() < .5)
+ if (synth[i] <= 3)
+ bass[i] = synth[i] + 3;
+ else if(synth[i] > 3){
+ bass[i] = synth[i] - 3;
}
}
if(Math.random() < .5){
@@ -682,10 +710,12 @@ else if(synth[i] >= 2){
bass[i] = -1;
}
}
- }
-
+ }
}
-
+ for (int i = 1; i < 64; i++)
+ if (bass[i] == -1)
+ if (bass[i - 1] != -1)
+ bass[i] = bass[i - 1];
}
/**

0 comments on commit b0f359f

Please sign in to comment.