00001 // 00002 // ChordEngine class to calculate chords 00003 // 00004 00005 // Copyright (c) 2001 Camilo Mesias 00006 // camilo@mesias.co.uk 00007 // 00008 // derived from JavaScript code by Jim Cranwell, used with permission 00009 // 00010 // This program is free software; you can redistribute it and/or 00011 // modify it under the terms of the GNU General Public License 00012 // as published by the Free Software Foundation; either version 2 00013 // of the License, or (at your option) any later version. 00014 // 00015 // This program is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU General Public License 00021 // along with this program; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00023 00024 00025 #ifndef __CHORDENGINE_H 00026 #define __CHORDENGINE_H 00027 00028 #include <stdio.h> 00029 00030 class ChordEngine; 00031 00032 class ChordEngine { 00033 00034 private: 00035 //saved state 00036 00037 int base_note; 00038 int chord_type; 00039 int fret_pos; 00040 int span_size; 00041 int variation; 00042 int tuning; 00043 00044 int string[6]; 00045 const char *notename[6]; 00046 00047 // unfathomable stuff ported from javascript: js_prefix 00048 // may ask Jim Cranwell if he'd like to comment on it 00049 int js_MMM[6]; 00050 int note_indices[6]; 00051 00052 void js_tunit(int t); 00053 00054 int js_T[12]; 00055 00056 void js_whatchord(int c); 00057 00058 int js_L, js_Y, js_Z, js_VM; 00059 00060 void js_vboy(int v); 00061 00062 // stuff I put in 00063 char label_text[20]; 00064 static const int chordbases[][12]; 00065 static const int alt_tunings[][6]; 00066 00067 public: 00068 static const char* notes[]; 00069 static const char* keys[]; 00070 static const char* frets[]; 00071 static const char* variations[]; 00072 static const char* tunings[]; 00073 00074 00075 static const int OPEN = 0; 00076 static const int MUTED = 7; 00077 00078 ChordEngine(); 00079 00080 // accessors 00081 const char *name(int f){return notename[f];}; 00082 int noteindex(int f){ 00083 if (string[f] == MUTED){ 00084 return -1; 00085 }else{ 00086 return note_indices[f] + string[f]; 00087 } 00088 }; 00089 00090 void base(int b){base_note = b;}; 00091 int base(){return base_note;}; 00092 00093 void chord(int c){chord_type = c; js_whatchord(c);}; 00094 int chord(){return chord_type;}; 00095 00096 void fret(int f){fret_pos = f;}; 00097 int fret(){return fret_pos;}; 00098 00099 void span(int s){span_size = s;}; 00100 int span(){return span_size;}; 00101 00102 void vary(int v){variation = v; js_vboy(v);}; 00103 int vary(){return variation;}; 00104 00105 void tune(int t){tuning = t; js_tunit(t);}; 00106 int tune(){return tuning;}; 00107 00108 // methods 00109 void calculate(); 00110 00111 const char *label(){return label_text;}; 00112 00113 int finger(int string); // returns fret position or MUTED 00114 00115 }; 00116 00117 #endif 00118 00119 00120 00121 00122 00123 00124
1.4.2