Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Elixir, MIDI and LiveView
Search
Thibaut Barrère
June 18, 2019
Programming
0
320
Elixir, MIDI and LiveView
(Paris.Ex meetup)
Thibaut Barrère
June 18, 2019
Tweet
Share
More Decks by Thibaut Barrère
See All by Thibaut Barrère
Kiba ETL: feedback on OSS / open-core sustainability for a Ruby gem
thbar
0
100
Elixir, MIDI & LiveView (CodeElixir London 2019)
thbar
0
1k
Kiba ETL v2 - RubyKaigi 2018
thbar
4
1.5k
Elixir hot-reloading & MIDI events generation
thbar
1
440
De Rails à Phoenix - retour d'expérience sur une réécriture d'application SaaS
thbar
3
2.2k
Processing data with Ruby and Kiba ETL
thbar
0
210
Retour d'expérience sur le bootstrapping de WiseCash (produit SaaS)
thbar
0
770
Bootstrapping your SaaS product (with freelancing)
thbar
3
510
Prestations agiles avec Acunote et Freckle
thbar
3
550
Other Decks in Programming
See All in Programming
rtcamp 10 (vk-illuminati)
yumcyawiz
0
140
CSC509 Lecture 03
javiergs
PRO
0
140
Hi, have you met Kotlin Multiplatform? | DevFest Vienna 2024
prof18
0
180
2024-10-01 dev2next - Observability for Modern JVM Applications
jonatan_ivanov
0
140
Integrating AI in Your Enterprise Java Applications
ivargrimstad
0
320
色んなオートローダーを覗き見る #phpcon_okinawa
o0h
PRO
5
410
pytest プラグインを開発して DRY に自動テストを書こう
inuatsu
2
260
ML-прайсинг_на_Lamoda__вошли_и_вышли__приключение_на_20_минут__Слава_Цыганков.pdf
lamodatech
0
220
Pydantic x Database API:turu-pyの開発
yassun7010
1
730
(Deep|Web) Link support with expo-router
mrtry
0
180
Compose Multiplatform과 Ktor로 플랫폼의 경계를 넘어보자
kwakeuijin
0
280
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
11
1.5k
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
46
2k
KATA
mclloyd
28
13k
Become a Pro
speakerdeck
PRO
24
4.9k
4 Signs Your Business is Dying
shpigford
180
21k
What's in a price? How to price your products and services
michaelherold
243
11k
Building Applications with DynamoDB
mza
90
6k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
225
22k
A designer walks into a library…
pauljervisheath
202
24k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Building an army of robots
kneath
302
42k
Ruby is Unlike a Banana
tanoku
96
11k
Transcript
Elixir, MIDI & LiveView
@thibaut_barrere Consultant Ruby / Elixir / Ansible Kiba ETL /
Kiba Pro Remote 100% (Charente Maritime)
Elixir => Code-Centric Digital Audio Workstation? infiniwip (tm)
Previous episode https://github.com/thbar/demo-elixir-reloading-music Code.eval_file("music.exs")
MIDI
Note On {0x90 + channel, note, velocity} Note Off {0x80
+ channel, note, release_velocity}
Keyboard / Piano / Synthetizers photo by Clavia
MIDI controllers photo by Novation
Virtual Instruments (on computer)
Virtual Instruments (on iOS) photo by Korg
Lightning = Inter-Device Audio & MIDI (IDAM) photo by Apple
Elixir Code / DRY Refactoring Music Augmented Human (theory, scales)
Soft realtime
brew install portmidi
None
# Start a process for MIDI event queue {:ok, pid}
= PortMidi.open(:output, "Kontakt Virtual Input") note = 48 # C-4 velocity = 127 # Send "NOTE ON" PortMidi.write(pid, {0x90, note, velocity}) # Send "NOTE OFF" PortMidi.write(pid, {0x80, note})
None
Computer: Note 60 Human: WTF????
Translation def note_number_to_latin_name(midi_note, middle_c \\ @default_middle_c) do remap_note(midi_note, @latin_names, middle_c)
end defp remap_note(midi_note, names, middle_c) do offset = get_base_offset(middle_c) octave = div(midi_note + offset, 12) octave_note = rem(midi_note + offset, 12) octave_note = names |> Enum.at(octave_note) "#{octave_note}#{octave}" end defp get_base_offset("C4"), do: -12
DocTests ❤ ## Examples iex> MusicRef.note_number_to_latin_name(60) "Do4" iex> MusicRef.note_number_to_latin_name(78) "Fa#5"
Phoenix LiveView <div> <p> Time is <%= @time %> </p>
</div> HTML? ✔
Phoenix LiveView <svg> <%= for note <- notes do %>
<rect x="..." y="0" width="10" height="20" fill="<%= note.color %>"> <% end %> </svg> SVG? ✔
Phoenix LiveView <svg> <g> # white notes </g> <g> #
black notes </g> </svg>
None
None
def note_on({channel, note, velocity}, device, portmidi \\ PortMidi) do Phoenix.PubSub.broadcast(Widgets.PubSub,
"notes", {:note_on, note}) :ok = portmidi.write(device, {0x90 + channel, note, velocity}) end
None
Code & Demo