Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Big cleanup

  • Loading branch information...
commit b3dcce16aa8a59d7e2986c45c2ca3fb3adce04fe 1 parent 21d80aa
@mtytel authored
Showing with 836 additions and 1,088 deletions.
  1. +1 −1  Makefile
  2. +21 −18 src/Aliaser.cpp
  3. +4 −13 src/Aliaser.h
  4. +21 −17 src/BitCrush.cpp
  5. +4 −12 src/BitCrush.h
  6. +20 −7 src/Class.cpp
  7. +5 −15 src/Class.h
  8. +2 −2 src/Constant.cpp
  9. +2 −5 src/Constant.h
  10. +19 −14 src/Decay.cpp
  11. +4 −11 src/Decay.h
  12. +51 −41 src/Delay.cpp
  13. +4 −13 src/Delay.h
  14. +0 −2  src/Differentiator.cpp
  15. +2 −4 src/Differentiator.h
  16. +17 −13 src/Effect.cpp
  17. +4 −10 src/Effect.h
  18. +18 −14 src/Harmonizer.cpp
  19. +4 −11 src/Harmonizer.h
  20. +24 −24 src/Keyboard.cpp
  21. +5 −15 src/Keyboard.h
  22. +94 −108 src/Loop.cpp
  23. +9 −15 src/Loop.h
  24. +11 −9 src/Memory.cpp
  25. +3 −7 src/Memory.h
  26. +90 −93 src/Midi.cpp
  27. +10 −26 src/Midi.h
  28. +35 −24 src/Oscillator.cpp
  29. +4 −14 src/Oscillator.h
  30. +0 −2  src/Parallel.cpp
  31. +2 −4 src/Parallel.h
  32. +0 −83 src/Pitch.cpp
  33. +0 −55 src/Pitch.h
  34. +16 −21 src/Process.cpp
  35. +1 −2  src/Process.h
  36. +30 −37 src/Processor.cpp
  37. +6 −7 src/Processor.h
  38. +61 −67 src/ProcessorList.cpp
  39. +3 −6 src/ProcessorList.h
  40. +51 −42 src/RotateDelay.cpp
  41. +4 −16 src/RotateDelay.h
  42. +14 −16 src/Series.cpp
  43. +2 −4 src/Series.h
  44. +25 −21 src/Switch.cpp
  45. +4 −11 src/Switch.h
  46. +18 −13 src/Volume.cpp
  47. +2 −10 src/Volume.h
  48. +27 −27 src/WaveFunctions.cpp
  49. +2 −5 src/WaveFunctions.h
  50. +80 −81 src/main.cpp
View
2  Makefile
@@ -7,7 +7,7 @@ LDFLAGS=
OBJS := $(patsubst src/%.cpp,debug/src/%.o,$(wildcard src/*.cpp))
-all: clean dfex
+all: dfex
dfex: $(OBJS)
@echo 'Building Executable: $@'
View
39 src/Aliaser.cpp
@@ -22,34 +22,37 @@ using namespace std;
Class Aliaser::cls(string("Aliaser"), newInstance);
-void Aliaser::process(const sample_t* in, sample_t* out, int num) {
+Aliaser::Aliaser(float period) : Effect::Effect(), mOffset(0), mCurSamp(0) {
+ mPeriod = new Constant(period);
+}
- sample_t period[num];
- mPeriod->process(in, period, num);
+Aliaser::~Aliaser() {
+ delete mPeriod;
+}
- for (int i = 0; i < num; i++) {
+void Aliaser::process(const sample_t* in, sample_t* out, int num) {
+ sample_t period[num];
+ mPeriod->process(in, period, num);
- if (++mOffset >= period[i]) {
- mCurSamp = in[i];
- mOffset = 0;
- }
- out[i] = mCurSamp;
+ for (int i = 0; i < num; i++) {
+ if (++mOffset >= period[i]) {
+ mCurSamp = in[i];
+ mOffset = 0;
}
-
- postProcess(in, out, num);
+ out[i] = mCurSamp;
+ }
+ postProcess(in, out, num);
}
xml_node<> &Aliaser::read(xml_node<> &inode) {
-
- Effect::read(inode);
+ Effect::read(inode);
- delete mPeriod;
- mPeriod = Processor::readParameter(inode, "period", DEFAULTPERIOD);
+ delete mPeriod;
+ mPeriod = Processor::readParameter(inode, "period", DEFAULTPERIOD);
- return inode;
+ return inode;
}
xml_node<> &Aliaser::write(xml_node<> &onode) const {
-
- return onode;
+ return onode;
}
View
17 src/Aliaser.h
@@ -25,24 +25,16 @@
#define DEFAULTPERIOD 2.0
class Aliaser : public Effect {
-public:
-
- Aliaser(float period = DEFAULTPERIOD) : Effect::Effect(), mOffset(0),
- mCurSamp(0) {
- mPeriod = new Constant(period);
- }
-
- virtual ~Aliaser() {
- delete mPeriod;
- }
+ public:
+ Aliaser(float period = DEFAULTPERIOD);
+ virtual ~Aliaser();
const Class *getClass() const { return &cls; }
static Object *newInstance() { return new Aliaser(); }
void process(const sample_t* in, sample_t* out, int num);
-protected:
-
+ protected:
static Class cls;
Processor *mPeriod;
@@ -54,4 +46,3 @@ class Aliaser : public Effect {
};
#endif
-
View
38 src/BitCrush.cpp
@@ -21,31 +21,35 @@ using namespace rapidxml;
Class BitCrush::cls(std::string("BitCrush"), newInstance);
-void BitCrush::process(const sample_t* in, sample_t* out, int num) {
-
- sample_t bits[num];
- mBits->process(in, bits, num);
+BitCrush::BitCrush(float bits) : Effect::Effect() {
+ mBits = new Constant(bits);
+}
- for (int i = 0; i < num; i++) {
- float mult = pow(2, bits[i] / 2);
- float disc = round(mult * in[i]);
- out[i] = disc / mult;
- }
+BitCrush::~BitCrush() {
+ delete mBits;
+}
- postProcess(in, out, num);
+void BitCrush::process(const sample_t* in, sample_t* out, int num) {
+ sample_t bits[num];
+ mBits->process(in, bits, num);
+
+ for (int i = 0; i < num; i++) {
+ float mult = pow(2, bits[i] / 2);
+ float disc = round(mult * in[i]);
+ out[i] = disc / mult;
+ }
+ postProcess(in, out, num);
}
xml_node<> &BitCrush::read(xml_node<> &inode) {
-
- Effect::read(inode);
+ Effect::read(inode);
- delete mBits;
- mBits = Processor::readParameter(inode, "bits", DEFAULTBITS);
+ delete mBits;
+ mBits = Processor::readParameter(inode, "bits", DEFAULTBITS);
- return inode;
+ return inode;
}
xml_node<> &BitCrush::write(xml_node<> &onode) const {
-
- return onode;
+ return onode;
}
View
16 src/BitCrush.h
@@ -20,29 +20,21 @@
#include <stdlib.h>
#include <math.h>
-
#include "Effect.h"
#define DEFAULTBITS 2.0
class BitCrush : public Effect {
-public:
-
- BitCrush(float bits = DEFAULTBITS) : Effect::Effect() {
- mBits = new Constant(bits);
- }
-
- virtual ~BitCrush() {
- delete mBits;
- }
+ public:
+ BitCrush(float bits = DEFAULTBITS);
+ virtual ~BitCrush();
const Class *getClass() const { return &cls; }
static Object *newInstance() { return new BitCrush(); }
void process(const sample_t* in, sample_t* out, int num);
-protected:
-
+ protected:
static Class cls;
Processor *mBits;
View
27 src/Class.cpp
@@ -17,18 +17,31 @@
#include "Class.h"
+using namespace std;
+
Class *Class::mClsHead;
-const Class *Class::ForName(const std::string &name) {
- Class *cur = 0;
+Class::Class(const string &n, Object *(*c)()) : mName(n), mCreate(c) {
+ Class *cur = mClsHead;
+
+ if (!cur)
+ mClsHead = this;
+ else {
+ for (; cur->mNext; cur = cur->mNext)
+ ;
+ cur->mNext = this;
+ }
+}
- for (cur = mClsHead; cur && cur->mName != name; cur = cur->mNext)
- ;
+const Class *Class::ForName(const string &name) {
+ Class *cur = 0;
- return cur;
+ for (cur = mClsHead; cur && cur->mName != name; cur = cur->mNext)
+ ;
+
+ return cur;
}
Object *Class::NewInstance() const {
- return mCreate();
+ return mCreate();
}
-
View
20 src/Class.h
@@ -20,34 +20,24 @@
#include <string>
#include <vector>
-#include "rapidxml.hpp"
class Class;
class Object {
-public:
+ public:
virtual const Class *getClass() const = 0;
};
class Class {
-public:
- Class(const std::string &n, Object *(*c)()) : mName(n), mCreate(c) {
- Class *cur = mClsHead;
-
- if (!cur)
- mClsHead = this;
- else {
- for (; cur->mNext; cur = cur->mNext)
- ;
- cur->mNext = this;
- }
- }
+ public:
+ Class(const std::string &n, Object *(*c)());
virtual Object *NewInstance() const;
+
std::string GetName() const { return mName; }
static const Class *ForName(const std::string &name);
-protected:
+ protected:
std::string mName;
Object *(*mCreate)();
Class *mNext;
View
4 src/Constant.cpp
@@ -22,7 +22,7 @@ using namespace std;
Class Constant::cls(string("Constant"), newInstance);
void Constant::process(const sample_t* in, sample_t* out, int num) {
- for (int i = 0; i < num; i++)
- out[i] = mVal;
+ for (int i = 0; i < num; i++)
+ out[i] = mVal;
}
View
7 src/Constant.h
@@ -21,19 +21,16 @@
#include "Processor.h"
class Constant : public Processor {
-public:
-
+ public:
Constant(float val = 0) : Processor::Processor(), mVal(val) { }
virtual ~Constant() { }
const Class *getClass() const { return &cls; }
static Object *newInstance() { return new Constant(); }
- static Constant *readConstant(std::istream &is);
virtual void process(const sample_t* in, sample_t* out, int num);
-protected:
-
+ protected:
static Class cls;
float mVal;
View
33 src/Decay.cpp
@@ -22,29 +22,34 @@ using namespace std;
Class Decay::cls(std::string("Decay"), Decay::newInstance);
+Decay::Decay() : mCurVal(0) {
+ mDecay = new Constant(DEFAULTDECAY);
+}
+
+Decay::~Decay() {
+ delete mDecay;
+}
+
void Decay::process(const sample_t* in, sample_t* out, int num) {
+ sample_t decay[num];
+ mDecay->process(in, decay, num);
- sample_t decay[num];
- mDecay->process(in, decay, num);
-
- for (int i = 0; i < num; i++) {
- mCurVal = in[i] * decay[i] + mCurVal * (1 - decay[i]);
- out[i] = mCurVal;
- }
+ for (int i = 0; i < num; i++) {
+ mCurVal = in[i] * decay[i] + mCurVal * (1 - decay[i]);
+ out[i] = mCurVal;
+ }
}
xml_node<> &Decay::read(xml_node<> &inode) {
+ Processor::read(inode);
- Processor::read(inode);
-
- delete mDecay;
- mDecay = readParameter(inode, "decay", DEFAULTDECAY);
+ delete mDecay;
+ mDecay = readParameter(inode, "decay", DEFAULTDECAY);
- return inode;
+ return inode;
}
xml_node<> &Decay::write(xml_node<> &onode) const {
-
- return onode;
+ return onode;
}
View
15 src/Decay.h
@@ -25,23 +25,16 @@
#define DEFAULTDECAY 1
class Decay : public Processor {
-public:
-
- Decay() : mCurVal(0) {
- mDecay = new Constant(DEFAULTDECAY);
- }
-
- virtual ~Decay() {
- delete mDecay;
- }
+ public:
+ Decay();
+ virtual ~Decay();
const Class *getClass() const { return &cls; }
static Object *newInstance() { return new Decay(); }
virtual void process(const sample_t* in, sample_t* out, int num);
-protected:
-
+ protected:
static Class cls;
sample_t mCurVal;
View
92 src/Delay.cpp
@@ -21,61 +21,71 @@ using namespace rapidxml;
Class Delay::cls(std::string("Delay"), newInstance);
+Delay::Delay(float period) : mGranular(0), mGranularOffset(0) {
+ mPeriod = new Constant(period);
+ mMemory = new Memory();
+}
+
+Delay::~Delay() {
+ delete mPeriod;
+ delete mMemory;
+}
+
void Delay::granulate(const sample_t *in, sample_t *out, uint per, int num) {
-
- for (int i = 0; i < num; i++) {
- if (mGranularOffset >= per * mProcessors.size())
- mGranularOffset = 0;
- out[i] = mGranularOffset++ >= per ? 0 : in[i];
- }
+ for (int i = 0; i < num; i++) {
+ if (mGranularOffset >= per * mProcessors.size())
+ mGranularOffset = 0;
+
+ out[i] = mGranularOffset++ >= per ? 0 : in[i];
+ }
}
void Delay::process(const sample_t* in, sample_t* out, int num) {
- sample_t periods[num], fit[num], buffer[num];
- mPeriod->process(in, periods, num);
- uint prevPeriod = round(periods[0]);
- uint curPeriod = round(periods[num - 1]);
-
- if (mGranular) {
- sample_t granulated[num];
- granulate(in, granulated, curPeriod, num);
- mMemory->storeSamples(granulated, num);
- }
- else
- mMemory->storeSamples(in, num);
-
- memset(out, 0, num * sizeof(sample_t));
-
- for (uint st = 0; st < mProcessors.size(); st++) {
- int offsetStart = st * prevPeriod + num;
- int offsetEnd = st * curPeriod;
- int procNum = offsetStart - offsetEnd;
-
- const sample_t *sampStart = mMemory->getPastSamples(offsetStart);
- Process::fit(sampStart, fit, procNum, num);
- mProcessors[st]->process(fit, buffer, num);
- Process::combine(buffer, out, out, num);
- }
-
- postProcess(in, out, num);
+ sample_t periods[num], fit[num], buffer[num];
+ mPeriod->process(in, periods, num);
+ uint prevPeriod = round(periods[0]);
+ uint curPeriod = round(periods[num - 1]);
+
+ if (mGranular) {
+ sample_t granulated[num];
+ granulate(in, granulated, curPeriod, num);
+ mMemory->storeSamples(granulated, num);
+ }
+ else
+ mMemory->storeSamples(in, num);
+
+ memset(out, 0, num * sizeof(sample_t));
+
+ for (uint st = 0; st < mProcessors.size(); st++) {
+ int offsetStart = st * prevPeriod + num;
+ int offsetEnd = st * curPeriod;
+ int procNum = offsetStart - offsetEnd;
+
+ const sample_t *sampStart = mMemory->getPastSamples(offsetStart);
+ Process::fit(sampStart, fit, procNum, num);
+ mProcessors[st]->process(fit, buffer, num);
+ Process::combine(buffer, out, out, num);
+ }
+
+ postProcess(in, out, num);
}
xml_node<> &Delay::read(xml_node<> &inode) {
- ProcessorList::read(inode);
+ ProcessorList::read(inode);
+
+ delete mPeriod;
+ mPeriod = Processor::readParameter(inode, "period", DEFAULTPERIOD);
- delete mPeriod;
- mPeriod = Processor::readParameter(inode, "period", DEFAULTPERIOD);
-
- xml_node<> *granNode = inode.first_node("granular");
- mGranular = granNode ? 1 : 0;
+ xml_node<> *granNode = inode.first_node("granular");
+ mGranular = granNode ? 1 : 0;
- return inode;
+ return inode;
}
xml_node<> &Delay::write(xml_node<> &onode) const {
- return onode;
+ return onode;
}
View
17 src/Delay.h
@@ -26,17 +26,9 @@
#define DEFAULTPERIOD 5000
class Delay : public ProcessorList {
-public:
-
- Delay(float period = DEFAULTPERIOD) : mGranular(0), mGranularOffset(0) {
- mPeriod = new Constant(period);
- mMemory = new Memory();
- }
-
- virtual ~Delay() {
- delete mPeriod;
- delete mMemory;
- }
+ public:
+ Delay(float period = DEFAULTPERIOD);
+ virtual ~Delay();
const Class *getClass() const { return &cls; }
static Object *newInstance() { return new Delay(); }
@@ -44,8 +36,7 @@ class Delay : public ProcessorList {
void granulate(const sample_t *in, sample_t *out, uint per, int num);
void process(const sample_t* in, sample_t* out, int num);
-protected:
-
+ protected:
static Class cls;
uint mGranular, mGranularOffset;
View
2  src/Differentiator.cpp
@@ -23,12 +23,10 @@ using namespace std;
Class Differentiator::cls(string("Differentiator"), newInstance);
void Differentiator::process(const sample_t* in, sample_t* out, int num) {
-
for (int i = 0; i < num; i++) {
out[i] = in[i] - mLastSamp;
mLastSamp = in[i];
}
-
postProcess(in, out, num);
}
View
6 src/Differentiator.h
@@ -23,8 +23,7 @@
#include "Effect.h"
class Differentiator : public Effect {
-public:
-
+ public:
Differentiator() : Effect::Effect(), mLastSamp(0) { }
virtual ~Differentiator() { }
@@ -33,8 +32,7 @@ class Differentiator : public Effect {
void process(const sample_t* in, sample_t* out, int num);
-protected:
-
+ protected:
static Class cls;
sample_t mLastSamp;
View
30 src/Effect.cpp
@@ -21,28 +21,32 @@ using namespace rapidxml;
Class Effect::cls(std::string("Effect"), newInstance);
-void Effect::process(const sample_t* in, sample_t* out, int num) {
+Effect::Effect(float wet) : Processor::Processor() {
+ mWet = new Constant(wet);
+}
- Processor::process(in, out, num);
- postProcess(in, out, num);
+Effect::~Effect() {
+ delete mWet;
}
-void Effect::postProcess(const sample_t* in, sample_t* out, int num) {
+void Effect::process(const sample_t* in, sample_t* out, int num) {
+ Processor::process(in, out, num);
+ postProcess(in, out, num);
+}
- sample_t wet[num];
- mWet->process(in, wet, num);
+void Effect::postProcess(const sample_t* in, sample_t* out, int num) {
+ sample_t wet[num];
+ mWet->process(in, wet, num);
- for (int i = 0; i < num; i++)
- out[i] = out[i] * wet[i] + in[i] * (1 - wet[i]);
+ for (int i = 0; i < num; i++)
+ out[i] = out[i] * wet[i] + in[i] * (1 - wet[i]);
}
xml_node<> &Effect::read(xml_node<> &inode) {
-
- mWet = Processor::readParameter(inode, "wet", DEFAULTWET);
- return inode;
+ mWet = Processor::readParameter(inode, "wet", DEFAULTWET);
+ return inode;
}
xml_node<> &Effect::write(xml_node<> &onode) const {
-
- return onode;
+ return onode;
}
View
14 src/Effect.h
@@ -24,15 +24,10 @@
#define DEFAULTWET 1.0
class Effect : public Processor {
-public:
+ public:
- Effect(float wet = DEFAULTWET) : Processor::Processor() {
- mWet = new Constant(wet);
- }
-
- virtual ~Effect() {
- delete mWet;
- }
+ Effect(float wet = DEFAULTWET);
+ virtual ~Effect();
const Class *getClass() const { return &cls; }
static Object *newInstance() { return new Effect(); }
@@ -40,8 +35,7 @@ class Effect : public Processor {
virtual void process(const sample_t* in, sample_t* out, int num);
virtual void postProcess(const sample_t* in, sample_t* out, int num);
-protected:
-
+ protected:
static Class cls;
Processor *mWet;
View
32 src/Harmonizer.cpp
@@ -22,29 +22,33 @@ using namespace std;
Class Harmonizer::cls(string("Harmonizer"), newInstance);
-void Harmonizer::process(const sample_t* in, sample_t* out, int num) {
+Harmonizer::Harmonizer() : Effect::Effect() {
+ mRoot = new Constant(DEFAULTROOT);
+}
+
+Harmonizer::~Harmonizer() {
+ delete mRoot;
+}
- sample_t root[num];
- mRoot->process(in, root, num);
+void Harmonizer::process(const sample_t* in, sample_t* out, int num) {
+ sample_t root[num];
+ mRoot->process(in, root, num);
- for (int i = 0; i < num; i++)
- out[i] = root[i] / round(in[i]);
+ for (int i = 0; i < num; i++)
+ out[i] = root[i] / round(in[i]);
- postProcess(in, out, num);
+ postProcess(in, out, num);
}
xml_node<> &Harmonizer::read(xml_node<> &inode) {
-
- Effect::read(inode);
+ Effect::read(inode);
- delete mRoot;
- mRoot = Processor::readParameter(inode, "root", DEFAULTROOT);
+ delete mRoot;
+ mRoot = Processor::readParameter(inode, "root", DEFAULTROOT);
- return inode;
+ return inode;
}
xml_node<> &Harmonizer::write(xml_node<> &onode) const {
-
- return onode;
+ return onode;
}
-
View
15 src/Harmonizer.h
@@ -25,23 +25,16 @@
#define DEFAULTROOT 10000
class Harmonizer : public Effect {
-public:
-
- Harmonizer() : Effect::Effect() {
- mRoot = new Constant(DEFAULTROOT);
- }
-
- virtual ~Harmonizer() {
- delete mRoot;
- }
+ public:
+ Harmonizer();
+ virtual ~Harmonizer();
const Class *getClass() const { return &cls; }
static Object *newInstance() { return new Harmonizer(); }
void process(const sample_t* in, sample_t* out, int num);
-protected:
-
+ protected:
static Class cls;
Processor *mRoot;
View
48 src/Keyboard.cpp
@@ -26,48 +26,48 @@ vector<KeyboardStomp*> KeyboardStream::controllers;
Class KeyboardStomp::cls(string("KeyboardStomp"), newInstance);
void KeyboardStream::readKey() {
+ char c = getch();
+ boost::shared_lock<boost::shared_mutex> lock(KeyboardStream::mutex);
- char c = getch();
- boost::shared_lock<boost::shared_mutex> lock(KeyboardStream::mutex);
-
- for (uint i = 0; i < KeyboardStream::controllers.size(); i++)
- KeyboardStream::controllers[i]->keyInput(c);
+ for (uint i = 0; i < KeyboardStream::controllers.size(); i++)
+ KeyboardStream::controllers[i]->keyInput(c);
}
void KeyboardStream::stream() {
-
- while (1)
- readKey();
+ while (1)
+ readKey();
}
void KeyboardStream::addController(KeyboardStomp *controller) {
+ boost::unique_lock<boost::shared_mutex> lock(KeyboardStream::mutex);
+ KeyboardStream::controllers.push_back(controller);
+}
- boost::unique_lock<boost::shared_mutex> lock(KeyboardStream::mutex);
- KeyboardStream::controllers.push_back(controller);
+KeyboardStomp::KeyboardStomp() : mCur(0), mToggle(0) {
+ KeyboardStream::addController(this);
+
+ mMapping.push_back("123\tqwaszx");
+ mMapping.push_back("45678ertyuidfghjcvbn");
+ mMapping.push_back("90-=op[]\\kl;'\nm,./");
}
void KeyboardStomp::process(const sample_t* in, sample_t* out, int num) {
-
- for (int i = 0; i < num; i++)
- out[i] = mCur;
+ for (int i = 0; i < num; i++)
+ out[i] = mCur;
}
void KeyboardStomp::keyInput(char c) {
-
- for (int i = 0; i < 3; i++) {
- if (mMapping[i].find(c) != string::npos)
- mCur = (mToggle && mCur == i) ? kOff : i;
- }
+ for (int i = 0; i < 3; i++) {
+ if (mMapping[i].find(c) != string::npos)
+ mCur = (mToggle && mCur == i) ? kOff : i;
+ }
}
xml_node<> &KeyboardStomp::read(xml_node<> &inode) {
-
- mToggle = inode.first_node("toggle") ? 1 : 0;
- return inode;
+ mToggle = inode.first_node("toggle") ? 1 : 0;
+ return inode;
}
xml_node<> &KeyboardStomp::write(xml_node<> &onode) const {
-
- return onode;
+ return onode;
}
-
View
20 src/Keyboard.h
@@ -26,13 +26,11 @@
class KeyboardStomp;
class KeyboardStream {
-public:
-
+ public:
static void stream();
static void addController(KeyboardStomp*);
-protected:
-
+ protected:
static boost::shared_mutex mutex;
static std::vector<KeyboardStomp*> controllers;
@@ -40,17 +38,10 @@ class KeyboardStream {
};
class KeyboardStomp : public Processor {
-public:
+ public:
enum { kOff = -1 };
- KeyboardStomp() : mCur(0), mToggle(0) {
- KeyboardStream::addController(this);
-
- mMapping.push_back("123\tqwaszx");
- mMapping.push_back("45678ertyuidfghjcvbn");
- mMapping.push_back("90-=op[]\\kl;'\nm,./");
- }
-
+ KeyboardStomp();
virtual ~KeyboardStomp() { }
const Class *getClass() const { return &cls; }
@@ -59,8 +50,7 @@ class KeyboardStomp : public Processor {
void process(const sample_t* in, sample_t* out, int num);
void keyInput(char c);
-protected:
-
+ protected:
static Class cls;
int mCur, mToggle;
View
202 src/Loop.cpp
@@ -20,170 +20,156 @@
using namespace std;
using namespace rapidxml;
-Class Loop::cls(std::string("Loop"), newInstance);
+Class Loop::cls(string("Loop"), newInstance);
-Loop::Loop() : Parallel::Parallel(), mSilentId(DEFAULTSILENT),
- mReverseId(DEFAULTREVERSE), mTrackQuant(1), mLastVal(0), mLastButton(0) {
-
- mControl = new Constant(DEFAULTSILENT);
- addProcessor(new Processor());
+Loop::Loop() : Parallel::Parallel(), mSilentId(DEFAULTSILENT), mTrackQuant(1),
+ mLastVal(0), mLastButton(0) {
+ mControl = new Constant(DEFAULTSILENT);
+ addProcessor(new Processor());
}
Loop::~Loop() {
+ delete mControl;
+}
- delete mControl;
+Loop::LoopTrack::LoopTrack(int quant) : mMemSize(DEFAULTSIZE),
+ mRecLength(0), mOffset(0),
+ mState(kRecording), mQuant(quant) {
+ mMemory = (sample_t*)calloc(mMemSize, sizeof(sample_t));
}
-void Loop::LoopTrack::process(const sample_t* in, sample_t* out, int num) {
+Loop::LoopTrack::~LoopTrack() {
+ free(mMemory);
+}
- memset(out, 0, num * sizeof(size_t));
+void Loop::LoopTrack::process(const sample_t* in, sample_t* out, int num) {
+ memset(out, 0, num * sizeof(size_t));
- if (mState == kRecording)
- record(in, num);
- else if (mState == kPlaying)
- play(out, num);
- else if (mState == kSilence)
- mOffset = (mOffset + num) % mRecLength;
+ if (mState == kRecording)
+ record(in, num);
+ else if (mState == kPlaying)
+ playBack(out, num);
+ else if (mState == kSilence)
+ mOffset = (mOffset + num) % mRecLength;
}
void Loop::LoopTrack::record(const sample_t *in, int num) {
+ mRecLength = mOffset + num;
+ resize();
- mRecLength = mOffset + num;
- resize();
-
- memcpy(mMemory + mOffset, in, num * sizeof(sample_t));
- mOffset += num;
+ memcpy(mMemory + mOffset, in, num * sizeof(sample_t));
+ mOffset += num;
}
void Loop::LoopTrack::stopRecording() {
-
- mState = kPlaying;
- mRecLength = (mOffset / mQuant + 1) * mQuant;
- resize();
+ mState = kPlaying;
+ mRecLength = (mOffset / mQuant + 1) * mQuant;
+ resize();
+ cout << mQuant << endl;
}
-void Loop::LoopTrack::play(sample_t *out, int num) {
-
- for (int i = 0; i < num; i++) {
- out[i] = mMemory[mOffset];
- mOffset = (mOffset + 1) %mRecLength;
- }
+void Loop::LoopTrack::playBack(sample_t *out, int num) {
+ for (int i = 0; i < num; i++) {
+ out[i] = mMemory[mOffset];
+ mOffset = (mOffset + 1) % mRecLength;
+ }
}
void Loop::LoopTrack::resize() {
+ if (mMemSize < mRecLength) {
- if (mMemSize < mRecLength) {
-
- mMemSize *= (mRecLength / mMemSize + 1);
- mMemory = (sample_t*)realloc(mMemory, mMemSize * sizeof(sample_t));
- }
+ mMemSize *= (mRecLength / mMemSize + 1);
+ mMemory = (sample_t*)realloc(mMemory, mMemSize * sizeof(sample_t));
+ }
}
void Loop::LoopTrack::toggle() {
-
- if (mState == kRecording)
- stopRecording();
- else if (mState == kPlaying)
- mState = kSilence;
- else if (mState == kSilence)
- mState = kPlaying;
+ if (mState == kRecording)
+ stopRecording();
+ else if (mState == kPlaying)
+ mState = kSilence;
+ else if (mState == kSilence)
+ mState = kPlaying;
}
void Loop::process(const sample_t* in, sample_t* out, int num) {
+ sample_t control[num];
+ mControl->process(in, control, num);
+ controlResponse(control[num - 1]);
- sample_t control[num];
- mControl->process(in, control, num);
- controlResponse(control[num - 1]);
-
- Parallel::process(in, out, num);
- postProcess(in, out, num);
+ Parallel::process(in, out, num);
+ postProcess(in, out, num);
}
void Loop::controlResponse(char val) {
-
- if (val != mLastVal)
- buttonPushed(val >= 0 ? val : mLastVal);
+ if (val != mLastVal)
+ buttonPushed(val >= 0 ? val : mLastVal);
- mLastVal = val;
+ mLastVal = val;
}
void Loop::buttonPushed(char but) {
-
-
- if (but == mSilentId) {
- if (anyPlaying())
- silenceAll();
- else
- playAll();
+ if (but == mSilentId) {
+ if (anyPlaying())
+ silenceAll();
+ else
+ playAll();
+ }
+ else {
+ map<int, LoopTrack*>::const_iterator found = mTrackMap.find(but);
+ map<int, LoopTrack*>::const_iterator last = mTrackMap.find(mLastButton);
+ int recording = last != mTrackMap.end() && last->second->isRecording();
+ if (recording) {
+ last->second->toggle();
+ int length = last->second->getRecLength();
+ mTrackQuant = mTrackQuant < length ? length : mTrackQuant;
}
- else if (but == mReverseId) {
+ if (found == mTrackMap.end()) {
+ LoopTrack *newLoop = new LoopTrack(getMinQuant());
+ mTrackMap[but] = newLoop;
+ addProcessor(newLoop);
}
- else {
- map<int, LoopTrack*>::const_iterator found = mTrackMap.find(but);
-
- if (found == mTrackMap.end()) {
- LoopTrack *newLoop = new LoopTrack(getMinQuant());
- mTrackMap[but] = newLoop;
- addProcessor(newLoop);
- }
- else
- mTrackMap[but]->toggle();
- }
-
- map<int, LoopTrack*>::const_iterator found = mTrackMap.find(mLastButton);
- if (found != mTrackMap.end() && found->second->isRecording()) {
- found->second->play();
- int length = found->second->getRecLength();
- mTrackQuant = mTrackQuant < length ? length : mTrackQuant;
- }
-
- mLastButton = but;
+ else if (!recording || mLastButton != but)
+ found->second->toggle();
+ }
+ mLastButton = but;
}
int Loop::anyPlaying() {
+ map<int, LoopTrack*>::const_iterator it;
+ for (it = mTrackMap.begin(); it != mTrackMap.end(); it++)
+ if (it->second->isPlaying())
+ return 1;
- map<int, LoopTrack*>::const_iterator it, end = mTrackMap.end();
- for (it = mTrackMap.begin(); it != end; it++)
- if (it->second->isPlaying())
- return 1;
-
- return 0;
+ return 0;
}
void Loop::silenceAll() {
-
- map<int, LoopTrack*>::const_iterator it, end = mTrackMap.end();
- for (it = mTrackMap.begin(); it != end; it++)
- it->second->silence();
+ map<int, LoopTrack*>::const_iterator it, end = mTrackMap.end();
+ for (it = mTrackMap.begin(); it != end; it++)
+ it->second->silence();
}
void Loop::playAll() {
-
- map<int, LoopTrack*>::const_iterator it, end = mTrackMap.end();
- for (it = mTrackMap.begin(); it != end; it++)
- it->second->play();
+ map<int, LoopTrack*>::const_iterator it, end = mTrackMap.end();
+ for (it = mTrackMap.begin(); it != end; it++)
+ it->second->play();
}
xml_node<> &Loop::read(xml_node<> &inode) {
+ xml_node<> *val = inode.first_node("silent");
+ mSilentId = val ? atoi(val->value()) : DEFAULTSILENT;
- xml_node<> *val = inode.first_node("silent");
- mSilentId = val ? atoi(val->value()) : DEFAULTSILENT;
-
- val = inode.first_node("reverse");
- mReverseId = val ? atoi(val->value()) : DEFAULTREVERSE;
+ val = inode.first_node("quant");
+ mTrackQuant = val ? atoi(val->value()) : 1;
- val = inode.first_node("quant");
- mTrackQuant = val ? atoi(val->value()) : 1;
+ delete mControl;
+ mControl = Processor::readParameter(inode, "control", DEFAULTSILENT);
- delete mControl;
- mControl = Processor::readParameter(inode, "control", DEFAULTSILENT);
-
- return inode;
+ return inode;
}
xml_node<> &Loop::write(xml_node<> &onode) const {
-
- return onode;
+ return onode;
}
-
View
24 src/Loop.h
@@ -27,10 +27,9 @@
#define DEFAULTSIZE 480000
#define DEFAULTSILENT 0
-#define DEFAULTREVERSE 9
class Loop : public Parallel {
-public:
+ public:
Loop();
virtual ~Loop();
@@ -46,17 +45,13 @@ class Loop : public Parallel {
void silenceAll();
void playAll();
-protected:
-
+ protected:
class LoopTrack : public Processor {
- public:
+ public:
enum { kRecording, kPlaying, kSilence };
- LoopTrack(int quant = 1) : mMemSize(DEFAULTSIZE), mRecLength(0),
- mOffset(0), mState(kRecording), mQuant(quant) {
-
- mMemory = (sample_t*)calloc(mMemSize, sizeof(sample_t));
- }
+ LoopTrack(int quant = 1);
+ virtual ~LoopTrack();
void process(const sample_t* in, sample_t* out, int num);
void toggle();
@@ -67,11 +62,11 @@ class Loop : public Parallel {
int isRecording() { return mState == kRecording; }
int getRecLength() { return mRecLength; }
- protected:
-
+ protected:
+
void record(const sample_t *in, int num);
void stopRecording();
- void play(sample_t *out, int num);
+ void playBack(sample_t *out, int num);
void resize();
int mMemSize, mRecLength, mOffset, mState, mQuant;
@@ -81,7 +76,7 @@ class Loop : public Parallel {
static Class cls;
Processor *mControl;
- int mSilentId, mReverseId, mTrackQuant;
+ int mSilentId, mTrackQuant;
std::map<int, LoopTrack*> mTrackMap;
char mLastVal, mLastButton;
@@ -90,4 +85,3 @@ class Loop : public Parallel {
};
#endif
-
View
20 src/Memory.cpp
@@ -17,17 +17,19 @@
#include "Memory.h"
-void Memory::storeSamples(const sample_t *in, int num) {
+Memory::Memory() : mOffset(0) {
+ memset(mMemory, 0, MAXMEMORY * 3 * sizeof(sample_t));
+}
- for (int i = 0; i < num; i++) {
- mMemory[mOffset] = mMemory[mOffset + MAXMEMORY] =
- mMemory[mOffset + MAXMEMORY * 2] = in[i];
- mOffset = (mOffset + 1) % MAXMEMORY;
- }
+void Memory::storeSamples(const sample_t *in, int num) {
+ for (int i = 0; i < num; i++) {
+ mMemory[mOffset] = mMemory[mOffset + MAXMEMORY] =
+ mMemory[mOffset + MAXMEMORY * 2] = in[i];
+ mOffset = (mOffset + 1) % MAXMEMORY;
+ }
}
const sample_t* Memory::getPastSamples(int num) {
-
- int index = (MAXMEMORY + mOffset - num) % MAXMEMORY;
- return &mMemory[MAXMEMORY + index];
+ int index = (MAXMEMORY + mOffset - num) % MAXMEMORY;
+ return &mMemory[MAXMEMORY + index];
}
View
10 src/Memory.h
@@ -19,24 +19,20 @@
#define MEMORY_H
#include <string.h>
-
#include "Setup.h"
#define MAXMEMORY 4800000
class Memory {
-public:
-
- Memory() : mOffset(0) {
- memset(mMemory, 0, MAXMEMORY * 3 * sizeof(sample_t));
- }
+ public:
+ Memory();
virtual ~Memory() { }
virtual void storeSamples(const sample_t *in, int num);
const sample_t* getPastSamples(int num);
-protected:
+ protected:
sample_t mMemory[MAXMEMORY * 3];
long mOffset;
View
183 src/Midi.cpp
@@ -28,152 +28,149 @@ boost::thread MidiStream::midiThread(MidiStream::stream);
Class MidiStomp::cls(std::string("MidiStomp"), MidiStomp::newInstance);
Class MidiExpression::cls(std::string("MidiExpression"),
- MidiExpression::newInstance);
+ MidiExpression::newInstance);
void MidiStream::addController(MidiControl *controller) {
-
- boost::unique_lock<boost::shared_mutex> lock(MidiStream::mutex);
- MidiStream::controllers.push_back(controller);
+ boost::unique_lock<boost::shared_mutex> lock(MidiStream::mutex);
+ MidiStream::controllers.push_back(controller);
}
void MidiStream::readMidi() {
-
- unsigned char inbytes[4];
- int status = read(MidiStream::seqfd, &inbytes, sizeof(inbytes));
+ unsigned char inbytes[4];
+ int status = read(MidiStream::seqfd, &inbytes, sizeof(inbytes));
- if (status < 0) {
- //TODO Some sort of error checking
- }
+ if (status < 0) {
+ //TODO Some sort of error checking
+ }
- boost::shared_lock<boost::shared_mutex> lock(MidiStream::mutex);
- if (inbytes[0] == SEQ_MIDIPUTC)
- for (uint i = 0; i < MidiStream::controllers.size(); i++)
- MidiStream::controllers[i]->midiInput(inbytes[1]);
+ boost::shared_lock<boost::shared_mutex> lock(MidiStream::mutex);
+ if (inbytes[0] == SEQ_MIDIPUTC)
+ for (uint i = 0; i < MidiStream::controllers.size(); i++)
+ MidiStream::controllers[i]->midiInput(inbytes[1]);
}
void MidiStream::stream() {
-
- MidiStream::seqfd = open(MIDI_DEVICE, O_RDONLY);
- //TODO Some sort of error checking
+ MidiStream::seqfd = open(MIDI_DEVICE, O_RDONLY);
+ //TODO Some sort of error checking
- while (1)
- readMidi();
+ while (1)
+ readMidi();
}
MidiControl::MidiControl() : Processor::Processor(), mVal(0), mMatches(0),
- mLowBound(0), mUpBound(-1) {
+ mLowBound(0), mUpBound(-1) {
MidiStream::addController(this);
-}
+ }
void MidiControl::process(const sample_t* in, sample_t* out, int num) {
-
- for (int i = 0; i < num; i++)
- out[i] = mVal;
+ for (int i = 0; i < num; i++)
+ out[i] = mVal;
}
void MidiControl::midiInput(unsigned char val) {
-
- if (mMatches >= mSignal.size() && val >= mLowBound && val <= mUpBound) {
- matchedValue(val);
- mMatches = 0;
- }
- mMatches = val == mSignal[mMatches] ? mMatches + 1 : 0;
+ if (mMatches >= mSignal.size() && val >= mLowBound && val <= mUpBound) {
+ matchedValue(val);
+ mMatches = 0;
+ }
+ mMatches = val == mSignal[mMatches] ? mMatches + 1 : 0;
}
xml_node<> &MidiControl::read(xml_node<> &inode) {
-
- char *tok = strtok(inode.first_attribute("id")->value(), ", ");
- mSignal.clear();
- while (tok != NULL) {
- mSignal.push_back(atoi(tok));
- tok = strtok(NULL, ", ");
- }
-
- xml_node<> *val = inode.first_node("range");
- if (val) {
- char *tok = strtok(inode.first_node("range")->value(), "-, ");
- mLowBound = atoi(tok);
-
- tok = strtok(NULL, "-, ");
- mUpBound = atoi(tok);
- }
- else {
- mLowBound = 0;
- mUpBound = -1;
- }
-
- return inode;
+ char *tok = strtok(inode.first_attribute("id")->value(), ", ");
+ mSignal.clear();
+ while (tok != NULL) {
+ mSignal.push_back(atoi(tok));
+ tok = strtok(NULL, ", ");
+ }
+
+ xml_node<> *val = inode.first_node("range");
+ if (val) {
+ char *tok = strtok(inode.first_node("range")->value(), "-, ");
+ mLowBound = atoi(tok);
+
+ tok = strtok(NULL, "-, ");
+ mUpBound = atoi(tok);
+ }
+ else {
+ mLowBound = 0;
+ mUpBound = -1;
+ }
+ return inode;
}
xml_node<> &MidiControl::write(xml_node<> &onode) const {
-
- return onode;
+ return onode;
}
void MidiStomp::matchedValue(char val) {
-
- mVal = (mToggle && val == mVal) ? kOff : val;
+ mVal = (mToggle && val == mVal) ? kOff : val;
}
xml_node<> &MidiStomp::read(xml_node<> &inode) {
+ MidiControl::read(inode);
- MidiControl::read(inode);
-
- mToggle = inode.first_node("toggle") ? 1 : 0;
+ mToggle = inode.first_node("toggle") ? 1 : 0;
- return inode;
+ return inode;
}
xml_node<> &MidiStomp::write(xml_node<> &onode) const {
+ return onode;
+}
- return onode;
+MidiExpression::MidiExpression() : MidiControl(), mMidiMax(0),
+ mMidiMin(0), mScale(0) {
+ mMin = new Constant(DEFAULTMIN);
+ mMax = new Constant(DEFAULTMAX);
+}
+
+MidiExpression::~MidiExpression() {
+ delete mMin;
+ delete mMax;
}
void MidiExpression::process(const sample_t* in, sample_t* out, int num) {
+ sample_t min[num], max[num];
+ mMin->process(in, min, num);
+ mMax->process(in, max, num);
+
+ for (int i = 0; i < num; i++) {
+ float perc = (mVal - mMidiMin) / (mMidiMax - mMidiMin);
- sample_t min[num], max[num];
- mMin->process(in, min, num);
- mMax->process(in, max, num);
-
- for (int i = 0; i < num; i++) {
- float perc = (mVal - mMidiMin) / (mMidiMax - mMidiMin);
-
- if (mScale == kLin)
- out[i] = perc * max[i] + (1 - perc) * min[i];
- else {
- float logMin = log2(min[i]);
- float logMax = log2(max[i]);
- out[i] = pow(2, perc * logMax + (1 - perc) * logMin);
- }
+ if (mScale == kLin)
+ out[i] = perc * max[i] + (1 - perc) * min[i];
+ else {
+ float logMin = log2(min[i]);
+ float logMax = log2(max[i]);
+ out[i] = pow(2, perc * logMax + (1 - perc) * logMin);
}
+ }
}
xml_node<> &MidiExpression::read(xml_node<> &inode) {
+ MidiControl::read(inode);
- MidiControl::read(inode);
+ char *scale = inode.first_attribute("scale")->value();
+ if (strlen(scale) > 3)
+ scale[3] = 0;
- char *scale = inode.first_attribute("scale")->value();
- if (strlen(scale) > 3)
- scale[3] = 0;
+ if (strcmp(scale, "lin") == 0)
+ mScale = kLin;
+ else
+ mScale = kExp;
- if (strcmp(scale, "lin") == 0)
- mScale = kLin;
- else
- mScale = kExp;
-
- mMidiMin = atoi(inode.first_attribute("midimin")->value());
- mMidiMax = atoi(inode.first_attribute("midimax")->value());
+ mMidiMin = atoi(inode.first_attribute("midimin")->value());
+ mMidiMax = atoi(inode.first_attribute("midimax")->value());
- delete mMin;
- mMin = readParameter(inode, "min", DEFAULTMIN);
- delete mMax;
- mMax = readParameter(inode, "max", DEFAULTMAX);
+ delete mMin;
+ mMin = readParameter(inode, "min", DEFAULTMIN);
+ delete mMax;
+ mMax = readParameter(inode, "max", DEFAULTMAX);
- return inode;
+ return inode;
}
xml_node<> &MidiExpression::write(xml_node<> &onode) const {
-
- return onode;
+ return onode;
}
View
36 src/Midi.h
@@ -34,14 +34,12 @@
class MidiControl;
class MidiStream {
-public:
-
+ public:
static void addController(MidiControl *controller);
static void readMidi();
static void stream();
-protected:
-
+ protected:
static boost::shared_mutex mutex;
static boost::thread midiThread;
static int seqfd;
@@ -49,7 +47,7 @@ class MidiStream {
};
class MidiControl : public Processor {
-public:
+ public:
enum { kOff = -1 };
MidiControl();
@@ -59,8 +57,7 @@ class MidiControl : public Processor {
void midiInput(unsigned char val);
virtual void matchedValue(char val) { mVal = val; }
-protected:
-
+ protected:
sample_t mVal;
uint mMatches;
std::vector<unsigned char> mSignal;
@@ -70,10 +67,8 @@ class MidiControl : public Processor {
virtual rapidxml::xml_node<> &write(rapidxml::xml_node<> &) const;
};
-
class MidiStomp : public MidiControl {
-public:
-
+ public:
MidiStomp() : MidiControl(), mToggle(0) { }
virtual ~MidiStomp() { }
@@ -81,8 +76,7 @@ class MidiStomp : public MidiControl {
static Object *newInstance() { return new MidiStomp(); }
void matchedValue(char val);
-protected:
-
+ protected:
static Class cls;
int mToggle;
@@ -90,29 +84,19 @@ class MidiStomp : public MidiControl {
virtual rapidxml::xml_node<> &write(rapidxml::xml_node<> &) const;
};
-
class MidiExpression : public MidiControl {
-public:
-
+ public:
enum { kExp, kLin };
- MidiExpression() : MidiControl(), mMidiMax(0), mMidiMin(0), mScale(0) {
- mMin = new Constant(DEFAULTMIN);
- mMax = new Constant(DEFAULTMAX);
- }
-
- ~MidiExpression() {
- delete mMin;
- delete mMax;
- }
+ MidiExpression();
+ virtual ~MidiExpression();
const Class *getClass() const { return &cls; }
static Object *newInstance() { return new MidiExpression(); }
virtual void process(const sample_t* in, sample_t* out, int num);
-protected:
-
+ protected:
static Class cls;
char mMidiMax, mMidiMin;
View
59 src/Oscillator.cpp
@@ -22,43 +22,54 @@ using namespace std;
Class Oscillator::cls(std::string("Oscillator"), newInstance);
+Oscillator::Oscillator(int period, float min, float max) :
+ Processor::Processor(), mOffset(0) {
+ mMin = new Constant(min);
+ mMax = new Constant(max);
+ mPeriod = new Constant(period);
+}
+
+Oscillator::~Oscillator() {
+ delete mMin;
+ delete mMax;
+ delete mPeriod;
+}
+
void Oscillator::process(const sample_t* in, sample_t* out, int num) {
- sample_t period[num], max[num], min[num];
- mPeriod->process(in, period, num);
- mMax->process(in, max, num);
- mMin->process(in, min, num);
+ sample_t period[num], max[num], min[num];
+ mPeriod->process(in, period, num);
+ mMax->process(in, max, num);
+ mMin->process(in, min, num);
- for (int i = 0; i < num; i ++) {
- float val = mWaveFunc(1.0 * mOffset++ / period[i]);
- out[i] = val * max[i] + (1 - val) * min[i];
+ for (int i = 0; i < num; i ++) {
+ float val = mWaveFunc(1.0 * mOffset++ / period[i]);
+ out[i] = val * max[i] + (1 - val) * min[i];
- if (mOffset >= period[i])
- mOffset -= period[i];
- }
+ if (mOffset >= period[i])
+ mOffset -= period[i];
+ }
}
void Oscillator::setPeriod(float period) {
-
- delete mPeriod;
- mPeriod = new Constant(period);
+ delete mPeriod;
+ mPeriod = new Constant(period);
}
xml_node<> &Oscillator::read(xml_node<> &inode) {
- mWaveFunc =
- WaveFunctions::getFunction(inode.first_attribute("wave")->value());
+ mWaveFunc =
+ WaveFunctions::getFunction(inode.first_attribute("wave")->value());
- delete mPeriod;
- mPeriod = readParameter(inode, "period", DEFAULTPERIOD);
- delete mMin;
- mMin = readParameter(inode, "min", DEFAULTMIN);
- delete mMax;
- mMax = readParameter(inode, "max", DEFAULTMAX);
+ delete mPeriod;
+ mPeriod = readParameter(inode, "period", DEFAULTPERIOD);
+ delete mMin;
+ mMin = readParameter(inode, "min", DEFAULTMIN);
+ delete mMax;
+ mMax = readParameter(inode, "max", DEFAULTMAX);
- return inode;
+ return inode;
}
xml_node<> &Oscillator::write(xml_node<> &onode) const {
-
- return onode;
+ return onode;
}
View
18 src/Oscillator.h
@@ -28,20 +28,11 @@
#define DEFAULTPERIOD 4000
class Oscillator : public Processor {
-public:
+ public:
Oscillator(int period = DEFAULTPERIOD, float min = DEFAULTMIN,
- float max = DEFAULTMAX) : Processor::Processor(), mOffset(0) {
- mMin = new Constant(min);
- mMax = new Constant(max);
- mPeriod = new Constant(period);
- }
-
- virtual ~Oscillator() {
- delete mMin;
- delete mMax;
- delete mPeriod;
- }
+ float max = DEFAULTMAX);
+ virtual ~Oscillator();
const Class *getClass() const { return &cls; }
static Object *newInstance() { return new Oscillator(); }
@@ -49,8 +40,7 @@ class Oscillator : public Processor {
virtual void process(const sample_t* in, sample_t* out, int num);
void setPeriod(float period);
-protected:
-
+ protected:
static Class cls;
Processor *mMin, *mMax, *mPeriod;
View
2  src/Parallel.cpp
@@ -22,14 +22,12 @@ using namespace std;
Class Parallel::cls(string("Parallel"), newInstance);
void Parallel::process(const sample_t* in, sample_t* out, int num) {
-
memset(out, 0, num * sizeof(sample_t));
for (uint i = 0; i < mProcessors.size(); i++) {
mProcessors[i]->process(in, mBuffer, num);
Process::combine(mBuffer, out, out, num);
}
-
postProcess(in, out, num);
}
View
6 src/Parallel.h
@@ -21,15 +21,13 @@
#include "ProcessorList.h"
class Parallel : public ProcessorList {
-public:
-
+ public:
const Class *getClass() const { return &cls; }
static Object *newInstance() { return new Parallel(); }
void process(const sample_t* in, sample_t* out, int num);
-protected:
-
+ protected:
static Class cls;
sample_t mBuffer[MAXBUFFER];
View
83 src/Pitch.cpp
@@ -1,83 +0,0 @@
-/*
- * Copyright 2011 Matthew Tytel
- *
- * dfex 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 3 of the License, or
- * (at your option) any later version.
- *
- * dfex 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 dfex. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "Pitch.h"
-
-using namespace rapidxml;
-using namespace std;
-
-Class Pitch::cls(string("Pitch"), newInstance);
-
-Pitch::Pitch() : Effect::Effect(), mTransformOffset(0) {
- mMemory = new Memory();
- mInput = (double*)fftw_malloc(sizeof(double) * DEFAULTSIZE);
- mResult = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * DEFAULTSIZE);
- mInvResult = (double*)fftw_malloc(sizeof(double) * DEFAULTSIZE);
-
- mForward = fftw_plan_dft_r2c_1d(DEFAULTSIZE, mInput, mResult, FFTW_MEASURE);
- mBackward = fftw_plan_dft_c2r_1d(DEFAULTSIZE, mResult, mInvResult,
- FFTW_MEASURE);
-}
-
-Pitch::~Pitch() {
- fftw_free(mInput);
- fftw_free(mResult);
- fftw_free(mInvResult);
-
- fftw_free(mForward);
- fftw_free(mBackward);
-}
-
-void Pitch::process(const sample_t* in, sample_t* out, int num) {
-
- memmove(mInput, mInput + num, num * sizeof(double));
-
- for (int i = 0; i < num; i++) {
- mInput[num + i] = in[i];
- out[i] = (1 + cos(PI * i / num)) / 2 *
- mInvResult[num + i] / DEFAULTSIZE;
- }
-
- fftw_execute(mForward);
-
- for (int i = DEFAULTSIZE / 2 - 1; i >= 0; i--) {
- mResult[i * 2][0] = mResult[i][0];
- mResult[i * 2][1] = mResult[i][1];
- mResult[i * 2 + 1][0] = 0;
- mResult[i * 2 + 1][1] = 0;
- }
-
- fftw_execute(mBackward);
-
- for (int i = 0; i < num; i++)
- out[i] += (1 - cos(PI * i / num)) / 2 *
- mInvResult[i] / DEFAULTSIZE;
-
- postProcess(in, out, num);
-}
-
-xml_node<> &Pitch::read(xml_node<> &inode) {
-
- Effect::read(inode);
- return inode;
-}
-
-xml_node<> &Pitch::write(xml_node<> &onode) const {
-
- return onode;
-}
-
View
55 src/Pitch.h
@@ -1,55 +0,0 @@
-/*
- * Copyright 2011 Matthew Tytel
- *
- * dfex 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 3 of the License, or
- * (at your option) any later version.
- *
- * dfex 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 dfex. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef PITCH_H
-#define PITCH_H
-
-#include <stdlib.h>
-#include <math.h>
-#include <fftw3.h>
-#include "Effect.h"
-#include "Memory.h"
-
-#define DEFAULTSIZE 2048
-#define DEFAULTOVERLAP 1024
-
-class Pitch : public Effect {
-public:
-
- Pitch();
- ~Pitch();
-
- const Class *getClass() const { return &cls; }
- static Object *newInstance() { return new Pitch(); }
-
- void process(const sample_t* in, sample_t* out, int num);
-
-protected:
-
- static Class cls;
-
- int mTransformOffset;
- Memory *mMemory;
- double *mInput, *mInvResult;
- fftw_complex *mResult;
- fftw_plan mForward, mBackward;
-
- virtual rapidxml::xml_node<> &read(rapidxml::xml_node<> &);
- virtual rapidxml::xml_node<> &write(rapidxml::xml_node<> &) const;
-};
-
-#endif
View
37 src/Process.cpp
@@ -20,38 +20,33 @@
using namespace std;
void Process::combine(const sample_t* from1, const sample_t* from2,
- sample_t* to, int num) {
-
- for (int i = 0; i < num; i++)
- to[i] = from1[i] + from2[i];
+ sample_t* to, int num) {
+ for (int i = 0; i < num; i++)
+ to[i] = from1[i] + from2[i];
}
sample_t Process::linearInterpolate(sample_t left, sample_t right, float perc) {
-
- return perc * right + (1 - perc) * left;
+ return perc * right + (1 - perc) * left;
}
void Process::fit(const sample_t* from, sample_t* to, int numFrom, int numTo) {
-
- float fromInc = 1.0 * numFrom / numTo;
- float fromIndex = 0;
-
- for (int i = 0; i < numTo; i++) {
- to[i] = linearInterpolate(from[(int)(fromIndex)],
- from[(int)ceil(fromIndex)], fromIndex - floor(fromIndex));
- fromIndex += fromInc;
- }
+ float fromInc = 1.0 * numFrom / numTo;
+ float fromIndex = 0;
+
+ for (int i = 0; i < numTo; i++) {
+ to[i] = linearInterpolate(from[(int)(fromIndex)],
+ from[(int)ceil(fromIndex)], fromIndex - floor(fromIndex));
+ fromIndex += fromInc;
+ }
}
void Process::invert(const sample_t* from, sample_t* to, int num) {
-
- for (int i = 0; i < num; i++)
- to[i] = -from[i];
+ for (int i = 0; i < num; i++)
+ to[i] = -from[i];
}
void Process::power(const sample_t* from, sample_t* to, float exp, int num) {
-
- for (int i = 0; i < num; i++)
- to[i] = pow(from[i], exp);
+ for (int i = 0; i < num; i++)
+ to[i] = pow(from[i], exp);
}
View
3  src/Process.h
@@ -31,8 +31,7 @@
#include "Setup.h"
class Process {
-public:
-
+ public:
static sample_t linearInterpolate(sample_t, sample_t, float);
static void combine(const sample_t*, const sample_t*, sample_t*, int);
static void fit(const sample_t*, sample_t*, int, int);
View
67 src/Processor.cpp
@@ -25,61 +25,54 @@ using namespace std;
Class Processor::cls(string("Processor"), newInstance);
Processor *Processor::createConstant(const char *val) {
+ float num = atof(val);
- float num = atof(val);
+ if (num || val[0] == '0')
+ return new Constant(num);
- if (num || val[0] == '0')
- return new Constant(num);
-
- cerr << "Error reading configuration: " << val <<
- " is not a valid Processor" << endl;
- exit(1);
+ cerr << "Error reading configuration: " << val <<
+ " is not a valid Processor" << endl;
+ exit(1);
}
void Processor::process(const sample_t* in, sample_t* out, int num) {
-
- memcpy(out, in, num * sizeof(sample_t));
+ memcpy(out, in, num * sizeof(sample_t));
}
Processor* Processor::readProcessor(xml_node<> &inode) {
-
- string clsName = string(inode.name());
- const Class *eCls = Class::ForName(clsName);
-
- if (!eCls) {
- cerr << "Error reading configuration: No Processor '"
- << clsName << "'" << endl;
- exit(1);
- }
- Processor *p = dynamic_cast<Processor *>(eCls->NewInstance());
- inode >> *p;
-
- return p;
+ string clsName = string(inode.name());
+ const Class *eCls = Class::ForName(clsName);
+
+ if (!eCls) {
+ cerr << "Error reading configuration: No Processor '"
+ << clsName << "'" << endl;
+ exit(1);
+ }
+ Processor *p = dynamic_cast<Processor *>(eCls->NewInstance());
+ inode >> *p;
+
+ return p;
}
Processor *Processor::readParameter(rapidxml::xml_node<> &node,
- const char *tag, float defaultVal) {
+ const char *tag, float defaultVal) {
+ xml_node<> *found_node = node.first_node(tag);
- xml_node<> *found_node = node.first_node(tag);
+ if (found_node) {
+ xml_node<> *processor = found_node->first_node();
+ if (processor)
+ return Processor::readProcessor(*processor);
- if (found_node) {
- xml_node<> *processor = found_node->first_node();
- if (processor)
- return Processor::readProcessor(*processor);
+ return createConstant(found_node->value());
+ }
- return createConstant(found_node->value());
- }
-
- return new Constant(defaultVal);
+ return new Constant(defaultVal);
}
xml_node<> &Processor::read(xml_node<> &inode) {
-
- return inode;
+ return inode;
}
xml_node<> &Processor::write(xml_node<> &onode) const {
-
- return onode;
+ return onode;
}
-
View
13 src/Processor.h
@@ -26,28 +26,27 @@
#include "Setup.h"
#include "Class.h"
#include "Process.h"
+#include "rapidxml.hpp"
class Processor : public Object {
-public:
-
+ public:
const Class *getClass() const { return &cls; }
static Object *newInstance() { return new Processor(); }
static Processor *readProcessor(rapidxml::xml_node<> &);
static Processor *readParameter(rapidxml::xml_node<> &,
- const char *, float);
+ const char *, float);
static Processor *createConstant(const char *);
virtual void process(const sample_t* in, sample_t* out, int num);
virtual void postProcess(const sample_t* in, sample_t* out, int num) { }
friend rapidxml::xml_node<> &operator<<(rapidxml::xml_node<> &onode,
- const Processor &p) { return p.write(onode); }
+ const Processor &p) { return p.write(onode); }
friend rapidxml::xml_node<> &operator>>(rapidxml::xml_node<> &inode,
- Processor &p) { return p.read(inode); }
-
-protected:
+ Processor &p) { return p.read(inode); }
+ protected:
static Class cls;
virtual rapidxml::xml_node<> &read(rapidxml::xml_node<> &);
View
128 src/ProcessorList.cpp
@@ -25,99 +25,93 @@ using namespace std;
Class ProcessorList::cls(std::string("ProcessorList"), newInstance);
void ProcessorList::addProcessor(Processor* p) {
-
- mProcessors.push_back(p);
+ mProcessors.push_back(p);
}
void ProcessorList::readList(xml_node<> &inode, vector<Series*> *procs) {
-
- xml_node<> *pList = inode.first_node("processors");
- if (pList) {
- for (xml_node<> *proc = pList->first_node(); proc;
- proc = proc->next_sibling()) {
- Series *s = new Series();
- Processor *p = Processor::readProcessor(*proc);
- s->addProcessor(p);
- procs->push_back(s);
- }
+ xml_node<> *pList = inode.first_node("processors");
+ if (pList) {
+ for (xml_node<> *proc = pList->first_node(); proc;
+ proc = proc->next_sibling()) {
+ Series *s = new Series();
+ Processor *p = Processor::readProcessor(*proc);
+ s->addProcessor(p);
+ procs->push_back(s);
}
- else {
- xml_node<> *numNode = inode.first_node("num");
-
- if (!numNode) {
- cerr << "Expected num or processors tag in ProcessorsList" << endl;
- exit(1);
- }
+ }
+ else {
+ xml_node<> *numNode = inode.first_node("num");
- int num = atof(numNode->value());
- for (int i = 0; i < num; i++)
- procs->push_back(new Series());
+ if (!numNode) {
+ cerr << "Expected num or processors tag in ProcessorsList" << endl;
+ exit(1);
}
+ int num = atof(numNode->value());
+ for (int i = 0; i < num; i++)
+ procs->push_back(new Series());
+ }
}
void ProcessorList::loadAllModifications(xml_node<> &node, int length,
- vector<pair<xml_node<> *, Oscillator*> > *mods) {
-
- for (xml_node<> *chi = node.first_node(); chi; chi = chi->next_sibling()) {
- if (chi->first_attribute("mod")) {
- Oscillator *o = new Oscillator();
- *chi->first_node() >> *o;
- o->setPeriod(length);
- mods->push_back(pair<xml_node<>*, Oscillator*>(chi, o));
- chi->remove_all_nodes();
- }
- else
- loadAllModifications(*chi, length, mods);
+ vector<pair<xml_node<> *,
+ Oscillator*> > *mods) {
+ for (xml_node<> *chi = node.first_node(); chi; chi = chi->next_sibling()) {
+ if (chi->first_attribute("mod")) {
+ Oscillator *o = new Oscillator();
+ *chi->first_node() >> *o;
+ o->setPeriod(length);
+ mods->push_back(pair<xml_node<>*, Oscillator*>(chi, o));
+ chi->remove_all_nodes();
}
+ else
+ loadAllModifications(*chi, length, mods);
+ }
}
void ProcessorList::readModifier(xml_node<> &inode, vector<Series*> *procs) {
+ vector<pair<xml_node<>*, Oscillator*> > mods;
+ loadAllModifications(inode, procs->size(), &mods);
+ xml_document<> doc;
- vector<pair<xml_node<>*, Oscillator*> > mods;
- loadAllModifications(inode, procs->size(), &mods);
- xml_document<> doc;
-
- sample_t vals[mods.size()][procs->size()], blank[procs->size()];
-
- for (uint m = 0; m < mods.size(); m++)
- mods[m].second->process(blank, vals[m], procs->size());
+ sample_t vals[mods.size()][procs->size()], blank[procs->size()];
- for (uint p = 0; p < procs->size(); p++) {
- for (uint m = 0; m < mods.size(); m++) {
- ostringstream buffer;
- buffer << vals[m][p];
- char *val = doc.allocate_string(buffer.str().c_str());
- mods[m].first->value(val);