From 694eab3b7cb6e73f99aa992bdb1f47761c4a2e5f Mon Sep 17 00:00:00 2001 From: "Rachel Fae Fox (foxiepaws)" Date: Tue, 10 Mar 2020 01:02:31 -0400 Subject: [PATCH] moved things to namespace --- .gitignore | 2 ++ Makefile | 21 +++++++++++++-------- src/FM/Engine.cpp | 6 ++---- src/FM/Engine.h | 9 ++++++++- src/FM/Envelope.cpp | 2 ++ src/FM/Envelope.h | 3 ++- src/FM/Matrix.h | 3 ++- src/FM/Operator.cpp | 2 ++ src/FM/Operator.h | 3 ++- src/WavWriter/WavWriter.cpp | 3 ++- src/WavWriter/WavWriter.h | 5 +++-- src/fmtest.cpp | 1 + src/wavtest.cpp | 1 + 13 files changed, 42 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index b9ff718..59811c0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ fmtest *.w16 *.wav .#a +bin/ +lib/ build/ *.dSYM a.out diff --git a/Makefile b/Makefile index 0418061..f3d8532 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ SRCDIR ?= src INCDIR += -I${SRCDIR} OBJDIR ?= build BINDIR ?= bin +LIBDIR ?= lib INSTALLDIR ?= /usr/local/bin TARGET ?= amalgam @@ -21,7 +22,8 @@ SRC = $(wildcard ${SRCDIR}/*/*.cpp) OBJ = ${SRC:${SRCDIR}/%.cpp=${OBJDIR}/%.o} BINS = $(wildcard ${SRCDIR}/*.cpp) ALLOBJ = ${SRC:${SRCDIR}/%.cpp=${OBJDIR}/%.o} ${BINS:${SRCDIR}/%.cpp=${OBJDIR}/%.o} - +INCLUDES = ${wildcard ${SRCDIR}/*/*.h} +INC = ${INCLUDES:${SRCDIR}/%.h=${LIBDIR}/include/%.h} all: fmtest wavtest amalgam ${ALLOBJ}: $(OBJDIR)/%.o : $(SRCDIR)/%.cpp @@ -37,18 +39,21 @@ wavtest: ${ALLOBJ} @mkdir -p ${BINDIR} ${CXX} ${INCDIR} -o ${BINDIR}/wavtest ${OBJDIR}/wavtest.o ${OBJ} ${LDFLAGS} ${CFLAGS} ${DEFINES} -amalgam.so: ${OBJ} - ${CXX} ${INCDIR} -o ${BINDIR}/${TARGET}.so ${OBJ} --shared -fPIC ${LDFLAGS} ${CFLAGS} ${DEFINES} +libamalgam.so: ${OBJ} ${INC} + ${CXX} ${INCDIR} -o ${LIBDIR}/lib${TARGET}.so ${OBJ} --shared -fPIC ${LDFLAGS} ${CFLAGS} ${DEFINES} -amalgam.dylib: ${OBJ} - ${CXX} ${INCDIR} -o ${BINDIR}/${TARGET}.dylib ${OBJ} -dynamiclib ${LDFLAGS} ${CFLAGS} ${DEFINES} +libamalgam.dylib: ${OBJ} ${INC} + ${CXX} ${INCDIR} -o ${LIBDIR}/lib${TARGET}.dylib ${OBJ} -dynamiclib ${LDFLAGS} ${CFLAGS} ${DEFINES} ifeq (${UNAME},Darwin) -amalgam: amalgam.dylib +amalgam: libamalgam.dylib else -amalgam: amalgam.so -endif +amalgam: libamalgam.so +endif +${INC}: $(LIBDIR)/include/%.h : $(SRCDIR)/%.h + @mkdir -p $(dir $@) + cp $< $@ clean: @echo cleaning @rm -f ${OBJ} diff --git a/src/FM/Engine.cpp b/src/FM/Engine.cpp index 58ebf45..64157e9 100644 --- a/src/FM/Engine.cpp +++ b/src/FM/Engine.cpp @@ -12,7 +12,5 @@ */ #include "Engine.h" -template class FM::Engine<2>; -template class FM::Engine<4>; -template class FM::Engine<6>; -template class FM::Engine<8>; +namespace amalgam { +} diff --git a/src/FM/Engine.h b/src/FM/Engine.h index b6112af..5858e39 100644 --- a/src/FM/Engine.h +++ b/src/FM/Engine.h @@ -17,11 +17,13 @@ #include "Matrix.h" #include +namespace amalgam { namespace FM { template class Engine { Matrix gains; - std::array pans; // panning on master channels.? + std::array, T> _pans; // panning on master channels. + std::array pans; // panning on master channels. Matrix mutes; std::array operators; std::pair out; @@ -103,8 +105,13 @@ namespace FM { return out; } }; +template class Engine<1>; +template class Engine<4>; +template class Engine<6>; +template class Engine<8>; } +} /* Local Variables: */ /* mode: c++ */ diff --git a/src/FM/Envelope.cpp b/src/FM/Envelope.cpp index 5c04860..2f2b657 100644 --- a/src/FM/Envelope.cpp +++ b/src/FM/Envelope.cpp @@ -13,6 +13,7 @@ #include "Envelope.h" +namespace amalgam { namespace FM { float Envelope::process () { switch (envstate) { @@ -100,3 +101,4 @@ namespace FM { return 0.0f; // if this is reached, something went wrong or an unhandled function was used. } } +} diff --git a/src/FM/Envelope.h b/src/FM/Envelope.h index b8934fb..6e7ba67 100644 --- a/src/FM/Envelope.h +++ b/src/FM/Envelope.h @@ -13,6 +13,7 @@ #pragma once #include #include +namespace amalgam { namespace FM { class Envelope { enum EnvState {_e_off,_e_attack, _e_attackrelease, _e_decay, _e_sustain,_e_release, _e_finished}; @@ -73,7 +74,7 @@ namespace FM { float operator()() { return process(); } }; } - +} /* Local Variables: */ /* mode: c++ */ /* End: */ diff --git a/src/FM/Matrix.h b/src/FM/Matrix.h index 95541d8..4a3e41e 100644 --- a/src/FM/Matrix.h +++ b/src/FM/Matrix.h @@ -13,7 +13,7 @@ #pragma once #include - +namespace amalgam { namespace FM { template class Matrix { @@ -27,6 +27,7 @@ namespace FM { } }; } +} /* Local Variables: */ /* mode: c++ */ diff --git a/src/FM/Operator.cpp b/src/FM/Operator.cpp index cca3148..4849604 100644 --- a/src/FM/Operator.cpp +++ b/src/FM/Operator.cpp @@ -12,6 +12,7 @@ */ #include "Operator.h" +namespace amalgam { namespace FM { void Operator::process(){ phase += smpTime * (((*freq * mul) + detune)); @@ -59,3 +60,4 @@ namespace FM { } } } +} diff --git a/src/FM/Operator.h b/src/FM/Operator.h index 170a078..660e164 100644 --- a/src/FM/Operator.h +++ b/src/FM/Operator.h @@ -13,6 +13,7 @@ #pragma once #include "Envelope.h" +namespace amalgam { namespace FM { class Operator { double mul = 1.0; @@ -45,7 +46,7 @@ namespace FM { ~Operator(); }; } - +} /* Local Variables: */ /* mode: c++ */ /* End: */ diff --git a/src/WavWriter/WavWriter.cpp b/src/WavWriter/WavWriter.cpp index 3a06c9f..1e9e3bf 100644 --- a/src/WavWriter/WavWriter.cpp +++ b/src/WavWriter/WavWriter.cpp @@ -12,7 +12,7 @@ */ #include "WavWriter.h" #include - +namespace amalgam { WavWriter::WavWriter(char* filename, uint srate, uint chan, uint bps) { file = fopen(filename, "w"); sr = srate; @@ -67,3 +67,4 @@ void WavWriter::writeBytes(char* bytes, uint count) { } WavWriter::~WavWriter(){} +} diff --git a/src/WavWriter/WavWriter.h b/src/WavWriter/WavWriter.h index 97c6f4d..0b14243 100644 --- a/src/WavWriter/WavWriter.h +++ b/src/WavWriter/WavWriter.h @@ -15,8 +15,9 @@ // standard wave files have a 32bit size limit. #define WAVMAX (0xffffff - 20) - typedef unsigned int uint; + +namespace amalgam { class WavWriter { uint32_t length = 0; @@ -55,7 +56,7 @@ class WavWriter { void writeHeader(); void write(...); }; - +} /* Local Variables: */ /* mode: c++ */ diff --git a/src/fmtest.cpp b/src/fmtest.cpp index cd2ac7b..8730920 100644 --- a/src/fmtest.cpp +++ b/src/fmtest.cpp @@ -16,6 +16,7 @@ #include #include +using namespace amalgam; int16_t toint16(double i) { double temp = i *= 32767; return floor(temp); diff --git a/src/wavtest.cpp b/src/wavtest.cpp index ad7cb68..d3d615a 100644 --- a/src/wavtest.cpp +++ b/src/wavtest.cpp @@ -17,6 +17,7 @@ #include #include "FM/Engine.h" #include "WavWriter/WavWriter.h" +using namespace amalgam; int16_t toint16(double i) { double temp = i *= 32767;