diff --git a/Makefile b/Makefile index 1e23790..875666a 100644 --- a/Makefile +++ b/Makefile @@ -19,8 +19,8 @@ DEBUG=0 INCFLAGS=`pkg-config jack --cflags` LDFLAGS=`pkg-config jack --libs` -lreadline CFLAGS=$(INCFLAGS) -std=c99 -Wall -Wextra -Wfatal-errors -Werror -HDRS=src/args.h -OBJS=src/main.o +HDRS=src/args.h src/processing.h +OBJS=src/main.o src/processing.o ifeq ($(DEBUG),1) CFLAGS+=-g -O0 -DDEBUG diff --git a/src/main.c b/src/main.c index 96cc136..6d1ed2f 100644 --- a/src/main.c +++ b/src/main.c @@ -17,11 +17,19 @@ */ #include "args.h" +#include "processing.h" #include +#include #include #include +jack_port_t *in_port; +jack_port_t *out_port; +jack_client_t *client; + +void jack_shutdown(void *arg); + int main(int argc, char *argv[]) { struct arguments arguments; arguments.verbose = 0; @@ -29,5 +37,62 @@ int main(int argc, char *argv[]) { arguments.playlist_file = NULL; argp_parse(&argp, argc, argv, 0, 0, &arguments); + + /*const char **ports;*/ + const char *client_name = "saus"; + const char *server_name = NULL; + jack_options_t options = JackNullOption; + jack_status_t status; + + client = jack_client_open(client_name, options, &status, server_name); + if(!client) + { + fprintf(stderr, "jack_client_open() failed, " + "status = 0x%2.0x\n", status); + if(status & JackServerFailed) + { + fprintf(stderr, "Unable to connect to JACK server\n"); + } + exit(1); + } + if(status & JackServerStarted) + { + fprintf(stderr, "JACK server started\n"); + } + if(status & JackNameNotUnique) + { + client_name = jack_get_client_name(client); + fprintf(stderr, "unique name `%s' assigned\n", client_name); + } + + jack_set_process_callback(client, process, 0); + jack_on_shutdown(client, jack_shutdown, "Shut down by JACK server"); + + in_port = jack_port_register(client, "input", + JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); + out_port = jack_port_register(client, "output", + JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); + + if(!in_port || !out_port) + { + fprintf(stderr, "No more JACK ports available\n"); + exit(1); + } + + if(jack_activate(client)) + { + fprintf(stderr, "Cannot activate JACK client\n"); + exit(1); + } + + // TODO: add main loop here + + jack_client_close(client); + return 0; } + +void jack_shutdown(void *arg) { + fprintf(stderr, "%s", (char*)arg); + exit(1); +} diff --git a/src/processing.c b/src/processing.c new file mode 100644 index 0000000..cec90fb --- /dev/null +++ b/src/processing.c @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2019 Ortega Froysa, Nicolás + * Author: Ortega Froysa, Nicolás + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "processing.h" + +#include +#include +#include + +int process(jack_nframes_t nframes, void *arg) { + if(!arg) + { + fprintf(stderr, "No script supplied"); + exit(1); + } + jack_default_audio_sample_t *in, *out; + + memcpy(out, in, + sizeof(jack_default_audio_sample_t) *nframes); + + return 0; +} diff --git a/src/processing.h b/src/processing.h new file mode 100644 index 0000000..857425e --- /dev/null +++ b/src/processing.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2019 Ortega Froysa, Nicolás + * Author: Ortega Froysa, Nicolás + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include + +int process(jack_nframes_t nframes, void *arg);