From cb896a4fa1acd9167d3e7ee9f6336a63309eebde Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 24 May 2018 20:44:33 +0200 Subject: Add save/load of selections/regions in instruments. --- src/instrumentwidget.cc | 56 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 8 deletions(-) (limited to 'src/instrumentwidget.cc') diff --git a/src/instrumentwidget.cc b/src/instrumentwidget.cc index 641f690..f8b4046 100644 --- a/src/instrumentwidget.cc +++ b/src/instrumentwidget.cc @@ -92,7 +92,7 @@ InstrumentWidget::InstrumentWidget(Settings& settings, Instrument& instrument) QToolBar* toolbar = addToolBar(tr("Tools")); listen = new CanvasToolListen(canvaswidget->canvas, player); addTool(toolbar, canvaswidget->canvas, listen); - threshold = new CanvasToolThreshold(canvaswidget->canvas); + threshold = new CanvasToolThreshold(canvaswidget->canvas, instrument); canvaswidget->canvas->tools.push_back(threshold); tool_selections = new CanvasToolSelections(canvaswidget->canvas, selections, selections_preview); @@ -106,7 +106,7 @@ InstrumentWidget::InstrumentWidget(Settings& settings, Instrument& instrument) canvaswidget->canvas, SLOT(update())); addTool(toolbar, canvaswidget->canvas, tool_selections); - sorter = new SampleSorter(selections, selections_preview); + sorter = new SampleSorter(selections, selections_preview, instrument); connect(&selections, SIGNAL(added(sel_id_t)), sorter, SLOT(addSelection(sel_id_t))); connect(&selections_preview, SIGNAL(added(sel_id_t)), @@ -142,6 +142,7 @@ InstrumentWidget::InstrumentWidget(Settings& settings, Instrument& instrument) dockWidget->widget()->setLayout(new QVBoxLayout()); tabs = new QTabWidget(this); + tabs->setMinimumWidth(350); tabs->addTab(createFilesTab(), tr("Files")); generateTabId = tabs->addTab(createGenerateTab(), tr("Generate")); tabs->addTab(createEditTab(), tr("Edit")); @@ -166,6 +167,9 @@ InstrumentWidget::InstrumentWidget(Settings& settings, Instrument& instrument) canvaswidget->yoffset->setValue(MAXVAL/2); canvaswidget->xscale->setValue(0); canvaswidget->xoffset->setValue(0); + + // Update selections according to threshold + tool_selections->thresholdChanged(instrument.getThreshold()); } InstrumentWidget::~InstrumentWidget() @@ -203,12 +207,18 @@ QWidget* InstrumentWidget::createFilesTab() extractor, SLOT(changeName(QString, QString))); l->addWidget(filelist); + if(!instrument.getMasterFile().isEmpty()) + { + loadFile(instrument.getMasterFile()); + } + return w; } QWidget* InstrumentWidget::createEditTab() { - SelectionEditor* se = new SelectionEditor(selections); + selections = instrument.getSelections(); + SelectionEditor* se = new SelectionEditor(selections, instrument); connect(&selections, SIGNAL(added(sel_id_t)), se, SLOT(added(sel_id_t))); connect(&selections, SIGNAL(updated(sel_id_t)), se, SLOT(updated(sel_id_t))); @@ -216,9 +226,19 @@ QWidget* InstrumentWidget::createEditTab() connect(&selections, SIGNAL(activeChanged(sel_id_t)), se, SLOT(activeChanged(sel_id_t))); + connect(&selections, SIGNAL(added(sel_id_t)), this, SLOT(selectionChanged())); + connect(&selections, SIGNAL(updated(sel_id_t)), this, SLOT(selectionChanged())); + connect(&selections, SIGNAL(removed(sel_id_t)), this, SLOT(selectionChanged())); + connect(&selections, SIGNAL(activeChanged(sel_id_t)), this, SLOT(selectionChanged())); + return se; } +void InstrumentWidget::selectionChanged() +{ + instrument.setSelections(selections); +} + static QSlider* createAttribute(QWidget* parent, QString name, int range_from, int range_to) { @@ -281,41 +301,61 @@ QWidget* InstrumentWidget::createGenerateTab() sorter, SLOT(setAttackLength(int))); connect(slider_attacklength, SIGNAL(valueChanged(int)), tool_selections, SLOT(autoCreateSelectionsPreview())); - slider_attacklength->setValue(300); + slider_attacklength->setValue(instrument.getAttackLength()); + connect(slider_attacklength, SIGNAL(valueChanged(int)), + this, SLOT(generateSlidersChanged())); slider_spread = createAttribute(w, tr("Power spread:"), 1, 2000); connect(slider_spread, SIGNAL(valueChanged(int)), sorter, SLOT(setSpreadFactor(int))); connect(slider_spread, SIGNAL(valueChanged(int)), tool_selections, SLOT(autoCreateSelectionsPreview())); - slider_spread->setValue(1000); + slider_spread->setValue(instrument.getPowerSpread()); + connect(slider_spread, SIGNAL(valueChanged(int)), + this, SLOT(generateSlidersChanged())); slider_hold = createAttribute(w, tr("Minimum size (samples):"), 0, 200000); connect(slider_hold, SIGNAL(valueChanged(int)), tool_selections, SLOT(holdChanged(int))); connect(slider_hold, SIGNAL(valueChanged(int)), tool_selections, SLOT(autoCreateSelectionsPreview())); - slider_hold->setValue(100); + slider_hold->setValue(instrument.getMinimumSize()); + connect(slider_hold, SIGNAL(valueChanged(int)), + this, SLOT(generateSlidersChanged())); slider_falloff = createAttribute(w, tr("Falloff:"), 10, 5000); connect(slider_falloff, SIGNAL(valueChanged(int)), tool_selections, SLOT(noiseFloorChanged(int))); connect(slider_falloff, SIGNAL(valueChanged(int)), tool_selections, SLOT(autoCreateSelectionsPreview())); - slider_falloff->setValue(300); + slider_falloff->setValue(instrument.getFalloff()); + connect(slider_falloff, SIGNAL(valueChanged(int)), + this, SLOT(generateSlidersChanged())); slider_fadelength = createAttribute(w, tr("Fadelength:"), 0, 2000); connect(slider_fadelength, SIGNAL(valueChanged(int)), tool_selections, SLOT(fadeoutChanged(int))); connect(slider_fadelength, SIGNAL(valueChanged(int)), tool_selections, SLOT(autoCreateSelectionsPreview())); - slider_fadelength->setValue(666); + slider_fadelength->setValue(instrument.getFadeLength()); + connect(slider_fadelength, SIGNAL(valueChanged(int)), + this, SLOT(generateSlidersChanged())); l->addStretch(); return w; } +void InstrumentWidget::generateSlidersChanged() +{ + Project::RAIIBulkUpdate bulkUpdate(instrument.getProject()); + instrument.setAttackLength(slider_attacklength->value()); + instrument.setPowerSpread(slider_spread->value()); + instrument.setMinimumSize(slider_hold->value()); + instrument.setFalloff(slider_falloff->value()); + instrument.setFadeLength(slider_fadelength->value()); +} + QWidget* InstrumentWidget::createExportTab() { QWidget* w = new QWidget(); -- cgit v1.2.3