Commit 50fcae78 authored by brandon's avatar brandon

add guile modules for devices and midi constants

parent 8a620e9f
......@@ -21,7 +21,7 @@ LDADD = -lasound $(LIBINTL)
bin_PROGRAMS = librekontrol
librekontrol_SOURCES = librekontrol.c ni-device.c guile-ni-device.c \
guile-devices.c
guile-devices.c guile-midi.c
librekontrol_LDADD = $(LDADD) $(LIBSOCKET) $(LIB_POLL) $(LIB_SELECT) \
$(LIBINTL) $(EVDEV_LIBS) $(GUILE_LIBS)
librekontrol_CFLAGS = $(EVDEV_CFLAGS) $(GUILE_CFLAGS)
......
/*
* guile-devices.c ---
*
* Copyright (C) 2016 Brandon Invergo <brandon@invergo.net>
*
* Author: Brandon Invergo <brandon@invergo.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "guile-devices.h"
void
register_ctls (const char **ctls, size_t num_ctls, size_t offset)
{
size_t slen, i;
char *ctl_id;
ctl_id = (char *)malloc (9*sizeof (char));
if (!ctl_id)
{
error (EXIT_FAILURE, errno, "Memory exhausted");
}
for (i=0; i<num_ctls; i++)
{
if (i+offset > 8)
{
slen = 9;
}
else
{
slen = 8;
}
if (snprintf (ctl_id, slen, "numid=%zd", i+offset+1) <= 0)
{
error (EXIT_FAILURE, errno, "Unable to build ctl id string");
}
ctl_id[slen-1] = '\0';
scm_permanent_object
(scm_c_define (ctls[i], scm_from_latin1_string (ctl_id)));
scm_c_export (ctls[i]);
}
free (ctl_id);
}
void
register_in_evs (const int *in_evs, const char **in_ev_names,
const int *in_ev_types, size_t num_in_evs)
{
size_t i;
for (i=0; i<num_in_evs; i++)
{
scm_permanent_object
(scm_c_define (in_ev_names[i], scm_cons (scm_from_int (in_ev_types[i]),
scm_from_int (in_evs[i]))));
scm_c_export (in_ev_names[i]);
}
}
void
load_ak1_defs (void *data)
{
const char *ctls[] = {"ak1-led-left", "ak1-led-middle", "ak1-led-right",
"ak1-led-ring"};
int in_evs[] = {30, 48, 46, 0};
const char *in_ev_names[] = {"ak1-button-left", "ak1-button-middle",
"ak1-button-right", "ak1-knob-ring"};
int in_ev_types[] = {EV_KEY, EV_KEY, EV_KEY, EV_ABS};
scm_permanent_object
(scm_c_define ("ak1-device-name",
scm_from_latin1_string ("AudioKontrol1")));
scm_c_export ("ak1-device-name");
scm_permanent_object
(scm_c_define ("ak1-input-name",
scm_from_latin1_string ("Audio Kontrol 1")));
scm_c_export ("ak1-input-name");
register_ctls (ctls, 4, 0);
register_in_evs (in_evs, in_ev_names, in_ev_types, 4);
}
void
load_maschine_defs (void *data)
{
const char *pad_ctls[] =
{"maschine-led-pad-1", "maschine-led-pad-2", "maschine-led-pad-3",
"maschine-led-pad-4", "maschine-led-pad-5", "maschine-led-pad-6",
"maschine-led-pad-7", "maschine-led-pad-8", "maschine-led-pad-9",
"maschine-led-pad-10", "maschine-led-pad-11", "maschine-led-pad-12",
"maschine-led-pad-13", "maschine-led-pad-14", "maschine-led-pad-15",
"maschine-led-pad-16"};
int pad_in_evs[] = {36, 37, 38, 39, 32, 33, 34, 35, 28, 29, 30, 31,
24, 25, 26, 27};
const char *pad_in_ev_names[] =
{"maschine-button-pad-1", "maschine-button-pad-2",
"maschine-button-pad-3", "maschine-button-pad-4",
"maschine-button-pad-5", "maschine-button-pad-6",
"maschine-button-pad-7", "maschine-button-pad-8",
"maschine-button-pad-9", "maschine-button-pad-10",
"maschine-button-pad-11", "maschine-button-pad-12",
"maschine-button-pad-13", "maschine-button-pad-14",
"maschine-button-pad-15", "maschine-button-pad-16"};
int pad_in_ev_types[] =
{EV_ABS, EV_ABS, EV_ABS, EV_ABS, EV_ABS, EV_ABS, EV_ABS, EV_ABS,
EV_ABS, EV_ABS, EV_ABS, EV_ABS, EV_ABS, EV_ABS, EV_ABS, EV_ABS,};
const char *middle_ctls[] =
{"maschine-led-mute", "maschine-led-solo", "maschine-led-select",
"maschine-led-duplicate", "maschine-led-navigate", "maschine-led-pad-mode",
"maschine-led-pattern", "maschine-led-scene"};
int middle_in_evs[] = {296, 295, 294, 293, 292, 291, 290, 289};
const char *middle_in_ev_names[] =
{"maschine-button-mute", "maschine-button-solo", "maschine-button-select",
"maschine-button-duplicate", "maschine-button-navigate",
"maschine-button-pad-mode", "maschine-button-pattern",
"maschine-button-scene"};
int middle_in_ev_types[] =
{EV_KEY, EV_KEY, EV_KEY, EV_KEY, EV_KEY, EV_KEY, EV_KEY, EV_KEY};
const char *transport_ctls[] =
{"maschine-led-shift", "maschine-led-erase", "maschine-led-grid",
"maschine-led-right-bottom", "maschine-led-rec", "maschine-led-play",
"maschine-led-left-bottom", "maschine-led-restart"};
int transport_in_evs[] = {288, 287, 284, 283, 286, 285, 282, 281};
const char *transport_in_ev_names[] =
{"maschine-button-shift", "maschine-button-erase", "maschine-button-grid",
"maschine-button-right-bottom", "maschine-button-rec",
"maschine-button-play", "maschine-button-left-bottom",
"maschine-button-restart"};
int transport_in_ev_types[] =
{EV_KEY, EV_KEY, EV_KEY, EV_KEY, EV_KEY, EV_KEY, EV_KEY, EV_KEY};
const char *groups_ctls[] =
{"maschine-led-group-a", "maschine-led-group-b", "maschine-led-group-c",
"maschine-led-group-d", "maschine-led-group-e", "maschine-led-group-f",
"maschine-led-group-g", "maschine-led-group-h"};
int groups_in_evs[] = {273, 274, 275, 276, 277, 278, 279, 280};
const char *groups_in_ev_names[] =
{"maschine-button-group-a", "maschine-button-group-b",
"maschine-button-group-c", "maschine-button-group-d",
"maschine-button-group-e", "maschine-button-group-f",
"maschine-button-group-g", "maschine-button-group-h"};
int groups_in_ev_types[] =
{EV_KEY, EV_KEY, EV_KEY, EV_KEY, EV_KEY, EV_KEY, EV_KEY, EV_KEY};
const char *topleft_ctls[] =
{"maschine-led-auto-write", "maschine-led-snap", "maschine-led-right-top",
"maschine-led-left-top", "maschine-led-sampling", "maschine-led-browse",
"maschine-led-step", "maschine-led-control"};
int topleft_in_evs[] = {263, 262, 261, 260, 259, 258, 257, 256};
const char *topleft_in_ev_names[] =
{"maschine-button-auto-write", "maschine-button-snap",
"maschine-button-right-top", "maschine-button-left-top",
"maschine-button-sampling", "maschine-button-browse",
"maschine-button-step", "maschine-button-control"};
int topleft_in_ev_types[] =
{EV_KEY, EV_KEY, EV_KEY, EV_KEY, EV_KEY, EV_KEY, EV_KEY, EV_KEY};
const char *top_ctls[] =
{"maschine-led-top-1", "maschine-led-top-2", "maschine-led-top-3",
"maschine-led-top-4", "maschine-led-top-5", "maschine-led-top-6",
"maschine-led-top-7", "maschine-led-top-8"};
int top_in_evs[] = {264, 265, 266, 267, 268, 269, 270, 271};
const char *top_in_ev_names[] =
{"maschine-button-top-1", "maschine-button-top-2", "maschine-button-top-3",
"maschine-button-top-4", "maschine-button-top-5", "maschine-button-top-6",
"maschine-button-top-7", "maschine-button-top-8"};
int top_in_ev_types[] =
{EV_KEY, EV_KEY, EV_KEY, EV_KEY, EV_KEY, EV_KEY, EV_KEY, EV_KEY};
const char *misc_ctls[] =
{"maschine-led-note-repeat", "maschine-backlight-display"};
int misc_in_evs[] = {272};
const char *misc_in_ev_names[] = {"maschine-button-note-repeat"};
int misc_in_ev_types[] = {EV_KEY};
scm_permanent_object
(scm_c_define ("maschine-device-name",
scm_from_latin1_string ("MaschineControl")));
scm_c_export ("maschine-device-name");
scm_permanent_object
(scm_c_define ("maschine-input-name",
scm_from_latin1_string ("Maschine Controller")));
scm_c_export ("maschine-input-name");
register_ctls (pad_ctls, 16, 0);
register_in_evs (pad_in_evs, pad_in_ev_names, pad_in_ev_types, 16);
register_ctls (middle_ctls, 8, 16);
register_in_evs (middle_in_evs, middle_in_ev_names, middle_in_ev_types, 8);
register_ctls (transport_ctls, 8, 24);
register_in_evs (transport_in_evs, transport_in_ev_names,
transport_in_ev_types, 8);
register_ctls (groups_ctls, 8, 32);
register_in_evs (groups_in_evs, groups_in_ev_names, groups_in_ev_types, 8);
register_ctls (topleft_ctls, 8, 40);
register_in_evs (topleft_in_evs, topleft_in_ev_names, topleft_in_ev_types, 8);
register_ctls (top_ctls, 8, 48);
register_in_evs (top_in_evs, top_in_ev_names, top_in_ev_types, 8);
register_ctls (misc_ctls, 2, 56);
register_in_evs (misc_in_evs, misc_in_ev_names, misc_in_ev_types, 1);
}
void
load_device_defs (void)
{
scm_c_define_module ("librekontrol ak1", &load_ak1_defs, NULL);
scm_c_define_module ("librekontrol maschine", &load_maschine_defs, NULL);
}
/*
* guile-devices.h ---
*
* Copyright (C) 2016 Brandon Invergo <brandon@invergo.net>
*
* Author: Brandon Invergo <brandon@invergo.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GUILE_DEVICES_H
#define GUILE_DEVICES_H
#include "error.h"
#include <errno.h>
#include <stdio.h>
#include <libguile.h>
#include <libevdev/libevdev.h>
void load_device_defs (void);
#endif
/*
* guile-midi.c ---
*
* Copyright (C) 2016 Brandon Invergo <brandon@invergo.net>
*
* Author: Brandon Invergo <brandon@invergo.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "guile-midi.h"
void
load_midi_defs_sub (void *data)
{
char *notes[] = {"c", "c#", "d", "d#", "e", "f", "f#", "g", "g#", "a", "a#",
"b"};
size_t i, cur, slen;
unsigned int octave;
char *note;
note = (char *)malloc (15*sizeof (char));
if (!note)
{
error (EXIT_FAILURE, errno, "Memory exhausted");
}
for (i=0; i<128; i++)
{
octave = i/12;
cur = i % 11;
slen = 10 + strlen (notes[cur]) + octave/10 + 1;
snprintf (note, slen+1, "midi-note-%s%u", notes[cur], octave);
note[slen+1] = '\0';
scm_permanent_object
(scm_c_define (note, scm_from_int (i)));
scm_c_export (note);
}
free (note);
}
void
load_midi_defs (void)
{
scm_c_define_module ("librekontrol midi", &load_midi_defs_sub, NULL);
}
/*
* guile-midi.h ---
*
* Copyright (C) 2016 Brandon Invergo <brandon@invergo.net>
*
* Author: Brandon Invergo <brandon@invergo.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GUILE_MIDI_H
#define GUILE_MIDI_H
#include "error.h"
#include <errno.h>
#include <stdio.h>
#include <libguile.h>
void load_midi_defs (void);
#endif
......@@ -455,4 +455,5 @@ init_lk_scm (void *data)
(scm_c_define ("abs-event-max",
scm_from_int (libevdev_event_type_get_max (EV_ABS))));
load_device_defs ();
load_midi_defs ();
}
......@@ -26,6 +26,7 @@
#include <libevdev/libevdev.h>
#include "ni-device.h"
#include "guile-devices.h"
#include "guile-midi.h"
void *init_lk_scm (void *data);
void handle_event (char *device_id, int type, int code, int value);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment