Mercurial > hg > svgui
changeset 34:c43f2c4f66f2
* As previous commit
author | Chris Cannam |
---|---|
date | Fri, 17 Feb 2006 18:11:08 +0000 |
parents | 651e4e868bcc |
children | 10ba9276a315 |
files | layer/SpectrogramLayer.cpp layer/TimeValueLayer.cpp layer/WaveformLayer.cpp widgets/AudioDial.cpp widgets/AudioDial.h widgets/LEDButton.cpp widgets/LEDButton.h widgets/Pane.h widgets/PropertyBox.cpp widgets/PropertyBox.h |
diffstat | 10 files changed, 286 insertions(+), 116 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp Fri Feb 17 18:04:26 2006 +0000 +++ b/layer/SpectrogramLayer.cpp Fri Feb 17 18:11:08 2006 +0000 @@ -79,9 +79,14 @@ void SpectrogramLayer::setModel(const DenseTimeValueModel *model) { + std::cerr << "SpectrogramLayer(" << this << "): setModel(" << model << ")" << std::endl; + m_mutex.lock(); m_model = model; - delete m_cache; + delete m_cache; //!!! hang on, this isn't safe to do here is it? + // we need some sort of guard against the fill + // thread trying to read the defunct model too. + // should we use a scavenger? m_cache = 0; m_mutex.unlock(); @@ -605,10 +610,12 @@ m_mutex.lock(); m_dormant = true; - delete m_cache; - m_cache = 0; +// delete m_cache; +// m_cache = 0; + m_cacheInvalid = true; m_pixmapCacheInvalid = true; + m_cachedInitialVisibleArea = false; delete m_pixmapCache; m_pixmapCache = 0; @@ -828,7 +835,7 @@ fftw_execute(plan); - if (lock) m_mutex.lock(); +// if (lock) m_mutex.lock(); bool interrupted = false; for (size_t i = 0; i < windowSize / 2; ++i) { @@ -877,7 +884,7 @@ m_cache->setValueAt(column, i, value + 1); } - if (lock) m_mutex.unlock(); +// if (lock) m_mutex.unlock(); return !interrupted; } @@ -953,7 +960,14 @@ // std::cerr << "SpectrogramLayer::CacheFillThread::run in loop" << std::endl; - if (m_layer.m_model && m_layer.m_cacheInvalid && !m_layer.m_dormant) { + if (m_layer.m_dormant) { + + if (m_layer.m_cacheInvalid) { + delete m_layer.m_cache; + m_layer.m_cache = 0; + } + + } else if (m_layer.m_model && m_layer.m_cacheInvalid) { // std::cerr << "SpectrogramLayer::CacheFillThread::run: something to do" << std::endl;
--- a/layer/TimeValueLayer.cpp Fri Feb 17 18:04:26 2006 +0000 +++ b/layer/TimeValueLayer.cpp Fri Feb 17 18:11:08 2006 +0000 @@ -420,6 +420,22 @@ int x = getXForFrame(p.frame); int y = getYForValue(p.value); + bool haveNext = false; + int nx = getXForFrame(m_model->getEndFrame()); + int ny = y; + + SparseTimeValueModel::PointList::const_iterator j = i; + ++j; + + if (j != points.end()) { + const SparseTimeValueModel::Point &q(*j); + nx = getXForFrame(q.frame); + ny = getYForValue(q.value); + haveNext = true; + } + + int labelY = y; + if (w < 1) w = 1; paint.setPen(m_colour); @@ -428,6 +444,7 @@ QColor colour = QColor::fromHsv(256 - value, value / 2 + 128, value); paint.setBrush(QColor(colour.red(), colour.green(), colour.blue(), 120)); + labelY = m_view->height(); } else if (m_plotStyle == PlotLines || m_plotStyle == PlotCurve) { paint.setBrush(Qt::NoBrush); @@ -473,17 +490,10 @@ m_plotStyle == PlotLines || m_plotStyle == PlotCurve) { - SparseTimeValueModel::PointList::const_iterator j = i; - ++j; - - if (j != points.end()) { - - const SparseTimeValueModel::Point &q(*j); - int nx = getXForFrame(q.frame); - int ny = getYForValue(q.value); + if (haveNext) { if (m_plotStyle == PlotConnectedPoints) { - + paint.setPen(brushColour); paint.drawLine(x + w, y, nx, ny); @@ -508,18 +518,6 @@ if (m_plotStyle == PlotSegmentation) { - SparseTimeValueModel::PointList::const_iterator j = i; - ++j; - - int nx; - - if (j != points.end()) { - const SparseTimeValueModel::Point &q(*j); - nx = getXForFrame(q.frame); - } else { - nx = getXForFrame(m_model->getEndFrame()); - } - if (nx <= x) continue; if (illuminateFrame != p.frame &&
--- a/layer/WaveformLayer.cpp Fri Feb 17 18:04:26 2006 +0000 +++ b/layer/WaveformLayer.cpp Fri Feb 17 18:11:08 2006 +0000 @@ -107,7 +107,7 @@ *min = -50; *max = 50; - deft = int(nearbyint(log10(m_gain) * 20.0)); + deft = lrint(log10(m_gain) * 20.0); if (deft < *min) deft = *min; if (deft > *max) deft = *max;
--- a/widgets/AudioDial.cpp Fri Feb 17 18:04:26 2006 +0000 +++ b/widgets/AudioDial.cpp Fri Feb 17 18:11:08 2006 +0000 @@ -41,6 +41,7 @@ #include <QColormap> #include <QMouseEvent> #include <QPaintEvent> +#include <QInputDialog> using std::endl; using std::cerr; @@ -61,7 +62,8 @@ // Constructor. AudioDial::AudioDial(QWidget *parent) : QDial(parent), - m_knobColor(Qt::black), m_meterColor(Qt::white) + m_knobColor(Qt::black), m_meterColor(Qt::white), + m_defaultValue(0) { m_mouseDial = false; m_mousePressed = false; @@ -139,7 +141,7 @@ // Tick notches... - if ( true/* notchesVisible() */) { + if ( notchesVisible() ) { // std::cerr << "Notches visible" << std::endl; pen.setColor(palette().dark().color()); pen.setWidth(scale); @@ -293,6 +295,12 @@ } +void AudioDial::setDefaultValue(int defaultValue) +{ + m_defaultValue = defaultValue; +} + + // Alternate mouse behavior event handlers. void AudioDial::mousePressEvent(QMouseEvent *mouseEvent) { @@ -301,6 +309,30 @@ } else if (mouseEvent->button() == Qt::LeftButton) { m_mousePressed = true; m_posMouse = mouseEvent->pos(); + } else if (mouseEvent->button() == Qt::MidButton) { + int dv = m_defaultValue; + if (dv < minimum()) dv = minimum(); + if (dv > maximum()) dv = maximum(); + setValue(m_defaultValue); + } +} + + +void AudioDial::mouseDoubleClickEvent(QMouseEvent *mouseEvent) +{ + if (m_mouseDial) { + QDial::mouseDoubleClickEvent(mouseEvent); + } else if (mouseEvent->button() == Qt::LeftButton) { + bool ok = false; + int newValue = QInputDialog::getInteger + (this, + tr("Enter new value"), + tr("Select a new value in the range %1 to %2:") + .arg(minimum()).arg(maximum()), + value(), minimum(), maximum(), pageStep(), &ok); + if (ok) { + setValue(newValue); + } } }
--- a/widgets/AudioDial.h Fri Feb 17 18:04:26 2006 +0000 +++ b/widgets/AudioDial.h Fri Feb 17 18:11:08 2006 +0000 @@ -84,6 +84,8 @@ */ void setMouseDial(bool mouseDial); + void setDefaultValue(int defaultValue); + protected: void drawTick(QPainter &paint, float angle, int size, bool internal); virtual void paintEvent(QPaintEvent *); @@ -92,11 +94,14 @@ virtual void mousePressEvent(QMouseEvent *pMouseEvent); virtual void mouseMoveEvent(QMouseEvent *pMouseEvent); virtual void mouseReleaseEvent(QMouseEvent *pMouseEvent); + virtual void mouseDoubleClickEvent(QMouseEvent *pMouseEvent); private: QColor m_knobColor; QColor m_meterColor; + int m_defaultValue; + // Alternate mouse behavior tracking. bool m_mouseDial; bool m_mousePressed;
--- a/widgets/LEDButton.cpp Fri Feb 17 18:04:26 2006 +0000 +++ b/widgets/LEDButton.cpp Fri Feb 17 18:11:08 2006 +0000 @@ -24,6 +24,8 @@ #include <QColor> #include <QMouseEvent> +#include <iostream> + class LEDButton::LEDButtonPrivate { @@ -38,7 +40,7 @@ LEDButton::LEDButton(QWidget *parent) : QWidget(parent), - led_state(On) + led_state(true) { QColor col(Qt::green); d = new LEDButton::LEDButtonPrivate; @@ -53,7 +55,7 @@ LEDButton::LEDButton(const QColor& col, QWidget *parent) : QWidget(parent), - led_state(On) + led_state(true) { d = new LEDButton::LEDButtonPrivate; d->dark_factor = 300; @@ -64,7 +66,7 @@ setColor(col); } -LEDButton::LEDButton(const QColor& col, LEDButton::State state, QWidget *parent) : +LEDButton::LEDButton(const QColor& col, bool state, QWidget *parent) : QWidget(parent), led_state(state) { @@ -87,9 +89,13 @@ void LEDButton::mousePressEvent(QMouseEvent *e) { + std::cerr << "LEDButton(" << this << ")::mousePressEvent" << std::endl; + if (e->buttons() & Qt::LeftButton) { toggle(); - emit stateChanged(state()); + bool newState = state(); + std::cerr << "emitting new state " << newState << std::endl; + emit stateChanged(newState); } } @@ -112,39 +118,30 @@ if (width < 0) width = 0; - // maybe we could stop HERE, if width <=0 ? + QPixmap *tmpMap = 0; + + if (led_state) { + if (d->on_map) { + paint.begin(this); + paint.drawPixmap(0, 0, *d->on_map); + paint.end(); + return; + } + } else { + if (d->off_map) { + paint.begin(this); + paint.drawPixmap(0, 0, *d->off_map); + paint.end(); + return; + } + } int scale = 1; - QPixmap *tmpMap = 0; - bool smooth = true; + width *= scale; - if (smooth) { - if (led_state) { - if (d->on_map) { - paint.begin(this); - paint.drawPixmap(0, 0, *d->on_map); - paint.end(); - return; - } - } else { - if (d->off_map) { - paint.begin(this); - paint.drawPixmap(0, 0, *d->off_map); - paint.end(); - return; - } - } - - scale = 1; - width *= scale; - - tmpMap = new QPixmap(width, width); - tmpMap->fill(palette().background().color()); - paint.begin(tmpMap); - - } else { - paint.begin(this); - } + tmpMap = new QPixmap(width, width); + tmpMap->fill(palette().background().color()); + paint.begin(tmpMap); paint.setRenderHint(QPainter::Antialiasing, true); @@ -221,8 +218,10 @@ // // painting done - if (smooth) { - QPixmap *&dest = led_state ? d->on_map : d->off_map; + QPixmap *&dest = led_state ? d->on_map : d->off_map; + + if (scale > 1) { + QImage i = tmpMap->toImage(); width /= scale; delete tmpMap; @@ -230,13 +229,18 @@ (i.scaled(width, width, Qt::KeepAspectRatio, Qt::SmoothTransformation))); - paint.begin(this); - paint.drawPixmap(0, 0, *dest); - paint.end(); + + } else { + + dest = tmpMap; } + + paint.begin(this); + paint.drawPixmap(0, 0, *dest); + paint.end(); } -LEDButton::State +bool LEDButton::state() const { return led_state; @@ -249,7 +253,7 @@ } void -LEDButton::setState( State state ) +LEDButton::setState( bool state ) { if (led_state != state) { @@ -261,7 +265,7 @@ void LEDButton::toggleState() { - led_state = (led_state == On) ? Off : On; + led_state = (led_state == true) ? false : true; // setColor(led_color); update(); } @@ -305,13 +309,13 @@ void LEDButton::on() { - setState(On); + setState(true); } void LEDButton::off() { - setState(Off); + setState(false); } QSize
--- a/widgets/LEDButton.h Fri Feb 17 18:04:26 2006 +0000 +++ b/widgets/LEDButton.h Fri Feb 17 18:11:08 2006 +0000 @@ -30,28 +30,19 @@ class LEDButton : public QWidget { Q_OBJECT - Q_ENUMS(State) - Q_PROPERTY(State state READ state WRITE setState) Q_PROPERTY(QColor color READ color WRITE setColor) Q_PROPERTY(int darkFactor READ darkFactor WRITE setDarkFactor) public: - enum State { Off, On }; - LEDButton(QWidget *parent = 0); LEDButton(const QColor &col, QWidget *parent = 0); - LEDButton(const QColor& col, LEDButton::State state, QWidget *parent = 0); + LEDButton(const QColor& col, bool state, QWidget *parent = 0); ~LEDButton(); - State state() const; + bool state() const; QColor color() const; int darkFactor() const; - void setState(State state); - void toggleState(); - void setColor(const QColor& color); - void setDarkFactor(int darkfactor); - virtual QSize sizeHint() const; virtual QSize minimumSizeHint() const; @@ -63,12 +54,17 @@ void on(); void off(); + void setState(bool); + void toggleState(); + void setColor(const QColor& color); + void setDarkFactor(int darkfactor); + protected: void paintEvent(QPaintEvent *); void mousePressEvent(QMouseEvent *); private: - State led_state; + bool led_state; QColor led_color; private:
--- a/widgets/Pane.h Fri Feb 17 18:04:26 2006 +0000 +++ b/widgets/Pane.h Fri Feb 17 18:11:08 2006 +0000 @@ -28,6 +28,7 @@ public: Pane(QWidget *parent = 0); + virtual QString getPropertyContainerIconName() const { return "pane"; } virtual bool shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos);
--- a/widgets/PropertyBox.cpp Fri Feb 17 18:04:26 2006 +0000 +++ b/widgets/PropertyBox.cpp Fri Feb 17 18:11:08 2006 +0000 @@ -37,37 +37,23 @@ container->getPropertyContainerName().toStdString() << "\")]::PropertyBox" << std::endl; #endif - QVBoxLayout *vbox = new QVBoxLayout; - setLayout(vbox); + m_mainBox = new QVBoxLayout; + setLayout(m_mainBox); bool needViewPlayBox = false; - if (container->getPlayParameters() || dynamic_cast<Layer *>(container)) { - needViewPlayBox = true; - } + m_mainWidget = new QWidget; + m_mainBox->addWidget(m_mainWidget); + m_mainBox->insertStretch(1, 10); - if (needViewPlayBox) { -#ifdef DEBUG_PROPERTY_BOX - std::cerr << "Adding view play box" << std::endl; -#endif - QFrame *frame = new QFrame; - frame->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); - QHBoxLayout *hbox = new QHBoxLayout; - frame->setLayout(hbox); - vbox->addWidget(frame); - populateViewPlayBox(container, hbox); - hbox->insertStretch(-1, 10); - } - - m_mainWidget = new QWidget; - vbox->addWidget(m_mainWidget); - - vbox->insertStretch(-1, 10); + m_viewPlayFrame = 0; + populateViewPlayFrame(); m_layout = new QGridLayout; + m_layout->setMargin(0); m_mainWidget->setLayout(m_layout); - PropertyContainer::PropertyList properties = container->getProperties(); + PropertyContainer::PropertyList properties = m_container->getProperties(); blockSignals(true); @@ -94,26 +80,110 @@ } void -PropertyBox::populateViewPlayBox(PropertyContainer *container, QLayout *layout) +PropertyBox::populateViewPlayFrame() { - Layer *layer = dynamic_cast<Layer *>(container); - PlayParameters *params = container->getPlayParameters(); + std::cerr << "PropertyBox(" << m_container << ")::populateViewPlayFrame" << std::endl; + + if (m_viewPlayFrame) { + delete m_viewPlayFrame; + m_viewPlayFrame = 0; + } + + if (!m_container) return; + + Layer *layer = dynamic_cast<Layer *>(m_container); + if (layer) { + connect(layer, SIGNAL(modelReplaced()), + this, SLOT(populateViewPlayFrame())); + } + + PlayParameters *params = m_container->getPlayParameters(); if (!params && !layer) return; - std::cerr << "PropertyBox::populateViewPlayBox: container " << container << " (name " << container->getPropertyContainerName().toStdString() << ") params " << params << std::endl; + m_viewPlayFrame = new QFrame; + m_viewPlayFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); + m_mainBox->addWidget(m_viewPlayFrame); + + QHBoxLayout *layout = new QHBoxLayout; + m_viewPlayFrame->setLayout(layout); + + layout->setMargin(layout->margin() / 2); + + std::cerr << "PropertyBox::populateViewPlayFrame: container " << m_container << " (name " << m_container->getPropertyContainerName().toStdString() << ") params " << params << std::endl; if (layer) { + QLabel *showLabel = new QLabel(tr("Show")); + layout->addWidget(showLabel); + layout->setAlignment(showLabel, Qt::AlignVCenter); + LEDButton *showButton = new LEDButton(Qt::blue); layout->addWidget(showButton); connect(showButton, SIGNAL(stateChanged(bool)), layer, SLOT(showLayer(bool))); + layout->setAlignment(showButton, Qt::AlignVCenter); } if (params) { + + QLabel *playLabel = new QLabel(tr("Play")); + layout->addWidget(playLabel); + layout->setAlignment(playLabel, Qt::AlignVCenter); + LEDButton *playButton = new LEDButton(Qt::darkGreen); layout->addWidget(playButton); connect(playButton, SIGNAL(stateChanged(bool)), params, SLOT(setPlayAudible(bool))); + connect(params, SIGNAL(playAudibleChanged(bool)), + playButton, SLOT(setState(bool))); + layout->setAlignment(playButton, Qt::AlignVCenter); + + layout->insertStretch(-1, 10); + + AudioDial *gainDial = new AudioDial; + layout->addWidget(gainDial); + gainDial->setMeterColor(Qt::darkRed); + gainDial->setMinimum(-50); + gainDial->setMaximum(50); + gainDial->setPageStep(1); + gainDial->setFixedWidth(24); + gainDial->setFixedHeight(24); + gainDial->setNotchesVisible(false); + gainDial->setToolTip(tr("Layer playback level")); + gainDial->setDefaultValue(0); + connect(gainDial, SIGNAL(valueChanged(int)), + this, SLOT(playGainDialChanged(int))); + connect(params, SIGNAL(playGainChanged(float)), + this, SLOT(playGainChanged(float))); + connect(this, SIGNAL(changePlayGain(float)), + params, SLOT(setPlayGain(float))); + connect(this, SIGNAL(changePlayGainDial(int)), + gainDial, SLOT(setValue(int))); + layout->setAlignment(gainDial, Qt::AlignVCenter); + + AudioDial *panDial = new AudioDial; + layout->addWidget(panDial); + panDial->setMeterColor(Qt::darkGreen); + panDial->setMinimum(-50); + panDial->setMaximum(50); + panDial->setPageStep(1); + panDial->setFixedWidth(24); + panDial->setFixedHeight(24); + panDial->setNotchesVisible(false); + panDial->setToolTip(tr("Layer playback pan")); + panDial->setDefaultValue(0); + connect(panDial, SIGNAL(valueChanged(int)), + this, SLOT(playPanDialChanged(int))); + connect(params, SIGNAL(playPanChanged(float)), + this, SLOT(playPanChanged(float))); + connect(this, SIGNAL(changePlayPan(float)), + params, SLOT(setPlayPan(float))); + connect(this, SIGNAL(changePlayPanDial(int)), + panDial, SLOT(setValue(int))); + layout->setAlignment(panDial, Qt::AlignVCenter); + + } else { + + layout->insertStretch(-1, 10); } } @@ -209,7 +279,8 @@ dial->setMinimum(min); dial->setMaximum(max); dial->setPageStep(1); - dial->setNotchesVisible(true); + dial->setNotchesVisible((max - min) <= 12); + dial->setDefaultValue(value); connect(dial, SIGNAL(valueChanged(int)), this, SLOT(propertyControllerChanged(int))); @@ -302,8 +373,10 @@ QObject *obj = sender(); QString name = obj->objectName(); +#ifdef DEBUG_PROPERTY_BOX std::cerr << "PropertyBox::propertyControllerChanged(" << name.toStdString() << ", " << value << ")" << std::endl; +#endif PropertyContainer::PropertyType type = m_container->getPropertyType(name); @@ -320,7 +393,39 @@ } } - +void +PropertyBox::playGainChanged(float gain) +{ + int dialValue = lrint(log10(gain) * 20.0); + if (dialValue < -50) dialValue = -50; + if (dialValue > 50) dialValue = 50; + emit changePlayGainDial(dialValue); +} + +void +PropertyBox::playGainDialChanged(int dialValue) +{ + float gain = pow(10, float(dialValue) / 20.0); + emit changePlayGain(gain); +} + +void +PropertyBox::playPanChanged(float pan) +{ + int dialValue = lrint(pan * 50.0); + if (dialValue < -50) dialValue = -50; + if (dialValue > 50) dialValue = 50; + emit changePlayPanDial(dialValue); +} + +void +PropertyBox::playPanDialChanged(int dialValue) +{ + float pan = float(dialValue) / 50.0; + if (pan < -1.0) pan = -1.0; + if (pan > 1.0) pan = 1.0; + emit changePlayPan(pan); +} #ifdef INCLUDE_MOCFILES #include "PropertyBox.moc.cpp"
--- a/widgets/PropertyBox.h Fri Feb 17 18:04:26 2006 +0000 +++ b/widgets/PropertyBox.h Fri Feb 17 18:11:08 2006 +0000 @@ -18,6 +18,7 @@ class QLayout; class QWidget; class QGridLayout; +class QVBoxLayout; class PropertyBox : public QFrame { @@ -29,19 +30,33 @@ PropertyContainer *getContainer() { return m_container; } +signals: + void changePlayGain(float); + void changePlayGainDial(int); + void changePlayPan(float); + void changePlayPanDial(int); + public slots: void propertyContainerPropertyChanged(PropertyContainer *); protected slots: void propertyControllerChanged(int); + void playGainChanged(float); + void playGainDialChanged(int); + void playPanChanged(float); + void playPanDialChanged(int); + + void populateViewPlayFrame(); + protected: - void populateViewPlayBox(PropertyContainer *, QLayout *); void updatePropertyEditor(PropertyContainer::PropertyName); QWidget *m_mainWidget; QGridLayout *m_layout; PropertyContainer *m_container; + QFrame *m_viewPlayFrame; + QVBoxLayout *m_mainBox; std::map<QString, QLayout *> m_groupLayouts; std::map<QString, QWidget *> m_propertyControllers; };