wip midi
This commit is contained in:
+11
-9
@@ -166,14 +166,16 @@ static void init_inputs(char *video_in[MAX_VIDEO], unsigned int input_count,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void start_video_captures(unsigned int video_count) {
|
static bool start_video_captures(unsigned int video_count) {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < video_count; i++) {
|
for (i = 0; i < video_count; i++) {
|
||||||
if (!inputs[i].error) {
|
if (!inputs[i].error && !video_background_read(&inputs[i], context, i)) {
|
||||||
video_background_read(&inputs[i], context, i);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void free_video_captures(unsigned int video_count) {
|
static void free_video_captures(unsigned int video_count) {
|
||||||
@@ -253,14 +255,18 @@ void forge_run(Parameters params) {
|
|||||||
|
|
||||||
init_inputs(params.video_in, params.video_in_count, params.video_size);
|
init_inputs(params.video_in, params.video_in_count, params.video_size);
|
||||||
|
|
||||||
start_video_captures(params.video_in_count);
|
if (!start_video_captures(params.video_in_count)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
midi = midi_open(config_file_get_str(config, "MIDI_HW", "hw"));
|
midi = midi_open(config_file_get_str(config, "MIDI_HW", "hw"));
|
||||||
|
|
||||||
if (midi.error) {
|
if (midi.error) {
|
||||||
params.demo = true;
|
params.demo = true;
|
||||||
} else {
|
} else {
|
||||||
midi_background_listen(midi, context);
|
if (!midi_background_listen(midi, context)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window_startup(error_callback);
|
window_startup(error_callback);
|
||||||
@@ -311,8 +317,6 @@ void forge_run(Parameters params) {
|
|||||||
|
|
||||||
context->stop = true;
|
context->stop = true;
|
||||||
|
|
||||||
wait(NULL);
|
|
||||||
|
|
||||||
shaders_free(program);
|
shaders_free(program);
|
||||||
|
|
||||||
if (window_output != NULL) {
|
if (window_output != NULL) {
|
||||||
@@ -329,8 +333,6 @@ void forge_run(Parameters params) {
|
|||||||
|
|
||||||
free_video_captures(params.video_in_count);
|
free_video_captures(params.video_in_count);
|
||||||
|
|
||||||
midi_close(midi);
|
|
||||||
|
|
||||||
free_context();
|
free_context();
|
||||||
|
|
||||||
free_files(frag_count);
|
free_files(frag_count);
|
||||||
|
|||||||
+4
-19
@@ -4,15 +4,6 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
void midi_close(MidiDevice device) {
|
|
||||||
if (device.input != NULL) {
|
|
||||||
snd_rawmidi_close(device.input);
|
|
||||||
}
|
|
||||||
if (device.output != NULL) {
|
|
||||||
snd_rawmidi_close(device.input);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MidiDevice midi_open(char *name) {
|
MidiDevice midi_open(char *name) {
|
||||||
MidiDevice device;
|
MidiDevice device;
|
||||||
|
|
||||||
@@ -24,16 +15,12 @@ MidiDevice midi_open(char *name) {
|
|||||||
|
|
||||||
device.error = device.input == NULL || device.output == NULL;
|
device.error = device.input == NULL || device.output == NULL;
|
||||||
|
|
||||||
if (device.error) {
|
|
||||||
midi_close(device);
|
|
||||||
}
|
|
||||||
|
|
||||||
log_debug("(%s) MIDI open", name);
|
log_debug("(%s) MIDI open", name);
|
||||||
|
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
void midi_background_listen(MidiDevice device, SharedContext *context) {
|
bool midi_background_listen(MidiDevice device, SharedContext *context) {
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
unsigned char buffer[3];
|
unsigned char buffer[3];
|
||||||
@@ -41,10 +28,10 @@ void midi_background_listen(MidiDevice device, SharedContext *context) {
|
|||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
log_error("Could not create subprocess");
|
log_error("Could not create subprocess");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
log_info("(%s) background acquisition started (pid: %d)", device.name, pid);
|
log_info("(%s) background acquisition started (pid: %d)", device.name, pid);
|
||||||
|
|
||||||
@@ -57,7 +44,5 @@ void midi_background_listen(MidiDevice device, SharedContext *context) {
|
|||||||
|
|
||||||
log_info("(%s) background acquisition stopped by main thread (pid: %d)",
|
log_info("(%s) background acquisition stopped by main thread (pid: %d)",
|
||||||
device.name, pid);
|
device.name, pid);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// int bytes_read = snd_rawmidi_read(input, input_buffer, sizeof(input_buffer));
|
|
||||||
// snd_rawmidi_write(output, buffer, 3);
|
|
||||||
+1
-2
@@ -4,7 +4,6 @@
|
|||||||
#define MIDI_H
|
#define MIDI_H
|
||||||
|
|
||||||
MidiDevice midi_open(char *name);
|
MidiDevice midi_open(char *name);
|
||||||
void midi_close(MidiDevice device);
|
bool midi_background_listen(MidiDevice device, SharedContext *context);
|
||||||
void midi_background_listen(MidiDevice device, SharedContext *context);
|
|
||||||
|
|
||||||
#endif /* MIDI_H */
|
#endif /* MIDI_H */
|
||||||
+4
-3
@@ -327,7 +327,7 @@ static bool read_video(VideoCapture *video_capture) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void video_background_read(VideoCapture *video_capture, SharedContext *context,
|
bool video_background_read(VideoCapture *video_capture, SharedContext *context,
|
||||||
int input_index) {
|
int input_index) {
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
Timer timer;
|
Timer timer;
|
||||||
@@ -336,10 +336,10 @@ void video_background_read(VideoCapture *video_capture, SharedContext *context,
|
|||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
log_error("Could not create subprocess");
|
log_error("Could not create subprocess");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
log_info("(%s) background acquisition started (pid: %d)", video_capture->name,
|
log_info("(%s) background acquisition started (pid: %d)", video_capture->name,
|
||||||
pid);
|
pid);
|
||||||
@@ -362,6 +362,7 @@ void video_background_read(VideoCapture *video_capture, SharedContext *context,
|
|||||||
video_capture->name, pid);
|
video_capture->name, pid);
|
||||||
}
|
}
|
||||||
exit(context->stop ? EXIT_SUCCESS : EXIT_FAILURE);
|
exit(context->stop ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void video_free(VideoCapture video_capture) {
|
void video_free(VideoCapture video_capture) {
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
VideoCapture video_init(char *name, unsigned int preferred_height);
|
VideoCapture video_init(char *name, unsigned int preferred_height);
|
||||||
|
|
||||||
void video_background_read(VideoCapture *video_capture, SharedContext *context,
|
bool video_background_read(VideoCapture *video_capture, SharedContext *context,
|
||||||
int input_index);
|
int input_index);
|
||||||
|
|
||||||
void video_free(VideoCapture video_capture);
|
void video_free(VideoCapture video_capture);
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ static void init_glfw(void (*error_callback)(int, const char *)) {
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
log_info("[GLFS] Initialized...");
|
log_info("[GLFW] Initialized...");
|
||||||
}
|
}
|
||||||
|
|
||||||
static GLFWmonitor *get_monitor(unsigned char monitor_index) {
|
static GLFWmonitor *get_monitor(unsigned char monitor_index) {
|
||||||
|
|||||||
Reference in New Issue
Block a user