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/ChangeLog | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'muse2/ChangeLog') diff --git a/muse2/ChangeLog b/muse2/ChangeLog index 51ef9e30..960d558f 100644 --- a/muse2/ChangeLog +++ b/muse2/ChangeLog @@ -4,6 +4,13 @@ - added MDI-like and borland-like user interface (flo93) - improved pasting, added dialogs, added "copy in range", changed shortcut keys (flo93) + - New namespaces MusEArranger and MusEMixer. (Orcan) + - Updated default track colors on arranger. Indicate the selected track with a gradient instead of a + separate color. (Orcan) + - moved colorRect() and get_paste_len() into utils.cpp. (Orcan) + - Updated default colors of transport handles, bigtime foreground, waveedit background, track labels. + Made them more pastelish, easier on eyes. (Orcan) + - Made horizontal alignment of meter and slider in mstrip consistent with in astrip. (Orcan) 13.09.2011: *Added: You can now insert new tracks instead of always at the track list end. (Tim) If main menu 'Add track': Inserts before currently selected track, else adds at end. -- 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/ChangeLog') 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 c3085938a1938a07d473807908771a40518df6a4 Mon Sep 17 00:00:00 2001 From: Orcan Ogetbil Date: Sun, 18 Sep 2011 03:08:54 +0000 Subject: Fix minor namespace issue --- muse2/ChangeLog | 2 ++ muse2/muse/osc.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'muse2/ChangeLog') diff --git a/muse2/ChangeLog b/muse2/ChangeLog index 6674512d..610c71e3 100644 --- a/muse2/ChangeLog +++ b/muse2/ChangeLog @@ -1,3 +1,5 @@ +17.09.2011: + - Minor namespace fix in osc.cpp. (Orcan) 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) diff --git a/muse2/muse/osc.cpp b/muse2/muse/osc.cpp index ba0941f9..e7aaa46b 100644 --- a/muse2/muse/osc.cpp +++ b/muse2/muse/osc.cpp @@ -622,7 +622,7 @@ int OscIF::oscUpdate(lo_arg **argv) printf(" _uiOscProgramPath:%s\n", _uiOscProgramPath); printf(" _uiOscControlPath:%s\n",_uiOscControlPath); printf(" _uiOscShowPath:%s\n", _uiOscShowPath); - printf(" museProject:%s\n", museProject.toLatin1().constData()); + printf(" museProject:%s\n", MusEGlobal::museProject.toLatin1().constData()); #endif // Send sample rate. -- cgit v1.2.3 From 279cf178836509085b8cfb1f576f350e9fd28dca Mon Sep 17 00:00:00 2001 From: Orcan Ogetbil Date: Wed, 21 Sep 2011 01:29:34 +0000 Subject: Made the default config file consistent with gconfig.cpp. Reverted the selected track coloring. --- muse2/ChangeLog | 5 +++++ muse2/muse/arranger/tlist.cpp | 11 +++++++++-- muse2/muse/gconfig.cpp | 2 +- muse2/share/templates/MusE.cfg | 38 +++++++++++++++++++------------------- 4 files changed, 34 insertions(+), 22 deletions(-) (limited to 'muse2/ChangeLog') diff --git a/muse2/ChangeLog b/muse2/ChangeLog index 610c71e3..9b42c2ae 100644 --- a/muse2/ChangeLog +++ b/muse2/ChangeLog @@ -1,3 +1,8 @@ +20.09.2011: + - Revert the change in coloring of the selected track in tlist. Making full transpaency optional + requires more substantial changes. (Orcan) + - Update the default config file with the same defaults as in gconfig.cpp. Question: Why do we + have defaults defined in multiple places? (Orcan) 17.09.2011: - Minor namespace fix in osc.cpp. (Orcan) 16.09.2011: diff --git a/muse2/muse/arranger/tlist.cpp b/muse2/muse/arranger/tlist.cpp index 3b219f71..c28a40b2 100644 --- a/muse2/muse/arranger/tlist.cpp +++ b/muse2/muse/arranger/tlist.cpp @@ -193,8 +193,10 @@ void TList::paint(const QRect& r) mask.setColorAt(0, mask_edge); mask.setColorAt(0.15, mask_center); mask.setColorAt(0.3, mask_center); + mask.setColorAt(0.85, mask_edge); mask.setColorAt(1, mask_edge); + TrackList* l = song->tracks(); int idx = 0; int yy = -ypos; @@ -212,7 +214,11 @@ void TList::paint(const QRect& r) // clear one row // QColor bg; - + if (track->selected()) { + bg = MusEConfig::config.selectTrackBg; + p.setPen(MusEConfig::config.selectTrackFg); + } + else { switch(type) { case Track::MIDI: bg = MusEConfig::config.midiTrackBg; @@ -240,7 +246,8 @@ void TList::paint(const QRect& r) break; } - p.setPen(palette().color(QPalette::Active, QPalette::Text)); + p.setPen(palette().color(QPalette::Active, QPalette::Text)); + } p.fillRect(x1, yy, w, trackHeight, bg); if (track->selected()) { diff --git a/muse2/muse/gconfig.cpp b/muse2/muse/gconfig.cpp index 9492650b..0a521c3a 100644 --- a/muse2/muse/gconfig.cpp +++ b/muse2/muse/gconfig.cpp @@ -98,7 +98,7 @@ GlobalConfigValues config = { // at the price of only few more pixels than Normal mode. }, QColor(84, 97, 114), // trackBg; - QColor(120, 229, 166), // selected track Bg; + QColor(109, 174, 178), // selected track Bg; QColor(0x00, 0x00, 0x00), // selected track Fg; QColor(74, 150, 194), // midiTrackLabelBg; // Med blue diff --git a/muse2/share/templates/MusE.cfg b/muse2/share/templates/MusE.cfg index 9406e1ae..b95593d0 100644 --- a/muse2/share/templates/MusE.cfg +++ b/muse2/share/templates/MusE.cfg @@ -100,28 +100,28 @@ Keyboard Piano Saxophone - - + - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - + 1 00:00:00:00:00 0 -- 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/ChangeLog') 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