summaryrefslogtreecommitdiff
path: root/noncore/multimedia/powerchord/chordengine.h
blob: 44b738830283cccef19b336815a13dbc9acb651a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//
// ChordEngine class to calculate chords
//

// Copyright (c) 2001 Camilo Mesias
// camilo@mesias.co.uk
//
// derived from JavaScript code by Jim Cranwell, used with permission
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.


#ifndef __CHORDENGINE_H
#define __CHORDENGINE_H

#include <stdio.h>

class ChordEngine;

class ChordEngine {

 private:
  //saved state

  int base_note;
  int chord_type;
  int fret_pos;
  int span_size;
  int variation;
  int tuning;
  
  int string[6];
  const char *notename[6];

  // unfathomable stuff ported from javascript: js_prefix
  // may ask Jim Cranwell if he'd like to comment on it
  int js_MMM[6];
  int note_indices[6];

  void js_tunit(int t);

  int js_T[12];

  void js_whatchord(int c);

  int js_L, js_Y, js_Z, js_VM;

  void js_vboy(int v);

  // stuff I put in
  char label_text[20];
  static const int chordbases[][12];
  static const int alt_tunings[][6];

 public:
  static const char* notes[];
  static const char* keys[];
  static const char* frets[];
  static const char* variations[];
  static const char* tunings[];


  static const int OPEN = 0;
  static const int MUTED = 7;

  ChordEngine();

  // accessors
  const char *name(int f){return notename[f];};
  int noteindex(int f){
    if (string[f] == MUTED){
      return -1;
    }else{
      return note_indices[f] + string[f];
    }
  };

  void base(int b){base_note = b;};
  int base(){return base_note;};

  void chord(int c){chord_type = c; js_whatchord(c);};
  int chord(){return chord_type;};

  void fret(int f){fret_pos = f;};
  int fret(){return fret_pos;};

  void span(int s){span_size = s;};
  int span(){return span_size;};

  void vary(int v){variation = v; js_vboy(v);};
  int vary(){return variation;};

  void tune(int t){tuning = t; js_tunit(t);};
  int tune(){return tuning;};

  // methods
  void calculate();

  const char *label(){return label_text;};
  
  int finger(int string); // returns fret position or MUTED

};

#endif