active selection
This commit is contained in:
@@ -10,4 +10,17 @@ unsigned int arr_uint_index_of(UintArray array, unsigned int value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return ARRAY_NOT_FOUND;
|
return ARRAY_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int arr_uint_remap_index(UintArray offsets, unsigned int *index) {
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for (i = offsets.length - 1; i > 0; i--) {
|
||||||
|
if (*index >= offsets.values[i]) {
|
||||||
|
*index -= offsets.values[i];
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -5,4 +5,6 @@
|
|||||||
|
|
||||||
unsigned int arr_uint_index_of(UintArray array, unsigned int value);
|
unsigned int arr_uint_index_of(UintArray array, unsigned int value);
|
||||||
|
|
||||||
|
unsigned int arr_uint_remap_index(UintArray offsets, unsigned int *index);
|
||||||
|
|
||||||
#endif /* ARR_H */
|
#endif /* ARR_H */
|
||||||
+1
-3
@@ -15,7 +15,7 @@ MidiDevice midi_open(char *name) {
|
|||||||
|
|
||||||
device.error = device.input == NULL || device.output == NULL;
|
device.error = device.input == NULL || device.output == NULL;
|
||||||
|
|
||||||
log_debug("(%s) MIDI open", name);
|
log_info("(%s) MIDI open", name);
|
||||||
|
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
@@ -51,8 +51,6 @@ bool midi_background_listen(MidiDevice device, SharedContext *context,
|
|||||||
bytes_read = snd_rawmidi_read(device.input, buffer, 3);
|
bytes_read = snd_rawmidi_read(device.input, buffer, 3);
|
||||||
if (bytes_read == 3) {
|
if (bytes_read == 3) {
|
||||||
event_callback(buffer[1], (float)buffer[2] / 256.0);
|
event_callback(buffer[1], (float)buffer[2] / 256.0);
|
||||||
log_debug("midi: %02x %d %.2f", buffer[0], buffer[1],
|
|
||||||
(float)buffer[2] / 256);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -499,7 +499,7 @@ static void use_program(ShaderProgram program, int i, bool output,
|
|||||||
|
|
||||||
for (j = 0; j < program.active_count; j++) {
|
for (j = 0; j < program.active_count; j++) {
|
||||||
write_uniform_1i(program.iactive_locations[i * program.active_count + j],
|
write_uniform_1i(program.iactive_locations[i * program.active_count + j],
|
||||||
context->active[i] + 1);
|
context->active[j] + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (j = 0; j < program.in_count; j++) {
|
for (j = 0; j < program.in_count; j++) {
|
||||||
|
|||||||
+49
-38
@@ -9,8 +9,9 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
StateConfig state_parse_config(ConfigFile config) {
|
StateConfig state_parse_config(ConfigFile config) {
|
||||||
unsigned int i, j, offset, total, frag_count;
|
unsigned int i, j, offset, total;
|
||||||
StateConfig state_config;
|
StateConfig state_config;
|
||||||
|
UintArray tmp_counts;
|
||||||
char name[256];
|
char name[256];
|
||||||
|
|
||||||
state_config.select_page_codes.length =
|
state_config.select_page_codes.length =
|
||||||
@@ -43,55 +44,62 @@ StateConfig state_parse_config(ConfigFile config) {
|
|||||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO uint arrays
|
state_config.src_count = tmp_counts.length =
|
||||||
state_config.src_count = config_file_get_int(config, "SRC_COUNT", 0);
|
state_config.src_active_offsets.length = state_config.src_offsets.length =
|
||||||
|
config_file_get_int(config, "SRC_COUNT", 0);
|
||||||
|
|
||||||
total = 0;
|
total = 0;
|
||||||
for (i = 0; i < state_config.src_count; i++) {
|
for (i = 0; i < tmp_counts.length; i++) {
|
||||||
sprintf(name, "SRC_%d_ACTIVE_COUNT", i + 1);
|
sprintf(name, "SRC_%d_ACTIVE_COUNT", i + 1);
|
||||||
state_config.src_active_counts[i] = config_file_get_int(config, name, 0);
|
tmp_counts.values[i] = config_file_get_int(config, name, 0);
|
||||||
state_config.src_active_offsets[i] = total;
|
state_config.src_active_offsets.values[i] = total;
|
||||||
total += state_config.src_active_counts[i];
|
total += tmp_counts.values[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < state_config.src_count; i++) {
|
state_config.src_active_codes.length = total;
|
||||||
for (j = 0; j < state_config.src_active_counts[i]; j++) {
|
|
||||||
|
for (i = 0; i < tmp_counts.length; i++) {
|
||||||
|
for (j = 0; j < tmp_counts.values[i]; j++) {
|
||||||
sprintf(name, "SRC_%d_ACTIVE_%d", i + 1, j + 1);
|
sprintf(name, "SRC_%d_ACTIVE_%d", i + 1, j + 1);
|
||||||
state_config.src_active_codes[state_config.src_active_offsets[i] + j] =
|
state_config.src_active_codes
|
||||||
|
.values[state_config.src_active_offsets.values[i] + j] =
|
||||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
total = 0;
|
total = 0;
|
||||||
for (i = 0; i < state_config.src_count; i++) {
|
for (i = 0; i < tmp_counts.length; i++) {
|
||||||
sprintf(name, "SRC_%d_COUNT", i + 1);
|
sprintf(name, "SRC_%d_COUNT", i + 1);
|
||||||
state_config.src_subcounts[i] = config_file_get_int(config, name, 0);
|
tmp_counts.values[i] = config_file_get_int(config, name, 0);
|
||||||
state_config.src_offsets[i] = total;
|
state_config.src_offsets.values[i] = total;
|
||||||
total += state_config.src_subcounts[i];
|
total += tmp_counts.values[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < state_config.src_count; i++) {
|
state_config.src_codes.length = total * 3;
|
||||||
offset = state_config.src_offsets[i];
|
|
||||||
for (j = 0; j < state_config.src_subcounts[i]; j++) {
|
for (i = 0; i < tmp_counts.length; i++) {
|
||||||
|
offset = state_config.src_offsets.values[i];
|
||||||
|
for (j = 0; j < tmp_counts.values[i]; j++) {
|
||||||
sprintf(name, "SRC_%d_%d_X", i + 1, j + 1);
|
sprintf(name, "SRC_%d_%d_X", i + 1, j + 1);
|
||||||
state_config.src_active_codes[(offset + j) * 3] =
|
state_config.src_codes.values[(offset + j) * 3] =
|
||||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||||
|
|
||||||
sprintf(name, "SRC_%d_%d_Y", i + 1, j + 1);
|
sprintf(name, "SRC_%d_%d_Y", i + 1, j + 1);
|
||||||
state_config.src_active_codes[(offset + j) * 3 + 1] =
|
state_config.src_codes.values[(offset + j) * 3 + 1] =
|
||||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||||
|
|
||||||
sprintf(name, "SRC_%d_%d_Z", i + 1, j + 1);
|
sprintf(name, "SRC_%d_%d_Z", i + 1, j + 1);
|
||||||
state_config.src_active_codes[(offset + j) * 3 + 2] =
|
state_config.src_codes.values[(offset + j) * 3 + 2] =
|
||||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
state_config.fader_count = config_file_get_int(config, "FADER_COUNT", 0);
|
state_config.fader_codes.length =
|
||||||
|
config_file_get_int(config, "FADER_COUNT", 0);
|
||||||
|
|
||||||
for (i = 0; i < state_config.fader_count; i++) {
|
for (i = 0; i < state_config.fader_codes.length; i++) {
|
||||||
sprintf(name, "FADER_%d", i + 1);
|
sprintf(name, "FADER_%d", i + 1);
|
||||||
state_config.fader_codes[i] =
|
state_config.fader_codes.values[i] =
|
||||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,52 +111,55 @@ StateConfig state_parse_config(ConfigFile config) {
|
|||||||
|
|
||||||
void state_apply_event(SharedContext *context, StateConfig state_config,
|
void state_apply_event(SharedContext *context, StateConfig state_config,
|
||||||
MidiDevice midi, unsigned char code, float value) {
|
MidiDevice midi, unsigned char code, float value) {
|
||||||
unsigned int index;
|
unsigned int index, part;
|
||||||
bool found;
|
bool found;
|
||||||
|
|
||||||
found = false;
|
found = false;
|
||||||
|
|
||||||
if (value > 0) {
|
if (value > 0) {
|
||||||
index =
|
|
||||||
arr_uint_index_of(state_config.select_page_codes, (unsigned int)code);
|
|
||||||
|
|
||||||
// PAGE CHANGE
|
// PAGE CHANGE
|
||||||
|
index = arr_uint_index_of(state_config.select_page_codes, code);
|
||||||
if (index != ARRAY_NOT_FOUND) {
|
if (index != ARRAY_NOT_FOUND) {
|
||||||
context->page = index;
|
context->page = index;
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
index = arr_uint_index_of(state_config.select_frag_codes, code);
|
|
||||||
|
|
||||||
// TARGET CHANGE
|
// TARGET CHANGE
|
||||||
|
index = arr_uint_index_of(state_config.select_frag_codes, code);
|
||||||
if (index != ARRAY_NOT_FOUND) {
|
if (index != ARRAY_NOT_FOUND) {
|
||||||
context->selected = index + 1;
|
context->selected = index + 1;
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
index = arr_uint_index_of(state_config.select_item_codes, code);
|
|
||||||
|
|
||||||
// ITEM CHANGE
|
// ITEM CHANGE
|
||||||
|
index = arr_uint_index_of(state_config.select_item_codes, code);
|
||||||
if (index != ARRAY_NOT_FOUND) {
|
if (index != ARRAY_NOT_FOUND) {
|
||||||
context->state[context->selected - 1] =
|
context->state[context->selected - 1] =
|
||||||
context->page * state_config.select_item_codes.length + index;
|
context->page * state_config.select_item_codes.length + index;
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!found) {
|
// ACTIVE CHANGE
|
||||||
log_debug("unknown midi: %d %.2f", code, value);
|
index = arr_uint_index_of(state_config.src_active_codes, code);
|
||||||
|
if (index != ARRAY_NOT_FOUND) {
|
||||||
|
part = arr_uint_remap_index(state_config.src_active_offsets, &index);
|
||||||
|
context->active[part] = index;
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
log_trace("unknown midi: %d %.2f", code, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
midi_write(midi, code, value);
|
midi_write(midi, code, value);
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
bool state_background_midi_write(SharedContext *context,
|
bool state_background_midi_write(
|
||||||
StateConfig state_config, MidiDevice midi) {
|
SharedContext *context, __attribute__((unused)) StateConfig state_config,
|
||||||
|
__attribute__((unused)) MidiDevice midi) {
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int bytes_read;
|
|
||||||
unsigned char buffer[3];
|
|
||||||
|
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
|
|||||||
+8
-13
@@ -59,6 +59,7 @@ typedef struct ShaderProgram {
|
|||||||
GLuint vertex_array[2];
|
GLuint vertex_array[2];
|
||||||
|
|
||||||
unsigned int tex_count;
|
unsigned int tex_count;
|
||||||
|
// TODO use arrays
|
||||||
GLuint textures[ARRAY_SIZE];
|
GLuint textures[ARRAY_SIZE];
|
||||||
|
|
||||||
unsigned int frag_count;
|
unsigned int frag_count;
|
||||||
@@ -118,6 +119,7 @@ typedef GLFWwindow Window;
|
|||||||
typedef struct SharedContext {
|
typedef struct SharedContext {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
// TODO use arrays
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
unsigned int internal_width;
|
unsigned int internal_width;
|
||||||
@@ -141,23 +143,16 @@ typedef struct SharedContext {
|
|||||||
|
|
||||||
typedef struct StateConfig {
|
typedef struct StateConfig {
|
||||||
unsigned int state_max;
|
unsigned int state_max;
|
||||||
|
unsigned int src_count;
|
||||||
|
|
||||||
UintArray select_page_codes;
|
UintArray select_page_codes;
|
||||||
UintArray select_item_codes;
|
UintArray select_item_codes;
|
||||||
|
|
||||||
UintArray select_frag_codes;
|
UintArray select_frag_codes;
|
||||||
|
UintArray src_active_offsets;
|
||||||
// TODO Uint arrays
|
UintArray src_active_codes;
|
||||||
unsigned int src_count;
|
UintArray src_offsets;
|
||||||
unsigned int src_active_counts[ARRAY_SIZE];
|
UintArray src_codes;
|
||||||
unsigned int src_active_offsets[ARRAY_SIZE];
|
UintArray fader_codes;
|
||||||
unsigned int src_active_codes[ARRAY_SIZE];
|
|
||||||
unsigned int src_subcounts[ARRAY_SIZE];
|
|
||||||
unsigned int src_offsets[ARRAY_SIZE];
|
|
||||||
unsigned int src_codes[ARRAY_SIZE];
|
|
||||||
|
|
||||||
unsigned int fader_count;
|
|
||||||
unsigned int fader_codes[ARRAY_SIZE];
|
|
||||||
|
|
||||||
unsigned int tap_tempo_code;
|
unsigned int tap_tempo_code;
|
||||||
} StateConfig;
|
} StateConfig;
|
||||||
|
|||||||
Reference in New Issue
Block a user