|
1 | | -# obs-libre-macros |
2 | | -:8ball: Scripting and macros hotkeys in OBS Studio for Humans |
| 1 | +# Description |
| 2 | +*obs-libre-macros* is an Extension for OBS Studio built on top of its scripting facilities, |
| 3 | +utilising built-in embedded LuaJIT interpreter, filter UI and function environment from Lua 5.2 |
| 4 | + |
| 5 | +# Features |
| 6 | +- Attach `Console` to *any* source in real-time. |
| 7 | +- *Auto run* code when OBS starts, *load from file*, *Hot reload* expressions. |
| 8 | +- Hotkeys support for each `Console` instance. |
| 9 | +- Integration with 3-rd party plugins and scripts via `obs_data_json_settings` e.g: |
| 10 | + - [move transition](https://github.com/exeldro/obs-move-transition) - latest versions include `audio move filter` which monitors source volume level. |
| 11 | + - [websocket](https://github.com/Palakis/obs-websocket) - control obs through WebSockets |
| 12 | +- Less boilerplate: an environment provided with already defined namespace. |
| 13 | + - `t.source` - access source reference unique to each `Console` instance. |
| 14 | + - `t.pressed` - access hotkey state. |
| 15 | + - `sleep(seconds)` - command to pause execution. |
| 16 | + - `t.tasks` - asynchronous event loop. |
| 17 | + - `obslua` - accessed via `obs` and `obsffi` - native linked library. |
| 18 | + - Share GLOBAL state between `Console` instances via `gn` - global namespace. |
| 19 | + - `t.<setting_name>` - various settings |
| 20 | +- Crossplatform. |
| 21 | +- View output of `print` in `Script Log`. |
| 22 | + |
| 23 | +# Installation |
| 24 | +- One time setup |
| 25 | +- Download source code, unpack/unzip. |
| 26 | +- Add `console.lua` to OBS Studio via Tools > Scripts > "+" button |
| 27 | +--- |
| 28 | +# Usage |
| 29 | + |
| 30 | +- Left click on any source, add `Console` filter to it. |
| 31 | +- Open `Script Log` to view `Console` output. |
| 32 | +- Type some code into the text area. |
| 33 | +- Press `Execute!`. |
| 34 | +- Sample code: `print(obs.obs_frontend_get_current_scene_collection())` |
| 35 | + |
| 36 | +# REPL usage |
| 37 | + |
| 38 | +Each Console instance has it's own namespace `t`, |
| 39 | +you can access source which Console is attached to. |
| 40 | +You can do this by writing this: |
| 41 | +```lua |
| 42 | +print(obs.obs_source_get_name(t.source)) |
| 43 | +``` |
| 44 | +Note: use of `local`, if you decide to not to use it, variable will become global and all Console |
| 45 | +instances can access it. So if you want to save some state particular to Console |
| 46 | +instance you'd better write this: |
| 47 | +```lua |
| 48 | +local this_source_note = "sample text" |
| 49 | +t.this_source_note = this_source_note |
| 50 | +-- or |
| 51 | +t.k = 'value' |
| 52 | +``` |
| 53 | +Later if you want to change it you'd write: |
| 54 | +```lua |
| 55 | +t.this_source_note = "samplex text updated at" .. os.date(" %X ") |
| 56 | +print(t.this_source_note) |
| 57 | +``` |
| 58 | + |
| 59 | +# Auto run |
| 60 | +If you check `Auto run` then code from this console will be executed automatically |
| 61 | +when OBS starts. |
| 62 | + |
| 63 | +# Loading from file |
| 64 | +To load from file you need first select which one to load from properties, |
| 65 | +see "Settings for internal use", then paste this template into text area: |
| 66 | +```lua |
| 67 | +local _ENV = _G |
| 68 | +_ENV.t = __t |
| 69 | +local f = loadfile(t.p1,nil,"t",_ENV) |
| 70 | +success, result = pcall(f) |
| 71 | +if not success then print(result) end |
| 72 | +``` |
| 73 | +# Hotkeys usage |
| 74 | +There are 2 types of hotkeys: |
| 75 | + - First,can be found in settings with prefixed `0;` - it will execute code in text area |
| 76 | + - Second, prefixed with `1;`- it will mutate `t.pressed` state |
| 77 | + |
| 78 | +# License |
| 79 | +The *obs-libre-macros* is free software: you can redistribute it and/or modify it under the terms of |
| 80 | +the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, |
| 81 | +or (at your option) any later version. See also: https://www.gnu.org/licenses/agpl-3.0.en.html |
| 82 | +[](https://www.gnu.org/licenses/agpl-3.0.html) |
0 commit comments