Commit e29f48c4 authored by Jens-Christian Fischer's avatar Jens-Christian Fischer
Browse files

First autonmous version

sends regular information to the OSC channel, collects all performance
data from all players etc
parent 89c35d77
......@@ -8,12 +8,3 @@ config :grains, Grains.Endpoint,
# Print only warnings and errors during test
config :logger, level: :warn
# Configure your database
config :grains, Grains.Repo,
adapter: Ecto.Adapters.Postgres,
username: "postgres",
password: "postgres",
database: "grains_test",
hostname: "localhost",
pool: Ecto.Adapters.SQL.Sandbox
......@@ -14,6 +14,7 @@ defmodule Grains do
# worker(Grains.Worker, [arg1, arg2, arg3]),
worker(Grains.Concounter, [0]),
worker(Grains.StatefulMap, []),
worker(Grains.Beat, [60]),
supervisor(Grains.Presence, []),
]
......
defmodule Grains.Beat do
use GenServer
@minute 60_000
def start_link(bpm), do: GenServer.start_link(__MODULE__, bpm, name: __MODULE__)
def set_bpm(bpm), do: GenServer.cast(__MODULE__, {:set_bpm, bpm})
def init(bpm) do
millisec = round(@minute / bpm)
tick(millisec)
{:ok, millisec}
end
defp tick(millisec), do: Process.send_after(self(), :tick, millisec)
def handle_cast({:set_bpm, bpm}, state) do
{:noreply, round(@minute / bpm) }
end
def handle_info(:tick, state) do
Grengine.Conductor.perform()
|> send_values
tick(state)
{:noreply, state}
end
def send_values(values) do
Grains.Endpoint.broadcast("osc", "performance", values)
end
def handle_info(_, state), do: {:noreply, state}
end
......@@ -3,7 +3,7 @@ defmodule Grains.Mixfile do
def project do
[app: :grains,
version: "0.0.30",
version: "0.0.31",
elixir: "~> 1.2",
elixirc_paths: elixirc_paths(Mix.env),
compilers: [:phoenix, :gettext] ++ Mix.compilers,
......@@ -18,7 +18,10 @@ defmodule Grains.Mixfile do
def application do
[mod: {Grains, []},
applications: [:phoenix, :phoenix_pubsub, :phoenix_html, :cowboy, :logger, :gettext,
:logger_file_backend, :uuid]]
:logger_file_backend, :uuid,
:grengine
]
]
end
# Specifies which paths to compile per environment.
......@@ -31,15 +34,16 @@ defmodule Grains.Mixfile do
defp deps do
[{:phoenix, "~> 1.2.1"},
{:phoenix_pubsub, "~> 1.0"},
# {:phoenix_ecto, "~> 3.0"},
# {:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 2.6"},
{:phoenix_live_reload, "~> 1.0", only: :dev},
{:mix_test_watch, "~> 0.3", only: :dev, runtime: false},
{:gettext, "~> 0.11"},
{:cowboy, "~> 1.0"},
{ :uuid, "~> 1.1" },
{:uuid, "~> 1.1" },
{:logger_file_backend, "~> 0.0.8"},
{:distillery, "~>1.2.2"}]
{:distillery, "~>1.2.2"},
{:grengine, git: "git@gitlab.switch.ch:grains/grengine.git"}
]
end
end
......@@ -9,18 +9,21 @@
"ecto": {:hex, :ecto, "2.1.4", "d1ba932813ec0e0d9db481ef2c17777f1cefb11fc90fa7c142ff354972dfba7e", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, optional: true]}]},
"erlware_commons": {:hex, :erlware_commons, "0.13.0", "b86d493f3c3e52acba16f0a78900c12525e9eb46db3450b0d25b419aa8221115", [:rebar], []},
"exrm": {:hex, :exrm, "0.18.8", "8bc43a5da2cd54eb18fdffc6bb1608424f3897f97e816bcf752fb931c0ef1af4", [:mix], [{:conform, "~> 0.16.0", [hex: :conform, optional: false]}, {:relx, "~> 3.1.0", [hex: :relx, optional: false]}]},
"fs": {:hex, :fs, "0.9.2", "ed17036c26c3f70ac49781ed9220a50c36775c6ca2cf8182d123b6566e49ec59", [:rebar], []},
"fs": {:hex, :fs, "2.12.0", "ad631efacc9a5683c8eaa1b274e24fa64a1b8eb30747e9595b93bec7e492e25e", [:rebar3], []},
"getopt": {:hex, :getopt, "0.8.2", "b17556db683000ba50370b16c0619df1337e7af7ecbf7d64fbf8d1d6bce3109b", [:rebar], []},
"gettext": {:hex, :gettext, "0.13.1", "5e0daf4e7636d771c4c71ad5f3f53ba09a9ae5c250e1ab9c42ba9edccc476263", [:mix], []},
"gproc": {:hex, :gproc, "0.3.1", "ec14f40cb941bde3f940de59c11e59beb2977e90dbae72fab3ddf77743fd4ea9", [:rebar], []},
"grengine": {:git, "git@gitlab.switch.ch:grains/grengine.git", "5da595c1112981f7da7cfcf163cbffac07e28607", []},
"logger_file_backend": {:hex, :logger_file_backend, "0.0.9", "5c2f7d4a28431e695cdf94d191523dbafe609321a67bb654254897f546c393db", [:mix], []},
"mime": {:hex, :mime, "1.1.0", "01c1d6f4083d8aa5c7b8c246ade95139620ef8effb009edde934e0ec3b28090a", [:mix], []},
"mix_test_watch": {:hex, :mix_test_watch, "0.4.0", "7e44b681b0238999d4c39b5beed77b4ac45aef1c112a763aae414bdb5bc34523", [:mix], [{:fs, "~> 2.12", [hex: :fs, optional: false]}]},
"neotoma": {:hex, :neotoma, "1.7.3", "d8bd5404b73273989946e4f4f6d529e5c2088f5fa1ca790b4dbe81f4be408e61", [:rebar], []},
"phoenix": {:hex, :phoenix, "1.2.1", "6dc592249ab73c67575769765b66ad164ad25d83defa3492dc6ae269bd2a68ab", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, optional: true]}, {:phoenix_pubsub, "~> 1.0", [hex: :phoenix_pubsub, optional: false]}, {:plug, "~> 1.1", [hex: :plug, optional: false]}, {:poison, "~> 1.5 or ~> 2.0", [hex: :poison, optional: false]}]},
"phoenix": {:hex, :phoenix, "1.2.3", "b68dd6a7e6ff3eef38ad59771007d2f3f344988ea6e658e9b2c6ffb2ef494810", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, optional: true]}, {:phoenix_pubsub, "~> 1.0", [hex: :phoenix_pubsub, optional: false]}, {:plug, "~> 1.4 or ~> 1.3.3 or ~> 1.2.4 or ~> 1.1.8 or ~> 1.0.5", [hex: :plug, optional: false]}, {:poison, "~> 1.5 or ~> 2.0", [hex: :poison, optional: false]}]},
"phoenix_ecto": {:hex, :phoenix_ecto, "3.2.2", "2e51c57614528b130d54019e78349f83a5b5d53b3b2ef775dbc30df7e1fecb45", [:mix], [{:ecto, "~> 2.1", [hex: :ecto, optional: false]}, {:phoenix_html, "~> 2.9", [hex: :phoenix_html, optional: false]}, {:plug, "~> 1.0", [hex: :plug, optional: false]}]},
"phoenix_html": {:hex, :phoenix_html, "2.9.3", "1b5a2122cbf743aa242f54dced8a4f1cc778b8bd304f4b4c0043a6250c58e258", [:mix], [{:plug, "~> 1.0", [hex: :plug, optional: false]}]},
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.0.8", "4333f9c74190f485a74866beff2f9304f069d53f047f5fbb0fb8d1ee4c495f73", [:mix], [{:fs, "~> 0.9.1", [hex: :fs, optional: false]}, {:phoenix, "~> 1.0 or ~> 1.2-rc", [hex: :phoenix, optional: false]}]},
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.0.7", "167ab0942e88d1d4a597996cf7dd8d2b014cc14d3f9472b58858cde8dd9ac2e4", [:mix], [{:fs, "~> 2.12.0", [hex: :fs, optional: false]}, {:phoenix, "~> 1.0 or ~> 1.2-rc", [hex: :phoenix, optional: false]}]},
"phoenix_pubsub": {:hex, :phoenix_pubsub, "1.0.1", "c10ddf6237007c804bf2b8f3c4d5b99009b42eca3a0dfac04ea2d8001186056a", [:mix], []},
"plug": {:hex, :plug, "1.3.3", "d9be189924379b4e9d470caef87380d09549aea1ceafe6a0d41292c8c317c923", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1", [hex: :cowboy, optional: true]}, {:mime, "~> 1.0", [hex: :mime, optional: false]}]},
"plug": {:hex, :plug, "1.3.5", "7503bfcd7091df2a9761ef8cecea666d1f2cc454cbbaf0afa0b6e259203b7031", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1", [hex: :cowboy, optional: true]}, {:mime, "~> 1.0", [hex: :mime, optional: false]}]},
"poison": {:hex, :poison, "2.2.0", "4763b69a8a77bd77d26f477d196428b741261a761257ff1cf92753a0d4d24a63", [:mix], []},
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], []},
"postgrex": {:hex, :postgrex, "0.13.2", "2b88168fc6a5456a27bfb54ccf0ba4025d274841a7a3af5e5deb1b755d95154e", [:mix], [{:connection, "~> 1.0", [hex: :connection, optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}]},
......
......@@ -3,6 +3,6 @@ defmodule Grains.PageControllerTest do
test "GET /", %{conn: conn} do
conn = get conn, "/"
assert html_response(conn, 200) =~ "Welcome to Phoenix!"
assert html_response(conn, 200) =~ "Welcome to Grains!"
end
end
ExUnit.start
Ecto.Adapters.SQL.Sandbox.mode(Grains.Repo, :manual)
......@@ -11,28 +11,30 @@ defmodule Grains.OrientationChannel do
values = StatefulMap.values()
Logger.info(inspect(values))
resp = %{values: Phoenix.View.render_many(values, ValueView, "value.json") }
resp = %{values: []}
{:ok, resp, socket}
end
def handle_in("orientation", params, socket) do
Logger.info("orientations #{inspect(params)}")
uuid = socket.assigns.user_uuid
pitch = params["pitch"]
roll = params["roll"]
yaw = params["yaw"]
heading = params["heading"]
StatefulMap.put("pitch", pitch)
StatefulMap.put("roll", roll)
StatefulMap.put("yaw", yaw)
StatefulMap.put("heading", heading)
Grains.Endpoint.broadcast("osc", "orientation", %{user: socket.assigns.user_uuid,
pitch: pitch,
roll: roll,
yaw: yaw})
Grengine.Performance.set_values(uuid, %{
pitch: pitch,
roll: roll,
yaw: yaw,
heading: heading
} )
# Grains.Endpoint.broadcast("osc", "orientation", %{user: socket.assigns.user_uuid,
# pitch: pitch,
# roll: roll,
# yaw: yaw})
{:reply, :ok, socket}
......
......@@ -10,6 +10,11 @@ defmodule Grains.PresenceChannel do
def handle_info(:after_join, socket) do
IO.puts("handle_join: #{socket.assigns.user_uuid}")
Grengine.PerformanceSupervisor.start_performance(socket.assigns.user_uuid)
Grains.Endpoint.broadcast("osc", "presence", %{user: socket.assigns.user_uuid,
joins: true})
Presence.track(socket, socket.assigns.user_uuid, %{
online_at: :os.system_time(:milli_seconds)
......
defmodule Grains.SliderChannel do
use Grains.Web, :channel
alias Grains.StatefulMap
alias Grains.ValueView
def join("slider:" <> slider_id, _params, socket) do
values = StatefulMap.values()
resp = %{values: Phoenix.View.render_many(values, ValueView, "value.json") }
{:ok, resp, socket}
# resp = %{values: Phoenix.View.render_many({}, ValueView, "value.json") }
{:ok, %{values: []}, socket}
end
def handle_in("slider", params, socket) do
......@@ -16,12 +14,12 @@ defmodule Grains.SliderChannel do
IO.puts "slider: #{params["slider"]} : #{params["value"]}"
slider = params["slider"]
value = params["value"]
uuid = socket.assigns.user_uuid
StatefulMap.put(slider, value)
Grains.Endpoint.broadcast("osc", "slider", %{user: socket.assigns.user_uuid,
element: slider,
value: value})
Grengine.Performance.set_values(uuid, %{slider => value })
# Grains.Endpoint.broadcast("osc", "slider", %{user: socket.assigns.user_uuid,
# element: slider,
# value: value})
{:reply, :ok, socket}
......
......@@ -36,7 +36,12 @@ let OrientationPanel = {
console.log("adding orientation");
this.orientation = new Interface.Orientation({
onvaluechange: function(pitch, roll, yaw, heading) {
that.send_value([pitch, roll, yaw, heading]);
that.sliders['pitch'].setValue(pitch);
that.sliders['roll'].setValue(roll);
that.sliders['yaw'].setValue(yaw);
that.sliders['heading'].setValue(heading);
that.send_value([pitch, roll, yaw, heading]);
}
}).start();
......@@ -62,7 +67,7 @@ let OrientationPanel = {
return parseInt(i * 127);
});
if (!_.isEqual(scaled, this.old_values)) {
console.log(scaled);
// console.log(scaled);
let payload = {pitch: scaled[0],
roll: scaled[1],
yaw: scaled[2],
......
......@@ -14,7 +14,7 @@
<body>
<div class="container">
<header class="header">
<h1>Welcome to Grains</h1>
<img src="/images/switch.png" alt="SWITCH" height="46" width="180" />
</header>
<p class="alert alert-info" role="alert"><%= get_flash(@conn, :info) %></p>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment