diff --git a/JuceOPLVSTi.jucer b/JuceOPLVSTi.jucer index 942e45b..56c8035 100644 --- a/JuceOPLVSTi.jucer +++ b/JuceOPLVSTi.jucer @@ -1,105 +1,141 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Source/DROMultiplexer.cpp b/Source/DROMultiplexer.cpp index 8292c83..bbd5623 100644 --- a/Source/DROMultiplexer.cpp +++ b/Source/DROMultiplexer.cpp @@ -1,7 +1,17 @@ #include "DROMultiplexer.h" - #include "JuceHeader.h" -#include + +/// Jeff-Russ added guard against windows.h include if not windows: +#ifdef _WIN32 // covers both 32 and 64-bit + #include +#else + #include "windows.h" +#endif + +/// Jeff-Russ added to replace mising itoa for xcode: +#if __APPLE__ + #include "itoa.h" +#endif // Used by the first recording instance to claim master status DROMultiplexer* DROMultiplexer::master = NULL; @@ -186,7 +196,7 @@ void DROMultiplexer::TwoOpMelodicNoteOn(Hiopl* opl, int inCh) { char addr[16]; int outCh = _FindFreeChannel(opl, inCh); _DebugOut(" <- "); - _DebugOut(itoa((int)opl, addr, 16)); +/// _DebugOut(itoa((int)opl, addr, 16)); _DebugOut(" "); for (int i = 0; i < MELODIC_CHANNELS; i++) { Hiopl* tmpOpl = channels[i].opl; diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 879ce59..8b0566a 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -45,7 +45,7 @@ public: //============================================================================== const String getName() const; - static const int JuceOplvstiAudioProcessor::MAX_INSTRUMENT_FILE_SIZE_BYTES = 1024; + static const int MAX_INSTRUMENT_FILE_SIZE_BYTES = 1024; int getNumParameters(); diff --git a/Source/config.h b/Source/config.h index 5519f70..ff6fc51 100644 --- a/Source/config.h +++ b/Source/config.h @@ -63,20 +63,36 @@ #pragma warning(disable : 4996) #endif -#ifndef WIN32 -typedef long long __int64; +/// Jeff-Russ modified to be uniform across C++ implementations: +// The internal types: +#include +typedef unsigned char BYTE; +typedef int64_t __int64; +typedef double Real64; +typedef unsigned char Bit8u; +typedef signed char Bit8s; +typedef uint16_t Bit16u; +typedef int16_t Bit16s; +typedef uint32_t Bit32u; +typedef int32_t Bit32s; +typedef int64_t Bit64u; +typedef uint64_t Bit64s; +typedef Bit32u Bitu; +typedef Bit32s Bits; + + +/// Jeff-Russ PUT PLATFORM SPECIFIC STUFF HERE: +#ifdef _WIN32 // covers both 32 and 64-bit + #define INLINE __forceinline +#elif __APPLE__ + #include "TargetConditionals.h" + #define INLINE inline /// apple has no forceinline +#elif __linux + #define INLINE inline +#elif __unix + #define INLINE inline +#elif __posix + #define INLINE inline +#else + #error Unsupported Operating System #endif - -typedef double Real64; -/* The internal types */ -typedef unsigned char Bit8u; -typedef signed char Bit8s; -typedef unsigned short Bit16u; -typedef signed short Bit16s; -typedef unsigned long Bit32u; -typedef signed long Bit32s; -typedef unsigned __int64 Bit64u; -typedef signed __int64 Bit64s; -typedef unsigned int Bitu; -typedef signed int Bits; - diff --git a/Source/hiopl.h b/Source/hiopl.h index e2a9d4e..f762ca3 100644 --- a/Source/hiopl.h +++ b/Source/hiopl.h @@ -1,92 +1,92 @@ -#pragma once -#include - -#include "adlib.h" -#include "dbopl.h" -#include "zdopl.h" - -enum Waveform -{ - SIN = 0, HALF_SIN = 1, ABS_SIN = 2, QUART_SIN = 3 -}; - -enum FreqMultiple -{ - xHALF=0, x1=1, x2=2, x3=3, x4=4, x5=5, x6=6, x7=7, x8=8, x9=9, x10=10, x12=12, x15=15 -}; - -enum Emulator -{ - DOSBOX=0, ZDOOM=1 -}; - -enum Drum -{ - BDRUM=0x10, SNARE=0x8, TOM=0x4, CYMBAL=0x2, HIHAT=0x1 -}; - -class Hiopl { - public: - static const int CHANNELS = 9; - static const int OSCILLATORS = 2; - Hiopl(int buflen, Emulator emulator = ZDOOM); - void SetEmulator(Emulator emulator); - void SetPercussionMode(bool enable); - void HitPercussion(Drum drum); - void ReleasePercussion(); - - void Generate(int length, short* buffer); - void Generate(int length, float* buffer); - void SetSampleRate(int hz); - void EnableWaveformControl(); - void EnableOpl3Mode(); - - void EnableTremolo(int ch, int osc, bool enable); - void EnableVibrato(int ch, int osc, bool enable); - void VibratoDepth(bool high); - void TremoloDepth(bool high); - void EnableSustain(int ch, int osc, bool enable); - void EnableKsr(int ch, int osc, bool enable); - // true = additive; false = frequency modulation - void EnableAdditiveSynthesis(int ch, bool enable); - - void SetWaveform(int ch, int osc, Waveform wave); - void SetAttenuation(int ch, int osc, int level); - void SetKsl(int ch, int osc, int level); - void SetFrequencyMultiple(int ch, int osc, FreqMultiple mult); - void SetEnvelopeAttack(int ch, int osc, int t); - void SetEnvelopeDecay(int ch, int osc, int t); - void SetEnvelopeSustain(int ch, int osc, int level); - void SetEnvelopeRelease(int ch, int osc, int t); - // Get register address offset for operator settings for the specified channel and operator. - int _GetOffset(int ch, int osc); - // Get register address offset for channel-wide register settings for the specified channel. - int _GetOffset(int ch); - - void SetModulatorFeedback(int ch, int level); - void KeyOn(int ch, float frqHz); - void KeyOff(int ch); - // Return false if no note is active on the channel (ie release is complete) - bool IsActive(int ch); - // Return a single character string representing the stage of the envelope for the carrier operator for the channel - const char* GetState(int ch) const; - void SetFrequency(int ch, float frqHz, bool keyOn=false); - void _WriteReg(Bit32u reg, Bit8u value, Bit8u mask=0x0); - void _ClearRegBits(Bit32u reg, Bit8u mask); - // Read the last value written to the specified register address (cached) - Bit8u _ReadReg(Bit32u reg); - - ~Hiopl(); - private: - Emulator emulator; - DBOPL::Handler *adlib; - OPLEmul *zdoom; - Bit8u regCache[256]; - bool _CheckParams(int ch, int osc); - void _milliHertzToFnum(unsigned int milliHertz, unsigned int *fnum, unsigned int *block, unsigned int conversionFactor=49716); - void _ClearRegisters(); - - std::map _op1offset; - std::map _op2offset; - -}; +#pragma once +#include + +#include "adlib.h" +#include "dbopl.h" +#include "zdopl.h" + +enum Waveform +{ + SIN = 0, HALF_SIN = 1, ABS_SIN = 2, QUART_SIN = 3 +}; + +enum FreqMultiple +{ + xHALF=0, x1=1, x2=2, x3=3, x4=4, x5=5, x6=6, x7=7, x8=8, x9=9, x10=10, x12=12, x15=15 +}; + +enum Emulator +{ + DOSBOX=0, ZDOOM=1 +}; + +enum Drum +{ + BDRUM=0x10, SNARE=0x8, TOM=0x4, CYMBAL=0x2, HIHAT=0x1 +}; + +class Hiopl { + public: + static const int CHANNELS = 9; + static const int OSCILLATORS = 2; + Hiopl(int buflen, Emulator emulator = ZDOOM); + void SetEmulator(Emulator emulator); + void SetPercussionMode(bool enable); + void HitPercussion(Drum drum); + void ReleasePercussion(); + + void Generate(int length, short* buffer); + void Generate(int length, float* buffer); + void SetSampleRate(int hz); + void EnableWaveformControl(); + void EnableOpl3Mode(); + + void EnableTremolo(int ch, int osc, bool enable); + void EnableVibrato(int ch, int osc, bool enable); + void VibratoDepth(bool high); + void TremoloDepth(bool high); + void EnableSustain(int ch, int osc, bool enable); + void EnableKsr(int ch, int osc, bool enable); + // true = additive; false = frequency modulation + void EnableAdditiveSynthesis(int ch, bool enable); + + void SetWaveform(int ch, int osc, Waveform wave); + void SetAttenuation(int ch, int osc, int level); + void SetKsl(int ch, int osc, int level); + void SetFrequencyMultiple(int ch, int osc, FreqMultiple mult); + void SetEnvelopeAttack(int ch, int osc, int t); + void SetEnvelopeDecay(int ch, int osc, int t); + void SetEnvelopeSustain(int ch, int osc, int level); + void SetEnvelopeRelease(int ch, int osc, int t); + // Get register address offset for operator settings for the specified channel and operator. + int _GetOffset(int ch, int osc); + // Get register address offset for channel-wide register settings for the specified channel. + int _GetOffset(int ch); + + void SetModulatorFeedback(int ch, int level); + void KeyOn(int ch, float frqHz); + void KeyOff(int ch); + // Return false if no note is active on the channel (ie release is complete) + bool IsActive(int ch); + // Return a single character string representing the stage of the envelope for the carrier operator for the channel + const char* GetState(int ch) const; + void SetFrequency(int ch, float frqHz, bool keyOn=false); + void _WriteReg(Bit32u reg, Bit8u value, Bit8u mask=0x0); + void _ClearRegBits(Bit32u reg, Bit8u mask); + // Read the last value written to the specified register address (cached) + Bit8u _ReadReg(Bit32u reg); + + ~Hiopl(); + private: + Emulator emulator; + DBOPL::Handler *adlib; + OPLEmul *zdoom; + Bit8u regCache[256]; + bool _CheckParams(int ch, int osc); + void _milliHertzToFnum(unsigned int milliHertz, unsigned int *fnum, unsigned int *block, unsigned int conversionFactor=49716); + void _ClearRegisters(); + + std::map _op1offset; + std::map _op2offset; + +}; diff --git a/Source/itoa.h b/Source/itoa.h new file mode 100644 index 0000000..8b5a0c6 --- /dev/null +++ b/Source/itoa.h @@ -0,0 +1,50 @@ + +///============================================================================= +/// itoa.h - A C++ header to implement itoa() +/// Created: 11 Feb 2015 5:08:51pm +/// Author: Jeff-Russ +///============================================================================= +#pragma once + +#include +using namespace std; + +// A utility function to reverse a string: +void reverse(char str[], int length) +{ + int start = 0; + int end = length -1; + while (start < end) + { swap(*(str+start), *(str+end)); + start++; + end--; + } +}; + +char* itoa(int num, char* str, int base) +{ + int i = 0; + bool isNegative = false; + + if (num == 0) // Handle 0 explicitly, otherwise + { str[i++] = '0'; // empty string is printed for 0 + str[i] = '\0'; + return str; + } + // In standard itoa(), negative + if (num < 0 && base == 10) // numbers are handled only with + { isNegative = true; // base 10. Otherwise numbers + num = -num; // are considered unsigned. + } + while (num != 0) + { int rem = num % base; // Process individual digits + str[i++] = (rem > 9)? (rem-10) + 'a' : rem + '0'; + num = num/base; + } + if (isNegative) // If number is negative, append '-' + str[i++] = '-'; + + str[i] = '\0'; // Append string terminator + reverse(str, i); // Reverse the string + return str; +}; diff --git a/Source/windows.h b/Source/windows.h new file mode 100644 index 0000000..2fa0bff --- /dev/null +++ b/Source/windows.h @@ -0,0 +1,85 @@ + +///============================================================================= +/// windows.h - as needed re-definition of windows.h functions for non-win +/// Created: 11 Feb 2015 5:08:51pm +/// Author: Jeff-Russ +///============================================================================= + +#pragma once + +#include + + +// PVOID - A pointer to any type. +// This type is declared in WinNT.h as follows: +typedef void* PVOID; + +// DWORDLONG A 64-bit unsigned integer. +// This type is declared in IntSafe.h as follows: +typedef uint64_t DWORDLONG; + + +#define WINAPI + +// DWORD - A 32-bit unsigned integer. +// This type is declared in IntSafe.h as follows: +typedef uint32_t DWORD; + +// WCHAR - A 16-bit unicode character +// This type is declared in WinNT.h as follows: +typedef int16_t WCHAR; + +// HANDLE - A handle to an object. +// This type is declared in WinDef.h as follows: +typedef PVOID HANDLE; + +DWORD STD_INPUT_HANDLE = -10; +DWORD STD_OUTPUT_HANDLE = -11; +DWORD STD_ERROR_HANDLE = -12; + + +#define MAX_PATH PATH_MAX + +// BYTE - A byte (8-bits) +// This type is declared in WinDef.h as follows: +typedef unsigned char BYTE; + +// WORD - A 16-bit unsigned integer. +// This type is declared in WinDef.h as follows: +typedef uint16_t WORD; + +// BOOL - A boolean variable +// This type is declared in WinDef.h as follows: +typedef BYTE BOOL; + +DWORD GetStdHandle (DWORD handle) { return handle; } + +void WriteConsole(DWORD conout,const char* strPtr, + DWORD count, DWORD* countAdr, int* nul) +{ + std::string msgType = "NOTICE: "; + + if (conout == -10) + msgType = "INPUT: "; + else if (conout == -11) + msgType = "OUTPUT: "; + else if (conout == -12) + msgType = "ERROR: "; + else + msgType = "NOTICE: "; + + std::string message (const char* str, uint32_t count); + + std::cout << std::endl << msgType << message; +} + +void AllocConsole() +{ + std::cout << std::endl << "=== Starting debug console....." << std::endl; +} +void FreeConsole() +{ + std::cout << std::endl << "=== Exited debug console ===" << std::endl; +} + + diff --git a/Source/zdopl.cpp b/Source/zdopl.cpp index fae6b8c..e362768 100644 --- a/Source/zdopl.cpp +++ b/Source/zdopl.cpp @@ -46,9 +46,15 @@ #include #include #include +#include /// Jeff-Russ added to get rand() and RAND_MAX + + +/*typedef unsigned __int8 BYTE;*/ /// Jeff changed to char and put in config.h + +#ifndef M_PI /// Jeff-Russ added condition to silence xcode warning + #define M_PI 3.141592654 +#endif -typedef unsigned __int8 BYTE; -#define M_PI 3.141592654 #include "config.h" #include "zdopl.h"