Add tests for player and event.

This commit is contained in:
Pim Kunis 2020-10-11 18:15:16 +02:00
parent 362826eb2f
commit 2802e5fbf7
6 changed files with 85 additions and 16 deletions

View file

@ -11,8 +11,15 @@ defmodule MIDITools.Event do
defstruct channel: 0, tone: 0, start_time: 0, end_time: 0, velocity: 0
@spec new(MIDISynth.Command.channel(), non_neg_integer(), non_neg_integer(), non_neg_integer(), MIDISynth.Command.velocity()) :: %Note{}
def new(channel, tone, start_time, end_time, velocity) when start_time >= 0 and end_time > start_time do
@spec new(
MIDISynth.Command.channel(),
non_neg_integer(),
non_neg_integer(),
non_neg_integer(),
MIDISynth.Command.velocity()
) :: %Note{}
def new(channel, tone, start_time, end_time, velocity)
when start_time >= 0 and end_time > start_time do
%__MODULE__{
channel: channel,
tone: tone,
@ -30,7 +37,8 @@ defmodule MIDITools.Event do
defstruct channel: 0, time: 0, program: 0
@spec new(MIDISynth.Command.channel(), non_neg_integer(), non_neg_integer()) :: %ChangeProgram{}
@spec new(MIDISynth.Command.channel(), non_neg_integer(), non_neg_integer()) ::
%ChangeProgram{}
def new(channel, time, program) do
%__MODULE__{channel: channel, time: time, program: program}
end

View file

@ -66,7 +66,7 @@ defmodule MIDITools.Player do
@doc """
Resume playback on the player after it has been paused.
"""
@spec resume() :: :ok, {:error, :not_paused}
@spec(resume() :: :ok, {:error, :not_paused})
def resume do
GenServer.call(__MODULE__, :resume)
end
@ -100,15 +100,14 @@ defmodule MIDITools.Player do
start_time = Timex.now()
timer = start_timer(schedule, start_time)
{:reply, :ok,
%{reset(state) | timer: timer, start_time: start_time}}
{:reply, :ok, %{reset(state) | timer: timer, start_time: start_time}}
end
def handle_call({:set_repeat, repeat}, _from, state) do
{:reply, :ok, %{state | repeat: repeat}}
end
def handle_call(:stop_playing, _from, state) do
def handle_call(:stop_playing, _from, state) do
{:reply, :ok, reset(state)}
end