summaryrefslogtreecommitdiff
path: root/noncore/multimedia/powerchord/fretboard.cpp
Unidiff
Diffstat (limited to 'noncore/multimedia/powerchord/fretboard.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/powerchord/fretboard.cpp234
1 files changed, 234 insertions, 0 deletions
diff --git a/noncore/multimedia/powerchord/fretboard.cpp b/noncore/multimedia/powerchord/fretboard.cpp
new file mode 100644
index 0000000..0687d00
--- a/dev/null
+++ b/noncore/multimedia/powerchord/fretboard.cpp
@@ -0,0 +1,234 @@
1//
2// FretBoard class to display interface for chord finder application
3//
4
5// Copyright (c) 2001 Camilo Mesias
6// camilo@mesias.co.uk
7//
8// This program is free software; you can redistribute it and/or
9// modify it under the terms of the GNU General Public License
10// as published by the Free Software Foundation; either version 2
11// of the License, or (at your option) any later version.
12//
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
22//#include <FL/Fl.H>
23//#include <FL/Fl_Widget.H>
24//#include <FL/fl_draw.H>
25#include <stdio.h>
26#include <qpixmap.h>
27#include <qpe/resource.h>
28#include "fretboard.h"
29#include <qpainter.h>
30
31void FretBoard::refresh(){
32 ce.calculate();
33
34 emit nameChanged(QString(ce.label()));
35
36 for (int i=0;i<6;i++){
37 Finger(i, ce.finger(i));
38 // yuk
39 switch (i) {
40 case 0:
41 emit s1nameChanged(QString(ce.name(i)));
42 break;
43 case 1:
44 emit s2nameChanged(QString(ce.name(i)));
45 break;
46 case 2:
47 emit s3nameChanged(QString(ce.name(i)));
48 break;
49 case 3:
50 emit s4nameChanged(QString(ce.name(i)));
51 break;
52 case 4:
53 emit s5nameChanged(QString(ce.name(i)));
54 break;
55 case 5:
56 emit s6nameChanged(QString(ce.name(i)));
57 break;
58 }
59 }
60
61 update();
62}
63
64FretBoard::FretBoard(QWidget *parent, const char *name )
65 : QWidget( parent, name ), ce()
66{
67
68 ce.base(9);
69 ce.chord(0);
70 ce.fret(0);
71 ce.span(1);
72 ce.vary(7);
73 ce.tune(0);
74 refresh();
75
76 // setPalette( QPalette( QColor( 250, 250, 200) ) );
77
78 stringtop_pix = Resource::loadPixmap( "powerchord/stringtop_s");
79 string_pix = Resource::loadPixmap( "powerchord/string_s");
80 finger_pix = Resource::loadPixmap( "powerchord/justfing_s");
81 mute_pix = Resource::loadPixmap( "powerchord/muted_s");
82
83 // box(FL_NO_BOX);
84
85 // finger[0] = OPEN;
86 // finger[1] = OPEN;
87 // finger[2] = OPEN;
88 // finger[3] = OPEN;
89 // finger[4] = OPEN;
90 // finger[5] = OPEN;
91
92 initial_fret = 0;
93
94 // label(FL_NORMAL_LABEL, "Chord");
95}
96
97// int FretBoard::Finger(int f){
98// if (f < 0 || f > 5){
99// fprintf(stderr, "Error - finger value was %d\n", f);
100// return 0;
101// }
102// return finger[f];
103// }
104
105void FretBoard::Finger(int f, int position){
106 if (f < 0 || f > 5){
107 fprintf(stderr, "Error - finger2 value was %d\n", f);
108 return;
109 }
110
111 finger[f] = position;
112}
113
114// void FretBoard::draw(void) {
115// draw_box();
116// draw_label();
117// }
118
119// void FretBoard::draw_label(void) {
120// align(FL_ALIGN_CENTER | FL_ALIGN_TOP | FL_ALIGN_WRAP);
121
122// this->Fl_Widget::draw_label();
123// }
124
125
126//void FretBoard::draw_box(void) {
127
128void FretBoard::paintEvent(QPaintEvent *){
129
130 // fl_color(FL_WHITE);
131
132 // Fl_Widget::draw_box();
133
134 // fl_color(FL_BLACK);
135
136 QPainter p( this );
137
138 p.setBrush(black);
139 p.translate(0, 0);
140
141 // draw each string
142 for (int f=0; f<=5; f++){
143 // draw a string starting from the highest visible fret
144 for (int pp=0; pp<=6; pp++){
145 int this_fret = initial_fret + pp;
146 int cx = /* x() + */ 28*f;
147 int cy = /* y() + */ pp*30;
148
149 //fl_color(FL_WHITE);
150 // fl_rectf(cx, cy, 24, 24);
151 // p.setBrush(white);
152 // p.setPen(NoPen);
153
154 // p.drawRect( QRect(cx, cy, 24, 24) );
155// fl_color(FL_BLACK);
156 // p.setBrush(black);
157
158 // p.setPen(black);
159
160 // draw the string unless at top
161 if (this_fret!=0){
162 //fl_line(cx+12, cy, cx+12, cy+23);
163 //p.drawLine(cx+12, cy, cx+12, cy+23);
164 }
165
166 // draw mutes if at top
167 if (pp == 0 &&
168 finger[f] == MUTED){
169 p.drawPixmap(cx,cy,mute_pix);
170 //fl_line(cx+4, cy+19, cx+19, cy+4);
171 //p.drawLine(cx+4, cy+19, cx+19, cy+4);
172 //fl_line(cx+5, cy+19, cx+20, cy+4);
173 //p.drawLine(cx+5, cy+19, cx+20, cy+4);
174 //fl_line(cx+4, cy+4, cx+19, cy+19);
175 //p.drawLine(cx+4, cy+4, cx+19, cy+19);
176 //fl_line(cx+5, cy+4, cx+20, cy+19);
177 //p.drawLine(cx+5, cy+4, cx+20, cy+19);
178 }
179
180 if (this_fret==0){
181 // above, blank
182 }else if(this_fret==1){
183 // top
184 p.drawPixmap(cx,cy,stringtop_pix);
185 }else{
186 // normal
187 p.drawPixmap(cx,cy,string_pix);
188 }
189
190 // frets at bottom
191 // thick line if at top
192 // int x0 = (f==0)?(cx+12):cx;
193 // int x1 = (f==5)?(cx+12):(cx+23);
194 // for (int offset=23; offset>((this_fret==0)?20:22); offset--){
195 //fl_line(x0, cy+offset, x1, cy+offset);
196 //p.drawLine(x0, cy+offset, x1, cy+offset);
197 // }
198
199 // finger if at that position
200 if ((initial_fret==0 && pp == finger[f]) ||
201 (initial_fret!=0 && pp == finger[f]-8)){
202 p.drawPixmap(cx,cy,finger_pix);
203
204 // fl_color(FL_WHITE);
205 // p.setBrush(white);
206 // p.setPen(NoPen);
207
208 // fl_rectf(cx+4, cy+4, 16, 16);
209 //p.drawRect( QRect(cx+4, cy+4, 16, 16));
210// fl_color(FL_BLACK);
211 //p.setPen(black);
212 // fl_line(cx+4, cy+11, cx+7, cy+16);
213 //p.drawLine(cx+4, cy+11, cx+7, cy+16);
214 // fl_line(cx+7, cy+16, cx+12, cy+19);
215 //p.drawLine(cx+7, cy+16, cx+12, cy+19);
216 // fl_line(cx+12, cy+19, cx+16, cy+16);
217 //p.drawLine(cx+12, cy+19, cx+16, cy+16);
218 // fl_line(cx+16, cy+16, cx+19, cy+12);
219 //p.drawLine(cx+16, cy+16, cx+19, cy+12);
220 // fl_line(cx+19, cy+12, cx+16, cy+7);
221 //p.drawLine(cx+19, cy+12, cx+16, cy+7);
222 // fl_line(cx+16, cy+7, cx+12, cy+4);
223 //p.drawLine(cx+16, cy+7, cx+12, cy+4);
224 // fl_line(cx+11, cy+4, cx+7, cy+7);
225 //p.drawLine(cx+11, cy+4, cx+7, cy+7);
226 // fl_line(cx+7, cy+7, cx+4, cy+11);
227 //p.drawLine(cx+7, cy+7, cx+4, cy+11);
228 }
229 }
230 }
231 p.end();
232}
233
234