#! /usr/bin/python '''These are core Ocarina system calls that should help in both development of future Ocarina features and in usage of ocarina-core''' __author__="bjschuma" __date__ ="$Mar 30, 2010 11:24:43 PM$" from ocarina import events from ocarina import vars from ct import times from ct import path def exit(): '''Safely exit ocarina''' path.rm(vars.LOCKFILE) import gstreamer import sys events.start(events.OCARINA_QUIT) sys.exit(0) def about(): write("Ocarina Version 3.0") write("Written by Bryan Schumaker (bjschuma@umich.edu)") def write(s,verbose=0): if vars.VERBOSE >= verbose: print str(s) def load(path): '''Load the song located at path''' import gstreamer gstreamer.load(path) from ct import tags tags.get(path) def seek(prcnt): ''' Seek to prcnt% of the song. If 0 < prcnt < 1, then we will seek to (prcnt * 100)% of song's duration. If prcnt < 100, then we will seek to prcnt% of the song's duration.''' from gstreamer import position good = position.seek(prcnt) if good == -1: write("There was an error seeking to: "+str(prcnt)) def progress(): '''Return the fraction of the song that we have already played''' from gstreamer import position progress = position.getProgress() write(progress) return progress def duration(): '''Return the total duration of the song. If message printing is enabled, then we will also print out string representing the duration in hh:mm:ss form''' from gstreamer import position duration = position.duration() write(times.ms2str(duration)) return duration def time(): '''Returns how far into the song gstreamer currently is. If message printing is enabled, then we will also print out a string representing the duration in hh:mm:ss form''' from gstreamer import position time = position.currentpos() write(times.ms2str(time)) return time def gsstate(): '''Returns the current gstreamer state''' from gstreamer import playback state = playback.getstate() write(state) return state def playing(disp=True): '''Returns true if ocarina is currently playing''' from gstreamer import playback import gst state = playback.getstate() == gst.STATE_PLAYING if disp==True: if state == True: write("Ocarina is playing") else: write("Ocarina is not playing") return state def tags(disp=True): '''Returns (title, artist, album) for the current track''' if disp == True: print vars.TITLE print "by",vars.ARTIST print "from",vars.ALBUM return (vars.TITLE, vars.ARTIST, vars.ALBUM) def play(): '''Begin playback of the loaded song''' events.start(events.OCARINA_PLAY) def pause(): '''Pause playback of the current song''' events.start(events.OCARINA_PAUSE) def stop(): '''Pause playback of the current song and seek to the beginning''' pause() seek(0) def volup(): '''Increase the volume''' from gstreamer import volume volume.volup() def voldown(): '''Decrease the volume''' from gstreamer import volume volume.voldown() def volset(vol): '''Set the volume''' from gstreamer import volume volume.setvol(vol) def pyfile(file): '''If file exists, try to execute it as a python script''' if path.exists(file) == True: write("Running script: "+file,1) execfile(file)