Skip to content

Commit

Permalink
feat: add support for Phantom Power control
Browse files Browse the repository at this point in the history
  • Loading branch information
clook committed Feb 19, 2022
1 parent d18dfee commit 65a71ea
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions src/scarlett_mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#define MAX_HIZS 2
#define MAX_PADS 4
#define MAX_AIRS 2
#define MAX_PHANTOM_POWERS 1

typedef struct {
char name[64];
Expand All @@ -58,6 +59,7 @@ typedef struct {
unsigned num_hiz;
unsigned num_pad;
unsigned num_air;
unsigned num_phantom_power;
bool pads_are_switches;
bool matrix_mix_column_major;
unsigned matrix_mix_offset;
Expand All @@ -71,6 +73,7 @@ typedef struct {
int hiz_map[MAX_HIZS];
int pad_map[MAX_PADS];
int air_map[MAX_AIRS];
int phantom_power_map[MAX_PHANTOM_POWERS];
} Device;

static Device devices[] = {
Expand All @@ -83,6 +86,7 @@ static Device devices[] = {
.num_hiz = 2,
.num_pad = 0,
.num_air = 0,
.num_phantom_power = 0,
.pads_are_switches = false,
.matrix_mix_column_major = false,
.matrix_mix_offset = 33, .matrix_mix_stride = 7,
Expand All @@ -103,6 +107,7 @@ static Device devices[] = {
.num_hiz = 2,
.num_pad = 4,
.num_air = 0,
.num_phantom_power = 0,
.pads_are_switches = false,
.matrix_mix_column_major = false,
.matrix_mix_offset = 40, .matrix_mix_stride = 9, // < Matrix 01 Mix A
Expand All @@ -123,6 +128,7 @@ static Device devices[] = {
.num_hiz = 2,
.num_pad = 4, // XXX does the device have pad? bug in kernel-driver?
.num_air = 0,
.num_phantom_power = 0,
.pads_are_switches = false,
.matrix_mix_column_major = false,
.matrix_mix_offset = 26, .matrix_mix_stride = 9, // XXX stride should be 7, bug in kernel-driver ?!
Expand All @@ -143,6 +149,7 @@ static Device devices[] = {
.num_hiz = 0,
.num_pad = 0,
.num_air = 0,
.num_phantom_power = 0,
.pads_are_switches = false,
.matrix_mix_column_major = false,
.matrix_mix_offset = 50, .matrix_mix_stride = 9,
Expand All @@ -161,8 +168,9 @@ static Device devices[] = {
.smst = 0,
.samo = 4,
.num_hiz = 2,
.num_pad = 2,
.num_air = 2,
.num_pad = 2,
.num_air = 2,
.num_phantom_power = 0,
.pads_are_switches = true,
.matrix_mix_column_major = true,
.matrix_mix_offset = 20, .matrix_mix_stride = 8,
Expand All @@ -184,6 +192,7 @@ static Device devices[] = {
.num_hiz = 2,
.num_pad = 2,
.num_air = 2,
.num_phantom_power = 1,
.pads_are_switches = true,
.matrix_mix_column_major = true,
.matrix_mix_offset = 21, .matrix_mix_stride = 8,
Expand All @@ -195,6 +204,7 @@ static Device devices[] = {
.hiz_map = { 15, 19 },
.pad_map = { 16, 20, -1, -1 },
.air_map = { 14, 18 },
.phantom_power_map = { 17 },
},
};

Expand Down Expand Up @@ -232,6 +242,7 @@ typedef struct {
RobTkCBtn** btn_hiz;
RobTkCBtn** btn_pad;
RobTkCBtn** btn_air;
RobTkCBtn** btn_phantom_power;
RobTkPBtn* btn_reset;

RobTkLbl* heading[3];
Expand Down Expand Up @@ -380,6 +391,13 @@ static Mctrl* air (RobTkApp *ui, unsigned c)
return &ui->ctrl[ui->device->air_map[c]];
}

/* Phantom power switches */
static Mctrl* phantom_power (RobTkApp *ui, unsigned c)
{
assert (c < ui->device->num_phantom_power);
return &ui->ctrl[ui->device->phantom_power_map[c]];
}

/* master gain */
static Mctrl* mst_gain (RobTkApp* ui)
{
Expand Down Expand Up @@ -602,6 +620,8 @@ static int open_mixer (RobTkApp* ui, const char* card, int opts)
d.pads_are_switches = true;
} else if (strstr (c->name, " Air")) {
d.air_map[d.num_air++] = i;
} else if (strstr (c->name, " Phantom Power")) {
d.phantom_power_map[d.num_phantom_power++] = i;
}
} else {
if (strstr (c->name, "Line 0") || strstr (c->name, "Line 1")) {
Expand Down Expand Up @@ -896,6 +916,15 @@ static bool cb_set_air (RobWidget* w, void* handle) {
return TRUE;
}

static bool cb_set_phantom_power (RobWidget* w, void* handle) {
RobTkApp* ui = (RobTkApp*)handle;
if (ui->disable_signals) return TRUE;
for (uint32_t i = 0; i < ui->device->num_phantom_power; ++i) {
set_switch (phantom_power (ui, i), robtk_cbtn_get_active (ui->btn_phantom_power[i]));
}
return TRUE;
}

static bool cb_src_sel (RobWidget* w, void* handle) {
RobTkApp* ui = (RobTkApp*)handle;
if (ui->disable_signals) return TRUE;
Expand Down Expand Up @@ -1195,6 +1224,11 @@ static RobWidget* toplevel (RobTkApp* ui, void* const top) {
} else {
ui->btn_air = NULL;
}
if (ui->device->num_phantom_power > 0) {
ui->btn_phantom_power = malloc (ui->device->num_phantom_power * sizeof (RobTkCBtn *));
} else {
ui->btn_phantom_power = NULL;
}

const int c0 = 4; // matrix column offset
const int rb = 2 + ui->device->smi; // matrix bottom
Expand Down Expand Up @@ -1429,6 +1463,15 @@ static RobWidget* toplevel (RobTkApp* ui, void* const top) {
i, i + 1, 5, 6, 0, 0, RTK_SHRINK, RTK_SHRINK);
}

/* Phantom Power */
for (unsigned int i = 0; i < ui->device->num_phantom_power; ++i) {
ui->btn_phantom_power[i] = robtk_cbtn_new ("Phantom", GBT_LED_LEFT, false);
robtk_cbtn_set_active (ui->btn_phantom_power[i], get_switch (phantom_power (ui, i)) == 1);
robtk_cbtn_set_callback (ui->btn_phantom_power[i], cb_set_phantom_power, ui);
rob_table_attach (ui->output, robtk_cbtn_widget (ui->btn_phantom_power[i]),
i, i + 1, 6, 7, 0, 0, RTK_SHRINK, RTK_SHRINK);
}

/* output selectors */
for (unsigned int o = 0; o < ui->device->sout; ++o) {
int row = 4 * floor (o / 10); // beware of bleed into Hi-Z, Pads
Expand Down Expand Up @@ -1525,6 +1568,10 @@ static void gui_cleanup (RobTkApp* ui) {
robtk_cbtn_destroy (ui->btn_air[i]);
}

for (int i = 0; i < ui->device->num_phantom_power; i++) {
robtk_cbtn_destroy (ui->btn_phantom_power[i]);
}

robtk_sep_destroy (ui->sep_v);
robtk_sep_destroy (ui->sep_h);
robtk_sep_destroy (ui->spc_v[0]);
Expand Down Expand Up @@ -1554,6 +1601,7 @@ static void gui_cleanup (RobTkApp* ui) {
free (ui->btn_hiz);
free (ui->btn_pad);
free (ui->btn_air);
free (ui->btn_phantom_power);
}

static char* lookup_device ()
Expand Down

0 comments on commit 65a71ea

Please sign in to comment.