author | waspe <waspe> | 2003-11-16 19:31:57 (UTC) |
---|---|---|
committer | waspe <waspe> | 2003-11-16 19:31:57 (UTC) |
commit | e7a81ed5ba0dc6b996f179d1dc40d778492218a9 (patch) (unidiff) | |
tree | 62081f88e6dad4df5a2f278050cf402c2da9ed98 | |
parent | 0b0c071017298ebd189420f85b5aa8d44885c50e (diff) | |
download | opie-e7a81ed5ba0dc6b996f179d1dc40d778492218a9.zip opie-e7a81ed5ba0dc6b996f179d1dc40d778492218a9.tar.gz opie-e7a81ed5ba0dc6b996f179d1dc40d778492218a9.tar.bz2 |
first commit
-rw-r--r-- | noncore/multimedia/tonleiter/config.in | 4 | ||||
-rw-r--r-- | noncore/multimedia/tonleiter/fretboard.cpp | 159 | ||||
-rw-r--r-- | noncore/multimedia/tonleiter/fretboard.h | 54 | ||||
-rw-r--r-- | noncore/multimedia/tonleiter/main.cpp | 19 | ||||
-rw-r--r-- | noncore/multimedia/tonleiter/mainwidget.cpp | 28 | ||||
-rw-r--r-- | noncore/multimedia/tonleiter/mainwidget.h | 22 | ||||
-rw-r--r-- | noncore/multimedia/tonleiter/menuwidget.cpp | 72 | ||||
-rw-r--r-- | noncore/multimedia/tonleiter/menuwidget.h | 30 | ||||
-rw-r--r-- | noncore/multimedia/tonleiter/tonleiter.control | 9 | ||||
-rw-r--r-- | noncore/multimedia/tonleiter/tonleiter.cpp | 0 | ||||
-rw-r--r-- | noncore/multimedia/tonleiter/tonleiter.pro | 13 | ||||
-rw-r--r-- | noncore/multimedia/tonleiter/tonleiterdata.cpp | 151 | ||||
-rw-r--r-- | noncore/multimedia/tonleiter/tonleiterdata.h | 46 | ||||
-rw-r--r-- | noncore/multimedia/tonleiter/tonleiterdatahelper.cpp | 133 | ||||
-rw-r--r-- | noncore/multimedia/tonleiter/tonleiterdatahelper.h | 53 | ||||
-rw-r--r-- | pics/tonleiter.png | bin | 0 -> 416 bytes |
16 files changed, 793 insertions, 0 deletions
diff --git a/noncore/multimedia/tonleiter/config.in b/noncore/multimedia/tonleiter/config.in new file mode 100644 index 0000000..d580ad7 --- a/dev/null +++ b/noncore/multimedia/tonleiter/config.in | |||
@@ -0,0 +1,4 @@ | |||
1 | config TONLEITER | ||
2 | boolean "tonleiter (shows scales on sting instruments)" | ||
3 | default "n" | ||
4 | depends ( LIBQPE || LIBQPE-X11 ) | ||
diff --git a/noncore/multimedia/tonleiter/fretboard.cpp b/noncore/multimedia/tonleiter/fretboard.cpp new file mode 100644 index 0000000..d8e48d3 --- a/dev/null +++ b/noncore/multimedia/tonleiter/fretboard.cpp | |||
@@ -0,0 +1,159 @@ | |||
1 | #include "fretboard.h" | ||
2 | |||
3 | #include <qpainter.h> | ||
4 | |||
5 | FretBoard::FretBoard(TonleiterData* data,QWidget* parent,const char* name,WFlags f) | ||
6 | :QWidget(parent,name,f),data(data) | ||
7 | { | ||
8 | setBackgroundColor(QColor(0,0,0)); | ||
9 | fretpen=QPen(QColor(155,155,155),0); | ||
10 | markerbrush=QBrush(QColor(155,155,155)); | ||
11 | stringpen=QPen(QColor(255,255,255),3); | ||
12 | connect(data,SIGNAL(dataChange()),this,SLOT(dataChange())); | ||
13 | } | ||
14 | //**************************************************************************** | ||
15 | FretBoard::~FretBoard() | ||
16 | { | ||
17 | } | ||
18 | //**************************************************************************** | ||
19 | void FretBoard::dataChange() | ||
20 | { | ||
21 | repaint(true); | ||
22 | } | ||
23 | //**************************************************************************** | ||
24 | void FretBoard::paintEvent(QPaintEvent* pe) | ||
25 | { | ||
26 | Q_UNUSED(pe); | ||
27 | |||
28 | int instid=data->getCurrentInstrumentID(); | ||
29 | inst=data->getInstrument(instid); | ||
30 | //qDebug("inst %d is %s",instid,inst.instName().data()); | ||
31 | |||
32 | QRect mysize=rect(); | ||
33 | |||
34 | xmargin=(int)(mysize.width()*0.05); | ||
35 | xmin=2*xmargin; | ||
36 | xmax=mysize.width()-xmargin; | ||
37 | xwidth=xmax-xmin; | ||
38 | |||
39 | ymargin=(int)(mysize.height()*0.1); | ||
40 | ymin=ymargin; | ||
41 | ymax=mysize.height()-2*ymargin; | ||
42 | yheight=ymax-ymin; | ||
43 | |||
44 | QPainter p(this); | ||
45 | paintBoard(&p); | ||
46 | paintFrets(&p); | ||
47 | paintStrings(&p); | ||
48 | paintScale(&p); | ||
49 | } | ||
50 | //**************************************************************************** | ||
51 | void FretBoard::resizeEvent(QResizeEvent* re) | ||
52 | { | ||
53 | Q_UNUSED(re); | ||
54 | } | ||
55 | //**************************************************************************** | ||
56 | void FretBoard::paintBoard(QPainter* p) | ||
57 | { | ||
58 | //debug | ||
59 | QColor bgc=QColor(142,138,120); | ||
60 | p->setPen(QPen(bgc,5)); | ||
61 | p->setBrush(QBrush(bgc)); | ||
62 | p->drawRect(xmin,ymin,xwidth,yheight); | ||
63 | |||
64 | } | ||
65 | //**************************************************************************** | ||
66 | void FretBoard::paintFrets(QPainter* p) | ||
67 | { | ||
68 | //draw frets | ||
69 | p->setPen(fretpen); | ||
70 | p->setBrush(markerbrush); | ||
71 | fretdist=(double)(xwidth)/(double)(inst.noOfFrets()); | ||
72 | |||
73 | int markerwidth = (int)(fretdist/4.0); | ||
74 | if(markerwidth>5) | ||
75 | markerwidth=5; | ||
76 | else if(markerwidth<2) | ||
77 | markerwidth=2; | ||
78 | |||
79 | for(int f=0;f<=inst.noOfFrets();f++) | ||
80 | { | ||
81 | int fretpos=(int)(fretdist*f); | ||
82 | p->drawLine(fretpos+xmin,ymin,fretpos+xmin,ymax); | ||
83 | |||
84 | int above_octave=f%12; | ||
85 | int octave=(f-above_octave)/12; | ||
86 | int marker=f-12*octave; | ||
87 | |||
88 | |||
89 | if(marker==5 || marker==7 || marker==9) | ||
90 | { | ||
91 | p->drawEllipse(fretpos+xmin,ymax+ymargin,markerwidth,markerwidth); | ||
92 | } | ||
93 | else if(marker==0 && f!=0) | ||
94 | { | ||
95 | p->drawEllipse(fretpos+xmin,ymax+ymargin+2*markerwidth,markerwidth,markerwidth); | ||
96 | p->drawEllipse(fretpos+xmin,ymax+ymargin-2*markerwidth,markerwidth,markerwidth); | ||
97 | } | ||
98 | |||
99 | } | ||
100 | } | ||
101 | //**************************************************************************** | ||
102 | void FretBoard::paintStrings(QPainter* p) | ||
103 | { | ||
104 | //draw strings | ||
105 | p->setPen(stringpen); | ||
106 | |||
107 | stringdist=(double)(yheight)/(double)(inst.noOfStrings()-1); | ||
108 | for(int s=0;s<inst.noOfStrings();s++) | ||
109 | { | ||
110 | int stringpos=(int)(stringdist*s); | ||
111 | p->drawLine(xmin,stringpos+ymin,xmax,stringpos+ymin); | ||
112 | |||
113 | int stinglabelid=inst.noOfStrings()-(s+1); | ||
114 | QString label=Note::getNameOfNote(inst.string(stinglabelid)); | ||
115 | p->drawText(xmargin/2,stringpos+ymin,label); | ||
116 | } | ||
117 | } | ||
118 | //**************************************************************************** | ||
119 | void FretBoard::paintScale(QPainter* p) | ||
120 | { | ||
121 | int dotsize=10; | ||
122 | int scaleid=data->getCurrentScaleID(); | ||
123 | Scale scale=data->getScale(scaleid); | ||
124 | |||
125 | int colorstart=255%inst.noOfOctaves(); | ||
126 | int colorintervall=(255-colorstart)/inst.noOfOctaves(); | ||
127 | |||
128 | for(int s=0;s<inst.noOfStrings();s++) | ||
129 | { | ||
130 | int y=(int)(stringdist*s)+ymin; | ||
131 | int stingid=inst.noOfStrings()-(s+1); | ||
132 | for(int f=0;f<=inst.noOfFrets();f++) | ||
133 | { | ||
134 | int note=inst.string(stingid)+f; | ||
135 | if(scale.noteInScale(data->getCurrentBaseNote(),note)) | ||
136 | { | ||
137 | int x=(int)(fretdist*f)+xmin; | ||
138 | |||
139 | int octave=Note::octaveOfBaseNote(data->getCurrentBaseNote(),note); | ||
140 | if(octave>5) octave=5; | ||
141 | p->setPen(QColor(255,0,0)); | ||
142 | int c=colorstart+octave*colorintervall; | ||
143 | QColor dotcolor(c,c,255); | ||
144 | p->setBrush(dotcolor); | ||
145 | |||
146 | p->drawEllipse(x-dotsize/2,y-dotsize/2,dotsize,dotsize); | ||
147 | |||
148 | if(data->isDrawNames()) | ||
149 | { | ||
150 | p->setPen(QColor(0,255,0)); | ||
151 | p->drawText(x-dotsize/2,y-dotsize/2,Note::getNameOfNote(note)); | ||
152 | } | ||
153 | |||
154 | } | ||
155 | } | ||
156 | } | ||
157 | } | ||
158 | //**************************************************************************** | ||
159 | //**************************************************************************** | ||
diff --git a/noncore/multimedia/tonleiter/fretboard.h b/noncore/multimedia/tonleiter/fretboard.h new file mode 100644 index 0000000..eb509b0 --- a/dev/null +++ b/noncore/multimedia/tonleiter/fretboard.h | |||
@@ -0,0 +1,54 @@ | |||
1 | #ifndef TONLEITER_FRET_BOARD_H | ||
2 | #define TONLEITER_FRET_BOARD_H | ||
3 | |||
4 | #include <qbrush.h> | ||
5 | #include <qpen.h> | ||
6 | #include <qvaluelist.h> | ||
7 | #include <qwidget.h> | ||
8 | |||
9 | |||
10 | #include "tonleiterdata.h" | ||
11 | |||
12 | class FretBoard : public QWidget | ||
13 | { | ||
14 | Q_OBJECT | ||
15 | private: | ||
16 | TonleiterData* data; | ||
17 | |||
18 | QPen fretpen; | ||
19 | QBrush markerbrush; | ||
20 | QPen stringpen; | ||
21 | |||
22 | Instrument inst; | ||
23 | |||
24 | int xmargin; | ||
25 | int xmin; | ||
26 | int xmax; | ||
27 | int xwidth; | ||
28 | |||
29 | int ymargin; | ||
30 | int ymin; | ||
31 | int ymax; | ||
32 | int yheight; | ||
33 | |||
34 | double fretdist; | ||
35 | double stringdist; | ||
36 | |||
37 | public: | ||
38 | FretBoard(TonleiterData* data,QWidget* parent,const char* name="FretBoard",WFlags f=0); | ||
39 | virtual ~FretBoard(); | ||
40 | private slots: | ||
41 | void dataChange(); | ||
42 | private: | ||
43 | void paintEvent(QPaintEvent* pe); | ||
44 | void resizeEvent(QResizeEvent* re); | ||
45 | //void mousePressEvent(QMouseEvent* mpe); | ||
46 | //void mouseMoveEvent(QMouseEvent* mme); | ||
47 | //void mouseReleaseEvent(QMouseEvent* mre); | ||
48 | void paintBoard(QPainter* p); | ||
49 | void paintFrets(QPainter* p); | ||
50 | void paintStrings(QPainter* p); | ||
51 | void paintScale(QPainter* p); | ||
52 | }; | ||
53 | |||
54 | #endif //TONLEITER_FRET_BOARD_H | ||
diff --git a/noncore/multimedia/tonleiter/main.cpp b/noncore/multimedia/tonleiter/main.cpp new file mode 100644 index 0000000..0eaa162 --- a/dev/null +++ b/noncore/multimedia/tonleiter/main.cpp | |||
@@ -0,0 +1,19 @@ | |||
1 | /*************************************************************************** | ||
2 | * This program is free software; you can redistribute it and/or modify * | ||
3 | * it under the terms of the GNU General Public License as published by * | ||
4 | * the Free Software Foundation; either version 2 of the License, or * | ||
5 | * (at your option) any later version. * | ||
6 | ***************************************************************************/ | ||
7 | |||
8 | #include "mainwidget.h" | ||
9 | #include <qpe/qpeapplication.h> | ||
10 | |||
11 | int main(int argc, char* argv[]) | ||
12 | { | ||
13 | QPEApplication a(argc, argv); | ||
14 | MainWidget mw; | ||
15 | a.showMainWidget( &mw); | ||
16 | return a.exec(); | ||
17 | } | ||
18 | |||
19 | |||
diff --git a/noncore/multimedia/tonleiter/mainwidget.cpp b/noncore/multimedia/tonleiter/mainwidget.cpp new file mode 100644 index 0000000..0a20b9e --- a/dev/null +++ b/noncore/multimedia/tonleiter/mainwidget.cpp | |||
@@ -0,0 +1,28 @@ | |||
1 | #include "mainwidget.h" | ||
2 | |||
3 | #include <qwidget.h> | ||
4 | #include <qlayout.h> | ||
5 | |||
6 | MainWidget::MainWidget(QWidget* parent,const char* name,WFlags f) | ||
7 | :QMainWindow(parent,name,f) | ||
8 | { | ||
9 | setCaption("Tonleiter"); | ||
10 | data=new TonleiterData(this); | ||
11 | |||
12 | QWidget* mainwidget=new QWidget(this,"mainwidget"); | ||
13 | setCentralWidget(mainwidget); | ||
14 | QBoxLayout* mainlayout=new QBoxLayout(mainwidget,QBoxLayout::TopToBottom); | ||
15 | |||
16 | menuwidget=new MenuWidget(data,mainwidget); | ||
17 | mainlayout->addWidget(menuwidget); | ||
18 | |||
19 | fretboard=new FretBoard(data,mainwidget); | ||
20 | mainlayout->addWidget(fretboard); | ||
21 | |||
22 | } | ||
23 | //**************************************************************************** | ||
24 | MainWidget::~MainWidget() | ||
25 | { | ||
26 | } | ||
27 | //**************************************************************************** | ||
28 | //**************************************************************************** | ||
diff --git a/noncore/multimedia/tonleiter/mainwidget.h b/noncore/multimedia/tonleiter/mainwidget.h new file mode 100644 index 0000000..71b5ba9 --- a/dev/null +++ b/noncore/multimedia/tonleiter/mainwidget.h | |||
@@ -0,0 +1,22 @@ | |||
1 | #ifndef TONLEITER_MAINWIDGET_H | ||
2 | #define TONLEITER_MAINWIDGET_H | ||
3 | |||
4 | #include <qmainwindow.h> | ||
5 | |||
6 | #include "fretboard.h" | ||
7 | #include "menuwidget.h" | ||
8 | #include "tonleiterdata.h" | ||
9 | |||
10 | class MainWidget : public QMainWindow | ||
11 | { | ||
12 | Q_OBJECT | ||
13 | private: | ||
14 | TonleiterData* data; | ||
15 | MenuWidget* menuwidget; | ||
16 | FretBoard* fretboard; | ||
17 | public: | ||
18 | MainWidget(QWidget* parent=0,const char* name="MainWidget",WFlags f=0); | ||
19 | virtual ~MainWidget(); | ||
20 | }; | ||
21 | |||
22 | #endif //TONLEITER_MAINWIDGET_H | ||
diff --git a/noncore/multimedia/tonleiter/menuwidget.cpp b/noncore/multimedia/tonleiter/menuwidget.cpp new file mode 100644 index 0000000..9cc2c6b --- a/dev/null +++ b/noncore/multimedia/tonleiter/menuwidget.cpp | |||
@@ -0,0 +1,72 @@ | |||
1 | #include "menuwidget.h" | ||
2 | |||
3 | #include <qlabel.h> | ||
4 | #include <qlayout.h> | ||
5 | |||
6 | MenuWidget::MenuWidget(TonleiterData* data,QWidget* parent,const char* name,WFlags f) | ||
7 | :QWidget(parent,name,f),data(data) | ||
8 | { | ||
9 | QGridLayout* layout=new QGridLayout(this,3,3,10,-1,"menulayout"); | ||
10 | |||
11 | QLabel* instLabel=new QLabel(tr("Instrument"),this,"instLabel"); | ||
12 | layout->addWidget(instLabel,0,0); | ||
13 | boxInst=new QComboBox(this,"boxInst"); | ||
14 | connect(boxInst,SIGNAL(activated(int)),data,SLOT(setCurrentInstrumetID(int))); | ||
15 | layout->addWidget(boxInst,0,1); | ||
16 | editInst=new QPushButton(tr("Edit"),this,"editInst"); | ||
17 | layout->addWidget(editInst,0,2); | ||
18 | |||
19 | QLabel* noteLabel=new QLabel(tr("Note"),this,"noteLabel"); | ||
20 | layout->addWidget(noteLabel,1,0); | ||
21 | boxNote=new QComboBox(this,"boxNote"); | ||
22 | connect(boxNote,SIGNAL(activated(int)),data,SLOT(setCurrentNote(int))); | ||
23 | layout->addWidget(boxNote,1,1); | ||
24 | for(int a=0;a<12;a++) | ||
25 | boxNote->insertItem(Note::notenames[a],a); | ||
26 | boxNote->setCurrentItem(data->getCurrentBaseNote()); | ||
27 | noteCheck=new QCheckBox(tr("show notes"),this,"noteCheck"); | ||
28 | noteCheck->setChecked(data->isDrawNames()); | ||
29 | connect(noteCheck,SIGNAL(toggled(bool)),data,SLOT(setDrawNames(bool))); | ||
30 | layout->addWidget(noteCheck,1,2); | ||
31 | |||
32 | QLabel* scaleLabel=new QLabel(tr("Scale"),this,"scaleLabel"); | ||
33 | layout->addWidget(scaleLabel,2,0); | ||
34 | boxScale=new QComboBox(this,"boxScale"); | ||
35 | connect(boxScale,SIGNAL(activated(int)),data,SLOT(setCurrentScaleID(int))); | ||
36 | layout->addWidget(boxScale,2,1); | ||
37 | editScale=new QPushButton(tr("Edit"),this,"editScale"); | ||
38 | layout->addWidget(editScale,2,2); | ||
39 | |||
40 | updateBoxes(); | ||
41 | |||
42 | } | ||
43 | //**************************************************************************** | ||
44 | MenuWidget::~MenuWidget() | ||
45 | { | ||
46 | } | ||
47 | //**************************************************************************** | ||
48 | void MenuWidget::updateBoxes() | ||
49 | { | ||
50 | boxInst->clear(); | ||
51 | |||
52 | for(int i=0;i<data->noOfInstruments();i++) | ||
53 | { | ||
54 | Instrument inst=data->getInstrument(i); | ||
55 | QString name=inst.instName(); | ||
56 | if(name.isNull()) continue; | ||
57 | boxInst->insertItem(name,i); | ||
58 | } | ||
59 | boxInst->setCurrentItem(data->getCurrentInstrumentID()); | ||
60 | |||
61 | boxScale->clear(); | ||
62 | for(int s=0;s<data->noOfScales();s++) | ||
63 | { | ||
64 | Scale scale=data->getScale(s); | ||
65 | QString name=scale.scaleName(); | ||
66 | if(name.isNull()) continue; | ||
67 | boxScale->insertItem(name,s); | ||
68 | } | ||
69 | boxScale->setCurrentItem(data->getCurrentScaleID()); | ||
70 | } | ||
71 | //**************************************************************************** | ||
72 | //**************************************************************************** | ||
diff --git a/noncore/multimedia/tonleiter/menuwidget.h b/noncore/multimedia/tonleiter/menuwidget.h new file mode 100644 index 0000000..2635f8a --- a/dev/null +++ b/noncore/multimedia/tonleiter/menuwidget.h | |||
@@ -0,0 +1,30 @@ | |||
1 | #ifndef TONLEITER_MENU_WIDGET_H | ||
2 | #define TONLEITER_MENU_WIDGET_H | ||
3 | |||
4 | #include <qcheckbox.h> | ||
5 | #include <qcombobox.h> | ||
6 | #include <qpushbutton.h> | ||
7 | #include <qwidget.h> | ||
8 | #include <qlabel.h> | ||
9 | |||
10 | #include "tonleiterdata.h" | ||
11 | |||
12 | class MenuWidget : public QWidget | ||
13 | { | ||
14 | Q_OBJECT | ||
15 | private: | ||
16 | TonleiterData* data; | ||
17 | QComboBox* boxInst; | ||
18 | QPushButton* editInst; | ||
19 | QComboBox* boxNote; | ||
20 | QCheckBox* noteCheck; | ||
21 | QComboBox* boxScale; | ||
22 | QPushButton* editScale; | ||
23 | public: | ||
24 | MenuWidget(TonleiterData* data,QWidget* parent,const char* name="MenuWidget",WFlags f=0); | ||
25 | ~MenuWidget(); | ||
26 | public slots: | ||
27 | void updateBoxes(); | ||
28 | }; | ||
29 | |||
30 | #endif //TONLEITER_MENU_WIDGET_H | ||
diff --git a/noncore/multimedia/tonleiter/tonleiter.control b/noncore/multimedia/tonleiter/tonleiter.control new file mode 100644 index 0000000..e8a36e8 --- a/dev/null +++ b/noncore/multimedia/tonleiter/tonleiter.control | |||
@@ -0,0 +1,9 @@ | |||
1 | Package: tonleiter | ||
2 | Files: bin/tonlieter pics/tonleiter apps/Applications/tonleiter.desktop | ||
3 | Priority: optional | ||
4 | Section: multimedia/applications | ||
5 | Maintainer: Ralf Waspe <rwaspe@web.de> | ||
6 | Architecture: arm | ||
7 | Depends: task-opie-minimal | ||
8 | Description: music scales for sting instruments | ||
9 | Version: $QPE_VERSION$EXTRAVERSION | ||
diff --git a/noncore/multimedia/tonleiter/tonleiter.cpp b/noncore/multimedia/tonleiter/tonleiter.cpp new file mode 100644 index 0000000..e69de29 --- a/dev/null +++ b/noncore/multimedia/tonleiter/tonleiter.cpp | |||
diff --git a/noncore/multimedia/tonleiter/tonleiter.pro b/noncore/multimedia/tonleiter/tonleiter.pro new file mode 100644 index 0000000..bf19c3a --- a/dev/null +++ b/noncore/multimedia/tonleiter/tonleiter.pro | |||
@@ -0,0 +1,13 @@ | |||
1 | TEMPLATE = app | ||
2 | #CONFIG = qt warn_on debug | ||
3 | CONFIG = qt warn_on release | ||
4 | HEADERS = mainwidget.h tonleiterdata.h tonleiterdatahelper.h fretboard.h menuwidget.h | ||
5 | SOURCES = mainwidget.cpp tonleiterdata.cpp tonleiterdatahelper.cpp fretboard.cpp menuwidget.cpp main.cpp | ||
6 | INCLUDEPATH += $(OPIEDIR)/include | ||
7 | DEPENDPATH += $(OPIEDIR)/include | ||
8 | LIBS += -lqpe | ||
9 | INTERFACES = | ||
10 | TARGET = tonleiter | ||
11 | DESTDIR = $(OPIEDIR)/bin | ||
12 | #TMAKE_CXXFLAGS += -DQT_QWS_VERCEL_IDR -DQWS -fno-exceptions -fno-rtti | ||
13 | include ( $(OPIEDIR)/include.pro ) | ||
diff --git a/noncore/multimedia/tonleiter/tonleiterdata.cpp b/noncore/multimedia/tonleiter/tonleiterdata.cpp new file mode 100644 index 0000000..8a9fdca --- a/dev/null +++ b/noncore/multimedia/tonleiter/tonleiterdata.cpp | |||
@@ -0,0 +1,151 @@ | |||
1 | #include "tonleiterdata.h" | ||
2 | |||
3 | TonleiterData::TonleiterData(QObject* parent) | ||
4 | :QObject(parent) | ||
5 | { | ||
6 | drawnames=true; | ||
7 | loadData(); | ||
8 | } | ||
9 | //**************************************************************************** | ||
10 | TonleiterData::~TonleiterData() | ||
11 | { | ||
12 | saveData(); | ||
13 | } | ||
14 | //**************************************************************************** | ||
15 | void TonleiterData::setCurrentInstrumetID(int id) | ||
16 | { | ||
17 | if(id>=0 && id<noOfInstruments()) | ||
18 | { | ||
19 | currentInstrumentID=id; | ||
20 | emit dataChange(); | ||
21 | } | ||
22 | } | ||
23 | //**************************************************************************** | ||
24 | void TonleiterData::setCurrentScaleID(int id) | ||
25 | { | ||
26 | if(id>=0 && id<noOfScales()) | ||
27 | { | ||
28 | currentScaleID=id; | ||
29 | emit dataChange(); | ||
30 | } | ||
31 | } | ||
32 | //**************************************************************************** | ||
33 | void TonleiterData::setCurrentNote(int id) | ||
34 | { | ||
35 | if(id>=0 && id<12) | ||
36 | { | ||
37 | currentNote=id; | ||
38 | emit dataChange(); | ||
39 | } | ||
40 | } | ||
41 | //**************************************************************************** | ||
42 | void TonleiterData::setDrawNames(bool dn) | ||
43 | { | ||
44 | drawnames=dn; | ||
45 | emit dataChange(); | ||
46 | } | ||
47 | //**************************************************************************** | ||
48 | void TonleiterData::loadData() | ||
49 | { | ||
50 | QValueList<int> strings1; | ||
51 | strings1.append(Note::getNoteFromName("B",0)); | ||
52 | strings1.append(Note::getNoteFromName("E",1)); | ||
53 | strings1.append(Note::getNoteFromName("A",1)); | ||
54 | strings1.append(Note::getNoteFromName("D",2)); | ||
55 | strings1.append(Note::getNoteFromName("G",2)); | ||
56 | strings1.append(Note::getNoteFromName("C",3)); | ||
57 | instruments.append(Instrument("Thumb6",26,strings1)); | ||
58 | |||
59 | QValueList<int> strings2; | ||
60 | strings2.append(Note::getNoteFromName("E",1)); | ||
61 | strings2.append(Note::getNoteFromName("A",1)); | ||
62 | strings2.append(Note::getNoteFromName("D",2)); | ||
63 | strings2.append(Note::getNoteFromName("G",2)); | ||
64 | instruments.append(Instrument("Bass 4",12,strings2)); | ||
65 | |||
66 | currentInstrumentID=1; | ||
67 | |||
68 | QValueList<int> scale1; | ||
69 | scale1.append(0); | ||
70 | scale1.append(2); | ||
71 | scale1.append(3); | ||
72 | scale1.append(5); | ||
73 | scale1.append(7); | ||
74 | scale1.append(8); | ||
75 | scale1.append(10); | ||
76 | scales.append(Scale("Minor",scale1)); | ||
77 | |||
78 | QValueList<int> scale2; | ||
79 | scale2.append(0); | ||
80 | scale2.append(2); | ||
81 | scale2.append(4); | ||
82 | scale2.append(5); | ||
83 | scale2.append(7); | ||
84 | scale2.append(9); | ||
85 | scale2.append(10); | ||
86 | scales.append(Scale("Major",scale2)); | ||
87 | |||
88 | currentScaleID=0; | ||
89 | |||
90 | currentNote=Note::getNoteFromName("A",0); | ||
91 | } | ||
92 | //**************************************************************************** | ||
93 | void TonleiterData::saveData() | ||
94 | { | ||
95 | } | ||
96 | //**************************************************************************** | ||
97 | int TonleiterData::noOfInstruments() | ||
98 | { | ||
99 | return (int)instruments.count(); | ||
100 | } | ||
101 | //**************************************************************************** | ||
102 | Instrument TonleiterData::getInstrument(int id) | ||
103 | { | ||
104 | if(id>=0 && id<noOfInstruments()) | ||
105 | return instruments[id]; | ||
106 | else | ||
107 | { | ||
108 | qDebug("undefined insrtument %d of %d",id,instruments.count()); | ||
109 | return Instrument(); | ||
110 | } | ||
111 | |||
112 | } | ||
113 | //**************************************************************************** | ||
114 | int TonleiterData::getCurrentInstrumentID() | ||
115 | { | ||
116 | return currentInstrumentID; | ||
117 | } | ||
118 | //**************************************************************************** | ||
119 | int TonleiterData::noOfScales() | ||
120 | { | ||
121 | return (int)scales.count(); | ||
122 | } | ||
123 | //**************************************************************************** | ||
124 | Scale TonleiterData::getScale(int id) | ||
125 | { | ||
126 | if(id>=0 && id<noOfScales()) | ||
127 | return scales[id]; | ||
128 | else | ||
129 | { | ||
130 | qDebug("Undefined scale"); | ||
131 | return Scale(); | ||
132 | } | ||
133 | } | ||
134 | //**************************************************************************** | ||
135 | int TonleiterData::getCurrentScaleID() | ||
136 | { | ||
137 | return currentScaleID; | ||
138 | } | ||
139 | //**************************************************************************** | ||
140 | int TonleiterData::getCurrentBaseNote() | ||
141 | { | ||
142 | return currentNote; | ||
143 | } | ||
144 | //**************************************************************************** | ||
145 | bool TonleiterData::isDrawNames() | ||
146 | { | ||
147 | return drawnames; | ||
148 | } | ||
149 | //**************************************************************************** | ||
150 | //**************************************************************************** | ||
151 | |||
diff --git a/noncore/multimedia/tonleiter/tonleiterdata.h b/noncore/multimedia/tonleiter/tonleiterdata.h new file mode 100644 index 0000000..a5e6884 --- a/dev/null +++ b/noncore/multimedia/tonleiter/tonleiterdata.h | |||
@@ -0,0 +1,46 @@ | |||
1 | #ifndef TONLEITER_DATA_H | ||
2 | #define TONLEITER_DATA_H | ||
3 | |||
4 | #include <qobject.h> | ||
5 | |||
6 | #include "tonleiterdatahelper.h" | ||
7 | |||
8 | class TonleiterData : public QObject | ||
9 | { | ||
10 | Q_OBJECT | ||
11 | private: | ||
12 | QValueList<Instrument> instruments; | ||
13 | int currentInstrumentID; | ||
14 | |||
15 | QValueList<Scale> scales; | ||
16 | int currentScaleID; | ||
17 | |||
18 | int currentNote; | ||
19 | bool drawnames; | ||
20 | public: | ||
21 | TonleiterData(QObject* parent); | ||
22 | ~TonleiterData(); | ||
23 | signals: | ||
24 | void dataChange(); | ||
25 | public slots: | ||
26 | void setCurrentInstrumetID(int id); | ||
27 | void setCurrentScaleID(int id); | ||
28 | void setCurrentNote(int id); | ||
29 | void setDrawNames(bool dn); | ||
30 | private: | ||
31 | void loadData(); | ||
32 | void saveData(); | ||
33 | public: | ||
34 | int noOfInstruments(); | ||
35 | Instrument getInstrument(int id); | ||
36 | int getCurrentInstrumentID(); | ||
37 | |||
38 | int noOfScales(); | ||
39 | Scale getScale(int id); | ||
40 | int getCurrentScaleID(); | ||
41 | |||
42 | int getCurrentBaseNote(); | ||
43 | bool isDrawNames(); | ||
44 | }; | ||
45 | |||
46 | #endif //TONLEITER_DATA_H | ||
diff --git a/noncore/multimedia/tonleiter/tonleiterdatahelper.cpp b/noncore/multimedia/tonleiter/tonleiterdatahelper.cpp new file mode 100644 index 0000000..6b8a5bd --- a/dev/null +++ b/noncore/multimedia/tonleiter/tonleiterdatahelper.cpp | |||
@@ -0,0 +1,133 @@ | |||
1 | #include "tonleiterdatahelper.h" | ||
2 | |||
3 | int Note::getOctaveOfNote(int note) | ||
4 | { | ||
5 | int remain=note%12; | ||
6 | return (note-remain)/12; | ||
7 | } | ||
8 | //**************************************************************************** | ||
9 | QString Note::getNameOfNote(int note) | ||
10 | { | ||
11 | int octave=getOctaveOfNote(note); | ||
12 | return notenames[note-12*octave]; | ||
13 | } | ||
14 | //**************************************************************************** | ||
15 | int Note::getNoteFromName(QString name,int octave) | ||
16 | { | ||
17 | int notevalue=0; | ||
18 | for(int a=0;a<12;a++) | ||
19 | { | ||
20 | if(name==notenames[a]) | ||
21 | { | ||
22 | notevalue=a; | ||
23 | break; | ||
24 | } | ||
25 | } | ||
26 | return notevalue+12*octave; | ||
27 | } | ||
28 | //**************************************************************************** | ||
29 | int Note::octaveOfBaseNote(int base,int note) | ||
30 | { | ||
31 | int normnote = (note>=base) ? note-base : (12-base)+note; | ||
32 | int octave=getOctaveOfNote(normnote); | ||
33 | //qDebug("note %d of %d base is norm %d -> ocatve %d",note,base,normnote,octave); | ||
34 | return octave; | ||
35 | } | ||
36 | //**************************************************************************** | ||
37 | //**************************************************************************** | ||
38 | Instrument::Instrument() | ||
39 | { | ||
40 | name="UNDEFINED"; | ||
41 | frets=0; | ||
42 | } | ||
43 | //**************************************************************************** | ||
44 | Instrument::Instrument(QString name,int frets,QValueList<int> strings) | ||
45 | :name(name),frets(frets),strings(strings) | ||
46 | { | ||
47 | } | ||
48 | //**************************************************************************** | ||
49 | Instrument::~Instrument() | ||
50 | { | ||
51 | } | ||
52 | //**************************************************************************** | ||
53 | int Instrument::noOfStrings() | ||
54 | { | ||
55 | return (int)strings.count(); | ||
56 | } | ||
57 | //**************************************************************************** | ||
58 | int Instrument::noOfFrets() | ||
59 | { | ||
60 | return frets; | ||
61 | } | ||
62 | //**************************************************************************** | ||
63 | QString Instrument::instName() | ||
64 | { | ||
65 | return name; | ||
66 | } | ||
67 | //**************************************************************************** | ||
68 | int Instrument::string(int id) | ||
69 | { | ||
70 | return strings[id]; | ||
71 | } | ||
72 | //**************************************************************************** | ||
73 | int Instrument::noOfOctaves() | ||
74 | { | ||
75 | int lowest=strings[0]; | ||
76 | int highest=strings[strings.count()-1]+frets; | ||
77 | return (int)((highest-lowest)/12.0); | ||
78 | } | ||
79 | //**************************************************************************** | ||
80 | //**************************************************************************** | ||
81 | Scale::Scale() | ||
82 | { | ||
83 | name="UNDEFINED"; | ||
84 | } | ||
85 | //**************************************************************************** | ||
86 | Scale::Scale(QString name,QValueList<int> halftones) | ||
87 | :name(name),halftones(halftones) | ||
88 | { | ||
89 | } | ||
90 | //**************************************************************************** | ||
91 | Scale::~Scale() | ||
92 | { | ||
93 | } | ||
94 | //**************************************************************************** | ||
95 | int Scale::noOfHaltones() | ||
96 | { | ||
97 | return (int)halftones.count(); | ||
98 | } | ||
99 | //**************************************************************************** | ||
100 | int Scale::getHalfTone(int id) | ||
101 | { | ||
102 | if(id>=0 && noOfHaltones()<id) | ||
103 | { | ||
104 | return halftones[id]; | ||
105 | } | ||
106 | else | ||
107 | return 0; | ||
108 | } | ||
109 | //**************************************************************************** | ||
110 | QString Scale::scaleName() | ||
111 | { | ||
112 | return name; | ||
113 | } | ||
114 | //**************************************************************************** | ||
115 | bool Scale::noteInScale(int base,int note) | ||
116 | { | ||
117 | int octave=Note::getOctaveOfNote(note); | ||
118 | note-=12*octave; | ||
119 | int normnote = (note>=base) ? note-base : (12-base)+note; | ||
120 | |||
121 | if(halftones.contains(normnote)>0) | ||
122 | { | ||
123 | //qDebug("OK : base : %d, note %d -> norm %d",base,note,normnote); | ||
124 | return true; | ||
125 | } | ||
126 | else | ||
127 | { | ||
128 | //qDebug("BAD : base : %d, note %d -> norm %d",base,note,normnote); | ||
129 | return false; | ||
130 | } | ||
131 | } | ||
132 | //**************************************************************************** | ||
133 | //**************************************************************************** | ||
diff --git a/noncore/multimedia/tonleiter/tonleiterdatahelper.h b/noncore/multimedia/tonleiter/tonleiterdatahelper.h new file mode 100644 index 0000000..94895ea --- a/dev/null +++ b/noncore/multimedia/tonleiter/tonleiterdatahelper.h | |||
@@ -0,0 +1,53 @@ | |||
1 | #ifndef TONLEITER_DATA_HELPER_H | ||
2 | #define TONLEITER_DATA_HELPER_H | ||
3 | |||
4 | #include <qstring.h> | ||
5 | #include <qvaluelist.h> | ||
6 | |||
7 | namespace Note | ||
8 | { | ||
9 | const QString notenames[]={"C","C#","D","D#","E","F","F#","G","G#","A","A#","B"}; | ||
10 | |||
11 | int getOctaveOfNote(int note); | ||
12 | QString getNameOfNote(int note); | ||
13 | int getNoteFromName(QString name,int octave); | ||
14 | int octaveOfBaseNote(int base,int note); | ||
15 | }; | ||
16 | |||
17 | class Instrument | ||
18 | { | ||
19 | private: | ||
20 | QString name; | ||
21 | int frets; | ||
22 | QValueList<int> strings; | ||
23 | public: | ||
24 | Instrument(); | ||
25 | Instrument(QString name,int frets,QValueList<int> strings); | ||
26 | ~Instrument(); | ||
27 | public: | ||
28 | int noOfStrings(); | ||
29 | int noOfFrets(); | ||
30 | QString instName(); | ||
31 | int string(int id); | ||
32 | int noOfOctaves(); | ||
33 | }; | ||
34 | |||
35 | class Scale | ||
36 | { | ||
37 | private: | ||
38 | QValueList<int> halftones; | ||
39 | QString name; | ||
40 | public: | ||
41 | Scale(); | ||
42 | Scale(QString name,QValueList<int> halftones); | ||
43 | ~Scale(); | ||
44 | public: | ||
45 | int noOfHaltones(); | ||
46 | int getHalfTone(int id); | ||
47 | QString scaleName(); | ||
48 | bool noteInScale(int base,int note); | ||
49 | }; | ||
50 | |||
51 | |||
52 | #endif //TONLEITER_DATA_HELPER_H | ||
53 | |||
diff --git a/pics/tonleiter.png b/pics/tonleiter.png new file mode 100644 index 0000000..ce78597 --- a/dev/null +++ b/pics/tonleiter.png | |||
Binary files differ | |||