From 1a551c32ee9395ee83cc96245d7a5d30d3eebe13 Mon Sep 17 00:00:00 2001 From: "Tim E. Real" Date: Sat, 16 Apr 2011 04:19:10 +0000 Subject: Invert drum 'slivers' in arranger drum parts. --- muse2/ChangeLog | 2 ++ muse2/muse/arranger/pcanvas.cpp | 4 +++- muse2/muse/osc.cpp | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) (limited to 'muse2') diff --git a/muse2/ChangeLog b/muse2/ChangeLog index 9d5e7237..6378495e 100644 --- a/muse2/ChangeLog +++ b/muse2/ChangeLog @@ -1,3 +1,5 @@ +15.04.2011: + - And while we're at it... Invert drum track 'slivers' in arranger parts. (Tim) 14.04.2011: - Fixed notes 'sliver' drawing in arranger midi parts. Invert if too dark. (Tim) - Gave arranger part name text drawing a shadow to help contrast with drawn events. diff --git a/muse2/muse/arranger/pcanvas.cpp b/muse2/muse/arranger/pcanvas.cpp index ca2a16b0..57cccbf7 100644 --- a/muse2/muse/arranger/pcanvas.cpp +++ b/muse2/muse/arranger/pcanvas.cpp @@ -1719,6 +1719,7 @@ void PartCanvas::drawMidiPart(QPainter& p, const QRect& bb, EventList* events, M iEvent ito(events->lower_bound(to)); //printf("PartCanvas::drawItem pTick:%d from:%d to:%d\n", pTick, from, to); + bool isdrum = (mt->type() == Track::DRUM); for (iEvent i = events->begin(); i != ito; ++i) { int t = i->first + pTick; int te = t + i->second.lenTick(); @@ -1741,7 +1742,8 @@ void PartCanvas::drawMidiPart(QPainter& p, const QRect& bb, EventList* events, M int pitch = i->second.pitch(); int th = int(mt->height() * 0.75); // only draw on three quarters int hoffset = (mt->height() - th ) / 2; // offset from bottom - int y = hoffset + (r.y() + th - (pitch * (th) / 127)); + //int y = hoffset + (r.y() + th - (pitch * (th) / 127)); + int y = hoffset + r.y() + th - (isdrum?127-pitch:pitch) * th / 127; p.drawLine(t, y, te, y); } } diff --git a/muse2/muse/osc.cpp b/muse2/muse/osc.cpp index 66242e17..edaede1f 100644 --- a/muse2/muse/osc.cpp +++ b/muse2/muse/osc.cpp @@ -942,8 +942,8 @@ bool OscIF::oscInitGui(const QString& typ, const QString& baseName, const QStrin if(_oscGuiQProc == 0) //_oscGuiQProc = new QProcess(muse); _oscGuiQProc = new QProcess(); - - //QString program(fi.filePath()); + + //QString program(fi.filePath()); QString program(guiPath); QStringList arguments; arguments << oscUrl -- cgit v1.2.3 From f644f66566e933364baa66c825799ab7de3b4bbe Mon Sep 17 00:00:00 2001 From: "Tim E. Real" Date: Sat, 16 Apr 2011 04:50:17 +0000 Subject: Move part name text to bottom to accommodate drum 'slivers' --- muse2/ChangeLog | 2 ++ muse2/muse/arranger/pcanvas.cpp | 15 ++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'muse2') diff --git a/muse2/ChangeLog b/muse2/ChangeLog index 6378495e..3a160786 100644 --- a/muse2/ChangeLog +++ b/muse2/ChangeLog @@ -1,5 +1,7 @@ 15.04.2011: - And while we're at it... Invert drum track 'slivers' in arranger parts. (Tim) + - Move part name text to bottom to accommodate drum 'slivers'. + Use lowest gradient colour from new gGradientFromQColor(), to determine whether to invert. 14.04.2011: - Fixed notes 'sliver' drawing in arranger midi parts. Invert if too dark. (Tim) - Gave arranger part name text drawing a shadow to help contrast with drawn events. diff --git a/muse2/muse/arranger/pcanvas.cpp b/muse2/muse/arranger/pcanvas.cpp index 57cccbf7..e2c2b32d 100644 --- a/muse2/muse/arranger/pcanvas.cpp +++ b/muse2/muse/arranger/pcanvas.cpp @@ -1610,15 +1610,20 @@ void PartCanvas::drawItem(QPainter& p, const CItem* item, const QRect& rect) // draw name // FN: Set text color depending on part color (black / white) int part_r, part_g, part_b, brightness; - config.partColors[i].getRgb(&part_r, &part_g, &part_b); + //config.partColors[i].getRgb(&part_r, &part_g, &part_b); + // Since we'll draw the text on the bottom (to accommodate drum 'slivers'), + // get the lowest colour in the gradient used to draw the part. + QRect rr = map(r); + rr.setX(rr.x() + 3); + gGradientFromQColor(config.partColors[i], rr.topLeft(), rr.bottomLeft()).stops().last().second.getRgb(&part_r, &part_g, &part_b); brightness = part_r*29 + part_g*59 + part_b*12; //if (brightness < 12000 || part->selected()) // p.setPen(Qt::white); /* too dark: use white for text color */ //else // p.setPen(Qt::black); /* otherwise use black */ bool rev = brightness < 12000 || part->selected(); - QRect rr = map(r); - rr.setX(rr.x() + 3); + //QRect rr = map(r); + //rr.setX(rr.x() + 3); p.save(); p.setFont(config.fonts[1]); p.setWorldMatrixEnabled(false); @@ -1626,12 +1631,12 @@ void PartCanvas::drawItem(QPainter& p, const CItem* item, const QRect& rect) p.setPen(Qt::black); else p.setPen(Qt::white); - p.drawText(rr.translated(1, 1), Qt::AlignTop|Qt::AlignLeft, part->name()); + p.drawText(rr.translated(1, 1), Qt::AlignBottom|Qt::AlignLeft, part->name()); if (rev) p.setPen(Qt::white); else p.setPen(Qt::black); - p.drawText(rr, Qt::AlignTop|Qt::AlignLeft, part->name()); + p.drawText(rr, Qt::AlignBottom|Qt::AlignLeft, part->name()); p.restore(); } } -- cgit v1.2.3 From 47f7c86b68c156a0dff15c0e2486371bc8a801f6 Mon Sep 17 00:00:00 2001 From: Robert Jonsson Date: Sat, 16 Apr 2011 18:40:54 +0000 Subject: added keymap --- muse2/ChangeLog | 13 ++ muse2/awl/sigedit.cpp | 13 +- muse2/awl/sigedit.h | 1 + muse2/muse/CMakeLists.txt | 1 + muse2/muse/dssihost.cpp | 12 +- muse2/muse/keyevent.cpp | 303 ++++++++++++++++++++++++++++++++++++++++++ muse2/muse/keyevent.h | 97 ++++++++++++++ muse2/muse/master/lmaster.cpp | 277 +++++++++++++++++++++++++++++++------- muse2/muse/master/lmaster.h | 30 ++++- muse2/muse/shortcuts.cpp | 5 +- muse2/muse/shortcuts.h | 3 +- muse2/muse/song.cpp | 14 ++ muse2/muse/song.h | 1 + muse2/muse/songfile.cpp | 5 + 14 files changed, 717 insertions(+), 58 deletions(-) create mode 100644 muse2/muse/keyevent.cpp create mode 100644 muse2/muse/keyevent.h (limited to 'muse2') diff --git a/muse2/ChangeLog b/muse2/ChangeLog index 3a160786..b73c40c7 100644 --- a/muse2/ChangeLog +++ b/muse2/ChangeLog @@ -1,3 +1,16 @@ +16.04.2011: + - Added KeyList for keeping key change events and ability to edit it in + master list editor (rj) + - fixed stuff in master list editor (rj) + * editing tempo signature is now atleast working + * editing time position is now atleast working + * double clicking a line moves the playpointer to this position if we are not playing + * changed adding tempo/sig/key so they pick the postion from the play pointer instead + of just incrementing the time position, I can't fathom when that would be preferrable + (if there is a time, I'm sure someone will let me know :) ) + - song changed not implemented yet + - undo/redo is not implemented + - prevented initialization crash for dssi, Tim, please have a look (rj) 15.04.2011: - And while we're at it... Invert drum track 'slivers' in arranger parts. (Tim) - Move part name text to bottom to accommodate drum 'slivers'. diff --git a/muse2/awl/sigedit.cpp b/muse2/awl/sigedit.cpp index 826182ca..460aafe4 100644 --- a/muse2/awl/sigedit.cpp +++ b/muse2/awl/sigedit.cpp @@ -58,6 +58,16 @@ bool SigEdit::event(QEvent* event) if (event->type() == QEvent::KeyPress) { QKeyEvent* ke = static_cast(event); int segment = curSegment(); + if (ke->key() == Qt::Key_Return) + { + int z, n; + sscanf(lineEdit()->text().toLatin1().data(), "%d/%d", &z, &n); + AL::TimeSignature sig(z, n); + _sig = sig; + + emit returnPressed(); + return true; + } if (ke->key() == Qt::Key_Backtab) { if (segment == 2) { lineEdit()->setSelection(5, 2); @@ -117,6 +127,7 @@ void SigEdit::setValue(const QString& s) void SigEdit::updateValue() { + //printf("updateValue\n"); char buffer[64]; sprintf(buffer, "%d/%d", _sig.z, _sig.n); lineEdit()->setText(buffer); @@ -160,7 +171,7 @@ void SigEdit::fixup(QString& input) const QValidator::State SigEdit::validate(QString&,int&) const { // TODO - // printf("validate\n"); + //printf("validate\n"); return QValidator::Acceptable; } diff --git a/muse2/awl/sigedit.h b/muse2/awl/sigedit.h index dd059ea2..d2494798 100644 --- a/muse2/awl/sigedit.h +++ b/muse2/awl/sigedit.h @@ -54,6 +54,7 @@ class SigEdit : public QAbstractSpinBox signals: void valueChanged(const AL::TimeSignature&); + void returnPressed(); public slots: void setValue(const AL::TimeSignature&); diff --git a/muse2/muse/CMakeLists.txt b/muse2/muse/CMakeLists.txt index 0877d025..2a630f84 100644 --- a/muse2/muse/CMakeLists.txt +++ b/muse2/muse/CMakeLists.txt @@ -94,6 +94,7 @@ file (GLOB core_source_files helper.cpp importmidi.cpp key.cpp + keyevent.cpp memory.cpp midi.cpp midictrl.cpp diff --git a/muse2/muse/dssihost.cpp b/muse2/muse/dssihost.cpp index aa18025d..49204780 100644 --- a/muse2/muse/dssihost.cpp +++ b/muse2/muse/dssihost.cpp @@ -1104,11 +1104,13 @@ bool DssiSynthIF::init(DssiSynth* s) } else if (LADSPA_IS_PORT_OUTPUT(pd)) { - controlsOut[cop].idx = k; - controls[cop].val = 0.0; - controls[cop].tmpVal = 0.0; - controls[cop].enCtrl = false; - controls[cop].en2Ctrl = false; + controlsOut[cop].idx = k; + if (controls) { + controls[cop].val = 0.0; + controls[cop].tmpVal = 0.0; + controls[cop].enCtrl = false; + controls[cop].en2Ctrl = false; + } #ifdef DSSI_DEBUG printf("DssiSynthIF::init control output port:%d port idx:%d name:%s\n", cop, k, ld->PortNames[k]); diff --git a/muse2/muse/keyevent.cpp b/muse2/muse/keyevent.cpp new file mode 100644 index 00000000..de872c9c --- /dev/null +++ b/muse2/muse/keyevent.cpp @@ -0,0 +1,303 @@ +//========================================================= +// MusE +// Linux Music Editor +// $Id: key.cpp,v 1.7.2.7 2008/05/21 00:28:52 terminator356 Exp $ +// +// (C) Copyright 1999/2000 Werner Schweer (ws@seh.de) +//========================================================= + +#include +#include +#include + +#include "key.h" +#include "globals.h" +#include "gconfig.h" +#include "xml.h" +#include "keyevent.h" + +KeyList keymap; + +//--------------------------------------------------------- +// KeyList +//--------------------------------------------------------- + +KeyList::KeyList() + { + _key = 0; + insert(std::pair (MAX_TICK+1, new KeyEvent(_key, 0))); +// _keySN = 1; + useList = true; + } + +//--------------------------------------------------------- +// add +//--------------------------------------------------------- + +void KeyList::add(unsigned tick, int key) + { + if (tick > MAX_TICK) + tick = MAX_TICK; + iKeyEvent e = upper_bound(tick); + + if (tick == e->second->tick) + e->second->key = key; + else { + KeyEvent* ne = e->second; + KeyEvent* ev = new KeyEvent(ne->key, ne->tick); + ne->key = key; + ne->tick = tick; + insert(std::pair (tick, ev)); + } + } + +//--------------------------------------------------------- +// KeyList::dump +//--------------------------------------------------------- + +void KeyList::dump() const + { + printf("\nKeyList:\n"); + for (ciKeyEvent i = begin(); i != end(); ++i) { + printf("%6d %06d key %6d\n", + i->first, i->second->tick, i->second->key); + } + } + + +//--------------------------------------------------------- +// clear +//--------------------------------------------------------- + +void KeyList::clear() + { + for (iKeyEvent i = begin(); i != end(); ++i) + delete i->second; + KEYLIST::clear(); + insert(std::pair (MAX_TICK+1, new KeyEvent(0, 0))); +// ++_keySN; + } + +//--------------------------------------------------------- +// key +//--------------------------------------------------------- + +int KeyList::key(unsigned tick) const + { + if (useList) { + ciKeyEvent i = upper_bound(tick); + if (i == end()) { + printf("no key at tick %d,0x%x\n", tick, tick); + return 1000; + } + return i->second->key; + } + else + return _key; + } + +//--------------------------------------------------------- +// del +//--------------------------------------------------------- + +void KeyList::del(unsigned tick) + { +// printf("KeyList::del(%d)\n", tick); + iKeyEvent e = find(tick); + if (e == end()) { + printf("KeyList::del(%d): not found\n", tick); + return; + } + del(e); +// ++_keySN; + } + +void KeyList::del(iKeyEvent e) + { + iKeyEvent ne = e; + ++ne; + if (ne == end()) { + printf("KeyList::del() HALLO\n"); + return; + } + ne->second->key = e->second->key; + ne->second->tick = e->second->tick; + erase(e); +// ++_keySN; + } + +//--------------------------------------------------------- +// change +//--------------------------------------------------------- + +void KeyList::change(unsigned tick, int newkey) + { + iKeyEvent e = find(tick); + e->second->key = newkey; +// ++_keySN; + } + +//--------------------------------------------------------- +// setKey +// called from transport window +// & slave mode key changes +//--------------------------------------------------------- + +//void KeyList::setKey(unsigned tick, int newkey) +// { +// if (useList) +// add(tick, newkey); +// else +// _key = newkey; +// ++_keySN; +// } + +//--------------------------------------------------------- +// addKey +//--------------------------------------------------------- + +void KeyList::addKey(unsigned t, int key) + { + add(t, key); +// ++_keySN; + } + +//--------------------------------------------------------- +// delKey +//--------------------------------------------------------- + +void KeyList::delKey(unsigned tick) + { + del(tick); +// ++_keySN; + } + +//--------------------------------------------------------- +// changeKey +//--------------------------------------------------------- + +//void KeyList::changeKey(unsigned tick, int newkey) +// { +// change(tick, newkey); +// ++_keySN; +// } + +//--------------------------------------------------------- +// setMasterFlag +//--------------------------------------------------------- + +bool KeyList::setMasterFlag(unsigned /*tick*/, bool val) + { + if (useList != val) { + useList = val; +// ++_keySN; + return true; + } + return false; + } + + + +//--------------------------------------------------------- +// KeyList::write +//--------------------------------------------------------- + +void KeyList::write(int level, Xml& xml) const + { + xml.put(level++, "", _key); + for (ciKeyEvent i = begin(); i != end(); ++i) + i->second->write(level, xml, i->first); + xml.tag(level, "/keylist"); + } + +//--------------------------------------------------------- +// KeyList::read +//--------------------------------------------------------- + +void KeyList::read(Xml& xml) + { + for (;;) { + Xml::Token token = xml.parse(); + const QString& tag = xml.s1(); + switch (token) { + case Xml::Error: + case Xml::End: + return; + case Xml::TagStart: + if (tag == "key") { + KeyEvent* t = new KeyEvent(); + unsigned tick = t->read(xml); + iKeyEvent pos = find(tick); + if (pos != end()) + erase(pos); + insert(std::pair (tick, t)); + } + else + xml.unknown("keyList"); + break; + case Xml::Attribut: + if (tag == "fix") + _key = xml.s2().toInt(); + break; + case Xml::TagEnd: + if (tag == "keylist") { + //++_keySN; + return; + } + default: + break; + } + } + } + +//--------------------------------------------------------- +// KeyEvent::write +//--------------------------------------------------------- + +void KeyEvent::write(int level, Xml& xml, int at) const + { + xml.tag(level++, "key at=\"%d\"", at); + xml.intTag(level, "tick", tick); + xml.intTag(level, "val", key); + xml.tag(level, "/key"); + } + +//--------------------------------------------------------- +// KeyEvent::read +//--------------------------------------------------------- + +int KeyEvent::read(Xml& xml) + { + int at = 0; + for (;;) { + Xml::Token token = xml.parse(); + const QString& tag = xml.s1(); + switch (token) { + case Xml::Error: + case Xml::End: + return 0; + case Xml::TagStart: + if (tag == "tick") + tick = xml.parseInt(); + else if (tag == "val") + key = xml.parseInt(); + else + xml.unknown("KeyEvent"); + break; + case Xml::Attribut: + if (tag == "at") + at = xml.s2().toInt(); + break; + case Xml::TagEnd: + if (tag == "key") { + return at; + } + default: + break; + } + } + return 0; + } + + + diff --git a/muse2/muse/keyevent.h b/muse2/muse/keyevent.h new file mode 100644 index 00000000..cf475a52 --- /dev/null +++ b/muse2/muse/keyevent.h @@ -0,0 +1,97 @@ +//========================================================= +// MusE +// Linux Music Editor +// $Id: tempo.h,v 1.2.2.1 2006/09/19 19:07:09 spamatica Exp $ +// +// (C) Copyright 1999/2000 Werner Schweer (ws@seh.de) +//========================================================= +#ifndef KEYEVENT_H +#define KEYEVENT_H + +#include + +#ifndef MAX_TICK +#define MAX_TICK (0x7fffffff/100) +#endif + +class Xml; + +//--------------------------------------------------------- +// Tempo Event +//--------------------------------------------------------- + +struct KeyEvent { + int key; + unsigned tick; // new tempo at tick + //unsigned frame; // precomputed time for tick in sec + + int read(Xml&); + void write(int, Xml&, int) const; + + KeyEvent() { } + KeyEvent(unsigned k, unsigned tk) { + key = k; + tick = tk; + //frame = 0; + } + }; + +//--------------------------------------------------------- +// TempoList +//--------------------------------------------------------- + +typedef std::map > KEYLIST; +typedef KEYLIST::iterator iKeyEvent; +typedef KEYLIST::const_iterator ciKeyEvent; +typedef KEYLIST::reverse_iterator riKeyEvent; +typedef KEYLIST::const_reverse_iterator criKeyEvent; + +class KeyList : public KEYLIST { +// int _keySN; // serial no to track key changes + bool useList; + int _key; // key if not using key list + + void add(unsigned tick, int tempo); + void change(unsigned tick, int newKey); + void del(iKeyEvent); + void del(unsigned tick); + + public: + + enum keyList { + keyC, + keyCis, + keyD, + keyDis, + keyE, + keyF, + keyFis, + keyG, + keyGis, + keyA, + keyB, + keyBes, + }; + + + KeyList(); + void clear(); + + void read(Xml&); + void write(int, Xml&) const; + void dump() const; + + int key(unsigned tick) const; + + //int keySN() const { return _keySN; } +// void setKey(unsigned tick, int newKey); + void addKey(unsigned t, int newKey); + void delKey(unsigned tick); +// void changeKey(unsigned tick, int newKey); + bool setMasterFlag(unsigned tick, bool val); + }; + +extern KeyList keymap; + + +#endif // KEYEVENT_H diff --git a/muse2/muse/master/lmaster.cpp b/muse2/muse/master/lmaster.cpp index 00a09d13..8b2d84a8 100644 --- a/muse2/muse/master/lmaster.cpp +++ b/muse2/muse/master/lmaster.cpp @@ -13,8 +13,8 @@ #include "song.h" #include "globals.h" #include "audio.h" -///#include "posedit.h" -///#include "sigedit.h" +//#include "posedit.h" +//#include "sigedit.h" #include "shortcuts.h" #include "debug.h" @@ -30,6 +30,7 @@ #include #include #include +#include #define LMASTER_BEAT_COL 0 #define LMASTER_TIME_COL 1 @@ -37,6 +38,13 @@ #define LMASTER_VAL_COL 3 #define LMASTER_MSGBOX_STRING "MusE: List Editor" + +QStringList keyStrs = QStringList() + << "C" << "C#" << "D" << "D#"<< "E" << "F" + << "F#"<< "G"<< "G#"<< "A"<< "B"<< "B#"; + + + //--------------------------------------------------------- // closeEvent //--------------------------------------------------------- @@ -67,6 +75,7 @@ LMaster::LMaster() pos_editor = 0; editor = 0; sig_editor = 0; + key_editor = 0; editedItem = 0; editingNewItem = false; setWindowTitle(tr("MusE: Mastertrack")); @@ -80,6 +89,7 @@ LMaster::LMaster() menuEdit->addSeparator(); tempoAction = menuEdit->addAction(tr("Insert Tempo")); signAction = menuEdit->addAction(tr("Insert Signature")); + keyAction = menuEdit->addAction(tr("Insert Key")); posAction = menuEdit->addAction(tr("Edit Positon")); valAction = menuEdit->addAction(tr("Edit Value")); delAction = menuEdit->addAction(tr("Delete Event")); @@ -87,12 +97,14 @@ LMaster::LMaster() connect(tempoAction, SIGNAL(triggered()), signalMapper, SLOT(map())); connect(signAction, SIGNAL(triggered()), signalMapper, SLOT(map())); + connect(keyAction, SIGNAL(triggered()), signalMapper, SLOT(map())); connect(posAction, SIGNAL(triggered()), signalMapper, SLOT(map())); connect(valAction, SIGNAL(triggered()), signalMapper, SLOT(map())); connect(delAction, SIGNAL(triggered()), signalMapper, SLOT(map())); signalMapper->setMapping(tempoAction, CMD_INSERT_TEMPO); signalMapper->setMapping(signAction, CMD_INSERT_SIG); + signalMapper->setMapping(keyAction, CMD_INSERT_KEY); signalMapper->setMapping(posAction, CMD_EDIT_BEAT); signalMapper->setMapping(valAction, CMD_EDIT_VALUE); signalMapper->setMapping(delAction, CMD_DELETE); @@ -103,18 +115,19 @@ LMaster::LMaster() tools = addToolBar(tr("Master tools")); tools->addActions(undoRedo->actions()); - //QToolBar* edit = new QToolBar(this, "edit tools"); QToolBar* edit = addToolBar(tr("Edit tools")); - //QToolButton* tempoButton = new QToolButton(edit); QToolButton* tempoButton = new QToolButton(); - //QToolButton* timeSigButton = new QToolButton(edit); QToolButton* timeSigButton = new QToolButton(); + QToolButton* keyButton = new QToolButton(); tempoButton->setText(tr("Tempo")); timeSigButton->setText(tr("Timesig")); + keyButton->setText(tr("Key")); tempoButton->setToolTip(tr("new tempo")); timeSigButton->setToolTip(tr("new signature")); + keyButton->setToolTip(tr("new key")); edit->addWidget(tempoButton); edit->addWidget(timeSigButton); + edit->addWidget(keyButton); ///Q3Accel* qa = new Q3Accel(this); ///qa->connectItem(qa->insertItem(Qt::CTRL+Qt::Key_Z), song, SLOT(undo())); @@ -153,8 +166,10 @@ LMaster::LMaster() connect(view, SIGNAL(itemPressed(QTreeWidgetItem*, int)), SLOT(itemPressed(QTreeWidgetItem*, int))); connect(view, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), SLOT(itemDoubleClicked(QTreeWidgetItem*))); connect(song, SIGNAL(songChanged(int)), SLOT(songChanged(int))); + connect(this, SIGNAL(seekTo(int)), song, SLOT(seekTo(int))); connect(tempoButton, SIGNAL(clicked()), SLOT(tempoButtonClicked())); connect(timeSigButton, SIGNAL(clicked()), SLOT(timeSigButtonClicked())); + connect(keyButton, SIGNAL(clicked()), SLOT(insertKey())); initShortcuts(); } @@ -186,6 +201,10 @@ void LMaster::insertTempo(const TEvent* ev) new LMasterTempoItem(view, ev); } +void LMaster::insertKey(const KeyEvent* ev) + { + new LMasterKeyEventItem(view, ev); + } //--------------------------------------------------------- // updateList //--------------------------------------------------------- @@ -204,33 +223,65 @@ void LMaster::updateList() view->clear(); const TempoList* t = &tempomap; const AL::SigList* s = &AL::sigmap; + const KeyList* k = &keymap; criTEvent it = t->rbegin(); AL::criSigEvent is = s->rbegin(); + criKeyEvent ik = k->rbegin(); + + // three lists that should be added to the view. + // question if it would not be easier to merge the lists and use a sorting algorithm? + // how often is this function called? A: only on songChanged (SC_TEMPO && SC_SIG) + for (;;) { - if (it == t->rend()) { - while(is != s->rend()) { - insertSig(is->second); - ++is; - } - break; - } - if (is == s->rend()) { - while (it != t->rend()) { - insertTempo(it->second); - ++it; - } - break; - } - if (is->second->tick > it->second->tick) { - insertSig(is->second); - ++is; - } - else { - insertTempo(it->second); - ++it; - } - } + + // crazy long, must be possible to solve more elegantly... + + if (ik != k->rend() && is == s->rend() && it == t->rend()) {// ik biggest + insertKey(ik->second); + ++ik; + } + else if (is != s->rend() && ik == k->rend() && it == t->rend()) {// is biggest + insertSig(is->second); + ++is; + } + else if (it != t->rend() && ik == k->rend() && is == s->rend()) {// it biggest + insertTempo(it->second); + ++it; + } + + else if (ik != k->rend() && (is == s->rend() && (ik->second->tick >= it->second->tick) + || (it == t->rend() && ik->second->tick >= is->second->tick ))) {// ik biggest + insertKey(ik->second); + ++ik; + } + else if (is != s->rend() && (ik == k->rend() && (is->second->tick >= it->second->tick) + || (it == t->rend() && is->second->tick >= ik->second->tick ))) {// is biggest + insertSig(is->second); + ++is; + } + + else if (it != t->rend() && (ik == k->rend() && (it->second->tick >= is->second->tick) + || (is == s->rend() && it->second->tick >= ik->second->tick ))) {// it biggest + insertTempo(it->second); + ++it; + } + + else if (ik != k->rend() && ik->second->tick >= is->second->tick && ik->second->tick >= it->second->tick) {// ik biggest + insertKey(ik->second); + ++ik; + } + else if (is != s->rend() && is->second->tick >= it->second->tick && is->second->tick >= ik->second->tick) { // is biggest + insertSig(is->second); + ++is; + } + else if (it != t->rend() && it->second->tick >= is->second->tick && it->second->tick >= ik->second->tick) { // it biggest + insertTempo(it->second); + ++it; + } + if (ik == k->rend() && is == s->rend() && it == t->rend() ) + break; + } // Try to reselect the previous selection: if(selected) @@ -321,6 +372,13 @@ void LMaster::cmd(int cmd) audio->msgRemoveSig(s->tick(), s->z(), s->n()); break; } + case LMASTER_KEYEVENT: + { + //LMasterKeyEventItem* k = (LMasterKeyEventItem*) l; + keymap.delKey(l->tick()); + //audio->msgRemoveSig(k->tick(), k->z(), k->n()); + break; + } default: M_ERROR("Default switch statement reached"); break; @@ -334,6 +392,9 @@ void LMaster::cmd(int cmd) case CMD_INSERT_SIG: timeSigButtonClicked(); break; + case CMD_INSERT_KEY: + insertKey(); + break; case CMD_EDIT_BEAT: case CMD_EDIT_VALUE: cmd == CMD_EDIT_VALUE ? editorColumn = LMASTER_VAL_COL : editorColumn = LMASTER_BEAT_COL; @@ -365,6 +426,7 @@ void LMaster::itemPressed(QTreeWidgetItem* i, int column) void LMaster::itemDoubleClicked(QTreeWidgetItem* i) { //printf("itemDoubleClicked\n"); + emit seekTo(((LMasterLViewItem*) i)->tick()); if (!editedItem && editorColumn == LMASTER_VAL_COL) { editedItem = (LMasterLViewItem*) i; @@ -394,7 +456,7 @@ void LMaster::itemDoubleClicked(QTreeWidgetItem* i) editor->selectAll(); connect(editor, SIGNAL(returnPressed()), SLOT(returnPressed())); } - else { // Edit signatur value: + else if (editedItem->getType() == LMASTER_SIGEVENT) { // Edit signatur value: if (!sig_editor) sig_editor = new SigEdit(view->viewport()); sig_editor->setValue(editedItem->text(LMASTER_VAL_COL)); @@ -403,6 +465,21 @@ void LMaster::itemDoubleClicked(QTreeWidgetItem* i) sig_editor->setFocus(); connect(sig_editor, SIGNAL(returnPressed()), SLOT(returnPressed())); } + else if (editedItem->getType() == LMASTER_KEYEVENT) { + if (!key_editor) + key_editor = new QComboBox(view->viewport()); + key_editor->addItems(keyStrs); + //key_editor->setText(editedItem->text(LMASTER_VAL_COL)); + key_editor->setCurrentIndex(keyStrs.indexOf(editedItem->text(LMASTER_VAL_COL))); + key_editor->setGeometry(itemRect); + key_editor->show(); + key_editor->setFocus(); + //key_editor->selectAll(); + connect(key_editor, SIGNAL(currentIndexChanged(int)), SLOT(returnPressed())); + } + else { + printf("illegal Master list type\n"); + } } // Edit tempo or signal position: else if (!editedItem && editorColumn == LMASTER_BEAT_COL) { @@ -523,6 +600,25 @@ void LMaster::returnPressed() view->setCurrentItem(newSelected); } } + else if (editedItem->getType() == LMASTER_KEYEVENT) { + LMasterKeyEventItem* k = (LMasterKeyEventItem*) editedItem; + int key = k->key(); +// song->startUndo(); +// audio->msgDeleteTempo(oldtick, tempo, false); +// audio->msgAddTempo(newtick, tempo, false); +// song->endUndo(SC_TEMPO); + keymap.delKey(oldtick); + keymap.addKey(newtick, key); + // Select the item: + QTreeWidgetItem* newSelected = (QTreeWidgetItem*) getItemAtPos(newtick, LMASTER_KEYEVENT); + if (newSelected) { + view->clearSelection(); + view->setCurrentItem(newSelected); + } + } + else { + printf("unknown master list event type!\n"); + } } pos_editor->hide(); @@ -533,7 +629,8 @@ void LMaster::returnPressed() // else if (editedItem->getType() == LMASTER_SIGEVENT && editorColumn == LMASTER_VAL_COL) { - ///Sig newSig = sig_editor->sig(); + printf("SIGEVENT return\n"); + ///Sig newSig = sig_editor->sig(); AL::TimeSignature newSig = sig_editor->sig(); sig_editor->hide(); @@ -541,8 +638,8 @@ void LMaster::returnPressed() // Added p3.3.43 Prevents aborting with 0 z or n. if(newSig.isValid()) { - LMasterSigEventItem* e = (LMasterSigEventItem*) editedItem; + printf("adding sig %d %d\n", e->z(),e->n()); int tick = e->tick(); if (!editingNewItem) { song->startUndo(); @@ -553,9 +650,38 @@ void LMaster::returnPressed() } else audio->msgAddSig(tick, newSig.z, newSig.n, true); - } + } + else { + printf("Signature is not valid!\n"); + } } + else if (editedItem->getType() == LMASTER_KEYEVENT && editorColumn == LMASTER_VAL_COL) { + printf("KEYEVENT return\n"); + QString input = key_editor->currentText(); + key_editor->hide(); + repaint(); + LMasterKeyEventItem* e = (LMasterKeyEventItem*) editedItem; + const KeyEvent* t = e->getEvent(); + unsigned tick = t->tick; + int key = keyStrs.indexOf(input); + + if (!editingNewItem) { +// song->startUndo(); +// audio->msgDeleteTempo(tick, e->tempo(), false); +// audio->msgAddTempo(tick, tempo, false); +// song->endUndo(SC_TEMPO); + keymap.addKey(tick,key); + } + // + // New item edited: + // + else { + //audio->msgAddTempo(tick, tempo, true); + keymap.addKey(tick,key); + } + } + updateList(); view->setFocus(); // No item edited now: editedItem = 0; @@ -592,6 +718,35 @@ QString LMasterLViewItem::text(int column) const return ret; } +//--------------------------------------------------------- +// LMasterKeyEventItem +//! Initializes a LMasterKeyEventItem with a KeyEvent +//--------------------------------------------------------- +LMasterKeyEventItem::LMasterKeyEventItem(QTreeWidget* parent, const KeyEvent* ev) + : LMasterLViewItem(parent) + { + keyEvent = ev; + unsigned t = ev->tick; + int bar, beat; + unsigned tick; + AL::sigmap.tickValues(t, &bar, &beat, &tick); + c1.sprintf("%04d.%02d.%03d", bar+1, beat+1, tick); + + double time = double(tempomap.tick2frame(t)) / double(sampleRate); + int min = int(time) / 60; + int sec = int(time) % 60; + int msec = int((time - (min*60 + sec)) * 1000.0); + c2.sprintf("%03d:%02d:%03d", min, sec, msec); + c3 = "Key"; + //int dt = ev->key; + c4 = keyStrs[ev->key]; + setText(0, c1); + setText(1, c2); + setText(2, c3); + setText(3, c4); + } + + //--------------------------------------------------------- // LMasterTempoItem //! Initializes a LMasterTempoItem with a TEvent @@ -607,7 +762,7 @@ LMasterTempoItem::LMasterTempoItem(QTreeWidget* parent, const TEvent* ev) AL::sigmap.tickValues(t, &bar, &beat, &tick); c1.sprintf("%04d.%02d.%03d", bar+1, beat+1, tick); - double time = double(ev->frame) / double(sampleRate); + double time = double(tempomap.tick2frame(t) /*ev->frame*/) / double(sampleRate); int min = int(time) / 60; int sec = int(time) % 60; int msec = int((time - (min*60 + sec)) * 1000.0); @@ -655,12 +810,13 @@ LMasterSigEventItem::LMasterSigEventItem(QTreeWidget* parent, const AL::SigEvent void LMaster::tempoButtonClicked() { LMasterTempoItem* lastTempo = (LMasterTempoItem*) getLastOfType(LMASTER_TEMPO); - QString beatString = ((LMasterLViewItem*)lastTempo)->text(LMASTER_BEAT_COL); - int m, b, t; - Pos p = Pos(beatString); - p.mbt(&m, &b, &t); - m++; //Next bar - int newTick = AL::sigmap.bar2tick(m, b, t); +// QString beatString = ((LMasterLViewItem*)lastTempo)->text(LMASTER_BEAT_COL); +// int m, b, t; +// Pos p = Pos(beatString); +// p.mbt(&m, &b, &t); +// m++; //Next bar +// int newTick = AL::sigmap.bar2tick(m, b, t); + int newTick = song->cpos(); TEvent* ev = new TEvent(lastTempo->tempo(), newTick); new LMasterTempoItem(view, ev); QTreeWidgetItem* newTempoItem = view->topLevelItem(0); @@ -675,18 +831,19 @@ void LMaster::tempoButtonClicked() //--------------------------------------------------------- -// tempoButtonClicked() +// timeSigButtonClicked() //! inserts a new sig-item in the list and starts the editor for it //--------------------------------------------------------- void LMaster::timeSigButtonClicked() { LMasterSigEventItem* lastSig = (LMasterSigEventItem*) getLastOfType(LMASTER_SIGEVENT); - QString beatString = ((LMasterLViewItem*)lastSig)->text(LMASTER_BEAT_COL); - int m, b, t; - Pos p = Pos(beatString); - p.mbt(&m, &b, &t); - m++; - int newTick = AL::sigmap.bar2tick(m, b, t); +// QString beatString = ((LMasterLViewItem*)lastSig)->text(LMASTER_BEAT_COL); +// int m, b, t; +// Pos p = Pos(beatString); +// p.mbt(&m, &b, &t); +// m++; +// int newTick = AL::sigmap.bar2tick(m, b, t); + int newTick = song->cpos(); AL::SigEvent* ev = new AL::SigEvent(AL::TimeSignature(lastSig->z(), lastSig->n()), newTick); new LMasterSigEventItem(view, ev); QTreeWidgetItem* newSigItem = view->topLevelItem(0); @@ -699,6 +856,33 @@ void LMaster::timeSigButtonClicked() itemDoubleClicked(newSigItem); } +//--------------------------------------------------------- +// insertKey() +//! inserts a new key in the list and starts the editor for it +//--------------------------------------------------------- +void LMaster::insertKey() + { + LMasterKeyEventItem* lastKey = (LMasterKeyEventItem*) getLastOfType(LMASTER_KEYEVENT); + + //QString beatString = ((LMasterLViewItem*)lastKey)->text(LMASTER_BEAT_COL); + //int m, b, t; + //Pos p = Pos(beatString); + //p.mbt(&m, &b, &t); + //m++; //Next bar + + //int newTick = AL::sigmap.bar2tick(m, b, t); + int newTick = song->cpos(); + KeyEvent* ev = new KeyEvent(lastKey->key(), newTick); + new LMasterKeyEventItem(view, ev); + QTreeWidgetItem* newKeyItem = view->topLevelItem(0); + + editingNewItem = true; // State + editorColumn = LMASTER_VAL_COL; // Set that we edit editorColumn + view->clearSelection(); + view->setCurrentItem(newKeyItem); + itemDoubleClicked(newKeyItem); + } + /*! \fn LMaster::getLastOfType(LMASTER_LVTYPE t) @@ -745,6 +929,7 @@ void LMaster::initShortcuts() { tempoAction->setShortcut(shortcuts[SHRT_LM_INS_TEMPO].key); signAction->setShortcut(shortcuts[SHRT_LM_INS_SIG].key); + keyAction->setShortcut(shortcuts[SHRT_LM_INS_KEY].key); posAction->setShortcut(shortcuts[SHRT_LM_EDIT_BEAT].key); valAction->setShortcut(shortcuts[SHRT_LM_EDIT_VALUE].key); } diff --git a/muse2/muse/master/lmaster.h b/muse2/muse/master/lmaster.h index cd687e45..925b5837 100644 --- a/muse2/muse/master/lmaster.h +++ b/muse2/muse/master/lmaster.h @@ -12,6 +12,7 @@ #include "noteinfo.h" #include "cobject.h" #include "tempo.h" +#include "keyevent.h" ///#include "sig.h" //#include "al/sig.h" @@ -30,13 +31,16 @@ using Awl::PosEdit; using Awl::SigEdit; class QLineEdit; +class QComboBox; enum LMASTER_LVTYPE { LMASTER_TEMPO = 0, - LMASTER_SIGEVENT + LMASTER_SIGEVENT, + LMASTER_KEYEVENT }; + //--------------------------------------------------------- // LMasterLViewItem //! QListViewItem base class for LMasterTempoItem and LMasterSigEventItem @@ -71,6 +75,22 @@ class LMasterTempoItem : public LMasterLViewItem { }; //--------------------------------------------------------- +// LMasterKeyItem +//! QListViewItem which holds data for a KetEvent +//--------------------------------------------------------- +class LMasterKeyEventItem : public LMasterLViewItem { + + private: + const KeyEvent* keyEvent; + + public: + LMasterKeyEventItem(QTreeWidget* parent, const KeyEvent* t); + virtual LMASTER_LVTYPE getType() { return LMASTER_KEYEVENT; } + const KeyEvent* getEvent() { return keyEvent; } + virtual unsigned tick() { return keyEvent->tick; } + int key() { return keyEvent->key; } + }; +//--------------------------------------------------------- // LMasterTempoItem //! QListViewItem which holds data for a SigEvent //--------------------------------------------------------- @@ -98,24 +118,26 @@ class LMaster : public MidiEditor { QToolBar* tools; QMenu* menuEdit; - enum { CMD_DELETE, CMD_INSERT_SIG, CMD_INSERT_TEMPO, CMD_EDIT_BEAT, CMD_EDIT_VALUE }; + enum { CMD_DELETE, CMD_INSERT_SIG, CMD_INSERT_TEMPO, CMD_EDIT_BEAT, CMD_EDIT_VALUE, CMD_INSERT_KEY }; Q_OBJECT virtual void closeEvent(QCloseEvent*); void updateList(); void insertTempo(const TEvent*); void insertSig(const SigEvent*); + void insertKey(const KeyEvent*); LMasterLViewItem* getItemAtPos(unsigned tick, LMASTER_LVTYPE t); void initShortcuts(); QLineEdit* editor; PosEdit* pos_editor; + QComboBox* key_editor; // State-like members: LMasterLViewItem* editedItem; SigEdit* sig_editor; int editorColumn; bool editingNewItem; - QAction *tempoAction, *signAction, *posAction, *valAction, *delAction; + QAction *tempoAction, *signAction, *posAction, *valAction, *delAction, *keyAction; private slots: void select(QTreeWidgetItem*, QTreeWidgetItem*); @@ -124,6 +146,7 @@ class LMaster : public MidiEditor { void itemPressed(QTreeWidgetItem* i, int column); void tempoButtonClicked(); void timeSigButtonClicked(); + void insertKey(); void cmd(int cmd); public slots: @@ -132,6 +155,7 @@ class LMaster : public MidiEditor { signals: void deleted(unsigned long); + void seekTo(int tick); public: LMaster(); diff --git a/muse2/muse/shortcuts.cpp b/muse2/muse/shortcuts.cpp index 9cbc3726..cd54b096 100644 --- a/muse2/muse/shortcuts.cpp +++ b/muse2/muse/shortcuts.cpp @@ -134,7 +134,7 @@ void initShortCuts() defShrt(SHRT_SEL_BELOW_ADD, Qt::SHIFT + Qt::Key_Down, "Edit: Add nearest part on track below", ARRANG_SHRT, "sel_part_below_add"); defShrt(SHRT_INSERT, Qt::CTRL+Qt::SHIFT+ Qt::Key_I, "Edit: Insert parts, moving time", ARRANG_SHRT, "insert_parts"); - defShrt(SHRT_INSERTMEAS, Qt::CTRL+Qt::SHIFT+ Qt::Key_M, "Edit: Insert empty measure", ARRANG_SHRT, "insert_measure"); + defShrt(SHRT_INSERTMEAS, Qt::CTRL+Qt::SHIFT+ Qt::Key_O, "Edit: Insert empty measure", ARRANG_SHRT, "insert_measure"); defShrt(SHRT_PASTE_CLONE, Qt::CTRL+Qt::SHIFT+Qt::Key_V, "Edit: Paste clone", ARRANG_SHRT, "paste_clone"); defShrt(SHRT_PASTE_TO_TRACK, Qt::CTRL+Qt::Key_B, "Edit: Paste to track", ARRANG_SHRT, "paste_to_track"); @@ -299,7 +299,8 @@ void initShortCuts() defShrt(SHRT_LM_INS_SIG , Qt::CTRL + Qt::Key_R, "Insert Signature", LMEDIT_SHRT, "lm_ins_sig"); defShrt(SHRT_LM_EDIT_BEAT, Qt::CTRL + Qt::SHIFT+ Qt::Key_E, "Change Event Position", LMEDIT_SHRT, "lm_edit_beat"); defShrt(SHRT_LM_EDIT_VALUE, Qt::CTRL + Qt::Key_E, "Edit Event Value", LMEDIT_SHRT, "lm_edit_val"); - + defShrt(SHRT_LM_INS_KEY, Qt::CTRL + Qt::Key_K, "Insert Key", LMEDIT_SHRT, "lm_ins_key"); + defShrt(SHRT_NEXT_MARKER, Qt::Key_F6, "Goto Next Marker", ARRANG_SHRT, "me_sel_next"); defShrt(SHRT_PREV_MARKER, Qt::Key_F5, "Goto Prev Marker", ARRANG_SHRT, "me_sel_prev"); diff --git a/muse2/muse/shortcuts.h b/muse2/muse/shortcuts.h index 6878d177..1098be49 100644 --- a/muse2/muse/shortcuts.h +++ b/muse2/muse/shortcuts.h @@ -316,7 +316,8 @@ enum { SHRT_LM_INS_SIG, // Ctrl+R SHRT_LM_EDIT_BEAT, // Ctrl+Shift+E SHRT_LM_EDIT_VALUE,// Ctrl+E - + SHRT_LM_INS_KEY, // Ctrl+K + // Marker view SHRT_NEXT_MARKER, SHRT_PREV_MARKER, diff --git a/muse2/muse/song.cpp b/muse2/muse/song.cpp index dbb193d9..a7cff79d 100644 --- a/muse2/muse/song.cpp +++ b/muse2/muse/song.cpp @@ -42,6 +42,7 @@ #include "midi.h" ///#include "sig.h" #include "al/sig.h" +#include "keyevent.h" #include extern void clearMidiTransforms(); @@ -1288,6 +1289,17 @@ void Song::swapTracks(int i1, int i2) _tracks[i2] = track; } +//--------------------------------------------------------- +// seekTo +// setPos slot, only active when not doing playback +//--------------------------------------------------------- +void Song::seekTo(int tick) +{ + if (!audio->isPlaying()) { + Pos p(tick, true); + setPos(0, p); + } +} //--------------------------------------------------------- // setPos // song->setPos(Song::CPOS, pos, true, true, true); @@ -2098,6 +2110,7 @@ void Song::clear(bool signal, bool /*clear_all*/) tempomap.clear(); AL::sigmap.clear(); + keymap.clear(); undoList->clearDelete(); redoList->clear(); _markerList->clear(); @@ -2183,6 +2196,7 @@ void Song::cleanupForQuit() tempomap.clear(); AL::sigmap.clear(); + keymap.clear(); if(debugMsg) printf("deleting undoList, clearing redoList\n"); diff --git a/muse2/muse/song.h b/muse2/muse/song.h index c735dfd5..e4695728 100644 --- a/muse2/muse/song.h +++ b/muse2/muse/song.h @@ -362,6 +362,7 @@ class Song : public QObject { void executeScript(const char* scriptfile, PartList* parts, int quant, bool onlyIfSelected); public slots: + void seekTo(int tick); void update(int flags = -1); void beat(); diff --git a/muse2/muse/songfile.cpp b/muse2/muse/songfile.cpp index 1e8a849b..7a690f74 100644 --- a/muse2/muse/songfile.cpp +++ b/muse2/muse/songfile.cpp @@ -36,6 +36,7 @@ //#include "mixer/amixer.h" // p4.0.2 #include "conf.h" #include "driver/jackmidi.h" +#include "keyevent.h" //struct ClonePart { //const EventList* el; @@ -1258,6 +1259,9 @@ void Song::read(Xml& xml) else if (tag == "siglist") ///sigmap.read(xml); AL::sigmap.read(xml); + else if (tag == "keylist") { + keymap.read(xml); + } else if (tag == "miditrack") { MidiTrack* track = new MidiTrack(); track->read(xml); @@ -1484,6 +1488,7 @@ void Song::write(int level, Xml& xml) const tempomap.write(level, xml); ///sigmap.write(level, xml); AL::sigmap.write(level, xml); + keymap.write(level, xml); _markerList->write(level, xml); writeDrumMap(level, xml, false); -- cgit v1.2.3 From 42be6376637248e01ea2ab0a41a6653b53d71800 Mon Sep 17 00:00:00 2001 From: "Tim E. Real" Date: Sat, 16 Apr 2011 20:49:55 +0000 Subject: Fixed crash in dssihost.cpp - my bad from recent p4.0.20 changes. --- muse2/ChangeLog | 2 +- muse2/muse/dssihost.cpp | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'muse2') diff --git a/muse2/ChangeLog b/muse2/ChangeLog index b73c40c7..a48daf9a 100644 --- a/muse2/ChangeLog +++ b/muse2/ChangeLog @@ -10,7 +10,7 @@ (if there is a time, I'm sure someone will let me know :) ) - song changed not implemented yet - undo/redo is not implemented - - prevented initialization crash for dssi, Tim, please have a look (rj) + - Fixed crash in dssihost.cpp - my bad from recent p4.0.20 changes. (Tim) 15.04.2011: - And while we're at it... Invert drum track 'slivers' in arranger parts. (Tim) - Move part name text to bottom to accommodate drum 'slivers'. diff --git a/muse2/muse/dssihost.cpp b/muse2/muse/dssihost.cpp index 49204780..f2e94dae 100644 --- a/muse2/muse/dssihost.cpp +++ b/muse2/muse/dssihost.cpp @@ -1105,12 +1105,10 @@ bool DssiSynthIF::init(DssiSynth* s) else if (LADSPA_IS_PORT_OUTPUT(pd)) { controlsOut[cop].idx = k; - if (controls) { - controls[cop].val = 0.0; - controls[cop].tmpVal = 0.0; - controls[cop].enCtrl = false; - controls[cop].en2Ctrl = false; - } + controlsOut[cop].val = 0.0; + controlsOut[cop].tmpVal = 0.0; + controlsOut[cop].enCtrl = false; + controlsOut[cop].en2Ctrl = false; #ifdef DSSI_DEBUG printf("DssiSynthIF::init control output port:%d port idx:%d name:%s\n", cop, k, ld->PortNames[k]); -- cgit v1.2.3 From 7afee6563e1b620f06b567ff19e428c6dd203835 Mon Sep 17 00:00:00 2001 From: "Tim E. Real" Date: Sun, 17 Apr 2011 01:57:25 +0000 Subject: Added destructors to sigmap and tempomap. --- muse2/ChangeLog | 1 + muse2/al/sig.cpp | 6 ++++++ muse2/al/sig.h | 1 + muse2/muse/tempo.cpp | 6 ++++++ muse2/muse/tempo.h | 1 + 5 files changed, 15 insertions(+) (limited to 'muse2') diff --git a/muse2/ChangeLog b/muse2/ChangeLog index a48daf9a..002b8bf6 100644 --- a/muse2/ChangeLog +++ b/muse2/ChangeLog @@ -11,6 +11,7 @@ - song changed not implemented yet - undo/redo is not implemented - Fixed crash in dssihost.cpp - my bad from recent p4.0.20 changes. (Tim) + - Added destructors to sigmap and tempomap. Test OK. (Tim) 15.04.2011: - And while we're at it... Invert drum track 'slivers' in arranger parts. (Tim) - Move part name text to bottom to accommodate drum 'slivers'. diff --git a/muse2/al/sig.cpp b/muse2/al/sig.cpp index 7eeae6be..293a5b3e 100644 --- a/muse2/al/sig.cpp +++ b/muse2/al/sig.cpp @@ -64,6 +64,12 @@ SigList::SigList() insert(std::pair (MAX_TICK, new SigEvent(TimeSignature(4, 4), 0))); } +SigList::~SigList() + { + for (iSigEvent i = begin(); i != end(); ++i) + delete i->second; + } + //--------------------------------------------------------- // add // signatures are only allowed at the beginning of diff --git a/muse2/al/sig.h b/muse2/al/sig.h index ed18981f..618cd53c 100644 --- a/muse2/al/sig.h +++ b/muse2/al/sig.h @@ -85,6 +85,7 @@ class SigList : public SIGLIST { public: SigList(); + ~SigList(); void clear(); void add(unsigned tick, const TimeSignature& s); //void add(unsigned tick, int z, int n); diff --git a/muse2/muse/tempo.cpp b/muse2/muse/tempo.cpp index 418ec031..1e476e45 100644 --- a/muse2/muse/tempo.cpp +++ b/muse2/muse/tempo.cpp @@ -30,6 +30,12 @@ TempoList::TempoList() useList = true; } +TempoList::~TempoList() + { + for (iTEvent i = begin(); i != end(); ++i) + delete i->second; + } + //--------------------------------------------------------- // add //--------------------------------------------------------- diff --git a/muse2/muse/tempo.h b/muse2/muse/tempo.h index 61ec50f5..632d60bb 100644 --- a/muse2/muse/tempo.h +++ b/muse2/muse/tempo.h @@ -61,6 +61,7 @@ class TempoList : public TEMPOLIST { public: TempoList(); + ~TempoList(); void clear(); void read(Xml&); -- cgit v1.2.3 From aab05a914e357938f0ccb3d592186320e0646366 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Sun, 17 Apr 2011 15:11:10 +0000 Subject: changed keymap to my needs, and removed all that ugly pointer stuff from the keymap (still to do for the other *maps) --- muse2/muse/keyevent.cpp | 66 +++++++++++++------------------- muse2/muse/keyevent.h | 78 +++++++++++++++++++++---------------- muse2/muse/master/lmaster.cpp | 89 ++++++++++++++++++++++++++++++++----------- muse2/muse/master/lmaster.h | 12 +++--- 4 files changed, 144 insertions(+), 101 deletions(-) (limited to 'muse2') diff --git a/muse2/muse/keyevent.cpp b/muse2/muse/keyevent.cpp index de872c9c..865aef01 100644 --- a/muse2/muse/keyevent.cpp +++ b/muse2/muse/keyevent.cpp @@ -24,9 +24,8 @@ KeyList keymap; KeyList::KeyList() { - _key = 0; - insert(std::pair (MAX_TICK+1, new KeyEvent(_key, 0))); -// _keySN = 1; + _key = KEY_C; + insert(std::pair (MAX_TICK+1, KeyEvent(_key, 0))); useList = true; } @@ -34,20 +33,20 @@ KeyList::KeyList() // add //--------------------------------------------------------- -void KeyList::add(unsigned tick, int key) +void KeyList::add(unsigned tick, key_enum key) { if (tick > MAX_TICK) tick = MAX_TICK; iKeyEvent e = upper_bound(tick); - if (tick == e->second->tick) - e->second->key = key; + if (tick == e->second.tick) + e->second.key = key; else { - KeyEvent* ne = e->second; - KeyEvent* ev = new KeyEvent(ne->key, ne->tick); - ne->key = key; - ne->tick = tick; - insert(std::pair (tick, ev)); + KeyEvent& ne = e->second; + KeyEvent ev = KeyEvent(ne.key, ne.tick); + ne.key = key; + ne.tick = tick; + insert(std::pair (tick, ev)); } } @@ -60,7 +59,7 @@ void KeyList::dump() const printf("\nKeyList:\n"); for (ciKeyEvent i = begin(); i != end(); ++i) { printf("%6d %06d key %6d\n", - i->first, i->second->tick, i->second->key); + i->first, i->second.tick, i->second.key); } } @@ -71,26 +70,23 @@ void KeyList::dump() const void KeyList::clear() { - for (iKeyEvent i = begin(); i != end(); ++i) - delete i->second; KEYLIST::clear(); - insert(std::pair (MAX_TICK+1, new KeyEvent(0, 0))); -// ++_keySN; + insert(std::pair (MAX_TICK+1, KeyEvent(_key, 0))); } //--------------------------------------------------------- -// key +// keyAtTick //--------------------------------------------------------- -int KeyList::key(unsigned tick) const +key_enum KeyList::keyAtTick(unsigned tick) const { if (useList) { ciKeyEvent i = upper_bound(tick); if (i == end()) { printf("no key at tick %d,0x%x\n", tick, tick); - return 1000; + return _key; } - return i->second->key; + return i->second.key; } else return _key; @@ -102,14 +98,12 @@ int KeyList::key(unsigned tick) const void KeyList::del(unsigned tick) { -// printf("KeyList::del(%d)\n", tick); iKeyEvent e = find(tick); if (e == end()) { printf("KeyList::del(%d): not found\n", tick); return; } del(e); -// ++_keySN; } void KeyList::del(iKeyEvent e) @@ -120,21 +114,19 @@ void KeyList::del(iKeyEvent e) printf("KeyList::del() HALLO\n"); return; } - ne->second->key = e->second->key; - ne->second->tick = e->second->tick; + ne->second.key = e->second.key; + ne->second.tick = e->second.tick; erase(e); -// ++_keySN; } //--------------------------------------------------------- // change //--------------------------------------------------------- -void KeyList::change(unsigned tick, int newkey) +void KeyList::change(unsigned tick, key_enum newkey) { iKeyEvent e = find(tick); - e->second->key = newkey; -// ++_keySN; + e->second.key = newkey; } //--------------------------------------------------------- @@ -156,10 +148,9 @@ void KeyList::change(unsigned tick, int newkey) // addKey //--------------------------------------------------------- -void KeyList::addKey(unsigned t, int key) +void KeyList::addKey(unsigned t, key_enum key) { add(t, key); -// ++_keySN; } //--------------------------------------------------------- @@ -169,7 +160,6 @@ void KeyList::addKey(unsigned t, int key) void KeyList::delKey(unsigned tick) { del(tick); -// ++_keySN; } //--------------------------------------------------------- @@ -190,7 +180,6 @@ bool KeyList::setMasterFlag(unsigned /*tick*/, bool val) { if (useList != val) { useList = val; -// ++_keySN; return true; } return false; @@ -206,7 +195,7 @@ void KeyList::write(int level, Xml& xml) const { xml.put(level++, "", _key); for (ciKeyEvent i = begin(); i != end(); ++i) - i->second->write(level, xml, i->first); + i->second.write(level, xml, i->first); xml.tag(level, "/keylist"); } @@ -225,23 +214,22 @@ void KeyList::read(Xml& xml) return; case Xml::TagStart: if (tag == "key") { - KeyEvent* t = new KeyEvent(); - unsigned tick = t->read(xml); + KeyEvent t; + unsigned tick = t.read(xml); iKeyEvent pos = find(tick); if (pos != end()) erase(pos); - insert(std::pair (tick, t)); + insert(std::pair (tick, t)); } else xml.unknown("keyList"); break; case Xml::Attribut: if (tag == "fix") - _key = xml.s2().toInt(); + _key = key_enum(xml.s2().toInt()); break; case Xml::TagEnd: if (tag == "keylist") { - //++_keySN; return; } default: @@ -280,7 +268,7 @@ int KeyEvent::read(Xml& xml) if (tag == "tick") tick = xml.parseInt(); else if (tag == "val") - key = xml.parseInt(); + key = key_enum(xml.parseInt()); else xml.unknown("KeyEvent"); break; diff --git a/muse2/muse/keyevent.h b/muse2/muse/keyevent.h index cf475a52..4a7fc8f9 100644 --- a/muse2/muse/keyevent.h +++ b/muse2/muse/keyevent.h @@ -16,64 +16,78 @@ class Xml; +//don't change this enum! changing the numeric values will affect +//all files using key_enum, and even worse: +//PREVIOUSLY SAVED FILES WILL BE CORRUPT because the keys are +//stored as integers. when the integer -> key mapping changes +//(by inserting or removing elements, for example), this will +//break stuff! (flo) +enum key_enum +{ + KEY_SHARP_BEGIN, + KEY_C, // C or am, uses # for "black keys" + KEY_G, + KEY_D, + KEY_A, + KEY_E, + KEY_B, // or H in german. + KEY_FIS, //replaces F with E# + KEY_SHARP_END, + KEY_B_BEGIN, + KEY_C_B, // the same as C, but uses b for "black keys" + KEY_F, + KEY_BES, // or B in german + KEY_ES, + KEY_AS, + KEY_DES, + KEY_GES, //sounds like FIS, but uses b instead of # + KEY_B_END +}; + + + + //--------------------------------------------------------- -// Tempo Event +// Key Event //--------------------------------------------------------- struct KeyEvent { - int key; - unsigned tick; // new tempo at tick - //unsigned frame; // precomputed time for tick in sec + key_enum key; + unsigned tick; int read(Xml&); void write(int, Xml&, int) const; KeyEvent() { } - KeyEvent(unsigned k, unsigned tk) { + KeyEvent(key_enum k, unsigned tk) { key = k; tick = tk; - //frame = 0; } }; //--------------------------------------------------------- -// TempoList +// KeyList //--------------------------------------------------------- -typedef std::map > KEYLIST; +typedef std::map > KEYLIST; typedef KEYLIST::iterator iKeyEvent; typedef KEYLIST::const_iterator ciKeyEvent; typedef KEYLIST::reverse_iterator riKeyEvent; typedef KEYLIST::const_reverse_iterator criKeyEvent; + + class KeyList : public KEYLIST { -// int _keySN; // serial no to track key changes bool useList; - int _key; // key if not using key list + key_enum _key; // key if not using key list - void add(unsigned tick, int tempo); - void change(unsigned tick, int newKey); + void add(unsigned tick, key_enum tempo); + void change(unsigned tick, key_enum newKey); void del(iKeyEvent); void del(unsigned tick); public: - enum keyList { - keyC, - keyCis, - keyD, - keyDis, - keyE, - keyF, - keyFis, - keyG, - keyGis, - keyA, - keyB, - keyBes, - }; - - KeyList(); void clear(); @@ -81,13 +95,11 @@ class KeyList : public KEYLIST { void write(int, Xml&) const; void dump() const; - int key(unsigned tick) const; + key_enum keyAtTick(unsigned tick) const; - //int keySN() const { return _keySN; } -// void setKey(unsigned tick, int newKey); - void addKey(unsigned t, int newKey); + void addKey(unsigned t, key_enum newKey); void delKey(unsigned tick); -// void changeKey(unsigned tick, int newKey); +// void changeKey(unsigned tick, key_enum newKey); bool setMasterFlag(unsigned tick, bool val); }; diff --git a/muse2/muse/master/lmaster.cpp b/muse2/muse/master/lmaster.cpp index 8b2d84a8..412360e3 100644 --- a/muse2/muse/master/lmaster.cpp +++ b/muse2/muse/master/lmaster.cpp @@ -39,11 +39,53 @@ #define LMASTER_MSGBOX_STRING "MusE: List Editor" +//don't remove or insert new elements in keyStrs. +//only renaming (keeping the semantic sense) is allowed! (flo( QStringList keyStrs = QStringList() - << "C" << "C#" << "D" << "D#"<< "E" << "F" - << "F#"<< "G"<< "G#"<< "A"<< "B"<< "B#"; - - + << "C (sharps)" << "G" << "D" << "A"<< "E" << "B" << "F#" + << "C (flats)"<< "F"<< "Bb" << "Eb"<< "Ab"<< "Db"<< "Gb"; + +//don't change this function (except when renaming stuff) +key_enum stringToKey(QString input) //flo +{ + int index = keyStrs.indexOf(input); + key_enum map[]={KEY_C, KEY_G, KEY_D, KEY_A, KEY_E, KEY_B, KEY_FIS, KEY_C_B, KEY_F, KEY_BES, KEY_ES, KEY_AS, KEY_DES, KEY_GES}; + return map[index]; +} + +//don't change this function (except when renaming stuff) +QString keyToString(key_enum key) //flo +{ + int index; + switch(key) + { + case KEY_C: index= 0; break; + case KEY_G: index= 1; break; + case KEY_D: index= 2; break; + case KEY_A: index= 3; break; + case KEY_E: index= 4; break; + case KEY_B: index= 5; break; + case KEY_FIS: index= 6; break; + case KEY_C_B: index= 7; break; + case KEY_F: index= 8; break; + case KEY_BES: index= 9; break; + case KEY_ES: index=10; break; + case KEY_AS: index=11; break; + case KEY_DES: index=12; break; + case KEY_GES: index=13; break; + + case KEY_SHARP_BEGIN: + case KEY_SHARP_END: + case KEY_B_BEGIN: + case KEY_B_END: + printf("ILLEGAL FUNCTION CALL: keyToString called with key_sharp_begin etc.\n"); + break; + + default: + printf("ILLEGAL FUNCTION CALL: keyToString called with illegal key value (not in enum)\n"); + } + return keyStrs[index]; +} //--------------------------------------------------------- // closeEvent @@ -201,7 +243,7 @@ void LMaster::insertTempo(const TEvent* ev) new LMasterTempoItem(view, ev); } -void LMaster::insertKey(const KeyEvent* ev) +void LMaster::insertKey(const KeyEvent& ev) { new LMasterKeyEventItem(view, ev); } @@ -250,32 +292,32 @@ void LMaster::updateList() ++it; } - else if (ik != k->rend() && (is == s->rend() && (ik->second->tick >= it->second->tick) - || (it == t->rend() && ik->second->tick >= is->second->tick ))) {// ik biggest + else if (ik != k->rend() && (is == s->rend() && (ik->second.tick >= it->second->tick) + || (it == t->rend() && ik->second.tick >= is->second->tick ))) {// ik biggest insertKey(ik->second); ++ik; } else if (is != s->rend() && (ik == k->rend() && (is->second->tick >= it->second->tick) - || (it == t->rend() && is->second->tick >= ik->second->tick ))) {// is biggest + || (it == t->rend() && is->second->tick >= ik->second.tick ))) {// is biggest insertSig(is->second); ++is; } else if (it != t->rend() && (ik == k->rend() && (it->second->tick >= is->second->tick) - || (is == s->rend() && it->second->tick >= ik->second->tick ))) {// it biggest + || (is == s->rend() && it->second->tick >= ik->second.tick ))) {// it biggest insertTempo(it->second); ++it; } - else if (ik != k->rend() && ik->second->tick >= is->second->tick && ik->second->tick >= it->second->tick) {// ik biggest + else if (ik != k->rend() && ik->second.tick >= is->second->tick && ik->second.tick >= it->second->tick) {// ik biggest insertKey(ik->second); ++ik; } - else if (is != s->rend() && is->second->tick >= it->second->tick && is->second->tick >= ik->second->tick) { // is biggest + else if (is != s->rend() && is->second->tick >= it->second->tick && is->second->tick >= ik->second.tick) { // is biggest insertSig(is->second); ++is; } - else if (it != t->rend() && it->second->tick >= is->second->tick && it->second->tick >= ik->second->tick) { // it biggest + else if (it != t->rend() && it->second->tick >= is->second->tick && it->second->tick >= ik->second.tick) { // it biggest insertTempo(it->second); ++it; } @@ -467,8 +509,10 @@ void LMaster::itemDoubleClicked(QTreeWidgetItem* i) } else if (editedItem->getType() == LMASTER_KEYEVENT) { if (!key_editor) + { key_editor = new QComboBox(view->viewport()); - key_editor->addItems(keyStrs); + key_editor->addItems(keyStrs); + } //key_editor->setText(editedItem->text(LMASTER_VAL_COL)); key_editor->setCurrentIndex(keyStrs.indexOf(editedItem->text(LMASTER_VAL_COL))); key_editor->setGeometry(itemRect); @@ -602,7 +646,7 @@ void LMaster::returnPressed() } else if (editedItem->getType() == LMASTER_KEYEVENT) { LMasterKeyEventItem* k = (LMasterKeyEventItem*) editedItem; - int key = k->key(); + key_enum key = k->key(); // song->startUndo(); // audio->msgDeleteTempo(oldtick, tempo, false); // audio->msgAddTempo(newtick, tempo, false); @@ -662,9 +706,9 @@ void LMaster::returnPressed() key_editor->hide(); repaint(); LMasterKeyEventItem* e = (LMasterKeyEventItem*) editedItem; - const KeyEvent* t = e->getEvent(); - unsigned tick = t->tick; - int key = keyStrs.indexOf(input); + const KeyEvent& t = e->getEvent(); + unsigned tick = t.tick; + key_enum key = stringToKey(input); if (!editingNewItem) { // song->startUndo(); @@ -722,11 +766,11 @@ QString LMasterLViewItem::text(int column) const // LMasterKeyEventItem //! Initializes a LMasterKeyEventItem with a KeyEvent //--------------------------------------------------------- -LMasterKeyEventItem::LMasterKeyEventItem(QTreeWidget* parent, const KeyEvent* ev) +LMasterKeyEventItem::LMasterKeyEventItem(QTreeWidget* parent, const KeyEvent& ev) : LMasterLViewItem(parent) { keyEvent = ev; - unsigned t = ev->tick; + unsigned t = ev.tick; int bar, beat; unsigned tick; AL::sigmap.tickValues(t, &bar, &beat, &tick); @@ -738,8 +782,8 @@ LMasterKeyEventItem::LMasterKeyEventItem(QTreeWidget* parent, const KeyEvent* ev int msec = int((time - (min*60 + sec)) * 1000.0); c2.sprintf("%03d:%02d:%03d", min, sec, msec); c3 = "Key"; - //int dt = ev->key; - c4 = keyStrs[ev->key]; + //int dt = ev.key; + c4 = keyToString(ev.key); setText(0, c1); setText(1, c2); setText(2, c3); @@ -872,8 +916,7 @@ void LMaster::insertKey() //int newTick = AL::sigmap.bar2tick(m, b, t); int newTick = song->cpos(); - KeyEvent* ev = new KeyEvent(lastKey->key(), newTick); - new LMasterKeyEventItem(view, ev); + new LMasterKeyEventItem(view, KeyEvent(lastKey->key(), newTick)); QTreeWidgetItem* newKeyItem = view->topLevelItem(0); editingNewItem = true; // State diff --git a/muse2/muse/master/lmaster.h b/muse2/muse/master/lmaster.h index 925b5837..23c86c82 100644 --- a/muse2/muse/master/lmaster.h +++ b/muse2/muse/master/lmaster.h @@ -81,14 +81,14 @@ class LMasterTempoItem : public LMasterLViewItem { class LMasterKeyEventItem : public LMasterLViewItem { private: - const KeyEvent* keyEvent; + KeyEvent keyEvent; public: - LMasterKeyEventItem(QTreeWidget* parent, const KeyEvent* t); + LMasterKeyEventItem(QTreeWidget* parent, const KeyEvent& t); virtual LMASTER_LVTYPE getType() { return LMASTER_KEYEVENT; } - const KeyEvent* getEvent() { return keyEvent; } - virtual unsigned tick() { return keyEvent->tick; } - int key() { return keyEvent->key; } + const KeyEvent& getEvent() { return keyEvent; } + virtual unsigned tick() { return keyEvent.tick; } + key_enum key() { return keyEvent.key; } }; //--------------------------------------------------------- // LMasterTempoItem @@ -125,7 +125,7 @@ class LMaster : public MidiEditor { void updateList(); void insertTempo(const TEvent*); void insertSig(const SigEvent*); - void insertKey(const KeyEvent*); + void insertKey(const KeyEvent&); LMasterLViewItem* getItemAtPos(unsigned tick, LMASTER_LVTYPE t); void initShortcuts(); QLineEdit* editor; -- cgit v1.2.3