Can seek to any point of song

git-svn-id: file:///home/anna/Desktop/ocarina-legacy/mithos/ocarina@44 1daee41c-8060-4895-b1f0-2197c00d777a
This commit is contained in:
bjschuma 2009-07-04 20:18:53 +00:00
parent 4dcd210f3e
commit 57393a9150
16 changed files with 79 additions and 77 deletions

View File

@ -11,7 +11,9 @@ clean:
rm *~
install:
rsync src/ ~/bin/ocarina-bin/
# mkdir ~/bin/ocarina-bin
rsync -avz src/ ~/bin/ocarina-bin/src
rsync -avs images/ ~/bin/ocarina-bin/images
# rsync *.py ~/bin/ocarina-bin/
cp ocarina ~/bin/ocarina-bin/
rm ~/bin/ocarina

View File

@ -1,23 +1,22 @@
import pygtk
pygtk.require('2.0')
import gtk
from image import Image
class Button(gtk.Button):
def __init__(self,name,image,text,func):
gtk.Button.__init__(self)
self.set_relief(gtk.RELIEF_NONE)
box = gtk.HBox(True,0)
# Add an image if we were given one
if image!= None:
box.pack_start(image,True,True,0)
#box.add(image)
# Add text if we were given some
if text != None:
label = gtk.Label(text)
label.set_line_wrap(True)
label.set_size_request(100,100)
label.show()
box.pack_start(label,True,True,0)
# Show and add callback function
box.show()
self.add(box)
self.connect("clicked",func,name)

View File

@ -1,5 +1,3 @@
import pygtk
pygtk.require('2.0')
import gtk

View File

@ -1,7 +1,7 @@
import os
import gobject
import pygtk
pygtk.require('2.0')
#import pygtk
#pygtk.require('2.0')
import gtk
from button import Button
@ -37,11 +37,23 @@ class ControlPanel(gtk.HBox):
vbox = gtk.VBox()
pbar = gtk.ProgressBar()
pbar.set_fraction(0)
vbox.pack_start(pbar,True,False,0)
event = gtk.EventBox()
event.add(pbar)
vbox.pack_start(event,True,False,0)
#vbox.pack_start(pbar,True,False,0)
self.pack_start(vbox,True,True,0)
event.connect("button_release_event",self.pbarclick,pbar)
event.show()
vbox.show()
pbar.show()
gobject.timeout_add(100,self.updatePBar,pbar)
gobject.timeout_add(1000,self.updatePBar,pbar)
def pbarclick(self,widgit,data,pbar):
if data.button == 1:
prcnt = float(data.x) / float(pbar.get_allocation()[2])
self.data.song.seek(int(prcnt * self.data.song.info.duration * 1000000000))
#print float(data.x)/float(pbar.get_allocation()[0])
# Play/Pause function
@ -66,12 +78,13 @@ class ControlPanel(gtk.HBox):
# Update time/progress of the progress bar
def updatePBar(self,pbar):
if self.data.song and (self.data.song.playing == False):
return True
try:
(success,time) = self.data.song.curTime()
except:
success = False
if success == True:
#time = time/1000000000
pbar.set_fraction(float(time)/self.data.song.info.duration)
pbar.set_text(self.data.song.info.fixTime(time) + " / " + self.data.song.info.length)
return True

View File

@ -1,7 +1,6 @@
import pygtk
pygtk.require('2.0')
import gtk
class Image(gtk.Image):
def __init__(self,path):
gtk.Image.__init__(self)

View File

@ -1,7 +1,4 @@
import pango
import gobject
import pygtk
pygtk.require('2.0')
import gtk
@ -13,24 +10,24 @@ class InfoView(gtk.VBox):
self.album = self.makeLabel("",10000,400)
self.artist = self.makeLabel("",10000,400)
self.changeLabels()
gobject.timeout_add(1000,self.changeLabels)
self.show()
# Called when the song changes
def changeLabels(self):
title = ""
album = ""
artist = ""
if self.data.song:
title = self.data.song.info.title
album = "from "+self.data.song.info.album
artist = "by "+self.data.song.info.artist
title = self.data.song.info.title.title()
album = "from "+self.data.song.info.album.title()
artist = "by "+self.data.song.info.artist.title()
self.title.set_text(title)
self.album.set_text(album)
self.artist.set_text(artist)
return True
# Set the text, font, and weight of a label
def makeLabel(self,text,size,weight):
label = gtk.Label(text)
align = gtk.Alignment(0,1,0,0)

View File

@ -1,6 +1,4 @@
import gobject
import pygtk
pygtk.require('2.0')
import gtk
from menuItem import MenuItem
@ -39,10 +37,9 @@ class LibView(gtk.VBox):
for album in self.data.library.artAlb[artist]:
aliter = tree.append(ariter,[album.title(),-1])
for track in self.data.library.albTrk[(artist,album)]:
tree.append(aliter,[self.data.library.files[track].title,self.data.library.files[track].id])
tree.append(aliter,[self.data.library.files[track].title.title(),self.data.library.files[track].id])
tree.set_sort_column_id(0,gtk.SORT_ASCENDING)
self.treeview = gtk.TreeView(tree)
#self.treeview.set_hover_expand(True)
self.treeview.set_enable_search(True)
self.treeview.connect("button_release_event",self.clicked)
self.col = gtk.TreeViewColumn('Library ('+str(self.data.library.count)+')')

View File

@ -1,7 +1,6 @@
import pygtk
pygtk.require('2.0')
import gtk
class MenuItem(gtk.MenuItem):
#
def __init__(self,lbl,func,text,data,subs):

View File

@ -1,9 +1,7 @@
import random
import gobject
import pygtk
pygtk.require('2.0')
import gtk
import thread
import re
from menuItem import MenuItem
from song import Song
@ -13,11 +11,12 @@ PAFTER = 1
# This is both the playlist and the queue
class PlistView(gtk.Notebook):
def __init__(self,data):
def __init__(self,data,info):
gtk.Notebook.__init__(self)
self.connect("switch-page",self.changedTab)
self.set_scrollable(True)
self.data = data
self.info = info
self.controls = None
self.status = CONTINUE
@ -89,6 +88,7 @@ class PlistView(gtk.Notebook):
self.pfilter.set_visible_func(self.hideRows)
self.psort = gtk.TreeModelSort(self.pfilter)
self.ptree.set_model(self.psort)
#self.pfilter.set_child(self.ptreesel)
@ -112,7 +112,7 @@ class PlistView(gtk.Notebook):
i = len(dst)
for index in src:
track = self.data.library.files[index]
dst.insert(i,[track.id,track.title,track.length,track.artist,track.album,track.count])
dst.insert(i,[track.id,track.title.title(),track.length,track.artist.title(),track.album.title(),track.count])
time+=track.duration
i+=1
return time
@ -135,7 +135,7 @@ class PlistView(gtk.Notebook):
col = gtk.TreeViewColumn(cols[i],cell)
col.add_attribute(cell,'text',i)
col.set_resizable(True)
#col.set_sort_column_id(i)
col.set_sort_column_id(i)
col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
col.set_min_width(2)
col.set_max_width(700)
@ -272,6 +272,7 @@ class PlistView(gtk.Notebook):
if self.data.song:
self.data.song.close()
self.data.song = Song(self.data.library.files[self.data.curSong],self.next)
self.info.changeLabels()
if scroll == True:
self.gotoCurSong()
@ -299,7 +300,7 @@ class PlistView(gtk.Notebook):
def enqueue(self,widgit,func,data):
(model,pathlist) = self.ptreesel.get_selected_rows()
for path in pathlist:
q = self.plist[path]
q = self.pfilter[path]
self.data.curQ+=[q[0]]
self.qlist.append([q[0],q[1],q[2],q[3],q[4],q[5]])
self.qtime+=self.data.library.files[q[0]].duration
@ -323,18 +324,17 @@ class PlistView(gtk.Notebook):
def textTyped(self,entry):
self.search = entry.get_text().lower()
self.pfilter.refilter()
self.gotoCurSong()
def hideRows(self,list,iter):
if self.search != "":
title = list[iter][1].lower()
if title.find(self.search) > -1:
file = self.data.library.files[list[iter][0]]
if re.search(self.search,file.title):
return True
artist = list[iter][3].lower()
if artist.find(self.search) > -1:
elif re.search(self.search,file.artist):
return True
album = list[iter][4].lower()
if album.find(self.search) > -1:
elif re.search(self.search,file.album):
return True
return False
return True

View File

@ -1,14 +1,14 @@
import urllib2
import pygtk
pygtk.require('2.0')
#import pygtk
#pygtk.require('2.0')
import gtk
import webbrowser
import thread
#import thread
import hashlib
from button import Button
import xml.dom
#import xml.dom
from xml.dom import minidom
@ -58,9 +58,10 @@ class Scrobbler(gtk.VBox):
# Open to authorization page
def authorize(self):
url = "http://www.last.fm/api/auth/?"
(url,list) = self.addParam(url,[],"api_key",self.key)
url = "http://www.last.fm/api/auth/?api_key="+self.key
#(url,list) = self.addParam(url,[],"api_key",self.key)
(url,list) = self.addParam(url,[],"token",self.token)
print url
#url+="&"+self.token
webbrowser.open(url)
@ -74,13 +75,13 @@ class Scrobbler(gtk.VBox):
print url
#status = self.placeRequest(url)
return
attr = status.getAttributeNode("status")
if attr.value != "ok":
return
node = status.firstChild.firstChild
user = node.data
key = node.nextSibling.data
subscriber = node.nextSibling.nextSibling.data
#attr = status.getAttributeNode("status")
#if attr.value != "ok":
# return
#node = status.firstChild.firstChild
#user = node.data
#key = node.nextSibling.data
#subscriber = node.nextSibling.nextSibling.data
#print user,key,subscriber
@ -113,7 +114,7 @@ class Scrobbler(gtk.VBox):
def placeRequest(self,url):
print url
#print url
req = urllib2.Request(url)
req.add_header('User-Agent','Ocarina')
return minidom.parse(urllib2.urlopen(req)).documentElement

View File

@ -1,7 +1,7 @@
import os
import re
import tagpy
import cPickle as pickle
#import cPickle as pickle
from songInfo import SongInfo
import thread
@ -9,7 +9,7 @@ import thread
class Library:
#def __init__(self,prnt):
def __init__(self):
self.goodTypes = ["ogg","mp3","wav","avi","flac","mid"]#,"wma"]
self.goodTypes = ["ogg","mp3","wav","flac","mid"]#,"wma"]
self.reset()
self.scanning = False
#self.notAdded = open("/home/bjschuma/Desktop/notAdded.txt",'w')
@ -104,8 +104,12 @@ class Library:
info.setTime(a.length)
except:
print info.filename
artist = info.artist.lower()
album = info.album.lower()
info.title = info.title.lower()
info.album = info.album.lower()
info.artist = info.artist.lower()
artist = info.artist
album = info.album
if (artist in self.artAlb.keys()) == False:

View File

@ -1,16 +1,10 @@
import gobject
import os
import sys
import thread
import pygtk
pygtk.require('2.0')
import gtk
import gobject
from options import Options
from saveddata import SavedData
from song import Song
from window import Window
gobject.threads_init()

View File

@ -1,9 +1,7 @@
import gobject
import os
import cPickle as pickle
from library import Library
from song import Song
class SavedData:
def __init__(self,options):

View File

@ -1,7 +1,3 @@
import sys
import time
import pygst
pygst.require("0.10")
import gst
@ -10,6 +6,7 @@ class Song():
def __init__(self,info,next):
self.next = next
self.info = info
self.position = 0
self.player = gst.Pipeline("player")
self.bin = gst.element_factory_make("playbin",None)
self.bin.set_property("uri","file://"+self.info.filename)
@ -56,7 +53,12 @@ class Song():
self.player.set_state(gst.STATE_PAUSED)
self.playing = False
self.current = 0
self.player.seek_simple(self.time_format,gst.SEEK_FLAG_FLUSH,self.current)
#self.player.seek_simple(self.time_format,gst.SEEK_FLAG_FLUSH,self.current)
self.seek(current)
def seek(self,time):
self.player.seek_simple(self.time_format,gst.SEEK_FLAG_FLUSH,time)
# Close the song

View File

@ -1,3 +1,5 @@
class SongInfo:
def __init__(self):
self.id = 0

View File

@ -1,6 +1,3 @@
import gobject
import pygtk
pygtk.require('2.0')
import gtk
import thread
@ -122,7 +119,7 @@ class Window(gtk.Window):
infoview = InfoView(self.data)
topRight.pack_start(infoview,False,False,0)
rightPane.pack_start(topRight,False,False,0)
self.plistview = PlistView(self.data)
self.plistview = PlistView(self.data,infoview)
topRight.pack_end(self.plistview.searchBar,False,False,0)
rightPane.add(self.plistview)
self.makeBottomRow(rightPane)