changeset 181:879b2488340a

Clean up player logic some more.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 06 Oct 2012 13:24:50 +0300
parents bc8019c38ba5
children 9024d249e47a
files jssplr.c
diffstat 1 files changed, 25 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/jssplr.c	Sat Oct 06 12:51:20 2012 +0300
+++ b/jssplr.c	Sat Oct 06 13:24:50 2012 +0300
@@ -550,6 +550,24 @@
 
 /* Starts playing module from a given ORDER.
  */
+static int jmpPlayStart(JSSPlayer *mp)
+{
+    int result;
+
+    mp->speed = mp->module->defSpeed;
+    jmpSetTempo(mp, mp->module->defTempo);
+
+    result = jvmSetCallback(mp->device, jmpExec, (void *) mp);
+    if (result != DMERR_OK)
+    {
+        JSSERROR(result, result, "Could not initialize callback for player.\n");
+    }
+
+    mp->isPlaying = TRUE;
+    return DMERR_OK;
+}
+
+
 int jmpPlayOrder(JSSPlayer * mp, int order)
 {
     int result;
@@ -561,19 +579,10 @@
     // Stop if already playing
     jmpStop(mp);
     jmpClearChannels(mp);
+    jmpClearPlayer(mp);
 
     // Check starting order
-    if (order < 0 || order >= mp->module->norders)
-    {
-        JSS_UNLOCK(mp);
-        JSSERROR(DMERR_INVALID_ARGS, DMERR_INVALID_ARGS, "Invalid playing startorder given.\n");
-    }
-
-    // Initialize playing
-    jmpClearPlayer(mp);
-
     jmpSetNewOrder(mp, order);
-
     if (mp->order == jsetNotSet)
     {
         JSS_UNLOCK(mp);
@@ -581,19 +590,12 @@
              "Could not start playing from given order #%i\n", order);
     }
 
-    mp->speed = mp->module->defSpeed;
-    jmpSetTempo(mp, mp->module->defTempo);
-
-    // Set callback
-    result = jvmSetCallback(mp->device, jmpExec, (void *) mp);
-    if (result != DMERR_OK)
+    if ((result = jmpPlayStart(mp)) != DMERR_OK)
     {
         JSS_UNLOCK(mp);
-        JSSERROR(result, result, "Could not initialize callback for player.\n");
+        return result;
     }
 
-    mp->isPlaying = TRUE;
-
     if (mp->future != NULL)
     {
         jmpPlayOrder(mp->future, order);
@@ -601,7 +603,7 @@
     }
 
     JSS_UNLOCK(mp);
-    return 0;
+    return DMERR_OK;
 }
 
 
@@ -616,25 +618,16 @@
 
     // Stop if already playing
     jmpStop(mp);
-    jmpClearChannels(mp);
-
-    // Initialize playing
     jmpClearPlayer(mp);
 
     mp->npattern = pattern;
-    mp->speed = mp->module->defSpeed;
-    jmpSetTempo(mp, mp->module->defTempo);
 
-    // Set callback
-    result = jvmSetCallback(mp->device, jmpExec, (void *) mp);
-    if (result != DMERR_OK)
+    if ((result = jmpPlayStart(mp)) != DMERR_OK)
     {
         JSS_UNLOCK(mp);
-        JSSERROR(result, result, "Could not initialize callback for player.\n");
+        return result;
     }
 
-    mp->isPlaying = TRUE;
-
     if (mp->future != NULL)
     {
         jmpPlayPattern(mp->future, pattern);
@@ -642,7 +635,7 @@
     }
 
     JSS_UNLOCK(mp);
-    return 0;
+    return DMERR_OK;
 }