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

Open
wants to merge 96 commits into
base: master
from

Conversation

4 participants
@harryhaaren
Contributor

harryhaaren commented Jun 17, 2018

A staging PR, to discuss the mapping strategy between Ctlra and any host. The "mappa" infrastructure is used to provide complex multi-layered mappings between the generic Ctlra events and the software-application.

A "target" is a value in the application that can be updated/changed by Ctlra.
A "source" is a value in the application that can be read by Ctlra for feedback to hardware devices.

The APIs are currently prototype and POC only, these will change, please don't expect API stability at this point.

harryhaaren added some commits Jun 11, 2018

mappa: initial commit of v1 input mapping API
This commit adds a sample application that implements an
initial draft of the mappa API. In particular the abstraction
between the application and the mappa software is being kept
as simple as possible - even still it will probably change
a few times - so do not start using this API just yet!

This commit closes #80 initial mapping design.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: adding lists for targets and implementation
Testing with valgrind to fix leaks + access issues, #81

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: add removal of target impl and test
See details in #81

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: adding multiple targets to linked list
This enables the app to add and remove multiple targets.
Internally they're stored for book-keeping, but not
event-lookup is implemented yet. See #81

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: implemented event lut, and event handling
This commit is a significant step towards POC of using Ctlra
look-up-table for event mapping. The software target events
are stored in a linear array sorted by type, so the lookup of
the target is just an array access. The function pointer is
called if one is set.

This almost completes #81.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: refactor lut and error check
Error check to avoid segfault on NULL m or lut,
refactor to make it easier to store a list of lut's

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: insert concept of dev_t for devices
this allows multiple lut layers to be present in a single
device. It also gives a good abstraction for using the
userdata pointer for the ctlra dev callbacks, and a place
to store state like current-layer for a device.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: reworking dev, few valgrind gotchas to fix
Segfaulting due to incorrect linked-lists / target setup

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: refactoring event handling / lookup
Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: fix handling of null ptr
Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: enable other control types
Enable other types of ctlra inputs than slider, exposing it to
the external API. Need to think about if this is the right solution
to the interface for mapping

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: give luts an index for switching
This allows the lut switch to target a specific
integer lut for each device.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: poc layer switching is working
This commit enables layer switching by using an internal
mappa callback function that takes a dev_t *. This allows
the mappa instance to changes its active_lut, which causes
different actions to be triggered by each input event.

This closes #81.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: test layer 2 binding too
This tests the cross-fader being bound to something else
on layer 2 - to ensure that the functionality gets transposed
correctly.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: error check items based on control counts
This commit checks the ids of controls being bound,
failing with -EINVAL if the target is out of bounds
for the hardware device being mapped.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: refactor error handling, no more crashy
This commit strenghtens the error checking on events as compared
to the events that are advertised by the device's metadata. If
the event id is beyond the advertised range, it is ignored and
a print issued to notify - this is due to invalid event/metadata
pairing in the device code.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: initial feedback prototype
This commit is the first version of the feedback prototype.
It uses the token concept, along with a unique name per source
of feedback.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: refactoring feedback sources
Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: feedback wip, almost there, some pointer issue
Mostly working - need to dig into last few pointer issues

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: fixed led feedback, 2 src functions in app
This commit fixes the array issues mentioned in the previous
commit, and adds a new source callback function in the app.
The value returned by the two functions is now different, and
a simple "musher" allows mapping a float value to 0-6 lights.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: cleanup prints, error checks, mini refactor
General cleanup of prints and noisy code, added error check
for dev if there's no device available.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: refactor main, cleanup sources
This commit refactors main to have a seperate function for
binding - this needs to be abstracted out of the app and into
the mappa library at some point.

Some valgrind mem leaks on close fixed by cleaning up sources.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: add tailq of devices
This commit adds the tailq infrastructure to support multiple
devices. This allows more than one ctlra instance to be mapped.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: fix error return in bind source
The missing return was causing invalid reads in valgrind.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: cleanup now has zero valgrind warnings
This commit adds a bunch of destroy() functions, which
free the linked-lists of targets, lut, devices etc.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: initial token based target approach
This approach uses a "token" that the application can
give to each callback - think function parameters. This
is in addition to the function pointer itself.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: token targets, large refactor, broken/wip
Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: add error checks, fix function prototype
Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: refactor targets to contain pointers
This enables the token style variable size method.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: refactor cloning / adding of targets
Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>

harryhaaren and others added some commits Jun 27, 2018

mappa: error check inputs for load_bindings better
Previously if there was no virtual or physical device attached
a segfault would occur as dev_t* was never checked.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: add name to lut_create() function
This ensures that a name is passed in when creating a lut

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: fix bug in strcmp() == 0 vs != 0
This was freeing the lut_t * even though we didn't want it to,
which would later lead to segfaults / use-after-free.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: mapping_count error check value added
The "mapping_count" item in a layer allows the human to indicate
the number of mappings that are created for this layer. This allows
mappa to check that exactly that number of mappings are made. If
fewer are made, warning/error prints are emitted to inform the
user that something has gone wrong.

WIP on active-on-load, which should enable activating layers once
the file is loaded.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: initial overlay list implementation
This commit adds the concept of the active_lut_list, which contains
the currently active layers in the order that they should be handled.
The entries in this lut_list must be itereated and flattended into the
dev->active_lut in order for them to be used for event input lookup.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: fix layer count lookup from config file
This commit uses the [mapping] layer_count field to get
the number of layers defined in the mapping, which is then
iterated to in the mapping lookups.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: lut flattening implemented
This commit implements lut_t flattening based on the order that
the layers are read from the config file. If a layer is active,
it is appended to the active_lut_list, which later gets flattened
into the active_lut.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: layer active switching using names working
This is a WIP commit but does prove the concept of the layer
active switching working with the sample .ini file.

This shows that the mapping can be achieved using the overlay
techinque, and that the button mapping to the layer-switch target
allows the user to program all aspects of multilayered mappings
using just the .ini config file, and some knowledge of the
controller and software in question.

Note that with virtual devices, a software developer can easily
assist the user with any issues that arise - actually the development
of this commit (and most of the previous mappa related ones) was
done entirely using virtual devices, away from the hardware. With
the hardware present, the cross-over was seamless to have working
input mappings with those devices.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: add demo config file to the repo
This commit adds the demo config file to use with the mappa
branch, so others can test mappings easier. It is possible
create a virtual device in order test this mapping if you
don't have access to the Z1 hardware:

$ export CTLRA_VIRTUAL_VENDOR="Native Instruments"
$ export CTLRA_VIRTUAL_DEVICE="Kontrol Z1"

Now run ./examples/ctlra_mappa, and the middle "mode" button
will remap the "A" headphones que button (top left button)
between two different targets - NO application logic in
multiplexing, and NO user-programming - just a config file.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: cleanup layer_active function
Remove some prints and add a TODO note on how to enable different
types of button actuation types in future.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: implement value scaling and set_range() api
This commit implements value scaling inside Mappa. The end
result is that an application can set a range for each target,
which Mappa then automatically range-scales and offsets any
float value mapped to it.

The end result is "transparent" range-scaling for users, where
a full movement of the hardware translates to full movement of
the software parameter (aka; basic expected experience).

However the value of having the target range exposed here is that
mappa can in future support "ranges" for each control, which can
be user defined, and the range numbers are not 0-1 based, but actual
real units (eg, remap lowpass filter min value from 0Hz to 110Hz, so
the sound is never 100% cut out).

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: rework how config files are used by app
This commit refactors the previous "load_bindings()" function,
replacing it with the more generic add_config_file(). This allows
the application to indicate config files that are present, and
gives mappa freedom to scan/load them as appropriate on hotplug
of devices.

All in all, this reduces complexity in the application (eg: no
need to implement a callback to get the correct mappa config for
a specific devices). It also allows future mappa to timestamp
loads of files, and auto-reload files etc.

Note that this commit breaks API/ABI of load_bindings()

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: improve error reporting of file load issues
Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
examples/daemon: update to new API
Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: fix a bunch of code-sanity things
Some %d %u mixups, some variable scope reductions.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: some more code fixups
Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: code cleanup - fix MAPPA_ERROR check
This commit removes the mappa_check() function call
from the MAPPA_ERROR macro, as it *should* always print.
Code-checkers were throwing up all sorts of errors saying
that the limited data type comparison was invalid.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
mappa: final code cleanup fixes
Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
Some more fixes to the MIDI code.
Improved error checking on the input side. Also make sure that the registered *decoder* is used for decoding received MIDI messages, rather than the *encoder* which is already used in MIDI output, which might cause races when both MIDI input and output happens simultaneously.
Bugfix: buttons encoded at byte offset 3 would also trigger the pedal…
…. Also simplify the horribly convoluted masking of button values.
Put the top 8 button in its rightful position after top 7, instead of…
… following the mad layout in the actual data from the device.
Merge pull request #95 from agraef/bugfixes-ag
Mk3 and MIDI Fixes, thanks @agraef!
Merge pull request #96 from agraef/mapping_v1-examples-buildargs
Add install and c_args variables for examples, thanks @agraef!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment