aboutsummaryrefslogtreecommitdiffhomepage
path: root/backends
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2019-08-24 20:19:24 +0200
committercbdev <cb@cbcdn.com>2019-08-24 20:19:24 +0200
commit0906c00d23be220928a656476c26a490998e826e (patch)
tree211b181eefa6d32230912867fe93da31e62bbdb4 /backends
parentfe952470ca4bae4cff25a9090e4c1b05a76a7961 (diff)
downloadmidimonster-0906c00d23be220928a656476c26a490998e826e.tar.gz
midimonster-0906c00d23be220928a656476c26a490998e826e.tar.bz2
midimonster-0906c00d23be220928a656476c26a490998e826e.zip
Only connect to ALSA when instances are requested
Diffstat (limited to 'backends')
-rw-r--r--backends/midi.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/backends/midi.c b/backends/midi.c
index 5b8e561..88b841c 100644
--- a/backends/midi.c
+++ b/backends/midi.c
@@ -3,6 +3,7 @@
#include "midi.h"
#define BACKEND_NAME "midi"
+static char* sequencer_name = NULL;
static snd_seq_t* sequencer = NULL;
enum /*_midi_channel_type*/ {
@@ -40,29 +41,19 @@ int init(){
return 1;
}
- if(snd_seq_open(&sequencer, "default", SND_SEQ_OPEN_DUPLEX, 0) < 0){
- fprintf(stderr, "Failed to open ALSA sequencer\n");
- return 1;
- }
-
//register backend
if(mm_backend_register(midi)){
fprintf(stderr, "Failed to register MIDI backend\n");
return 1;
}
- snd_seq_nonblock(sequencer, 1);
-
- fprintf(stderr, "MIDI client ID is %d\n", snd_seq_client_id(sequencer));
return 0;
}
static int midi_configure(char* option, char* value){
if(!strcmp(option, "name")){
- if(snd_seq_set_client_name(sequencer, value) < 0){
- fprintf(stderr, "Failed to set MIDI client name to %s\n", value);
- return 1;
- }
+ free(sequencer_name);
+ sequencer_name = strdup(value);
return 0;
}
@@ -361,6 +352,21 @@ static int midi_start(){
return 0;
}
+ //connect to the sequencer
+ if(snd_seq_open(&sequencer, "default", SND_SEQ_OPEN_DUPLEX, 0) < 0){
+ fprintf(stderr, "Failed to open ALSA sequencer\n");
+ return 0;
+ }
+
+ snd_seq_nonblock(sequencer, 1);
+ fprintf(stderr, "MIDI client ID is %d\n", snd_seq_client_id(sequencer));
+
+ //update the sequencer client name
+ if(snd_seq_set_client_name(sequencer, sequencer_name) < 0){
+ fprintf(stderr, "Failed to set MIDI client name to %s\n", sequencer_name);
+ return 1;
+ }
+
//create all ports
for(p = 0; p < n; p++){
data = (midi_instance_data*) inst[p]->impl;
@@ -437,12 +443,17 @@ static int midi_shutdown(){
free(inst);
//close midi
- snd_seq_close(sequencer);
- sequencer = NULL;
+ if(sequencer){
+ snd_seq_close(sequencer);
+ sequencer = NULL;
+ }
//free configuration cache
snd_config_update_free_global();
+ free(sequencer_name);
+ sequencer_name = NULL;
+
fprintf(stderr, "MIDI backend shut down\n");
return 0;
}