From b80448211a4ae53e0a5a0ec5d38774ba9060b3db Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Mon, 5 Aug 2024 11:18:00 +0200 Subject: Rename 'Selection' to 'Range' --- src/Makefile.am | 12 +- src/audioextractor.cc | 20 +-- src/audioextractor.h | 4 +- src/canvastoolranges.cc | 352 ++++++++++++++++++++++++++++++++++++++++++++ src/canvastoolranges.h | 92 ++++++++++++ src/canvastoolselections.cc | 352 -------------------------------------------- src/canvastoolselections.h | 92 ------------ src/dgedit.pro | 12 +- src/filelist.cc | 4 +- src/filelist.h | 2 +- src/instrumentwidget.cc | 114 +++++++------- src/instrumentwidget.h | 12 +- src/player.cc | 40 ++--- src/player.h | 14 +- src/project.cc | 8 +- src/project.h | 8 +- src/projectrenderer.cc | 6 +- src/projectserialiser.cc | 30 ++-- src/range.cc | 129 ++++++++++++++++ src/range.h | 115 +++++++++++++++ src/rangeeditor.cc | 123 ++++++++++++++++ src/rangeeditor.h | 66 +++++++++ src/samplesorter.cc | 58 ++++---- src/samplesorter.h | 16 +- src/selection.cc | 129 ---------------- src/selection.h | 115 --------------- src/selectioneditor.cc | 123 ---------------- src/selectioneditor.h | 66 --------- src/ts/dgedit_da.ts | 14 +- src/ts/dgedit_fr.ts | 15 +- 30 files changed, 1071 insertions(+), 1072 deletions(-) create mode 100644 src/canvastoolranges.cc create mode 100644 src/canvastoolranges.h delete mode 100644 src/canvastoolselections.cc delete mode 100644 src/canvastoolselections.h create mode 100644 src/range.cc create mode 100644 src/range.h create mode 100644 src/rangeeditor.cc create mode 100644 src/rangeeditor.h delete mode 100644 src/selection.cc delete mode 100644 src/selection.h delete mode 100644 src/selectioneditor.cc delete mode 100644 src/selectioneditor.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index d9a3a90..6b23d17 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -20,7 +20,7 @@ dgedit_SOURCES = \ $(top_srcdir)/src/canvas.cc \ $(top_srcdir)/src/canvastool.cc \ $(top_srcdir)/src/canvastoollisten.cc \ - $(top_srcdir)/src/canvastoolselections.cc \ + $(top_srcdir)/src/canvastoolranges.cc \ $(top_srcdir)/src/canvastoolthreshold.cc \ $(top_srcdir)/src/canvaswidget.cc \ $(top_srcdir)/src/channeldialog.cc \ @@ -40,8 +40,8 @@ dgedit_SOURCES = \ $(top_srcdir)/src/projectserialiser.cc \ $(top_srcdir)/src/renderdialog.cc \ $(top_srcdir)/src/samplesorter.cc \ - $(top_srcdir)/src/selection.cc \ - $(top_srcdir)/src/selectioneditor.cc \ + $(top_srcdir)/src/range.cc \ + $(top_srcdir)/src/rangeeditor.cc \ $(top_srcdir)/src/settings.cc \ $(top_srcdir)/src/volumefader.cc \ $(top_srcdir)/src/zoomslider.cc @@ -52,7 +52,7 @@ HDRS = \ $(top_srcdir)/src/canvas.h \ $(top_srcdir)/src/canvastool.h \ $(top_srcdir)/src/canvastoollisten.h \ - $(top_srcdir)/src/canvastoolselections.h \ + $(top_srcdir)/src/canvastoolranges.h \ $(top_srcdir)/src/canvastoolthreshold.h \ $(top_srcdir)/src/canvaswidget.h \ $(top_srcdir)/src/channeldialog.h \ @@ -72,8 +72,8 @@ HDRS = \ $(top_srcdir)/src/projectserialiser.h \ $(top_srcdir)/src/renderdialog.h \ $(top_srcdir)/src/samplesorter.h \ - $(top_srcdir)/src/selection.h \ - $(top_srcdir)/src/selectioneditor.h \ + $(top_srcdir)/src/range.h \ + $(top_srcdir)/src/rangeeditor.h \ $(top_srcdir)/src/sleep.h \ $(top_srcdir)/src/settings.h \ $(top_srcdir)/src/volumefader.h \ diff --git a/src/audioextractor.cc b/src/audioextractor.cc index 95fe6b2..d14370e 100644 --- a/src/audioextractor.cc +++ b/src/audioextractor.cc @@ -50,14 +50,14 @@ AudioExtractor::AudioExtractor(Instrument& instrument, QObject *parent) { } -bool AudioExtractor::exportSelections() +bool AudioExtractor::exportRanges() { - auto selections = instrument.getSelections(); + auto ranges = instrument.getRanges(); auto exportpath = instrument.getProject().getExportPath(); auto prefix = instrument.getPrefix(); int samplerate = -1; - emit setMaximumProgress(selections.ids().size() + 1/* for xml writing*/); + emit setMaximumProgress(ranges.ids().size() + 1/* for xml writing*/); int progress = 0; emit progressUpdate(progress++); qApp->processEvents(); @@ -92,15 +92,15 @@ bool AudioExtractor::exportSelections() } idx = 1; - QVector sels = selections.ids(); + QVector sels = ranges.ids(); - // Sort selections by velocity + // Sort ranges by velocity for(int v1 = 0; v1 < sels.size(); v1++) { for(int v2 = 0; v2 < sels.size(); v2++) { - Selection sel1 = selections.get(sels[v1]); - Selection sel2 = selections.get(sels[v2]); + Range sel1 = ranges.get(sels[v1]); + Range sel2 = ranges.get(sels[v2]); if(sel1.energy < sel2.energy) { @@ -121,7 +121,7 @@ bool AudioExtractor::exportSelections() QVector::iterator si = sels.begin(); while(si != sels.end()) { - Selection sel = selections.get(*si); + Range sel = ranges.get(*si); size_t offset = sel.from; size_t size = sel.to - sel.from; size_t fadein = sel.fadein; @@ -241,7 +241,7 @@ bool AudioExtractor::exportSelections() { index++; - Selection i = selections.get(*si); + Range i = ranges.get(*si); i.name = prefix + "-" + QString::number(index); QDomElement sample = doc.createElement("sample"); @@ -249,7 +249,7 @@ bool AudioExtractor::exportSelections() sample.setAttribute("power", QString::number(i.energy)); samples.appendChild(sample); - selections.update(*si, i); + ranges.update(*si, i); int channelnum = 1; // Filechannel numbers are 1-based. diff --git a/src/audioextractor.h b/src/audioextractor.h index 134c582..aa85d98 100644 --- a/src/audioextractor.h +++ b/src/audioextractor.h @@ -32,7 +32,7 @@ #include #include -#include "selection.h" +#include "range.h" #include "samplesorter.h" class Instrument; @@ -45,7 +45,7 @@ public: AudioExtractor(Instrument& instrument, QObject* parent); public slots: - bool exportSelections(); + bool exportRanges(); signals: void progressUpdate(int value); diff --git a/src/canvastoolranges.cc b/src/canvastoolranges.cc new file mode 100644 index 0000000..bd359a6 --- /dev/null +++ b/src/canvastoolranges.cc @@ -0,0 +1,352 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * canvastoolranges.cc + * + * Thu Jul 28 20:16:59 CEST 2011 + * Copyright 2011 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * DrumGizmo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "canvastoolranges.h" + +#include +#include + +#define mapX(x) canvas->mapX(x) +#define mapY(x) canvas->mapY(x) +#define unmapX(x) canvas->unmapX(x) +#define unmapY(x) canvas->unmapY(x) + +CanvasToolRanges::CanvasToolRanges(Canvas* c, Ranges& s, + Ranges& p) + : ranges(s) + , ranges_preview(p) +{ + threshold = 0.5; // Default from CanvasToolThreshold + hold = 100; + + canvas = c; + + range_is_moving_left = false; + range_is_moving_right = false; + + colSelBg = QColor(255, 0, 0, 60); + colSel = QColor(255, 0, 0, 160); + colActiveSelBg = QColor(255, 255, 0, 60); + colActiveSel = QColor(255, 255, 0, 160); + colPreviewSelBg = QColor(0, 0, 255, 60); + colPreviewSel = QColor(0, 0, 255, 160); +} + +bool CanvasToolRanges::mouseMoveEvent(QMouseEvent* event) +{ + sel_id_t active_range = ranges.active(); + Range act_sel = ranges.get(active_range); + + if(range_is_moving_left) + { + float val = unmapX(event->x()); + if(val > act_sel.to) val = act_sel.to - 1; + act_sel.from = std::max(0.0f, val); + ranges.update(active_range, act_sel); + canvas->update(); + return true; + } + + if(range_is_moving_right) + { + float val = unmapX(event->x()); + if(val < act_sel.from) val = act_sel.from + 1; + act_sel.to = std::min(val, (float)canvas->size); + ranges.update(active_range, act_sel); + canvas->update(); + return true; + } + + if(event->button() != Qt::LeftButton) + { + // Check if a range is being dragged. + QVector ids = ranges.ids(); + QVector::iterator i = ids.begin(); + while(i != ids.end()) + { + Range sel = ranges.get(*i); + if(abs(event->x() - mapX(sel.from)) < 2 + || abs(event->x() - mapX(sel.to)) < 2) + { + canvas->setCursor(Qt::SplitHCursor); + return true; + } + i++; + } + } + + return false; +} + +bool CanvasToolRanges::mousePressEvent(QMouseEvent* event) +{ + if(event->button() == Qt::LeftButton) + { + // Check if a range is being dragged. + QVector ids = ranges.ids(); + QVector::iterator i = ids.begin(); + while(i != ids.end()) + { + Range sel = ranges.get(*i); + if(abs(event->x() - mapX(sel.from)) < 2) + { + ranges.setActive(*i); + range_is_moving_left = true; + return true; + } + + if(abs(event->x() - mapX(sel.to)) < 2) + { + ranges.setActive(*i); + range_is_moving_right = true; + return true; + } + + i++; + } + + // Check if a range is being selected. + i = ids.begin(); + while(i != ids.end()) + { + Range sel = ranges.get(*i); + if(event->x() > mapX(sel.from) && + event->x() < mapX(sel.to)) + { + ranges.setActive(*i); + canvas->update(); + return true; + } + + i++; + } + + // Make new range + int from = unmapX(event->x()); + Range new_range(from, from); + sel_id_t id = ranges.add(new_range); + ranges.setActive(id); + range_is_moving_right = true; + canvas->update(); + return true; + } + + return false; +} + +bool CanvasToolRanges::mouseReleaseEvent(QMouseEvent* event) +{ + if(event->button() == Qt::LeftButton) + { + if(range_is_moving_left || range_is_moving_right) + { + range_is_moving_left = false; + range_is_moving_right = false; + canvas->setCursor(Qt::ArrowCursor); + canvas->update(); + return true; + } + } + + return false; +} + +void CanvasToolRanges::paintEvent(QPaintEvent* event, QPainter& painter) +{ + int pos = unmapX(event->rect().x()); + int width = unmapX(event->rect().width()); + + { + QVector ids = ranges.ids(); + QVector::iterator i = ids.begin(); + while(i != ids.end()) + { + Range sel = ranges.get(*i); + int from = sel.from; + int to = sel.to; + int fadein = sel.fadein; + int fadeout = sel.fadeout; + if(from > pos + width || to + width < pos) + { i++; continue; } + if(ranges.active() ==* i) + { + painter.setBrush(colActiveSelBg); + painter.setPen(colActiveSel); + } + else + { + painter.setBrush(colSelBg); + painter.setPen(colSel); + } + painter.drawRect(mapX(from), mapY(-1.0), + mapX(to) - mapX(from), mapY(1.0) - mapY(-1.0)); + painter.drawLine(mapX(from), mapY(0.0), mapX(from + fadein), mapY(-1.0)); + painter.drawLine(mapX(from), mapY(0.0), mapX(from + fadein), mapY(1.0)); + painter.drawLine(mapX(to - fadeout), mapY(-1.0), mapX(to), mapY(0.0)); + painter.drawLine(mapX(to - fadeout), mapY(1.0), mapX(to), mapY(0.0)); + i++; + } + } + + if(show_preview) + { + QVector ids = ranges_preview.ids(); + QVector::iterator i = ids.begin(); + while(i != ids.end()) + { + Range sel = ranges_preview.get(*i); + int from = sel.from; + int to = sel.to; + int fadein = sel.fadein; + int fadeout = sel.fadeout; + if(from > pos + width || to + width < pos) + { i++; continue; } + painter.setBrush(colPreviewSelBg); + painter.setPen(colPreviewSel); + + painter.drawRect(mapX(from), mapY(-1.0), + mapX(to) - mapX(from), mapY(1.0) - mapY(-1.0)); + painter.drawLine(mapX(from), mapY(0.0), mapX(from + fadein), mapY(-1.0)); + painter.drawLine(mapX(from), mapY(0.0), mapX(from + fadein), mapY(1.0)); + painter.drawLine(mapX(to - fadeout), mapY(-1.0), mapX(to), mapY(0.0)); + painter.drawLine(mapX(to - fadeout), mapY(1.0), mapX(to), mapY(0.0)); + i++; + } + } +} + +void CanvasToolRanges::keyReleaseEvent(QKeyEvent* event) +{ + if(ranges.active() != SEL_NONE && event->key() == Qt::Key_Delete) + { + ranges.remove(ranges.active()); + canvas->update(); + } +} + +void CanvasToolRanges::thresholdChanged(double t) +{ + threshold = t; +} + +void CanvasToolRanges::holdChanged(int h) +{ + hold = h; +} + +void CanvasToolRanges::noiseFloorChanged(int t) +{ + double div = 666.0 / 0.00003; + noise_floor = (double)t/div; +} + +void CanvasToolRanges::fadeoutChanged(int t) +{ + fadeout = (double)t/1000.0; +} + +void CanvasToolRanges::autoCreateRanges() +{ + doAutoCreateRanges(false); +} + +void CanvasToolRanges::autoCreateRangesPreview() +{ + doAutoCreateRanges(true); +} + +void CanvasToolRanges::doAutoCreateRanges(bool preview) +{ + float* data = canvas->data; + size_t size = canvas->size; + + if(preview) ranges_preview.clear(); + + for(size_t i = 0; i < size; i++) + { + if(fabs(data[i]) > fabs(threshold)) + { + int from = i; + + if(data[from] > 0.0) + { + while(/*data[from] > data[from-1] &&*/ // Falling + data[from-1] > 0.0 // Not crossing zero + ) + { + from--; + } + } + else if(data[from] < 0.0) + { + while(/*data[from] < data[from-1] &&*/ // Rising + data[from-1] < 0.0 // Not crossing zero + ) + { + from--; + } + } + + int to = i; + float runavg = fabs(data[from]); + while((runavg > noise_floor || to < from + hold) && + to < (int)size) + { + double p = 0.9; + runavg = runavg * p + fabs(data[to]) * (1 - p); + to++; + } + + Range s(from, to, 2, ((to - from) / 3) * fadeout); + if(preview) + { + ranges_preview.add(s); + } + else + { + ranges.add(s); + } + + i = to+1; + } + } + canvas->update(); +} + +void CanvasToolRanges::clearRanges() +{ + ranges.clear(); + range_is_moving_left = false; + range_is_moving_right = false; + canvas->setCursor(Qt::ArrowCursor); + canvas->update(); +} + +void CanvasToolRanges::setShowPreview(bool s) +{ + show_preview = s; + canvas->update(); +} diff --git a/src/canvastoolranges.h b/src/canvastoolranges.h new file mode 100644 index 0000000..122c21c --- /dev/null +++ b/src/canvastoolranges.h @@ -0,0 +1,92 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * canvastoolranges.h + * + * Thu Jul 28 20:16:59 CEST 2011 + * Copyright 2011 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * DrumGizmo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#pragma once + +#include "canvastool.h" + +#include + +#include "canvas.h" + +#include "range.h" + +class CanvasToolRanges + : public CanvasTool +{ + Q_OBJECT +public: + CanvasToolRanges(Canvas* canvas, Ranges& ranges, + Ranges& ranges_preview); + + QString name() { return tr("Ranges"); } + bool mouseMoveEvent(QMouseEvent* event); + bool mousePressEvent(QMouseEvent* event); + bool mouseReleaseEvent(QMouseEvent* event); + void paintEvent(QPaintEvent* event, QPainter& painter); + void keyReleaseEvent(QKeyEvent* event); + + //Ranges ranges(); + +signals: + //void rangesChanged(Ranges ranges); + //void activeRangeChanged(sel_id_t id); + +public slots: + void autoCreateRanges(); + void autoCreateRangesPreview(); + void clearRanges(); + void thresholdChanged(double threshold); + void noiseFloorChanged(int t); + void holdChanged(int h); + void fadeoutChanged(int f); + void setShowPreview(bool show_preview); + +private: + void doAutoCreateRanges(bool preview); + + bool range_is_moving_left; + bool range_is_moving_right; + + Canvas* canvas; + + double threshold; + double noise_floor; + double fadeout; + int hold; + + QColor colSelBg; + QColor colSel; + QColor colActiveSelBg; + QColor colActiveSel; + QColor colPreviewSelBg; + QColor colPreviewSel; + + Ranges& ranges; + Ranges& ranges_preview; + + bool show_preview; +}; diff --git a/src/canvastoolselections.cc b/src/canvastoolselections.cc deleted file mode 100644 index d3e90f1..0000000 --- a/src/canvastoolselections.cc +++ /dev/null @@ -1,352 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/*************************************************************************** - * canvastoolselections.cc - * - * Thu Jul 28 20:16:59 CEST 2011 - * Copyright 2011 Bent Bisballe Nyeng - * deva@aasimon.org - ****************************************************************************/ - -/* - * This file is part of DrumGizmo. - * - * DrumGizmo is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * DrumGizmo is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with DrumGizmo; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ -#include "canvastoolselections.h" - -#include -#include - -#define mapX(x) canvas->mapX(x) -#define mapY(x) canvas->mapY(x) -#define unmapX(x) canvas->unmapX(x) -#define unmapY(x) canvas->unmapY(x) - -CanvasToolSelections::CanvasToolSelections(Canvas* c, Selections& s, - Selections& p) - : selections(s) - , selections_preview(p) -{ - threshold = 0.5; // Default from CanvasToolThreshold - hold = 100; - - canvas = c; - - selection_is_moving_left = false; - selection_is_moving_right = false; - - colSelBg = QColor(255, 0, 0, 60); - colSel = QColor(255, 0, 0, 160); - colActiveSelBg = QColor(255, 255, 0, 60); - colActiveSel = QColor(255, 255, 0, 160); - colPreviewSelBg = QColor(0, 0, 255, 60); - colPreviewSel = QColor(0, 0, 255, 160); -} - -bool CanvasToolSelections::mouseMoveEvent(QMouseEvent* event) -{ - sel_id_t active_selection = selections.active(); - Selection act_sel = selections.get(active_selection); - - if(selection_is_moving_left) - { - float val = unmapX(event->x()); - if(val > act_sel.to) val = act_sel.to - 1; - act_sel.from = std::max(0.0f, val); - selections.update(active_selection, act_sel); - canvas->update(); - return true; - } - - if(selection_is_moving_right) - { - float val = unmapX(event->x()); - if(val < act_sel.from) val = act_sel.from + 1; - act_sel.to = std::min(val, (float)canvas->size); - selections.update(active_selection, act_sel); - canvas->update(); - return true; - } - - if(event->button() != Qt::LeftButton) - { - // Check if a selection is being dragged. - QVector ids = selections.ids(); - QVector::iterator i = ids.begin(); - while(i != ids.end()) - { - Selection sel = selections.get(*i); - if(abs(event->x() - mapX(sel.from)) < 2 - || abs(event->x() - mapX(sel.to)) < 2) - { - canvas->setCursor(Qt::SplitHCursor); - return true; - } - i++; - } - } - - return false; -} - -bool CanvasToolSelections::mousePressEvent(QMouseEvent* event) -{ - if(event->button() == Qt::LeftButton) - { - // Check if a selection is being dragged. - QVector ids = selections.ids(); - QVector::iterator i = ids.begin(); - while(i != ids.end()) - { - Selection sel = selections.get(*i); - if(abs(event->x() - mapX(sel.from)) < 2) - { - selections.setActive(*i); - selection_is_moving_left = true; - return true; - } - - if(abs(event->x() - mapX(sel.to)) < 2) - { - selections.setActive(*i); - selection_is_moving_right = true; - return true; - } - - i++; - } - - // Check if a selection is being selected. - i = ids.begin(); - while(i != ids.end()) - { - Selection sel = selections.get(*i); - if(event->x() > mapX(sel.from) && - event->x() < mapX(sel.to)) - { - selections.setActive(*i); - canvas->update(); - return true; - } - - i++; - } - - // Make new selection - int from = unmapX(event->x()); - Selection new_selection(from, from); - sel_id_t id = selections.add(new_selection); - selections.setActive(id); - selection_is_moving_right = true; - canvas->update(); - return true; - } - - return false; -} - -bool CanvasToolSelections::mouseReleaseEvent(QMouseEvent* event) -{ - if(event->button() == Qt::LeftButton) - { - if(selection_is_moving_left || selection_is_moving_right) - { - selection_is_moving_left = false; - selection_is_moving_right = false; - canvas->setCursor(Qt::ArrowCursor); - canvas->update(); - return true; - } - } - - return false; -} - -void CanvasToolSelections::paintEvent(QPaintEvent* event, QPainter& painter) -{ - int pos = unmapX(event->rect().x()); - int width = unmapX(event->rect().width()); - - { - QVector ids = selections.ids(); - QVector::iterator i = ids.begin(); - while(i != ids.end()) - { - Selection sel = selections.get(*i); - int from = sel.from; - int to = sel.to; - int fadein = sel.fadein; - int fadeout = sel.fadeout; - if(from > pos + width || to + width < pos) - { i++; continue; } - if(selections.active() ==* i) - { - painter.setBrush(colActiveSelBg); - painter.setPen(colActiveSel); - } - else - { - painter.setBrush(colSelBg); - painter.setPen(colSel); - } - painter.drawRect(mapX(from), mapY(-1.0), - mapX(to) - mapX(from), mapY(1.0) - mapY(-1.0)); - painter.drawLine(mapX(from), mapY(0.0), mapX(from + fadein), mapY(-1.0)); - painter.drawLine(mapX(from), mapY(0.0), mapX(from + fadein), mapY(1.0)); - painter.drawLine(mapX(to - fadeout), mapY(-1.0), mapX(to), mapY(0.0)); - painter.drawLine(mapX(to - fadeout), mapY(1.0), mapX(to), mapY(0.0)); - i++; - } - } - - if(show_preview) - { - QVector ids = selections_preview.ids(); - QVector::iterator i = ids.begin(); - while(i != ids.end()) - { - Selection sel = selections_preview.get(*i); - int from = sel.from; - int to = sel.to; - int fadein = sel.fadein; - int fadeout = sel.fadeout; - if(from > pos + width || to + width < pos) - { i++; continue; } - painter.setBrush(colPreviewSelBg); - painter.setPen(colPreviewSel); - - painter.drawRect(mapX(from), mapY(-1.0), - mapX(to) - mapX(from), mapY(1.0) - mapY(-1.0)); - painter.drawLine(mapX(from), mapY(0.0), mapX(from + fadein), mapY(-1.0)); - painter.drawLine(mapX(from), mapY(0.0), mapX(from + fadein), mapY(1.0)); - painter.drawLine(mapX(to - fadeout), mapY(-1.0), mapX(to), mapY(0.0)); - painter.drawLine(mapX(to - fadeout), mapY(1.0), mapX(to), mapY(0.0)); - i++; - } - } -} - -void CanvasToolSelections::keyReleaseEvent(QKeyEvent* event) -{ - if(selections.active() != SEL_NONE && event->key() == Qt::Key_Delete) - { - selections.remove(selections.active()); - canvas->update(); - } -} - -void CanvasToolSelections::thresholdChanged(double t) -{ - threshold = t; -} - -void CanvasToolSelections::holdChanged(int h) -{ - hold = h; -} - -void CanvasToolSelections::noiseFloorChanged(int t) -{ - double div = 666.0 / 0.00003; - noise_floor = (double)t/div; -} - -void CanvasToolSelections::fadeoutChanged(int t) -{ - fadeout = (double)t/1000.0; -} - -void CanvasToolSelections::autoCreateSelections() -{ - doAutoCreateSelections(false); -} - -void CanvasToolSelections::autoCreateSelectionsPreview() -{ - doAutoCreateSelections(true); -} - -void CanvasToolSelections::doAutoCreateSelections(bool preview) -{ - float* data = canvas->data; - size_t size = canvas->size; - - if(preview) selections_preview.clear(); - - for(size_t i = 0; i < size; i++) - { - if(fabs(data[i]) > fabs(threshold)) - { - int from = i; - - if(data[from] > 0.0) - { - while(/*data[from] > data[from-1] &&*/ // Falling - data[from-1] > 0.0 // Not crossing zero - ) - { - from--; - } - } - else if(data[from] < 0.0) - { - while(/*data[from] < data[from-1] &&*/ // Rising - data[from-1] < 0.0 // Not crossing zero - ) - { - from--; - } - } - - int to = i; - float runavg = fabs(data[from]); - while((runavg > noise_floor || to < from + hold) && - to < (int)size) - { - double p = 0.9; - runavg = runavg * p + fabs(data[to]) * (1 - p); - to++; - } - - Selection s(from, to, 2, ((to - from) / 3) * fadeout); - if(preview) - { - selections_preview.add(s); - } - else - { - selections.add(s); - } - - i = to+1; - } - } - canvas->update(); -} - -void CanvasToolSelections::clearSelections() -{ - selections.clear(); - selection_is_moving_left = false; - selection_is_moving_right = false; - canvas->setCursor(Qt::ArrowCursor); - canvas->update(); -} - -void CanvasToolSelections::setShowPreview(bool s) -{ - show_preview = s; - canvas->update(); -} diff --git a/src/canvastoolselections.h b/src/canvastoolselections.h deleted file mode 100644 index 21f00c6..0000000 --- a/src/canvastoolselections.h +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/*************************************************************************** - * canvastoolselections.h - * - * Thu Jul 28 20:16:59 CEST 2011 - * Copyright 2011 Bent Bisballe Nyeng - * deva@aasimon.org - ****************************************************************************/ - -/* - * This file is part of DrumGizmo. - * - * DrumGizmo is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * DrumGizmo is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with DrumGizmo; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ -#pragma once - -#include "canvastool.h" - -#include - -#include "canvas.h" - -#include "selection.h" - -class CanvasToolSelections - : public CanvasTool -{ - Q_OBJECT -public: - CanvasToolSelections(Canvas* canvas, Selections& selections, - Selections& selections_preview); - - QString name() { return tr("Selections"); } - bool mouseMoveEvent(QMouseEvent* event); - bool mousePressEvent(QMouseEvent* event); - bool mouseReleaseEvent(QMouseEvent* event); - void paintEvent(QPaintEvent* event, QPainter& painter); - void keyReleaseEvent(QKeyEvent* event); - - //Selections selections(); - -signals: - //void selectionsChanged(Selections selections); - //void activeSelectionChanged(sel_id_t id); - -public slots: - void autoCreateSelections(); - void autoCreateSelectionsPreview(); - void clearSelections(); - void thresholdChanged(double threshold); - void noiseFloorChanged(int t); - void holdChanged(int h); - void fadeoutChanged(int f); - void setShowPreview(bool show_preview); - -private: - void doAutoCreateSelections(bool preview); - - bool selection_is_moving_left; - bool selection_is_moving_right; - - Canvas* canvas; - - double threshold; - double noise_floor; - double fadeout; - int hold; - - QColor colSelBg; - QColor colSel; - QColor colActiveSelBg; - QColor colActiveSel; - QColor colPreviewSelBg; - QColor colPreviewSel; - - Selections& selections; - Selections& selections_preview; - - bool show_preview; -}; diff --git a/src/dgedit.pro b/src/dgedit.pro index 517be08..7c5034d 100644 --- a/src/dgedit.pro +++ b/src/dgedit.pro @@ -13,7 +13,7 @@ HEADERS += audioextractor.h \ canvas.h \ canvastool.h \ canvastoollisten.h \ - canvastoolselections.h \ + canvastoolranges.h \ canvastoolthreshold.h \ canvaswidget.h \ filelist.h \ @@ -22,8 +22,8 @@ HEADERS += audioextractor.h \ mipmap.h \ player.h \ samplesorter.h \ - selection.h \ - selectioneditor.h \ + range.h \ + rangeeditor.h \ sleep.h \ volumefader.h \ zoomslider.h @@ -31,7 +31,7 @@ SOURCES += audioextractor.cc \ canvas.cc \ canvastool.cc \ canvastoollisten.cc \ - canvastoolselections.cc \ + canvastoolranges.cc \ canvastoolthreshold.cc \ canvaswidget.cc \ dgedit.cc \ @@ -41,8 +41,8 @@ SOURCES += audioextractor.cc \ mipmap.cc \ player.cc \ samplesorter.cc \ - selection.cc \ - selectioneditor.cc \ + range.cc \ + rangeeditor.cc \ volumefader.cc \ zoomslider.cc RESOURCES += dgedit.qrc diff --git a/src/filelist.cc b/src/filelist.cc index e1467e3..dab2095 100644 --- a/src/filelist.cc +++ b/src/filelist.cc @@ -433,7 +433,7 @@ FileList::FileList(Instrument& instrument) header()->resizeSection(2, 24); connect(this, SIGNAL(doubleClicked(const QModelIndex&)), - this, SLOT(selectionChanged(const QModelIndex&))); + this, SLOT(rangeChanged(const QModelIndex&))); createMenus(); } @@ -510,7 +510,7 @@ void FileList::addFiles() model->refresh(); } -void FileList::selectionChanged(const QModelIndex &index) +void FileList::rangeChanged(const QModelIndex &index) { auto audiofile_ids = instrument.getAudioFileList(); auto audiofile_id = audiofile_ids.begin() + index.row(); diff --git a/src/filelist.h b/src/filelist.h index 165af83..120fc77 100644 --- a/src/filelist.h +++ b/src/filelist.h @@ -53,7 +53,7 @@ public slots: void addFiles(); private slots: - void selectionChanged(const QModelIndex &index); + void rangeChanged(const QModelIndex &index); void onCustomContextMenu(const QPoint &point); void setMaster(); void removeFile(); diff --git a/src/instrumentwidget.cc b/src/instrumentwidget.cc index 6a2e17e..9aeb7ee 100644 --- a/src/instrumentwidget.cc +++ b/src/instrumentwidget.cc @@ -51,7 +51,7 @@ #include "canvastool.h" #include "canvastoolthreshold.h" #include "volumefader.h" -#include "selectioneditor.h" +#include "rangeeditor.h" #include "zoomslider.h" #include "settings.h" #include "project.h" @@ -76,8 +76,8 @@ InstrumentWidget::InstrumentWidget(Settings& settings, Instrument& instrument) { int start = 44100 * 60; - Selection p(start, start + 44100 * 60, 0, 0); // one minute selection - selections_preview.add(p); + Range p(start, start + 44100 * 60, 0, 0); // one minute range + ranges_preview.add(p); } QWidget* central = new QWidget(); @@ -94,30 +94,30 @@ InstrumentWidget::InstrumentWidget(Settings& settings, Instrument& instrument) addTool(toolbar, canvaswidget->canvas, listen); threshold = new CanvasToolThreshold(canvaswidget->canvas, instrument); canvaswidget->canvas->tools.push_back(threshold); - tool_selections = new CanvasToolSelections(canvaswidget->canvas, selections, - selections_preview); + tool_ranges = new CanvasToolRanges(canvaswidget->canvas, ranges, + ranges_preview); connect(threshold, SIGNAL(thresholdChanged(double)), - tool_selections, SLOT(thresholdChanged(double))); + tool_ranges, SLOT(thresholdChanged(double))); connect(threshold, SIGNAL(thresholdChanging(double)), - tool_selections, SLOT(thresholdChanged(double))); - connect(&selections, SIGNAL(activeChanged(sel_id_t)), + tool_ranges, SLOT(thresholdChanged(double))); + connect(&ranges, SIGNAL(activeChanged(sel_id_t)), canvaswidget->canvas, SLOT(update())); - connect(&selections, SIGNAL(updated(sel_id_t)), + connect(&ranges, SIGNAL(updated(sel_id_t)), canvaswidget->canvas, SLOT(update())); - addTool(toolbar, canvaswidget->canvas, tool_selections); - - 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)), - sorter, SLOT(addSelectionPreview(sel_id_t))); - connect(&selections, SIGNAL(updated(sel_id_t)), sorter, SLOT(relayout())); - connect(&selections_preview, SIGNAL(updated(sel_id_t)), + addTool(toolbar, canvaswidget->canvas, tool_ranges); + + sorter = new SampleSorter(ranges, ranges_preview, instrument); + connect(&ranges, SIGNAL(added(sel_id_t)), + sorter, SLOT(addRange(sel_id_t))); + connect(&ranges_preview, SIGNAL(added(sel_id_t)), + sorter, SLOT(addRangePreview(sel_id_t))); + connect(&ranges, SIGNAL(updated(sel_id_t)), sorter, SLOT(relayout())); + connect(&ranges_preview, SIGNAL(updated(sel_id_t)), sorter, SLOT(relayout())); - connect(&selections, SIGNAL(removed(sel_id_t)), sorter, SLOT(relayout())); - connect(&selections_preview, SIGNAL(removed(sel_id_t)), + connect(&ranges, SIGNAL(removed(sel_id_t)), sorter, SLOT(relayout())); + connect(&ranges_preview, SIGNAL(removed(sel_id_t)), sorter, SLOT(relayout())); - connect(&selections, SIGNAL(activeChanged(sel_id_t)), + connect(&ranges, SIGNAL(activeChanged(sel_id_t)), sorter, SLOT(relayout())); QPushButton* btn_playsamples = new QPushButton(tr("Play samples")); @@ -168,8 +168,8 @@ InstrumentWidget::InstrumentWidget(Settings& settings, Instrument& instrument) canvaswidget->xscale->setValue(0); canvaswidget->xoffset->setValue(0); - // Update selections according to threshold - tool_selections->thresholdChanged(instrument.getThreshold()); + // Update ranges according to threshold + tool_ranges->thresholdChanged(instrument.getThreshold()); } InstrumentWidget::~InstrumentWidget() @@ -178,9 +178,9 @@ InstrumentWidget::~InstrumentWidget() void InstrumentWidget::tabChanged(int tabid) { - tool_selections->setShowPreview(tabid == generateTabId); + tool_ranges->setShowPreview(tabid == generateTabId); sorter->setShowPreview(tabid == generateTabId); - tool_selections->autoCreateSelectionsPreview(); + tool_ranges->autoCreateRangesPreview(); threshold->setActive(tabid == generateTabId); } @@ -211,26 +211,26 @@ QWidget* InstrumentWidget::createFilesTab() QWidget* InstrumentWidget::createEditTab() { - selections = instrument.getSelections(); - SelectionEditor* se = new SelectionEditor(selections, instrument); + ranges = instrument.getRanges(); + RangeEditor* se = new RangeEditor(ranges, 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))); - connect(&selections, SIGNAL(removed(sel_id_t)), se, SLOT(removed(sel_id_t))); - connect(&selections, SIGNAL(activeChanged(sel_id_t)), + connect(&ranges, SIGNAL(added(sel_id_t)), se, SLOT(added(sel_id_t))); + connect(&ranges, SIGNAL(updated(sel_id_t)), se, SLOT(updated(sel_id_t))); + connect(&ranges, SIGNAL(removed(sel_id_t)), se, SLOT(removed(sel_id_t))); + connect(&ranges, 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())); + connect(&ranges, SIGNAL(added(sel_id_t)), this, SLOT(rangeChanged())); + connect(&ranges, SIGNAL(updated(sel_id_t)), this, SLOT(rangeChanged())); + connect(&ranges, SIGNAL(removed(sel_id_t)), this, SLOT(rangeChanged())); + connect(&ranges, SIGNAL(activeChanged(sel_id_t)), this, SLOT(rangeChanged())); return se; } -void InstrumentWidget::selectionChanged() +void InstrumentWidget::rangeChanged() { - instrument.setSelections(selections); + instrument.setRanges(ranges); } static QSlider* createAttribute(QWidget* parent, QString name, @@ -271,19 +271,19 @@ QWidget* InstrumentWidget::createGenerateTab() QPushButton* autosel = new QPushButton(); autosel->setText(tr("Generate")); connect(autosel, SIGNAL(clicked()), - tool_selections, SLOT(clearSelections())); + tool_ranges, SLOT(clearRanges())); connect(autosel, SIGNAL(clicked()), - tool_selections, SLOT(autoCreateSelections())); + tool_ranges, SLOT(autoCreateRanges())); connect(threshold, SIGNAL(thresholdChanged(double)), - tool_selections, SLOT(autoCreateSelectionsPreview())); + tool_ranges, SLOT(autoCreateRangesPreview())); connect(threshold, SIGNAL(thresholdChanging(double)), - tool_selections, SLOT(autoCreateSelectionsPreview())); + tool_ranges, SLOT(autoCreateRangesPreview())); QPushButton* clearsel = new QPushButton(); clearsel->setText(tr("Clear")); connect(clearsel, SIGNAL(clicked()), - tool_selections, SLOT(clearSelections())); + tool_ranges, SLOT(clearRanges())); btns->addWidget(autosel); btns->addWidget(clearsel); @@ -294,7 +294,7 @@ QWidget* InstrumentWidget::createGenerateTab() connect(slider_attacklength, SIGNAL(valueChanged(int)), sorter, SLOT(setAttackLength(int))); connect(slider_attacklength, SIGNAL(valueChanged(int)), - tool_selections, SLOT(autoCreateSelectionsPreview())); + tool_ranges, SLOT(autoCreateRangesPreview())); slider_attacklength->setValue(instrument.getAttackLength()); connect(slider_attacklength, SIGNAL(valueChanged(int)), this, SLOT(generateSlidersChanged())); @@ -303,34 +303,34 @@ QWidget* InstrumentWidget::createGenerateTab() connect(slider_spread, SIGNAL(valueChanged(int)), sorter, SLOT(setSpreadFactor(int))); connect(slider_spread, SIGNAL(valueChanged(int)), - tool_selections, SLOT(autoCreateSelectionsPreview())); + tool_ranges, SLOT(autoCreateRangesPreview())); 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))); + tool_ranges, SLOT(holdChanged(int))); connect(slider_hold, SIGNAL(valueChanged(int)), - tool_selections, SLOT(autoCreateSelectionsPreview())); + tool_ranges, SLOT(autoCreateRangesPreview())); 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))); + tool_ranges, SLOT(noiseFloorChanged(int))); connect(slider_falloff, SIGNAL(valueChanged(int)), - tool_selections, SLOT(autoCreateSelectionsPreview())); + tool_ranges, SLOT(autoCreateRangesPreview())); 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))); + tool_ranges, SLOT(fadeoutChanged(int))); connect(slider_fadelength, SIGNAL(valueChanged(int)), - tool_selections, SLOT(autoCreateSelectionsPreview())); + tool_ranges, SLOT(autoCreateRangesPreview())); slider_fadelength->setValue(instrument.getFadeLength()); connect(slider_fadelength, SIGNAL(valueChanged(int)), this, SLOT(generateSlidersChanged())); @@ -404,10 +404,10 @@ void InstrumentWidget::exportPathChanged() void InstrumentWidget::playSamples() { - Selections* sels = &selections; + Ranges* sels = &ranges; if(tabs->currentIndex() == generateTabId) { - sels = &selections_preview; + sels = &ranges_preview; } QVector ids = sels->ids(); @@ -415,8 +415,8 @@ void InstrumentWidget::playSamples() { for(int v2 = 0; v2 < ids.size(); v2++) { - Selection sel1 = sels->get(ids[v1]); - Selection sel2 = sels->get(ids[v2]); + Range sel1 = sels->get(ids[v1]); + Range sel2 = sels->get(ids[v2]); if(sel1.energy < sel2.energy) { @@ -430,7 +430,7 @@ void InstrumentWidget::playSamples() QVector::iterator i = ids.begin(); while(i != ids.end()) { - Selection sel = sels->get(*i); + Range sel = sels->get(*i); unsigned int length = sb_playsamples->value() * 44100 / 1000; @@ -448,7 +448,7 @@ void InstrumentWidget::playSamples() connect(&player, SIGNAL(positionUpdate(size_t)), listen, SLOT(update(size_t))); - player.playSelection(sel, to - sel.from); + player.playRange(sel, to - sel.from); QTime t; t.start(); while(t.elapsed() < sb_playsamples->value()) @@ -466,7 +466,7 @@ void InstrumentWidget::playSamples() void InstrumentWidget::doExport() { - extractor->exportSelections(); + extractor->exportRanges(); } void InstrumentWidget::loadFile(QString filename) diff --git a/src/instrumentwidget.h b/src/instrumentwidget.h index 721b829..d2a4b9d 100644 --- a/src/instrumentwidget.h +++ b/src/instrumentwidget.h @@ -38,10 +38,10 @@ #include "audioextractor.h" #include "samplesorter.h" #include "filelist.h" -#include "canvastoolselections.h" +#include "canvastoolranges.h" #include "canvastoolthreshold.h" #include "canvastoollisten.h" -#include "selection.h" +#include "range.h" #include "player.h" #include "zoomslider.h" #include "canvaswidget.h" @@ -74,7 +74,7 @@ public slots: void browse(); void tabChanged(int tabid); void generateSlidersChanged(); - void selectionChanged(); + void rangeChanged(); void prefixChanged(); void exportPathChanged(); @@ -87,7 +87,7 @@ private: int generateTabId; SampleSorter* sorter; - CanvasToolSelections* tool_selections; + CanvasToolRanges* tool_ranges; CanvasToolThreshold* threshold; CanvasToolListen* listen; AudioExtractor* extractor; @@ -108,8 +108,8 @@ private: QTabWidget* tabs; // Session state information: - Selections selections; - Selections selections_preview; + Ranges ranges; + Ranges ranges_preview; Player player; Settings& settings; diff --git a/src/player.cc b/src/player.cc index d598d9f..a3eeaa2 100644 --- a/src/player.cc +++ b/src/player.cc @@ -38,7 +38,7 @@ Player::Player() pcm_data = NULL; pcm_size = 0; end = 0; - new_selection = false; + new_range = false; connect(&report_timer, SIGNAL(timeout()), this, SLOT(reportTimeout())); report_timer.start(50); // Update 25 times per second @@ -55,7 +55,7 @@ Player::~Player() #define _MIN(a, b) (a= sel_end || pos >= selection.to; + return pos >= sel_end || pos >= range.to; } -void Player::playSelection(Selection s, int len) +void Player::playRange(Range s, int len) { { - // Enqueue new Selection for player consumation + // Enqueue new Range for player consumation QMutexLocker lock(&mutex); - selection = s; + range = s; if(len > 0) { @@ -153,16 +153,16 @@ void Player::playSelection(Selection s, int len) } else { - sel_end = selection.to - selection.from; + sel_end = range.to - range.from; } - sel_end += selection.from; + sel_end += range.from; - new_selection = true; + new_range = true; } - // Wait until player actually consumed the new Selection. - while(new_selection) + // Wait until player actually consumed the new Range. + while(new_range) { msleep(1); } @@ -197,20 +197,20 @@ void Player::setPcmData(float* data, size_t size, double samplerate) void Player::setPosition(size_t position) { - Selection s; + Range s; s.from = position; s.to = pcm_size; s.fadein = 0; s.fadeout = 0; - playSelection(s); + playRange(s); } void Player::stop() { - Selection s; + Range s; s.from = 0; s.to = 0; s.fadein = 0; s.fadeout = 0; - playSelection(s, pos); + playRange(s, pos); } diff --git a/src/player.h b/src/player.h index 0f5b780..9bc03b7 100644 --- a/src/player.h +++ b/src/player.h @@ -32,7 +32,7 @@ #include -#include "selection.h" +#include "range.h" class Player : public QThread @@ -67,12 +67,12 @@ public slots: //! Set player position as sample offset. void setPosition(size_t position); - //! Play range based on selection including fade-in/out. + //! Play range based on range including fade-in/out. //! \param length Stop playing after length samples. -1 means play all. - void playSelection(Selection selection, int length = -1); + void playRange(Range range, int length = -1); - //! Return true if last selection is done playing. - bool playSelectionDone(); + //! Return true if last range is done playing. + bool playRangeDone(); //! Stop playing void stop(); @@ -105,7 +105,7 @@ private: bool running; QMutex mutex; - volatile bool new_selection; + volatile bool new_range; size_t sel_end; - Selection selection; + Range range; }; diff --git a/src/project.cc b/src/project.cc index 9cac537..b3b88a3 100644 --- a/src/project.cc +++ b/src/project.cc @@ -335,16 +335,16 @@ void Instrument::setThreshold(float threshold) } } -Selections Instrument::getSelections() const +Ranges Instrument::getRanges() const { - return selections; + return ranges; } -void Instrument::setSelections(const Selections& selections) +void Instrument::setRanges(const Ranges& ranges) { { Project::RAIIBulkUpdate bulkUpdate(project); - this->selections = selections; + this->ranges = ranges; } } diff --git a/src/project.h b/src/project.h index 3e2b886..b21f089 100644 --- a/src/project.h +++ b/src/project.h @@ -32,7 +32,7 @@ #include #include "audioextractor.h" -#include "selection.h" +#include "range.h" class Project; class Instrument; @@ -105,8 +105,8 @@ public: float getThreshold() const; void setThreshold(float threshold); - Selections getSelections() const; - void setSelections(const Selections& selectios); + Ranges getRanges() const; + void setRanges(const Ranges& selectios); QString getPrefix() const; void setPrefix(const QString& prefix); @@ -134,7 +134,7 @@ private: float threshold{0.5f}; // Edit tab - Selections selections; + Ranges ranges; // Export tab QString prefix; diff --git a/src/projectrenderer.cc b/src/projectrenderer.cc index 62d646e..a8e805b 100644 --- a/src/projectrenderer.cc +++ b/src/projectrenderer.cc @@ -85,8 +85,8 @@ void ProjectRenderer::render() instrument.getInstrumentName()); { - auto selections = instrument.getSelections().ids(); - emit progressRenderStart(selections.count()); + auto ranges = instrument.getRanges().ids(); + emit progressRenderStart(ranges.count()); qApp->processEvents(); } @@ -94,7 +94,7 @@ void ProjectRenderer::render() connect(&extractor, SIGNAL(progressUpdate(int)), this, SIGNAL(progressRenderTask(int))); - if(!extractor.exportSelections()) + if(!extractor.exportRanges()) { emit progressFinished(1); qApp->processEvents(); diff --git a/src/projectserialiser.cc b/src/projectserialiser.cc index 6a204eb..59cb97d 100644 --- a/src/projectserialiser.cc +++ b/src/projectserialiser.cc @@ -192,11 +192,11 @@ QString ProjectSerialiser::serialise(const Project& project) } auto regions = doc.createElement("regions"); - regions.setAttribute("nextid", i.selections.nextid); - regions.setAttribute("act", i.selections.act); + regions.setAttribute("nextid", i.ranges.nextid); + regions.setAttribute("act", i.ranges.act); instrument.appendChild(regions); - for(auto r = i.selections.sels.begin(); r != i.selections.sels.end(); ++r) + for(auto r = i.ranges.sels.begin(); r != i.ranges.sels.end(); ++r) { auto region = doc.createElement("region"); region.setAttribute("id", (int)r.key()); @@ -292,20 +292,20 @@ bool ProjectSerialiser::deserialise(const QString& data, Project& project) instr.prefix = instrument("prefix").text(); - auto selections = instrument("regions"); - instr.selections.nextid = selections["nextid"].toInt(); - instr.selections.act = selections["act"].toInt(); + auto ranges = instrument("regions"); + instr.ranges.nextid = ranges["nextid"].toInt(); + instr.ranges.act = ranges["act"].toInt(); - for(auto& selection : selections.children()) + for(auto& range : ranges.children()) { - Selection s; - s.from = selection["from"].toInt(); - s.to = selection["to"].toInt(); - s.fadein = selection["fadein"].toInt(); - s.fadeout = selection["fadeout"].toInt(); - s.energy = selection["energy"].toFloat(); - s.name = selection["name"]; - instr.selections.sels[selection["id"].toInt()] = s; + Range s; + s.from = range["from"].toInt(); + s.to = range["to"].toInt(); + s.fadein = range["fadein"].toInt(); + s.fadeout = range["fadeout"].toInt(); + s.energy = range["energy"].toFloat(); + s.name = range["name"]; + instr.ranges.sels[range["id"].toInt()] = s; } } diff --git a/src/range.cc b/src/range.cc new file mode 100644 index 0000000..28bf48e --- /dev/null +++ b/src/range.cc @@ -0,0 +1,129 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * range.cc + * + * Mon Apr 14 10:13:21 CEST 2014 + * Copyright 2014 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * DrumGizmo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "range.h" + +Ranges::Ranges() + : QObject(NULL) +{ + nextid = 0; + act = SEL_NONE; +} + +Ranges::Ranges(const Ranges& other) +{ + *this = other; +} + +void Ranges::operator=(const Ranges& other) +{ + sels = other.sels; + nextid = other.nextid; + act = other.act; +} + +sel_id_t Ranges::add(Range range) +{ + sel_id_t id = nextid++; + sels[id] = range; + added(id); + return id; +} + +Range Ranges::get(sel_id_t id) +{ + if(sels.find(id) == sels.end()) + { + Range s(0,0,0,0); + return s; + } + return sels[id]; +} + +QVector Ranges::ids() +{ + QVector v; + + QMap::iterator i = sels.begin(); + while(i != sels.end()) + { + v.push_back(i.key()); + i++; + } + + return v; +} + +void Ranges::update(sel_id_t id, Range range) +{ + if(sels.find(id) != sels.end()) + { + sels[id] = range; + emit updated(id); + } +} + +void Ranges::remove(sel_id_t id) +{ + if(sels.find(id) != sels.end()) + { + sels.erase(sels.find(id)); + if(id == act) + { + setActive(SEL_NONE); + } + emit removed(id); + } +} + +void Ranges::clear() +{ + QVector _ids = ids(); + QVector::iterator i = _ids.begin(); + while(i != _ids.end()) + { + remove(*i); + i++; + } +} + +void Ranges::setActive(sel_id_t id) +{ + if(sels.find(id) != sels.end()) + { + act = id; + } + else + { + act = SEL_NONE; + } + emit activeChanged(act); +} + +sel_id_t Ranges::active() +{ + return act; +} diff --git a/src/range.h b/src/range.h new file mode 100644 index 0000000..c887a66 --- /dev/null +++ b/src/range.h @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * range.h + * + * Sat Nov 21 13:20:46 CET 2009 + * Copyright 2009 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * DrumGizmo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#pragma once + +#include + +#include +#include + +class Range +{ +public: + Range(int from = 0, int to = 0, int fadein = 0, int fadeout = 0) + { + this->from = from; + this->to = to; + this->fadein = fadein; + this->fadeout = fadeout; + } + size_t from; + size_t to; + size_t fadein; + size_t fadeout; + + double energy; + + QString name; +}; + +typedef int sel_id_t; +#define SEL_NONE -1 + +class Ranges + : public QObject +{ + Q_OBJECT +public: + Ranges(); + Ranges(const Ranges&); + + void operator=(const Ranges& other); + + //! Add a new range object. The new id is returned. + //! Adding a new ranges will emit an added signal with the new id. + sel_id_t add(Range range); + + //! Get a stack copy of a specific range object, by id. + //! NOTE: If id does not exist an empty range (from = to = 0) is + //! returned. + Range get(sel_id_t id); + + //! Return vector (unsorted) of all ids in the object. + QVector ids(); + + //! Set active range (to be rendered yellow) + void setActive(sel_id_t id); + + //! Get active range id. + sel_id_t active(); + +public slots: + //! Update a range by id. + //! Updating a range will emit a updated signal. + void update(sel_id_t id, Range range); + + //! Delete a range by id. + //! Deleting a range will emit a deleted signal. + void remove(sel_id_t id); + + //! Delete all ranges + void clear(); + +signals: + //! This signal is emitted when a new range has been added. + void added(sel_id_t id); + + //! This signal is emitted when an existing range has been updated. + void updated(sel_id_t id); + + //! This signal is emitted when a range has been removed. + void removed(sel_id_t id); + + //! The active range changed. + void activeChanged(sel_id_t id); + +private: + friend class ProjectSerialiser; + QMap sels; + sel_id_t nextid; + sel_id_t act; +}; diff --git a/src/rangeeditor.cc b/src/rangeeditor.cc new file mode 100644 index 0000000..868f434 --- /dev/null +++ b/src/rangeeditor.cc @@ -0,0 +1,123 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * rangeeditor.cc + * + * Thu Apr 17 17:25:18 CEST 2014 + * Copyright 2014 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * DrumGizmo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "rangeeditor.h" + +#include "project.h" + +#include +#include +#include + +static QLineEdit *createWidget(QString name, QWidget* parent) +{ + QHBoxLayout* l = new QHBoxLayout(); + + l->addWidget(new QLabel(name)); + + QLineEdit* edt = new QLineEdit(); + QObject::connect(edt, SIGNAL(editingFinished()), + parent, SLOT(updateRange())); + + l->addWidget(edt); + + ((QHBoxLayout*)parent->layout())->addLayout(l); + + return edt; +} + +RangeEditor::RangeEditor(Ranges &s, Instrument& instrument) + : ranges(s) + , instrument(instrument) +{ + cur = SEL_NONE; + + setLayout(new QVBoxLayout()); + + from = createWidget(tr("From:"), this); + to = createWidget(tr("To:"), this); + fadein = createWidget(tr("FadeIn:"), this); + fadeout = createWidget(tr("FadeOut:"), this); + energy = createWidget(tr("Energy:"), this); + name = createWidget(tr("Name:"), this); + + ((QHBoxLayout*)layout())->addStretch(); +} + +void RangeEditor::updateRange() +{ + Range sel; + + sel.from = from->text().toInt(); + sel.to = to->text().toInt(); + sel.fadein = fadein->text().toInt(); + sel.fadeout = fadeout->text().toInt(); + sel.energy = energy->text().toDouble(); + sel.name = name->text(); + + ranges.update(cur, sel); + + instrument.setRanges(ranges); +} + +void RangeEditor::update() +{ + Range sel = ranges.get(cur); + from->setText(QString::number(sel.from)); + to->setText(QString::number(sel.to)); + fadein->setText(QString::number(sel.fadein)); + fadeout->setText(QString::number(sel.fadeout)); + energy->setText(QString::number(sel.energy)); + name->setText(sel.name); +} + +void RangeEditor::added(sel_id_t id) +{ + // Nothing to do here... +} + +void RangeEditor::updated(sel_id_t id) +{ + if(cur == id) + { + update(); + } +} + +void RangeEditor::removed(sel_id_t id) +{ + if(cur == id) + { + cur = SEL_NONE; + update(); + } +} + +void RangeEditor::activeChanged(sel_id_t id) +{ + cur = id; + update(); +} diff --git a/src/rangeeditor.h b/src/rangeeditor.h new file mode 100644 index 0000000..b3ecd9b --- /dev/null +++ b/src/rangeeditor.h @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * rangeeditor.h + * + * Thu Apr 17 17:25:17 CEST 2014 + * Copyright 2014 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * DrumGizmo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#pragma once + +#include + +#include +#include "range.h" + +class Instrument; + +class RangeEditor + : public QWidget +{ + Q_OBJECT +public: + RangeEditor(Ranges& ranges, Instrument& instrument); + +public slots: + void added(sel_id_t id); + void updated(sel_id_t id); + void removed(sel_id_t id); + void activeChanged(sel_id_t id); + +private slots: + void update(); + void updateRange(); + +private: + Ranges& ranges; + + sel_id_t cur; + + QLineEdit* from; + QLineEdit* to; + QLineEdit* fadein; + QLineEdit* fadeout; + QLineEdit* energy; + QLineEdit* name; + + Instrument& instrument; +}; diff --git a/src/samplesorter.cc b/src/samplesorter.cc index 29c24e6..15d6c3f 100644 --- a/src/samplesorter.cc +++ b/src/samplesorter.cc @@ -37,9 +37,9 @@ #define MAXFLOAT (3.40282347e+38F) #endif -SampleSorter::SampleSorter(Selections& s, Selections& p, Instrument& instrument) - : selections(s) - , selections_preview(p) +SampleSorter::SampleSorter(Ranges& s, Ranges& p, Instrument& instrument) + : ranges(s) + , ranges_preview(p) , instrument(instrument) { setMouseTracking(true); @@ -84,9 +84,9 @@ void SampleSorter::setAttackLength(int len) relayout(); } -void SampleSorter::addSelection(sel_id_t id) +void SampleSorter::addRange(sel_id_t id) { - Selection s = selections.get(id); + Range s = ranges.get(id); double energy = 0.0; for(size_t idx = s.from; @@ -98,14 +98,14 @@ void SampleSorter::addSelection(sel_id_t id) } s.energy = pow(energy, spread); - selections.update(id, s); + ranges.update(id, s); relayout(); } -void SampleSorter::addSelectionPreview(sel_id_t id) +void SampleSorter::addRangePreview(sel_id_t id) { - Selection s = selections_preview.get(id); + Range s = ranges_preview.get(id); double energy = 0.0; for(size_t idx = s.from; @@ -117,7 +117,7 @@ void SampleSorter::addSelectionPreview(sel_id_t id) } s.energy = pow(energy, spread); - selections_preview.update(id, s); + ranges_preview.update(id, s); relayout(); } @@ -128,11 +128,11 @@ void SampleSorter::relayout() max = 0.0; { - QVector ids = selections.ids(); + QVector ids = ranges.ids(); QVector::iterator i = ids.begin(); while(i != ids.end()) { - Selection sel = selections.get(*i); + Range sel = ranges.get(*i); if(sel.energy < min) { @@ -149,11 +149,11 @@ void SampleSorter::relayout() if(show_preview) { - QVector ids = selections_preview.ids(); + QVector ids = ranges_preview.ids(); QVector::iterator i = ids.begin(); while(i != ids.end()) { - Selection sel = selections_preview.get(*i); + Range sel = ranges_preview.get(*i); if(sel.energy < min) { @@ -203,12 +203,12 @@ void SampleSorter::paintEvent(QPaintEvent* event) { - QVector ids = selections.ids(); + QVector ids = ranges.ids(); QVector::iterator i = ids.begin(); while(i != ids.end()) { - Selection sel = selections.get(*i); - if(*i == selections.active()) + Range sel = ranges.get(*i); + if(*i == ranges.active()) { painter.setPen(colPtSel); } @@ -226,11 +226,11 @@ void SampleSorter::paintEvent(QPaintEvent* event) if(show_preview) { - QVector ids = selections_preview.ids(); + QVector ids = ranges_preview.ids(); QVector::iterator i = ids.begin(); while(i != ids.end()) { - Selection sel = selections_preview.get(*i); + Range sel = ranges_preview.get(*i); painter.setPen(colPtPreview); float x = (sel.energy / max); x = sqrt(x); @@ -243,16 +243,16 @@ void SampleSorter::paintEvent(QPaintEvent* event) } -sel_id_t SampleSorter::getSelectionByCoordinate(int px, int py) +sel_id_t SampleSorter::getRangeByCoordinate(int px, int py) { // Hit radius is slithly larger than the circles themselves. int hit_r = C_RADIUS + 1; - QVector ids = selections.ids(); + QVector ids = ranges.ids(); QVector::iterator i = ids.begin(); while(i != ids.end()) { - Selection sel = selections.get(*i); + Range sel = ranges.get(*i); float x = (sel.energy/max); x = sqrt(x); x *= (float)width() * 0.9; @@ -273,14 +273,14 @@ void SampleSorter::mouseMoveEvent(QMouseEvent* event) { if(sel_moving != SEL_NONE) { - Selection sel = selections.get(sel_moving); + Range sel = ranges.get(sel_moving); if(sel_moving != SEL_NONE) { double power = unmapX(event->x()); power *= power; power *= max; sel.energy = power; - selections.update(sel_moving, sel); + ranges.update(sel_moving, sel); } update(); @@ -288,7 +288,7 @@ void SampleSorter::mouseMoveEvent(QMouseEvent* event) } else { - sel_id_t psel = getSelectionByCoordinate(event->x(), event->y()); + sel_id_t psel = getRangeByCoordinate(event->x(), event->y()); if(psel != SEL_NONE) { setCursor(Qt::OpenHandCursor); @@ -304,9 +304,9 @@ void SampleSorter::mousePressEvent(QMouseEvent* event) { if(event->button() == Qt::LeftButton) { - sel_id_t psel = getSelectionByCoordinate(event->x(), event->y()); + sel_id_t psel = getRangeByCoordinate(event->x(), event->y()); sel_moving = psel; - selections.setActive(psel); + ranges.setActive(psel); if(psel != SEL_NONE) { setCursor(Qt::ClosedHandCursor); @@ -319,7 +319,7 @@ void SampleSorter::mouseReleaseEvent(QMouseEvent* event) if(event->button() == Qt::LeftButton) { sel_moving = SEL_NONE; - sel_id_t psel = getSelectionByCoordinate(event->x(), event->y()); + sel_id_t psel = getRangeByCoordinate(event->x(), event->y()); if(psel != SEL_NONE) { setCursor(Qt::OpenHandCursor); @@ -333,8 +333,8 @@ void SampleSorter::mouseReleaseEvent(QMouseEvent* event) void SampleSorter::keyReleaseEvent(QKeyEvent* event) { - if(selections.active() != SEL_NONE && event->key() == Qt::Key_Delete) + if(ranges.active() != SEL_NONE && event->key() == Qt::Key_Delete) { - selections.remove(selections.active()); + ranges.remove(ranges.active()); } } diff --git a/src/samplesorter.h b/src/samplesorter.h index 056161d..f1774e3 100644 --- a/src/samplesorter.h +++ b/src/samplesorter.h @@ -28,7 +28,7 @@ #include #include -#include "selection.h" +#include "range.h" class Instrument; @@ -37,7 +37,7 @@ class SampleSorter { Q_OBJECT public: - SampleSorter(Selections& selections, Selections& selections_preview, + SampleSorter(Ranges& ranges, Ranges& ranges_preview, Instrument& instrument); public slots: @@ -45,8 +45,8 @@ public slots: void setAttackLength(int len); int attackLength(); - void addSelection(sel_id_t id); - void addSelectionPreview(sel_id_t id); + void addRange(sel_id_t id); + void addRangePreview(sel_id_t id); void relayout(); @@ -62,10 +62,10 @@ protected: void keyReleaseEvent(QKeyEvent* event) override; private: - sel_id_t getSelectionByCoordinate(int x, int y); + sel_id_t getRangeByCoordinate(int x, int y); - Selections& selections; - Selections& selections_preview; + Ranges& ranges; + Ranges& ranges_preview; bool show_preview; @@ -77,7 +77,7 @@ private: const float* data; size_t size; - Selection sel; + Range sel; sel_id_t sel_moving; diff --git a/src/selection.cc b/src/selection.cc deleted file mode 100644 index e18e485..0000000 --- a/src/selection.cc +++ /dev/null @@ -1,129 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/*************************************************************************** - * selection.cc - * - * Mon Apr 14 10:13:21 CEST 2014 - * Copyright 2014 Bent Bisballe Nyeng - * deva@aasimon.org - ****************************************************************************/ - -/* - * This file is part of DrumGizmo. - * - * DrumGizmo is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * DrumGizmo is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with DrumGizmo; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ -#include "selection.h" - -Selections::Selections() - : QObject(NULL) -{ - nextid = 0; - act = SEL_NONE; -} - -Selections::Selections(const Selections& other) -{ - *this = other; -} - -void Selections::operator=(const Selections& other) -{ - sels = other.sels; - nextid = other.nextid; - act = other.act; -} - -sel_id_t Selections::add(Selection selection) -{ - sel_id_t id = nextid++; - sels[id] = selection; - added(id); - return id; -} - -Selection Selections::get(sel_id_t id) -{ - if(sels.find(id) == sels.end()) - { - Selection s(0,0,0,0); - return s; - } - return sels[id]; -} - -QVector Selections::ids() -{ - QVector v; - - QMap::iterator i = sels.begin(); - while(i != sels.end()) - { - v.push_back(i.key()); - i++; - } - - return v; -} - -void Selections::update(sel_id_t id, Selection selection) -{ - if(sels.find(id) != sels.end()) - { - sels[id] = selection; - emit updated(id); - } -} - -void Selections::remove(sel_id_t id) -{ - if(sels.find(id) != sels.end()) - { - sels.erase(sels.find(id)); - if(id == act) - { - setActive(SEL_NONE); - } - emit removed(id); - } -} - -void Selections::clear() -{ - QVector _ids = ids(); - QVector::iterator i = _ids.begin(); - while(i != _ids.end()) - { - remove(*i); - i++; - } -} - -void Selections::setActive(sel_id_t id) -{ - if(sels.find(id) != sels.end()) - { - act = id; - } - else - { - act = SEL_NONE; - } - emit activeChanged(act); -} - -sel_id_t Selections::active() -{ - return act; -} diff --git a/src/selection.h b/src/selection.h deleted file mode 100644 index 338b381..0000000 --- a/src/selection.h +++ /dev/null @@ -1,115 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/*************************************************************************** - * selection.h - * - * Sat Nov 21 13:20:46 CET 2009 - * Copyright 2009 Bent Bisballe Nyeng - * deva@aasimon.org - ****************************************************************************/ - -/* - * This file is part of DrumGizmo. - * - * DrumGizmo is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * DrumGizmo is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with DrumGizmo; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ -#pragma once - -#include - -#include -#include - -class Selection -{ -public: - Selection(int from = 0, int to = 0, int fadein = 0, int fadeout = 0) - { - this->from = from; - this->to = to; - this->fadein = fadein; - this->fadeout = fadeout; - } - size_t from; - size_t to; - size_t fadein; - size_t fadeout; - - double energy; - - QString name; -}; - -typedef int sel_id_t; -#define SEL_NONE -1 - -class Selections - : public QObject -{ - Q_OBJECT -public: - Selections(); - Selections(const Selections&); - - void operator=(const Selections& other); - - //! Add a new selection object. The new id is returned. - //! Adding a new selections will emit an added signal with the new id. - sel_id_t add(Selection selection); - - //! Get a stack copy of a specific selection object, by id. - //! NOTE: If id does not exist an empty selection (from = to = 0) is - //! returned. - Selection get(sel_id_t id); - - //! Return vector (unsorted) of all ids in the object. - QVector ids(); - - //! Set active selection (to be rendered yellow) - void setActive(sel_id_t id); - - //! Get active selection id. - sel_id_t active(); - -public slots: - //! Update a selection by id. - //! Updating a selection will emit a updated signal. - void update(sel_id_t id, Selection selection); - - //! Delete a selection by id. - //! Deleting a selection will emit a deleted signal. - void remove(sel_id_t id); - - //! Delete all selections - void clear(); - -signals: - //! This signal is emitted when a new selection has been added. - void added(sel_id_t id); - - //! This signal is emitted when an existing selection has been updated. - void updated(sel_id_t id); - - //! This signal is emitted when a selection has been removed. - void removed(sel_id_t id); - - //! The active selection changed. - void activeChanged(sel_id_t id); - -private: - friend class ProjectSerialiser; - QMap sels; - sel_id_t nextid; - sel_id_t act; -}; diff --git a/src/selectioneditor.cc b/src/selectioneditor.cc deleted file mode 100644 index 417059d..0000000 --- a/src/selectioneditor.cc +++ /dev/null @@ -1,123 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/*************************************************************************** - * selectioneditor.cc - * - * Thu Apr 17 17:25:18 CEST 2014 - * Copyright 2014 Bent Bisballe Nyeng - * deva@aasimon.org - ****************************************************************************/ - -/* - * This file is part of DrumGizmo. - * - * DrumGizmo is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * DrumGizmo is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with DrumGizmo; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ -#include "selectioneditor.h" - -#include "project.h" - -#include -#include -#include - -static QLineEdit *createWidget(QString name, QWidget* parent) -{ - QHBoxLayout* l = new QHBoxLayout(); - - l->addWidget(new QLabel(name)); - - QLineEdit* edt = new QLineEdit(); - QObject::connect(edt, SIGNAL(editingFinished()), - parent, SLOT(updateSelection())); - - l->addWidget(edt); - - ((QHBoxLayout*)parent->layout())->addLayout(l); - - return edt; -} - -SelectionEditor::SelectionEditor(Selections &s, Instrument& instrument) - : selections(s) - , instrument(instrument) -{ - cur = SEL_NONE; - - setLayout(new QVBoxLayout()); - - from = createWidget(tr("From:"), this); - to = createWidget(tr("To:"), this); - fadein = createWidget(tr("FadeIn:"), this); - fadeout = createWidget(tr("FadeOut:"), this); - energy = createWidget(tr("Energy:"), this); - name = createWidget(tr("Name:"), this); - - ((QHBoxLayout*)layout())->addStretch(); -} - -void SelectionEditor::updateSelection() -{ - Selection sel; - - sel.from = from->text().toInt(); - sel.to = to->text().toInt(); - sel.fadein = fadein->text().toInt(); - sel.fadeout = fadeout->text().toInt(); - sel.energy = energy->text().toDouble(); - sel.name = name->text(); - - selections.update(cur, sel); - - instrument.setSelections(selections); -} - -void SelectionEditor::update() -{ - Selection sel = selections.get(cur); - from->setText(QString::number(sel.from)); - to->setText(QString::number(sel.to)); - fadein->setText(QString::number(sel.fadein)); - fadeout->setText(QString::number(sel.fadeout)); - energy->setText(QString::number(sel.energy)); - name->setText(sel.name); -} - -void SelectionEditor::added(sel_id_t id) -{ - // Nothing to do here... -} - -void SelectionEditor::updated(sel_id_t id) -{ - if(cur == id) - { - update(); - } -} - -void SelectionEditor::removed(sel_id_t id) -{ - if(cur == id) - { - cur = SEL_NONE; - update(); - } -} - -void SelectionEditor::activeChanged(sel_id_t id) -{ - cur = id; - update(); -} diff --git a/src/selectioneditor.h b/src/selectioneditor.h deleted file mode 100644 index cdbf2de..0000000 --- a/src/selectioneditor.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/*************************************************************************** - * selectioneditor.h - * - * Thu Apr 17 17:25:17 CEST 2014 - * Copyright 2014 Bent Bisballe Nyeng - * deva@aasimon.org - ****************************************************************************/ - -/* - * This file is part of DrumGizmo. - * - * DrumGizmo is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * DrumGizmo is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with DrumGizmo; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ -#pragma once - -#include - -#include -#include "selection.h" - -class Instrument; - -class SelectionEditor - : public QWidget -{ - Q_OBJECT -public: - SelectionEditor(Selections& selections, Instrument& instrument); - -public slots: - void added(sel_id_t id); - void updated(sel_id_t id); - void removed(sel_id_t id); - void activeChanged(sel_id_t id); - -private slots: - void update(); - void updateSelection(); - -private: - Selections& selections; - - sel_id_t cur; - - QLineEdit* from; - QLineEdit* to; - QLineEdit* fadein; - QLineEdit* fadeout; - QLineEdit* energy; - QLineEdit* name; - - Instrument& instrument; -}; diff --git a/src/ts/dgedit_da.ts b/src/ts/dgedit_da.ts index bda3ba5..7fc26cc 100644 --- a/src/ts/dgedit_da.ts +++ b/src/ts/dgedit_da.ts @@ -25,7 +25,7 @@ CanvasToolSelections - + Selections Markeringer @@ -537,32 +537,32 @@ SelectionEditor - + From: Fra: - + To: Til: - + FadeIn: FadeIn: - + FadeOut: FadeOut: - + Energy: Energi: - + Name: Navn: diff --git a/src/ts/dgedit_fr.ts b/src/ts/dgedit_fr.ts index deb07bd..b37cad8 100644 --- a/src/ts/dgedit_fr.ts +++ b/src/ts/dgedit_fr.ts @@ -25,7 +25,7 @@ CanvasToolSelections - + Selections Sélections @@ -537,32 +537,32 @@ SelectionEditor - + From: Depuis : - + To: Jusqu'à : - + FadeIn: Fondu ouverture : - + FadeOut: Fondu fermeture : - + Energy: Énergie : - + Name: Nom : @@ -581,4 +581,3 @@ - -- cgit v1.2.3