Code cleanup.

pull/1/head
Holger Wirtz 8 years ago
parent da56d6ba6d
commit 3bc4c28cfe
  1. 4
      src/Dexed.ttl
  2. 110
      src/dexed.cpp
  3. 8
      src/dexed.h

@ -61,7 +61,7 @@
lv2:index 5 ; lv2:index 5 ;
lv2:symbol "engine" ; lv2:symbol "engine" ;
lv2:name "ENGINE" ; lv2:name "ENGINE" ;
lv2:default 3 ; lv2:default 2 ;
lv2:minimum 1 ; lv2:minimum 1 ;
lv2:maximum 3 ; lv2:maximum 3 ;
lv2:portProperty lv2:integer ; lv2:portProperty lv2:integer ;
@ -1517,6 +1517,6 @@
lv2:portProperty lv2:integer ; lv2:portProperty lv2:integer ;
] ; ] ;
doap:name "DeeAxe7" ; doap:name "Dexed" ;
doap:maintainer [ foaf:name "dcoredump" ] . doap:maintainer [ foaf:name "dcoredump" ] .

@ -19,7 +19,6 @@ Dexed::Dexed(double rate) : lvtk::Synth<DexedVoice, Dexed>(p_n_ports, p_midi_in)
TRACE("Hi"); TRACE("Hi");
bufsize_=256; bufsize_=256;
//outbuf_=new int16_t[bufsize_];
outbuf_=new float[bufsize_]; outbuf_=new float[bufsize_];
Exp2::init(); Exp2::init();
@ -89,14 +88,29 @@ Dexed::~Dexed()
void Dexed::set_params(void) void Dexed::set_params(void)
{ {
TRACE("Hi"); // Dexed-Engine
if(getEngineType()!=(*p(p_engine))-1)
refreshVoice=true; {
panic();
setEngineType((*p(p_engine))-1);
}
// Dexed-Filter // Dexed-Filter
fx.uiCutoff=*p(p_cutoff); if(fx.uiCutoff!=*p(p_cutoff))
fx.uiReso=*p(p_resonance); {
fx.uiGain=*p(p_output); fx.uiCutoff=*p(p_cutoff);
refreshVoice=true;
}
if(fx.uiReso!=*p(p_resonance))
{
fx.uiReso=*p(p_resonance);
refreshVoice=true;
}
if(fx.uiGain!=*p(p_output))
{
fx.uiGain=*p(p_output);
refreshVoice=true;
}
// OP6 // OP6
onParam(0,static_cast<char>(*p(p_op6_eg_rate_1))); onParam(0,static_cast<char>(*p(p_op6_eg_rate_1)));
@ -252,8 +266,6 @@ void Dexed::set_params(void)
onParam(144,static_cast<char>(*p(p_transpose))); onParam(144,static_cast<char>(*p(p_transpose)));
// 10 bytes (145-154) are the name of the patch // 10 bytes (145-154) are the name of the patch
onParam(155,0x3f); // operator on/off => All OPs on onParam(155,0x3f); // operator on/off => All OPs on
TRACE("Bye");
} }
// override the run() method // override the run() method
@ -263,6 +275,8 @@ void Dexed::run (uint32_t sample_count)
float* output = p(p_audio_out); float* output = p(p_audio_out);
uint32_t last_frame = 0, num_this_time = 0; uint32_t last_frame = 0, num_this_time = 0;
set_params(); // pre_process: copy actual voice params
for (LV2_Atom_Event* ev = lv2_atom_sequence_begin (&seq->body); for (LV2_Atom_Event* ev = lv2_atom_sequence_begin (&seq->body);
!lv2_atom_sequence_is_end(&seq->body, seq->atom.size, ev); !lv2_atom_sequence_is_end(&seq->body, seq->atom.size, ev);
ev = lv2_atom_sequence_next (ev)) ev = lv2_atom_sequence_next (ev))
@ -272,14 +286,16 @@ void Dexed::run (uint32_t sample_count)
// If it's midi, send it to the engine // If it's midi, send it to the engine
if (ev->body.type == m_midi_type) if (ev->body.type == m_midi_type)
{ {
set_params(); // pre_process: copy actual voice params
ring_buffer_.Write ((uint8_t*) LV2_ATOM_BODY (&ev->body), ev->body.size);
#ifdef DEBUG #ifdef DEBUG
for(uint i=0;i<ev->body.size;i++) for(uint i=0;i<ev->body.size;i++)
{ {
TRACE("midi msg %d: %d\n",i,((uint8_t*)LV2_ATOM_BODY(&ev->body))[i]); TRACE("midi msg %d: %d\n",i,((uint8_t*)LV2_ATOM_BODY(&ev->body))[i]);
} }
#endif #endif
// ring_buffer_.Write ((uint8_t*) LV2_ATOM_BODY (&ev->body), ev->body.size);
if(ProcessMidiMessage((uint8_t*) LV2_ATOM_BODY (&ev->body),ev->body.size)==false)
break;
} }
// render audio from the last frame until the timestamp of this event // render audio from the last frame until the timestamp of this event
@ -289,7 +305,6 @@ void Dexed::run (uint32_t sample_count)
// j is the index of the plugin's float output buffer which will be the timestamp // j is the index of the plugin's float output buffer which will be the timestamp
// of the last processed atom event. // of the last processed atom event.
for (uint32_t i = 0, j = last_frame; i < num_this_time; ++i, ++j) for (uint32_t i = 0, j = last_frame; i < num_this_time; ++i, ++j)
//output[j] = (static_cast<float> (outbuf_[i])) * *p(p_output);
output[j]=outbuf_[i]; output[j]=outbuf_[i];
last_frame = ev->time.frames; last_frame = ev->time.frames;
@ -305,7 +320,6 @@ void Dexed::run (uint32_t sample_count)
num_this_time = sample_count - last_frame; num_this_time = sample_count - last_frame;
GetSamples (num_this_time, outbuf_); GetSamples (num_this_time, outbuf_);
for (uint32_t i = 0, j = last_frame; i < num_this_time; ++i, ++j) for (uint32_t i = 0, j = last_frame; i < num_this_time; ++i, ++j)
//output[j] = (static_cast<float> (outbuf_[i])) * *p(p_output);
output[j] = outbuf_[i]; output[j] = outbuf_[i];
} }
@ -314,7 +328,7 @@ void Dexed::run (uint32_t sample_count)
void Dexed::GetSamples(int n_samples, float *buffer) void Dexed::GetSamples(int n_samples, float *buffer)
{ {
size_t input_offset; /* size_t input_offset;
TransferInput(); TransferInput();
for (input_offset = 0; input_offset < input_buffer_index_; ) { for (input_offset = 0; input_offset < input_buffer_index_; ) {
@ -325,7 +339,7 @@ void Dexed::GetSamples(int n_samples, float *buffer)
} }
input_offset += bytes_consumed; input_offset += bytes_consumed;
} }
ConsumeInput(input_offset); ConsumeInput(input_offset); */
int i; int i;
if ( refreshVoice ) { if ( refreshVoice ) {
@ -394,20 +408,25 @@ void Dexed::GetSamples(int n_samples, float *buffer)
} }
extra_buf_size_ = i - n_samples; extra_buf_size_ = i - n_samples;
} }
//#ifdef DEBUG
//for(i=0;i<n_samples;i++)
// TRACE("samplebuffer[%d]=%f",i,buffer[i]);
//#endif
} }
//void Dexed::processMidiMessage(const MidiMessage *msg) { bool Dexed::ProcessMidiMessage(const uint8_t *buf, int buf_size) {
int Dexed::ProcessMidiMessage(const uint8_t *buf, int buf_size) { TRACE("Hi");
uint8_t cmd = buf[0]; uint8_t cmd = buf[0];
switch(cmd & 0xf0) { switch(cmd & 0xf0) {
case 0x80 : case 0x80 :
keyup(buf[1]); keyup(buf[1]);
return(3); return(true);
case 0x90 : case 0x90 :
keydown(buf[1], buf[2]); keydown(buf[1], buf[2]);
return(3); return(true);
case 0xb0 : { case 0xb0 : {
int ctrl = buf[1]; int ctrl = buf[1];
@ -439,45 +458,32 @@ int Dexed::ProcessMidiMessage(const uint8_t *buf, int buf_size) {
break; break;
} }
} }
return(3); return(true);
case 0xc0 : case 0xc0 :
//setCurrentProgram(buf[1]); //setCurrentProgram(buf[1]);
return(3); return(true);
// aftertouch // aftertouch
case 0xd0 : case 0xd0 :
controllers.aftertouch_cc = buf[1]; controllers.aftertouch_cc = buf[1];
controllers.refresh(); controllers.refresh();
return(3); return(true);
} }
switch (cmd) { switch (cmd) {
case 0xe0 : case 0xe0 :
controllers.values_[kControllerPitch] = buf[1] | (buf[2] << 7); controllers.values_[kControllerPitch] = buf[1] | (buf[2] << 7);
return(3); return(true);
break; break;
} }
return(3);
}
void Dexed::TransferInput() { TRACE("MIDI event unknown: cmd=%d, val1=%d, val2=%d",buf[0],buf[1],buf[2]);
size_t bytes_available = ring_buffer_.BytesAvailable();
int bytes_to_read = min(bytes_available,
sizeof(input_buffer_) - input_buffer_index_);
if (bytes_to_read > 0) {
ring_buffer_.Read(bytes_to_read, input_buffer_ + input_buffer_index_);
input_buffer_index_ += bytes_to_read;
}
}
void Dexed::ConsumeInput(size_t n_input_bytes) { TRACE("Bye");
if (n_input_bytes < input_buffer_index_) {
memmove(input_buffer_, input_buffer_ + n_input_bytes, return(false);
input_buffer_index_ - n_input_bytes);
}
input_buffer_index_ -= n_input_bytes;
} }
void Dexed::keydown(uint8_t pitch, uint8_t velo) { void Dexed::keydown(uint8_t pitch, uint8_t velo) {
@ -580,7 +586,11 @@ TRACE("Bye");
void Dexed::onParam(int param_num,int param_val) void Dexed::onParam(int param_num,int param_val)
{ {
data[param_num]=param_val; if(param_val!=data[param_num])
{
refreshVoice=true;
data[param_num]=param_val;
}
} }
int Dexed::getEngineType() { int Dexed::getEngineType() {
@ -611,6 +621,16 @@ void Dexed::setMonoMode(bool mode) {
monoMode = mode; monoMode = mode;
} }
void Dexed::panic(void) {
for(int i=0;i<MAX_ACTIVE_NOTES;i++) {
voices[i].keydown = false;
voices[i].live = false;
if ( voices[i].dx7_note != NULL ) {
voices[i].dx7_note->oscSync();
}
}
}
//============================================================================== //==============================================================================
DexedVoice::DexedVoice(double rate) : m_key(lvtk::INVALID_KEY), m_rate(rate) DexedVoice::DexedVoice(double rate) : m_key(lvtk::INVALID_KEY), m_rate(rate)

@ -92,12 +92,11 @@ class Dexed : public lvtk::Synth<DexedVoice, Dexed>
VoiceStatus voiceStatus; VoiceStatus voiceStatus;
protected: protected:
int ProcessMidiMessage(const uint8_t *buf, int buf_size); bool ProcessMidiMessage(const uint8_t *buf, int buf_size);
void onParam(int param_num,int param_val); void onParam(int param_num,int param_val);
void TransferInput();
void ConsumeInput(size_t n_input_bytes);
void keyup(uint8_t pitch); void keyup(uint8_t pitch);
void keydown(uint8_t pitch, uint8_t velo); void keydown(uint8_t pitch, uint8_t velo);
void panic(void);
static const int MAX_ACTIVE_NOTES = 16; static const int MAX_ACTIVE_NOTES = 16;
ProcessorVoice voices[MAX_ACTIVE_NOTES]; ProcessorVoice voices[MAX_ACTIVE_NOTES];
@ -115,13 +114,10 @@ class Dexed : public lvtk::Synth<DexedVoice, Dexed>
EngineMkI engineMkI; EngineMkI engineMkI;
EngineOpl engineOpl; EngineOpl engineOpl;
RingBuffer ring_buffer_; RingBuffer ring_buffer_;
//int16_t* outbuf16_;
float* outbuf_; float* outbuf_;
uint32_t bufsize_; uint32_t bufsize_;
int16_t extra_buf_[N]; int16_t extra_buf_[N];
int extra_buf_size_; int extra_buf_size_;
uint8_t input_buffer_[8192];
size_t input_buffer_index_;
private: private:
}; };

Loading…
Cancel
Save