Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

fretboard.cpp

Go to the documentation of this file.
00001 //
00002 // FretBoard class to display interface for chord finder application
00003 //
00004 
00005 // Copyright (c) 2001 Camilo Mesias
00006 // camilo@mesias.co.uk
00007 //
00008 // This program is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU General Public License
00010 // as published by the Free Software Foundation; either version 2
00011 // of the License, or (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00021 
00022 #include "fretboard.h"
00023 
00024 #include <opie2/oresource.h>
00025 
00026 #include <qpainter.h>
00027 
00028 void FretBoard::refresh(){
00029   ce.calculate();
00030 
00031   emit nameChanged(QString(ce.label()));
00032 
00033   for (int i=0;i<6;i++){
00034     Finger(i, ce.finger(i));
00035     // yuk
00036     switch (i) {
00037     case 0:
00038       emit s1nameChanged(QString(ce.name(i)));
00039       break;
00040     case 1:
00041       emit s2nameChanged(QString(ce.name(i)));
00042       break;
00043     case 2:
00044       emit s3nameChanged(QString(ce.name(i)));
00045       break;
00046     case 3:
00047       emit s4nameChanged(QString(ce.name(i)));
00048       break;
00049     case 4:
00050       emit s5nameChanged(QString(ce.name(i)));
00051       break;
00052     case 5:
00053       emit s6nameChanged(QString(ce.name(i)));
00054       break;
00055     }
00056   }
00057 
00058   update();
00059 }
00060 
00061 FretBoard::FretBoard(QWidget *parent, const char *name )
00062   : QWidget( parent, name ), ce()
00063 {
00064   
00065   ce.base(9);
00066   ce.chord(0);
00067   ce.fret(0);
00068   ce.span(1);
00069   ce.vary(7);
00070   ce.tune(0);
00071   refresh();
00072 
00073   //  setPalette( QPalette( QColor( 250, 250, 200) ) );
00074 
00075   stringtop_pix = Opie::Core::OResource::loadPixmap( "powerchord/stringtop_s");
00076   string_pix = Opie::Core::OResource::loadPixmap( "powerchord/string_s");
00077   finger_pix = Opie::Core::OResource::loadPixmap( "powerchord/justfing_s");
00078   mute_pix = Opie::Core::OResource::loadPixmap( "powerchord/muted_s");
00079 
00080   //  box(FL_NO_BOX);
00081 
00082   //  finger[0] = OPEN;
00083   //  finger[1] = OPEN;
00084   //  finger[2] = OPEN;
00085   //  finger[3] = OPEN;
00086   //  finger[4] = OPEN;
00087   //  finger[5] = OPEN;
00088 
00089   initial_fret = 0;
00090 
00091   //  label(FL_NORMAL_LABEL, "Chord");
00092 }
00093 
00094 //  int FretBoard::Finger(int f){
00095 //    if (f < 0 || f > 5){
00096 //      fprintf(stderr, "Error - finger value was %d\n", f);
00097 //      return 0;
00098 //    }
00099 //    return finger[f];
00100 //  }
00101 
00102 void FretBoard::Finger(int f, int position){
00103   if (f < 0 || f > 5){
00104     fprintf(stderr, "Error - finger2 value was %d\n", f);
00105     return;
00106   }
00107   
00108   finger[f] = position;
00109 }
00110 
00111 //  void FretBoard::draw(void) {
00112 //    draw_box();
00113 //    draw_label();
00114 //  }
00115 
00116 //  void FretBoard::draw_label(void) {
00117 //    align(FL_ALIGN_CENTER | FL_ALIGN_TOP | FL_ALIGN_WRAP);
00118 
00119 //    this->Fl_Widget::draw_label();
00120 //  }
00121 
00122 
00123 //void FretBoard::draw_box(void) {
00124   
00125 void FretBoard::paintEvent(QPaintEvent *){
00126 
00127   //  fl_color(FL_WHITE);
00128 
00129   //  Fl_Widget::draw_box();
00130 
00131   //  fl_color(FL_BLACK);
00132 
00133   QPainter p( this );
00134 
00135   p.setBrush(black);
00136   p.translate(0, 0);
00137 
00138   // draw each string
00139   for (int f=0; f<=5; f++){
00140     // draw a string starting from the highest visible fret
00141     for (int pp=0; pp<=6; pp++){
00142       int this_fret = initial_fret + pp;
00143       int cx = /* x() + */ 28*f;
00144       int cy = /* y() + */ pp*30;
00145 
00146       //        fl_color(FL_WHITE);
00147 //      fl_rectf(cx, cy, 24, 24);
00148       //      p.setBrush(white);
00149       //      p.setPen(NoPen);
00150 
00151       //      p.drawRect( QRect(cx, cy, 24, 24) );
00152 //          fl_color(FL_BLACK);
00153       //      p.setBrush(black);
00154 
00155       //      p.setPen(black);
00156 
00157       // draw the string unless at top
00158       if (this_fret!=0){
00159         //      fl_line(cx+12, cy, cx+12, cy+23);
00160         //      p.drawLine(cx+12, cy, cx+12, cy+23);
00161       }
00162 
00163       // draw mutes if at top
00164       if (pp == 0 &&
00165           finger[f] == MUTED){
00166         p.drawPixmap(cx,cy,mute_pix);
00167         //      fl_line(cx+4, cy+19, cx+19, cy+4);
00168         //      p.drawLine(cx+4, cy+19, cx+19, cy+4);
00169         //      fl_line(cx+5, cy+19, cx+20, cy+4);
00170         //      p.drawLine(cx+5, cy+19, cx+20, cy+4);
00171         //      fl_line(cx+4, cy+4, cx+19, cy+19);
00172         //      p.drawLine(cx+4, cy+4, cx+19, cy+19);
00173         //      fl_line(cx+5, cy+4, cx+20, cy+19);
00174         //      p.drawLine(cx+5, cy+4, cx+20, cy+19);
00175       }
00176 
00177       if (this_fret==0){
00178         // above, blank
00179       }else if(this_fret==1){
00180         // top
00181         p.drawPixmap(cx,cy,stringtop_pix);
00182       }else{
00183         // normal
00184         p.drawPixmap(cx,cy,string_pix);
00185       }
00186 
00187       // frets at bottom
00188       // thick line if at top
00189       //      int x0 = (f==0)?(cx+12):cx;
00190       //      int x1 = (f==5)?(cx+12):(cx+23);
00191       //      for (int offset=23; offset>((this_fret==0)?20:22); offset--){
00192         //      fl_line(x0, cy+offset, x1, cy+offset);
00193         //      p.drawLine(x0, cy+offset, x1, cy+offset);
00194       //      }
00195 
00196       // finger if at that position
00197       if ((initial_fret==0 && pp == finger[f]) ||
00198           (initial_fret!=0 && pp == finger[f]-8)){
00199         p.drawPixmap(cx,cy,finger_pix);
00200 
00201 //      fl_color(FL_WHITE);
00202 //      p.setBrush(white);
00203 //      p.setPen(NoPen);
00204         
00205 //      fl_rectf(cx+4, cy+4, 16, 16);
00206         //      p.drawRect( QRect(cx+4, cy+4, 16, 16));
00207 //          fl_color(FL_BLACK);
00208         //p.setPen(black);
00209 //      fl_line(cx+4, cy+11, cx+7, cy+16);
00210         //p.drawLine(cx+4, cy+11, cx+7, cy+16);
00211 //      fl_line(cx+7, cy+16, cx+12, cy+19);
00212         //p.drawLine(cx+7, cy+16, cx+12, cy+19);
00213 //      fl_line(cx+12, cy+19, cx+16, cy+16);
00214         //p.drawLine(cx+12, cy+19, cx+16, cy+16);
00215 //      fl_line(cx+16, cy+16, cx+19, cy+12);
00216         //p.drawLine(cx+16, cy+16, cx+19, cy+12);
00217 //      fl_line(cx+19, cy+12, cx+16, cy+7);
00218         //p.drawLine(cx+19, cy+12, cx+16, cy+7);
00219 //      fl_line(cx+16, cy+7, cx+12, cy+4);
00220         //p.drawLine(cx+16, cy+7, cx+12, cy+4);
00221 //      fl_line(cx+11, cy+4, cx+7, cy+7);
00222         //p.drawLine(cx+11, cy+4, cx+7, cy+7);
00223 //      fl_line(cx+7, cy+7, cx+4, cy+11);
00224         //p.drawLine(cx+7, cy+7, cx+4, cy+11);
00225       }
00226     }
00227   }
00228   p.end();
00229 }
00230 
00231 

Generated on Sat Nov 5 16:17:34 2005 for OPIE by  doxygen 1.4.2