From 75ae830ef228763f5206eb380f2fa74b536fcf58 Mon Sep 17 00:00:00 2001 From: bjschuma Date: Mon, 8 Feb 2010 10:07:45 -0500 Subject: [PATCH] Began work on random playback --- src/core/ct/db.py | 6 ++-- src/core/ct/gstreamer.py | 4 ++- src/core/music.py | 2 ++ src/core/next.py | 16 ++++++--- src/extra/__init__.py | 5 --- src/extra/guiOGTK/__init__.py | 5 --- src/extra/guiOGTK/listPage.py | 46 ------------------------ src/extra/ogtk.py | 59 ------------------------------ src/extra/rand.py | 67 ++++++++++++++--------------------- src/ocarina | 4 +-- 10 files changed, 48 insertions(+), 166 deletions(-) delete mode 100644 src/extra/__init__.py delete mode 100644 src/extra/guiOGTK/__init__.py delete mode 100644 src/extra/guiOGTK/listPage.py delete mode 100644 src/extra/ogtk.py diff --git a/src/core/ct/db.py b/src/core/ct/db.py index 053ae060..a1effa2c 100644 --- a/src/core/ct/db.py +++ b/src/core/ct/db.py @@ -139,7 +139,7 @@ def listlib(): write("Current: "+curname) -def getpath(dbid, curtrk): +def getpath(dbid): curlib = str( settings.get("curlib") ) selr = sql.Select("path","library","id="+curlib) @@ -147,6 +147,4 @@ def getpath(dbid, curtrk): selt = sql.Select("path","track","id="+str(dbid)) track = selt.execute().fetchone()[0] -# write(root) -# write(track) - write(root+track) \ No newline at end of file + return root+track \ No newline at end of file diff --git a/src/core/ct/gstreamer.py b/src/core/ct/gstreamer.py index 3fc1f39f..47adce41 100644 --- a/src/core/ct/gstreamer.py +++ b/src/core/ct/gstreamer.py @@ -63,4 +63,6 @@ def init(): def close(): global pipeline if not pipeline == None: - pipeline.set_state(gst.STATE_NULL) \ No newline at end of file + pause() + pipeline.set_state(gst.STATE_NULL) + pipeline = None \ No newline at end of file diff --git a/src/core/music.py b/src/core/music.py index d9cc7187..41631686 100644 --- a/src/core/music.py +++ b/src/core/music.py @@ -23,6 +23,8 @@ class Plugin(plugin.Plugin): write("Usage: music load track") join = ' ' path = join.join(args) + write("Loading: "+path) + gstreamer.close() gstreamer.load(path) diff --git a/src/core/next.py b/src/core/next.py index 1e8b82e9..3f046c94 100644 --- a/src/core/next.py +++ b/src/core/next.py @@ -11,7 +11,7 @@ from bt import sql from ct import db import settings -from manager import run +import manager class Plugin(plugin.Plugin): @@ -44,16 +44,24 @@ class Plugin(plugin.Plugin): sel = sql.Select("track","libtrack","library="+str(curlib)) rows = sel.execute().fetchall() - run("next",[rows[nxttrk][0], nxttrk]) + manager.run("next",[rows[nxttrk][0], nxttrk]) def run(self, args=None): + # args[0] : database track ID + # args[1] : new current track number + if args==None or len(args)==0: signal.emit("next") return elif len(args) == 1: write("Usage:" + self.usage) - # db ID, list index - path = db.getpath(args[0],args[1]) + + path = db.getpath(args[0]) + + settings.set("curtrk",args[1]) + manager.run("music",["load",path]) + manager.run("music",["play"]) + diff --git a/src/extra/__init__.py b/src/extra/__init__.py deleted file mode 100644 index ad9abe4c..00000000 --- a/src/extra/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -__author__="bjschuma" -__date__ ="$Jan 9, 2010 8:07:29 PM$" - - -__all__ = ["rand"] \ No newline at end of file diff --git a/src/extra/guiOGTK/__init__.py b/src/extra/guiOGTK/__init__.py deleted file mode 100644 index 61249cf3..00000000 --- a/src/extra/guiOGTK/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -__author__="bjschuma" -__date__ ="$Jan 16, 2010 12:46:48 PM$" - - -__all__ = ["listPage"] \ No newline at end of file diff --git a/src/extra/guiOGTK/listPage.py b/src/extra/guiOGTK/listPage.py deleted file mode 100644 index ba21a40c..00000000 --- a/src/extra/guiOGTK/listPage.py +++ /dev/null @@ -1,46 +0,0 @@ -#! /usr/bin/python - -# To change this template, choose Tools | Templates -# and open the template in the editor. - -__author__="bjschuma" -__date__ ="$Jan 16, 2010 12:47:28 PM$" - -import gtk -from guiGTK import * -from bt.message import * - - -from tools import database - -def library(): - select = "track.name, artist.name, album.name" - frm = "track,artist,album" - where = "track.artist=artist.id AND track.album=album.id" - return database.select(select,frm,where).fetchall() - - -class ListPage(box.VBox): - def __init__(self,name): - box.VBox.__init__(self) - self.labelText = name - self.label = label.Label(self.labelText) - self.label.rotate(90) - self.list = list.List(gtk.ListStore(str,str,str), ["Title", "Artist", "Album"]) - self.list.rules(True) - self.pack(self.list,True,True) - if name == "Library": - self.fromLibrary() - self.setLabel() - - - def fromLibrary(self): - for track in library(): - self.list.insert(track) - - - def setLabel(self): - text = self.labelText + " (" - text += str( self.list.count() ) - text += ")" - self.label.change(text) \ No newline at end of file diff --git a/src/extra/ogtk.py b/src/extra/ogtk.py deleted file mode 100644 index c804b9eb..00000000 --- a/src/extra/ogtk.py +++ /dev/null @@ -1,59 +0,0 @@ -# This is a simple test plugin, to make sure everything is working - -__author__="bjschuma" -__date__ ="$Jan 16, 2010 12:18:10 PM$" - - -global name, app, type, path, opt -name = "test" -app = "scion" -type = "extra" -path = "" -opt = [] - -from bt.message import write -from manager import manager -import settings -from guiGTK import * -from guiOGTK import * - - -global window -global vbox -global bar -global tabs - - -# Called when the plugin needs to perform some action -def run(args): - if args == None: - manager.run("sgtk") - else: - global window, vbox, bar, tabs - window = args[0] - vbox = args[1] - bar = args[2] - window.resize(settings.get("winsize")) - tabs = tabs.Tabs() - vbox.pack(tabs,True,True) - library = listPage.ListPage("Library") - tabs.append(library,library.label) - tabs.tabpos("left") - - - -# Called every time the plugin is enabled -def open(): - # Enable scion GTK when we are enabled - manager.run("enable", ["sgtk"]) - settings.set("gtkfuncs",run) - settings.set("winsize",(800,600)) - - -# Called every time the plugin is stopped -def close(): - pass - - -def help(): - return "Ocarina GTK functions" diff --git a/src/extra/rand.py b/src/extra/rand.py index 08bf93a7..fa22faad 100644 --- a/src/extra/rand.py +++ b/src/extra/rand.py @@ -1,55 +1,42 @@ -# This is a simple test plugin, to make sure everything is working +# Basic plugin class __author__="bjschuma" -__date__ ="$Jan 2, 2010 1:14:04 PM$" +__date__ ="$Feb 8, 2010 10:00:40 AM$" -global name, app, type, path, opt -name = "rand" -app = "ocarina" -type = "extra" -path = "" -opt = [] - +from bt import plugin from bt.message import write -from tools import database -import random import settings +from bt import signal -def randnext(): - cur = str(settings.get("curlib")) - count = database.select("count(*)","libtrack","library="+cur).fetchone()[0] - id = random.randint(0,count) - rows = database.select("track","libtrack","library="+cur).fetchall() - id = rows[id][0] - return id,id +class Plugin(plugin.Plugin): + def __init__(self): + plugin.Plugin.__init__(self) + self.help = "" -# Called every time the plugin is enabled -def open(): - settings.init("random",False) - if settings.get("random") == True: - settings.set("next",randnext) + def open(self): + if settings.has("random") == False: + settings.set("random",False) + elif settings.get("random") == True: + signal.register("next",self.randNext,90) + pass -# Called every time the plugin is stopped -def close(): - pass + def randNext(self): + pass -def help(): - return "Changes next to play a random song" + def run(self, args=None): + if args==None or len(args)==0: + rand = not settings.get("random") + settings.set("random",rand) + if rand == True: + signal.register("next",self.randNext,90) + else: + signal.remove("next",self.randNext) + + elif args[0] == "?": + write(settings.get("random")) - -# Called when the plugin needs to perform some action -def run(args=None): - if args==None or len(args)==0: - settings.replace("random",not settings.get("random")) - random = settings.get("random") - if random == True: - settings.set("next",next) - else: - settings.pop("next") - elif args[0]=="?": - write(str(settings.get("random"))) diff --git a/src/ocarina b/src/ocarina index 652047df..d471a2c5 100755 --- a/src/ocarina +++ b/src/ocarina @@ -1,5 +1,5 @@ #!/bin/bash CORE=`pwd`/`dirname $0`"/core" -#EXTRA=`pwd`/`dirname $0`"/extra" -cd && `which scion` "-p $CORE" $* +EXTRA=`pwd`/`dirname $0`"/extra" +cd && `which scion` "-p $CORE -p $EXTRA" $*