From 3859b10f9a5eaca7df8f85394756375af0b17a1c Mon Sep 17 00:00:00 2001 From: Orcan Ogetbil Date: Thu, 15 Sep 2011 04:13:10 +0000 Subject: New namespaces and change in default colors. See ChangeLog. --- muse2/muse/arranger/pcanvas.cpp | 108 +++------------------------------------- 1 file changed, 6 insertions(+), 102 deletions(-) (limited to 'muse2/muse/arranger/pcanvas.cpp') diff --git a/muse2/muse/arranger/pcanvas.cpp b/muse2/muse/arranger/pcanvas.cpp index 056dcce7..10cd9735 100644 --- a/muse2/muse/arranger/pcanvas.cpp +++ b/muse2/muse/arranger/pcanvas.cpp @@ -34,7 +34,7 @@ #include #include #include -#include +//#include #include #include @@ -48,7 +48,7 @@ #include "globals.h" #include "icons.h" #include "event.h" -#include "xml.h" +//#include "xml.h" #include "wave.h" #include "audio.h" #include "shortcuts.h" @@ -70,24 +70,7 @@ using std::set; -int get_paste_len(); - -//--------------------------------------------------------- -// colorRect -// paints a rectangular icon with a given color -//--------------------------------------------------------- - -QIcon colorRect(const QColor& color, int width, int height) { - QPainter painter; - QPixmap image(width, height); - painter.begin(&image); - painter.setBrush(color); - QRect rectangle(0, 0, width, height); - painter.drawRect(rectangle); - painter.end(); - QIcon icon(image); - return icon; -} +namespace MusEArranger { //--------------------------------------------------------- // NPart @@ -646,7 +629,7 @@ QMenu* PartCanvas::genItemPopup(MusEWidget::CItem* item) // part color selection for (int i = 0; i < NUM_PARTCOLORS; ++i) { - QAction *act_color = colorPopup->addAction(colorRect(MusEConfig::config.partColors[i], 80, 80), MusEConfig::config.partColorNames[i]); + QAction *act_color = colorPopup->addAction(MusEUtil::colorRect(MusEConfig::config.partColors[i], 80, 80), MusEConfig::config.partColorNames[i]); act_color->setData(20+i); } @@ -2623,7 +2606,7 @@ void PartCanvas::cmd(int cmd) case CMD_PASTE_CLONE_DIALOG: { unsigned temp_begin = AL::sigmap.raster1(song->vcpos(),0); - unsigned temp_end = AL::sigmap.raster2(temp_begin + get_paste_len(), 0); + unsigned temp_end = AL::sigmap.raster2(temp_begin + MusEUtil::get_paste_len(), 0); paste_dialog->raster = temp_end - temp_begin; paste_dialog->clone = (cmd == CMD_PASTE_CLONE_DIALOG); @@ -2805,86 +2788,6 @@ void PartCanvas::copy(PartList* pl) } - -int get_paste_len() -{ - QClipboard* cb = QApplication::clipboard(); - const QMimeData* md = cb->mimeData(QClipboard::Clipboard); - - QString pfx("text/"); - QString mdpl("x-muse-midipartlist"); - QString wvpl("x-muse-wavepartlist"); - QString mxpl("x-muse-mixedpartlist"); - QString txt; - - if(md->hasFormat(pfx + mdpl)) - txt = cb->text(mdpl, QClipboard::Clipboard); - else if(md->hasFormat(pfx + wvpl)) - txt = cb->text(wvpl, QClipboard::Clipboard); - else if(md->hasFormat(pfx + mxpl)) - txt = cb->text(mxpl, QClipboard::Clipboard); - else - return 0; - - - QByteArray ba = txt.toLatin1(); - const char* ptxt = ba.constData(); - Xml xml(ptxt); - bool end = false; - - unsigned begin_tick=-1; //this uses the greatest possible begin_tick - unsigned end_tick=0; - - for (;;) - { - Xml::Token token = xml.parse(); - const QString& tag = xml.s1(); - switch (token) - { - case Xml::Error: - case Xml::End: - end = true; - break; - - case Xml::TagStart: - if (tag == "part") - { - Part* p = 0; - p = readXmlPart(xml, NULL, false, false); - - if (p) - { - if (p->tick() < begin_tick) - begin_tick=p->tick(); - - if (p->endTick() > end_tick) - end_tick=p->endTick(); - - delete p; - } - } - else - xml.unknown("PartCanvas::get_paste_len"); - break; - - case Xml::TagEnd: - break; - - default: - end = true; - break; - } - if(end) - break; - } - - if (begin_tick > end_tick) - return 0; - else - return end_tick - begin_tick; -} - - Undo PartCanvas::pasteAt(const QString& pt, Track* track, unsigned int pos, bool clone, bool toTrack, int* finalPosPtr, set* affected_tracks) { Undo operations; @@ -4046,3 +3949,4 @@ void PartCanvas::endMoveItems(const QPoint& pos, DragType dragtype, int dir) redraw(); } +} // namespace MusEArranger -- cgit v1.2.3 From 663b022ab88acc47a5df898aa8df10d2e6422ba1 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Fri, 16 Sep 2011 14:50:34 +0000 Subject: fixed wrong usages of tr() like: QString::toNumber(num) + ( num > 1 ? tr("parts") : tr("part")) or tr("file ")+ filename +tr(" could not be loaded") and commited scripts to find such errors --- muse2/find_manual_plural.sh | 20 ++++++++++++++++++++ muse2/find_translation_concatenation.sh | 16 ++++++++++++++++ muse2/muse/app.cpp | 8 ++++---- muse2/muse/arranger/pcanvas.cpp | 7 +++---- muse2/muse/importmidi.cpp | 5 ++--- muse2/muse/instruments/editinstrument.cpp | 14 +++++++------- muse2/muse/song.cpp | 3 +-- muse2/muse/widgets/filedialog.cpp | 8 +++----- muse2/muse/widgets/pastedialog.cpp | 4 ++-- muse2/muse/widgets/pasteeventsdialog.cpp | 4 ++-- muse2/muse/widgets/routepopup.cpp | 2 +- muse2/muse/widgets/shortcutcapturedialog.cpp | 2 +- 12 files changed, 62 insertions(+), 31 deletions(-) create mode 100755 muse2/find_manual_plural.sh create mode 100755 muse2/find_translation_concatenation.sh (limited to 'muse2/muse/arranger/pcanvas.cpp') diff --git a/muse2/find_manual_plural.sh b/muse2/find_manual_plural.sh new file mode 100755 index 00000000..3e77f304 --- /dev/null +++ b/muse2/find_manual_plural.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# this script tries to find all "bad" code like +# (number > 1 ? tr ("tracks") : tr("track")) +# that is, all manual plural diversifications +# you should replace them by: +# tr("processed %n track(s)", "", number) +# the "" is a translator comment. you may write what you want +# +# you have to create appropriate translations for this (even for +# english!). linguist will ask you for the singular, plural, +# and in some language even paucal form then. +# +# this script is not perfect. it misses some "bad" things, and +# finds some "good" things. + +{ +find . -iname '*.cpp' -print0 | xargs -0 grep -E '[^:]: *tr *\("[^"]*".*\)' +find . -iname '*.cpp' -print0 | xargs -0 grep -E '\? *tr *\("[^"]*".*\)' +} | sort | uniq diff --git a/muse2/find_translation_concatenation.sh b/muse2/find_translation_concatenation.sh new file mode 100755 index 00000000..644944f1 --- /dev/null +++ b/muse2/find_translation_concatenation.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# this script tries to find all "bad" code like +# tr("the file ") + your_file + tr(" could not be loaded!") +# you should replace it by: +# tr("the file %1 could not be loaded!").arg(your_file) +# +# this script is not perfect. it misses some "bad" things, and +# finds some "good" things. + +{ +find . -iname '*.cpp' -print0 | xargs -0 grep -E 'tr *\("[^"]*" *\) *\+'; +find . -iname '*.cpp' -print0 | xargs -0 grep -E '\+ *tr *\("[^"]*" *\)'; +} | sort | uniq + + diff --git a/muse2/muse/app.cpp b/muse2/muse/app.cpp index 3d52e4f2..7c716464 100644 --- a/muse2/muse/app.cpp +++ b/muse2/muse/app.cpp @@ -1218,7 +1218,7 @@ void MusE::loadProjectFile1(const QString& name, bool songTemplate, bool loadAll } else { QMessageBox::critical(this, QString("MusE"), - tr("Unknown File Format: ") + ex); + tr("Unknown File Format: %1").arg(ex)); setUntitledProject(); } if (!songTemplate) { @@ -1348,7 +1348,7 @@ void MusE::setUntitledProject() QString name("untitled"); MusEGlobal::museProject = "./"; //QFileInfo(name).absolutePath(); project.setFile(name); - setWindowTitle(tr("MusE: Song: ") + project.completeBaseName()); + setWindowTitle(tr("MusE: Song: %1").arg(project.completeBaseName())); } //--------------------------------------------------------- @@ -1756,7 +1756,7 @@ bool MusE::saveAs() ok = save(name, true); if (ok) { project.setFile(name); - setWindowTitle(tr("MusE: Song: ") + project.completeBaseName()); + setWindowTitle(tr("MusE: Song: %1").arg(project.completeBaseName())); addProject(name); } else @@ -2651,7 +2651,7 @@ MusE::lash_idle_cb () int ok = save (ss.toAscii(), false); if (ok) { project.setFile(ss.toAscii()); - setWindowTitle(tr("MusE: Song: ") + project.completeBaseName()); + setWindowTitle(tr("MusE: Song: %1").arg(project.completeBaseName())); addProject(ss.toAscii()); MusEGlobal::museProject = QFileInfo(ss.toAscii()).absolutePath(); } diff --git a/muse2/muse/arranger/pcanvas.cpp b/muse2/muse/arranger/pcanvas.cpp index 10cd9735..9e27ca41 100644 --- a/muse2/muse/arranger/pcanvas.cpp +++ b/muse2/muse/arranger/pcanvas.cpp @@ -771,7 +771,7 @@ void PartCanvas::itemPopup(MusEWidget::CItem* item, int n, const QPoint& pt) { Part* p = item->part(); EventList* el = p->events(); - QString str = tr("Part name") + ": " + p->name() + "\n" + tr("Files") + ":"; + QString str = tr("Part name: %1\nFiles:").arg(p->name()); for (iEvent e = el->begin(); e != el->end(); ++e) { Event event = e->second; @@ -2861,9 +2861,8 @@ Undo PartCanvas::pasteAt(const QString& pt, Track* track, unsigned int pos, bool { int tot = notDone + done; QMessageBox::critical(this, QString("MusE"), - QString().setNum(notDone) + (tot > 1 ? (tr(" out of ") + QString().setNum(tot)) : QString("")) + - (tot > 1 ? tr(" parts") : tr(" part")) + - tr(" could not be pasted.\nLikely the selected track is the wrong type.")); + (tot > 1 ? tr("%n part(s) out of %1 could not be pasted.\nLikely the selected track is the wrong type.","",notDone).arg(tot) + : tr("%n part(s) could not be pasted.\nLikely the selected track is the wrong type.","",notDone))); } if (finalPosPtr) *finalPosPtr=finalPos; diff --git a/muse2/muse/importmidi.cpp b/muse2/muse/importmidi.cpp index fd690671..558ffb69 100644 --- a/muse2/muse/importmidi.cpp +++ b/muse2/muse/importmidi.cpp @@ -618,9 +618,8 @@ void MusE::importPartToTrack(QString& filename, unsigned tick, Track* track) { int tot = notDone + done; QMessageBox::critical(this, QString("MusE"), - QString().setNum(notDone) + (tot > 1 ? (tr(" out of ") + QString().setNum(tot)) : QString("")) + - (tot > 1 ? tr(" parts") : tr(" part")) + - tr(" could not be imported.\nLikely the track is the wrong type.")); + (tot > 1 ? tr("%n part(s) out of %1 could not be imported.\nLikely the selected track is the wrong type.","",notDone).arg(tot) + : tr("%n part(s) could not be imported.\nLikely the selected track is the wrong type.","",notDone))); } return; diff --git a/muse2/muse/instruments/editinstrument.cpp b/muse2/muse/instruments/editinstrument.cpp index 49bdd6c2..e1639d04 100644 --- a/muse2/muse/instruments/editinstrument.cpp +++ b/muse2/muse/instruments/editinstrument.cpp @@ -408,7 +408,7 @@ void EditInstrument::saveAs() { if(QMessageBox::question(this, tr("MusE:"), - tr("The user instrument directory\n") + MusEGlobal::museUserInstruments + tr("\ndoes not exist yet. Create it now?\n") + + tr("The user instrument directory\n%1\ndoes not exist yet. Create it now?\n").arg(MusEGlobal::museUserInstruments) + tr("(You can change the user instruments directory at Settings->Global Settings->Midi)"), QMessageBox::Ok | QMessageBox::Default, QMessageBox::Cancel | QMessageBox::Escape, @@ -419,7 +419,7 @@ void EditInstrument::saveAs() else { printf("Unable to create user instrument directory: %s\n", MusEGlobal::museUserInstruments.toLatin1().constData()); - QMessageBox::critical(this, tr("MusE:"), tr("Unable to create user instrument directory\n") + MusEGlobal::museUserInstruments); + QMessageBox::critical(this, tr("MusE:"), tr("Unable to create user instrument directory '%1'").arg(MusEGlobal::museUserInstruments)); //return; path = MusEGlobal::museUser; } @@ -610,7 +610,7 @@ void EditInstrument::fileSaveAs() // Can not have two user files containing the same instrument name. if(QMessageBox::question(this, tr("MusE: Save instrument as"), - tr("The user instrument:\n") + s + tr("\nalready exists. This will overwrite its .idf instrument file.\nAre you sure?"), + tr("The user instrument '%1' already exists. This will overwrite its .idf instrument file.\nAre you sure?").arg(s), QMessageBox::Ok | QMessageBox::Default, QMessageBox::Cancel | QMessageBox::Escape, Qt::NoButton) == QMessageBox::Ok) @@ -700,7 +700,7 @@ void EditInstrument::fileSaveAs() { if(QMessageBox::question(this, tr("MusE:"), - tr("The user instrument directory\n") + MusEGlobal::museUserInstruments + tr("\ndoes not exist yet. Create it now?\n") + + tr("The user instrument directory\n%1\ndoes not exist yet. Create it now?\n").arg(MusEGlobal::museUserInstruments) + tr("(You can change the user instruments directory at Settings->Global Settings->Midi)"), QMessageBox::Ok | QMessageBox::Default, QMessageBox::Cancel | QMessageBox::Escape, @@ -711,7 +711,7 @@ void EditInstrument::fileSaveAs() else { printf("Unable to create user instrument directory: %s\n", MusEGlobal::museUserInstruments.toLatin1().constData()); - QMessageBox::critical(this, tr("MusE:"), tr("Unable to create user instrument directory\n") + MusEGlobal::museUserInstruments); + QMessageBox::critical(this, tr("MusE:"), tr("Unable to create user instrument directory '%1'").arg(MusEGlobal::museUserInstruments)); //return; path = MusEGlobal::museUser; } @@ -3111,7 +3111,7 @@ void EditInstrument::addControllerClicked() { QMessageBox::critical(this, tr("MusE: Cannot add common controller"), - tr("A controller named ") + name + tr(" already exists."), + tr("A controller named '%1' already exists.").arg(name), QMessageBox::Ok, Qt::NoButton, Qt::NoButton); @@ -3123,7 +3123,7 @@ void EditInstrument::addControllerClicked() { QMessageBox::critical(this, tr("MusE: Cannot add common controller"), - tr("A controller number ") + QString().setNum(num) + tr(" already exists."), + tr("A controller number %1 already exists.").arg(num), QMessageBox::Ok, Qt::NoButton, Qt::NoButton); diff --git a/muse2/muse/song.cpp b/muse2/muse/song.cpp index 7adc37f3..29ed7023 100644 --- a/muse2/muse/song.cpp +++ b/muse2/muse/song.cpp @@ -3804,8 +3804,7 @@ void Song::executeScript(const char* scriptfile, PartList* parts, int quant, boo if (myProcess->exitCode()) { QMessageBox::warning(MusEGlobal::muse, tr("MusE - external script failed"), - tr("MusE was unable to launch the script, error message:\n ")+ QString(errStr) - ); + tr("MusE was unable to launch the script, error message:\n%1").arg(QString(errStr))); endUndo(SC_EVENT_REMOVED); return; } diff --git a/muse2/muse/widgets/filedialog.cpp b/muse2/muse/widgets/filedialog.cpp index 0df0fa7f..4e3c1fb2 100644 --- a/muse2/muse/widgets/filedialog.cpp +++ b/muse2/muse/widgets/filedialog.cpp @@ -78,8 +78,7 @@ static bool testDirCreate(QWidget* parent, const QString& path) { if(QMessageBox::information(parent, QWidget::tr("MusE: get file name"), - QWidget::tr("The directory\n") + path - + QWidget::tr("\ndoes not exist.\nCreate it?"), + QWidget::tr("The directory\n%1\ndoes not exist.\nCreate it?").arg(path), QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok) != QMessageBox::Ok) return true; @@ -483,7 +482,7 @@ FILE* fileOpen(QWidget* parent, QString name, const QString& ext, } if (strcmp(mode,"w") == 0 && overwriteWarning && info.exists()) { - QString s(QWidget::tr("File\n") + name + QWidget::tr("\nexists. Overwrite?")); + QString s(QWidget::tr("File\n%1\nexists. Overwrite?").arg(name)); /* int rv = QMessageBox::warning(parent, QWidget::tr("MusE: write"), @@ -516,8 +515,7 @@ FILE* fileOpen(QWidget* parent, QString name, const QString& ext, fp = fopen(name.toAscii().data(), mode); } if (fp == 0 && !noError) { - QString s(QWidget::tr("Open File\n") + name + QWidget::tr("\nfailed: ") - + QString(strerror(errno))); + QString s(QWidget::tr("Open File\n%1\nfailed: %2").arg(name).arg(strerror(errno))); QMessageBox::critical(parent, QWidget::tr("MusE: Open File"), s); return 0; } diff --git a/muse2/muse/widgets/pastedialog.cpp b/muse2/muse/widgets/pastedialog.cpp index 7c9c2248..bc031b30 100644 --- a/muse2/muse/widgets/pastedialog.cpp +++ b/muse2/muse/widgets/pastedialog.cpp @@ -85,9 +85,9 @@ QString PasteDialog::ticks_to_quarter_string(int ticks) double quarters = (double) ticks/config.division; bool one = ( quarters > 0.995 && quarters < 1.005 ); if (one) - return QString::number(quarters, 'f', 2) + " " + tr("quarter"); + return tr("%1 quarter", "for floating-point arguments like 1.5").arg(quarters, 0, 'f', 2); else - return QString::number(quarters, 'f', 2) + " " + tr("quarters"); + return tr("%1 quarters", "for floating-point arguments like 1.5").arg(quarters, 0, 'f', 2); } } diff --git a/muse2/muse/widgets/pasteeventsdialog.cpp b/muse2/muse/widgets/pasteeventsdialog.cpp index 04b7cbd7..e8436711 100644 --- a/muse2/muse/widgets/pasteeventsdialog.cpp +++ b/muse2/muse/widgets/pasteeventsdialog.cpp @@ -99,9 +99,9 @@ QString PasteEventsDialog::ticks_to_quarter_string(int ticks) double quarters = (double) ticks/config.division; bool one = ( quarters > 0.995 && quarters < 1.005 ); if (one) - return QString::number(quarters, 'f', 2) + " " + tr("quarter"); + return tr("%1 quarter", "for floating-point arguments like 1.5").arg(quarters, 0, 'f', 2); else - return QString::number(quarters, 'f', 2) + " " + tr("quarters"); + return tr("%1 quarters", "for floating-point arguments like 1.5").arg(quarters, 0, 'f', 2); } } diff --git a/muse2/muse/widgets/routepopup.cpp b/muse2/muse/widgets/routepopup.cpp index ec3f3ea0..0336f8ed 100644 --- a/muse2/muse/widgets/routepopup.cpp +++ b/muse2/muse/widgets/routepopup.cpp @@ -1152,7 +1152,7 @@ void RoutePopupMenu::prepare() continue; PopupMenu* subp = new PopupMenu(morep, true); - subp->setTitle(QString("%1:").arg(i) + tr("")); + subp->setTitle(QString("%1:%2").arg(i).arg(tr(""))); // MusE-2: Check this - needed with QMenu? Help says no. No - verified, it actually causes double triggers! //connect(subp, SIGNAL(triggered(QAction*)), pup, SIGNAL(triggered(QAction*))); diff --git a/muse2/muse/widgets/shortcutcapturedialog.cpp b/muse2/muse/widgets/shortcutcapturedialog.cpp index a470d698..26526f1e 100644 --- a/muse2/muse/widgets/shortcutcapturedialog.cpp +++ b/muse2/muse/widgets/shortcutcapturedialog.cpp @@ -105,7 +105,7 @@ void ShortcutCaptureDialog::keyPressEvent(QKeyEvent* e) (( shortcuts[i].type & (shortcuts[shortcutindex].type | INVIS_SHRT)) || shortcuts[i].type & GLOBAL_SHRT || shortcuts[shortcutindex].type & GLOBAL_SHRT)) { // affect the same scope - msgString = tr("Shortcut conflicts with ") + QString(shortcuts[i].descr); + msgString = tr("Shortcut conflicts with %1").arg(shortcuts[i].descr); conflict = true; break; } -- cgit v1.2.3 From 030457faadce72a099193617237d5b7dcc792c87 Mon Sep 17 00:00:00 2001 From: "Tim E. Real" Date: Sat, 17 Sep 2011 08:35:55 +0000 Subject: Fixed errors when ladspa plugins not found while loading. Fixed forgotten bool to pointer conversion in some calls to song::addTrack, createSynthI. --- muse2/ChangeLog | 3 ++ muse2/muse/arranger/pcanvas.cpp | 6 ++-- muse2/muse/confmport.cpp | 2 +- muse2/muse/plugin.cpp | 67 +++++++++++++++++++++++++++-------------- muse2/muse/remote/pyapi.cpp | 2 +- 5 files changed, 53 insertions(+), 27 deletions(-) (limited to 'muse2/muse/arranger/pcanvas.cpp') diff --git a/muse2/ChangeLog b/muse2/ChangeLog index 960d558f..6674512d 100644 --- a/muse2/ChangeLog +++ b/muse2/ChangeLog @@ -1,3 +1,6 @@ +16.09.2011: + - Fixed errors when ladspa plugins not found while loading. (Tim) + - Fixed forgotten bool to pointer conversion in some calls to song::addTrack, createSynthI. (Tim) 14.09.2011: - added sane configuration defaults to muse (flo93) - several minor fixes (flo93) diff --git a/muse2/muse/arranger/pcanvas.cpp b/muse2/muse/arranger/pcanvas.cpp index 9e27ca41..d6ae1300 100644 --- a/muse2/muse/arranger/pcanvas.cpp +++ b/muse2/muse/arranger/pcanvas.cpp @@ -332,7 +332,7 @@ UndoOp PartCanvas::moveItem(MusEWidget::CItem* item, const QPoint& newpos, DragT ntrack = tracks->size(); if (MusEGlobal::debugMsg) printf("PartCanvas::moveItem - add new track\n"); - Track* newTrack = song->addTrack(type, false); // Add at end of list. + Track* newTrack = song->addTrack(type); // Add at end of list. if (type == Track::WAVE) { WaveTrack* st = (WaveTrack*) track; WaveTrack* dt = (WaveTrack*) newTrack; @@ -3138,9 +3138,9 @@ void PartCanvas::viewDropEvent(QDropEvent* event) if (!track) { // we need to create a track for this drop if (text.endsWith(".mpt", Qt::CaseInsensitive)) { - track = song->addTrack(Track::MIDI, false); // Add at end of list. + track = song->addTrack(Track::MIDI); // Add at end of list. } else { - track = song->addTrack(Track::WAVE, false); // Add at end of list. + track = song->addTrack(Track::WAVE); // Add at end of list. } } if (track->type() == Track::WAVE && diff --git a/muse2/muse/confmport.cpp b/muse2/muse/confmport.cpp index 6e371d0e..724b5a51 100644 --- a/muse2/muse/confmport.cpp +++ b/muse2/muse/confmport.cpp @@ -1341,7 +1341,7 @@ void MPConfig::addInstanceClicked() QTreeWidgetItem* item = synthList->currentItem(); if (item == 0) return; - SynthI *si = song->createSynthI(item->text(0), item->text(2), false); // Add at end of list. + SynthI *si = song->createSynthI(item->text(0), item->text(2)); // Add at end of list. if(!si) return; diff --git a/muse2/muse/plugin.cpp b/muse2/muse/plugin.cpp index e2170ebb..53e3d471 100644 --- a/muse2/muse/plugin.cpp +++ b/muse2/muse/plugin.cpp @@ -2252,22 +2252,25 @@ bool PluginI::loadControl(Xml& xml) // p4.0.23 Special for loader - bypass the ring buffer and store directly, // so that upon the 'gui = 1' tag (show the gui), the gui has immediate // access to the values. - bool found = false; - for(unsigned long i = 0; i < controlPorts; ++i) - { - if(_plugin->portName(controls[i].idx) == name) - { - controls[i].val = controls[i].tmpVal = val; - found = true; - } - } - if(!found) - { - printf("PluginI:loadControl(%s, %f) controller not found\n", - name.toLatin1().constData(), val); - return false; - } - initControlValues = true; + if(_plugin) + { + bool found = false; + for(unsigned long i = 0; i < controlPorts; ++i) + { + if(_plugin->portName(controls[i].idx) == name) + { + controls[i].val = controls[i].tmpVal = val; + found = true; + } + } + if(!found) + { + printf("PluginI:loadControl(%s, %f) controller not found\n", + name.toLatin1().constData(), val); + return false; + } + initControlValues = true; + } } return true; default: @@ -2304,11 +2307,22 @@ bool PluginI::readConfiguration(Xml& xml, bool readPreset) //if (_plugin && initPluginInstance(_plugin, instances)) { // p3.3.41 - if (_plugin && initPluginInstance(_plugin, channel)) { + if (_plugin) + { + if(initPluginInstance(_plugin, channel)) { _plugin = 0; xml.parse1(); - break; + printf("Error initializing plugin instance (%s, %s)\n", + file.toLatin1().constData(), label.toLatin1().constData()); + //break; // Don't break - let it read any control tags. } + } + else + { + //printf("Warning: Plugin not found (%s, %s)\n", + // file.toLatin1().constData(), label.toLatin1().constData()); + //break; // Don't break - let it read any control tags. + } } if (tag == "control") loadControl(xml); @@ -2319,7 +2333,8 @@ bool PluginI::readConfiguration(Xml& xml, bool readPreset) } else if (tag == "gui") { bool flag = xml.parseInt(); - showGui(flag); + if (_plugin) + showGui(flag); } else if (tag == "nativegui") { // We can't tell OSC to show the native plugin gui @@ -2368,12 +2383,20 @@ bool PluginI::readConfiguration(Xml& xml, bool readPreset) if (!readPreset && _plugin == 0) { _plugin = plugins.find(file, label); if (_plugin == 0) - return true; - + { + printf("Warning: Plugin not found (%s, %s)\n", + file.toLatin1().constData(), label.toLatin1().constData()); + return true; + } + //if (initPluginInstance(_plugin, instances)) // p3.3.41 if (initPluginInstance(_plugin, channel)) - return true; + { + printf("Error initializing plugin instance (%s, %s)\n", + file.toLatin1().constData(), label.toLatin1().constData()); + return true; + } } if (_gui) _gui->updateValues(); diff --git a/muse2/muse/remote/pyapi.cpp b/muse2/muse/remote/pyapi.cpp index c9f9470f..27a44e49 100644 --- a/muse2/muse/remote/pyapi.cpp +++ b/muse2/muse/remote/pyapi.cpp @@ -1127,7 +1127,7 @@ bool Song::event(QEvent* _e) break; } case QPybridgeEvent::SONG_ADD_TRACK: - song->addTrack((Track::TrackType)e->getP1(), false); // Add at end of list. + song->addTrack((Track::TrackType)e->getP1()); // Add at end of list. break; case QPybridgeEvent::SONG_CHANGE_TRACKNAME: { Track* t = this->findTrack(e->getS1()); -- cgit v1.2.3 From 6f6c78229e4e1dee80d36c89c27e2e58e23e0eb3 Mon Sep 17 00:00:00 2001 From: "Tim E. Real" Date: Wed, 21 Sep 2011 06:31:12 +0000 Subject: Need to get it off the drive: Part canvas drawing speed boosts. Working on meter speed. --- muse2/ChangeLog | 5 + muse2/muse/arranger/pcanvas.cpp | 80 ++++++---- muse2/muse/arranger/pcanvas.h | 2 +- muse2/muse/song.cpp | 16 ++ muse2/muse/widgets/meter.cpp | 324 +++++++++++++++++++++++++++++++++++++--- muse2/muse/widgets/meter.h | 4 +- 6 files changed, 381 insertions(+), 50 deletions(-) (limited to 'muse2/muse/arranger/pcanvas.cpp') diff --git a/muse2/ChangeLog b/muse2/ChangeLog index 9b42c2ae..f8032198 100644 --- a/muse2/ChangeLog +++ b/muse2/ChangeLog @@ -1,3 +1,8 @@ +21.09.2011: + - Drawing speed boosts in part canvas. TODO Fix slight dashed border shifting. Do 'hidden' polygons (Tim) + - Working on meter speed. WIP. Can enable by commenting out #define _USE_NEW_METERS in meter.cpp (Tim) + Combined with part canvas fixes, meter work so far makes MusE2 near-Muse1 speed when playing big songs + with many active mixer strip meters. 20.09.2011: - Revert the change in coloring of the selected track in tlist. Making full transpaency optional requires more substantial changes. (Orcan) diff --git a/muse2/muse/arranger/pcanvas.cpp b/muse2/muse/arranger/pcanvas.cpp index d6ae1300..0de8d278 100644 --- a/muse2/muse/arranger/pcanvas.cpp +++ b/muse2/muse/arranger/pcanvas.cpp @@ -3,7 +3,7 @@ // Linux Music Editor // $Id: pcanvas.cpp,v 1.48.2.26 2009/11/22 11:08:33 spamatica Exp $ // (C) Copyright 1999 Werner Schweer (ws@seh.de) -// Additions, modifications (C) Copyright 2011 Tim E. Real (terminator356 on users DOT sourceforge DOT net) +// (C) Copyright 2011 Tim E. Real (terminator356 on users DOT sourceforge DOT net) // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -1754,19 +1754,16 @@ void PartCanvas::drawItem(QPainter& p, const MusEWidget::CItem* item, const QRec //QRect rr = p.transform().mapRect(r); // Gives inconsistent positions. Source shows wrong operation for our needs. QRect rr = map(r); // Use our own map instead. + QRect mr = map(rect); + // Item bounding box x is in tick coordinates, same as rectangle. - //if(item->bbox().intersect(rect).isNull()) - //if((item->bbox() & rect).isNull()) - if((rr & map(rect)).isNull()) + if((rr & mr).isNull()) { //printf("PartCanvas::drawItem rectangle is null\n"); return; } - //printf("PartCanvas::drawItem called map rx:%d rw:%d rrx:%d rrw:%d\n", r.x(), r.width(), rr.x(), rr.width()); - //printf("PartCanvas::drawItem called map rx:%d rw:%d\n", r.x(), r.width()); - - p.save(); + //p.save(); p.setWorldMatrixEnabled(false); // NOTE: Optimization: For each item, hasHiddenEvents() is called once in Canvas::draw(), and we use cachedHasHiddenEvents(). @@ -1815,6 +1812,15 @@ void PartCanvas::drawItem(QPainter& p, const MusEWidget::CItem* item, const QRec if(ye_2 < ys_0) ye_2 = ys_0; + int mrxs_0 = mr.x(); + int mrxe_0 = mrxs_0 + mr.width(); + bool lbt = ((NPart*)item)->leftBorderTouches; + bool rbt = ((NPart*)item)->rightBorderTouches; + int lbx = lbt?xs_1:xs_0; + int rbx = rbt?xe_1:xe_0; + int lbx_c = lbx < mrxs_0 ? mrxs_0 : lbx; + int rbx_c = rbx > mrxe_0 ? mrxe_0 : rbx; + int cidx = part->colorIndex(); if (item->isMoving()) { @@ -1873,8 +1879,11 @@ void PartCanvas::drawItem(QPainter& p, const MusEWidget::CItem* item, const QRec p.setBrush(brush); p.setPen(Qt::NoPen); + if(het) { + // TODO: Make this part respect the requested drawing rectangle (rr & mr), for speed ! + pts = 0; if(het == (Part::LeftEventsHidden | Part::RightEventsHidden)) { @@ -1988,7 +1997,8 @@ void PartCanvas::drawItem(QPainter& p, const MusEWidget::CItem* item, const QRec } else { - p.fillRect(rr, brush); + //p.fillRect(rr, brush); + p.fillRect(rr & mr, brush); // Respect the requested drawing rectangle. Gives speed boost! } // Draw a pattern brush on muted parts... @@ -1998,8 +2008,9 @@ void PartCanvas::drawItem(QPainter& p, const MusEWidget::CItem* item, const QRec //brush.setStyle(Qt::DiagCrossPattern); brush.setStyle(Qt::Dense7Pattern); - p.fillRect(rr, brush); // FIXME: Some shifting going on + //p.fillRect(rr, brush); // FIXME: Some shifting going on //p.fillRect(QRect(rr.x(), rr.y(), rr.width() + 1, rr.height() + 1), brush); // Same here + p.fillRect(rr & mr, brush); // Respect the requested drawing rectangle. Gives speed boost! } p.setWorldMatrixEnabled(true); @@ -2035,7 +2046,10 @@ void PartCanvas::drawItem(QPainter& p, const MusEWidget::CItem* item, const QRec p.setBrush(Qt::NoBrush); p.drawRect(r); - #else + //#else + #endif + + #if 1 // // Now draw the borders, using custom segments... // @@ -2089,18 +2103,20 @@ void PartCanvas::drawItem(QPainter& p, const MusEWidget::CItem* item, const QRec penSelect2V.setDashOffset(1.0); penNormal2V.setDashOffset(1.0); //penHidden2.setDashPattern(customDashPattern); + + // FIXME: Some shifting still going on. Values likely not quite right here. + int xdiff = mrxs_0 - lbx; + if(xdiff > 0) + { + int doff = xdiff % 10; + penSelect1H.setDashOffset(doff); + penNormal1H.setDashOffset(doff); + doff = xdiff % 5; + penSelect2H.setDashOffset(doff); + penNormal2H.setDashOffset(doff); + } } - bool lbt = ((NPart*)item)->leftBorderTouches; - bool rbt = ((NPart*)item)->rightBorderTouches; - - QLine l1(lbt?xs_1:xs_0, ys_0, rbt?xe_1:xe_0, ys_0); // Top - //QLine l2(rbt?xe_1:xe_0, rbt?ys_1:ys_2, rbt?xe_1:xe_0, rbt?ye_1:ye_2); // Right - QLine l2(rbt?xe_1:xe_0, ys_0, rbt?xe_1:xe_0, ye_0); // Right - QLine l3(lbt?xs_1:xs_0, ye_0, rbt?xe_1:xe_0, ye_0); // Bottom - //QLine l4(xs_0, lbt?ys_1:ys_2, xs_0, lbt?ye_1:ye_2); // Left - QLine l4(xs_0, ys_0, xs_0, ye_0); // Left - //if(het & Part::RightEventsHidden) // p.setPen(((NPart*)item)->rightBorderTouches ? penHidden1 : penHidden2); //else @@ -2110,7 +2126,12 @@ void PartCanvas::drawItem(QPainter& p, const MusEWidget::CItem* item, const QRec else p.setPen(part->selected() ? penSelect2V : penNormal2V); } - p.drawLine(l2); // Right line + + if(rbx >= mrxs_0 && rbx <= mrxe_0) // Respect the requested drawing rectangle. Gives speed boost! + { + QLine l2(rbx, ys_0, rbx, ye_0); // Right + p.drawLine(l2); // Right line + } /* int xx = rbt?xe_1:xe_0; @@ -2138,7 +2159,12 @@ void PartCanvas::drawItem(QPainter& p, const MusEWidget::CItem* item, const QRec else p.setPen(part->selected() ? penSelect2V : penNormal2V); } - p.drawLine(l4); // Left line + + if(xs_0 >= mrxs_0 && xs_0 <= mrxe_0) + { + QLine l4(xs_0, ys_0, xs_0, ye_0); // Left + p.drawLine(l4); // Left line + } /* xx = xs_0; @@ -2158,7 +2184,11 @@ void PartCanvas::drawItem(QPainter& p, const MusEWidget::CItem* item, const QRec */ p.setPen(part->selected() ? penSelect2H : penNormal2H); + + // Respect the requested drawing rectangle. Gives speed boost! + QLine l1(lbx_c, ys_0, rbx_c, ys_0); p.drawLine(l1); // Top line + QLine l3(lbx_c, ye_0, rbx_c, ye_0); p.drawLine(l3); // Bottom line #endif @@ -2189,8 +2219,8 @@ void PartCanvas::drawItem(QPainter& p, const MusEWidget::CItem* item, const QRec p.drawText(tr, Qt::AlignBottom|Qt::AlignLeft, part->name()); } - p.restore(); - //p.setWorldMatrixEnabled(true); + //p.restore(); + p.setWorldMatrixEnabled(true); } //--------------------------------------------------------- diff --git a/muse2/muse/arranger/pcanvas.h b/muse2/muse/arranger/pcanvas.h index 7eec87c6..3e320e56 100644 --- a/muse2/muse/arranger/pcanvas.h +++ b/muse2/muse/arranger/pcanvas.h @@ -3,7 +3,7 @@ // Linux Music Editor // $Id: pcanvas.h,v 1.11.2.4 2009/05/24 21:43:44 terminator356 Exp $ // (C) Copyright 1999 Werner Schweer (ws@seh.de) -// Additions, modifications (C) Copyright 2011 Tim E. Real (terminator356 on users DOT sourceforge DOT net) +// (C) Copyright 2011 Tim E. Real (terminator356 on users DOT sourceforge DOT net) // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License diff --git a/muse2/muse/song.cpp b/muse2/muse/song.cpp index 29ed7023..6a43e457 100644 --- a/muse2/muse/song.cpp +++ b/muse2/muse/song.cpp @@ -61,6 +61,7 @@ #include "al/sig.h" #include "keyevent.h" #include +//#include "utils.h" extern void clearMidiTransforms(); extern void clearMidiInputTransforms(); @@ -1700,6 +1701,21 @@ void Song::setMType(MType t) void Song::beat() { + #if 0 + static double _heartbeatRateTimer = 0.0; + double t = MusEUtil::curTime(); + if(t - _heartbeatRateTimer > 0.0) + { + double rate = 1/ (t - _heartbeatRateTimer); + printf("heartbeat rate:%f\n", rate); + // Results: Song::beat() is not even called sometimes because apparently all the other + // stuff connected to the heartbeat is taking up all the time before the next timer event - + // apparently Song::beat() is called last, or close to last - after the others. (Possible to choose order?) + // With fancy strip meters active, Song::beat() was quiet for long periods of time! + } + _heartbeatRateTimer = t; + #endif + // Keep the sync detectors running... for(int port = 0; port < MIDI_PORTS; ++port) { diff --git a/muse2/muse/widgets/meter.cpp b/muse2/muse/widgets/meter.cpp index 239f7655..50d265b5 100644 --- a/muse2/muse/widgets/meter.cpp +++ b/muse2/muse/widgets/meter.cpp @@ -6,6 +6,7 @@ // // (C) Copyright 2000 Werner Schweer (ws@seh.de) // (C) Copyright 2011 Orcan Ogetbil (ogetbilo at sf.net) +// (C) Copyright 2011 Tim E. Real (terminator356 on users DOT sourceforge DOT net) // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -34,6 +35,9 @@ #include "gconfig.h" #include "fastlog.h" +// Uncomment to use the new meters. Warning: They are currently very time-consuming and unoptimized. +#define _USE_NEW_METERS 1 + namespace MusEWidget { //--------------------------------------------------------- @@ -49,11 +53,15 @@ Meter::Meter(QWidget* parent, MeterType type) // This is absolutely required for speed! Otherwise painfully slow because we get // full rect paint events even on small scrolls! See help on QPainter::scroll(). // Commented out for now. Orcan 20110911 - //setAttribute(Qt::WA_OpaquePaintEvent); + #ifndef _USE_NEW_METERS + setAttribute(Qt::WA_OpaquePaintEvent); + #endif //setFrameStyle(QFrame::Raised | QFrame::StyledPanel); mtype = type; overflow = false; + cur_yv = -1; // Flag as -1 to initialize in paint. + last_yv = 0; val = 0.0; maxVal = 0.0; minScale = mtype == DBMeter ? MusEConfig::config.minMeter : 0.0; // min value in dB or int @@ -152,8 +160,39 @@ void Meter::setVal(double v, double max, bool ovl) ud = true; } - if(ud) - update(); + if(ud) + { + #ifdef _USE_NEW_METERS + update(); + + #else + double range = maxScale - minScale; + int fw = frameWidth(); + int w = width() - 2*fw; + int h = height() - 2*fw; + + if(mtype == DBMeter) + cur_yv = val == 0 ? h : int(((maxScale - (fast_log10(val) * 20.0)) * h)/range); + else + cur_yv = val == 0 ? h : int(((maxScale - val) * h)/range); + + if(cur_yv > h) cur_yv = h; + + int y1, y2; + if(last_yv < cur_yv) + { + y1 = last_yv; + y2 = cur_yv; + } + else + { + y1 = cur_yv; + y2 = last_yv; + } + last_yv = cur_yv; + update(fw, y1, w, y2); + #endif + } } //--------------------------------------------------------- // resetPeaks @@ -164,7 +203,7 @@ void Meter::resetPeaks() { maxVal = val; overflow = val > 0.0; - update(); + update(); } //--------------------------------------------------------- @@ -175,6 +214,7 @@ void Meter::setRange(double min, double max) { minScale = min; maxScale = max; + cur_yv = -1; // Force re-initialization. update(); } @@ -182,12 +222,14 @@ void Meter::setRange(double min, double max) // paintEvent //--------------------------------------------------------- -void Meter::paintEvent(QPaintEvent* /*ev*/) +void Meter::paintEvent(QPaintEvent* ev) { // TODO: Could make better use of event rectangle, for speed. QPainter p(this); - p.setRenderHint(QPainter::Antialiasing); + #ifdef _USE_NEW_METERS + p.setRenderHint(QPainter::Antialiasing); + #endif double range = maxScale - minScale; @@ -195,22 +237,25 @@ void Meter::paintEvent(QPaintEvent* /*ev*/) int w = width() - 2*fw; int h = height() - 2*fw; - /* - QRect rect = ev->rect(); - int w = rect.width() - 2*fw; - int h = rect.height() - 2*fw; - */ - int yv; - - if(mtype == DBMeter) - yv = val == 0 ? h : int(((maxScale - (fast_log10(val) * 20.0)) * h)/range); - else - yv = val == 0 ? h : int(((maxScale - val) * h)/range); + const QRect& rect = ev->rect(); + //printf("Meter::paintEvent rx:%d ry:%d rw:%d rh:%d w:%d h:%d\n", rect.x(), rect.y(), rect.width(), rect.height(), w, h); + //p.setClipRect(rect); // Nope, didn't help (I think it's already clipped. So check why we bother to do it in View). - if(yv > h) yv = h; + // Initialize. Can't do in ctor, must be done after layouts have been done. Most reliable to do it here. + #ifndef _USE_NEW_METERS + if(cur_yv == -1) + #endif + { + if(mtype == DBMeter) + cur_yv = val == 0 ? h : int(((maxScale - (fast_log10(val) * 20.0)) * h)/range); + else + cur_yv = val == 0 ? h : int(((maxScale - val) * h)/range); + if(cur_yv > h) cur_yv = h; + //last_yv = cur_yv; + } // Draw the red, green, and yellow sections. - drawVU(p, w, h, yv); + drawVU(p, rect, cur_yv); // Draw the peak white line. int ymax; @@ -218,9 +263,13 @@ void Meter::paintEvent(QPaintEvent* /*ev*/) ymax = maxVal == 0 ? 0 : int(((maxScale - (fast_log10(maxVal) * 20.0)) * h)/range); else ymax = maxVal == 0 ? 0 : int(((maxScale - maxVal) * h)/range); - p.setPen(peak_color); - p.drawLine(0, ymax, w, ymax); + if(ymax >= rect.y() && ymax < rect.height()) + { + p.setPen(peak_color); + p.drawLine(0, ymax, w, ymax); + } + #ifdef _USE_NEW_METERS // Draw the transparent layer on top of everything to give a 3d look QPainterPath round_path = MusEUtil::roundedPath(0, 0, w, h, xrad, yrad, @@ -228,6 +277,7 @@ void Meter::paintEvent(QPaintEvent* /*ev*/) maskGrad.setStart(QPointF(0, 0)); maskGrad.setFinalStop(QPointF(w, 0)); p.fillPath(round_path, QBrush(maskGrad)); + #endif } @@ -236,8 +286,17 @@ void Meter::paintEvent(QPaintEvent* /*ev*/) // drawVU //--------------------------------------------------------- -void Meter::drawVU(QPainter& p, int w, int h, int yv) +void Meter::drawVU(QPainter& p, const QRect& rect, int yv) { + int fw = frameWidth(); + int w = width() - 2*fw; + int h = height() - 2*fw; + + // Test OK. We are passed small rectangles on small value changes. + //printf("Meter::drawVU rx:%d ry:%d rw:%d rh:%d w:%d h:%d\n", rect.x(), rect.y(), rect.width(), rect.height(), w, h); + + #ifdef _USE_NEW_METERS + if(mtype == DBMeter) { double range = maxScale - minScale; @@ -373,15 +432,234 @@ void Meter::drawVU(QPainter& p, int w, int h, int yv) } } + + /* WIP... + // TODO: Instead of drawing the whole area, make this respect the requested drawing rectangle, for speed... + // Done. But not correct yet. And could possibly simplify the whole drawing some more... + QRect pr(0, 0, w, 0); + QPainterPath rectp; + rectp.addRect(rect.x(), rect.y(), rect.width(), rect.height()); + if(mtype == DBMeter) + { + double range = maxScale - minScale; + int y1 = int((maxScale - redScale) * h / range); + int y2 = int((maxScale - yellowScale) * h / range); + + darkGradGreen.setStart(QPointF(0, y2)); + darkGradGreen.setFinalStop(QPointF(0, h)); + darkGradYellow.setStart(QPointF(0, y1)); + darkGradYellow.setFinalStop(QPointF(0, y2)); + darkGradRed.setStart(QPointF(0, 0)); + darkGradRed.setFinalStop(QPointF(0, y1)); + + lightGradGreen.setStart(QPointF(0, y2)); + lightGradGreen.setFinalStop(QPointF(0, h)); + lightGradYellow.setStart(QPointF(0, y1)); + lightGradYellow.setFinalStop(QPointF(0, y2)); + lightGradRed.setStart(QPointF(0, 0)); + lightGradRed.setFinalStop(QPointF(0, y1)); + + QPainterPath p_top = MusEUtil::roundedPath(0, 0, w, y1, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight ) ); + + QPainterPath p_bottom = MusEUtil::roundedPath(0, y2, w, h-y2, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::LowerLeft | MusEUtil::LowerRight ) ); + + if(yv < y1) + { + + QPainterPath p_dark_red = MusEUtil::roundedPath(0, 0, w, yv, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight ) ); + p_top = p_top.subtracted(p_dark_red); + + // Red section: + p.fillPath(p_dark_red & rectp, QBrush(darkGradRed)); // dark red + p.fillPath(p_top & rectp, QBrush(lightGradRed)); // light red + + // Yellow section: + pr.setTop(y1); pr.setHeight(y2-y1); + p.fillRect(pr & rect, QBrush(lightGradYellow)); // light yellow + + // Green section: + p.fillPath(p_bottom & rectp, QBrush(lightGradGreen)); // light green + } + else + if(yv < y2) + { + // Red section: + p.fillPath(p_top & rectp, QBrush(darkGradRed)); // dark red + + // Yellow section: + pr.setTop(y1); pr.setHeight(yv-y1); + p.fillRect(pr & rect, QBrush(darkGradYellow)); // dark yellow + pr.setTop(yv); pr.setHeight(y2-yv); + p.fillRect(pr & rect, QBrush(lightGradYellow)); // light yellow + + // Green section: + p.fillPath(p_bottom & rectp, QBrush(lightGradGreen)); // light green + } + else + //if(yv <= y3) + { + QPainterPath p_light_green = MusEUtil::roundedPath(0, yv, w, h-yv, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::LowerLeft | MusEUtil::LowerRight ) ); + p_bottom = p_bottom.subtracted(p_light_green); + + // Red section: + p.fillPath(p_top & rectp, QBrush(darkGradRed)); // dark red + + // Yellow section: + pr.setTop(y1); pr.setHeight(y2-y1); + p.fillRect(pr & rect, QBrush(darkGradYellow)); // dark yellow + + // Green section: + p.fillPath(p_bottom & rectp, QBrush(darkGradGreen)); // dark green + p.fillPath(p_light_green & rectp, QBrush(lightGradGreen)); // light green + } + + pr.setTop(y1); pr.setHeight(1); + p.fillRect(pr & rect, separator_color); + pr.setTop(y2); //pr.setHeight(1); + p.fillRect(pr & rect, separator_color); + + } + else + { + darkGradGreen.setStart(QPointF(0, 0)); + darkGradGreen.setFinalStop(QPointF(0, h)); + + lightGradGreen.setStart(QPointF(0, 0)); + lightGradGreen.setFinalStop(QPointF(0, h)); + + // We need to draw the meter in two parts. The cutoff for upper rectangle can be + // anywhere between yrad and h-yrad. Without loss of generality we pick the lower limit. + int cut = yrad; + + QPainterPath p_top = MusEUtil::roundedPath(0, 0, w, cut, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight ) ); + + QPainterPath p_bottom = MusEUtil::roundedPath(0, cut, w, h-cut, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::LowerLeft | MusEUtil::LowerRight ) ); + + if(yv < cut) + { + + QPainterPath p_dark = MusEUtil::roundedPath(0, 0, w, yv, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::UpperLeft | MusEUtil::UpperRight ) ); + + p_top = p_top.subtracted(p_dark); + + // top section: + p.fillPath(p_dark & rectp, QBrush(darkGradGreen)); // dark green + p.fillPath(p_top & rectp, QBrush(lightGradGreen)); // light green + + // bottom section: + p.fillPath(p_bottom & rectp, QBrush(lightGradGreen)); // light green + } + else + { + QPainterPath p_light = MusEUtil::roundedPath(0, yv, w, h-yv, + xrad, yrad, + (MusEUtil::Corner) (MusEUtil::LowerLeft | MusEUtil::LowerRight ) ); + p_bottom = p_bottom.subtracted(p_light); + + // top section: + p.fillPath(p_top & rectp, QBrush(darkGradGreen)); // dark green + + // bottom section: + p.fillPath(p_bottom & rectp, QBrush(darkGradGreen)); // dark green + p.fillPath(p_light & rectp, QBrush(lightGradGreen)); // light green + } + + } + */ + + #else + + QRect pr(0, 0, w, 0); + if(mtype == DBMeter) + { + double range = maxScale - minScale; + int y1 = int((maxScale - redScale) * h / range); + int y2 = int((maxScale - yellowScale) * h / range); + + if(yv < y1) + { + // Red section: + pr.setTop(0); pr.setHeight(yv); + p.fillRect(pr & rect, QBrush(0x8e0000)); // dark red + pr.setTop(yv); pr.setHeight(y1-yv); + p.fillRect(pr & rect, QBrush(0xff0000)); // light red + + // Yellow section: + pr.setTop(y1); pr.setHeight(y2-y1); + p.fillRect(pr & rect, QBrush(0xffff00)); // light yellow + + // Green section: + pr.setTop(y2); pr.setHeight(h-y2); + p.fillRect(pr & rect, QBrush(0x00ff00)); // light green + } + else + if(yv < y2) + { + // Red section: + pr.setTop(0); pr.setHeight(y1); + p.fillRect(pr & rect, QBrush(0x8e0000)); // dark red + + // Yellow section: + pr.setTop(y1); pr.setHeight(yv-y1); + p.fillRect(pr & rect, QBrush(0x8e8e00)); // dark yellow + pr.setTop(yv); pr.setHeight(y2-yv); + p.fillRect(pr & rect, QBrush(0xffff00)); // light yellow + + // Green section: + pr.setTop(y2); pr.setHeight(h-y2); + p.fillRect(pr & rect, QBrush(0x00ff00)); // light green + } + else + //if(yv <= y3) + { + // Red section: + pr.setTop(0); pr.setHeight(y1); + p.fillRect(pr & rect, QBrush(0x8e0000)); // dark red + + // Yellow section: + pr.setTop(y1); pr.setHeight(y2-y1); + p.fillRect(pr & rect, QBrush(0x8e8e00)); // dark yellow + + // Green section: + pr.setTop(y2); pr.setHeight(yv-y2); + p.fillRect(pr & rect, QBrush(0x007000)); // dark green + pr.setTop(yv); pr.setHeight(h-yv); + p.fillRect(pr & rect, QBrush(0x00ff00)); // light green + } + } + else + { + pr.setTop(0); pr.setHeight(yv); + p.fillRect(pr & rect, QBrush(0x007000)); // dark green + pr.setTop(yv); pr.setHeight(h-yv); + p.fillRect(pr & rect, QBrush(0x00ff00)); // light green + } + + #endif } //--------------------------------------------------------- // resizeEvent //--------------------------------------------------------- - void Meter::resizeEvent(QResizeEvent* /*ev*/) +void Meter::resizeEvent(QResizeEvent* /*ev*/) { + cur_yv = -1; // Force re-initialization. } //--------------------------------------------------------- diff --git a/muse2/muse/widgets/meter.h b/muse2/muse/widgets/meter.h index 06f35ca2..ba816319 100644 --- a/muse2/muse/widgets/meter.h +++ b/muse2/muse/widgets/meter.h @@ -6,6 +6,7 @@ // // (C) Copyright 2000 Werner Schweer (ws@seh.de) // (C) Copyright 2011 Orcan Ogetbil (ogetbilo at sf.net) +// (C) Copyright 2011 Tim E. Real (terminator356 on users DOT sourceforge DOT net) // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -81,8 +82,9 @@ class Meter : public QFrame { double maxVal; double minScale, maxScale; int yellowScale, redScale; + int cur_yv, last_yv; - void drawVU(QPainter& p, int, int, int); + void drawVU(QPainter& p, const QRect&, int); void paintEvent(QPaintEvent*); void resizeEvent(QResizeEvent*); -- cgit v1.2.3