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
990
Kiba ETL v2 - RubyKaigi 2018
thbar
4
1.5k
Elixir hot-reloading & MIDI events generation
thbar
1
430
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
760
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
Kotlin 2.0が与えるAndroid開発の進化
masayukisuda
1
420
Developer Joy == Developer Productivity (really!)
hollycummins
1
220
いまから追い上げる、Jetpack Compose トレーニング
nyafunta9858
0
610
The Sequel to a Dream of Ruby Parser's Grammar
ydah
1
220
Prompt Cachingは本当に効果的なのか検証してみた.pdf
ttnyt8701
0
530
いつか使える ObjectSpace / Maybe useful ObjectSpace
euglena1215
2
140
The Shape of a Service Object
inem
0
530
あなたのアプリ、ログはでてますか?あるいはログをだしてますか? (Funabashi.dev用 軽量版)
uzulla
2
130
なぜアジャイルがうまくいかないのか?
yum3
1
100
LangChainの現在とv0.3にむけて
os1ma
4
940
Jakarta EE meets AI
ivargrimstad
0
390
[DroidKaigi 2024] Android ViewからJetpack Composeへ 〜Jetpack Compose移行のすゝめ〜 / From Android View to Jetpack Compose: A Guide to Migration
syarihu
1
680
Featured
See All Featured
Ruby is Unlike a Banana
tanoku
96
11k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Creatively Recalculating Your Daily Design Routine
revolveconf
215
12k
The Invisible Side of Design
smashingmag
296
50k
A better future with KSS
kneath
235
17k
Facilitating Awesome Meetings
lara
49
6k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
38
9.2k
The Cost Of JavaScript in 2023
addyosmani
42
5.7k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
190
16k
The Straight Up "How To Draw Better" Workshop
denniskardys
230
130k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
103
48k
Imperfection Machines: The Place of Print at Facebook
scottboms
263
13k
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