From 3b3613760330e982780d3fafeda6657b679df029 Mon Sep 17 00:00:00 2001 From: Werner Schweer Date: Fri, 12 May 2006 13:26:46 +0000 Subject: add templatedialog --- muse/muse/CMakeLists.txt | 3 +- muse/muse/conf.cpp | 3 + muse/muse/gconfig.cpp | 1 + muse/muse/gconfig.h | 1 + muse/muse/muse.cpp | 68 ++++++++++++- muse/muse/preferences.cpp | 2 + muse/muse/preferences.ui | 50 ++++++---- muse/muse/song.cpp | 29 +----- muse/muse/song.h | 1 - muse/muse/templatedialog.cpp | 233 +++++++++++++++++++++++++++++++++++++++++++ muse/muse/templatedialog.h | 50 ++++++++++ muse/muse/templatedialog.ui | 188 ++++++++++++++++++++++++++++++++++ muse/muse/track.cpp | 8 +- muse/muse/transport.cpp | 2 +- muse/muse/wavetrack.cpp | 2 +- 15 files changed, 584 insertions(+), 57 deletions(-) create mode 100644 muse/muse/templatedialog.cpp create mode 100644 muse/muse/templatedialog.h create mode 100644 muse/muse/templatedialog.ui diff --git a/muse/muse/CMakeLists.txt b/muse/muse/CMakeLists.txt index 438d22f1..88deda29 100644 --- a/muse/muse/CMakeLists.txt +++ b/muse/muse/CMakeLists.txt @@ -48,13 +48,14 @@ set (muse_uics muse preferences exportmididialog configmidifile transport aboutbox transpose projectdialog + templatedialog midiedit/quantconfig mixer/routedialog arranger/configtrack ) set(muse_mocs - projectdialog preferences plugingui midiplugin muse + projectdialog templatedialog preferences plugingui midiplugin muse song transport conf editor cobject transpose track midisynti midiport miditrack wavetrack audiotrack audioaux audiooutput diff --git a/muse/muse/conf.cpp b/muse/muse/conf.cpp index ca8064f7..0ba0119e 100644 --- a/muse/muse/conf.cpp +++ b/muse/muse/conf.cpp @@ -267,6 +267,8 @@ void readConfiguration(QDomNode node) config.createDefaultMidiInput = i; else if (tag == "projectPath") config.projectPath = s; + else if (tag == "templatePath") + config.templatePath = s; else if (tag == "PianoRoll") PianoRoll::readConfiguration(node); else if (tag == "DrumEdit") @@ -485,6 +487,7 @@ void MusE::writeGlobalConfiguration(Xml& xml) const xml.intTag("connectToAllMidiTracks", config.connectToAllMidiTracks); xml.intTag("createDefaultMidiInput", config.createDefaultMidiInput); xml.strTag("projectPath", config.projectPath); + xml.strTag("templatePath", config.templatePath); PianoRoll::writeConfiguration(xml); DrumEdit::writeConfiguration(xml); diff --git a/muse/muse/gconfig.cpp b/muse/muse/gconfig.cpp index 37534203..7a90489c 100644 --- a/muse/muse/gconfig.cpp +++ b/muse/muse/gconfig.cpp @@ -136,5 +136,6 @@ GlobalConfigValues config = { true, // connectToAllMidiTracks true, // createDefaultMidiInput QString("MusE/projects"), // projectPath + QString("MusE/templates"), // templatePath }; diff --git a/muse/muse/gconfig.h b/muse/muse/gconfig.h index 8bfed74b..d35ba0f9 100644 --- a/muse/muse/gconfig.h +++ b/muse/muse/gconfig.h @@ -124,6 +124,7 @@ struct GlobalConfigValues { bool connectToAllMidiTracks; bool createDefaultMidiInput; QString projectPath; + QString templatePath; }; extern GlobalConfigValues config; diff --git a/muse/muse/muse.cpp b/muse/muse/muse.cpp index 26da3c8c..9e67f104 100644 --- a/muse/muse/muse.cpp +++ b/muse/muse/muse.cpp @@ -60,6 +60,7 @@ #include "instruments/editinstrument.h" #include "part.h" #include "projectdialog.h" +#include "templatedialog.h" static pthread_t watchdogThread; @@ -1104,6 +1105,9 @@ void MusE::loadProject1(const QString& path) return; } } + // + // close all toplevel windows + // foreach(QWidget* w, QApplication::topLevelWidgets()) { if (!w->isVisible()) continue; @@ -1120,7 +1124,33 @@ void MusE::loadProject1(const QString& path) } emit startLoadSong(); song->setProjectPath(path); - song->load(); + song->clear(false); + + QString s = pd.absoluteFilePath(path + "/" + name + ".med"); + QFile f(s); + + bool rv = true; + if (f.open(QIODevice::ReadOnly)) { + rv = song->read(&f); + f.close(); + } + else { + TemplateDialog templateDialog; + if (templateDialog.exec() == 1) { + QString path = templateDialog.templatePath(); + if (!path.isEmpty()) { + QFile f(path); + if (f.open(QIODevice::ReadOnly)) { + rv = song->read(&f); + f.close(); + } + } + } + } + if (!rv) { + QMessageBox::critical(this, QString("MusE"), + tr("File read error")); + } tr_id->setChecked(config.transportVisible); bt_id->setChecked(config.bigTimeVisible); @@ -2858,17 +2888,19 @@ int main(int argc, char* argv[]) // load project //--------------------------------------------------- - // first check if there is a project directory: + // check if there is a project directory: QDir pd(QDir::homePath() + "/" + config.projectPath); if (!pd.exists()) { // ask user to create a new project directory + QString title(muse->tr("MusE: create project directory")); + QString s; s = "The MusE project directory\n%1\ndoes not exists"; s = s.arg(pd.path()); int rv = QMessageBox::question(0, - "MusE: create project directory", + title, s, "Create", "Abort", @@ -2879,12 +2911,40 @@ int main(int argc, char* argv[]) if (!pd.mkpath(pd.path())) { // TODO: tell user why this has happened QMessageBox::critical(0, - "MusE: create project directory", + title, "Creating project directory failed"); exit(-1); } } + // check if there is a template directory: + + pd.setPath(QDir::homePath() + "/" + config.templatePath); + if (!pd.exists()) { + // ask user to create a new template directory + QString title(muse->tr("MusE: create template directory")); + + QString s; + s = "The MusE template directory\n%1\ndoes not exists"; + s = s.arg(pd.path()); + + int rv = QMessageBox::question(0, + title, + s, + "Create", + "Abort", + QString(), + 0, 1); + if (rv == 0) { + if (!pd.mkpath(pd.path())) { + // TODO: tell user why this has happened + QMessageBox::critical(0, + title, + "Creating template directory failed"); + } + } + } + QString path; // project path relativ to config.projectPath if (argc >= 2) path = argv[optind]; // start with first name on command line diff --git a/muse/muse/preferences.cpp b/muse/muse/preferences.cpp index f8b838cd..7efd6751 100644 --- a/muse/muse/preferences.cpp +++ b/muse/muse/preferences.cpp @@ -341,6 +341,7 @@ PreferencesDialog::PreferencesDialog(Arranger* a, QWidget* parent) freewheelMode->setChecked(config->useJackFreewheelMode); showSplash->setChecked(config->showSplashScreen); projectPath->setText(config->projectPath); + templatePath->setText(config->templatePath); stopActive->setChecked(midiRCList.isActive(RC_STOP)); playActive->setChecked(midiRCList.isActive(RC_PLAY)); @@ -595,6 +596,7 @@ void PreferencesDialog::apply() ::config.showSplashScreen = showSplash->isChecked(); ::config.projectPath = projectPath->text(); + ::config.templatePath = templatePath->text(); PianoRoll::initWidth = pianorollWidth->value(); PianoRoll::initHeight = pianorollHeight->value(); diff --git a/muse/muse/preferences.ui b/muse/muse/preferences.ui index cb7e2db4..116fb3e7 100644 --- a/muse/muse/preferences.ui +++ b/muse/muse/preferences.ui @@ -9,7 +9,7 @@ 0 0 731 - 602 + 713 @@ -117,24 +117,34 @@ - Path + Local Paths - + 9 6 - - + + + + + + + + - Project Path + Templates - - + + + + Projects + + @@ -2307,30 +2317,30 @@ - GreendotButton - QToolButton -
greendotbutton.h
+ QuantCombo + QComboBox +
quantcombo.h
0
- RasterCombo - QComboBox -
rastercombo.h
+ RecordButton + QToolButton +
recordbutton.h
0
- QuantCombo - QComboBox -
quantcombo.h
+ GreendotButton + QToolButton +
greendotbutton.h
0
- RecordButton - QToolButton -
recordbutton.h
+ RasterCombo + QComboBox +
rastercombo.h
0
diff --git a/muse/muse/song.cpp b/muse/muse/song.cpp index 35e277ae..0832e054 100644 --- a/muse/muse/song.cpp +++ b/muse/muse/song.cpp @@ -2392,31 +2392,9 @@ void Song::setProjectPath(const QString& s) _projectPath = s; } -//--------------------------------------------------------- -// load -//--------------------------------------------------------- - -void Song::load() - { - clear(false); - - QString s = absoluteProjectPath() + "/" + projectName() + ".med"; - - QFile f(s); - if (f.open(QIODevice::ReadOnly)) { - int rv = read(&f); - f.close(); - if (rv) { - QMessageBox::critical(0, QString("MusE"), - tr("File read error")); - return; - } - } - dirty = false; - } - //--------------------------------------------------------- // read +// return false on error //--------------------------------------------------------- bool Song::read(QFile* qf) @@ -2431,7 +2409,7 @@ bool Song::read(QFile* qf) ln.setNum(line); error = err + "\n at line: " + ln + " col: " + col; printf("error reading med file: %s\n", error.toLatin1().data()); - return true; + return false; } for (QDomNode node = doc.documentElement(); !node.isNull(); node = node.nextSibling()) { QDomElement e = node.toElement(); @@ -2452,7 +2430,8 @@ bool Song::read(QFile* qf) else printf("MusE: %s not supported\n", e.tagName().toLatin1().data()); } - return false; + dirty = false; + return true; } //--------------------------------------------------------- diff --git a/muse/muse/song.h b/muse/muse/song.h index 1338de13..f7322c7f 100644 --- a/muse/muse/song.h +++ b/muse/muse/song.h @@ -402,7 +402,6 @@ class Song : public QObject { QString comment() const { return _comment; } void setComment(const QString& s) { _comment = s; } - void load(); bool read(QFile* qf); void read20(QDomNode node); void read10(QDomNode); diff --git a/muse/muse/templatedialog.cpp b/muse/muse/templatedialog.cpp new file mode 100644 index 00000000..3e72fdf8 --- /dev/null +++ b/muse/muse/templatedialog.cpp @@ -0,0 +1,233 @@ +//============================================================================= +// MusE +// Linux Music Editor +// $Id:$ +// +// Copyright (C) 2002-2006 by Werner Schweer and others +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//============================================================================= + +#include "templatedialog.h" +#include "gconfig.h" +#include "song.h" +#include "icons.h" + +// +// entry types for templateTree tree widget: +// +enum { DIR_TYPE, TEMPLATE_TYPE }; + +//--------------------------------------------------------- +// processSubdir +//--------------------------------------------------------- + +void TemplateDialog::processSubdir(QTreeWidgetItem* item, const QString& p, + const QString& subdir) + { + QDir pd(p + "/" + subdir); + pd.setFilter(QDir::Files | QDir::AllDirs | QDir::NoDotAndDotDot); + pd.setNameFilters(QStringList("*.med")); + QFileInfoList el = pd.entryInfoList(); + foreach (QFileInfo s, el) { + QTreeWidgetItem* pi; + if (s.isDir()) { + pi = new QTreeWidgetItem(item, DIR_TYPE); + pi->setIcon(0, style()->standardIcon(QStyle::SP_FileIcon)); + itemCollapsed(pi); + processSubdir(pi, pd.absolutePath(), s.fileName()); + } + else { + pi = new QTreeWidgetItem(item, TEMPLATE_TYPE); + pi->setIcon(0, style()->standardIcon(QStyle::SP_FileIcon)); + } + pi->setText(0, s.fileName()); + } + } + +//--------------------------------------------------------- +// TemplateDialog +//--------------------------------------------------------- + +TemplateDialog::TemplateDialog(QWidget* parent) + : QDialog(parent) + { + setupUi(this); + templateTree->setSelectionBehavior(QAbstractItemView::SelectRows); + templateTree->setSelectionMode(QAbstractItemView::SingleSelection); + + QDir pd(QDir::homePath() + "/" + config.templatePath); + pd.setFilter(QDir::Files | QDir::AllDirs | QDir::NoDotAndDotDot); + pd.setNameFilters(QStringList("*.med")); + QFileInfoList el = pd.entryInfoList(); + foreach (QFileInfo s, el) { + QTreeWidgetItem* pi; + + if (s.isDir()) { + pi = new QTreeWidgetItem(templateTree, DIR_TYPE); + pi->setIcon(0, style()->standardIcon(QStyle::SP_FileIcon)); + itemCollapsed(pi); + processSubdir(pi, pd.absolutePath(), s.fileName()); + } + else { + pi = new QTreeWidgetItem(templateTree, TEMPLATE_TYPE); + pi->setIcon(0, style()->standardIcon(QStyle::SP_FileIcon)); + } + pi->setText(0, s.fileName()); + } + connect(templateTree, + SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), + SLOT(currentChanged(QTreeWidgetItem*, QTreeWidgetItem*))); + connect(templateTree, + SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), + SLOT(itemDoubleClicked(QTreeWidgetItem*, int))); + connect(templateTree, + SIGNAL(itemCollapsed(QTreeWidgetItem*)), + SLOT(itemCollapsed(QTreeWidgetItem*))); + connect(templateTree, + SIGNAL(itemExpanded(QTreeWidgetItem*)), + SLOT(itemExpanded(QTreeWidgetItem*))); + + currentChanged(0, 0); + } + +//--------------------------------------------------------- +// itemCollapsed +//--------------------------------------------------------- + +void TemplateDialog::itemCollapsed(QTreeWidgetItem* item) + { + item->setIcon(0, style()->standardIcon(QStyle::SP_DirClosedIcon)); + } + +//--------------------------------------------------------- +// itemExpanded +//--------------------------------------------------------- + +void TemplateDialog::itemExpanded(QTreeWidgetItem* item) + { + item->setIcon(0, style()->standardIcon(QStyle::SP_DirOpenIcon)); + } + +//--------------------------------------------------------- +// itemPath +//--------------------------------------------------------- + +QString TemplateDialog::itemPath(QTreeWidgetItem* item) const + { + QString path; + QTreeWidgetItem* ti = item; + QStringList dirComponent; + do { + dirComponent.prepend(ti->text(0)); + ti = ti->parent(); + } while (ti); + foreach (QString s, dirComponent) { + if (!path.isEmpty()) + path += "/"; + path += s; + } + return path; + } + +//--------------------------------------------------------- +// currentChanged +//--------------------------------------------------------- + +void TemplateDialog::currentChanged(QTreeWidgetItem* item, QTreeWidgetItem*) + { + bool enable = (item != 0) && (item->type() == TEMPLATE_TYPE); + createdDate->setEnabled(enable); + modifiedDate->setEnabled(enable); + comment->setEnabled(enable); + + // newFolder->setEnabled(item == 0 || item->type() == DIR_TYPE); + if (!enable) + return; + + QString pd(QDir::homePath() + "/" + config.templatePath + "/"); + + pd += "/" + itemPath(item); + + QFileInfo pf(pd + "/" + item->text(0) + ".med"); + createdDate->setDateTime(pf.created()); + modifiedDate->setDateTime(pf.lastModified()); + + QTime time(0, 0, 0); + + QFile f(pf.filePath()); + QDomDocument doc; + int line, column; + QString err; + if (!doc.setContent(&f, false, &err, &line, &column)) { + QString col, ln, error; + col.setNum(column); + ln.setNum(line); + error = err + "\n at line: " + ln + " col: " + col; + printf("error reading med file: %s\n", error.toLatin1().data()); + return; + } + for (QDomNode node = doc.documentElement(); !node.isNull(); node = node.nextSibling()) { + QDomElement e = node.toElement(); + if (e.isNull()) + continue; + if (e.tagName() == "muse") { + QString sversion = e.attribute("version", "1.0"); + int major=0, minor=0; + sscanf(sversion.toLatin1().data(), "%d.%d", &major, &minor); + int version = major << 8 + minor; + if (version >= 0x200) { + for (QDomNode n1 = node.firstChild(); !n1.isNull(); n1 = n1.nextSibling()) { + QDomElement e = n1.toElement(); + if (e.tagName() == "song") { + for (QDomNode n2 = n1.firstChild(); !n2.isNull(); n2 = n2.nextSibling()) { + QDomElement e = n2.toElement(); + QString tag(e.tagName()); + QString s(e.text()); + if (tag == "comment") + comment->setPlainText(s); + else if (tag == "LenInSec") { + int sec = s.toInt(); + time = time.addSecs(sec); + } + } + } + } + } + } + } + } + +//--------------------------------------------------------- +// templatePath +//--------------------------------------------------------- + +QString TemplateDialog::templatePath() const + { + QTreeWidgetItem* item = templateTree->currentItem(); + QString s; + if (item) + s = itemPath(item); + return s; + } + +//--------------------------------------------------------- +// itemDoubleClicked +//--------------------------------------------------------- + +void TemplateDialog::itemDoubleClicked(QTreeWidgetItem* item, int) + { + if (item->type() == TEMPLATE_TYPE) + accept(); + } + diff --git a/muse/muse/templatedialog.h b/muse/muse/templatedialog.h new file mode 100644 index 00000000..108163d1 --- /dev/null +++ b/muse/muse/templatedialog.h @@ -0,0 +1,50 @@ +//============================================================================= +// MusE +// Linux Music Editor +// $Id:$ +// +// Copyright (C) 2002-2006 by Werner Schweer and others +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//============================================================================= + +#ifndef __TEMPLATE_DIALOG_H__ +#define __TEMPLATE_DIALOG_H__ + +#include "ui_templatedialog.h" + +//--------------------------------------------------------- +// TemplateDialog +//--------------------------------------------------------- + +class TemplateDialog : public QDialog, public Ui_TemplateDialogBase { + Q_OBJECT + + void processSubdir(QTreeWidgetItem*, const QString&, + const QString&); + + QString itemPath(QTreeWidgetItem*) const; + + private slots: + void currentChanged(QTreeWidgetItem*, QTreeWidgetItem*); + void itemCollapsed(QTreeWidgetItem*); + void itemExpanded(QTreeWidgetItem*); + void itemDoubleClicked(QTreeWidgetItem*, int); + + public: + TemplateDialog(QWidget* parent = 0); + QString templatePath() const; + }; + +#endif + diff --git a/muse/muse/templatedialog.ui b/muse/muse/templatedialog.ui new file mode 100644 index 00000000..cbbc295d --- /dev/null +++ b/muse/muse/templatedialog.ui @@ -0,0 +1,188 @@ + + + + + TemplateDialogBase + + + + 0 + 0 + 574 + 385 + + + + MusE: Select Template + + + + 9 + + + 6 + + + + + Properties + + + + 9 + + + 3 + + + + + Qt::NoFocus + + + true + + + + + + + Qt::NoFocus + + + true + + + + + + + Comment: + + + + + + + Modified: + + + + + + + Created: + + + + + + + Qt::NoFocus + + + true + + + + + + + + + + 0 + + + 6 + + + + + Qt::Horizontal + + + + 131 + 31 + + + + + + + + OK + + + true + + + + + + + Cancel + + + + + + + + + + Templates + + + + + + + + + okButton + cancelButton + templateTree + modifiedDate + createdDate + comment + + + + + + + okButton + clicked() + TemplateDialogBase + accept() + + + 278 + 253 + + + 96 + 254 + + + + + cancelButton + clicked() + TemplateDialogBase + reject() + + + 369 + 253 + + + 179 + 282 + + + + + diff --git a/muse/muse/track.cpp b/muse/muse/track.cpp index 0df6ef1b..c8f1f20e 100644 --- a/muse/muse/track.cpp +++ b/muse/muse/track.cpp @@ -205,7 +205,7 @@ void Track::setDefaultName() void Track::dump() const { - printf("Track <%s>: typ %d, parts %ld sel %d\n", + printf("Track <%s>: typ %d, parts %zd sel %d\n", _name.toLatin1().data(), _type, _parts->size(), _selected); } @@ -429,7 +429,7 @@ bool Track::addControllerVal(int id, unsigned time, CVal val) return c->add(time, val); } } - printf("Track::addControllerVal(): id 0x%x not found, listsize %ld\n", + printf("Track::addControllerVal(): id 0x%x not found, listsize %zd\n", id, controller()->size()); return false; } @@ -444,7 +444,7 @@ void Track::removeControllerVal(int id, unsigned time) { iCtrl i = controller()->find(id); if (i == controller()->end()) { - printf("Track::removeControllerVal(): id 0x%x not found, listsize %ld\n", + printf("Track::removeControllerVal(): id 0x%x not found, listsize %zd\n", id, controller()->size()); return; } @@ -873,7 +873,7 @@ int Track::getCtrl(int tick, int ctrl) const ciCtrl cl = _controller.find(ctrl); if (cl == _controller.end()) { if (debugMsg) - printf("getCtrl: controller %d(0x%x) not found %ld\n", + printf("getCtrl: controller %d(0x%x) not found %zd\n", ctrl, ctrl, _controller.size()); return CTRL_VAL_UNKNOWN; } diff --git a/muse/muse/transport.cpp b/muse/muse/transport.cpp index c2c421f9..e54096a4 100644 --- a/muse/muse/transport.cpp +++ b/muse/muse/transport.cpp @@ -167,7 +167,7 @@ void Transport::setLen(const AL::Pos& len) // setTimesig //--------------------------------------------------------- -void Transport::setTimesig(int z, int n) +void Transport::setTimesig(int /*z*/, int /*n*/) { //TD tempo->setTimesig(z, n); } diff --git a/muse/muse/wavetrack.cpp b/muse/muse/wavetrack.cpp index 76d7bdf3..b7a688d3 100644 --- a/muse/muse/wavetrack.cpp +++ b/muse/muse/wavetrack.cpp @@ -321,7 +321,7 @@ void WaveTrack::collectInputData() return; } - unsigned framePos = audio->pos().frame(); +// unsigned framePos = audio->pos().frame(); if (audio->freewheel()) { // when freewheeling, read data direct from file: // TODO: fetchData(framePos, segmentSize, buffer); -- cgit v1.2.3