Skip to content

Commit

Permalink
Start undermidi automatically and use the custom undermidi banner.
Browse files Browse the repository at this point in the history
  • Loading branch information
oubiwann committed Sep 27, 2024
1 parent 690883f commit 2958ea8
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Then start the LFE REPL with prefined options for undermidi:
$ rebar3 as undermidi repl
```

**IMPORTANT!!**: the command given above automatically starts undermidid. If you do not use that command, you will need to manually start undermidi. Not doing so will result in many commands cusing a segmentation fault of the Erlang VM due to the MIDI NIF not being initialised!

Once the LFE REPL is ready, you can start the app:

```cl
Expand All @@ -59,13 +61,11 @@ Note that, depending upon the configured log level, you may see a fair amount of
(set term (midimsg:note-off channel 48 64))
(um.ml:send device term)
(undermidi:start)
(undermidi:list-devices)
(set device "model_15")
(set channel 1)
(um.note:play device channel (um.note:make 'C3))
(undermidi:start)
(undermidi:list-devices)
(set device "model_15")
(set channel 1)
Expand All @@ -75,7 +75,6 @@ Note that, depending upon the configured log level, you may see a fair amount of
(set notes (um.note:make '(C3 C3 Eb3 C3 Eb4 Bb3 C4 C3)))
(um.note:play-notes device channel notes 250 8)
(undermidi:start)
(undermidi:list-devices)
(set device "model_15")
(set `#(ok ,d) (undermidi.devices:new device))
Expand All @@ -88,16 +87,14 @@ Note that, depending upon the configured log level, you may see a fair amount of
(undermidi:play-notes d '(seq-2a) 250 8)
(undermidi:play-notes d '(seq-3a) 250 8)
(undermidi:start)
(undermidi:list-devices)
(set device "midi_bus_1")
(set device "provs-mini_provs-mini_midi_1_24_0")
(set `#(ok ,d) (undermidi.devices:new device))
(include-lib "priv/seqs/basic.lfe")
(set notes (um.note:legnthen (um.chord:make-fuzzy (seq-3a) 80)))
(set notes (um.note:lengthen (um.chord:make-fuzzy (seq-3a)) 80))
(undermidi:play-notes d notes 8200 1)
(undermidi:start)
(set device "midi_bus_1")
(set `#(ok ,d) (undermidi.devices:new device))
(set cmaj7 (um.chord:lengthen (um.chord:make-fuzzy '(C4 E4 G4 B4)) 40))
Expand Down
4 changes: 4 additions & 0 deletions include/errors.lfe
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
(defun ERR_NO_DEVICE () #(error "no such device; see (um:list-devices) for known system MIDI devices."))

;; This function is for display purposes when used in the REPL
;; and needs to be the last function in the include file.
(defun |-- loaded include: errors --| ()
'ok)
4 changes: 2 additions & 2 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
{plugins, [rebar3_hex]}
]},
{undermidi, [
{lfe, [{nobanner, true}]}
{lfe, [{repl, [{nobanner, true}]}]}
]}
]}.

Expand All @@ -78,7 +78,7 @@
%% The following should be run with `rebar3 as undermidi repl`:
{repl, [
clean,
{lfe, repl, "--name undermidi@local"}
{lfe, repl, "--name undermidi@local --apps undermidi"}
]},
{publish, [
compile,
Expand Down
1 change: 1 addition & 0 deletions src/undermidi.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{applications,
[kernel,
stdlib,
logjam,
lfe
]},
{env,[]},
Expand Down
7 changes: 1 addition & 6 deletions src/undermidi.lfe
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@
(include-lib "logjam/include/logjam.hrl")

(defun start ()
(let ((cfg-file "config/sys.config"))
(io:format "~s" (list (undermidi.util:banner)))
(logjam:set-config `#(path ,cfg-file))
(log-notice "Starting undermidi, version ~s ..." (list (undermidi:version)))
(application:ensure_all_started 'undermidi)
(log-debug "\nVersions:\n~p\n" (list (versions)))))
(application:ensure_all_started 'undermidi))

(defun stop ()
(application:stop 'undermidi))
Expand Down
12 changes: 9 additions & 3 deletions src/undermidi/app.lfe
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun start (_start-type _start-args)
(log-info "Starting OTP application ..." '())
(um.nif:initialise)
(undermidi.supervisor:start_link))
(let ((cfg-file "config/sys.config"))
(logjam:set-config `#(path ,cfg-file))
(log-info "Starting OTP application ..." '())
(um.nif:initialise)
(io:format "~s" (list (undermidi.util:banner)))
(logjam:set-config `#(path ,cfg-file))
(log-notice "Starting undermidi, version ~s ..." (list (undermidi:version)))
(log-debug "\nVersions:\n~p\n" (list (undermidi:versions)))
(undermidi.supervisor:start_link)))

(defun stop (_state)
(um.nif:deinitialise)
Expand Down

0 comments on commit 2958ea8

Please sign in to comment.