From 871bc1568f94ee4026fd64df062572b91d45d462 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sat, 4 Jan 2020 18:39:04 +0100 Subject: Add input_channel call to Lua backend --- backends/lua.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'backends/lua.md') diff --git a/backends/lua.md b/backends/lua.md index f38e189..650fdb9 100644 --- a/backends/lua.md +++ b/backends/lua.md @@ -16,7 +16,7 @@ The following functions are provided within the Lua interpreter for interaction | `interval(function, number)` | `interval(update, 100)` | Register a function to be called periodically. Intervals are milliseconds (rounded to the nearest 10 ms) | | `input_value(string)` | `input_value("foo")` | Get the last input value on a channel | | `output_value(string)` | `output_value("bar")` | Get the last output value on a channel | - +| `input_channel()` | `print(input_channel())` | Returns the name of the input channel whose handler function is currently running or `nil` if in an `interval`'ed function (or the initial parse step) | Example script: ``` @@ -58,8 +58,8 @@ lua1.foo > lua2.bar #### Known bugs / problems -Using any of the interface functions (`output`, `interval`, `input_value`, `output_value`) as an -input channel name to a Lua instance will not call any handler functions. +Using any of the interface functions (`output`, `interval`, `input_value`, `output_value`, `input_channel`) +as an input channel name to a Lua instance will not call any handler functions. Using these names as arguments to the output and value interface functions works as intended. Output values will not trigger corresponding input event handlers unless the channel is mapped -- cgit v1.2.3 From 8ebc4311185e3329622ad883dde54409fa1c8350 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sun, 9 Feb 2020 11:50:41 +0100 Subject: Mention release page in installer section, move images around --- backends/lua.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/lua.md') diff --git a/backends/lua.md b/backends/lua.md index 650fdb9..d01a8c6 100644 --- a/backends/lua.md +++ b/backends/lua.md @@ -3,7 +3,7 @@ The `lua` backend provides a flexible programming environment, allowing users to route and manipulate events using the Lua programming language. -Every instance has it's own interpreter state which can be loaded with custom handler scripts. +Every instance has its own interpreter state which can be loaded with custom handler scripts. To process incoming channel events, the MIDIMonster calls corresponding Lua functions (if they exist) with the value (as a Lua `number` type) as parameter. -- cgit v1.2.3 From f49c46c184ecdd5209f1fd9df47daed0acfae728 Mon Sep 17 00:00:00 2001 From: cbdev Date: Fri, 28 Feb 2020 18:53:45 +0100 Subject: Update README to reflect all backends, add notes for building Lua on Windows --- backends/lua.md | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'backends/lua.md') diff --git a/backends/lua.md b/backends/lua.md index d01a8c6..b936a99 100644 --- a/backends/lua.md +++ b/backends/lua.md @@ -64,3 +64,13 @@ Using these names as arguments to the output and value interface functions works Output values will not trigger corresponding input event handlers unless the channel is mapped back in the MIDIMonster configuration. + +To build (and run) the `lua` backend on Windows, a compiled version of the Lua library is required. +For various reasons (legal, separations of concern, not wanting to ship binary data in the repository), +you will need to acquire a copy of `lua53.dll` (for example by downloading it from the [luabinaries +project](http://luabinaries.sourceforge.net/download.html). + +To build the `lua` backend for Windows, place `lua53.dll` in a subdirectory `libs/` in the project root +and run `make lua.dll` inside the `backends/` directory. + +At runtime, Windows searches for the file in the same directory as `midimonster.exe`. -- cgit v1.2.3 From d574abf032da350f1208d9480d24c51187bc7c63 Mon Sep 17 00:00:00 2001 From: cbdev Date: Fri, 28 Feb 2020 19:00:58 +0100 Subject: Minor documentation fix --- backends/lua.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'backends/lua.md') diff --git a/backends/lua.md b/backends/lua.md index b936a99..d2552e0 100644 --- a/backends/lua.md +++ b/backends/lua.md @@ -65,9 +65,10 @@ Using these names as arguments to the output and value interface functions works Output values will not trigger corresponding input event handlers unless the channel is mapped back in the MIDIMonster configuration. -To build (and run) the `lua` backend on Windows, a compiled version of the Lua library is required. +To build (and run) the `lua` backend on Windows, a compiled version of the Lua 5.3 library is required. For various reasons (legal, separations of concern, not wanting to ship binary data in the repository), -you will need to acquire a copy of `lua53.dll` (for example by downloading it from the [luabinaries +the MIDIMonster project can not provide this file within this repository. +You will need to acquire a copy of `lua53.dll`, for example by downloading it from the [luabinaries project](http://luabinaries.sourceforge.net/download.html). To build the `lua` backend for Windows, place `lua53.dll` in a subdirectory `libs/` in the project root -- cgit v1.2.3 From 1618f49ff5dc317968e385e5cbc4aae32e8fb67b Mon Sep 17 00:00:00 2001 From: cbdev Date: Sun, 1 Mar 2020 15:02:33 +0100 Subject: Fix some errors in the Lua documentation --- backends/lua.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'backends/lua.md') diff --git a/backends/lua.md b/backends/lua.md index d2552e0..ce82a4d 100644 --- a/backends/lua.md +++ b/backends/lua.md @@ -1,7 +1,7 @@ ### The `lua` backend -The `lua` backend provides a flexible programming environment, allowing users to route and manipulate -events using the Lua programming language. +The `lua` backend provides a flexible programming environment, allowing users to route, generate +and manipulate events using the Lua scripting language. Every instance has its own interpreter state which can be loaded with custom handler scripts. @@ -45,7 +45,7 @@ The `lua` backend does not take any global configuration. |---------------|-----------------------|-----------------------|-----------------------| | `script` | `script.lua` | none | Lua source file (relative to configuration file)| -A single instance may have multiple `source` options specified, which will all be read cumulatively. +A single instance may have multiple `script` options specified, which will all be read cumulatively. #### Channel specification @@ -63,7 +63,7 @@ as an input channel name to a Lua instance will not call any handler functions. Using these names as arguments to the output and value interface functions works as intended. Output values will not trigger corresponding input event handlers unless the channel is mapped -back in the MIDIMonster configuration. +back in the MIDIMonster configuration. This is intentional. To build (and run) the `lua` backend on Windows, a compiled version of the Lua 5.3 library is required. For various reasons (legal, separations of concern, not wanting to ship binary data in the repository), -- cgit v1.2.3 From dde2cca435b2c314a08024825b1daffa6437b947 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sat, 7 Mar 2020 14:11:26 +0100 Subject: Update interval() documentation --- backends/lua.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/lua.md') diff --git a/backends/lua.md b/backends/lua.md index ce82a4d..0c592b7 100644 --- a/backends/lua.md +++ b/backends/lua.md @@ -13,7 +13,7 @@ The following functions are provided within the Lua interpreter for interaction | Function | Usage example | Description | |-------------------------------|-------------------------------|---------------------------------------| | `output(string, number)` | `output("foo", 0.75)` | Output a value event to a channel | -| `interval(function, number)` | `interval(update, 100)` | Register a function to be called periodically. Intervals are milliseconds (rounded to the nearest 10 ms) | +| `interval(function, number)` | `interval(update, 100)` | Register a function to be called periodically. Intervals are milliseconds (rounded to the nearest 10 ms). Calling `interval` on a Lua function multiple times updates the interval. Specifying `0` as interval stops periodic calls to the function | | `input_value(string)` | `input_value("foo")` | Get the last input value on a channel | | `output_value(string)` | `output_value("bar")` | Get the last output value on a channel | | `input_channel()` | `print(input_channel())` | Returns the name of the input channel whose handler function is currently running or `nil` if in an `interval`'ed function (or the initial parse step) | -- cgit v1.2.3 From f9829ae90d4017940047b561e412c6eb7f431adb Mon Sep 17 00:00:00 2001 From: cbdev Date: Sun, 8 Mar 2020 12:13:38 +0100 Subject: Implement timestamp() callback for Lua --- backends/lua.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'backends/lua.md') diff --git a/backends/lua.md b/backends/lua.md index 0c592b7..db4cf39 100644 --- a/backends/lua.md +++ b/backends/lua.md @@ -17,6 +17,7 @@ The following functions are provided within the Lua interpreter for interaction | `input_value(string)` | `input_value("foo")` | Get the last input value on a channel | | `output_value(string)` | `output_value("bar")` | Get the last output value on a channel | | `input_channel()` | `print(input_channel())` | Returns the name of the input channel whose handler function is currently running or `nil` if in an `interval`'ed function (or the initial parse step) | +| `timestamp()` | `print(timestamp())` | Returns the core timestamp for this iteration with millisecond resolution. This is not a performance timer, but intended for timeouting, etc | Example script: ``` @@ -58,8 +59,8 @@ lua1.foo > lua2.bar #### Known bugs / problems -Using any of the interface functions (`output`, `interval`, `input_value`, `output_value`, `input_channel`) -as an input channel name to a Lua instance will not call any handler functions. +Using any of the interface functions (`output`, `interval`, `input_value`, `output_value`, `input_channel`, +`timestamp`) as an input channel name to a Lua instance will not call any handler functions. Using these names as arguments to the output and value interface functions works as intended. Output values will not trigger corresponding input event handlers unless the channel is mapped -- cgit v1.2.3 From 9718e10c7f4151cea895f515c785c14e0021d967 Mon Sep 17 00:00:00 2001 From: cbdev Date: Wed, 18 Mar 2020 22:36:35 +0100 Subject: Implement default channel handlers for Lua/Python --- backends/lua.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'backends/lua.md') diff --git a/backends/lua.md b/backends/lua.md index db4cf39..96e53c8 100644 --- a/backends/lua.md +++ b/backends/lua.md @@ -6,7 +6,8 @@ and manipulate events using the Lua scripting language. Every instance has its own interpreter state which can be loaded with custom handler scripts. To process incoming channel events, the MIDIMonster calls corresponding Lua functions (if they exist) -with the value (as a Lua `number` type) as parameter. +with the value (as a Lua `number` type) as parameter. Alternatively, a designated default channel handler +may be supplied in the configuration. The following functions are provided within the Lua interpreter for interaction with the MIDIMonster @@ -42,9 +43,10 @@ The `lua` backend does not take any global configuration. #### Instance configuration -| Option | Example value | Default value | Description | -|---------------|-----------------------|-----------------------|-----------------------| -| `script` | `script.lua` | none | Lua source file (relative to configuration file)| +| Option | Example value | Default value | Description | +|-----------------------|-----------------------|-----------------------|-----------------------| +| `script` | `script.lua` | none | Lua source file (relative to configuration file) | +| `default-handler` | `handler` | none | Name of a function to be called as handler for all incoming channels (instead of the per-channel handlers) | A single instance may have multiple `script` options specified, which will all be read cumulatively. -- cgit v1.2.3 From 2d66d5cee9bf3ed5779f65d8a99b40ee5181bf30 Mon Sep 17 00:00:00 2001 From: cbdev Date: Fri, 20 Mar 2020 21:50:33 +0100 Subject: Implement Lua threading --- backends/lua.md | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'backends/lua.md') diff --git a/backends/lua.md b/backends/lua.md index 96e53c8..05509b6 100644 --- a/backends/lua.md +++ b/backends/lua.md @@ -19,24 +19,41 @@ The following functions are provided within the Lua interpreter for interaction | `output_value(string)` | `output_value("bar")` | Get the last output value on a channel | | `input_channel()` | `print(input_channel())` | Returns the name of the input channel whose handler function is currently running or `nil` if in an `interval`'ed function (or the initial parse step) | | `timestamp()` | `print(timestamp())` | Returns the core timestamp for this iteration with millisecond resolution. This is not a performance timer, but intended for timeouting, etc | +| `thread(function)` | `thread(run_show)` | Run a function as a Lua thread (see below) | +| `sleep(number)` | `sleep(100)` | Suspend current thread for time specified in milliseconds | Example script: -``` +```lua function bar(value) - output("foo", value / 2) + output("foo", value / 2); end step = 0 function toggle() - output("bar", step * 1.0) + output("bar", step * 1.0); step = (step + 1) % 2; end +function run_show() + while(true) do + sleep(1000); + output("narf", 0); + sleep(1000); + output("narf", 1.0); + end +end + interval(toggle, 1000) +thread(run_show) ``` Input values range between 0.0 and 1.0, output values are clamped to the same range. +Threads are implemented as Lua coroutines, not operating system threads. This means that +cooperative multithreading is required, which can be achieved by calling the `sleep(number)` +function from within a running thread. Calling that function from any other context is +not supported. + #### Global configuration The `lua` backend does not take any global configuration. @@ -61,9 +78,10 @@ lua1.foo > lua2.bar #### Known bugs / problems -Using any of the interface functions (`output`, `interval`, `input_value`, `output_value`, `input_channel`, -`timestamp`) as an input channel name to a Lua instance will not call any handler functions. -Using these names as arguments to the output and value interface functions works as intended. +Using any of the interface functions (`output`, `interval`, etc.) as an input channel name to a +Lua instance will not call any handler functions. Using these names as arguments to the output and +value interface functions works as intended. When using a default handler, the default handler will +be called. Output values will not trigger corresponding input event handlers unless the channel is mapped back in the MIDIMonster configuration. This is intentional. -- cgit v1.2.3