Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping v1 #87

Closed
wants to merge 134 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
4220ae1
mappa: initial commit of v1 input mapping API
harryhaaren Jun 11, 2018
c1392ec
mappa: adding lists for targets and implementation
harryhaaren Jun 11, 2018
69cc30d
mappa: add removal of target impl and test
harryhaaren Jun 11, 2018
f03dd27
mappa: adding multiple targets to linked list
harryhaaren Jun 11, 2018
4a79a34
mappa: implemented event lut, and event handling
harryhaaren Jun 12, 2018
2c174e0
mappa: refactor lut and error check
harryhaaren Jun 15, 2018
57f0b06
mappa: insert concept of dev_t for devices
harryhaaren Jun 15, 2018
adcc42e
mappa: reworking dev, few valgrind gotchas to fix
harryhaaren Jun 15, 2018
5ea7211
mappa: refactoring event handling / lookup
harryhaaren Jun 16, 2018
5069202
mappa: fix handling of null ptr
harryhaaren Jun 16, 2018
1ceeeac
mappa: enable other control types
harryhaaren Jun 16, 2018
9a0b244
mappa: give luts an index for switching
harryhaaren Jun 16, 2018
bf71bc1
mappa: poc layer switching is working
harryhaaren Jun 16, 2018
5a99064
mappa: test layer 2 binding too
harryhaaren Jun 16, 2018
e71f42a
mappa: error check items based on control counts
harryhaaren Jun 16, 2018
3cdecf1
mappa: refactor error handling, no more crashy
harryhaaren Jun 16, 2018
a234489
mappa: initial feedback prototype
harryhaaren Jun 16, 2018
2c3d5e1
mappa: refactoring feedback sources
harryhaaren Jun 16, 2018
beb597e
mappa: feedback wip, almost there, some pointer issue
harryhaaren Jun 16, 2018
d6b8ad6
mappa: fixed led feedback, 2 src functions in app
harryhaaren Jun 17, 2018
851a5ca
mappa: cleanup prints, error checks, mini refactor
harryhaaren Jun 17, 2018
3ceb202
mappa: refactor main, cleanup sources
harryhaaren Jun 17, 2018
d0bfc71
mappa: add tailq of devices
harryhaaren Jun 17, 2018
fb2765e
mappa: fix error return in bind source
harryhaaren Jun 17, 2018
5644f8a
mappa: cleanup now has zero valgrind warnings
harryhaaren Jun 17, 2018
c55150d
mappa: initial token based target approach
harryhaaren Jun 17, 2018
cf800b1
mappa: token targets, large refactor, broken/wip
harryhaaren Jun 17, 2018
86e82e0
mappa: add error checks, fix function prototype
harryhaaren Jun 17, 2018
4cbf7d9
mappa: refactor targets to contain pointers
harryhaaren Jun 17, 2018
be05e89
mappa: refactor cloning / adding of targets
harryhaaren Jun 17, 2018
11e3ec9
mappa: refactor lut target pointer handling
harryhaaren Jun 17, 2018
bcc8593
mappa: API refactoring for consist. tokens working
harryhaaren Jun 17, 2018
a9a1221
mappa: remove dead code for target mappings
harryhaaren Jun 17, 2018
25b1dbd
mappa: tokens verified with 32 byte payload
harryhaaren Jun 17, 2018
96a3b9a
mappa: relax asserts() to debug prints
harryhaaren Jun 17, 2018
62d0b7e
mappa: token based feedback initial commit
harryhaaren Jun 17, 2018
52f9630
mappa: feedback using source_id for search
harryhaaren Jun 17, 2018
be912e0
mappa: feedback mapped to layer 2
harryhaaren Jun 17, 2018
48be0cf
mappa: fixed layer binding with outputs
harryhaaren Jun 17, 2018
84f58e3
mappa: fix layer switching
harryhaaren Jun 17, 2018
a86574e
mappa: reduce asserts() to debug printfs
harryhaaren Jun 17, 2018
1f4a907
mappa: implement lookup APIs for ID
harryhaaren Jun 18, 2018
f22406b
mappa: add ini.h/c files
harryhaaren Jun 18, 2018
4fb051b
mappa: implement config file loading
harryhaaren Jun 18, 2018
103c102
mappa: add demo map file
harryhaaren Jun 18, 2018
1563fc2
mappa: config file feedback to device working
harryhaaren Jun 18, 2018
f390c44
mappa: mute some runtime prints
harryhaaren Jun 18, 2018
59e9b16
mappa: refactor config binding loading
harryhaaren Jun 18, 2018
08b66ab
mappa: layer switching by config file enabled
harryhaaren Jun 18, 2018
6661dc9
mappa: refactor header file, remove impl functions
harryhaaren Jun 18, 2018
eb78d1c
mappa: implement source_remove()
harryhaaren Jun 20, 2018
5e810da
mappa: include in main ctlra directory
harryhaaren Jun 25, 2018
6748397
mappa: add C++ gaurds to header, fix filename
harryhaaren Jun 25, 2018
6e71859
mappa: fix includes to be local path includes
harryhaaren Jun 25, 2018
baf8b59
mappa: dynamic log prints with MACRO, cleanup
harryhaaren Jun 26, 2018
cea7ad7
mappa: handle resource freeing in remove callback
harryhaaren Jun 26, 2018
c4970b6
mappa: fix iteration over binding items
harryhaaren Jun 26, 2018
b0454b3
mappa: refactor lut creation code
harryhaaren Jun 26, 2018
4b0c09a
mappa: reworking lut loading adding name
harryhaaren Jun 27, 2018
ecf91dd
mappa: rework mapping APIs to take char layer name
harryhaaren Jun 27, 2018
aa10b24
mappa: wip conversion to ctlra name based config
harryhaaren Jun 27, 2018
c6ecc94
mappa: large refactor of config file loading
harryhaaren Jun 27, 2018
4eb9c8b
mappa: prefix names with button. slider. etc
harryhaaren Jun 27, 2018
fee71a0
mappa: added TODO on dynamic target add from app
harryhaaren Jun 27, 2018
e54ba67
ctlra: fix event name array missing item
harryhaaren Jun 27, 2018
2f8e815
mappa: fix mem leak on close by free of active_lut
harryhaaren Jun 27, 2018
ebfcdc8
mappa: error check inputs for load_bindings better
harryhaaren Jun 27, 2018
bc7760b
mappa: add name to lut_create() function
harryhaaren Jun 27, 2018
e811c2c
mappa: fix bug in strcmp() == 0 vs != 0
harryhaaren Jun 27, 2018
74d1720
mappa: mapping_count error check value added
harryhaaren Jun 28, 2018
d039f7c
mappa: initial overlay list implementation
harryhaaren Jun 28, 2018
c9ee7e4
mappa: fix layer count lookup from config file
harryhaaren Jun 28, 2018
a493996
mappa: lut flattening implemented
harryhaaren Jun 28, 2018
6c01844
mappa: layer active switching using names working
harryhaaren Jun 28, 2018
ce2dca1
mappa: add demo config file to the repo
harryhaaren Jun 28, 2018
345da4d
mappa: cleanup layer_active function
harryhaaren Jun 28, 2018
4ff33f8
mappa: implement value scaling and set_range() api
harryhaaren Jun 30, 2018
734a5ed
mappa: rework how config files are used by app
harryhaaren Jul 1, 2018
7667c0c
mappa: improve error reporting of file load issues
harryhaaren Jul 7, 2018
9c16573
examples/daemon: update to new API
harryhaaren Jul 14, 2018
e3d425b
mappa: fix a bunch of code-sanity things
harryhaaren Jul 15, 2018
1752048
mappa: some more code fixups
harryhaaren Jul 15, 2018
0ddb49e
Merge branch 'master' into map_v1_merge
harryhaaren Jul 15, 2018
a0bfb22
mappa: code cleanup - fix MAPPA_ERROR check
harryhaaren Jul 15, 2018
9b95e6e
mappa: final code cleanup fixes
harryhaaren Jul 15, 2018
8560df6
mappa: adding of config directories working
harryhaaren Jul 19, 2018
9c42fa7
ctlra/mappa: add tinydir header file for xplatform file iteration
harryhaaren Jul 19, 2018
76560da
mappa: add config file iteration using tinydir
harryhaaren Jul 19, 2018
0b58e22
mappa: config file prep, callbacks in foreach
harryhaaren Jul 19, 2018
a92fb6a
mappa: refactor config file open and device scan
harryhaaren Jul 19, 2018
b71e8a7
mappa: improve error checks for device existence
harryhaaren Jul 19, 2018
6f2811b
mappa: config file loading using tailq / tinydir working
harryhaaren Jul 19, 2018
0f46cef
mappa: defer attempted loading of configs until after probe()
harryhaaren Jul 19, 2018
2781ff7
mappa: dev conf path stored in dev
harryhaaren Jul 19, 2018
423677a
mappa: target list has revision (towards hotplug)
harryhaaren Jul 19, 2018
8b6663f
mappa: reworking printfs() and debug warnings
harryhaaren Jul 19, 2018
c1729dd
mappa: rework [hardware]serial warning reporting
harryhaaren Jul 19, 2018
ee546ef
mappa: relax check for layer error print
harryhaaren Jul 19, 2018
8f9b961
mappa: prep for large refactor of binding create
harryhaaren Jul 19, 2018
d3c2a07
mappa: Remove add_config_file() API
harryhaaren Jul 19, 2018
1d9e024
mappa: apply config file loading improved, wip
harryhaaren Jul 24, 2018
3d0002e
midi: re-enable midi backend
harryhaaren Jul 27, 2018
10a3c54
mappa: load name of software from .ini file
harryhaaren Jul 27, 2018
602ee2e
mappa: refactor create() API to include app name
harryhaaren Jul 27, 2018
fae2534
mappa: create() stores app name
harryhaaren Jul 27, 2018
5062deb
mappa: check software name vs app when loading
harryhaaren Jul 27, 2018
2096c1a
examples/mappa: remove .ini file
harryhaaren Jul 29, 2018
3b9501c
mappa: fix mem leaks detected by valgrind
harryhaaren Jul 29, 2018
b136a74
mappa: wip on testing hotplug functionality
harryhaaren Sep 14, 2018
aae8d4b
mappa: config loading in accept() instead of main()
harryhaaren Sep 29, 2018
f3f0b5d
mappa: delay .ini scan til after dev_create()
harryhaaren Oct 1, 2018
7faae38
mappa: enable reload as mappa target
harryhaaren Oct 28, 2018
2183501
mappa: enable screen redraw func
harryhaaren Oct 28, 2018
3024499
usb: extend timeout duration
harryhaaren Oct 28, 2018
a5bbbb5
mappa: working on source_t feedback to ctlra
harryhaaren Oct 29, 2018
36f3273
mappa: lookups for feedback ids working
harryhaaren Oct 29, 2018
de2a677
mappa: wip on making ctlra fb id more flexible
harryhaaren Oct 29, 2018
76a96d0
mappa: feedback mappings to lights working
harryhaaren Nov 3, 2018
47bfa5d
mappa: sources use token, cleanup/improve impl
harryhaaren Nov 3, 2018
e0a8a45
examples/mappa: update to more complex tests
harryhaaren Nov 3, 2018
3cb6923
mappa: zero lights if no source mapped
harryhaaren Nov 3, 2018
d119afd
mappa: cleanup and comment prints
harryhaaren Nov 3, 2018
91f7c3f
mappa: add avtka functionality to draw screens
harryhaaren Nov 3, 2018
adb08e9
mappa: value on AVTKA UI updates from source
harryhaaren Nov 3, 2018
e2ab18e
mappa: rework screens to be part of LUTs
harryhaaren Nov 3, 2018
71c1c1f
Fix some glitches in the Maschine Mk3 backend.
agraef Sep 7, 2018
79bc0e6
Increase buffer sizes in MIDI input, so that we can properly receive …
agraef Sep 7, 2018
45f8db7
Disable running status on the message decoder.
agraef Sep 7, 2018
543f697
Some more fixes to the MIDI code.
agraef Sep 7, 2018
1566b30
Make sure that we decode the message before the call to snd_seq_event…
agraef Sep 8, 2018
8f4e5fd
Bugfix: buttons encoded at byte offset 3 would also trigger the pedal…
agraef Sep 9, 2018
c3c3ffd
Put the top 8 button in its rightful position after top 7, instead of…
agraef Sep 9, 2018
cba118b
Reverse the encoder touches, so that they are in ascending order.
agraef Sep 9, 2018
a8980f3
Secs are 1e9 ns, not 10e9. Typo?
agraef Sep 21, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ctlra/ctlra.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ void ctlra_idle_iter(struct ctlra_t *ctlra)

time_t secs = now.tv_sec - dev_iter->screen_last_redraw.tv_sec;
long nanos = now.tv_nsec - dev_iter->screen_last_redraw.tv_nsec;
uint64_t nanos_elapsed = secs * 10e9 + nanos;
uint64_t nanos_elapsed = secs * 1e9 + nanos;
uint64_t fps_in_nanos = 100000000;

if(dev_iter->screen_redraw_cb && fps_in_nanos < nanos_elapsed) {
Expand Down
2 changes: 0 additions & 2 deletions ctlra/devices/avtka.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ event_cb(struct avtka_t *avtka, uint32_t item, float value, void *userdata)
uint32_t id = dev->id_to_ctlra[item].id;
uint32_t col = dev->id_to_ctlra[item].col;

printf("%s : event\n", __func__);

/* default type is button */
struct ctlra_event_t event = {
.type = type,
Expand Down
2 changes: 1 addition & 1 deletion ctlra/devices/midi_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,4 @@ struct ctlra_dev_info_t ctlra_midi_generic_info = {
.get_name = midi_generic_control_get_name,
};

//CTLRA_DEVICE_REGISTER(midi_generic)
CTLRA_DEVICE_REGISTER(midi_generic)
131 changes: 82 additions & 49 deletions ctlra/devices/ni_maschine_mk3.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ static const char *ni_maschine_mk3_control_names[] = {
"Enc. Left",
"Enc. Down",
"Shift",
"Top 8",
"A",
"B",
"C",
Expand Down Expand Up @@ -126,15 +125,16 @@ static const char *ni_maschine_mk3_control_names[] = {
"Top 5",
"Top 6",
"Top 7",
"Top 8",
"Enc. Touch",
"Enc. Touch 8",
"Enc. Touch 7",
"Enc. Touch 6",
"Enc. Touch 5",
"Enc. Touch 4",
"Enc. Touch 3",
"Enc. Touch 2",
"Enc. Touch 1",
"Enc. Touch 2",
"Enc. Touch 3",
"Enc. Touch 4",
"Enc. Touch 5",
"Enc. Touch 6",
"Enc. Touch 7",
"Enc. Touch 8",
};
#define CONTROL_NAMES_SIZE (sizeof(ni_maschine_mk3_control_names) /\
sizeof(ni_maschine_mk3_control_names[0]))
Expand All @@ -146,9 +146,8 @@ static const struct ni_maschine_mk3_ctlra_t buttons[] = {
{1, 1, 0x04},
{1, 1, 0x20},
{1, 1, 0x10},
/* shift, top right above screen */
/* shift */
{1, 1, 0x40},
{1, 1, 0x80},
/* group buttons ABCDEFGH */
{1, 2, 0x01},
{1, 2, 0x02},
Expand Down Expand Up @@ -218,32 +217,35 @@ static const struct ni_maschine_mk3_ctlra_t buttons[] = {
{1, 9, 0x10},
{1, 9, 0x20},
{1, 9, 0x40},
// AG: note that "Top 8" is actually stored in the first byte, NI
// probably crammed it in there to save an extra byte
{1, 1, 0x80},
/* Encoder Touch */
{1, 9, 0x80},
/* Dial touch 8 - 1 */
{1, 10, 0x01},
{1, 10, 0x02},
{1, 10, 0x04},
{1, 10, 0x08},
{1, 10, 0x10},
{1, 10, 0x20},
{1, 10, 0x40},
/* Dial touch 1 - 8 (reverse order in data) */
{1, 10, 0x80},
{1, 10, 0x40},
{1, 10, 0x20},
{1, 10, 0x10},
{1, 10, 0x08},
{1, 10, 0x04},
{1, 10, 0x02},
{1, 10, 0x01},
};
#define BUTTONS_SIZE (sizeof(buttons) / sizeof(buttons[0]))

#define MK3_BTN (CTLRA_ITEM_BUTTON | CTLRA_ITEM_LED_INTENSITY | CTLRA_ITEM_HAS_FB_ID)
#define MK3_BTN_NOFB (CTLRA_ITEM_BUTTON | CTLRA_ITEM_LED_INTENSITY)
static struct ctlra_item_info_t buttons_info[] = {
/* TODO: represent encoders better in the UI */
/* encoder press, right up left down */
{.x = 21, .y = 138, .w = 18, .h = 10, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 0},
{.x = 21, .y = 138, .w = 18, .h = 10, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 0},
{.x = 21, .y = 138, .w = 18, .h = 10, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 0},
{.x = 21, .y = 138, .w = 18, .h = 10, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 0},
{.x = 21, .y = 138, .w = 18, .h = 10, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 0},
/* shift, top-right above screen (mad ordering..) */
{.x = 21, .y = 138, .w = 18, .h = 10, .flags = MK3_BTN_NOFB, .colour = 0xff000000, .fb_id = 0},
{.x = 21, .y = 138, .w = 18, .h = 10, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 60},
{.x = 21, .y = 138, .w = 18, .h = 10, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 58},
{.x = 21, .y = 138, .w = 18, .h = 10, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 59},
{.x = 21, .y = 138, .w = 18, .h = 10, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 61},
/* shift */
{.x = 94, .y = 268, .w = 24, .h = 14, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 44},
{.x = 278, .y = 10, .w = 24, .h = 8, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 19},
/* group ABCDEFGH */
{.x = 9, .y = 210, .w = 24, .h = 14, .flags = MK3_BTN, .colour = 0xffffffff, .fb_id = 29},
{.x = 37, .y = 210, .w = 24, .h = 14, .flags = MK3_BTN, .colour = 0xffffffff, .fb_id = 30},
Expand Down Expand Up @@ -278,7 +280,7 @@ static struct ctlra_item_info_t buttons_info[] = {
{.x = 137, .y = 248, .w = 24, .h = 14, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 56},
{.x = 137, .y = 266, .w = 24, .h = 14, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 57},
/* Pitch, Mod, Perform */
{.x = 9, .y = 170, .w = 24, .h = 8, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 0},
{.x = 9, .y = 170, .w = 24, .h = 8, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 25},
{.x = 37, .y = 170, .w = 24, .h = 8, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 26},
{.x = 65, .y = 170, .w = 24, .h = 8, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 27},
/* restart, erase, tap, follow */
Expand All @@ -304,26 +306,27 @@ static struct ctlra_item_info_t buttons_info[] = {
{.x = 9, .y = 62, .w = 24, .h = 8, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 6},
{.x = 9, .y = 74, .w = 24, .h = 8, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 8},
{.x = 9, .y = 86, .w = 24, .h = 8, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 10},
/* Top buttons (7, 8 already above) */
/* Top buttons */
{.x = 82, .y = 10, .w = 24, .h = 8, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 12},
{.x = 110, .y = 10, .w = 24, .h = 8, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 13},
{.x = 138, .y = 10, .w = 24, .h = 8, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 14},
{.x = 166, .y = 10, .w = 24, .h = 8, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 15},
{.x = 194, .y = 10, .w = 24, .h = 8, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 16},
{.x = 222, .y = 10, .w = 24, .h = 8, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 17},
{.x = 250, .y = 10, .w = 24, .h = 8, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 18},
{.x = 278, .y = 10, .w = 24, .h = 8, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 19},
{.x = 278, .y = 10, .w = 24, .h = 8, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 19},
/* TODO: show encoder dial touch control */
/* big dial encoder touch */
{.x = 1, .y = 1, .w = 1, .h = 1, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 0},
{.x = 1, .y = 1, .w = 1, .h = 1, .flags = MK3_BTN_NOFB, .colour = 0xff000000, .fb_id = 0},
/* 1-8 dial encoder touch */
{.x = 1, .y = 1, .w = 1, .h = 1, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 0},
{.x = 1, .y = 1, .w = 1, .h = 1, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 0},
{.x = 1, .y = 1, .w = 1, .h = 1, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 0},
{.x = 1, .y = 1, .w = 1, .h = 1, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 0},
{.x = 1, .y = 1, .w = 1, .h = 1, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 0},
{.x = 1, .y = 1, .w = 1, .h = 1, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 0},
{.x = 1, .y = 1, .w = 1, .h = 1, .flags = MK3_BTN, .colour = 0xff000000, .fb_id = 0},
{.x = 1, .y = 1, .w = 1, .h = 1, .flags = MK3_BTN_NOFB, .colour = 0xff000000, .fb_id = 0},
{.x = 1, .y = 1, .w = 1, .h = 1, .flags = MK3_BTN_NOFB, .colour = 0xff000000, .fb_id = 0},
{.x = 1, .y = 1, .w = 1, .h = 1, .flags = MK3_BTN_NOFB, .colour = 0xff000000, .fb_id = 0},
{.x = 1, .y = 1, .w = 1, .h = 1, .flags = MK3_BTN_NOFB, .colour = 0xff000000, .fb_id = 0},
{.x = 1, .y = 1, .w = 1, .h = 1, .flags = MK3_BTN_NOFB, .colour = 0xff000000, .fb_id = 0},
{.x = 1, .y = 1, .w = 1, .h = 1, .flags = MK3_BTN_NOFB, .colour = 0xff000000, .fb_id = 0},
{.x = 1, .y = 1, .w = 1, .h = 1, .flags = MK3_BTN_NOFB, .colour = 0xff000000, .fb_id = 0},
{.x = 1, .y = 1, .w = 1, .h = 1, .flags = MK3_BTN_NOFB, .colour = 0xff000000, .fb_id = 0},
};

static struct ctlra_item_info_t sliders_info[] = {
Expand Down Expand Up @@ -424,7 +427,10 @@ struct ni_maschine_mk3_t {
/* base handles usb i/o etc */
struct ctlra_dev_t base;
/* current value of each controller is stored here */
float hw_values[CONTROLS_SIZE];
// AG: These appear to spit out some random values initially, which we
// just record on the first run without passing them on. Same applies
// to the big encoder and the touchstrip below.
float hw_values[CONTROLS_SIZE], hw_init[CONTROLS_SIZE];
/* current state of the lights, only flush on dirty */
uint8_t lights_dirty;
uint8_t lights_pads_dirty;
Expand All @@ -440,8 +446,8 @@ struct ni_maschine_mk3_t {
/* state of the pedal, according to the hardware */
uint8_t pedal;

uint8_t encoder_value;
uint16_t touchstrip_value;
uint8_t encoder_value, encoder_init;
uint16_t touchstrip_value, touchstrip_init;
/* Pressure filtering for note-onset detection */
uint64_t pad_last_msg_time;
uint16_t pad_hit;
Expand All @@ -462,6 +468,15 @@ ni_maschine_mk3_control_get_name(enum ctlra_event_type_t type,
return encoder_names[control_id];
if(type == CTLRA_EVENT_SLIDER && control_id == 0)
return "Touchstrip";
if(type == CTLRA_EVENT_GRID && control_id == 0)
return "Pad Grid";
if(type == CTLRA_FEEDBACK_ITEM) {
if(control_id == 0)
return "Left Screen";
else
return "Right Screen";
}

return 0;
}

Expand Down Expand Up @@ -540,9 +555,7 @@ ni_maschine_mk3_pads_decode_set(struct ni_maschine_mk3_t *dev,
if(current == new)
continue;

/* rotate grid to match order on device (but zero
* based counting instead of 1 based). */
event.grid.pos = (3-(i/4))*4 + (i%4);
event.grid.pos = i;
int press = new > 0;
event.grid.pressed = press;
event.grid.pressure = pad_pressures[i] * (1 / 4096.f) * press;
Expand Down Expand Up @@ -624,9 +637,12 @@ ni_maschine_mk3_usb_read_cb(struct ctlra_dev_t *base,
break;
case 42: {
/* pedal */
int pedal = buf[3] > 0;
// AG: 0x40 = bit mask for pedal; we *must* test for this
// specific value, since other bits of this byte may also be
// set by some of the buttons (see below)
int pedal = buf[3] & 0x40;
if(pedal != dev->pedal) {
printf("PEDAL: %d, inv = %d\n", pedal, !pedal);
//printf("PEDAL: %d, inv = %d\n", pedal, !pedal);
struct ctlra_event_t event[] = {
{ .type = CTLRA_EVENT_BUTTON,
.button = {
Expand All @@ -650,7 +666,10 @@ ni_maschine_mk3_usb_read_cb(struct ctlra_dev_t *base,

/* touchstrip: dont send event if 0, as this is release */
uint16_t v = *((uint16_t *)&buf[30]);
if(v && v != dev->touchstrip_value) {
if(!dev->touchstrip_init) {
dev->touchstrip_value = v;
dev->touchstrip_init = 1;
} else if(v && v != dev->touchstrip_value) {
struct ctlra_event_t event = {
.type = CTLRA_EVENT_SLIDER,
.slider = {
Expand All @@ -670,7 +689,16 @@ ni_maschine_mk3_usb_read_cb(struct ctlra_dev_t *base,
int offset = buttons[i].buf_byte_offset;
int mask = buttons[i].mask;

#if 0
// AG XXXFIXME: Why should we read a 16 bit value here, only to mask out the
// MSB immediately? (Note that all the button masks are single-byte.) Also,
// the byte offsets for the various buttons are consecutive, so we'd actually
// be reading overlapping values here. This just doesn't make any sense to me.
uint16_t v = *((uint16_t *)&buf[offset]) & mask;
#else
// This should work just as well.
uint16_t v = buf[offset] & mask;
#endif
int value_idx = i;

if(dev->hw_values[value_idx] != v) {
Expand All @@ -695,7 +723,10 @@ ni_maschine_mk3_usb_read_cb(struct ctlra_dev_t *base,
const float value = v / 1000.f;
const uint8_t idx = BUTTONS_SIZE + i;

if(dev->hw_values[idx] != value) {
if(!dev->hw_init[idx]) {
dev->hw_values[idx] = value;
dev->hw_init[idx] = 1;
} else if(dev->hw_values[idx] != value) {
const float d = (value - dev->hw_values[idx]);
if(fabsf(d) > 0.7) {
/* wrap around */
Expand Down Expand Up @@ -729,7 +760,10 @@ ni_maschine_mk3_usb_read_cb(struct ctlra_dev_t *base,
};
struct ctlra_event_t *e = {&event};
int8_t enc = buf[11] & 0x0f;
if(enc != dev->encoder_value) {
if(!dev->encoder_init) {
dev->encoder_value = enc;
dev->encoder_init = 1;
} else if(enc != dev->encoder_value) {
int dir = ctlra_dev_encoder_wrap_16(enc, dev->encoder_value);
event.encoder.delta = dir;
dev->encoder_value = enc;
Expand All @@ -751,8 +785,7 @@ static void ni_maschine_mk3_light_set(struct ctlra_dev_t *base,
if(!dev)
return;

// TODO: debug the -1, why is it required to get the right size?
if(light_id > (LIGHTS_SIZE + 25 + 16) - 1)
if(light_id >= (LIGHTS_SIZE + 25 + 16))
return;

int idx = light_id;
Expand Down
9 changes: 9 additions & 0 deletions ctlra/event.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
#include <stdint.h>
#include "event.h"
#include "impl.h"

const char *ctlra_event_type_names[] = {
"Button",
"Encoder",
"Slider",
"Grid",
"Feedback",
};
#define NAMES_SIZE (sizeof(ctlra_event_type_names) / \
sizeof(ctlra_event_type_names[0]))

void event_checks(void)
{
BUILD_BUG_ON(NAMES_SIZE != CTLRA_EVENT_T_COUNT);
}
10 changes: 8 additions & 2 deletions ctlra/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ extern "C" {
#include "ctlra.h"
#include "event.h"


#define debug_print_check(c, level) \
(!c || ((c->opts.debug_level & CTLRA_DEBUG_LEVEL_MASK) > level))

Expand Down Expand Up @@ -302,10 +303,15 @@ static const struct ctlra_dev_connect_func_t __ctlra_dev = { \
__attribute__((constructor(102))) \
static void ctlra_ ## name ## _register() { \
__ctlra_devices[__ctlra_device_count++] = __ctlra_dev; \
if(1) \
printf("[ctlra] register %s %s\n", __ctlra_dev.info->vendor, \
__ctlra_dev.info->device); \
}



/* helper macro to compile-time debug struct sizes, and function to
* actually perform those checks in the correct .c file */
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
void event_checks(void);

/* Helper function for dealing with wrapped encoders */
static inline int8_t ctlra_dev_encoder_wrap_16(uint8_t newer, uint8_t older)
Expand Down
Loading