2
0
Fork 0

Basics of instrument loading in place.

This commit is contained in:
bruce 2013-11-13 17:15:17 +08:00
parent e5d38e5784
commit b1d907e9b8
7 changed files with 103 additions and 13 deletions

11
Source/InstrumentLoader.h Normal file
View file

@ -0,0 +1,11 @@
#pragma once
#include "PluginProcessor.h"
// Just specifies the interfaces for instrument loaders.
class InstrumentLoader
{
public:
virtual void loadInstrumentData(int n, const unsigned char* data, JuceOplvstiAudioProcessor *proc) = 0;
virtual String getExtension() = 0;
};

View file

@ -1411,7 +1411,7 @@ void PluginGui::buttonClicked (Button* buttonThatWasClicked)
bool PluginGui::isInterestedInFileDrag (const StringArray& files)
{
// TODO: check extensions?
return true;
return 1 == files.size();
}
void PluginGui::fileDragEnter (const StringArray& files, int x, int y)
@ -1432,6 +1432,9 @@ void PluginGui::buttonClicked (Button* buttonThatWasClicked)
void PluginGui::filesDropped (const StringArray& files, int x, int y)
{
if (isInterestedInFileDrag(files)) {
processor->loadInstrumentFromFile(files[0]);
}
//message = "files dropped: " + files.joinIntoString ("\n");
//somethingIsBeingDraggedOver = false;

View file

@ -2,6 +2,7 @@
#include "PluginGui.h"
#include "EnumFloatParameter.h"
#include "IntFloatParameter.h"
#include "SbiLoader.h"
//==============================================================================
JuceOplvstiAudioProcessor::JuceOplvstiAudioProcessor()
@ -11,7 +12,6 @@ JuceOplvstiAudioProcessor::JuceOplvstiAudioProcessor()
Opl = new Hiopl(44100); // 1 second at 44100
Opl->SetSampleRate(44100);
Opl->EnableWaveformControl();
//Opl->EnableOpl3Mode();
// Initialize parameters
@ -460,6 +460,37 @@ void JuceOplvstiAudioProcessor::setParameter (int index, float newValue)
}
}
void JuceOplvstiAudioProcessor::loadInstrumentFromFile(String filename)
{
FILE* f = fopen(filename.toUTF8(), "rb");
unsigned char buf[MAX_INSTRUMENT_FILE_SIZE_BYTES];
int n = fread(buf, 1, MAX_INSTRUMENT_FILE_SIZE_BYTES, f);
SbiLoader* loader = new SbiLoader();
loader->loadInstrumentData(n, buf, this);
fclose(f);
}
void JuceOplvstiAudioProcessor::setParametersByRegister(int register_base, int op, uint8 value)
{
register_base &= 0xF0;
switch (register_base) {
case 0x20:
break;
case 0x40:
break;
case 0x60:
break;
case 0x80:
break;
case 0xC0:
break;
case 0xE0:
break;
default:
break;
}
}
const String JuceOplvstiAudioProcessor::getParameterName (int index)
{
return params[index]->getName();
@ -482,12 +513,12 @@ const String JuceOplvstiAudioProcessor::getOutputChannelName (int channelIndex)
bool JuceOplvstiAudioProcessor::isInputChannelStereoPair (int index) const
{
return true;
return false;
}
bool JuceOplvstiAudioProcessor::isOutputChannelStereoPair (int index) const
{
return true;
return false;
}
bool JuceOplvstiAudioProcessor::acceptsMidi() const

View file

@ -1,9 +1,8 @@
/*
==============================================================================
This file was auto-generated!
It contains the basic startup code for a Juce application.
This file was initially auto-generated by the Introjucer.
Now it is safe to edit.
==============================================================================
*/
@ -40,7 +39,9 @@ public:
//==============================================================================
const String getName() const;
int getNumParameters();
static const int JuceOplvstiAudioProcessor::MAX_INSTRUMENT_FILE_SIZE_BYTES = 1024;
int getNumParameters();
float getParameter (int index);
void setParameter (int index, float newValue);
@ -48,6 +49,8 @@ public:
void setIntParameter (String name, int newValue);
int getIntParameter (String name);
int getEnumParameter (String name);
void loadInstrumentFromFile(String filename);
void setParametersByRegister(int register_base, int op, uint8 value);
const String getParameterName (int index);
const String getParameterText (int index);
@ -87,5 +90,4 @@ private:
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (JuceOplvstiAudioProcessor)
};
#endif // PLUGINPROCESSOR_H_INCLUDED

34
Source/SbiLoader.cpp Normal file
View file

@ -0,0 +1,34 @@
#include "SbiLoader.h"
SbiLoader::SbiLoader(void)
{
}
void SbiLoader::loadInstrumentData(int n, const unsigned char* data, JuceOplvstiAudioProcessor *proc)
{
if (strncmp("SBI", (const char*)data, 3)) {
data += 40;
proc->setParametersByRegister(0x20, 0, data[0]);
proc->setParametersByRegister(0x20, 1, data[1]);
proc->setParametersByRegister(0x40, 0, data[2]);
proc->setParametersByRegister(0x40, 1, data[3]);
proc->setParametersByRegister(0x60, 0, data[4]);
proc->setParametersByRegister(0x60, 1, data[5]);
proc->setParametersByRegister(0x80, 0, data[6]);
proc->setParametersByRegister(0x80, 1, data[7]);
proc->setParametersByRegister(0xE0, 0, data[8]);
proc->setParametersByRegister(0xE0, 1, data[9]);
proc->setParametersByRegister(0xC0, 1, data[10]);
} // else throw "Invalid header";
}
String SbiLoader::getExtension()
{
return String("sbi");
}
SbiLoader::~SbiLoader(void)
{
}

13
Source/SbiLoader.h Normal file
View file

@ -0,0 +1,13 @@
#pragma once
#include "c:\code\juceoplvsti\source\instrumentloader.h"
class SbiLoader :
public InstrumentLoader
{
public:
SbiLoader(void);
virtual ~SbiLoader(void);
void loadInstrumentData(int n, const unsigned char* data, JuceOplvstiAudioProcessor *proc);
String getExtension();
};

View file

@ -82,10 +82,6 @@ void Hiopl::EnableWaveformControl() {
_WriteReg(0x01, 0x20);
}
void Hiopl::EnableOpl3Mode() {
_WriteReg(0x105, 0x1);
}
void Hiopl::SetWaveform(int ch, int osc, Waveform wave) {
int offset = this->_GetOffset(ch, osc);
_WriteReg(0xe0+offset, (Bit8u)wave, 0x7);