Diffstat (limited to 'noncore/multimedia/tonleiter/fretboard.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/tonleiter/fretboard.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/noncore/multimedia/tonleiter/fretboard.cpp b/noncore/multimedia/tonleiter/fretboard.cpp index 57806be..7936c83 100644 --- a/noncore/multimedia/tonleiter/fretboard.cpp +++ b/noncore/multimedia/tonleiter/fretboard.cpp | |||
@@ -1,143 +1,143 @@ | |||
1 | #include "fretboard.h" | 1 | #include "fretboard.h" |
2 | 2 | ||
3 | #include <qpainter.h> | 3 | #include <qpainter.h> |
4 | 4 | ||
5 | FretBoard::FretBoard(TonleiterData* data,QWidget* parent,const char* name,WFlags f) | 5 | Graph::FretBoard::FretBoard(TonleiterData* data,QWidget* parent,const char* name,WFlags f) |
6 | :QWidget(parent,name,f),data(data) | 6 | :QWidget(parent,name,f),data(data) |
7 | { | 7 | { |
8 | setBackgroundColor(QColor(0,0,0)); | 8 | setBackgroundColor(QColor(0,0,0)); |
9 | fretpen=QPen(QColor(155,155,155),0); | 9 | fretpen=QPen(QColor(155,155,155),0); |
10 | markerbrush=QBrush(QColor(155,155,155)); | 10 | markerbrush=QBrush(QColor(155,155,155)); |
11 | stringpen=QPen(QColor(255,255,255),3); | 11 | stringpen=QPen(QColor(255,255,255),3); |
12 | connect(data,SIGNAL(dataChange()),this,SLOT(dataChange())); | 12 | connect(data,SIGNAL(dataChange()),this,SLOT(dataChange())); |
13 | } | 13 | } |
14 | //**************************************************************************** | 14 | //**************************************************************************** |
15 | FretBoard::~FretBoard() | 15 | Graph::FretBoard::~FretBoard() |
16 | { | 16 | { |
17 | } | 17 | } |
18 | //**************************************************************************** | 18 | //**************************************************************************** |
19 | void FretBoard::dataChange() | 19 | void Graph::FretBoard::dataChange() |
20 | { | 20 | { |
21 | repaint(true); | 21 | repaint(true); |
22 | } | 22 | } |
23 | //**************************************************************************** | 23 | //**************************************************************************** |
24 | void FretBoard::paintEvent(QPaintEvent* pe) | 24 | void Graph::FretBoard::paintEvent(QPaintEvent* pe) |
25 | { | 25 | { |
26 | Q_UNUSED(pe); | 26 | Q_UNUSED(pe); |
27 | 27 | ||
28 | int instid=data->getCurrentInstrumentID(); | 28 | int instid=data->getCurrentInstrumentID(); |
29 | inst=data->getInstrument(instid); | 29 | inst=data->getInstrument(instid); |
30 | //qDebug("inst %d is %s",instid,inst.instName().data()); | 30 | //qDebug("inst %d is %s",instid,inst.instName().data()); |
31 | 31 | ||
32 | QRect mysize=rect(); | 32 | QRect mysize=rect(); |
33 | 33 | ||
34 | xmargin=(int)(mysize.width()*0.05); | 34 | xmargin=(int)(mysize.width()*0.05); |
35 | xmin=2*xmargin; | 35 | xmin=2*xmargin; |
36 | xmax=mysize.width()-xmargin; | 36 | xmax=mysize.width()-xmargin; |
37 | xwidth=xmax-xmin; | 37 | xwidth=xmax-xmin; |
38 | 38 | ||
39 | ymargin=(int)(mysize.height()*0.1); | 39 | ymargin=(int)(mysize.height()*0.1); |
40 | ymin=ymargin; | 40 | ymin=ymargin; |
41 | ymax=mysize.height()-2*ymargin; | 41 | ymax=mysize.height()-2*ymargin; |
42 | yheight=ymax-ymin; | 42 | yheight=ymax-ymin; |
43 | 43 | ||
44 | QPainter p(this); | 44 | QPainter p(this); |
45 | paintBoard(&p); | 45 | paintBoard(&p); |
46 | paintFrets(&p); | 46 | paintFrets(&p); |
47 | paintStrings(&p); | 47 | paintStrings(&p); |
48 | paintScale(&p); | 48 | paintScale(&p); |
49 | } | 49 | } |
50 | //**************************************************************************** | 50 | //**************************************************************************** |
51 | void FretBoard::resizeEvent(QResizeEvent* re) | 51 | void Graph::FretBoard::resizeEvent(QResizeEvent* re) |
52 | { | 52 | { |
53 | Q_UNUSED(re); | 53 | Q_UNUSED(re); |
54 | } | 54 | } |
55 | //**************************************************************************** | 55 | //**************************************************************************** |
56 | void FretBoard::paintBoard(QPainter* p) | 56 | void Graph::FretBoard::paintBoard(QPainter* p) |
57 | { | 57 | { |
58 | //debug | 58 | //debug |
59 | QColor bgc=QColor(142,138,120); | 59 | QColor bgc=QColor(142,138,120); |
60 | p->setPen(QPen(bgc,5)); | 60 | p->setPen(QPen(bgc,5)); |
61 | p->setBrush(QBrush(bgc)); | 61 | p->setBrush(QBrush(bgc)); |
62 | p->drawRect(xmin,ymin,xwidth,yheight); | 62 | p->drawRect(xmin,ymin,xwidth,yheight); |
63 | 63 | ||
64 | } | 64 | } |
65 | //**************************************************************************** | 65 | //**************************************************************************** |
66 | void FretBoard::paintFrets(QPainter* p) | 66 | void Graph::FretBoard::paintFrets(QPainter* p) |
67 | { | 67 | { |
68 | //draw frets | 68 | //draw frets |
69 | p->setPen(fretpen); | 69 | p->setPen(fretpen); |
70 | p->setBrush(markerbrush); | 70 | p->setBrush(markerbrush); |
71 | fretdist=(double)(xwidth)/(double)(inst.noOfFrets()); | 71 | fretdist=(double)(xwidth)/(double)(inst.noOfFrets()); |
72 | 72 | ||
73 | int markerwidth = (int)(fretdist/4.0); | 73 | int markerwidth = (int)(fretdist/4.0); |
74 | if(markerwidth>5) | 74 | if(markerwidth>5) |
75 | markerwidth=5; | 75 | markerwidth=5; |
76 | else if(markerwidth<2) | 76 | else if(markerwidth<2) |
77 | markerwidth=2; | 77 | markerwidth=2; |
78 | 78 | ||
79 | for(int f=0;f<=inst.noOfFrets();f++) | 79 | for(int f=0;f<=inst.noOfFrets();f++) |
80 | { | 80 | { |
81 | int fretpos=(int)(fretdist*f); | 81 | int fretpos=(int)(fretdist*f); |
82 | p->drawLine(fretpos+xmin,ymin,fretpos+xmin,ymax); | 82 | p->drawLine(fretpos+xmin,ymin,fretpos+xmin,ymax); |
83 | 83 | ||
84 | int above_octave=f%12; | 84 | int above_octave=f%12; |
85 | int octave=(f-above_octave)/12; | 85 | int octave=(f-above_octave)/12; |
86 | int marker=f-12*octave; | 86 | int marker=f-12*octave; |
87 | 87 | ||
88 | 88 | ||
89 | if(marker==5 || marker==7 || marker==9) | 89 | if(marker==5 || marker==7 || marker==9) |
90 | { | 90 | { |
91 | p->drawEllipse(fretpos+xmin,ymax+ymargin,markerwidth,markerwidth); | 91 | p->drawEllipse(fretpos+xmin,ymax+ymargin,markerwidth,markerwidth); |
92 | } | 92 | } |
93 | else if(marker==0 && f!=0) | 93 | else if(marker==0 && f!=0) |
94 | { | 94 | { |
95 | p->drawEllipse(fretpos+xmin,ymax+ymargin+2*markerwidth,markerwidth,markerwidth); | 95 | p->drawEllipse(fretpos+xmin,ymax+ymargin+2*markerwidth,markerwidth,markerwidth); |
96 | p->drawEllipse(fretpos+xmin,ymax+ymargin-2*markerwidth,markerwidth,markerwidth); | 96 | p->drawEllipse(fretpos+xmin,ymax+ymargin-2*markerwidth,markerwidth,markerwidth); |
97 | } | 97 | } |
98 | 98 | ||
99 | } | 99 | } |
100 | } | 100 | } |
101 | //**************************************************************************** | 101 | //**************************************************************************** |
102 | void FretBoard::paintStrings(QPainter* p) | 102 | void Graph::FretBoard::paintStrings(QPainter* p) |
103 | { | 103 | { |
104 | //draw strings | 104 | //draw strings |
105 | p->setPen(stringpen); | 105 | p->setPen(stringpen); |
106 | 106 | ||
107 | stringdist=(double)(yheight)/(double)(inst.noOfStrings()-1); | 107 | stringdist=(double)(yheight)/(double)(inst.noOfStrings()-1); |
108 | for(int s=0;s<inst.noOfStrings();s++) | 108 | for(int s=0;s<inst.noOfStrings();s++) |
109 | { | 109 | { |
110 | int stringpos=(int)(stringdist*s); | 110 | int stringpos=(int)(stringdist*s); |
111 | p->drawLine(xmin,stringpos+ymin,xmax,stringpos+ymin); | 111 | p->drawLine(xmin,stringpos+ymin,xmax,stringpos+ymin); |
112 | 112 | ||
113 | int stinglabelid=inst.noOfStrings()-(s+1); | 113 | int stinglabelid=inst.noOfStrings()-(s+1); |
114 | QString label=Note::getNameOfNote(inst.string(stinglabelid)); | 114 | QString label=Note::getNameOfNote(inst.string(stinglabelid)); |
115 | p->drawText(xmargin/2,stringpos+ymin,label); | 115 | p->drawText(xmargin/2,stringpos+ymin,label); |
116 | } | 116 | } |
117 | } | 117 | } |
118 | //**************************************************************************** | 118 | //**************************************************************************** |
119 | void FretBoard::paintScale(QPainter* p) | 119 | void Graph::FretBoard::paintScale(QPainter* p) |
120 | { | 120 | { |
121 | int dotsize=10; | 121 | int dotsize=10; |
122 | int scaleid=data->getCurrentScaleID(); | 122 | int scaleid=data->getCurrentScaleID(); |
123 | Scale scale=data->getScale(scaleid); | 123 | Scale scale=data->getScale(scaleid); |
124 | 124 | ||
125 | int colorstart=255%inst.noOfOctaves(); | 125 | int colorstart=255%inst.noOfOctaves(); |
126 | int colorintervall=(255-colorstart)/inst.noOfOctaves(); | 126 | int colorintervall=(255-colorstart)/inst.noOfOctaves(); |
127 | 127 | ||
128 | for(int s=0;s<inst.noOfStrings();s++) | 128 | for(int s=0;s<inst.noOfStrings();s++) |
129 | { | 129 | { |
130 | int y=(int)(stringdist*s)+ymin; | 130 | int y=(int)(stringdist*s)+ymin; |
131 | int stingid=inst.noOfStrings()-(s+1); | 131 | int stingid=inst.noOfStrings()-(s+1); |
132 | for(int f=0;f<=inst.noOfFrets();f++) | 132 | for(int f=0;f<=inst.noOfFrets();f++) |
133 | { | 133 | { |
134 | int note=inst.string(stingid)+f; | 134 | int note=inst.string(stingid)+f; |
135 | if(scale.noteInScale(data->getCurrentBaseNote(),note)) | 135 | if(scale.noteInScale(data->getCurrentBaseNote(),note)) |
136 | { | 136 | { |
137 | int x=(int)(fretdist*f)+xmin; | 137 | int x=(int)(fretdist*f)+xmin; |
138 | 138 | ||
139 | int octave=Note::octaveOfBaseNote(data->getCurrentBaseNote(),note); | 139 | int octave=Note::octaveOfBaseNote(data->getCurrentBaseNote(),note); |
140 | if(octave>5) octave=5; | 140 | if(octave>5) octave=5; |
141 | p->setPen(QColor(255,0,0)); | 141 | p->setPen(QColor(255,0,0)); |
142 | int c=colorstart+octave*colorintervall; | 142 | int c=colorstart+octave*colorintervall; |
143 | QColor dotcolor(c,c,255); | 143 | QColor dotcolor(c,c,255); |