Mercurial > hg > tony
changeset 128:06f9caf5928d
Initial hack for switching visibility & audibility of layers on and off. This doesn't work well.
author | Chris Cannam |
---|---|
date | Thu, 09 Jan 2014 14:05:20 +0000 |
parents | 5d60f5102baf |
children | ca3997bd8232 |
files | .hgsubstate src/Analyser.cpp src/Analyser.h src/MainWindow.cpp src/MainWindow.h |
diffstat | 5 files changed, 195 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgsubstate Thu Jan 09 14:00:52 2014 +0000 +++ b/.hgsubstate Thu Jan 09 14:05:20 2014 +0000 @@ -1,5 +1,5 @@ 236814e07bd07473958c1ff89103124536a0c3c8 dataquay -7c42c2fc4173ccadd234f0d711fb2c96059e8477 sv-dependency-builds +fffb975dc0b1d3a5cb74d4436194616d5d43014f sv-dependency-builds e86596839f27750cff1ddd3ea2e3e2ed953b8ac7 svapp 8e22795fe30bf9540103181d994a2e795a83d8c0 svcore c65826b5e980005bbecb3da5b8d2fc1d2f7c4195 svgui
--- a/src/Analyser.cpp Thu Jan 09 14:00:52 2014 +0000 +++ b/src/Analyser.cpp Thu Jan 09 14:05:20 2014 +0000 @@ -35,8 +35,7 @@ Analyser::Analyser() : m_document(0), m_fileModel(0), - m_pane(0), - m_flexiNoteLayer(0) + m_pane(0) { QSettings settings; settings.beginGroup("LayerDefaults"); @@ -87,8 +86,10 @@ waveform->setShowMeans(false); // too small & pale for this waveform->setBaseColour (ColourDatabase::getInstance()->getColourIndex(tr("Grey"))); + + m_document->addLayerToView(m_pane, waveform); - m_document->addLayerToView(m_pane, waveform); + m_layers[Audio] = waveform; Transforms transforms; @@ -114,35 +115,91 @@ if (!layers.empty()) { - ColourDatabase *cdb = ColourDatabase::getInstance(); - for (int i = 0; i < (int)layers.size(); ++i) { - SingleColourLayer *scl = dynamic_cast<SingleColourLayer *> - (layers[i]); + FlexiNoteLayer *f = qobject_cast<FlexiNoteLayer *>(layers[i]); + TimeValueLayer *t = qobject_cast<TimeValueLayer *>(layers[i]); - if (scl) { - if (i == 0) { - scl->setBaseColour(cdb->getColourIndex(tr("Black"))); - } else { - scl->setBaseColour(cdb->getColourIndex(tr("Bright Blue"))); - } - } + if (f) m_layers[Notes] = f; + if (t) m_layers[PitchTrack] = t; m_document->addLayerToView(m_pane, layers[i]); } + + ColourDatabase *cdb = ColourDatabase::getInstance(); - m_flexiNoteLayer = dynamic_cast<FlexiNoteLayer *> - (layers[layers.size()-1]); - paneStack->setCurrentLayer(m_pane, m_flexiNoteLayer); + TimeValueLayer *pitchLayer = + qobject_cast<TimeValueLayer *>(m_layers[PitchTrack]); + if (pitchLayer) { + pitchLayer->setBaseColour(cdb->getColourIndex(tr("Black"))); + paneStack->setCurrentLayer(m_pane, pitchLayer); + } + + FlexiNoteLayer *flexiNoteLayer = + qobject_cast<FlexiNoteLayer *>(m_layers[Notes]); + if (flexiNoteLayer) { + flexiNoteLayer->setBaseColour(cdb->getColourIndex(tr("Bright Blue"))); + paneStack->setCurrentLayer(m_pane, flexiNoteLayer); + } } + + emit layersChanged(); } void Analyser::setIntelligentActions(bool on) { std::cerr << "toggle setIntelligentActions " << on << std::endl; - if (m_flexiNoteLayer) { - m_flexiNoteLayer->setIntelligentActions(on); + + FlexiNoteLayer *flexiNoteLayer = + qobject_cast<FlexiNoteLayer *>(m_layers[Notes]); + if (flexiNoteLayer) { + flexiNoteLayer->setIntelligentActions(on); } } + +bool +Analyser::isVisible(Component c) const +{ + if (m_layers[c]) { + return !m_layers[c]->isLayerDormant(m_pane); + } else { + return false; + } +} + +void +Analyser::setVisible(Component c, bool v) +{ + if (m_layers[c]) { + m_layers[c]->setLayerDormant(m_pane, !v); + m_pane->layerParametersChanged(); + } +} + +bool +Analyser::isAudible(Component c) const +{ + if (m_layers[c]) { + + PlayParameters *params = m_layers[c]->getPlayParameters(); + if (!params) return false; + + return params->isPlayAudible(); + } else { + return false; + } +} + +void +Analyser::setAudible(Component c, bool a) +{ + if (m_layers[c]) { + + PlayParameters *params = m_layers[c]->getPlayParameters(); + if (!params) return; + + params->setPlayAudible(a); + } +} +
--- a/src/Analyser.h Thu Jan 09 14:00:52 2014 +0000 +++ b/src/Analyser.h Thu Jan 09 14:05:20 2014 +0000 @@ -18,16 +18,15 @@ #include <QObject> -#include "transform/Transform.h" -#include "layer/LayerFactory.h" // GF: added so we can access the FlexiNotes enum value. -#include "layer/FlexiNoteLayer.h" +#include <map> class WaveFileModel; class Pane; class PaneStack; class Document; class Layer; -class LayerFactory; +class TimeValueLayer; +class Layer; class Analyser : public QObject { @@ -42,11 +41,40 @@ void setIntelligentActions(bool); + enum Component { + Audio, + PitchTrack, + Notes, + }; + + bool isVisible(Component c) const; + void setVisible(Component c, bool v); + + bool isAudible(Component c) const; + void setAudible(Component c, bool v); + + void cycleStatus(Component c) { + if (isVisible(c)) { + if (isAudible(c)) { + setVisible(c, false); + setAudible(c, false); + } else { + setAudible(c, true); + } + } else { + setVisible(c, true); + setAudible(c, false); + } + } + +signals: + void layersChanged(); + protected: Document *m_document; WaveFileModel *m_fileModel; Pane *m_pane; - FlexiNoteLayer *m_flexiNoteLayer; + mutable std::map<Component, Layer *> m_layers; }; #endif
--- a/src/MainWindow.cpp Thu Jan 09 14:00:52 2014 +0000 +++ b/src/MainWindow.cpp Thu Jan 09 14:05:20 2014 +0000 @@ -71,6 +71,7 @@ #include <QPushButton> #include <QSettings> #include <QScrollArea> +#include <QPainter> #include <iostream> #include <cstdio> @@ -216,6 +217,8 @@ frame->setLayout(layout); m_analyser = new Analyser(); + connect(m_analyser, SIGNAL(layersChanged()), + this, SLOT(updateLayerStatuses())); setupMenus(); setupToolbars(); @@ -661,6 +664,31 @@ toolbar->addWidget(m_playSpeed); toolbar->addWidget(m_fader); + toolbar = addToolBar(tr("Show and Play")); + + QAction *cycleWaveformAction = toolbar->addAction(tr("Audio")); + //!!! shortcut etc + connect(cycleWaveformAction, SIGNAL(triggered()), this, SLOT(cycleWaveform())); + + m_waveformStatus = new QLabel(); + toolbar->addWidget(m_waveformStatus); + + QAction *cyclePitchAction = toolbar->addAction(tr("Pitch")); + //!!! shortcut etc + connect(cyclePitchAction, SIGNAL(triggered()), this, SLOT(cyclePitch())); + + m_pitchStatus = new QLabel(); + toolbar->addWidget(m_pitchStatus); + + QAction *cycleNotesAction = toolbar->addAction(tr("Notes")); + //!!! shortcut etc + connect(cycleNotesAction, SIGNAL(triggered()), this, SLOT(cycleNotes())); + + m_notesStatus = new QLabel(); + toolbar->addWidget(m_notesStatus); + + updateLayerStatuses(); + Pane::registerShortcuts(*m_keyReference); } @@ -742,6 +770,54 @@ } void +MainWindow::updateLayerStatuses() +{ + IconLoader il; + QPixmap eye = il.loadPixmap("eye"); + QPixmap speaker = il.loadPixmap("speaker"); + + // NB these need to be in the same order as the Analyser::Component enum + QLabel *statuses[] = { m_waveformStatus, m_pitchStatus, m_notesStatus }; + + for (int i = 0; i < sizeof(statuses)/sizeof(statuses[0]); ++i) { + QPixmap p(40, 16); + p.fill(QColor(0, 0, 0, 0)); + QPainter paint(&p); + if (m_analyser->isVisible((Analyser::Component)i)) { + paint.drawPixmap(0, 0, eye); + } + if (m_analyser->isAudible((Analyser::Component)i)) { + paint.drawPixmap(20, 0, speaker); + } + statuses[i]->setPixmap(p); + } +} + +void +MainWindow::cycleWaveform() +{ + cerr << "cycleWaveform" << endl; + m_analyser->cycleStatus(Analyser::Audio); + updateLayerStatuses(); +} + +void +MainWindow::cyclePitch() +{ + cerr << "cyclePitch" << endl; + m_analyser->cycleStatus(Analyser::PitchTrack); + updateLayerStatuses(); +} + +void +MainWindow::cycleNotes() +{ + cerr << "cycleNotes" << endl; + m_analyser->cycleStatus(Analyser::Notes); + updateLayerStatuses(); +} + +void MainWindow::updateDescriptionLabel() { // Nothing, we don't have one
--- a/src/MainWindow.h Thu Jan 09 14:00:52 2014 +0000 +++ b/src/MainWindow.h Thu Jan 09 14:05:20 2014 +0000 @@ -50,6 +50,11 @@ virtual void toolEditSelected(); virtual void toolFreeEditSelected(); + virtual void cycleWaveform(); + virtual void cyclePitch(); + virtual void cycleNotes(); + virtual void updateLayerStatuses(); + virtual void paneAdded(Pane *); virtual void paneHidden(Pane *); virtual void paneAboutToBeDeleted(Pane *); @@ -126,6 +131,10 @@ QAction *m_editSelectAction; QAction *m_toggleIntelligenceAction; bool m_intelligentActionOn; // GF: !!! temporary + + QLabel *m_waveformStatus; + QLabel *m_pitchStatus; + QLabel *m_notesStatus; KeyReference *m_keyReference; VersionTester *m_versionTester;