summaryrefslogtreecommitdiff
path: root/noncore/multimedia/tonleiter/fretboard.cpp
Unidiff
Diffstat (limited to 'noncore/multimedia/tonleiter/fretboard.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/tonleiter/fretboard.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/noncore/multimedia/tonleiter/fretboard.cpp b/noncore/multimedia/tonleiter/fretboard.cpp
index 7e63e01..58bdb86 100644
--- a/noncore/multimedia/tonleiter/fretboard.cpp
+++ b/noncore/multimedia/tonleiter/fretboard.cpp
@@ -1,54 +1,59 @@
1#include "fretboard.h" 1#include "fretboard.h"
2 2
3/* OPIE */
4#include <opie2/odebug.h>
5using namespace Opie::Core;
6
7/* QT */
3#include <qpainter.h> 8#include <qpainter.h>
4 9
5Graph::FretBoard::FretBoard(TonleiterData* data,QWidget* parent,const char* name,WFlags f) 10Graph::FretBoard::FretBoard(TonleiterData* data,QWidget* parent,const char* name,WFlags f)
6:QWidget(parent,name,f),data(data) 11:QWidget(parent,name,f),data(data)
7{ 12{
8 setBackgroundColor(QColor(0,0,0)); 13 setBackgroundColor(QColor(0,0,0));
9 fretpen=QPen(QColor(155,155,155),0); 14 fretpen=QPen(QColor(155,155,155),0);
10 markerbrush=QBrush(QColor(155,155,155)); 15 markerbrush=QBrush(QColor(155,155,155));
11 stringpen=QPen(QColor(255,255,255),3); 16 stringpen=QPen(QColor(255,255,255),3);
12 connect(data,SIGNAL(dataChange()),this,SLOT(dataChange())); 17 connect(data,SIGNAL(dataChange()),this,SLOT(dataChange()));
13} 18}
14//**************************************************************************** 19//****************************************************************************
15Graph::FretBoard::~FretBoard() 20Graph::FretBoard::~FretBoard()
16{ 21{
17} 22}
18//**************************************************************************** 23//****************************************************************************
19void Graph::FretBoard::dataChange() 24void Graph::FretBoard::dataChange()
20{ 25{
21 repaint(true); 26 repaint(true);
22} 27}
23//**************************************************************************** 28//****************************************************************************
24void Graph::FretBoard::paintEvent(QPaintEvent* pe) 29void Graph::FretBoard::paintEvent(QPaintEvent* pe)
25{ 30{
26 Q_UNUSED(pe); 31 Q_UNUSED(pe);
27 32
28 int instid=data->getCurrentInstrumentID(); 33 int instid=data->getCurrentInstrumentID();
29 inst=data->getInstrument(instid); 34 inst=data->getInstrument(instid);
30 //qDebug("inst %d is %s",instid,inst.instName().data()); 35 //odebug << "inst " << instid << " is " << inst.instName().data() << "" << oendl;
31 36
32 QRect mysize=rect(); 37 QRect mysize=rect();
33 38
34 xmargin=(int)(mysize.width()*0.05); 39 xmargin=(int)(mysize.width()*0.05);
35 xmin=2*xmargin; 40 xmin=2*xmargin;
36 xmax=mysize.width()-xmargin; 41 xmax=mysize.width()-xmargin;
37 xwidth=xmax-xmin; 42 xwidth=xmax-xmin;
38 43
39 ymargin=(int)(mysize.height()*0.1); 44 ymargin=(int)(mysize.height()*0.1);
40 ymin=ymargin; 45 ymin=ymargin;
41 ymax=mysize.height()-2*ymargin; 46 ymax=mysize.height()-2*ymargin;
42 yheight=ymax-ymin; 47 yheight=ymax-ymin;
43 48
44 QPainter p(this); 49 QPainter p(this);
45 paintBoard(&p); 50 paintBoard(&p);
46 paintFrets(&p); 51 paintFrets(&p);
47 paintStrings(&p); 52 paintStrings(&p);
48 paintScale(&p); 53 paintScale(&p);
49} 54}
50//**************************************************************************** 55//****************************************************************************
51void Graph::FretBoard::resizeEvent(QResizeEvent* re) 56void Graph::FretBoard::resizeEvent(QResizeEvent* re)
52{ 57{
53 Q_UNUSED(re); 58 Q_UNUSED(re);
54} 59}
@@ -122,59 +127,59 @@ void Graph::FretBoard::paintStrings(QPainter* p)
122 } 127 }
123} 128}
124//**************************************************************************** 129//****************************************************************************
125void Graph::FretBoard::paintScale(QPainter* p) 130void Graph::FretBoard::paintScale(QPainter* p)
126{ 131{
127 int dotsize=10; 132 int dotsize=10;
128 int scaleid=data->getCurrentScaleID(); 133 int scaleid=data->getCurrentScaleID();
129 Scale scale=data->getScale(scaleid); 134 Scale scale=data->getScale(scaleid);
130 int baseoctave=Note::octaveOfBaseNote(data->getCurrentBaseNote(),inst.lowestNote()); 135 int baseoctave=Note::octaveOfBaseNote(data->getCurrentBaseNote(),inst.lowestNote());
131 136
132 for(int s=0;s<inst.noOfStrings();s++) 137 for(int s=0;s<inst.noOfStrings();s++)
133 { 138 {
134 int y=(int)(stringdist*s)+ymin; 139 int y=(int)(stringdist*s)+ymin;
135 int stingid=inst.noOfStrings()-(s+1); 140 int stingid=inst.noOfStrings()-(s+1);
136 for(int f=0;f<=inst.noOfFrets();f++) 141 for(int f=0;f<=inst.noOfFrets();f++)
137 { 142 {
138 int note=inst.string(stingid)+f; 143 int note=inst.string(stingid)+f;
139 if(scale.noteInScale(data->getCurrentBaseNote(),note)) 144 if(scale.noteInScale(data->getCurrentBaseNote(),note))
140 { 145 {
141 int x=(int)(fretdist*f)+xmin; 146 int x=(int)(fretdist*f)+xmin;
142 147
143 //no more than six octaves can be visualised (there is a zero octave) 148 //no more than six octaves can be visualised (there is a zero octave)
144 int octave=Note::octaveOfBaseNote(data->getCurrentBaseNote(),note)-baseoctave; 149 int octave=Note::octaveOfBaseNote(data->getCurrentBaseNote(),note)-baseoctave;
145 if(octave<0) 150 if(octave<0)
146 qDebug("%d,%d",octave,baseoctave); 151 odebug << "" << octave << "," << baseoctave << "" << oendl;
147 if(octave>5) 152 if(octave>5)
148 { 153 {
149 qDebug("octave out of range"); 154 odebug << "octave out of range" << oendl;
150 octave=5; 155 octave=5;
151 } 156 }
152 157
153 p->setPen(QColor(255,0,0)); 158 p->setPen(QColor(255,0,0));
154 int c= ( (note-12*baseoctave) - (12*octave+data->getCurrentBaseNote()) )*15; 159 int c= ( (note-12*baseoctave) - (12*octave+data->getCurrentBaseNote()) )*15;
155 if(c<0 || c>255) 160 if(c<0 || c>255)
156 qDebug("%d = %d - ( %d + %d)",c,note,12*octave,data->getCurrentBaseNote()); 161 odebug << "" << c << " = " << note << " - ( " << 12*octave << " + " << data->getCurrentBaseNote() << ")" << oendl;
157 QColor dotcolor(255,255,255); 162 QColor dotcolor(255,255,255);
158 163
159 if(octave==0) 164 if(octave==0)
160 dotcolor=QColor(c,c,255); 165 dotcolor=QColor(c,c,255);
161 else if(octave==1) 166 else if(octave==1)
162 dotcolor=QColor(c,255,c); 167 dotcolor=QColor(c,255,c);
163 else if(octave==2) 168 else if(octave==2)
164 dotcolor=QColor(255,c,c); 169 dotcolor=QColor(255,c,c);
165 else if(octave==3) 170 else if(octave==3)
166 dotcolor=QColor(255,255,c); 171 dotcolor=QColor(255,255,c);
167 else if(octave==4) 172 else if(octave==4)
168 dotcolor=QColor(255,c,255); 173 dotcolor=QColor(255,c,255);
169 else 174 else
170 dotcolor=QColor(c,255,255); 175 dotcolor=QColor(c,255,255);
171 176
172 p->setBrush(dotcolor); 177 p->setBrush(dotcolor);
173 p->drawEllipse(x-dotsize/2,y-dotsize/2,dotsize,dotsize); 178 p->drawEllipse(x-dotsize/2,y-dotsize/2,dotsize,dotsize);
174 179
175 if(data->isDrawNames()) 180 if(data->isDrawNames())
176 { 181 {
177 p->setPen(QColor(255,155,0)); 182 p->setPen(QColor(255,155,0));
178 p->drawText(x-dotsize/2,y-dotsize/2,Note::getNameOfNote(note)); 183 p->drawText(x-dotsize/2,y-dotsize/2,Note::getNameOfNote(note));
179 } 184 }
180 185