summaryrefslogtreecommitdiff
path: root/dgedit
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2011-10-02 16:24:57 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2011-10-02 16:24:57 +0200
commit0e3ed82bedabcfcd78dd8c16bbd59ada66bd2e56 (patch)
tree697fad8169f7b96e9039e9ebd5361578ee83f7dd /dgedit
parentf474c3c923fe5bb27c1ee11e2c6dd57e41889f27 (diff)
Convert velocity levels from 0-127 (midi) to 0.0-1.0 (more generic).
Diffstat (limited to 'dgedit')
-rw-r--r--dgedit/audioextractor.cc6
-rw-r--r--dgedit/canvastoolselections.cc1
-rw-r--r--dgedit/samplesorter.cc42
-rw-r--r--dgedit/samplesorter.h4
4 files changed, 27 insertions, 26 deletions
diff --git a/dgedit/audioextractor.cc b/dgedit/audioextractor.cc
index 015d323..3d11f84 100644
--- a/dgedit/audioextractor.cc
+++ b/dgedit/audioextractor.cc
@@ -190,9 +190,9 @@ void AudioExtractor::exportSelections(Selections selections,
Levels::iterator nxt = k;
nxt++;
- int next;
- if(nxt == levels.end()) next = 127;
- else next = nxt->velocity - 1;
+ float next;
+ if(nxt == levels.end()) next = 1.0;
+ else next = nxt->velocity;
QDomElement velocity = doc.createElement("velocity");
diff --git a/dgedit/canvastoolselections.cc b/dgedit/canvastoolselections.cc
index ba2d6b0..35c8e05 100644
--- a/dgedit/canvastoolselections.cc
+++ b/dgedit/canvastoolselections.cc
@@ -184,6 +184,7 @@ void CanvasToolSelections::keyReleaseEvent(QKeyEvent *event)
{
if(active_selection && event->key() == Qt::Key_Delete) {
_selections.remove(active_selection->from);
+ emit selectionsChanged(_selections);
canvas->update();
}
}
diff --git a/dgedit/samplesorter.cc b/dgedit/samplesorter.cc
index 545c7cd..0338bd7 100644
--- a/dgedit/samplesorter.cc
+++ b/dgedit/samplesorter.cc
@@ -45,7 +45,7 @@ SampleSorter::SampleSorter()
attlen = 666; // Magical constants needs biblical proportions...
cur_thr = -1;
- threshold.push_back(100);
+ threshold.push_back(0.8);
threshold_is_moving = false;
}
@@ -94,7 +94,7 @@ Levels SampleSorter::levels()
for(int i = 0; i < threshold.size(); i++) {
for(int j = 0; j < threshold.size(); j++) {
if(threshold[i] < threshold[j]) {
- int tmp = threshold[i];
+ float tmp = threshold[i];
threshold[i] = threshold[j];
threshold[j] = tmp;
}
@@ -108,13 +108,13 @@ Levels SampleSorter::levels()
if(i == -1) lvl.velocity = 0;
else lvl.velocity = threshold[i];
- int next;
- if(i == threshold.size() - 1) next = 127;
+ float next;
+ if(i == threshold.size() - 1) next = 1.0;
else next = threshold[i+1];
QMap<float, Selection>::iterator i = sorted.begin();
while(i != sorted.end()) {
- float val = (i.key()/max)*127.0;
+ float val = (i.key()/max);
if(val >= lvl.velocity && val <= next) {
lvl.selections[i.key()] = i.value();
}
@@ -170,9 +170,9 @@ void SampleSorter::setActiveSelection(Selection s)
#define MAP(p) (height()-(int)(p*((float)height()/(float)width())))
-#define unmapX(x) ((double)x/(double)(width()-1)*127.0)
+#define unmapX(x) ((double)x/(double)(width()-1))
#define unmapY(x) x
-#define mapX(x) (((double)x/127.0)*(width()-1))
+#define mapX(x) (((double)x)*(width()-1))
#define mapY(x) x
@@ -198,6 +198,16 @@ void SampleSorter::paintEvent(QPaintEvent *event)
painter.setPen(colFg);
painter.drawLine(0,height(),width(),0);
+ for(int i = 0; i < threshold.size(); i++) {
+ if(cur_thr == i) painter.setPen(colPtSel);
+ else painter.setPen(colPt);
+ painter.drawLine(mapX(threshold[i]), 0, mapX(threshold[i]), height());
+ char valstr[32];
+ sprintf(valstr, "%.3f", threshold[i]);
+ painter.setPen(colVel);
+ painter.drawText(mapX(threshold[i]), height(), valstr);
+ }
+
if(sorted.isEmpty()) return;
QMap<float, Selection>::iterator i = sorted.begin();
@@ -209,24 +219,14 @@ void SampleSorter::paintEvent(QPaintEvent *event)
drawCircle(painter, x, MAP(x));
i++;
}
-
- for(int i = 0; i < threshold.size(); i++) {
- if(cur_thr == i) painter.setPen(colPtSel);
- else painter.setPen(colPt);
- painter.drawLine(mapX(threshold[i]), 0, mapX(threshold[i]), height());
- char valstr[32];
- sprintf(valstr, "%d", (int)threshold[i]);
- painter.setPen(colVel);
- painter.drawText(mapX(threshold[i]), height(), valstr);
- }
}
void SampleSorter::mouseMoveEvent(QMouseEvent *event)
{
if(cur_thr != -1 && cur_thr < threshold.size()) {
float val = unmapX(event->x());
- if(val < 0) val = 0;
- if(val > 127) val = 127;
+ if(val < 0.0) val = 0.0;
+ if(val > 1.0) val = 1.0;
threshold[cur_thr] = fabs(val);
update();
return;
@@ -259,7 +259,7 @@ void SampleSorter::mousePressEvent(QMouseEvent *event)
}
// Make new selection
- int from = unmapX(event->x());
+ float from = unmapX(event->x());
threshold.push_back(from);
cur_thr = threshold.size() - 1;
threshold_is_moving = true;
@@ -272,7 +272,7 @@ void SampleSorter::mouseReleaseEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton) {
if(threshold_is_moving) {
- if(threshold[cur_thr] == 0 || threshold[cur_thr] == 127) {
+ if(threshold[cur_thr] == 0.0 || threshold[cur_thr] == 1.0) {
threshold.remove(cur_thr);
}
threshold_is_moving = false;
diff --git a/dgedit/samplesorter.h b/dgedit/samplesorter.h
index ff45f3e..f277ff1 100644
--- a/dgedit/samplesorter.h
+++ b/dgedit/samplesorter.h
@@ -33,7 +33,7 @@
class Level {
public:
- int velocity;
+ float velocity;
QMap<float, Selection> selections;
};
@@ -74,7 +74,7 @@ private:
Selection sel;
- QVector<int> threshold;
+ QVector<double> threshold;
bool threshold_is_moving;
bool selection_is_moving_left;
bool selection_is_moving_right;