Skip to content

Commit

Permalink
Not working Arp
Browse files Browse the repository at this point in the history
  • Loading branch information
jnonis committed Jul 18, 2024
1 parent 9c55aa6 commit 0cb0553
Show file tree
Hide file tree
Showing 18 changed files with 2,242 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ OBJS = main.o kernel.o minidexed.o config.o userinterface.o uimenu.o \
effect_talreverb3.o effect_ds1.o effect_bigmuff.o \
moddistortion/Distortion_DS1.o moddistortion/Distortion_BigMuff.o \
moddistortion/HyperbolicTables.o moddistortion/OverSample.o \
effect_compressor.o effect_platervbstereo.o uibuttons.o midipin.o
effect_compressor.o effect_platervbstereo.o uibuttons.o midipin.o \
midi_arp.o modarpeggiator/common/clock.o \
modarpeggiator/common/midiHandler.o modarpeggiator/common/pattern.o \
modarpeggiator/utils.o modarpeggiator/arpeggiator.o

OPTIMIZE = -O3

include ./Synth_Dexed.mk
include ./Rules.mk

EXTRACLEAN += moddistortion/*.[od]
EXTRACLEAN += moddistortion/*.[od] modarpeggiator/*.[od] modarpeggiator/common/*.[od]
101 changes: 101 additions & 0 deletions src/midi_arp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#include "midi_arp.h"
#include <stdio.h>

MidiArp::MidiArp(float32_t samplerate, CDexedAdapter* synth)
{
this->samplerate = samplerate;
this->syncMode = 1;
this->synth = synth;

arpeggiator.transmitHostInfo(0, 4, 1, 1, 120.0);
arpeggiator.setSampleRate(samplerate);
arpeggiator.setDivision(7);

arpeggiator.getMidiBuffer();
}

MidiArp::~MidiArp()
{
}

void MidiArp::keydown(int16_t pitch, uint8_t velocity)
{
MidiEvent event;
event.data[0] = MIDI_NOTE_ON << 4;
event.data[1] = pitch;
event.data[2] = velocity;
event.size = 3;
event.frame = 0;
this->events.push_back(event);
}

void MidiArp::keyup(int16_t pitch)
{
MidiEvent event;
event.data[0] = MIDI_NOTE_OFF << 4;
event.data[1] = pitch;
event.data[2] = 0;
event.size = 3;
event.frame = 0;
this->events.push_back(event);
}

void MidiArp::process(uint16_t len)
{
arpeggiator.emptyMidiBuffer();

// Check if host supports Bar-Beat-Tick position
/*
const TimePosition& position = getTimePosition();
if (!position.bbt.valid) {
// set-arpeggiator in free running mode
arpeggiator.setSyncMode(0);
} else {
arpeggiator.setSyncMode(syncMode);
arpeggiator.transmitHostInfo(position.playing, position.bbt.beatsPerBar, position.bbt.beat, position.bbt.barBeat, static_cast<float>(position.bbt.beatsPerMinute));
}
*/

arpeggiator.process(events.data(), events.size(), len);
events.clear();
events.shrink_to_fit();

/*
printf("Before Send Midi\n");
fflush(NULL);
struct MidiBuffer buffer = arpeggiator.getMidiBuffer();
for (unsigned x = 0; x < buffer.numBufferedEvents + buffer.numBufferedThroughEvents; x++) {
printf("Loop x: %d\n", x);
fflush(NULL);
MidiEvent event = buffer.bufferedEvents[x];
unsigned eventType = event.data[0] >> 4;
switch (eventType)
{
case MIDI_NOTE_ON:
if (event.data[2] > 0)
{
if (event.data[2] <= 127)
{
this->synth->keydown(event.data[1], event.data[2]);
}
}
else
{
this->synth->keyup(event.data[1]);
}
break;
case MIDI_NOTE_OFF:
this->synth->keyup(event.data[1]);
break;
default:
break;
}
}
printf("After Send Midi\n");
fflush(NULL);
*/
}
40 changes: 40 additions & 0 deletions src/midi_arp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Base AudioEffect interface
* Javier Nonis (https://github.com/jnonis) - 2024
*/
#ifndef _MIDI_ARP_H
#define _MIDI_ARP_H

#include <vector>
#include <arm_math.h>
#include "modarpeggiator/common/commons.h"
#include "modarpeggiator/arpeggiator.hpp"
#include "modarpeggiator/common/clock.hpp"
#include "modarpeggiator/common/pattern.hpp"
#include "dexedadapter.h"

class MidiArp
{
public:
MidiArp(float32_t samplerate, CDexedAdapter* synth);
~MidiArp();

void keydown(int16_t pitch, uint8_t velocity);
void keyup(int16_t pitch);

void process(uint16_t len);
protected:
bool bypass = false;
float32_t samplerate;

private:
static const unsigned MIDI_NOTE_OFF = 0b1000;
static const unsigned MIDI_NOTE_ON = 0b1001;

CDexedAdapter* synth;
Arpeggiator arpeggiator;
int syncMode;
std::vector<MidiEvent> events;
};

#endif // _MIDI_ARP_H
12 changes: 9 additions & 3 deletions src/minidexed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ CMiniDexed::CMiniDexed (CConfig *pConfig, CInterruptSystem *pInterrupt,

m_pTG[i] = new CDexedAdapter (CConfig::MaxNotes, pConfig->GetSampleRate ());
assert (m_pTG[i]);

m_MidiArp[i] = new MidiArp(pConfig->GetSampleRate(), m_pTG[i]);

m_pTG[i]->setEngineType(pConfig->GetEngineType ());
m_pTG[i]->activate ();
}
Expand Down Expand Up @@ -416,6 +417,7 @@ void CMiniDexed::Run (unsigned nCore)
for (unsigned i = 0; i < CConfig::TGsCore23; i++, nTG++)
{
assert (m_pTG[nTG]);
m_MidiArp[nTG]->process(m_nFramesToProcess);
m_pTG[nTG]->getSamples (m_OutputLevel[nTG][0],m_nFramesToProcess);
m_InsertFXSpinLock[nTG]->Acquire();
m_InsertFX[nTG]->process(m_OutputLevel[nTG][0], m_OutputLevel[nTG][0], m_OutputLevel[nTG][0], m_OutputLevel[nTG][1], m_nFramesToProcess);
Expand Down Expand Up @@ -783,7 +785,8 @@ void CMiniDexed::keyup (int16_t pitch, unsigned nTG)
pitch = ApplyNoteLimits (pitch, nTG);
if (pitch >= 0)
{
m_pTG[nTG]->keyup (pitch);
m_MidiArp[nTG]->keyup(pitch);
//m_pTG[nTG]->keyup (pitch);
}
}

Expand All @@ -795,7 +798,8 @@ void CMiniDexed::keydown (int16_t pitch, uint8_t velocity, unsigned nTG)
pitch = ApplyNoteLimits (pitch, nTG);
if (pitch >= 0)
{
m_pTG[nTG]->keydown (pitch, velocity);
m_MidiArp[nTG]->keydown(pitch, velocity);
//m_pTG[nTG]->keydown (pitch, velocity);
}
}

Expand Down Expand Up @@ -1214,6 +1218,7 @@ void CMiniDexed::ProcessSound (void)
}

float32_t SampleBuffer[2][nFrames];
m_MidiArp[0]->process(nFrames);
m_pTG[0]->getSamples (SampleBuffer[0], nFrames);
m_InsertFXSpinLock[0]->Acquire();
m_InsertFX[0]->process(SampleBuffer[0], SampleBuffer[0], SampleBuffer[0], SampleBuffer[1], nFrames);
Expand Down Expand Up @@ -1271,6 +1276,7 @@ void CMiniDexed::ProcessSound (void)
for (unsigned i = 0; i < CConfig::TGsCore1; i++)
{
assert (m_pTG[i]);
m_MidiArp[i]->process(nFrames);
m_pTG[i]->getSamples (m_OutputLevel[i][0], nFrames);
m_InsertFXSpinLock[i]->Acquire();
m_InsertFX[i]->process(m_OutputLevel[i][0], m_OutputLevel[i][0], m_OutputLevel[i][0], m_OutputLevel[i][1], nFrames);
Expand Down
2 changes: 2 additions & 0 deletions src/minidexed.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <circle/sound/soundbasedevice.h>
#include <circle/spinlock.h>
#include "common.h"
#include "midi_arp.h"
#include "effect_mixer.hpp"
#include "effect_platervbstereo.h"
#include "effect_compressor.h"
Expand Down Expand Up @@ -302,6 +303,7 @@ class CMiniDexed
unsigned m_nNoteLimitHigh[CConfig::ToneGenerators];
int m_nNoteShift[CConfig::ToneGenerators];

MidiArp* m_MidiArp[CConfig::ToneGenerators];
AudioEffect* m_InsertFX[CConfig::ToneGenerators];
unsigned m_nReverbSend[CConfig::ToneGenerators];

Expand Down
Loading

0 comments on commit 0cb0553

Please sign in to comment.