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