Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 1 file changed
  • 0 comments
  • 2 contributors
Nov 05, 2011
Werner Almesberger midi.c: "learn" mode for controllers
While a miniN tag is being clicked (click button 1 and hold down),
any incoming controller message will map that MIDI variable to the
respective controller. This simplified MIDI configuration.

Controls appearing as multiple controllers may need special
precautions. E.g., an X/Y pad may have three controllers: X, Y, and
touch/release. X and Y can be distinguished by moving the finger
and simply stopping when the right value has been taken. To prevent
release from overriding an X/Y controller, release the mouse button
before releasing the pad.

Some scenarios may be beyond the capabilities of this simple
mechanism and require manual setup.
a77d1c9
Sébastien Bourdeauducq midi.c: use mtk_bindf + style corrections fedfe72

Showing 1 changed file with 17 additions and 0 deletions. Show diff stats Hide diff stats

  1. 17  src/midi.c
17  src/midi.c
@@ -23,6 +23,7 @@
23 23
 #include <string.h>
24 24
 #include <dirent.h>
25 25
 #include <unistd.h>
  26
+#include <assert.h>
26 27
 #include <mtklib.h>
27 28
 
28 29
 #include "util.h"
@@ -158,6 +159,7 @@ static int midistr(const char *str)
158 159
 
159 160
 static int appid;
160 161
 static struct filedialog *browse_dlg;
  162
+static int learn = -1;
161 163
 
162 164
 static int w_open;
163 165
 
@@ -269,6 +271,8 @@ static void note_event(int code)
269 271
 static void controller_event(int controller, int value)
270 272
 {
271 273
 	mtk_cmdf(appid, "l_lastctl.set(-text \"%d (%d)\")", controller, value);
  274
+	if(learn != -1)
  275
+		mtk_cmdf(appid, "e_midi%d.set(-text \"%d\")", learn, controller);
272 276
 }
273 277
 
274 278
 static void midi_event(mtk_event *e, int count)
@@ -347,6 +351,17 @@ static void addupdate_callback(mtk_event *e, void *arg)
347 351
 	mtk_cmd(appid, "e_filename.set(-text \"\")");
348 352
 }
349 353
 
  354
+static void press_callback(mtk_event *e, void *arg)
  355
+{
  356
+	learn = (int)arg;
  357
+	assert(learn >= 0 && learn < MIDI_COUNT);
  358
+}
  359
+
  360
+static void release_callback(mtk_event *e, void *arg)
  361
+{
  362
+	learn = -1;
  363
+}
  364
+
350 365
 static int cmpstringp(const void *p1, const void *p2)
351 366
 {
352 367
 	return strcmp(*(char * const *)p1, *(char * const *)p2);
@@ -537,6 +552,8 @@ void init_midi()
537 552
 		mtk_cmdf(appid, "e_midi%d = new Entry()", i);
538 553
 		mtk_cmdf(appid, "g_vars.place(l_midi%d, -column 1 -row %d)", i, i);
539 554
 		mtk_cmdf(appid, "g_vars.place(e_midi%d, -column 2 -row %d)", i, i);
  555
+		mtk_bindf(appid, "l_midi%d", "press", press_callback, (void *)i, i);
  556
+		mtk_bindf(appid, "l_midi%d", "release", release_callback, NULL, i);
540 557
 	}
541 558
 
542 559
 	mtk_bind(appid, "lst_existing", "selchange", selchange_callback, NULL);

No commit comments for this range

Something went wrong with that request. Please try again.