1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <qwidget.h>
#include <qstring.h>
#include <qslider.h>
#include <qcheckbox.h>
#include <qlabel.h>
#include <qvbox.h>
#include <qhbox.h>
#include <qspinbox.h>
#include <qradiobutton.h>
#include <qpushbutton.h>
#include <qdialog.h>
#include <qpainter.h>
#include <alsa/asoundlib.h>
#include "synthdata.h"
#include "m_vcpanning.h"
#include "port.h"
M_vcpanning::M_vcpanning(QWidget* parent, const char *name, SynthData *p_synthdata)
: Module(2, parent, name, p_synthdata) {
QString qs;
int l1, l2;
float pos, q;
M_type = M_type_vcpanning;
setGeometry(MODULE_NEW_X, MODULE_NEW_Y, MODULE_VCPANNING_WIDTH, MODULE_VCPANNING_HEIGHT);
port_M_in = new Port("In", PORT_IN, 0, this, synthdata);
port_M_in->move(0, 35);
port_M_in->outTypeAcceptList.append(outType_audio);
portList.append(port_M_in);
port_M_pan = new Port("Pan CV", PORT_IN, 1, this, synthdata);
port_M_pan->move(0, 55);
port_M_pan->outTypeAcceptList.append(outType_audio);
portList.append(port_M_pan);
for (l1 = 0; l1 < 2; l1++) {
qs.sprintf("Out %d", l1);
port_out[l1] = new Port(qs, PORT_OUT, l1, this, synthdata);
port_out[l1]->move(width() - port_out[l1]->width(), 75 + 20 * l1);
port_out[l1]->outType = outType_audio;
portList.append(port_out[l1]);
}
q = 2.0 / ((double)synthdata->poly - 1.0);
for (l2 = 0; l2 < 2; l2++) {
for (l1 = 0; l1 < synthdata->poly; l1++) {
pan[l2][l1] = 0;
oldpan[l2][l1] = 0;
}
}
if (synthdata->poly & 1) {
pos = 0;
for (l1 = 0; l1 < synthdata->poly; l1++) {
if (l1 & 1) {
pos += q;
}
panPos[l1] = (l1 & 1) ? -pos : pos;
// fprintf(stderr, "odd pan[%d] = %f\n", l1, panPos[l1]);
}
} else {
pos = q / 2.0;
for (l1 = 0; l1 < synthdata->poly; l1++) {
panPos[l1] = (l1 & 1) ? -pos : pos;
if (l1 & 1) {
pos += q;
}
// fprintf(stderr, "even pan[%d] = %f\n", l1, panPos[l1]);
}
}
panGain = 0.0;
panOffset = 0.0;
configDialog->addSlider(-1, 1, panOffset, "Pan Offset", &panOffset);
configDialog->addSlider(0, 2, panGain, "Pan Gain", &panGain);
QStrList *panModeNames = new QStrList(true);
panModeNames->append("VC control");
panModeNames->append("Fixed alternating panorama, full width");
panModeNames->append("Fixed alternating panorama, half width");
panModeNames->append("Fixed alternating panorama, quarter width");
panModeNames->append("Sort by pitch, Low <--> High");
panModeNames->append("Sort by pitch, High <--> Low");
panModeNames->append("Mono");
configDialog->addComboBox(0, "Panning Mode", &panMode, panModeNames->count(), panModeNames);
qs.sprintf("VC Panning ID %d", moduleID);
configDialog->setCaption(qs);
}
M_vcpanning::~M_vcpanning() {
}
void M_vcpanning::generateCycle() {
int l1, l2, k, len;
double dpan[2], x, y, x_2, widthConst;
if (!cycleReady) {
cycleProcessing = true;
inData = port_M_in->getinputdata ();
panData = port_M_pan->getinputdata ();
widthConst = 2.0 / 88.0;
for (l1 = 0; l1 < synthdata->poly; l1++) {
len = synthdata->cyclesize;
l2 = -1;
do {
k = (len > 24) ? 16 : len;
l2 += k;
len -= k;
switch (panMode) {
case 0: x = panOffset + panGain * panData[l1][l2];
x_2 = 0.5 * x;
if (x < -1) x = -1;
if (x > 1) x = 1;
y = 0.2125 * (1.0 - x * x);
pan[1][l1] = (0.5 + x_2) + y;
pan[0][l1] = (0.5 - x_2) + y;
break;
case 1: x = panPos[l1];
x_2 = 0.5 * x;
y = 0.2125 * (1.0 - x * x);
pan[1][l1] = (0.5 + x_2) + y;
pan[0][l1] = (0.5 - x_2) + y;
break;
case 2: x = 0.5 * panPos[l1];
x_2 = 0.5 * x;
y = 0.2125 * (1.0 - x * x);
pan[1][l1] = (0.5 + x_2) + y;
pan[0][l1] = (0.5 - x_2) + y;
break;
case 3: x = 0.25 * panPos[l1];
x_2 = 0.5 * x;
y = 0.2125 * (1.0 - x * x);
pan[1][l1] = (0.5 + x_2) + y;
pan[0][l1] = (0.5 - x_2) + y;
break;
case 4: x = ((double)(synthdata->notes[l1] - 21) * widthConst - 1.0 ) * panGain + panOffset;
if (x < -1) x = -1;
if (x > 1) x = 1;
x_2 = 0.5 * x;
y = 0.2125 * (1.0 - x * x);
pan[1][l1] = (0.5 + x_2) + y;
pan[0][l1] = (0.5 - x_2) + y;
break;
case 5: x = ((double)(88 - (synthdata->notes[l1] - 21)) * widthConst - 1.0) * panGain + panOffset;
if (x < -1) x = -1;
if (x > 1) x = 1;
x_2 = 0.5 * x;
y = 0.2125 * (1.0 - x * x);
pan[1][l1] = (0.5 + x_2) + y;
pan[0][l1] = (0.5 - x_2) + y;
break;
case 6: pan[1][l1] = 1;
pan[0][l1] = 1;
break;
}
dpan[0] = (pan[0][l1] - oldpan[0][l1]) / (double) k;
dpan[1] = (pan[1][l1] - oldpan[1][l1]) / (double) k;
while(k--) {
oldpan[0][l1] += dpan[0];
oldpan[1][l1] += dpan[1];
data[0][l1][l2-k] = oldpan[0][l1] * inData[l1][l2-k];
data[1][l1][l2-k] = oldpan[1][l1] * inData[l1][l2-k];
}
} while(len);
}
}
cycleProcessing = false;
cycleReady = true;
}
void M_vcpanning::showConfigDialog() {
}
|