Skip to content
Snippets Groups Projects
Commit 77f6a14b authored by Jonathan Lane-Smith's avatar Jonathan Lane-Smith
Browse files

Update CircleModel to have equal slices

parent 98f6a77c
No related branches found
No related tags found
No related merge requests found
......@@ -4,20 +4,21 @@ class CircleModel extends Model {
// Keys: C C# D Eb E F F# G G# A Bb B // Scales
int[] chromatic = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // 0
int[] major = {0, 0, 2, 2, 4, 5, 5, 7, 7, 9, 9, 11}; // 1
int[] minor = {0, 0, 2, 3, 3, 5, 5, 7, 8, 8, 8, 11}; // 2
int[] blues = {0, 0, 0, 3, 3, 5, 6, 7, 7, 7, 10, 10}; // 3
int[] penta = {0, 0, 2, 2, 4, 4, 4, 7, 7, 9, 9, 9}; // 4
int[] major = {0, 2, 4, 5, 7, 9, 11,0, 0, 0, 0, 0}; // 1
int[] minor = {0, 2, 3, 5, 7, 8, 11,0, 0, 0, 0, 0}; // 2
int[] blues = {0, 3, 5, 6, 7, 10,0, 0, 0, 0, 0, 0}; // 3
int[] penta = {0, 2, 4, 7, 9, 0, 0, 0, 0, 0, 0, 0}; // 4
int initialKeyNum = 10; // C, C#, ...
int initialKeyNum = 0; // C, C#, ...
int initialScaleNum = 1; // chromatic, major, ...
int[][] allScales = {chromatic, major, minor, blues, penta};
int[] scaleLengths = {12, 7, 7, 6, 5};
String[] keys = {"C", "C#", "D", "Eb", "E", "F", "F#", "G", "G#", "A", "Bb", "B", "C", "C#", "D", "Eb", "E"};
String[] scaleNames = {"Chromatic", "Major", "Minor", "Blues", "Pentatonic"};
String[] scaleNamesShort = {"Chrom", "Major", "Minor", "Blues", "Penta"};
String[] noteNames = {"C3", "C#3", "D3", "Eb3", "E3", "F3", "F#3", "G3", "G#3", "A4", "Bb4", "B4", "C4", "C#4", "D4", "Eb4", "E4", "F4", "F#4", "G4", "G#4", "A5", "Bb5", "B5"};
String[] noteNames = {"C3", "C#3", "D3", "Eb3", "E3", "F3", "F#3", "G3", "G#3", "A4", "Bb4", "B4", "C4", "C#4", "D4", "Eb4", "E4", "F4", "F#4", "G4", "G#4", "A5", "Bb5", "B5", "C5", "C#5", "D5", "Eb5", "E5", "F5", "F#5", "G5", "G#5", "A6", "Bb6", "B6", };
int[] pitches = new int[24];
String pitchLetter = "";
......@@ -32,7 +33,7 @@ class CircleModel extends Model {
int selectedSlot = 0;
float circleCenterY = 0.085;
float innerRadius = 0.040;
float innerRadius = 0.035;
float outerRadius = 0.060;
StringMaterial[] strings = new StringMaterial[57];
......@@ -46,7 +47,7 @@ class CircleModel extends Model {
float maxPositive = 0;
float maxNegative = 0;
boolean isVibrato = false;
float movementThreshold = 2;
float movementThreshold = 1;//2;
long timeThreshold = 200;
boolean menuVisible = true;
......@@ -91,11 +92,6 @@ class CircleModel extends Model {
/* create pantagraph graphics */
create_pantagraph();
for (int i = 0; i < 24; i++) {
int angle = 180 - i*15;
innerPoints[i] = new PVector(innerRadius * sin(angle*PI/180), innerRadius * cos(angle*PI/180) + circleCenterY);
outerPoints[i] = new PVector(outerRadius * sin(angle*PI/180), outerRadius * cos(angle*PI/180) + circleCenterY);
}
circles[0] = new StringMaterialCircle(0, circleCenterY, outerRadius, 800, pixelsPerMeter, deviceOrigin);
circles[1] = new StringMaterialCircle(0, circleCenterY, innerRadius, 700, pixelsPerMeter, deviceOrigin);
circles[2] = new StringMaterialCircle(menuX, menuY, menuRadius, 300, pixelsPerMeter, deviceOrigin);
......@@ -118,43 +114,28 @@ class CircleModel extends Model {
}
void create_spokes() {
int[] scale = allScales[getScale()];
for (int i = 0; i < pitches.length; i++) {
if (i < 12)
pitches[i] = scale[i];
else
pitches[i] = scale[i-12] + 12;
}
int[] oldPitches = pitches.clone();
for (int i = 0; i < pitches.length; i++) {
if (i - getKey() >= 0)
pitches[i] = oldPitches[i - getKey()] + getKey();
else {
pitches[i] = oldPitches[i - getKey() + 12] + getKey() - 12;
}
}
if (pitches [0] < 0) {
pitches[0] = pitches[23];
int scaleLength = scaleLengths[getScale()];
for (int i = 0; i < scaleLength*2; i++) {
float angle = 180 - i*((float)360/(scaleLength*2));
innerPoints[i] = new PVector(innerRadius * sin(angle*PI/180), innerRadius * cos(angle*PI/180) + circleCenterY);
outerPoints[i] = new PVector(outerRadius * sin(angle*PI/180), outerRadius * cos(angle*PI/180) + circleCenterY);
}
if (pitches [1] < 0) {
pitches[1] = pitches[23];
}
for (int i = 0; i < 24; i++) {
float centroid = 0; // notes away from center
if (pitches[(i-2+24)%24] == pitches[i]) {centroid -= 0.5;}
if (pitches[(i-1+24)%24] == pitches[i]) {centroid -= 0.5;}
if (pitches[(i+1)%24] == pitches[i]) {centroid += 0.5;}
if (pitches[(i+2)%24] == pitches[i]) {centroid += 0.5;}
magnetPosition[i] = i + centroid;
for (int i = 0; i < scaleLength*2; i++) {
if (i < scaleLength)
pitches[i] = scale[i] + getKey();
else
pitches[i] = scale[i-scaleLength] + 12 + getKey();
}
for (int i = 0; i < 24; i++) {
if ((i==0 && pitches[0] != pitches[23]) || i>0 && pitches[i] != pitches[i-1]) {
strings[i] = new StringMaterial(innerPoints[i].x, innerPoints[i].y, outerPoints[i].x, outerPoints[i].y, 350, pixelsPerMeter, deviceOrigin);
if (i < scaleLength*2) {
strings[i] = new StringMaterial(innerPoints[i].x, innerPoints[i].y, outerPoints[i].x, outerPoints[i].y, 300, pixelsPerMeter, deviceOrigin);
} else {
strings[i] = null;
strings[i] = null;
}
}
}
......@@ -194,7 +175,7 @@ class CircleModel extends Model {
float xVeloc = (posEE.x - xPositions[positionCounter])*1000;
float yVeloc = (posEE.y - yPositions[positionCounter])*1000;
float veloc = sqrt(pow(xVeloc,2) + pow(yVeloc,2)) * ((xVeloc > 0) ? 1 : -1);
if (returnValue.justCrossedString && sqrt(pow(posEE.x-menuX,2) + pow(posEE.y-menuY,2)) < menuRadius) {
menuVisible = !menuVisible;
} else if (menuVisible && posEE.x < -0.08) {
......@@ -215,8 +196,9 @@ class CircleModel extends Model {
} else {
// Calculate pitch
int scaleLength = scaleLengths[getScale()];
float angle = atan2(-posEE.x, (posEE.y-circleCenterY))/PI*180 +180;
int pos = min(floor((angle)/15),23); // Make sure it's never 24
int pos = min(floor((angle)/((float)360/(scaleLength*2))),23); // Make sure it's never 24
float distFromMiddle = sqrt(pow(posEE.y - circleCenterY,2) + pow(posEE.x, 2));
if (returnValue.justCrossedString) { // If just moved across a string
isVibrato = false;
......@@ -241,18 +223,18 @@ class CircleModel extends Model {
}
}
// Figure out magnetic force
float centroidAngle = (magnetPosition[pos]*15+7.5)/180*PI;
float centroidAngle = ((pos+0.5)*(360/(scaleLengths[getScale()]*2)))/180*PI;
PVector centroid = new PVector((innerRadius+outerRadius)/2*sin(centroidAngle), -(innerRadius+outerRadius)/2*cos(centroidAngle) + circleCenterY);
float angleToCentroid = atan2((posEE.x-centroid.x), (posEE.y-centroid.y)) + PI;
float distanceToCentroid = sqrt(pow(posEE.x - centroid.x,2)+pow(posEE.y-centroid.y,2));
float xComponent = 200 * distanceToCentroid * sin(angleToCentroid);
float yComponent = 200 * distanceToCentroid * cos(angleToCentroid);
forceEE.add(new PVector(xComponent, yComponent));
float xComponent = 150 * distanceToCentroid * sin(angleToCentroid);
float yComponent = 150 * distanceToCentroid * cos(angleToCentroid);
//forceEE.add(new PVector(xComponent, yComponent)); // magnet creates more problems than solves
}
if (continuousPitch) {
pitchLetter = "";
pitchMIDI = 59.5 + angle/360*24;
pitchMIDI = 59.5 + angle/360*24 + getKey();
}
pitchFreq = pow(2,(pitchMIDI-69)/12) * 440 * (isVibrato ? 1+veloc/100 : 1); // Convert MIDI note number into frequency
message = new float[]{pitchFreq};
......@@ -308,12 +290,11 @@ class CircleModel extends Model {
}
}
}
for (int i = 0; i < 24; i++) {
if ((i==0 && pitches[0] != pitches[23]) || i>0 && pitches[i] != pitches[i-1]) {
int angle = i*15+8;
float meanRad = (innerRadius + outerRadius)/2;
text(noteNames[i], 485 + meanRad*sin(angle*PI/180)*pixelsPerMeter, 4000*0.085 + 5 - meanRad*cos(angle*PI/180)*pixelsPerMeter);
}
for (int i = 0; i < scaleLengths[getScale()]*2; i++) {
float segment = (float)360/(scaleLengths[getScale()]*2);
float angle = i*segment+segment/2;
float meanRad = (innerRadius + outerRadius)/2;
text(noteNames[allScales[getScale()][i%scaleLengths[getScale()]] + getKey() + (i < scaleLengths[getScale()] ? 0 : 12)], 485 + meanRad*sin(angle*PI/180)*pixelsPerMeter, 4000*0.085 + 5 - meanRad*cos(angle*PI/180)*pixelsPerMeter);
}
xE = pixelsPerMeter * xE;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment