author | waspe <waspe> | 2004-01-24 13:44:29 (UTC) |
---|---|---|
committer | waspe <waspe> | 2004-01-24 13:44:29 (UTC) |
commit | 5f333c6832ff429a00498e6a36be950525541a2a (patch) (unidiff) | |
tree | 035616d3cc11622f6d9b14245372362620327a46 | |
parent | d542ba6a426f9868d521dbd9eb502184086535fc (diff) | |
download | opie-5f333c6832ff429a00498e6a36be950525541a2a.zip opie-5f333c6832ff429a00498e6a36be950525541a2a.tar.gz opie-5f333c6832ff429a00498e6a36be950525541a2a.tar.bz2 |
new color scheme on fretboard, maekes each ocatave appear in different color
-rw-r--r-- | noncore/multimedia/tonleiter/editinst.cpp | 6 | ||||
-rw-r--r-- | noncore/multimedia/tonleiter/editinst.h | 1 | ||||
-rw-r--r-- | noncore/multimedia/tonleiter/fretboard.cpp | 43 | ||||
-rw-r--r-- | noncore/multimedia/tonleiter/fretboard.h | 3 | ||||
-rw-r--r-- | noncore/multimedia/tonleiter/mainwidget.cpp | 17 | ||||
-rw-r--r-- | noncore/multimedia/tonleiter/mainwidget.h | 3 | ||||
-rw-r--r-- | noncore/multimedia/tonleiter/tonleiterdatahelper.cpp | 15 | ||||
-rw-r--r-- | noncore/multimedia/tonleiter/tonleiterdatahelper.h | 2 |
8 files changed, 77 insertions, 13 deletions
diff --git a/noncore/multimedia/tonleiter/editinst.cpp b/noncore/multimedia/tonleiter/editinst.cpp index 120c3ac..f172ef8 100644 --- a/noncore/multimedia/tonleiter/editinst.cpp +++ b/noncore/multimedia/tonleiter/editinst.cpp | |||
@@ -1,107 +1,109 @@ | |||
1 | #include "editinst.h" | 1 | #include "editinst.h" |
2 | 2 | ||
3 | #include <qlabel.h> | 3 | #include <qlabel.h> |
4 | #include <qpushbutton.h> | 4 | #include <qpushbutton.h> |
5 | 5 | ||
6 | Menu::InstEditDialog::InstEditDialog(TonleiterData* data,QWidget* parent,const char* name) | 6 | Menu::InstEditDialog::InstEditDialog(TonleiterData* data,QWidget* parent,const char* name) |
7 | :QDialog(parent,name,true,0),data(data) | 7 | :QDialog(parent,name,true,0),data(data) |
8 | { | 8 | { |
9 | setCaption("Tonleiter::"+tr("Instrument")); | 9 | setCaption("Tonleiter::"+tr("Instrument")); |
10 | QBoxLayout* masterlayout=new QBoxLayout(this,QBoxLayout::TopToBottom); | 10 | QBoxLayout* masterlayout=new QBoxLayout(this,QBoxLayout::TopToBottom); |
11 | instid=data->getCurrentInstrumentID(); | 11 | instid=data->getCurrentInstrumentID(); |
12 | stringlist.setAutoDelete(true); | 12 | stringlist.setAutoDelete(true); |
13 | 13 | ||
14 | QBoxLayout* toplayout=new QBoxLayout(masterlayout,QBoxLayout::LeftToRight); | 14 | QBoxLayout* toplayout=new QBoxLayout(masterlayout,QBoxLayout::LeftToRight); |
15 | 15 | ||
16 | //Name combo + Add + Delete | 16 | //Name combo + Add + Delete |
17 | boxInst=new QComboBox(this,"boxInst"); | 17 | boxInst=new QComboBox(this,"boxInst"); |
18 | boxInst->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Maximum)); | 18 | boxInst->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Maximum)); |
19 | connect(boxInst,SIGNAL(activated(int)),this,SLOT(setCurrentInstrumetID(int))); | 19 | connect(boxInst,SIGNAL(activated(int)),this,SLOT(setCurrentInstrumetID(int))); |
20 | for(int i=0;i<data->noOfInstruments();i++) | 20 | for(int i=0;i<data->noOfInstruments();i++) |
21 | { | 21 | { |
22 | Instrument inst=data->getInstrument(i); | 22 | Instrument inst=data->getInstrument(i); |
23 | QString name=inst.instName(); | 23 | QString name=inst.instName(); |
24 | if(name.isNull()) continue; | 24 | if(name.isNull()) continue; |
25 | boxInst->insertItem(name,i); | 25 | boxInst->insertItem(name,i); |
26 | } | 26 | } |
27 | boxInst->setCurrentItem(instid); | 27 | boxInst->setCurrentItem(instid); |
28 | toplayout->addWidget(boxInst); | 28 | toplayout->addWidget(boxInst); |
29 | 29 | ||
30 | QPushButton* addButton=new QPushButton(tr("Add"),this,"addButton"); | 30 | QPushButton* addButton=new QPushButton(tr("Add"),this,"addButton"); |
31 | connect(addButton,SIGNAL(pressed()),this,SLOT(addInstrument())); | 31 | connect(addButton,SIGNAL(pressed()),this,SLOT(addInstrument())); |
32 | toplayout->addWidget(addButton); | 32 | toplayout->addWidget(addButton); |
33 | 33 | ||
34 | QPushButton* delButton=new QPushButton(tr("Delete"),this,"delButton"); | 34 | QPushButton* delButton=new QPushButton(tr("Delete"),this,"delButton"); |
35 | connect(delButton,SIGNAL(pressed()),this,SLOT(deleteInstrument())); | 35 | connect(delButton,SIGNAL(pressed()),this,SLOT(deleteInstrument())); |
36 | toplayout->addWidget(delButton); | 36 | toplayout->addWidget(delButton); |
37 | 37 | ||
38 | QPushButton* addhighButton=new QPushButton(tr("Add High String"),this,"addhighButton"); | 38 | QPushButton* addhighButton=new QPushButton(tr("Add High String"),this,"addhighButton"); |
39 | masterlayout->addWidget(addhighButton); | 39 | masterlayout->addWidget(addhighButton); |
40 | 40 | ||
41 | QScrollView* scrollview=new QScrollView(this); | 41 | scrollview=new QScrollView(this); |
42 | scrollview->setVScrollBarMode(QScrollView::AlwaysOn); | 42 | scrollview->setVScrollBarMode(QScrollView::AlwaysOn); |
43 | scrollview->setHScrollBarMode(QScrollView::AlwaysOff); | 43 | scrollview->setHScrollBarMode(QScrollView::AlwaysOff); |
44 | stringwidget=new QVBox(scrollview->viewport()); | 44 | stringwidget=new QVBox(scrollview->viewport()); |
45 | stringwidget->setSizePolicy(QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum)); | 45 | stringwidget->setSizePolicy(QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum)); |
46 | stringwidget->setSpacing(10); | 46 | stringwidget->setSpacing(10); |
47 | scrollview->addChild(stringwidget); | 47 | scrollview->addChild(stringwidget); |
48 | scrollview->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Maximum)); | 48 | scrollview->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Maximum)); |
49 | //scrollview->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::MinimumExpanding)); | ||
50 | masterlayout->addWidget(scrollview); | 49 | masterlayout->addWidget(scrollview); |
51 | 50 | ||
52 | loadInstrument(); | 51 | loadInstrument(); |
53 | 52 | ||
54 | QPushButton* addlowButton=new QPushButton(tr("Add Low String"),this,"addlowButton"); | 53 | QPushButton* addlowButton=new QPushButton(tr("Add Low String"),this,"addlowButton"); |
55 | masterlayout->addWidget(addlowButton); | 54 | masterlayout->addWidget(addlowButton); |
56 | 55 | ||
57 | //make dialog fit the screen | 56 | //make dialog fit the screen |
58 | showMaximized(); | 57 | showMaximized(); |
59 | } | 58 | } |
60 | //**************************************************************************** | 59 | //**************************************************************************** |
61 | Menu::InstEditDialog::~InstEditDialog() | 60 | Menu::InstEditDialog::~InstEditDialog() |
62 | { | 61 | { |
63 | } | 62 | } |
64 | //**************************************************************************** | 63 | //**************************************************************************** |
65 | void Menu::InstEditDialog::setCurrentInstrumetID(int id) | 64 | void Menu::InstEditDialog::setCurrentInstrumetID(int id) |
66 | { | 65 | { |
67 | saveInstrument(); | 66 | saveInstrument(); |
68 | instid=id; | 67 | instid=id; |
69 | data->setCurrentInstrumetID(id); | 68 | data->setCurrentInstrumetID(id); |
70 | loadInstrument(); | 69 | loadInstrument(); |
71 | } | 70 | } |
72 | //**************************************************************************** | 71 | //**************************************************************************** |
73 | void Menu::InstEditDialog::addInstrument() | 72 | void Menu::InstEditDialog::addInstrument() |
74 | { | 73 | { |
75 | } | 74 | } |
76 | //**************************************************************************** | 75 | //**************************************************************************** |
77 | void Menu::InstEditDialog::deleteInstrument() | 76 | void Menu::InstEditDialog::deleteInstrument() |
78 | { | 77 | { |
79 | } | 78 | } |
80 | //**************************************************************************** | 79 | //**************************************************************************** |
81 | void Menu::InstEditDialog::addLowString() | 80 | void Menu::InstEditDialog::addLowString() |
82 | { | 81 | { |
83 | } | 82 | } |
84 | //**************************************************************************** | 83 | //**************************************************************************** |
85 | void Menu::InstEditDialog::addHighString() | 84 | void Menu::InstEditDialog::addHighString() |
86 | { | 85 | { |
87 | } | 86 | } |
88 | //**************************************************************************** | 87 | //**************************************************************************** |
89 | void Menu::InstEditDialog::deleteString(int id) | 88 | void Menu::InstEditDialog::deleteString(int id) |
90 | { | 89 | { |
91 | } | 90 | } |
92 | //**************************************************************************** | 91 | //**************************************************************************** |
93 | void Menu::InstEditDialog::saveInstrument() | 92 | void Menu::InstEditDialog::saveInstrument() |
94 | { | 93 | { |
94 | //auto delete is set to true so widgets _should_ be deleted | ||
95 | stringlist.clear(); | 95 | stringlist.clear(); |
96 | } | 96 | } |
97 | //**************************************************************************** | 97 | //**************************************************************************** |
98 | void Menu::InstEditDialog::loadInstrument() | 98 | void Menu::InstEditDialog::loadInstrument() |
99 | { | 99 | { |
100 | stringlist.clear(); | ||
100 | Instrument inst=data->getInstrument(instid); | 101 | Instrument inst=data->getInstrument(instid); |
102 | qDebug("load Instrument : %d strings",inst.noOfStrings()); | ||
101 | for(uint s=0;s<inst.noOfStrings();s++) | 103 | for(uint s=0;s<inst.noOfStrings();s++) |
102 | { | 104 | { |
103 | stringlist.append(new EditStringWidget(inst.string(s),stringwidget)); | 105 | stringlist.append(new EditStringWidget(inst.string(s),stringwidget)); |
104 | } | 106 | } |
105 | } | 107 | } |
106 | //**************************************************************************** | 108 | //**************************************************************************** |
107 | //**************************************************************************** | 109 | //**************************************************************************** |
diff --git a/noncore/multimedia/tonleiter/editinst.h b/noncore/multimedia/tonleiter/editinst.h index 948a2de..a90c9ec 100644 --- a/noncore/multimedia/tonleiter/editinst.h +++ b/noncore/multimedia/tonleiter/editinst.h | |||
@@ -1,52 +1,53 @@ | |||
1 | #ifndef TONLEITER_EDIT_INSTRUMENT_DIALOG_H | 1 | #ifndef TONLEITER_EDIT_INSTRUMENT_DIALOG_H |
2 | #define TONLEITER_EDIT_INSTRUMENT_DIALOG_H | 2 | #define TONLEITER_EDIT_INSTRUMENT_DIALOG_H |
3 | 3 | ||
4 | #include <qdialog.h> | 4 | #include <qdialog.h> |
5 | #include <qcombobox.h> | 5 | #include <qcombobox.h> |
6 | #include <qscrollview.h> | 6 | #include <qscrollview.h> |
7 | #include <qspinbox.h> | 7 | #include <qspinbox.h> |
8 | #include <qlayout.h> | 8 | #include <qlayout.h> |
9 | #include <qlist.h> | 9 | #include <qlist.h> |
10 | #include <qvbox.h> | 10 | #include <qvbox.h> |
11 | 11 | ||
12 | 12 | ||
13 | #include "editstringwidget.h" | 13 | #include "editstringwidget.h" |
14 | 14 | ||
15 | using namespace Data; | 15 | using namespace Data; |
16 | 16 | ||
17 | 17 | ||
18 | namespace Menu | 18 | namespace Menu |
19 | { | 19 | { |
20 | class InstEditDialog : public QDialog | 20 | class InstEditDialog : public QDialog |
21 | { | 21 | { |
22 | Q_OBJECT | 22 | Q_OBJECT |
23 | private: | 23 | private: |
24 | TonleiterData* data; | 24 | TonleiterData* data; |
25 | int instid; | 25 | int instid; |
26 | 26 | ||
27 | QComboBox* boxInst; | 27 | QComboBox* boxInst; |
28 | QSpinBox* stringBox; | 28 | QSpinBox* stringBox; |
29 | 29 | ||
30 | QScrollView* scrollview; | ||
30 | QVBox* stringwidget; | 31 | QVBox* stringwidget; |
31 | 32 | ||
32 | //this is a QPtrList !! | 33 | //this is a QPtrList !! |
33 | typedef QList<EditStringWidget> StringWidgetList; | 34 | typedef QList<EditStringWidget> StringWidgetList; |
34 | StringWidgetList stringlist; | 35 | StringWidgetList stringlist; |
35 | public: | 36 | public: |
36 | InstEditDialog(TonleiterData* data,QWidget* parent,const char* name="InstEditDialog"); | 37 | InstEditDialog(TonleiterData* data,QWidget* parent,const char* name="InstEditDialog"); |
37 | ~InstEditDialog(); | 38 | ~InstEditDialog(); |
38 | private slots: | 39 | private slots: |
39 | void setCurrentInstrumetID(int id); | 40 | void setCurrentInstrumetID(int id); |
40 | void addInstrument(); | 41 | void addInstrument(); |
41 | void deleteInstrument(); | 42 | void deleteInstrument(); |
42 | 43 | ||
43 | void addLowString(); | 44 | void addLowString(); |
44 | void addHighString(); | 45 | void addHighString(); |
45 | void deleteString(int id); | 46 | void deleteString(int id); |
46 | private: | 47 | private: |
47 | void saveInstrument(); | 48 | void saveInstrument(); |
48 | void loadInstrument(); | 49 | void loadInstrument(); |
49 | }; | 50 | }; |
50 | }; | 51 | }; |
51 | 52 | ||
52 | #endif //TONLEITER_EDIT_INSTRUMENT_DIALOG_H | 53 | #endif //TONLEITER_EDIT_INSTRUMENT_DIALOG_H |
diff --git a/noncore/multimedia/tonleiter/fretboard.cpp b/noncore/multimedia/tonleiter/fretboard.cpp index 7936c83..7e63e01 100644 --- a/noncore/multimedia/tonleiter/fretboard.cpp +++ b/noncore/multimedia/tonleiter/fretboard.cpp | |||
@@ -8,152 +8,179 @@ Graph::FretBoard::FretBoard(TonleiterData* data,QWidget* parent,const char* name | |||
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 | Graph::FretBoard::~FretBoard() | 15 | Graph::FretBoard::~FretBoard() |
16 | { | 16 | { |
17 | } | 17 | } |
18 | //**************************************************************************** | 18 | //**************************************************************************** |
19 | void Graph::FretBoard::dataChange() | 19 | void Graph::FretBoard::dataChange() |
20 | { | 20 | { |
21 | repaint(true); | 21 | repaint(true); |
22 | } | 22 | } |
23 | //**************************************************************************** | 23 | //**************************************************************************** |
24 | void Graph::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 Graph::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 Graph::FretBoard::mouseReleaseEvent(QMouseEvent* me) | ||
57 | { | ||
58 | Q_UNUSED(me); | ||
59 | emit pressed(); | ||
60 | } | ||
61 | //**************************************************************************** | ||
56 | void Graph::FretBoard::paintBoard(QPainter* p) | 62 | void Graph::FretBoard::paintBoard(QPainter* p) |
57 | { | 63 | { |
58 | //debug | 64 | //debug |
59 | QColor bgc=QColor(142,138,120); | 65 | QColor bgc=QColor(142,138,120); |
60 | p->setPen(QPen(bgc,5)); | 66 | p->setPen(QPen(bgc,5)); |
61 | p->setBrush(QBrush(bgc)); | 67 | p->setBrush(QBrush(bgc)); |
62 | p->drawRect(xmin,ymin,xwidth,yheight); | 68 | p->drawRect(xmin,ymin,xwidth,yheight); |
63 | 69 | ||
64 | } | 70 | } |
65 | //**************************************************************************** | 71 | //**************************************************************************** |
66 | void Graph::FretBoard::paintFrets(QPainter* p) | 72 | void Graph::FretBoard::paintFrets(QPainter* p) |
67 | { | 73 | { |
68 | //draw frets | 74 | //draw frets |
69 | p->setPen(fretpen); | 75 | p->setPen(fretpen); |
70 | p->setBrush(markerbrush); | 76 | p->setBrush(markerbrush); |
71 | fretdist=(double)(xwidth)/(double)(inst.noOfFrets()); | 77 | fretdist=(double)(xwidth)/(double)(inst.noOfFrets()); |
72 | 78 | ||
73 | int markerwidth = (int)(fretdist/4.0); | 79 | int markerwidth = (int)(fretdist/4.0); |
74 | if(markerwidth>5) | 80 | if(markerwidth>5) |
75 | markerwidth=5; | 81 | markerwidth=5; |
76 | else if(markerwidth<2) | 82 | else if(markerwidth<2) |
77 | markerwidth=2; | 83 | markerwidth=2; |
78 | 84 | ||
79 | for(int f=0;f<=inst.noOfFrets();f++) | 85 | for(int f=0;f<=inst.noOfFrets();f++) |
80 | { | 86 | { |
81 | int fretpos=(int)(fretdist*f); | 87 | int fretpos=(int)(fretdist*f); |
82 | p->drawLine(fretpos+xmin,ymin,fretpos+xmin,ymax); | 88 | p->drawLine(fretpos+xmin,ymin,fretpos+xmin,ymax); |
83 | 89 | ||
84 | int above_octave=f%12; | 90 | int above_octave=f%12; |
85 | int octave=(f-above_octave)/12; | 91 | int octave=(f-above_octave)/12; |
86 | int marker=f-12*octave; | 92 | int marker=f-12*octave; |
87 | 93 | ||
88 | 94 | ||
89 | if(marker==5 || marker==7 || marker==9) | 95 | if(marker==5 || marker==7 || marker==9) |
90 | { | 96 | { |
91 | p->drawEllipse(fretpos+xmin,ymax+ymargin,markerwidth,markerwidth); | 97 | p->drawEllipse(fretpos+xmin,ymax+ymargin,markerwidth,markerwidth); |
92 | } | 98 | } |
93 | else if(marker==0 && f!=0) | 99 | else if(marker==0 && f!=0) |
94 | { | 100 | { |
95 | p->drawEllipse(fretpos+xmin,ymax+ymargin+2*markerwidth,markerwidth,markerwidth); | 101 | p->drawEllipse(fretpos+xmin,ymax+ymargin+2*markerwidth,markerwidth,markerwidth); |
96 | p->drawEllipse(fretpos+xmin,ymax+ymargin-2*markerwidth,markerwidth,markerwidth); | 102 | p->drawEllipse(fretpos+xmin,ymax+ymargin-2*markerwidth,markerwidth,markerwidth); |
97 | } | 103 | } |
98 | 104 | ||
99 | } | 105 | } |
100 | } | 106 | } |
101 | //**************************************************************************** | 107 | //**************************************************************************** |
102 | void Graph::FretBoard::paintStrings(QPainter* p) | 108 | void Graph::FretBoard::paintStrings(QPainter* p) |
103 | { | 109 | { |
104 | //draw strings | 110 | //draw strings |
105 | p->setPen(stringpen); | 111 | p->setPen(stringpen); |
106 | 112 | ||
107 | stringdist=(double)(yheight)/(double)(inst.noOfStrings()-1); | 113 | stringdist=(double)(yheight)/(double)(inst.noOfStrings()-1); |
108 | for(int s=0;s<inst.noOfStrings();s++) | 114 | for(int s=0;s<inst.noOfStrings();s++) |
109 | { | 115 | { |
110 | int stringpos=(int)(stringdist*s); | 116 | int stringpos=(int)(stringdist*s); |
111 | p->drawLine(xmin,stringpos+ymin,xmax,stringpos+ymin); | 117 | p->drawLine(xmin,stringpos+ymin,xmax,stringpos+ymin); |
112 | 118 | ||
113 | int stinglabelid=inst.noOfStrings()-(s+1); | 119 | int stinglabelid=inst.noOfStrings()-(s+1); |
114 | QString label=Note::getNameOfNote(inst.string(stinglabelid)); | 120 | QString label=Note::getNameOfNote(inst.string(stinglabelid)); |
115 | p->drawText(xmargin/2,stringpos+ymin,label); | 121 | p->drawText(xmargin/2,stringpos+ymin,label); |
116 | } | 122 | } |
117 | } | 123 | } |
118 | //**************************************************************************** | 124 | //**************************************************************************** |
119 | void Graph::FretBoard::paintScale(QPainter* p) | 125 | void Graph::FretBoard::paintScale(QPainter* p) |
120 | { | 126 | { |
121 | int dotsize=10; | 127 | int dotsize=10; |
122 | int scaleid=data->getCurrentScaleID(); | 128 | int scaleid=data->getCurrentScaleID(); |
123 | Scale scale=data->getScale(scaleid); | 129 | Scale scale=data->getScale(scaleid); |
124 | 130 | int baseoctave=Note::octaveOfBaseNote(data->getCurrentBaseNote(),inst.lowestNote()); | |
125 | int colorstart=255%inst.noOfOctaves(); | ||
126 | int colorintervall=(255-colorstart)/inst.noOfOctaves(); | ||
127 | 131 | ||
128 | for(int s=0;s<inst.noOfStrings();s++) | 132 | for(int s=0;s<inst.noOfStrings();s++) |
129 | { | 133 | { |
130 | int y=(int)(stringdist*s)+ymin; | 134 | int y=(int)(stringdist*s)+ymin; |
131 | int stingid=inst.noOfStrings()-(s+1); | 135 | int stingid=inst.noOfStrings()-(s+1); |
132 | for(int f=0;f<=inst.noOfFrets();f++) | 136 | for(int f=0;f<=inst.noOfFrets();f++) |
133 | { | 137 | { |
134 | int note=inst.string(stingid)+f; | 138 | int note=inst.string(stingid)+f; |
135 | if(scale.noteInScale(data->getCurrentBaseNote(),note)) | 139 | if(scale.noteInScale(data->getCurrentBaseNote(),note)) |
136 | { | 140 | { |
137 | int x=(int)(fretdist*f)+xmin; | 141 | int x=(int)(fretdist*f)+xmin; |
138 | 142 | ||
139 | int octave=Note::octaveOfBaseNote(data->getCurrentBaseNote(),note); | 143 | //no more than six octaves can be visualised (there is a zero octave) |
140 | if(octave>5) octave=5; | 144 | int octave=Note::octaveOfBaseNote(data->getCurrentBaseNote(),note)-baseoctave; |
145 | if(octave<0) | ||
146 | qDebug("%d,%d",octave,baseoctave); | ||
147 | if(octave>5) | ||
148 | { | ||
149 | qDebug("octave out of range"); | ||
150 | octave=5; | ||
151 | } | ||
152 | |||
141 | p->setPen(QColor(255,0,0)); | 153 | p->setPen(QColor(255,0,0)); |
142 | int c=colorstart+octave*colorintervall; | 154 | int c= ( (note-12*baseoctave) - (12*octave+data->getCurrentBaseNote()) )*15; |
143 | QColor dotcolor(c,c,255); | 155 | if(c<0 || c>255) |
144 | p->setBrush(dotcolor); | 156 | qDebug("%d = %d - ( %d + %d)",c,note,12*octave,data->getCurrentBaseNote()); |
157 | QColor dotcolor(255,255,255); | ||
158 | |||
159 | if(octave==0) | ||
160 | dotcolor=QColor(c,c,255); | ||
161 | else if(octave==1) | ||
162 | dotcolor=QColor(c,255,c); | ||
163 | else if(octave==2) | ||
164 | dotcolor=QColor(255,c,c); | ||
165 | else if(octave==3) | ||
166 | dotcolor=QColor(255,255,c); | ||
167 | else if(octave==4) | ||
168 | dotcolor=QColor(255,c,255); | ||
169 | else | ||
170 | dotcolor=QColor(c,255,255); | ||
145 | 171 | ||
172 | p->setBrush(dotcolor); | ||
146 | p->drawEllipse(x-dotsize/2,y-dotsize/2,dotsize,dotsize); | 173 | p->drawEllipse(x-dotsize/2,y-dotsize/2,dotsize,dotsize); |
147 | 174 | ||
148 | if(data->isDrawNames()) | 175 | if(data->isDrawNames()) |
149 | { | 176 | { |
150 | p->setPen(QColor(255,155,0)); | 177 | p->setPen(QColor(255,155,0)); |
151 | p->drawText(x-dotsize/2,y-dotsize/2,Note::getNameOfNote(note)); | 178 | p->drawText(x-dotsize/2,y-dotsize/2,Note::getNameOfNote(note)); |
152 | } | 179 | } |
153 | 180 | ||
154 | } | 181 | } |
155 | } | 182 | } |
156 | } | 183 | } |
157 | } | 184 | } |
158 | //**************************************************************************** | 185 | //**************************************************************************** |
159 | //**************************************************************************** | 186 | //**************************************************************************** |
diff --git a/noncore/multimedia/tonleiter/fretboard.h b/noncore/multimedia/tonleiter/fretboard.h index 458c733..bb696fb 100644 --- a/noncore/multimedia/tonleiter/fretboard.h +++ b/noncore/multimedia/tonleiter/fretboard.h | |||
@@ -1,56 +1,59 @@ | |||
1 | #ifndef TONLEITER_FRET_BOARD_H | 1 | #ifndef TONLEITER_FRET_BOARD_H |
2 | #define TONLEITER_FRET_BOARD_H | 2 | #define TONLEITER_FRET_BOARD_H |
3 | 3 | ||
4 | #include <qbrush.h> | 4 | #include <qbrush.h> |
5 | #include <qpen.h> | 5 | #include <qpen.h> |
6 | #include <qvaluelist.h> | 6 | #include <qvaluelist.h> |
7 | #include <qwidget.h> | 7 | #include <qwidget.h> |
8 | 8 | ||
9 | 9 | ||
10 | #include "tonleiterdata.h" | 10 | #include "tonleiterdata.h" |
11 | 11 | ||
12 | using namespace Data; | 12 | using namespace Data; |
13 | 13 | ||
14 | namespace Graph | 14 | namespace Graph |
15 | { | 15 | { |
16 | class FretBoard : public QWidget | 16 | class FretBoard : public QWidget |
17 | { | 17 | { |
18 | Q_OBJECT | 18 | Q_OBJECT |
19 | private: | 19 | private: |
20 | TonleiterData* data; | 20 | TonleiterData* data; |
21 | 21 | ||
22 | QPen fretpen; | 22 | QPen fretpen; |
23 | QBrush markerbrush; | 23 | QBrush markerbrush; |
24 | QPen stringpen; | 24 | QPen stringpen; |
25 | 25 | ||
26 | Instrument inst; | 26 | Instrument inst; |
27 | 27 | ||
28 | int xmargin; | 28 | int xmargin; |
29 | int xmin; | 29 | int xmin; |
30 | int xmax; | 30 | int xmax; |
31 | int xwidth; | 31 | int xwidth; |
32 | 32 | ||
33 | int ymargin; | 33 | int ymargin; |
34 | int ymin; | 34 | int ymin; |
35 | int ymax; | 35 | int ymax; |
36 | int yheight; | 36 | int yheight; |
37 | 37 | ||
38 | double fretdist; | 38 | double fretdist; |
39 | double stringdist; | 39 | double stringdist; |
40 | 40 | ||
41 | public: | 41 | public: |
42 | FretBoard(TonleiterData* data,QWidget* parent,const char* name="FretBoard",WFlags f=0); | 42 | FretBoard(TonleiterData* data,QWidget* parent,const char* name="FretBoard",WFlags f=0); |
43 | virtual ~FretBoard(); | 43 | virtual ~FretBoard(); |
44 | signals: | ||
45 | void pressed(); | ||
44 | private slots: | 46 | private slots: |
45 | void dataChange(); | 47 | void dataChange(); |
46 | private: | 48 | private: |
47 | void paintEvent(QPaintEvent* pe); | 49 | void paintEvent(QPaintEvent* pe); |
48 | void resizeEvent(QResizeEvent* re); | 50 | void resizeEvent(QResizeEvent* re); |
51 | void mouseReleaseEvent(QMouseEvent* me); | ||
49 | void paintBoard(QPainter* p); | 52 | void paintBoard(QPainter* p); |
50 | void paintFrets(QPainter* p); | 53 | void paintFrets(QPainter* p); |
51 | void paintStrings(QPainter* p); | 54 | void paintStrings(QPainter* p); |
52 | void paintScale(QPainter* p); | 55 | void paintScale(QPainter* p); |
53 | }; | 56 | }; |
54 | }; | 57 | }; |
55 | 58 | ||
56 | #endif //TONLEITER_FRET_BOARD_H | 59 | #endif //TONLEITER_FRET_BOARD_H |
diff --git a/noncore/multimedia/tonleiter/mainwidget.cpp b/noncore/multimedia/tonleiter/mainwidget.cpp index f09207b..b9c3d01 100644 --- a/noncore/multimedia/tonleiter/mainwidget.cpp +++ b/noncore/multimedia/tonleiter/mainwidget.cpp | |||
@@ -1,28 +1,45 @@ | |||
1 | #include "mainwidget.h" | 1 | #include "mainwidget.h" |
2 | 2 | ||
3 | #include <qwidget.h> | 3 | #include <qwidget.h> |
4 | #include <qlayout.h> | 4 | #include <qlayout.h> |
5 | 5 | ||
6 | MainWidget::MainWidget(QWidget* parent,const char* name,WFlags f) | 6 | MainWidget::MainWidget(QWidget* parent,const char* name,WFlags f) |
7 | :QMainWindow(parent,name,f) | 7 | :QMainWindow(parent,name,f) |
8 | { | 8 | { |
9 | setCaption("Tonleiter"); | 9 | setCaption("Tonleiter"); |
10 | data=new Data::TonleiterData(this); | 10 | data=new Data::TonleiterData(this); |
11 | 11 | ||
12 | QWidget* mainwidget=new QWidget(this,"mainwidget"); | 12 | QWidget* mainwidget=new QWidget(this,"mainwidget"); |
13 | setCentralWidget(mainwidget); | 13 | setCentralWidget(mainwidget); |
14 | QBoxLayout* mainlayout=new QBoxLayout(mainwidget,QBoxLayout::TopToBottom); | 14 | QBoxLayout* mainlayout=new QBoxLayout(mainwidget,QBoxLayout::TopToBottom); |
15 | 15 | ||
16 | menuwidget=new Menu::MenuWidget(data,mainwidget); | 16 | menuwidget=new Menu::MenuWidget(data,mainwidget); |
17 | mainlayout->addWidget(menuwidget); | 17 | mainlayout->addWidget(menuwidget); |
18 | 18 | ||
19 | fretboard=new Graph::FretBoard(data,mainwidget); | 19 | fretboard=new Graph::FretBoard(data,mainwidget); |
20 | connect(fretboard,SIGNAL(pressed()),this,SLOT(fretboardPressed())); | ||
20 | mainlayout->addWidget(fretboard); | 21 | mainlayout->addWidget(fretboard); |
21 | 22 | ||
23 | showmenu=true; | ||
24 | |||
22 | } | 25 | } |
23 | //**************************************************************************** | 26 | //**************************************************************************** |
24 | MainWidget::~MainWidget() | 27 | MainWidget::~MainWidget() |
25 | { | 28 | { |
26 | } | 29 | } |
27 | //**************************************************************************** | 30 | //**************************************************************************** |
31 | void MainWidget::fretboardPressed() | ||
32 | { | ||
33 | if(showmenu) | ||
34 | { | ||
35 | menuwidget->hide(); | ||
36 | showmenu=false; | ||
37 | } | ||
38 | else | ||
39 | { | ||
40 | menuwidget->show(); | ||
41 | showmenu=true; | ||
42 | } | ||
43 | } | ||
44 | //**************************************************************************** | ||
28 | //**************************************************************************** | 45 | //**************************************************************************** |
diff --git a/noncore/multimedia/tonleiter/mainwidget.h b/noncore/multimedia/tonleiter/mainwidget.h index 9bb593c..5c0a1f8 100644 --- a/noncore/multimedia/tonleiter/mainwidget.h +++ b/noncore/multimedia/tonleiter/mainwidget.h | |||
@@ -1,22 +1,25 @@ | |||
1 | #ifndef TONLEITER_MAINWIDGET_H | 1 | #ifndef TONLEITER_MAINWIDGET_H |
2 | #define TONLEITER_MAINWIDGET_H | 2 | #define TONLEITER_MAINWIDGET_H |
3 | 3 | ||
4 | #include <qmainwindow.h> | 4 | #include <qmainwindow.h> |
5 | 5 | ||
6 | #include "fretboard.h" | 6 | #include "fretboard.h" |
7 | #include "menuwidget.h" | 7 | #include "menuwidget.h" |
8 | #include "tonleiterdata.h" | 8 | #include "tonleiterdata.h" |
9 | 9 | ||
10 | class MainWidget : public QMainWindow | 10 | class MainWidget : public QMainWindow |
11 | { | 11 | { |
12 | Q_OBJECT | 12 | Q_OBJECT |
13 | private: | 13 | private: |
14 | Data::TonleiterData* data; | 14 | Data::TonleiterData* data; |
15 | Menu::MenuWidget* menuwidget; | 15 | Menu::MenuWidget* menuwidget; |
16 | Graph::FretBoard* fretboard; | 16 | Graph::FretBoard* fretboard; |
17 | bool showmenu; | ||
17 | public: | 18 | public: |
18 | MainWidget(QWidget* parent=0,const char* name="MainWidget",WFlags f=0); | 19 | MainWidget(QWidget* parent=0,const char* name="MainWidget",WFlags f=0); |
19 | virtual ~MainWidget(); | 20 | virtual ~MainWidget(); |
21 | private slots: | ||
22 | void fretboardPressed(); | ||
20 | }; | 23 | }; |
21 | 24 | ||
22 | #endif //TONLEITER_MAINWIDGET_H | 25 | #endif //TONLEITER_MAINWIDGET_H |
diff --git a/noncore/multimedia/tonleiter/tonleiterdatahelper.cpp b/noncore/multimedia/tonleiter/tonleiterdatahelper.cpp index 156dba5..d904a71 100644 --- a/noncore/multimedia/tonleiter/tonleiterdatahelper.cpp +++ b/noncore/multimedia/tonleiter/tonleiterdatahelper.cpp | |||
@@ -31,99 +31,108 @@ int Note::getNoteFromName(QString name,int octave) | |||
31 | } | 31 | } |
32 | //**************************************************************************** | 32 | //**************************************************************************** |
33 | int Note::octaveOfBaseNote(int base,int note) | 33 | int Note::octaveOfBaseNote(int base,int note) |
34 | { | 34 | { |
35 | int normnote = (note>=base) ? note-base : (12-base)+note; | 35 | int normnote = (note>=base) ? note-base : (12-base)+note; |
36 | int octave=getOctaveOfNote(normnote); | 36 | int octave=getOctaveOfNote(normnote); |
37 | //qDebug("note %d of %d base is norm %d -> ocatve %d",note,base,normnote,octave); | 37 | //qDebug("note %d of %d base is norm %d -> ocatve %d",note,base,normnote,octave); |
38 | return octave; | 38 | return octave; |
39 | } | 39 | } |
40 | //**************************************************************************** | 40 | //**************************************************************************** |
41 | //**************************************************************************** | 41 | //**************************************************************************** |
42 | Instrument::Instrument() | 42 | Instrument::Instrument() |
43 | { | 43 | { |
44 | name="UNDEFINED"; | 44 | name="UNDEFINED"; |
45 | frets=0; | 45 | frets=0; |
46 | } | 46 | } |
47 | //**************************************************************************** | 47 | //**************************************************************************** |
48 | Instrument::Instrument(QString name,int frets,QValueList<int> strings) | 48 | Instrument::Instrument(QString name,int frets,QValueList<int> strings) |
49 | :name(name),frets(frets),strings(strings) | 49 | :name(name),frets(frets),strings(strings) |
50 | { | 50 | { |
51 | } | 51 | } |
52 | //**************************************************************************** | 52 | //**************************************************************************** |
53 | Instrument::~Instrument() | 53 | Instrument::~Instrument() |
54 | { | 54 | { |
55 | } | 55 | } |
56 | //**************************************************************************** | 56 | //**************************************************************************** |
57 | int Instrument::noOfStrings() | 57 | int Instrument::noOfStrings() |
58 | { | 58 | { |
59 | return (int)strings.count(); | 59 | return (int)strings.count(); |
60 | } | 60 | } |
61 | //**************************************************************************** | 61 | //**************************************************************************** |
62 | int Instrument::noOfFrets() | 62 | int Instrument::noOfFrets() |
63 | { | 63 | { |
64 | return frets; | 64 | return frets; |
65 | } | 65 | } |
66 | //**************************************************************************** | 66 | //**************************************************************************** |
67 | QString Instrument::instName() | 67 | QString Instrument::instName() |
68 | { | 68 | { |
69 | return name; | 69 | return name; |
70 | } | 70 | } |
71 | //**************************************************************************** | 71 | //**************************************************************************** |
72 | int Instrument::string(int id) | 72 | int Instrument::string(int id) |
73 | { | 73 | { |
74 | return strings[id]; | 74 | return strings[id]; |
75 | } | 75 | } |
76 | //**************************************************************************** | 76 | //**************************************************************************** |
77 | int Instrument::noOfOctaves() | 77 | int Instrument::noOfOctaves() |
78 | { | 78 | { |
79 | int lowest=strings[0]; | 79 | return (int) ceil((highestNote()-lowestNote())/12.0); |
80 | int highest=strings[strings.count()-1]+frets; | 80 | } |
81 | return (int) ceil((highest-lowest)/12.0); | 81 | //**************************************************************************** |
82 | int Instrument::lowestNote() | ||
83 | { | ||
84 | return strings[0]; | ||
85 | |||
86 | } | ||
87 | //**************************************************************************** | ||
88 | int Instrument::highestNote() | ||
89 | { | ||
90 | return strings[strings.count()-1]+frets; | ||
82 | } | 91 | } |
83 | //**************************************************************************** | 92 | //**************************************************************************** |
84 | //**************************************************************************** | 93 | //**************************************************************************** |
85 | Scale::Scale() | 94 | Scale::Scale() |
86 | { | 95 | { |
87 | name="UNDEFINED"; | 96 | name="UNDEFINED"; |
88 | } | 97 | } |
89 | //**************************************************************************** | 98 | //**************************************************************************** |
90 | Scale::Scale(QString name,QValueList<int> halftones) | 99 | Scale::Scale(QString name,QValueList<int> halftones) |
91 | :name(name),halftones(halftones) | 100 | :name(name),halftones(halftones) |
92 | { | 101 | { |
93 | } | 102 | } |
94 | //**************************************************************************** | 103 | //**************************************************************************** |
95 | Scale::~Scale() | 104 | Scale::~Scale() |
96 | { | 105 | { |
97 | } | 106 | } |
98 | //**************************************************************************** | 107 | //**************************************************************************** |
99 | int Scale::noOfHaltones() | 108 | int Scale::noOfHaltones() |
100 | { | 109 | { |
101 | return (int)halftones.count(); | 110 | return (int)halftones.count(); |
102 | } | 111 | } |
103 | //**************************************************************************** | 112 | //**************************************************************************** |
104 | int Scale::getHalfTone(int id) | 113 | int Scale::getHalfTone(int id) |
105 | { | 114 | { |
106 | if(id>=0 && id<noOfHaltones()) | 115 | if(id>=0 && id<noOfHaltones()) |
107 | return halftones[id]; | 116 | return halftones[id]; |
108 | else | 117 | else |
109 | return 0; | 118 | return 0; |
110 | } | 119 | } |
111 | //**************************************************************************** | 120 | //**************************************************************************** |
112 | QString Scale::scaleName() | 121 | QString Scale::scaleName() |
113 | { | 122 | { |
114 | return name; | 123 | return name; |
115 | } | 124 | } |
116 | //**************************************************************************** | 125 | //**************************************************************************** |
117 | bool Scale::noteInScale(int base,int note) | 126 | bool Scale::noteInScale(int base,int note) |
118 | { | 127 | { |
119 | int octave=Note::getOctaveOfNote(note); | 128 | int octave=Note::getOctaveOfNote(note); |
120 | note-=12*octave; | 129 | note-=12*octave; |
121 | int normnote = (note>=base) ? note-base : (12-base)+note; | 130 | int normnote = (note>=base) ? note-base : (12-base)+note; |
122 | 131 | ||
123 | if(halftones.contains(normnote)>0) | 132 | if(halftones.contains(normnote)>0) |
124 | { | 133 | { |
125 | //qDebug("OK : base : %d, note %d -> norm %d",base,note,normnote); | 134 | //qDebug("OK : base : %d, note %d -> norm %d",base,note,normnote); |
126 | return true; | 135 | return true; |
127 | } | 136 | } |
128 | else | 137 | else |
129 | { | 138 | { |
diff --git a/noncore/multimedia/tonleiter/tonleiterdatahelper.h b/noncore/multimedia/tonleiter/tonleiterdatahelper.h index e4153d7..061c781 100644 --- a/noncore/multimedia/tonleiter/tonleiterdatahelper.h +++ b/noncore/multimedia/tonleiter/tonleiterdatahelper.h | |||
@@ -1,55 +1,57 @@ | |||
1 | #ifndef TONLEITER_DATA_HELPER_H | 1 | #ifndef TONLEITER_DATA_HELPER_H |
2 | #define TONLEITER_DATA_HELPER_H | 2 | #define TONLEITER_DATA_HELPER_H |
3 | 3 | ||
4 | #include <qstring.h> | 4 | #include <qstring.h> |
5 | #include <qvaluelist.h> | 5 | #include <qvaluelist.h> |
6 | 6 | ||
7 | namespace Data | 7 | namespace Data |
8 | { | 8 | { |
9 | namespace Note | 9 | namespace Note |
10 | { | 10 | { |
11 | const QString notenames[]={"A","Bb","B","C","C#","D","D#","E","F","F#","G","G#"}; | 11 | const QString notenames[]={"A","Bb","B","C","C#","D","D#","E","F","F#","G","G#"}; |
12 | 12 | ||
13 | int getOctaveOfNote(int note); | 13 | int getOctaveOfNote(int note); |
14 | QString getNameOfNote(int note); | 14 | QString getNameOfNote(int note); |
15 | int getNoteFromName(QString name,int octave); | 15 | int getNoteFromName(QString name,int octave); |
16 | int octaveOfBaseNote(int base,int note); | 16 | int octaveOfBaseNote(int base,int note); |
17 | }; | 17 | }; |
18 | 18 | ||
19 | class Instrument | 19 | class Instrument |
20 | { | 20 | { |
21 | private: | 21 | private: |
22 | QString name; | 22 | QString name; |
23 | int frets; | 23 | int frets; |
24 | QValueList<int> strings; | 24 | QValueList<int> strings; |
25 | public: | 25 | public: |
26 | Instrument(); | 26 | Instrument(); |
27 | Instrument(QString name,int frets,QValueList<int> strings); | 27 | Instrument(QString name,int frets,QValueList<int> strings); |
28 | ~Instrument(); | 28 | ~Instrument(); |
29 | public: | 29 | public: |
30 | int noOfStrings(); | 30 | int noOfStrings(); |
31 | int noOfFrets(); | 31 | int noOfFrets(); |
32 | QString instName(); | 32 | QString instName(); |
33 | int string(int id); | 33 | int string(int id); |
34 | int noOfOctaves(); | 34 | int noOfOctaves(); |
35 | int lowestNote(); | ||
36 | int highestNote(); | ||
35 | }; | 37 | }; |
36 | 38 | ||
37 | class Scale | 39 | class Scale |
38 | { | 40 | { |
39 | private: | 41 | private: |
40 | QValueList<int> halftones; | 42 | QValueList<int> halftones; |
41 | QString name; | 43 | QString name; |
42 | public: | 44 | public: |
43 | Scale(); | 45 | Scale(); |
44 | Scale(QString name,QValueList<int> halftones); | 46 | Scale(QString name,QValueList<int> halftones); |
45 | ~Scale(); | 47 | ~Scale(); |
46 | public: | 48 | public: |
47 | int noOfHaltones(); | 49 | int noOfHaltones(); |
48 | int getHalfTone(int id); | 50 | int getHalfTone(int id); |
49 | QString scaleName(); | 51 | QString scaleName(); |
50 | bool noteInScale(int base,int note); | 52 | bool noteInScale(int base,int note); |
51 | }; | 53 | }; |
52 | }; | 54 | }; |
53 | 55 | ||
54 | #endif //TONLEITER_DATA_HELPER_H | 56 | #endif //TONLEITER_DATA_HELPER_H |
55 | 57 | ||