From e7a81ed5ba0dc6b996f179d1dc40d778492218a9 Mon Sep 17 00:00:00 2001 From: waspe Date: Sun, 16 Nov 2003 19:31:57 +0000 Subject: first commit --- 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 @@ + config TONLEITER + boolean "tonleiter (shows scales on sting instruments)" + default "n" + 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 @@ +#include "fretboard.h" + +#include + +FretBoard::FretBoard(TonleiterData* data,QWidget* parent,const char* name,WFlags f) +:QWidget(parent,name,f),data(data) +{ + setBackgroundColor(QColor(0,0,0)); + fretpen=QPen(QColor(155,155,155),0); + markerbrush=QBrush(QColor(155,155,155)); + stringpen=QPen(QColor(255,255,255),3); + connect(data,SIGNAL(dataChange()),this,SLOT(dataChange())); +} +//**************************************************************************** +FretBoard::~FretBoard() +{ +} +//**************************************************************************** +void FretBoard::dataChange() +{ + repaint(true); +} +//**************************************************************************** +void FretBoard::paintEvent(QPaintEvent* pe) +{ + Q_UNUSED(pe); + + int instid=data->getCurrentInstrumentID(); + inst=data->getInstrument(instid); + //qDebug("inst %d is %s",instid,inst.instName().data()); + + QRect mysize=rect(); + + xmargin=(int)(mysize.width()*0.05); + xmin=2*xmargin; + xmax=mysize.width()-xmargin; + xwidth=xmax-xmin; + + ymargin=(int)(mysize.height()*0.1); + ymin=ymargin; + ymax=mysize.height()-2*ymargin; + yheight=ymax-ymin; + + QPainter p(this); + paintBoard(&p); + paintFrets(&p); + paintStrings(&p); + paintScale(&p); +} +//**************************************************************************** +void FretBoard::resizeEvent(QResizeEvent* re) +{ + Q_UNUSED(re); +} +//**************************************************************************** +void FretBoard::paintBoard(QPainter* p) +{ + //debug + QColor bgc=QColor(142,138,120); + p->setPen(QPen(bgc,5)); + p->setBrush(QBrush(bgc)); + p->drawRect(xmin,ymin,xwidth,yheight); + +} +//**************************************************************************** +void FretBoard::paintFrets(QPainter* p) +{ + //draw frets + p->setPen(fretpen); + p->setBrush(markerbrush); + fretdist=(double)(xwidth)/(double)(inst.noOfFrets()); + + int markerwidth = (int)(fretdist/4.0); + if(markerwidth>5) + markerwidth=5; + else if(markerwidth<2) + markerwidth=2; + + for(int f=0;f<=inst.noOfFrets();f++) + { + int fretpos=(int)(fretdist*f); + p->drawLine(fretpos+xmin,ymin,fretpos+xmin,ymax); + + int above_octave=f%12; + int octave=(f-above_octave)/12; + int marker=f-12*octave; + + + if(marker==5 || marker==7 || marker==9) + { + p->drawEllipse(fretpos+xmin,ymax+ymargin,markerwidth,markerwidth); + } + else if(marker==0 && f!=0) + { + p->drawEllipse(fretpos+xmin,ymax+ymargin+2*markerwidth,markerwidth,markerwidth); + p->drawEllipse(fretpos+xmin,ymax+ymargin-2*markerwidth,markerwidth,markerwidth); + } + + } +} +//**************************************************************************** +void FretBoard::paintStrings(QPainter* p) +{ + //draw strings + p->setPen(stringpen); + + stringdist=(double)(yheight)/(double)(inst.noOfStrings()-1); + for(int s=0;sdrawLine(xmin,stringpos+ymin,xmax,stringpos+ymin); + + int stinglabelid=inst.noOfStrings()-(s+1); + QString label=Note::getNameOfNote(inst.string(stinglabelid)); + p->drawText(xmargin/2,stringpos+ymin,label); + } +} +//**************************************************************************** +void FretBoard::paintScale(QPainter* p) +{ + int dotsize=10; + int scaleid=data->getCurrentScaleID(); + Scale scale=data->getScale(scaleid); + + int colorstart=255%inst.noOfOctaves(); + int colorintervall=(255-colorstart)/inst.noOfOctaves(); + + for(int s=0;sgetCurrentBaseNote(),note)) + { + int x=(int)(fretdist*f)+xmin; + + int octave=Note::octaveOfBaseNote(data->getCurrentBaseNote(),note); + if(octave>5) octave=5; + p->setPen(QColor(255,0,0)); + int c=colorstart+octave*colorintervall; + QColor dotcolor(c,c,255); + p->setBrush(dotcolor); + + p->drawEllipse(x-dotsize/2,y-dotsize/2,dotsize,dotsize); + + if(data->isDrawNames()) + { + p->setPen(QColor(0,255,0)); + p->drawText(x-dotsize/2,y-dotsize/2,Note::getNameOfNote(note)); + } + + } + } + } +} +//**************************************************************************** +//**************************************************************************** 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 @@ +#ifndef TONLEITER_FRET_BOARD_H +#define TONLEITER_FRET_BOARD_H + +#include +#include +#include +#include + + +#include "tonleiterdata.h" + +class FretBoard : public QWidget +{ + Q_OBJECT +private: + TonleiterData* data; + + QPen fretpen; + QBrush markerbrush; + QPen stringpen; + + Instrument inst; + + int xmargin; + int xmin; + int xmax; + int xwidth; + + int ymargin; + int ymin; + int ymax; + int yheight; + + double fretdist; + double stringdist; + +public: + FretBoard(TonleiterData* data,QWidget* parent,const char* name="FretBoard",WFlags f=0); + virtual ~FretBoard(); +private slots: + void dataChange(); +private: + void paintEvent(QPaintEvent* pe); + void resizeEvent(QResizeEvent* re); + //void mousePressEvent(QMouseEvent* mpe); + //void mouseMoveEvent(QMouseEvent* mme); + //void mouseReleaseEvent(QMouseEvent* mre); + void paintBoard(QPainter* p); + void paintFrets(QPainter* p); + void paintStrings(QPainter* p); + void paintScale(QPainter* p); +}; + +#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 @@ +/*************************************************************************** + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#include "mainwidget.h" +#include + +int main(int argc, char* argv[]) +{ + QPEApplication a(argc, argv); + MainWidget mw; + a.showMainWidget( &mw); + return a.exec(); +} + + 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 @@ +#include "mainwidget.h" + +#include +#include + +MainWidget::MainWidget(QWidget* parent,const char* name,WFlags f) +:QMainWindow(parent,name,f) +{ + setCaption("Tonleiter"); + data=new TonleiterData(this); + + QWidget* mainwidget=new QWidget(this,"mainwidget"); + setCentralWidget(mainwidget); + QBoxLayout* mainlayout=new QBoxLayout(mainwidget,QBoxLayout::TopToBottom); + + menuwidget=new MenuWidget(data,mainwidget); + mainlayout->addWidget(menuwidget); + + fretboard=new FretBoard(data,mainwidget); + mainlayout->addWidget(fretboard); + +} +//**************************************************************************** +MainWidget::~MainWidget() +{ +} +//**************************************************************************** +//**************************************************************************** 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 @@ +#ifndef TONLEITER_MAINWIDGET_H +#define TONLEITER_MAINWIDGET_H + +#include + +#include "fretboard.h" +#include "menuwidget.h" +#include "tonleiterdata.h" + +class MainWidget : public QMainWindow +{ + Q_OBJECT +private: + TonleiterData* data; + MenuWidget* menuwidget; + FretBoard* fretboard; +public: + MainWidget(QWidget* parent=0,const char* name="MainWidget",WFlags f=0); + virtual ~MainWidget(); +}; + +#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 @@ +#include "menuwidget.h" + +#include +#include + +MenuWidget::MenuWidget(TonleiterData* data,QWidget* parent,const char* name,WFlags f) +:QWidget(parent,name,f),data(data) +{ + QGridLayout* layout=new QGridLayout(this,3,3,10,-1,"menulayout"); + + QLabel* instLabel=new QLabel(tr("Instrument"),this,"instLabel"); + layout->addWidget(instLabel,0,0); + boxInst=new QComboBox(this,"boxInst"); + connect(boxInst,SIGNAL(activated(int)),data,SLOT(setCurrentInstrumetID(int))); + layout->addWidget(boxInst,0,1); + editInst=new QPushButton(tr("Edit"),this,"editInst"); + layout->addWidget(editInst,0,2); + + QLabel* noteLabel=new QLabel(tr("Note"),this,"noteLabel"); + layout->addWidget(noteLabel,1,0); + boxNote=new QComboBox(this,"boxNote"); + connect(boxNote,SIGNAL(activated(int)),data,SLOT(setCurrentNote(int))); + layout->addWidget(boxNote,1,1); + for(int a=0;a<12;a++) + boxNote->insertItem(Note::notenames[a],a); + boxNote->setCurrentItem(data->getCurrentBaseNote()); + noteCheck=new QCheckBox(tr("show notes"),this,"noteCheck"); + noteCheck->setChecked(data->isDrawNames()); + connect(noteCheck,SIGNAL(toggled(bool)),data,SLOT(setDrawNames(bool))); + layout->addWidget(noteCheck,1,2); + + QLabel* scaleLabel=new QLabel(tr("Scale"),this,"scaleLabel"); + layout->addWidget(scaleLabel,2,0); + boxScale=new QComboBox(this,"boxScale"); + connect(boxScale,SIGNAL(activated(int)),data,SLOT(setCurrentScaleID(int))); + layout->addWidget(boxScale,2,1); + editScale=new QPushButton(tr("Edit"),this,"editScale"); + layout->addWidget(editScale,2,2); + + updateBoxes(); + +} +//**************************************************************************** +MenuWidget::~MenuWidget() +{ +} +//**************************************************************************** +void MenuWidget::updateBoxes() +{ + boxInst->clear(); + + for(int i=0;inoOfInstruments();i++) + { + Instrument inst=data->getInstrument(i); + QString name=inst.instName(); + if(name.isNull()) continue; + boxInst->insertItem(name,i); + } + boxInst->setCurrentItem(data->getCurrentInstrumentID()); + + boxScale->clear(); + for(int s=0;snoOfScales();s++) + { + Scale scale=data->getScale(s); + QString name=scale.scaleName(); + if(name.isNull()) continue; + boxScale->insertItem(name,s); + } + boxScale->setCurrentItem(data->getCurrentScaleID()); +} +//**************************************************************************** +//**************************************************************************** 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 @@ +#ifndef TONLEITER_MENU_WIDGET_H +#define TONLEITER_MENU_WIDGET_H + +#include +#include +#include +#include +#include + +#include "tonleiterdata.h" + +class MenuWidget : public QWidget +{ + Q_OBJECT +private: + TonleiterData* data; + QComboBox* boxInst; + QPushButton* editInst; + QComboBox* boxNote; + QCheckBox* noteCheck; + QComboBox* boxScale; + QPushButton* editScale; +public: + MenuWidget(TonleiterData* data,QWidget* parent,const char* name="MenuWidget",WFlags f=0); + ~MenuWidget(); +public slots: + void updateBoxes(); +}; + +#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 @@ +Package: tonleiter +Files: bin/tonlieter pics/tonleiter apps/Applications/tonleiter.desktop +Priority: optional +Section: multimedia/applications +Maintainer: Ralf Waspe +Architecture: arm +Depends: task-opie-minimal +Description: music scales for sting instruments +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 @@ +TEMPLATE = app +#CONFIG = qt warn_on debug +CONFIG = qt warn_on release +HEADERS = mainwidget.h tonleiterdata.h tonleiterdatahelper.h fretboard.h menuwidget.h +SOURCES = mainwidget.cpp tonleiterdata.cpp tonleiterdatahelper.cpp fretboard.cpp menuwidget.cpp main.cpp +INCLUDEPATH += $(OPIEDIR)/include +DEPENDPATH += $(OPIEDIR)/include +LIBS += -lqpe +INTERFACES = +TARGET = tonleiter +DESTDIR = $(OPIEDIR)/bin +#TMAKE_CXXFLAGS += -DQT_QWS_VERCEL_IDR -DQWS -fno-exceptions -fno-rtti +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 @@ +#include "tonleiterdata.h" + +TonleiterData::TonleiterData(QObject* parent) +:QObject(parent) +{ + drawnames=true; + loadData(); +} +//**************************************************************************** +TonleiterData::~TonleiterData() +{ + saveData(); +} +//**************************************************************************** +void TonleiterData::setCurrentInstrumetID(int id) +{ + if(id>=0 && id=0 && id=0 && id<12) + { + currentNote=id; + emit dataChange(); + } +} +//**************************************************************************** +void TonleiterData::setDrawNames(bool dn) +{ + drawnames=dn; + emit dataChange(); +} +//**************************************************************************** +void TonleiterData::loadData() +{ + QValueList strings1; + strings1.append(Note::getNoteFromName("B",0)); + strings1.append(Note::getNoteFromName("E",1)); + strings1.append(Note::getNoteFromName("A",1)); + strings1.append(Note::getNoteFromName("D",2)); + strings1.append(Note::getNoteFromName("G",2)); + strings1.append(Note::getNoteFromName("C",3)); + instruments.append(Instrument("Thumb6",26,strings1)); + + QValueList strings2; + strings2.append(Note::getNoteFromName("E",1)); + strings2.append(Note::getNoteFromName("A",1)); + strings2.append(Note::getNoteFromName("D",2)); + strings2.append(Note::getNoteFromName("G",2)); + instruments.append(Instrument("Bass 4",12,strings2)); + + currentInstrumentID=1; + + QValueList scale1; + scale1.append(0); + scale1.append(2); + scale1.append(3); + scale1.append(5); + scale1.append(7); + scale1.append(8); + scale1.append(10); + scales.append(Scale("Minor",scale1)); + + QValueList scale2; + scale2.append(0); + scale2.append(2); + scale2.append(4); + scale2.append(5); + scale2.append(7); + scale2.append(9); + scale2.append(10); + scales.append(Scale("Major",scale2)); + + currentScaleID=0; + + currentNote=Note::getNoteFromName("A",0); +} +//**************************************************************************** +void TonleiterData::saveData() +{ +} +//**************************************************************************** +int TonleiterData::noOfInstruments() +{ + return (int)instruments.count(); +} +//**************************************************************************** +Instrument TonleiterData::getInstrument(int id) +{ + if(id>=0 && id=0 && id + +#include "tonleiterdatahelper.h" + +class TonleiterData : public QObject +{ + Q_OBJECT +private: + QValueList instruments; + int currentInstrumentID; + + QValueList scales; + int currentScaleID; + + int currentNote; + bool drawnames; +public: + TonleiterData(QObject* parent); + ~TonleiterData(); +signals: + void dataChange(); +public slots: + void setCurrentInstrumetID(int id); + void setCurrentScaleID(int id); + void setCurrentNote(int id); + void setDrawNames(bool dn); +private: + void loadData(); + void saveData(); +public: + int noOfInstruments(); + Instrument getInstrument(int id); + int getCurrentInstrumentID(); + + int noOfScales(); + Scale getScale(int id); + int getCurrentScaleID(); + + int getCurrentBaseNote(); + bool isDrawNames(); +}; + +#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 @@ +#include "tonleiterdatahelper.h" + +int Note::getOctaveOfNote(int note) +{ + int remain=note%12; + return (note-remain)/12; +} +//**************************************************************************** +QString Note::getNameOfNote(int note) +{ + int octave=getOctaveOfNote(note); + return notenames[note-12*octave]; +} +//**************************************************************************** +int Note::getNoteFromName(QString name,int octave) +{ + int notevalue=0; + for(int a=0;a<12;a++) + { + if(name==notenames[a]) + { + notevalue=a; + break; + } + } + return notevalue+12*octave; +} +//**************************************************************************** +int Note::octaveOfBaseNote(int base,int note) +{ + int normnote = (note>=base) ? note-base : (12-base)+note; + int octave=getOctaveOfNote(normnote); + //qDebug("note %d of %d base is norm %d -> ocatve %d",note,base,normnote,octave); + return octave; +} +//**************************************************************************** +//**************************************************************************** +Instrument::Instrument() +{ + name="UNDEFINED"; + frets=0; +} +//**************************************************************************** +Instrument::Instrument(QString name,int frets,QValueList strings) +:name(name),frets(frets),strings(strings) +{ +} +//**************************************************************************** +Instrument::~Instrument() +{ +} +//**************************************************************************** +int Instrument::noOfStrings() +{ + return (int)strings.count(); +} +//**************************************************************************** +int Instrument::noOfFrets() +{ + return frets; +} +//**************************************************************************** +QString Instrument::instName() +{ + return name; +} +//**************************************************************************** +int Instrument::string(int id) +{ + return strings[id]; +} +//**************************************************************************** +int Instrument::noOfOctaves() +{ + int lowest=strings[0]; + int highest=strings[strings.count()-1]+frets; + return (int)((highest-lowest)/12.0); +} +//**************************************************************************** +//**************************************************************************** +Scale::Scale() +{ + name="UNDEFINED"; +} +//**************************************************************************** +Scale::Scale(QString name,QValueList halftones) +:name(name),halftones(halftones) +{ +} +//**************************************************************************** +Scale::~Scale() +{ +} +//**************************************************************************** +int Scale::noOfHaltones() +{ + return (int)halftones.count(); +} +//**************************************************************************** +int Scale::getHalfTone(int id) +{ + if(id>=0 && noOfHaltones()=base) ? note-base : (12-base)+note; + + if(halftones.contains(normnote)>0) + { + //qDebug("OK : base : %d, note %d -> norm %d",base,note,normnote); + return true; + } + else + { + //qDebug("BAD : base : %d, note %d -> norm %d",base,note,normnote); + return false; + } +} +//**************************************************************************** +//**************************************************************************** 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 @@ +#ifndef TONLEITER_DATA_HELPER_H +#define TONLEITER_DATA_HELPER_H + +#include +#include + +namespace Note +{ + const QString notenames[]={"C","C#","D","D#","E","F","F#","G","G#","A","A#","B"}; + + int getOctaveOfNote(int note); + QString getNameOfNote(int note); + int getNoteFromName(QString name,int octave); + int octaveOfBaseNote(int base,int note); +}; + +class Instrument +{ +private: + QString name; + int frets; + QValueList strings; +public: + Instrument(); + Instrument(QString name,int frets,QValueList strings); + ~Instrument(); +public: + int noOfStrings(); + int noOfFrets(); + QString instName(); + int string(int id); + int noOfOctaves(); +}; + +class Scale +{ +private: + QValueList halftones; + QString name; +public: + Scale(); + Scale(QString name,QValueList halftones); + ~Scale(); +public: + int noOfHaltones(); + int getHalfTone(int id); + QString scaleName(); + bool noteInScale(int base,int note); +}; + + +#endif //TONLEITER_DATA_HELPER_H + 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 -- cgit v0.9.0.2