forked from probonopd/MiniDexed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
2,242 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.