// Metronome! @cid "YGmt"; @name "Metronome!"; @dbname "Metronome!"; #define pi 3.141592 #define top 105 /*********************************** * Draw selection * ***********************************/ draw(int ang, int oldA) { int x, y, i; i = oldA; x = 80 + 59 * cos((float)(i * (float)(2 * pi / (float)top)) - (float)pi/2); y = 87 + 59 * sin((float)(i * (float)(2 * pi / (float)top)) - (float)pi/2); rect(3, x - 8, y - 8, x + 8, y + 8, 8); i = ang; x = 80 + 59 * cos((float)(i * (float)(2 * pi / (float)top)) - (float)pi/2); y = 87 + 59 * sin((float)(i * (float)(2 * pi / (float)top)) - (float)pi/2); rect(3, x - 8, y - 8, x + 8, y + 8, 8); text(80, 87, " " + i + " "); } /*********************************** * Init stuff * ***********************************/ init() { int i, x, y; clear(); puts("Written 12/29/04 for D. L. by Isaac Good for use with his guitar because \"a real metronome cost, like, $30\". Enjoy!"); event(400); graph_on(); title("Metronome"); textalign(11); textattr(0, 1, 0); for(i = 0; i < top; i = i + 5) { x = 80 + 50 * cos((float)(i * (float)(2 * pi / (float)top)) - (float)pi/2); y = 87 + 50 * sin((float)(i * (float)(2 * pi / (float)top)) - (float)pi/2); pixel(1, x, y); x = 80 + 59 * cos((float)(i * (float)(2 * pi / (float)top)) - (float)pi/2); y = 87 + 59 * sin((float)(i * (float)(2 * pi / (float)top)) - (float)pi/2); text(x, y, (i)); } // Circles frame(1, 29, 36, 131, 138, 50); frame(1, 15, 22, 145, 153, 65); frame2(1, 15, 22, 145, 153, 3, 1); // Tempo box frame(1, 65, 72, 95, 102, 0); // Ticker rect(1, 72, 59, 88, 68, 0); line(1, 80, 59, 72, 44); rect(1, 67, 38, 73, 44, 3); // Vol frame(1, 51, 103, 110, 114, 0); for(i = 0; i < 7; i++) line(1, i * 10 + 50, 103, i * 10 + 50, 114); for(i = 1; i < 6; i++) text(i * 10 + 55, 107, i); text(56, 107, "M"); rect(3, 51, 103, 60, 114, 0); clear(); } /*********************************** * Main code * ***********************************/ main() { int i = 50, e, volm = 0, old, volSel = 0; float theta, x, y; init(); text(80, 87, i); x = 80 + 59 * cos((float)(i * (float)(2 * pi / (float)top)) - (float)pi/2); y = 87 + 59 * sin((float)(i * (float)(2 * pi / (float)top)) - (float)pi/2); rect(3, x - 8, y - 8, x + 8, y + 8, 8); old = i; do { // Nothing e = event(3 * (100 - i)); if(!e) { resetaot(); tonea(600, 50, volm); line(3, 80, 59, 72, 44); rect(3, 67, 38, 73, 44, 3); line(3, 80, 59, 88, 44); rect(3, 87, 38, 93, 44, 3); } // Pen down in tempo/volume button else if(e == 2) { // Tempo if(penx() > 65 && penx() < 95 && peny() > 72 && peny() < 102) { i = gets("How much, huh?"); i = i % 100; draw(i, old); old = i; // Volume } else if(penx() > 51 && penx() < 110 && peny() > 102 && peny() < 112) { rect(3, volSel * 10 + 51, 103, volSel * 10 + 60, 114, 0); volSel = (penx() - 50) / 10; rect(3, volSel * 10 + 51, 103, volSel * 10 + 60, 114, 0); if(volSel != 0) volm = pow(2, 4 + volSel); else volm = 0; // Streen pen down - select tempo } else { x = penx() - 80; // Prevent div by 0 error if(x == 0) i = 0; else { // Find tap angle y = peny() - 87; theta = (atan(y / x)) + (float)(pi / (float)2); i = (float)105 * (float)theta / (float)((float)2 * pi); if(x < 0) i = 52 + i; } i = i % 100; draw(i, old); old = i; } // Hard up button } else if(e == 5) { if(i < 100) { i++; draw(i, old); old = i; } // Hard down button } else if(e == 6) { if(i > 0) { i--; draw(i, old); old = i; } } } while(1); }