From 2abd89ef6bab5474e80f4037dfa65a610aee111c Mon Sep 17 00:00:00 2001 From: Michael Wittig Date: Thu, 14 Oct 2010 15:03:36 +0200 Subject: ehm ka --- server/media.erl | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/server/media.erl b/server/media.erl index b3b8e0f..c732107 100644 --- a/server/media.erl +++ b/server/media.erl @@ -91,14 +91,9 @@ play(Artist, Title, Callback) -> [Head|_] = ask(Artist, Title), {_, Title, Artist, _, _, Fp} = Head, Port = erlang:open_port({spawn_executable, "/usr/bin/mplayer"}, [{args, [Fp]}, exit_status]), - - % lock the song - F = fun() -> - New = Head#track{locked = 1}, - mnesia:write(New) - end, - mnesia:transaction(F), - + reset_votes(Artist, Title), + lock_process(Artist, Title), + io:format("playing: ~s, Artist: ~s~n", [Title, Artist]), receive {Port, {exit_status, 0}} -> start_playing(); -- cgit v1.2.3 From 6fec8b2bbfbd5ff9e4bf031cc8f110af262fe8dd Mon Sep 17 00:00:00 2001 From: Marco Ziener Date: Thu, 14 Oct 2010 15:13:12 +0200 Subject: Improvements --- server/cldb.erl | 12 ++++++++++++ server/media.erl | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 server/cldb.erl diff --git a/server/cldb.erl b/server/cldb.erl new file mode 100644 index 0000000..23eecff --- /dev/null +++ b/server/cldb.erl @@ -0,0 +1,12 @@ +% The clientdatabase + +-module(cldb). +-export([init/0]). +-record(user, {name, passwd, votes}). + +init() -> + mnesia:create_schema[node()], + mnesia:start(), + mnesia:create_table(track, [{attributes, record_info(fields, track)}]), + io:format("Userdb up and running \n"). + diff --git a/server/media.erl b/server/media.erl index c732107..9b58067 100644 --- a/server/media.erl +++ b/server/media.erl @@ -43,7 +43,7 @@ read_files([],Total,Fail) -> io:format("Total: ~w, Failed: ~w~n", [Total, Fail]) start_playing() -> {Artist, Title} = search_best(media:all(), 0,0), - play(Artist, Title, "muh"). + play(Artist, Title). % Basic insertion of entrys into the database. Some entries are left out because they are 0 or false. @@ -87,7 +87,7 @@ all() -> % In practice we are going to set their locked variable to true and spawn a process which will unlock them after a certain time. % Well this could be considered abuse. -play(Artist, Title, Callback) -> +play(Artist, Title) -> [Head|_] = ask(Artist, Title), {_, Title, Artist, _, _, Fp} = Head, Port = erlang:open_port({spawn_executable, "/usr/bin/mplayer"}, [{args, [Fp]}, exit_status]), -- cgit v1.2.3 From c0e5424a41d4f2a784bbc9ad01e12e1ff0df738d Mon Sep 17 00:00:00 2001 From: Jakob Pfender Date: Thu, 14 Oct 2010 15:16:38 +0200 Subject: minor bracket fix --- server/cldb.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/cldb.erl b/server/cldb.erl index 23eecff..0f9f407 100644 --- a/server/cldb.erl +++ b/server/cldb.erl @@ -5,7 +5,7 @@ -record(user, {name, passwd, votes}). init() -> - mnesia:create_schema[node()], + mnesia:create_schema([node()]), mnesia:start(), mnesia:create_table(track, [{attributes, record_info(fields, track)}]), io:format("Userdb up and running \n"). -- cgit v1.2.3 From ee91bed1f6d4eb661628811b786c3b7ad2ff11cd Mon Sep 17 00:00:00 2001 From: Marco Ziener Date: Thu, 14 Oct 2010 15:21:25 +0200 Subject: Fixed errors --- server/media.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/media.erl b/server/media.erl index 9b58067..7c08caa 100644 --- a/server/media.erl +++ b/server/media.erl @@ -135,7 +135,7 @@ reset_votes(Artist, Title) -> lock(Artist, Title) -> F = fun() -> [Head|_] = ask(Artist, Title), - Votes = Head#track.votes - 1, + Votes = Head#track.lock = true, New = Head#track{votes = Votes}, mnesia:write(New) end, @@ -144,7 +144,7 @@ lock(Artist, Title) -> unlock(Artist, Title) -> F = fun() -> [Head|_] = ask(Artist, Title), - Votes = Head#track.votes -1, + Votes = Head#track.lock = false, New = Head#track{votes = Votes}, mnesia:write(New) end, -- cgit v1.2.3 From 6fbd6d9be211e1dae9a4ba003cefb2eb34c05c4c Mon Sep 17 00:00:00 2001 From: Marco Ziener Date: Thu, 14 Oct 2010 15:23:29 +0200 Subject: Fixed errors --- server/media.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/media.erl b/server/media.erl index 7c08caa..10fed99 100644 --- a/server/media.erl +++ b/server/media.erl @@ -136,7 +136,7 @@ lock(Artist, Title) -> F = fun() -> [Head|_] = ask(Artist, Title), Votes = Head#track.lock = true, - New = Head#track{votes = Votes}, + New = Head#track{lock = Votes}, mnesia:write(New) end, mnesia:transaction(F). @@ -145,7 +145,7 @@ unlock(Artist, Title) -> F = fun() -> [Head|_] = ask(Artist, Title), Votes = Head#track.lock = false, - New = Head#track{votes = Votes}, + New = Head#track{lock = Votes}, mnesia:write(New) end, mnesia:transaction(F). -- cgit v1.2.3