Skip to content

Commit

Permalink
support for disting ex
Browse files Browse the repository at this point in the history
  • Loading branch information
scanner-darkly committed Jul 15, 2020
1 parent 2e72b01 commit 2bdee6e
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/ansible_grid.c
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,7 @@ static void preset_mode_handle_key(u8 x, u8 y, u8 z, u8* glyph) {
follower_change_mode(&followers[follower], x - 13);
}
}
if (y >= 2 && y <= 5) {
if (y >= 2 && y <= 6) {
if (x == 5) {
follower = y - 2;
}
Expand All @@ -1661,7 +1661,7 @@ static void preset_mode_handle_key(u8 x, u8 y, u8 z, u8* glyph) {
if (x > 7) {
glyph[y] ^= 1<<(x-8);
}
if (x == 5 && y >= 2 && y <= 5) {
if (x == 5 && y >= 2 && y <= 6) {
if (mod_follower) {
follower = y - 2;
follower_select = true;
Expand Down
102 changes: 102 additions & 0 deletions src/ansible_ii_leader.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,94 @@ static void ii_slew_txo(i2c_follower_t* follower, uint8_t track, uint16_t slew)
}
}

static void ii_mode_disting_ex(i2c_follower_t* follower, uint8_t track, uint8_t mode) {
if (mode > follower->mode_ct) return;
follower->active_mode = mode;
}

static void ii_tr_disting_ex(i2c_follower_t* follower, uint8_t track, uint8_t state) {
uint8_t d[4] = { 0 };

uint16_t dac_value = dac_get_value(track);
s32 note = (((s32)dac_value * 240) / 16384);
note = note / 2 + (note & 1) + 72 + 12 * follower->oct;
if ((follower->active_mode == 1 || follower->active_mode == 2) && (note < 0 || note > 127)) return;

switch (follower->active_mode) {
case 0: // SD Multisample / SD Triggers
if (state) {
d[0] = 0x52;
d[1] = track;
d[2] = 0x20;
d[3] = 0;
i2c_leader_tx(follower->addr, d, 4);
} else {
d[0] = 0x53;
d[1] = track;
i2c_leader_tx(follower->addr, d, 2);
}
break;
case 1: // MIDI channel 1
if (state) {
d[0] = 0x4F;
d[1] = 0x90;
d[2] = note;
d[3] = 80;
i2c_leader_tx(follower->addr, d, 4);
} else {
d[0] = 0x4F;
d[1] = 0x80;
d[2] = note;
d[3] = 0;
i2c_leader_tx(follower->addr, d, 4);
}
break;
case 2: // MIDI channels 1-4
if (state) {
d[0] = 0x4F;
d[1] = 0x90 + track;
d[2] = note;
d[3] = 80;
i2c_leader_tx(follower->addr, d, 4);
} else {
d[0] = 0x4F;
d[1] = 0x80 + track;
d[2] = note;
d[3] = 0;
i2c_leader_tx(follower->addr, d, 4);
}
break;
default: return;
}
}

static void ii_mute_disting_ex(i2c_follower_t* follower, uint8_t track, uint8_t mode) {
for (uint8_t i = 0; i < 4; i++) {
ii_tr_disting_ex(follower, i, 0);
}
}

static void ii_cv_disting_ex(i2c_follower_t* follower, uint8_t track, uint16_t dac_value) {
uint8_t d[4] = { 0 };

if (follower->active_mode == 0) {
s8 octave = ET[12*abs(follower->oct - 1)];
if (follower->oct - 1 < 0) octave = -octave;
dac_value = (int)dac_value + octave;
d[0] = 0x51;
d[1] = track;
d[2] = dac_value >> 8;
d[3] = dac_value;
i2c_leader_tx(follower->addr, d, 4);
}
}

static void ii_u8_nop(i2c_follower_t* follower, uint8_t track, uint8_t state) {
}

static void ii_s8_nop(i2c_follower_t* follower, uint8_t track, int8_t state) {
}

static void ii_u16_nop(i2c_follower_t* follower, uint8_t track, uint16_t dac_value) {
}

Expand Down Expand Up @@ -386,6 +471,23 @@ i2c_follower_t followers[I2C_FOLLOWER_COUNT] = {
.mode_ct = 1,
.active_mode = 1, // always gate/cv
},
{
.addr = DISTING_EX_1,
.active = false,
.track_en = 0xF,
.oct = 0,

.init = ii_u8_nop,
.mode = ii_mode_disting_ex,
.tr = ii_tr_disting_ex,
.mute = ii_mute_disting_ex,
.cv = ii_cv_disting_ex,
.octave = ii_s8_nop,
.slew = ii_u16_nop,

.mode_ct = 3,
.active_mode = 0,
},
};

void follower_change_mode(i2c_follower_t* follower, uint8_t param) {
Expand Down
2 changes: 1 addition & 1 deletion src/ansible_ii_leader.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#define I2C_FOLLOWER_COUNT 3
#define I2C_FOLLOWER_COUNT 4

struct i2c_follower_t;

Expand Down

0 comments on commit 2bdee6e

Please sign in to comment.