aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Wittig <michael.wittig@fu-berlin.de>2010-10-14 15:59:37 +0200
committerMichael Wittig <michael.wittig@fu-berlin.de>2010-10-14 15:59:37 +0200
commit4ce4e290a0557e616650ddb004f70cff2082e757 (patch)
treeb770d679c0f83f6c2b14b6fc4aea99f1d1a81520
parentbe34a99dbb4e516d7592d6a19d0c662b6d81ab17 (diff)
downloaderlang-4ce4e290a0557e616650ddb004f70cff2082e757.tar.gz
erlang-4ce4e290a0557e616650ddb004f70cff2082e757.tar.xz
erlang-4ce4e290a0557e616650ddb004f70cff2082e757.zip
next one
-rw-r--r--server/media.erl22
1 files changed, 16 insertions, 6 deletions
diff --git a/server/media.erl b/server/media.erl
index 561a2c7..165338b 100644
--- a/server/media.erl
+++ b/server/media.erl
@@ -55,7 +55,11 @@ insert(Artist, Title, Filepath) ->
end,
mnesia:transaction(F).
-% search the track with the highest votes and return {Artist, Title}
+% Of course we need a query to find out whats actually the most wished for track.
+% We will do it by requesting all the records from the database and then iteramte over just taking a look at the vote
+% variable, so it is like list of integers. In case no tracks were voted for we just take the first track we find and play it.
+% Of course it is locked afterwards so another will be choosen.
+
search_best([Head|Rest], Max_Votes, Track) ->
if
@@ -107,11 +111,7 @@ play(Artist, Title) ->
{Port, {exit_status, 0}} -> start_playing();
{Port, {exit_status, S}} -> throw({commandfailed, S})
end.
-
-
-% Of course we need a query to find out whats actually the most wished for track.
-% We will do it by requesting all the records from the database and then iteramte over just taking a look at the vote
-% variable, so it is like list of integers. In case no tracks were voted for we just take the first track we find and play it. Of course it is locked afterwards so another will be choosen.
+%Increase the vote in the database so it will hopefully be played in the future
vote(Artist, Title) ->
F = fun() ->
@@ -122,6 +122,8 @@ vote(Artist, Title) ->
end,
mnesia:transaction(F).
+% decrease votes in database
+
devote(Artist, Title) ->
F = fun() ->
[Head|_] = ask(Artist, Title),
@@ -131,6 +133,8 @@ devote(Artist, Title) ->
end,
mnesia:transaction(F).
+% Reset votes to zero in database
+
reset_votes(Artist, Title) ->
F = fun() ->
[Head|_] = ask(Artist, Title),
@@ -139,6 +143,7 @@ reset_votes(Artist, Title) ->
end,
mnesia:transaction(F).
+% Lock a song
lock(Artist, Title) ->
F = fun() ->
@@ -148,6 +153,8 @@ lock(Artist, Title) ->
end,
mnesia:transaction(F).
+% Unlock a song...
+
unlock(Artist, Title) ->
F = fun() ->
[Head|_] = ask(Artist, Title),
@@ -156,6 +163,9 @@ unlock(Artist, Title) ->
end,
mnesia:transaction(F).
+% Lock a song if it was just played, after a Timeout it will be unlocked automaticly
+% If all songs are locked, all will be unlocked.
+
lock_process(Artist, Title) ->
lock(Artist, Title),
receive