From 76206997f825b3901d9acaebd010ce0cb20012f9 Mon Sep 17 00:00:00 2001 From: bruce Date: Mon, 3 Nov 2014 18:16:59 +0900 Subject: [PATCH] Begin work on communication of recording state between instances using static variables. --- Source/PluginGui.cpp | 4 +- Source/PluginProcessor.cpp | 6 +- Source/PluginProcessor.h | 3 +- Source/hiopl.cpp | 123 ++++++++++++++++++++----------------- Source/hiopl.h | 3 + 5 files changed, 78 insertions(+), 61 deletions(-) diff --git a/Source/PluginGui.cpp b/Source/PluginGui.cpp index 6adbfba..c3e41c9 100644 --- a/Source/PluginGui.cpp +++ b/Source/PluginGui.cpp @@ -27,7 +27,7 @@ void PluginGui::updateFromParameters() { emulatorSlider->setValue(processor->getEnumParameter("Emulator"), juce::NotificationType::dontSendNotification); - setRecordButtonState(processor->isRecording()); + setRecordButtonState(processor->isThisInstanceRecording()); sineImageButton->setToggleState(false, false); halfsineImageButton->setToggleState(false, false); @@ -1498,7 +1498,7 @@ void PluginGui::buttonClicked (Button* buttonThatWasClicked) { //[UserButtonCode_recordButton] -- add your button handler code here.. recordButton->setToggleState(false, false); - if (!processor->isRecording()) { + if (!processor->isAnyInstanceRecording()) { WildcardFileFilter wildcardFilter ("*.dro", String::empty, "DRO files"); FileBrowserComponent browser (FileBrowserComponent::saveMode, File::nonexistent, diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 3440f12..c0a5349 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -136,10 +136,14 @@ JuceOplvstiAudioProcessor::JuceOplvstiAudioProcessor() available_channels.push_back(i); } -bool JuceOplvstiAudioProcessor::isRecording() { +bool JuceOplvstiAudioProcessor::isThisInstanceRecording() { return NULL != recordingFile; } +bool JuceOplvstiAudioProcessor::isAnyInstanceRecording() { + return Opl->IsAnInstanceRecording(); +} + void JuceOplvstiAudioProcessor::startRecording(File *outputFile) { recordingFile = outputFile; Opl->StartCapture(outputFile->getFullPathName().toUTF8()); diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 34483af..5c48366 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -26,7 +26,8 @@ public: void applyPitchBend(); ~JuceOplvstiAudioProcessor(); - bool isRecording(); + bool isThisInstanceRecording(); + bool isAnyInstanceRecording(); void startRecording(File *outputFile); void stopRecording(); diff --git a/Source/hiopl.cpp b/Source/hiopl.cpp index 4f4f752..3320faf 100644 --- a/Source/hiopl.cpp +++ b/Source/hiopl.cpp @@ -5,9 +5,15 @@ // A wrapper around the DOSBox and ZDoom OPL emulators. +// Used by the first recording instance to claim master status +Hiopl* Hiopl::master = NULL; + +bool Hiopl::IsAnInstanceRecording() { + return NULL != Hiopl::master; +} + Hiopl::Hiopl(int buflen, Emulator emulator) { - captureHandle = NULL; - StopCapture(); + InitCaptureVariables(); adlib = new DBOPL::Handler(); zdoom = JavaOPLCreate(false); @@ -244,56 +250,53 @@ static Bit8u dro_opl3_enable[]={ }; void Hiopl::StartCapture(const char* filepath) { - if (NULL != captureHandle) { - StopCapture(); - } else { - lastWrite = -1; - captureLengthBytes = 0; - captureStart = Time::currentTimeMillis(); - captureHandle = fopen(filepath, "wb"); - fwrite(dro_header, 1, sizeof(dro_header), captureHandle); - for (int i = 0; i <= 0xff; i++) { - _CaptureRegWrite(i, 0); - } - //_CaptureRegWrite(0x1, 0x20); - /* - for (int ch = 1; ch <= CHANNELS; ch++) { - int offset1 = this->_GetOffset(ch, 1); - int offset2 = this->_GetOffset(ch, 2); - int offset0 = this->_GetOffset(ch); - _CaptureRegWrite(0x20 + offset1, regCache[0x20 + offset1]); - _CaptureRegWrite(0x20 + offset2, regCache[0x20 + offset2]); - _CaptureRegWrite(0x40 + offset1, regCache[0x40 + offset1]); - _CaptureRegWrite(0x40 + offset2, regCache[0x40 + offset2]); - _CaptureRegWrite(0x60 + offset1, regCache[0x60 + offset1]); - _CaptureRegWrite(0x60 + offset2, regCache[0x60 + offset2]); - _CaptureRegWrite(0x80 + offset1, regCache[0x80 + offset1]); - _CaptureRegWrite(0x80 + offset2, regCache[0x80 + offset2]); - _CaptureRegWrite(0xe0 + offset1, regCache[0xe0 + offset1]); - _CaptureRegWrite(0xe0 + offset2, regCache[0xe0 + offset2]); - _CaptureRegWrite(0xc0 + offset0, regCache[0xc0 + offset0]); - } - */ - _CaptureOpl3Enable(); - for (Bit8u i = 0x20; i <= 0x35; i++) { - _CaptureRegWrite(i, regCache[i]); - } - for (Bit8u i = 0x40; i <= 0x55; i++) { - _CaptureRegWrite(i, regCache[i]); - } - for (Bit8u i = 0x60; i <= 0x75; i++) { - _CaptureRegWrite(i, regCache[i]); - } - for (Bit8u i = 0x80; i <= 0x95; i++) { - _CaptureRegWrite(i, regCache[i]); - } - _CaptureRegWrite(0xbd, regCache[0xbd]); - for (Bit8u i = 0xc0; i <= 0xc8; i++) { - _CaptureRegWrite(i, regCache[i] | 0x30); // enable L + R channels - } - for (Bit8u i = 0xe0; i <= 0xf5; i++) { - _CaptureRegWrite(i, regCache[i]); - } + Hiopl::master = this; + lastWrite = -1; + captureLengthBytes = 0; + captureStart = Time::currentTimeMillis(); + captureHandle = fopen(filepath, "wb"); + fwrite(dro_header, 1, sizeof(dro_header), captureHandle); + for (int i = 0; i <= 0xff; i++) { + _CaptureRegWrite(i, 0); + } + //_CaptureRegWrite(0x1, 0x20); + /* + for (int ch = 1; ch <= CHANNELS; ch++) { + int offset1 = this->_GetOffset(ch, 1); + int offset2 = this->_GetOffset(ch, 2); + int offset0 = this->_GetOffset(ch); + _CaptureRegWrite(0x20 + offset1, regCache[0x20 + offset1]); + _CaptureRegWrite(0x20 + offset2, regCache[0x20 + offset2]); + _CaptureRegWrite(0x40 + offset1, regCache[0x40 + offset1]); + _CaptureRegWrite(0x40 + offset2, regCache[0x40 + offset2]); + _CaptureRegWrite(0x60 + offset1, regCache[0x60 + offset1]); + _CaptureRegWrite(0x60 + offset2, regCache[0x60 + offset2]); + _CaptureRegWrite(0x80 + offset1, regCache[0x80 + offset1]); + _CaptureRegWrite(0x80 + offset2, regCache[0x80 + offset2]); + _CaptureRegWrite(0xe0 + offset1, regCache[0xe0 + offset1]); + _CaptureRegWrite(0xe0 + offset2, regCache[0xe0 + offset2]); + _CaptureRegWrite(0xc0 + offset0, regCache[0xc0 + offset0]); + } + */ + _CaptureOpl3Enable(); + for (Bit8u i = 0x20; i <= 0x35; i++) { + _CaptureRegWrite(i, regCache[i]); + } + for (Bit8u i = 0x40; i <= 0x55; i++) { + _CaptureRegWrite(i, regCache[i]); + } + for (Bit8u i = 0x60; i <= 0x75; i++) { + _CaptureRegWrite(i, regCache[i]); + } + for (Bit8u i = 0x80; i <= 0x95; i++) { + _CaptureRegWrite(i, regCache[i]); + } + _CaptureRegWrite(0xbd, regCache[0xbd]); + for (Bit8u i = 0xc0; i <= 0xc8; i++) { + _CaptureRegWrite(i, regCache[i] | 0x30); // enable L + R channels + } + for (Bit8u i = 0xe0; i <= 0xf5; i++) { + _CaptureRegWrite(i, regCache[i]); } } @@ -304,9 +307,18 @@ INLINE void host_writed(Bit8u *off, Bit32u val) { off[3]=(Bit8u)(val >> 24); }; +void Hiopl::InitCaptureVariables() { + captureHandle = NULL; + captureLengthBytes = 0; + lastWrite = -1; + captureStart = -1; +} + void Hiopl::StopCapture() { if (NULL != captureHandle) { - Bit32u lengthMilliseconds = (Bit32u)(3000 + Time::currentTimeMillis() - captureStart); + Bit16u finalDelay = (Bit16u)(Time::currentTimeMillis() - lastWrite); + _CaptureDelay(finalDelay); + Bit32u lengthMilliseconds = (Bit32u)(finalDelay + Time::currentTimeMillis() - captureStart); host_writed(&dro_header[0x0c], lengthMilliseconds); host_writed(&dro_header[0x10], captureLengthBytes); //if (opl.raw.opl3 && opl.raw.dualopl2) host_writed(&dro_header[0x14],0x1); @@ -317,10 +329,7 @@ void Hiopl::StopCapture() { fwrite(dro_header, 1, sizeof(dro_header), captureHandle); fclose(captureHandle); } - captureHandle = NULL; - captureLengthBytes = 0; - lastWrite = -1; - captureStart = -1; + InitCaptureVariables(); } void Hiopl::_CaptureDelay(Bit16u delayMs) { diff --git a/Source/hiopl.h b/Source/hiopl.h index f0e99b2..0cfbaf4 100644 --- a/Source/hiopl.h +++ b/Source/hiopl.h @@ -58,6 +58,8 @@ class Hiopl { void _WriteReg(Bit32u reg, Bit8u value, Bit8u mask=0x0); void _ClearRegBits(Bit32u reg, Bit8u mask); + void InitCaptureVariables(); + bool IsAnInstanceRecording(); void StartCapture(const char* filepath); void StopCapture(); @@ -79,6 +81,7 @@ class Hiopl { std::map _op1offset; std::map _op2offset; + static Hiopl* master; FILE* captureHandle; Bit64s captureStart; Bit64s lastWrite;