Skip to content

Commit 78c2f2f

Browse files
committed
updated & new guides
1 parent 9e695fd commit 78c2f2f

20 files changed

+1112
-683
lines changed

docs/SUMMARY.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
- [Sockets](guide/sockets.md)
1515
- [MIDI](guide/midi.md)
1616
- [OSC](guide/osc.md)
17-
- [Pattern Iterator](guide/pattern_iterator.md)
18-
- [Track Automation](guide/track_automation.md)
19-
- [Sample Buffers](guide/sample_buffer.md)
20-
- [Keybindings](guide/keybindings.md)
21-
- [Menu Entries](guide/menus.md)
22-
- [Views](guide/views.md)
23-
- [Preferences](guide/preferences.md)
17+
- [SQLite](guide/sqlite.md)
18+
- [Renoise Application](guide/application.md)
19+
- [Renoise Song](guide/song.md)
20+
- [Tool Keybindings](guide/keybindings.md)
21+
- [Tool Menu Entries](guide/menus.md)
22+
- [Tool Views](guide/views.md)
23+
- [Tool Preferences](guide/preferences.md)
2424
- [API Reference](API/README.md)
2525
<!-- API TOC START -->
2626
- [renoise](API/renoise.md)

docs/guide/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# Guides to the Renoise API
22

3-
In this section you can learn about different aspects of the API. These guides will assume you've already read the chapters in [our introduction](../start/development.md) and you are able to package and install tools.
3+
Welcome to the guides for the Renoise Scripting API.
4+
5+
In this section, you can learn about different aspects of the API through practical examples and explanations. These guides assume you have already read the chapters in our [introduction](../start/development.md) and are familiar with how to package and install tools.

docs/guide/application.md

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
# The Renoise Application
2+
3+
The `renoise.app()` function is the entry point for interacting with the Renoise application itself. It returns a [`renoise.Application`](../API/renoise/renoise.Application.md) object, which provides access to global application states, functions for user interaction like dialogs, and control over the main window.
4+
5+
## Controlling the Application Window
6+
7+
The [`renoise.ApplicationWindow`](../API/renoise/renoise.ApplicationWindow.md) object, accessed via `renoise.app().window`, allows you to query and control the state of the main Renoise UI.
8+
9+
```lua
10+
local window = renoise.app().window
11+
12+
-- Toggle fullscreen mode
13+
window.fullscreen = not window.fullscreen
14+
15+
-- Check if the disk browser is visible
16+
if window.disk_browser_is_visible then
17+
print("Disk browser is currently open.")
18+
end
19+
20+
-- Switch the middle frame to the Mixer view
21+
window.active_middle_frame =
22+
renoise.ApplicationWindow.MIDDLE_FRAME_MIXER
23+
```
24+
25+
You can also attach notifiers to many window properties to react to UI changes made by the user.
26+
27+
```lua
28+
local window = renoise.app().window
29+
30+
-- Be notified when the disk browser visibility changes
31+
function disk_browser_visibility_changed()
32+
if window.disk_browser_is_visible then
33+
renoise.app():show_status("Disk browser was opened.")
34+
else
35+
renoise.app():show_status("Disk browser was closed.")
36+
end
37+
end
38+
39+
window.disk_browser_is_visible_observable:add_notifier(
40+
disk_browser_visibility_changed
41+
)
42+
```
43+
44+
## Song and File Handling
45+
46+
The application object provides functions to load, and save songs, instrument and other kinds of components. Note that these operations are not always instantaneous, as Renoise may need to prompt the user to save changes.
47+
48+
To reliably execute code after a new song is created or loaded, you should use notifiers.
49+
50+
```lua
51+
local app = renoise.app()
52+
53+
-- This will show a file dialog to the user. The song is not loaded immediately.
54+
app:load_song("/path/to/some/song_file")
55+
56+
-- To run code after a new song is ready, use a notifier.
57+
-- This is typically done in your tool's initialization code.
58+
function handle_new_document()
59+
print("A new song was created or loaded. The new song name is: " ..
60+
renoise.song().name)
61+
end
62+
63+
-- The 'new_document_observable' is fired after a new song is
64+
--- successfully created or loaded.
65+
renoise.tool().app_new_document_observable:add_notifier(handle_new_document)
66+
67+
-- To save a song to a specific file:
68+
app:save_song_as("/path/to/MyNewSong.xrns")
69+
```
70+
71+
## Showing Dialogs and Messages
72+
73+
A common task for tools is to communicate with the user. The application object provides several functions to show different kinds of dialogs and messages.
74+
75+
### Simple Messages
76+
77+
For simple notifications, you can use `show_message`, `show_error`, `show_warning`, or `show_status`.
78+
79+
```lua
80+
local app = renoise.app()
81+
82+
-- Show a message in the status bar
83+
app:show_status("This is a status message.")
84+
85+
-- Show a modal info dialog
86+
app:show_message("This is an informational message.")
87+
88+
-- Show a modal warning dialog
89+
app:show_warning("This is a warning message.")
90+
91+
-- Show a modal error dialog
92+
app:show_error("This is an error message.")
93+
```
94+
95+
### User Prompts
96+
97+
To ask the user for a choice, you can use `show_prompt`. It displays a dialog with custom buttons and returns the label of the button that was pressed.
98+
99+
```lua
100+
local app = renoise.app()
101+
102+
local pressed_button = app:show_prompt(
103+
"Confirm Action",
104+
"Do you want to proceed?",
105+
{ "Yes", "No", "Cancel" }
106+
)
107+
108+
if pressed_button == "Yes" then
109+
app:show_message("You chose to proceed.")
110+
elseif pressed_button == "No" then
111+
app:show_message("You chose not to proceed.")
112+
else
113+
app:show_message("You canceled the operation.")
114+
end
115+
```
116+
117+
### Custom Dialogs
118+
119+
For more complex user interfaces, you can create custom non-modal dialogs (tool windows) with `show_custom_dialog`. This requires using the `renoise.ViewBuilder` API to construct the UI.
120+
121+
```lua
122+
-- A simple custom dialog example
123+
local vb = renoise.ViewBuilder()
124+
125+
local my_dialog = nil
126+
local my_dialog_content = vb:column {
127+
margin = renoise.ViewBuilder.DEFAULT_DIALOG_MARGIN,
128+
spacing = renoise.ViewBuilder.DEFAULT_DIALOG_SPACING,
129+
views = {
130+
vb:text {
131+
text = "This is a custom dialog."
132+
},
133+
vb:button {
134+
text = "Close Me",
135+
notifier = function()
136+
-- my_dialog is defined when calling show_custom_dialog
137+
my_dialog:close()
138+
end
139+
}
140+
}
141+
}
142+
143+
my_dialog = renoise.app():show_custom_dialog(
144+
"My Tool Window", my_dialog_content
145+
)
146+
```
147+
148+
## File and Path Prompts
149+
150+
Your tool might need to read from or write to files. The API provides functions to open native file browser dialogs.
151+
152+
```lua
153+
local app = renoise.app()
154+
155+
-- Prompt the user to select a directory
156+
local dir_path = app:prompt_for_path("Select a Project Folder")
157+
if dir_path and #dir_path > 0 then
158+
app:show_message("You selected the directory: " .. dir_path)
159+
end
160+
161+
-- Prompt the user to select a file to open
162+
local file_to_read = app:prompt_for_filename_to_read(
163+
{ "txt", "lua" },
164+
"Open a Text File"
165+
)
166+
if file_to_read and #file_to_read > 0 then
167+
app:show_message("You selected the file: " .. file_to_read)
168+
end
169+
170+
-- Prompt the user for a filename to save
171+
local file_to_write = app:prompt_for_filename_to_write(
172+
"xml",
173+
"Save Configuration"
174+
)
175+
if file_to_write and #file_to_write > 0 then
176+
app:show_message("File will be saved to: " .. file_to_write)
177+
end
178+
```

docs/guide/classes.md

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
# Classes
22

3-
The Lua language has by default no `class` construct. But the Renoises lua API has a simple OO support inbuilt -> `class "MyClass"`. All Renoise API objects use such classes and you can use them too in your tools.
3+
The Lua language does not have a built-in `class` construct. However, the Renoise Lua API provides simple object-oriented programming support via a global `class()` function. All Renoise API objects use such classes, and you can use them in your tools as well.
44

5-
See [luabind docs](https://www.rasterbar.com/products/luabind/docs.html#defining-classes-in-lua)
6-
for more technical info and below for some simple examples
5+
See the [luabind documentation](https://www.rasterbar.com/products/luabind/docs.html#defining-classes-in-lua) for more technical information, and the examples below for how to use them.
76

87
## Examples
98

109
```lua
1110
-- abstract class
12-
1311
class 'Animal'
12+
1413
function Animal:__init(name)
1514
self.name = name
1615
self.can_fly = nil
@@ -19,29 +18,32 @@ class 'Animal'
1918
function Animal:__tostring()
2019
assert(self.can_fly ~= nil, "I don't know if I can fly or not")
2120

22-
return ("I am a %s (%s) and I %s fly"):format(self.name, type(self),
23-
(self.can_fly and "can fly" or "can not fly"))
21+
return ("I am a %s (%s) and I %s"):format(self.name, type(self),
22+
(self.can_fly and "can fly" or "cannot fly"))
2423
end
2524

2625

2726
-- derived classes
2827

2928
-- MAMMAL
3029
class 'Mammal' (Animal)
30+
3131
function Mammal:__init(str)
3232
Animal.__init(self, str)
3333
self.can_fly = false
3434
end
3535

3636
-- BIRD
3737
class 'Bird' (Animal)
38+
3839
function Bird:__init(str)
3940
Animal.__init(self, str)
4041
self.can_fly = true
4142
end
4243

4344
-- FISH
4445
class 'Fish' (Animal)
46+
4547
function Fish:__init(str)
4648
Animal.__init(self, str)
4749
self.can_fly = false
@@ -50,50 +52,43 @@ class 'Fish' (Animal)
5052

5153
-- run
5254

53-
local farm = table.create()
55+
local farm = {}
5456

55-
farm:insert(Mammal("cow"))
56-
farm:insert(Bird("sparrow"))
57-
farm:insert(Fish("bass"))
57+
table.insert(farm, Mammal("cow"))
58+
table.insert(farm, Bird("sparrow"))
59+
table.insert(farm, Fish("bass"))
5860

5961
print(("type(Mammal('cow')) -> %s"):format(type(Mammal("cow"))))
6062
print(("type(Mammal) -> %s"):format(type(Mammal)))
6163

62-
for _,animal in pairs(farm) do
64+
for _,animal in ipairs(farm) do
6365
print(animal)
6466
end
6567
```
6668

6769
Something to keep in mind:
6870

69-
* constructor `function MyClass:__init(args)` must be defined for each class,
70-
or the class can't be used to instantiate objects.
71-
72-
* class defs are always global, so even locally defined classes will be
73-
registered globally.
71+
* A constructor, `function MyClass:__init(args)`, must be defined for each class, or the class cannot be used to instantiate objects.
72+
* Class definitions are always global, so even locally defined classes will be registered globally.
7473

7574

7675
## Class operators
7776

78-
You can overload most operators in Lua for your classes. You do this by
79-
simply declaring a member function with the same name as an operator
80-
(the name of the metamethods in Lua).
77+
You can overload most operators in Lua for your classes. You do this by simply declaring a member function with the same name as an operator's corresponding metamethod in Lua.
8178

8279
The operators you can overload are:
8380

84-
* __add
85-
* __sub
86-
* __mul
87-
* __div
88-
* __pow
89-
* __lt
90-
* __le
91-
* __eq
92-
* __call
93-
* __unm
94-
* __tostring
95-
* __len
96-
97-
Note: `__tostring` isn't really an operator, but it's the metamethod that is
98-
called by the standard library's tostring() function.
99-
81+
* `__add` (addition)
82+
* `__sub` (subtraction)
83+
* `__mul` (multiplication)
84+
* `__div` (division)
85+
* `__pow` (exponentiation)
86+
* `__lt` (less than)
87+
* `__le` (less than or equal to)
88+
* `__eq` (equality)
89+
* `__call` (function call)
90+
* `__unm` (unary minus)
91+
* `__tostring`
92+
* `__len` (length operator `#`)
93+
94+
Note: `__tostring` isn't really an operator, but it's the metamethod that is called by the standard library's `tostring()` function.

docs/guide/files&bits.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
# Files&Bits.lua
1+
# Files & Bits
22

3-
In order to access the raw bits and bytes of some data, e.g. to read or write binary (file) streams, you can use the Lua `bit` library. It's built into the Renoise API. There's no need to `require` it.
3+
To access the raw bits and bytes of some data, for example, to read or write binary file streams, you can use the `bit` library. It's built into the Renoise API, so there's no need to `require` it.
44

5-
See [bit documentation](https://bitop.luajit.org/) for more info and examples.
5+
See the [LuaJIT bit library documentation](https://bitop.luajit.org/api.html) for more info and examples. For file operations, you can use Lua's standard [io library](https://www.lua.org/pil/21.html).
66

77
```lua
8-
-- reading integer numbers or raw bytes from a file
8+
-- Reading integer numbers or raw bytes from a file
99

1010
local function read_word(file)
1111
local bytes = file:read(2)
1212
if (not bytes or #bytes < 2) then
1313
return nil
1414
else
15-
return bit.bor(bytes:byte( 1),
15+
-- little-endian
16+
return bit.bor(bytes:byte(1),
1617
bit.lshift(bytes:byte(2), 8))
1718
end
1819
end
@@ -22,16 +23,21 @@ local function read_dword(file)
2223
if (not bytes or #bytes < 4) then
2324
return nil
2425
else
26+
-- little-endian
2527
return bit.bor(bytes:byte(1),
2628
bit.lshift(bytes:byte(2), 8),
2729
bit.lshift(bytes:byte(3), 16),
2830
bit.lshift(bytes:byte(4), 24))
2931
end
3032
end
3133

32-
-- and so on (adapt as needed to mess with endianess!) ...
34+
-- and so on (adapt as needed to mess with endianness!) ...
3335

34-
local file = io.open("some_binary_file.bin", "rb")
36+
local file, err = io.open("some_binary_file.bin", "rb")
37+
if not file then
38+
print("Could not open file: " .. tostring(err))
39+
return
40+
end
3541

3642
local bytes = file:read(512)
3743

@@ -45,5 +51,6 @@ end
4551

4652
print(read_word(file) or "unexpected end of file")
4753
print(read_dword(file) or "unexpected end of file")
48-
```
4954

55+
file:close()
56+
```

0 commit comments

Comments
 (0)