Current section
6 Versions
Jump to
Current section
6 Versions
Compare versions
8
files changed
+81
additions
-56
deletions
| @@ -70,7 +70,7 @@ SuperCollider.response[:status] | |
| 70 70 | |
| 71 71 | # Send a command to play a basic 300Hz sinusoidal sound on node 100 |
| 72 72 | # This assumes the sine SynthGen is installed on the server |
| 73 | - SuperCollider.command(:s_new, ["sine", 100, 1, 1, ["freq", 300]]) |
| 73 | + SuperCollider.command(:s_new, ["sine", 100, 1, 0, ["freq", 300]]) |
| 74 74 | |
| 75 75 | # Stop the sound by freeing node 100 |
| 76 76 | SuperCollider.command(:n_free, 100) |
| @@ -95,17 +95,20 @@ The package can be installed by adding `supercollider` to your list of dependenc | |
| 95 95 | ```elixir |
| 96 96 | def deps do |
| 97 97 | [ |
| 98 | - {:supercollider, "~> 0.1.4"} |
| 98 | + {:supercollider, "~> 0.1.5"} |
| 99 99 | ] |
| 100 100 | end |
| 101 101 | ``` |
| 102 102 | |
| 103 103 | ### Using within LiveBook and IEx |
| 104 104 | ```elixir |
| 105 | - Mix.install([{:supercollider, "~> 0.1.4"}]) |
| 105 | + Mix.install([{:supercollider, "~> 0.1.5"}]) |
| 106 106 | ``` |
| 107 107 | |
| 108 | - Also see the interactive tour in LiveBook at [/livebook/supercollider_tour.livemd](https://github.com/haubie/supercollider/blob/main/livebook/supercollider_tour.livemd). |
| 108 | + #### LiveBook tour |
| 109 | + Also see the introductory tour in LiveBook at [/livebook/supercollider_tour.livemd](https://github.com/haubie/supercollider/blob/main/livebook/supercollider_tour.livemd). |
| 110 | + |
| 111 | + [](https://livebook.dev/run?url=https%3A%2F%2Fgithub.com%2Fhaubie%2Fsupercollider%2Fblob%2Fmain%2Flivebook%2Fsupercollider_tour.livemd) |
| 109 112 | |
| 110 113 | ## Documentation |
| 111 114 | The docs can be found at <https://hexdocs.pm/supercollider>. |
| \ No newline at end of file |
| @@ -1,8 +1,12 @@ | |
| 1 | - {<<"app">>,<<"supercollider">>}. |
| 2 | - {<<"build_tools">>,[<<"mix">>]}. |
| 1 | + {<<"links">>, |
| 2 | + [{<<"GitHub">>,<<"https://github.com/haubie/supercollider">>}, |
| 3 | + {<<"SuperCollider (offical)">>,<<"https://supercollider.github.io/">>}]}. |
| 4 | + {<<"name">>,<<"supercollider">>}. |
| 5 | + {<<"version">>,<<"0.1.5">>}. |
| 3 6 | {<<"description">>, |
| 4 7 | <<"An Elixir library for interacting with SuperCollider, an audio synthesis and composition platform.">>}. |
| 5 8 | {<<"elixir">>,<<"~> 1.14">>}. |
| 9 | + {<<"app">>,<<"supercollider">>}. |
| 6 10 | {<<"files">>, |
| 7 11 | [<<"lib">>,<<"lib/supercollider">>,<<"lib/supercollider/synthdef">>, |
| 8 12 | <<"lib/supercollider/synthdef/encoder.ex">>, |
| @@ -15,12 +19,10 @@ | |
| 15 19 | <<"lib/supercollider/soundserver/command.ex">>,<<"lib/supercollider.ex">>, |
| 16 20 | <<"mix.exs">>,<<"README.md">>,<<"LICENSE">>]}. |
| 17 21 | {<<"licenses">>,[<<"MIT">>]}. |
| 18 | - {<<"links">>,[{<<"GitHub">>,<<"https://github.com/haubie/supercollider">>}]}. |
| 19 | - {<<"name">>,<<"supercollider">>}. |
| 20 22 | {<<"requirements">>, |
| 21 | - [[{<<"app">>,<<"osc">>}, |
| 22 | - {<<"name">>,<<"osc">>}, |
| 23 | + [[{<<"name">>,<<"oscx">>}, |
| 24 | + {<<"app">>,<<"oscx">>}, |
| 23 25 | {<<"optional">>,false}, |
| 24 | - {<<"repository">>,<<"hexpm">>}, |
| 25 | - {<<"requirement">>,<<"~> 0.1.2">>}]]}. |
| 26 | - {<<"version">>,<<"0.1.4">>}. |
| 26 | + {<<"requirement">>,<<"~> 0.1.0">>}, |
| 27 | + {<<"repository">>,<<"hexpm">>}]]}. |
| 28 | + {<<"build_tools">>,[<<"mix">>]}. |
| @@ -21,11 +21,15 @@ defmodule SuperCollider do | |
| 21 21 | SC.response(:version) # retrieves the version response from the SoundServer's state |
| 22 22 | |
| 23 23 | # Play a sine wave UGen on node 600, with a frequency of 300 |
| 24 | - SC.command(:s_new, ["sine", 600, 1, 1, ["freq", 300]]) |
| 24 | + SC.command(:s_new, ["sine", 600, 1, 0, ["freq", 300]]) |
| 25 25 | |
| 26 26 | # Stop the sine wave by freeing node 600 |
| 27 27 | SC.command(:n_free, 600) |
| 28 28 | ``` |
| 29 | + |
| 30 | + ## LiveBook tour |
| 31 | + You can explore this library further in the [LiveBook demo](https://livebook.dev/run?url=https%3A%2F%2Fgithub.com%2Fhaubie%2Fsupercollider%2Fblob%2Fmain%2Flivebook%2Fsupercollider_tour.livemd). |
| 32 | + [](https://livebook.dev/run?url=https%3A%2F%2Fgithub.com%2Fhaubie%2Fsupercollider%2Fblob%2Fmain%2Flivebook%2Fsupercollider_tour.livemd) |
| 29 33 | """ |
| 30 34 | |
| 31 35 | alias SuperCollider.SoundServer |
| @@ -191,7 +195,7 @@ defmodule SuperCollider do | |
| 191 195 | ## Examples |
| 192 196 | ``` |
| 193 197 | # Send a command to play a basic 300Hz sinusoidal sound on node 100 |
| 194 | - SuperCollider.command(:s_new, ["sine", 100, 1, 1, ["freq", 300]]) |
| 198 | + SuperCollider.command(:s_new, ["sine", 100, 1, 0, ["freq", 300]]) |
| 195 199 | |
| 196 200 | # Stop the sound by freeing node 100 |
| 197 201 | SuperCollider.command(:n_free, 100) |
| @@ -1,23 +1,4 @@ | |
| 1 1 | defmodule SuperCollider.SoundServer do |
| 2 | - use GenServer |
| 3 | - require Logger |
| 4 | - |
| 5 | - @server_type [ |
| 6 | - mac: [ |
| 7 | - scsynth: "/Applications/SuperCollider.app/Contents/Resources/scsynth", |
| 8 | - supernova: "/Applications/SuperCollider.app/Contents/Resources/supernova" |
| 9 | - ], |
| 10 | - unix: [ |
| 11 | - scsynth: "/usr/local/scsynth", |
| 12 | - supernova: "/usr/local/supernova" |
| 13 | - ], |
| 14 | - windows: [ |
| 15 | - scsynth: "\\Program Files\\SuperCollider\\sclang.exe", |
| 16 | - supernova: "\\Program Files\\SuperCollider\\supernova.exe" |
| 17 | - ] |
| 18 | - ] |
| 19 | - |
| 20 | - |
| 21 2 | @moduledoc """ |
| 22 3 | GenServer for communicating with scserver or supernova. |
| 23 4 | |
| @@ -65,6 +46,23 @@ defmodule SuperCollider.SoundServer do | |
| 65 46 | SoundServer.command(pid, :n_free, 600) |
| 66 47 | ``` |
| 67 48 | """ |
| 49 | + use GenServer |
| 50 | + require Logger |
| 51 | + |
| 52 | + @server_type [ |
| 53 | + mac: [ |
| 54 | + scsynth: "/Applications/SuperCollider.app/Contents/Resources/scsynth", |
| 55 | + supernova: "/Applications/SuperCollider.app/Contents/Resources/supernova" |
| 56 | + ], |
| 57 | + unix: [ |
| 58 | + scsynth: "/usr/local/scsynth", |
| 59 | + supernova: "/usr/local/supernova" |
| 60 | + ], |
| 61 | + windows: [ |
| 62 | + scsynth: "\\Program Files\\SuperCollider\\sclang.exe", |
| 63 | + supernova: "\\Program Files\\SuperCollider\\supernova.exe" |
| 64 | + ] |
| 65 | + ] |
| 68 66 | |
| 69 67 | alias SuperCollider.SoundServer |
| 70 68 | alias SuperCollider.SoundServer.Command, as: Command |
| @@ -98,7 +96,8 @@ defmodule SuperCollider.SoundServer do | |
| 98 96 | """ |
| 99 97 | @impl true |
| 100 98 | def init(soundserver \\ %__MODULE__{}) do |
| 101 | - IO.inspect(soundserver, label: "INIT") |
| 99 | + # IO.inspect(soundserver, label: "INIT") |
| 100 | + Logger.info("Initialising sound server with #{inspect(soundserver)}") |
| 102 101 | new_state = run(soundserver) |
| 103 102 | {:ok, new_state} |
| 104 103 | end |
| @@ -373,8 +372,10 @@ defmodule SuperCollider.SoundServer do | |
| 373 372 | |
| 374 373 | receive do |
| 375 374 | {:udp, _process_port, _ip_addr, _port_num, data} -> |
| 376 | - packet = data |> OSC.decode!() |
| 377 | - %{address: "/status.reply", arguments: _arguments} = packet.contents |> List.first() |
| 375 | + message = OSCx.decode(data) |
| 376 | + |
| 377 | + %{address: "/status.reply", arguments: _arguments} = if is_list(message), do: List.first(message), else: message |
| 378 | + |
| 378 379 | Logger.info("#{soundserver.type} - already booted ✅") |
| 379 380 | true |
| @@ -51,8 +51,8 @@ defmodule SuperCollider.SoundServer.Command do | |
| 51 51 | Mainly used by `send_osc/3` as a helper function. |
| 52 52 | """ |
| 53 53 | def encode_osc(address, arguments \\ []) do |
| 54 | - %OSC.Message{address: address, arguments: arguments} |
| 55 | - |> OSC.encode() |
| 54 | + %OSCx.Message{address: address, arguments: arguments} |
| 55 | + |> OSCx.encode() |
| 56 56 | end |
| 57 57 | |
| 58 58 | @doc section: :osc |
| @@ -64,7 +64,7 @@ defmodule SuperCollider.SoundServer.Command do | |
| 64 64 | This function makes use of the `encode_osc/3` and `send_to_sc/2` helper functions. |
| 65 65 | """ |
| 66 66 | def send_osc(soundserver, address, arguments \\ []) do |
| 67 | - {:ok, osc_data} = encode_osc(address, arguments) |
| 67 | + osc_data = encode_osc(address, arguments) |
| 68 68 | send_to_sc(soundserver, osc_data) |
| 69 69 | soundserver |
| 70 70 | end |
Loading more files…