summaryrefslogtreecommitdiff
authorwaspe <waspe>2004-01-24 13:44:29 (UTC)
committer waspe <waspe>2004-01-24 13:44:29 (UTC)
commit5f333c6832ff429a00498e6a36be950525541a2a (patch) (side-by-side diff)
tree035616d3cc11622f6d9b14245372362620327a46
parentd542ba6a426f9868d521dbd9eb502184086535fc (diff)
downloadopie-5f333c6832ff429a00498e6a36be950525541a2a.zip
opie-5f333c6832ff429a00498e6a36be950525541a2a.tar.gz
opie-5f333c6832ff429a00498e6a36be950525541a2a.tar.bz2
new color scheme on fretboard, maekes each ocatave appear in different color
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/tonleiter/editinst.cpp6
-rw-r--r--noncore/multimedia/tonleiter/editinst.h1
-rw-r--r--noncore/multimedia/tonleiter/fretboard.cpp43
-rw-r--r--noncore/multimedia/tonleiter/fretboard.h3
-rw-r--r--noncore/multimedia/tonleiter/mainwidget.cpp17
-rw-r--r--noncore/multimedia/tonleiter/mainwidget.h3
-rw-r--r--noncore/multimedia/tonleiter/tonleiterdatahelper.cpp15
-rw-r--r--noncore/multimedia/tonleiter/tonleiterdatahelper.h2
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 @@
#include "editinst.h"
#include <qlabel.h>
#include <qpushbutton.h>
Menu::InstEditDialog::InstEditDialog(TonleiterData* data,QWidget* parent,const char* name)
:QDialog(parent,name,true,0),data(data)
{
setCaption("Tonleiter::"+tr("Instrument"));
QBoxLayout* masterlayout=new QBoxLayout(this,QBoxLayout::TopToBottom);
instid=data->getCurrentInstrumentID();
stringlist.setAutoDelete(true);
QBoxLayout* toplayout=new QBoxLayout(masterlayout,QBoxLayout::LeftToRight);
//Name combo + Add + Delete
boxInst=new QComboBox(this,"boxInst");
boxInst->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Maximum));
connect(boxInst,SIGNAL(activated(int)),this,SLOT(setCurrentInstrumetID(int)));
for(int i=0;i<data->noOfInstruments();i++)
{
Instrument inst=data->getInstrument(i);
QString name=inst.instName();
if(name.isNull()) continue;
boxInst->insertItem(name,i);
}
boxInst->setCurrentItem(instid);
toplayout->addWidget(boxInst);
QPushButton* addButton=new QPushButton(tr("Add"),this,"addButton");
connect(addButton,SIGNAL(pressed()),this,SLOT(addInstrument()));
toplayout->addWidget(addButton);
QPushButton* delButton=new QPushButton(tr("Delete"),this,"delButton");
connect(delButton,SIGNAL(pressed()),this,SLOT(deleteInstrument()));
toplayout->addWidget(delButton);
QPushButton* addhighButton=new QPushButton(tr("Add High String"),this,"addhighButton");
masterlayout->addWidget(addhighButton);
- QScrollView* scrollview=new QScrollView(this);
+ scrollview=new QScrollView(this);
scrollview->setVScrollBarMode(QScrollView::AlwaysOn);
scrollview->setHScrollBarMode(QScrollView::AlwaysOff);
stringwidget=new QVBox(scrollview->viewport());
stringwidget->setSizePolicy(QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
stringwidget->setSpacing(10);
scrollview->addChild(stringwidget);
scrollview->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Maximum));
- //scrollview->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::MinimumExpanding));
masterlayout->addWidget(scrollview);
loadInstrument();
QPushButton* addlowButton=new QPushButton(tr("Add Low String"),this,"addlowButton");
masterlayout->addWidget(addlowButton);
//make dialog fit the screen
showMaximized();
}
//****************************************************************************
Menu::InstEditDialog::~InstEditDialog()
{
}
//****************************************************************************
void Menu::InstEditDialog::setCurrentInstrumetID(int id)
{
saveInstrument();
instid=id;
data->setCurrentInstrumetID(id);
loadInstrument();
}
//****************************************************************************
void Menu::InstEditDialog::addInstrument()
{
}
//****************************************************************************
void Menu::InstEditDialog::deleteInstrument()
{
}
//****************************************************************************
void Menu::InstEditDialog::addLowString()
{
}
//****************************************************************************
void Menu::InstEditDialog::addHighString()
{
}
//****************************************************************************
void Menu::InstEditDialog::deleteString(int id)
{
}
//****************************************************************************
void Menu::InstEditDialog::saveInstrument()
{
+ //auto delete is set to true so widgets _should_ be deleted
stringlist.clear();
}
//****************************************************************************
void Menu::InstEditDialog::loadInstrument()
{
+ stringlist.clear();
Instrument inst=data->getInstrument(instid);
+ qDebug("load Instrument : %d strings",inst.noOfStrings());
for(uint s=0;s<inst.noOfStrings();s++)
{
stringlist.append(new EditStringWidget(inst.string(s),stringwidget));
}
}
//****************************************************************************
//****************************************************************************
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 @@
#ifndef TONLEITER_EDIT_INSTRUMENT_DIALOG_H
#define TONLEITER_EDIT_INSTRUMENT_DIALOG_H
#include <qdialog.h>
#include <qcombobox.h>
#include <qscrollview.h>
#include <qspinbox.h>
#include <qlayout.h>
#include <qlist.h>
#include <qvbox.h>
#include "editstringwidget.h"
using namespace Data;
namespace Menu
{
class InstEditDialog : public QDialog
{
Q_OBJECT
private:
TonleiterData* data;
int instid;
QComboBox* boxInst;
QSpinBox* stringBox;
+ QScrollView* scrollview;
QVBox* stringwidget;
//this is a QPtrList !!
typedef QList<EditStringWidget> StringWidgetList;
StringWidgetList stringlist;
public:
InstEditDialog(TonleiterData* data,QWidget* parent,const char* name="InstEditDialog");
~InstEditDialog();
private slots:
void setCurrentInstrumetID(int id);
void addInstrument();
void deleteInstrument();
void addLowString();
void addHighString();
void deleteString(int id);
private:
void saveInstrument();
void loadInstrument();
};
};
#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
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()));
}
//****************************************************************************
Graph::FretBoard::~FretBoard()
{
}
//****************************************************************************
void Graph::FretBoard::dataChange()
{
repaint(true);
}
//****************************************************************************
void Graph::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 Graph::FretBoard::resizeEvent(QResizeEvent* re)
{
Q_UNUSED(re);
}
//****************************************************************************
+void Graph::FretBoard::mouseReleaseEvent(QMouseEvent* me)
+{
+ Q_UNUSED(me);
+ emit pressed();
+}
+//****************************************************************************
void Graph::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 Graph::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 Graph::FretBoard::paintStrings(QPainter* p)
{
//draw strings
p->setPen(stringpen);
stringdist=(double)(yheight)/(double)(inst.noOfStrings()-1);
for(int s=0;s<inst.noOfStrings();s++)
{
int stringpos=(int)(stringdist*s);
p->drawLine(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 Graph::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();
+ int baseoctave=Note::octaveOfBaseNote(data->getCurrentBaseNote(),inst.lowestNote());
for(int s=0;s<inst.noOfStrings();s++)
{
int y=(int)(stringdist*s)+ymin;
int stingid=inst.noOfStrings()-(s+1);
for(int f=0;f<=inst.noOfFrets();f++)
{
int note=inst.string(stingid)+f;
if(scale.noteInScale(data->getCurrentBaseNote(),note))
{
int x=(int)(fretdist*f)+xmin;
- int octave=Note::octaveOfBaseNote(data->getCurrentBaseNote(),note);
- if(octave>5) octave=5;
+ //no more than six octaves can be visualised (there is a zero octave)
+ int octave=Note::octaveOfBaseNote(data->getCurrentBaseNote(),note)-baseoctave;
+ if(octave<0)
+ qDebug("%d,%d",octave,baseoctave);
+ if(octave>5)
+ {
+ qDebug("octave out of range");
+ octave=5;
+ }
+
p->setPen(QColor(255,0,0));
- int c=colorstart+octave*colorintervall;
- QColor dotcolor(c,c,255);
- p->setBrush(dotcolor);
+ int c= ( (note-12*baseoctave) - (12*octave+data->getCurrentBaseNote()) )*15;
+ if(c<0 || c>255)
+ qDebug("%d = %d - ( %d + %d)",c,note,12*octave,data->getCurrentBaseNote());
+ QColor dotcolor(255,255,255);
+
+ if(octave==0)
+ dotcolor=QColor(c,c,255);
+ else if(octave==1)
+ dotcolor=QColor(c,255,c);
+ else if(octave==2)
+ dotcolor=QColor(255,c,c);
+ else if(octave==3)
+ dotcolor=QColor(255,255,c);
+ else if(octave==4)
+ dotcolor=QColor(255,c,255);
+ else
+ dotcolor=QColor(c,255,255);
+ p->setBrush(dotcolor);
p->drawEllipse(x-dotsize/2,y-dotsize/2,dotsize,dotsize);
if(data->isDrawNames())
{
p->setPen(QColor(255,155,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
index 458c733..bb696fb 100644
--- a/noncore/multimedia/tonleiter/fretboard.h
+++ b/noncore/multimedia/tonleiter/fretboard.h
@@ -1,56 +1,59 @@
#ifndef TONLEITER_FRET_BOARD_H
#define TONLEITER_FRET_BOARD_H
#include <qbrush.h>
#include <qpen.h>
#include <qvaluelist.h>
#include <qwidget.h>
#include "tonleiterdata.h"
using namespace Data;
namespace Graph
{
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();
+ signals:
+ void pressed();
private slots:
void dataChange();
private:
void paintEvent(QPaintEvent* pe);
void resizeEvent(QResizeEvent* re);
+ void mouseReleaseEvent(QMouseEvent* me);
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/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 @@
#include "mainwidget.h"
#include <qwidget.h>
#include <qlayout.h>
MainWidget::MainWidget(QWidget* parent,const char* name,WFlags f)
:QMainWindow(parent,name,f)
{
setCaption("Tonleiter");
data=new Data::TonleiterData(this);
QWidget* mainwidget=new QWidget(this,"mainwidget");
setCentralWidget(mainwidget);
QBoxLayout* mainlayout=new QBoxLayout(mainwidget,QBoxLayout::TopToBottom);
menuwidget=new Menu::MenuWidget(data,mainwidget);
mainlayout->addWidget(menuwidget);
fretboard=new Graph::FretBoard(data,mainwidget);
+ connect(fretboard,SIGNAL(pressed()),this,SLOT(fretboardPressed()));
mainlayout->addWidget(fretboard);
+ showmenu=true;
+
}
//****************************************************************************
MainWidget::~MainWidget()
{
}
//****************************************************************************
+void MainWidget::fretboardPressed()
+{
+ if(showmenu)
+ {
+ menuwidget->hide();
+ showmenu=false;
+ }
+ else
+ {
+ menuwidget->show();
+ showmenu=true;
+ }
+}
+//****************************************************************************
//****************************************************************************
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 @@
#ifndef TONLEITER_MAINWIDGET_H
#define TONLEITER_MAINWIDGET_H
#include <qmainwindow.h>
#include "fretboard.h"
#include "menuwidget.h"
#include "tonleiterdata.h"
class MainWidget : public QMainWindow
{
Q_OBJECT
private:
Data::TonleiterData* data;
Menu::MenuWidget* menuwidget;
Graph::FretBoard* fretboard;
+ bool showmenu;
public:
MainWidget(QWidget* parent=0,const char* name="MainWidget",WFlags f=0);
virtual ~MainWidget();
+private slots:
+ void fretboardPressed();
};
#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)
}
//****************************************************************************
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<int> 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) ceil((highest-lowest)/12.0);
+ return (int) ceil((highestNote()-lowestNote())/12.0);
+}
+//****************************************************************************
+int Instrument::lowestNote()
+{
+ return strings[0];
+
+}
+//****************************************************************************
+int Instrument::highestNote()
+{
+ return strings[strings.count()-1]+frets;
}
//****************************************************************************
//****************************************************************************
Scale::Scale()
{
name="UNDEFINED";
}
//****************************************************************************
Scale::Scale(QString name,QValueList<int> halftones)
:name(name),halftones(halftones)
{
}
//****************************************************************************
Scale::~Scale()
{
}
//****************************************************************************
int Scale::noOfHaltones()
{
return (int)halftones.count();
}
//****************************************************************************
int Scale::getHalfTone(int id)
{
if(id>=0 && id<noOfHaltones())
return halftones[id];
else
return 0;
}
//****************************************************************************
QString Scale::scaleName()
{
return name;
}
//****************************************************************************
bool Scale::noteInScale(int base,int note)
{
int octave=Note::getOctaveOfNote(note);
note-=12*octave;
int normnote = (note>=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
{
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 @@
#ifndef TONLEITER_DATA_HELPER_H
#define TONLEITER_DATA_HELPER_H
#include <qstring.h>
#include <qvaluelist.h>
namespace Data
{
namespace Note
{
const QString notenames[]={"A","Bb","B","C","C#","D","D#","E","F","F#","G","G#"};
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<int> strings;
public:
Instrument();
Instrument(QString name,int frets,QValueList<int> strings);
~Instrument();
public:
int noOfStrings();
int noOfFrets();
QString instName();
int string(int id);
int noOfOctaves();
+ int lowestNote();
+ int highestNote();
};
class Scale
{
private:
QValueList<int> halftones;
QString name;
public:
Scale();
Scale(QString name,QValueList<int> halftones);
~Scale();
public:
int noOfHaltones();
int getHalfTone(int id);
QString scaleName();
bool noteInScale(int base,int note);
};
};
#endif //TONLEITER_DATA_HELPER_H