]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blame - documentation_en.md
Add config
[perso/Immae/Projets/Python/MusicSampler.git] / documentation_en.md
CommitLineData
faed2fa8
IB
1[TOC]
2
3# Music Sampler
4
5## Description
6
7Music Sampler is a music player which associates each key on the keyboard to a
8set of actions to run.
9
10## Dependencies and installation
11
b3951077
IB
12(See next section for Windows installation)
13
faed2fa8
IB
14- You need ffmpeg installed. For that, you can use package `libav-tools` (debian):
15
16 sudo apt-get install libav-tools
17
18If you use the compiled version of Music Sampler (cf. below for a download
19link), you need nothing else.
20
21- To use sources, the following modules are required:
22
23| module | minimum version | note |
24| ----------- | ---------------- | ------------------------------------------------------------- |
25| Cython | 0.24 | to compile Kivy |
26| Kivy | 1.9.1 | some features require to build/install with flag `USE_SDL2=1` |
27| Markdown | 2.6.6 | for documentation only |
28| pydub | 0.16.4 | |
29| Pygame | 1.9.2.dev1 | used by Kivy |
30| Pygments | 2.1.3 | for documentation only |
31| sounddevice | 0.3.3 | |
32| transitions | 0.4.1 | |
33| PyYAML | 3.11 | |
34
35The project is also available via `pip`:
36
37 pip install music_sampler
38
39The program makes use of fonts "Symbola" and "Ubuntu" (Regular / Bold), that
40must be available on your system, as well as the `portaudio` library:
41
42 sudo apt-get install ttf-ancient-fonts ttf-ubuntu-font-family portaudio
43
16847231 44To compile Kivy with the SDL2 library, you need some packages:
faed2fa8
IB
45
46 sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev
47
48cf [Installation
49Kivy](https://kivy.org/docs/installation/installation-linux.html)
50
fa904784 51## Windows installation
b3951077
IB
52
53Following processed worked to install music sampler in a Windows
54machine:
55
fa904784 56- [Install python 3.9.\* (take 64bit version!)](https://www.python.org/downloads/windows)
b3951077
IB
57- In a command shell (`cmd.exe`), run:
58
59 pip install music_sampler
60 pip install docutils pygments pypiwin32 PySDL2 kivy.deps.sdl2 kivy.deps.glew
61
62- [Install ffmpeg (64bit, static)](https://ffmpeg.zeranoe.com/builds/)
63 and put the content of folder `bin` in the same folder as music and configs.
64- [Download Ubuntu font](https://www.1001fonts.com/ubuntu-font.html)
65 and install Ubuntu-R and Ubuntu-B (Regular and Bold) *for all users* (right clic on the font)
66- [Download Symbola font](https://fontlibrary.org/en/font/symbola)
67 and install it *for all users* (right clic on the font)
68- Write a `run.bat` file with:
69
70 :::bash
71 @echo off
72 music_sampler
73
74- Run this `run.bat` when you need it.
75
faed2fa8
IB
76## Compiled version
77
78A compiled version can be created with `pyinstaller`:
79
80 :::bash
81 pyinstaller music_sampler.spec
82
83## Downloads
84
85- An example configuration together with some music examples can be found on
86 [owncloud](https://outils.immae.eu/owncloud/index.php/s/kSrIe15G1AiZ9YF)
87- A precompiled version of `music_sampler` can also be found
88 [in the same folder](https://outils.immae.eu/owncloud/index.php/s/kSrIe15G1AiZ9YF/download?path=%2F&files=music_sampler)
89 (beware, it might not be up-to-date, please run the program with `-V` to see
90 its corresponding version)
91
92## Usage
93
94The whole job consists in preparing all the transitions in the configuration
95file `config.yml`.
96
97The program should then be run in the folder in which the configuration file
98lies (see below for an advanced use). A window with a keyboard appears. The
99orange circle in the upper-right corner of the keyboard becomes green one every
100music is loaded (or red in case of problem). A key is semi-transparent and
101crossed when it is not usable at the moment: either because a music handled by
102this key is not loaded yet (it may take some time when the program launches), or
103because it has an action running.
104
105An example configuration file is given with some keys and transitions. The
106structure of the file (explained more in details below) should be easy to
107understand just by looking at it.
108
109### Possible actions
110
111 - Clic on a key: shows the associated actions in the bottom-left block of the
112 app.
113 - Key stroke: if available, runs the actions associated to this key. When a
114 key has currently running actions, his surround is black. Note that an
115 action like "play a music" is almost instantaneous as it is considered
116 "done" as soon as the music started playing.
117 To prevent accidents in case of repeated stroke on a key, `Music Sampler`
118 won't rerun the actions associated to that key if they are not already
119 finished.
120 - Ctrl+C or Ctrl+Q: leaves the program.
121 - Ctrl+R: reloads the configuration file
122
123### Options available at launch
124
125All the options below are optional; usually, running the program in the correct
16847231
IB
126folder is enough. Most of the parameters can be defined also in the config file.
127The command line parameters always take precedence.
faed2fa8
IB
128
129 * `-h, --help`: shows a list of available options
130 * `-c CONFIG, --config CONFIG`: gives the configuration file to load (by
131 default, `config.yml` in the current folder).
132 * `-p MUSIC_PATH, --music-path MUSIC_PATH`: gives the path to find the musics
133 (by default, the current folder)
16847231
IB
134 * `--no-debug, --debug`: show debug informations in the terminal (disabled by
135 default)
faed2fa8
IB
136 * `-V, --version`: show current version and exit (only for the compiled
137 version)
138 * `-L, --language`: change application language. Current languages: fr, en
139 (default 'fr')
16847231
IB
140 * `--focus-warning, --no-focus-warning`: show / don't show warning when focus gets
141 lost (default is to show it)
faed2fa8
IB
142
143The following options are reserved for a more advanced use of Music Sampler, or
144in case of problem with the standard configuration:
145
16847231
IB
146 * `--no-builtin-mixing, --builtin-mixing`: make the sound mixing locally. By
147 default, Music Sampler will let the system do it and open one channel per
148 music loaded. Use it only if the system cannot handle it.
faed2fa8
IB
149 * `-l LATENCY, --latency LATENCY`: "low", "high" or a number of seconds
150 (default "high")
151 * `-b BLOCKSIZE, --blocksize BLOCKSIZE`: Number of frames for each mixing
152 step. 0 (default) lets the program choose.
153 * `-f FRAME_RATE, --frame-rate FRAME_RATE`: default 44100Hz
154 * `-x CHANNELS, --channels CHANNELS` : Number of channels per music (default
155 2, for stereo)
156 * `-s SAMPLE_WIDTH, --sample-width SAMPLE_WIDTH`: number of bytes per frame
157 (default 2).
158 * `--device DEVICE` : select another sound device.
159 * `--list-devices` : list available sound devices.
b4583764 160 * `--load-all-musics` : load all the music when starting (default True)
faed2fa8
IB
161 * `-- ARGS` : arguments for Kivy library.
162
163## Configure keys
164
165**Warning: the format of the configuration file is still a work in progress and
166may change without ensuring backward compatibility**
167
168The file `config.yml` uses yaml syntax. Categories and sub-categories are
169handled by space indentations (no tabs). Symbol `#` may be used for comments.
170
171In case of error in the configuration file, an error message will show up.
172Depending on its severity, Music Sampler may try to continue (ignoring
173corresponding problems) or abort.
174
175The file contains several sections:
176
177 :::yaml
16847231
IB
178 config:
179 ...
180
faed2fa8
IB
181 aliases:
182 ...
183
184 music_properties:
185 ...
186
187 key_properties:
188 ...
189
190 keys:
191 ...
192
16847231
IB
193### `config`
194
195The config section lets you store configuration parameters that you would
196normally use in the command line parameters. The '-' in the long parameter name
197should be replaced by '_' (e.g. '--music-path' -> 'music_path'). For toggles
198(`debug`, `focus_warning`, `builtin_mixing`) use the version without 'no-' and
199specify `true` or `false` as value. Note that command line arguments always take
200precedence.
faed2fa8
IB
201
202### `music_properties`
203
204This section lets you define global properties for the musics.
205
206#### Examples
207
208 :::yaml
209 "music1.mp3":
210 name: My favorite music
211 gain: 1.4
212Music "music1.mp3" is named "My favorite music". She is loaded at 140% of its
213normal volume.
214
215 :::yaml
216 "music2.mp3":
217 gain: 0.7
218
219Music "music2.mp3" is loaded at 70% of its normal volume.
220
221#### List of available options
222- `name: My music` User-friendly name of the music, used in the interface
223 instead of the filename.
224
225- `gain: x` Loads the music with that initial gain x. This lets you equalize all
226 your music at desired level, independently of the volume afterwards.
227
228### `key_properties`: drawing and properties of keys
229
230This section lets you describe the drawing of the key: color, description. By
231default, a key assigned to one or more actions is shown in green
232
233#### Examples
234
235 :::yaml
236 'ESC':
237 description:
238 -
239 - STOP!
240 color: [255, 0, 0]
241 repeat_delay: 2
242
243The "esc" key is red, and text "STOP!" is shown on the second line. The key is
244protected for 2 seconds after each stroke.
245
246#### List of availale options
247- `description`: the text on the key. Each item is shown on a line (no automatic
248 line break). First line is shown just next to the "key" name and is in bold.
249 On a standard screen, you may have about 3 lines visible (including the first
250 one)
251- `color: [r, g, b]`: the key color. r, g and b are the proportions respectively
252 of red, green and blue, and each value must be between 0 and 255
253- `repeat_delay: x` (default 0) : protection delay. Once all its actions are
254 done, the key will remain disabled (semi-transparent and crossed) for that
255 amount of time (in seconds).
b798117b 256- `actions: list`: List of actions to run with the key.
faed2fa8 257
dac64df8
IB
258#### `common` key property
259
260A special entry `common` has its properties applying to all the keys. They can
261be overriden individually.
262
faed2fa8
IB
263### `keys` : actions related to keys
264
265This section lets you describe for each key, the list of actions associated to
266it. Note that except for `wait` and some particular cases (see below), all the
267actions are almost instantaneous.
268
b798117b
IB
269*This section is deprecated and replaced by an `actions` key containing a list
270in `key_properties` section for each key.*
faed2fa8
IB
271
272#### Examples
273
274 :::yaml
275 'a':
276 - play:
277 file: "music1.mp3"
278 volume: 70
279 start_at: 10
280 - wait:
281 duration: 5
282 - stop:
283 file: "music1.mp3"
284 fade_out: 2
285
286Runs music "music1.mp3" at 70% of its maximum volume, at 10 seconds from the
287start, then stops the music 5 seconds later with a 2 seconds fade out.
288
289 :::yaml
290 'b':
291 - stop:
292 file: "music1.mp3"
293 fade_out: 5
294 wait: false
295 - play:
296 file: "music2.mp3"
297 fade_in: 5
298
299Make a cross fade of 5 seconds between "music1.mp3" and "music2.mp3"
300
301 :::yaml
302 'c':
303 - stop:
304 file: "music1.mp3"
305 fade_out: 5
306 wait: true
307 - wait:
308 duration: 2
309 - play:
310 file: "music2.mp3"
311 - seek:
312 file: "music2.mp3"
313 delta: false
314 value: 60
315Stops music "music1.mp3" with a 5 seconds fade out, waits for the end of the
316fade out, plus 2 seconds, and then runs "music2.mp3" skipping the first minute.
317
318 :::yaml
319 'd':
320 - volume:
321 file: "music1.mp3"
322 value: 50
323 - play:
324 file: "noise.mp3"
325 loop: 1
326 - wait:
327 file: "noise.mp3"
328 - volume:
329 file: "music1.mp3"
330 value: 100
331
332Lower volume of "music1.mp3" while "noise.mp3" is played above it (twice). Then
333the volume of the music comes back to normal.
334
335 :::yaml
336 'e':
337 - pause:
338 file: "music1.mp3"
339 - wait:
340 duration: 10
341 - unpause:
342 file: "music1.mp3"
343 - seek:
344 file: "music1.mp3"
345 delta: true
346 value: 5
347
348Pauses "music1.mp3" for 10 seconds and reruns it afterward, seeking to 5 seconds
349later.
350
351#### List of all the actions:
de71c01c
IB
352- `comment`: does nothing, but shows a comment in the action windows
353 * `message: "some text"` the message to show
faed2fa8
IB
354- `play` : start a music. Music Sampler only runs a music once (if you want to
355 have it playing several time concurrently, duplicate it or make symbolic
356 link). Parameters:
357 * `file: "music.mp3"` gives the played music (relative path).
358 * `fade_in: x` (optional) runs the music with x seconds fade in.
359 * `volume: x` (optional, default 100) sets the volume of the music.
360 * `loop: x` (optional, default 0) music should be repeated x times. Indicate
361 -1 for infinite loop. Note: x is the number of repetitions, thus the music
362 is actually played x+1 times.
363 * `start_at: x` (optional, default 0) start music skipping the first x
364 seconds.
365 * `restart_if_running: true/false` (optional, default false) if the music is
366 already running, stop it and restart it.
367- `stop` : stops a given music. Parameters:
368 * `file: "music.mp3"` (optional) gives the music to stop. If no music is
369 given, stops all of them.
370 * `fade_out: x` (optional) stops music with a x seconds fade out.
371 * `wait: true/false` (optional, default: false) when stopping with a fade
372 out, wait for the fade to finish before continuing to the next actions. If
373 the music stops naturally before the en of the fade out, the wait stops
374 there too. When several musics are stopped in fade out, the `wait` only
375 waits for the last one in the playlist (which can finish naturally before
376 the others).
377 * `set_wait_id: name` (optional, useless when `wait` is false) sets an id
378 `name` to the wait (see `interrupt_wait`). Any valid string may be used.
379- `volume` : change the volume of a given music. Parameters:
380 * `file: "music.mp3"` (optional) which music to change. If no music is
381 given, the global volume is changed.
382 * `delta: true/false` (optional, default false) add/remove to the volume
383 instead of setting an absolute value.
384 * `value: x` if delta is false, sets the volume to x%. Note that this factor
385 is applied to the music already loaded (with the initial gain). If delta
386 is true, adds or remove the percentage to the current volume.
387 * `fade: x` (optional) the volume change is applied with a x seconds fade.
388- `pause` : pause a music. Parameters:
389 * `file: "music.mp3"` (optional) gives the music to pause. If no music is
390 given, it applies to all playing musics.
391- `unpause` : unpause a music. Parameters:
392 * `file: "music.mp3"` (optional) gives the msuic to unpause. If no music is
393 given, it applies to all paused musics.
394- `wait` : wait for some time or for an event. Parameters:
395 * `file: "music.mp3"` (optional) wait for the end of music "music.mp3"
396 * `duration: x` (optional) wait x seconds. If `file` and `duration` are
397 given, wait the end of the music PLUS the `duration`.
398 * `set_wait_id: name` (optional) gives an id to the wait event (see
399 `interrupt_wait`). The id can be any valid string.
400Note again that this action is one of the only action that is not almost
401instantaneous. Use it wherever you need to make some time adjustments for other
402actions.
403- `seek` : seek to a specific position in a music. Parameters:
404 * `file: "music.mp3"` (optional) gives the music to seek. If no music is
405 given, applies to all playing musics.
406 * `delta: true/false` (optional, default false) If `delta` is true, the time
407 seek is relative. Otherwise, it is absolute.
408 * `value: x` If `delta` is true, then moves the music forward or backward by
409 x seconds. If delta is false, the music goes to that position. If the
410 music is fading (fade in or volume fade), the effect is immediately
411 interrupted. If the music is fading out, the "seek" is ignored. In case of
412 `loop`, a relative seek may jump to previous or next loop if possible,
413 while an absolute seek will jump to a position in the current loop.
414- `stop_all_actions:` Interrupts all the running and pending actions. Note that
415 a started music (even with a `loop` option) is the result of an action that is
416 already finished and thus will keep playing (see `stop` for that). Parameters:
417 * `other_only: true/false` (optional, default false): if `other_only` is
418 true, the interruption is valid for all keys except the one that ran the
419 action. When false, it is thus useless to add actions after that one.
420- `interrupt_wait`: stop a wait event (normal `wait` or fade out wait). The keys
421 that were waiting will move to the next actions. Parameters:
d4217fda
IB
422 * `wait_id: name` (optional) gives the id of the `wait` to interrupt
423 (defined with `set_wait_id`, see actions `wait` and `stop`). If not given,
424 interrupts all wait events.
425- `pause_wait`: pauses a wait event (only for a wait with duration). The key
426 that were waiting will keep waiting until the `wait` is unpaused. Parameters:
427 * `wait_id: name` (optional) gives the id of the `wait` to pause. If not
428 given, pauses all compatible wait events.
429- `unpause_wait`: unpauses a paused wait event (only a wait with duration). The
430 countdown will resume for the corresponding keys. Parameters:
431 * `wait_id: name` (optional) gives the id of the `wait` to unpause. If not
432 given, unpauses all compatible wait events.
433- `reset_wait`: resets a wait counter (only a wait with duration). If the wait
434 was paused, it will stay paused and start at the beginning once it is
435 unpaused. Parameters:
436 * `wait_id: name` (optional) gives the id of the `wait` to reset. If not
437 given, resets all compatible wait events.
faed2fa8
IB
438- `run_command` : Run a command. Parameters:
439 * `command: my_command` : Gives the command to run.
440 * `wait: true/false` (optional, default false) if true, waits for the
441 command to finish (this wait is not interruptible by interrupt_wait)
b4583764
IB
442- `load_music/unload_music` : load/unload a music from memory. Useful
443 with `load_all_musics` option only
444 * `music: "music.mp3" the music to load/unload
faed2fa8
IB
445
446### `aliases` : define aliases
447
448It is possible to define some aliases for the parameters. Those aliases are
449internal to the configuration file. To give a nice name to a music, see
450"music_properties".
451
452The aliases syntax is the following:
453
454 :::yaml
455 aliases:
456 alias1:
457 param: value
458 alias2:
459 param1: value1
460 param2: value2
461
462You can then use in other places of the configuration file a special argument
463`include: alias1` or `include: [alias1, alias2]` instead of `param: value`. In
464the case of several aliases that have identical elements, only the last one is
465kept. In all cases, a value defined outside of an include takes precedence. See
466below examples.
467
468#### Examples
469
470 :::yaml
471 aliases:
472 music1:
473 file: "path/to/my/favourite/music.mp3"
474
475 keys:
476 'a':
477 play:
478 include: music1
479
480`music1` is now an alias for `file: "path/to/my/favourite/music.mp3"`. You can
481use `include: music1` at any place where you would have written `file:
482"path/to/my/favourite/music.mp3"`. Aliases cannot be used in section
483"music_properties".
484
485 :::yaml
486 aliases:
487 blue:
488 color: [0, 0, 255]
489
490 keys_properties:
491 'a':
492 description:
493 -
494 - blue key
495 include: blue
496
497`blue` is an alias for color `[0, 0, 255]`. Wherever you need to specify `color:
498[0, 0, 255]`, you may write `include: blue` instead.
499
500 :::yaml
501 aliases:
502 long_time:
503 duration: 42
504
505 keys:
506 'b':
507 wait:
508 include: long_time
509 play:
510 file: "music1.mp3"
511
512`long_time` is an alias for a 42 seconds duration. Instead of `duration: 42`,
513you may use `include: long_time`.
514
515## Troubleshooting
516
517You'll find below a list of possible problems, and a possible solution. If you
518find some other problems, please contact the author.
519
520* The program starts and stops immediately.
521
522It is usually a syntax error in the config file. In that case, the terminal
523should give some informations.
524
525* The music sizzles
526
527It may be a latency problems (with slow computers). Try to adapt it to a higher
528value (~0.1 seconds)
529
530* Impossible to play more than one music at a time.
531
532The system cannot mix the musics by itself. You may have a look at the device
533list (`--list-devices`) and choose another. You may also try the integrated
534mixer, but the result may not be very fluid (you will certainly need to adjust
535blocksize and latency parameters if you do that)
536
537If your system uses PulseAudio, it may be a configuration problem for the ALSA
538plugin. In that case, try to put the following configuration in
539`/etc/asound.conf` and restart your system. This is an empirical solution that
540seems to have worked, there is no garanty that it will!
541
542 pcm.!default {
543 type pulse
544 fallback "sysdefault"
545 hint {
546 show on
547 description "Default ALSA Output (currently PulseAudio Sound Server)"
548 }
549 }
550
551 ctl.!default {
552 type pulse
553 fallback "sysdefault"
554 }
555
556* The terminal shows an error:
557
558 Exception in thread Thread-1:
559 Traceback (most recent call last):
560 File "threading.py", line 914, in _bootstrap_inner
561 File "threading.py", line 862, in run
562 File "kivy/input/providers/mtdev.py", line 219, in _thread_run
563 File "kivy/lib/mtdev.py", line 131, in __init__
564 PermissionError: [Errno 13] Permission denied: '/dev/input/event6'
565
566This is a device permission error. It can be safely ignored.
567
568* For other problems or bug, please see [Bug
569 Tracker](https://git.immae.eu/mantisbt/view_all_bug_page.php?project_id=1&sort=status%2Clast_updated&dir=ASC%2CDESC)
570
571## About
572
573The musics in the examples come from [Jamendo](https://jamendo.com). The
574complete version of those musics are available for free for a non-commercial
575use:
576
577[Short Blues](https://www.jamendo.com/track/340173/short-blues)
578
579[To the Fantasy war](https://www.jamendo.com/track/778560/to-the-fantasy-war)
580
581The crocodile noise comes from
582[Universal-Soundbank](http://www.universal-soundbank.com/).
583
584This program was developped originaly to help handling music for shows of the
585circus company [Les pieds jaloux](http://piedsjaloux.fr/). With no available
586sound manager, the artists sometimes had to run from the scene to make the sound
587transitions, making as little interaction as possible with the computed (one
588key).