Added MP3 and OGG support

This commit is contained in:
Skyler Lehmkuhl 2013-01-20 16:49:21 -05:00
parent 023e4ca5bd
commit 1d08fd9587
3 changed files with 60 additions and 50 deletions

View File

@ -4,6 +4,6 @@ Section: graphics
Priority: optional Priority: optional
Architecture: all Architecture: all
Installed-size: 27000 Installed-size: 27000
Depends: bash, python, python-imaging, imagemagick, libzzip-0-13, sox, python-numpy Depends: bash, python, python-imaging, imagemagick, libzzip-0-13, sox, python-numpy, mplayer
Maintainer: skycooler@gmail.com Maintainer: skycooler@gmail.com
Description: Lightningbeam is an open-source animated content creation tool. Description: Lightningbeam is an open-source animated content creation tool.

View File

@ -685,7 +685,7 @@ def save_file_as(widget=None):
pass pass
def import_to_stage(widget=None): def import_to_stage(widget=None):
try: try:
thefile = svlgui.file_dialog("open",None,["jpg","png","bmp","wav"]).path thefile = svlgui.file_dialog("open",None,["jpg","png","bmp","wav","mp3","ogg"]).path
except AttributeError: except AttributeError:
# User cancelled # User cancelled
return return
@ -716,54 +716,63 @@ def import_to_stage(widget=None):
root.descendItem().add(im) root.descendItem().add(im)
break break
else: else:
if thefile.endswith("wav"): for i in ("wav", "mp3", "ogg"):
if svlgui.PLATFORM=="osx": if thefile.endswith(i):
if not os.path.exists('sox/sox'): if i in ("mp3", "ogg"):
try: theorigfile = thefile
import numpy as NP thefile = svlgui.SECURETEMPDIR+"/"+thefile.split('/')[-1]+'.wav'
result = svlgui.alert("To import sound you must install SoX. This will take about 1 MB of space. Install?", confirm=True) os.system('mplayer -srate 48000 -vo null -vc null -ao pcm:fast:file="'+thefile+'" "'+theorigfile+'"')
if not result: if svlgui.PLATFORM=="osx":
return if not os.path.exists('sox/sox'):
urllib.urlretrieve('http://downloads.sourceforge.net/project/sox/sox/14.4.0/sox-14.4.0-macosx.zip?r=&ts=1357270265&use_mirror=iweb', 'sox.zip') try:
os.system('ditto -V -x -k --sequesterRsrc --rsrc sox.zip .') import numpy as NP
os.system('mv sox-14.4.0 sox') result = svlgui.alert("To import sound you must install SoX. This will take about 1 MB of space. Install?", confirm=True)
except: if not result:
result = svlgui.alert("To import sound you must install NumPy and SoX. This will take about 10 MB of space. Install?", confirm=True) return
if not result: urllib.urlretrieve('http://downloads.sourceforge.net/project/sox/sox/14.4.0/sox-14.4.0-macosx.zip?r=&ts=1357270265&use_mirror=iweb', 'sox.zip')
return os.system('ditto -V -x -k --sequesterRsrc --rsrc sox.zip .')
os.system("""osascript -e 'do shell script "easy_install numpy" with administrator privileges'""") os.system('mv sox-14.4.0 sox')
import numpy as NP except:
urllib.urlretrieve('http://downloads.sourceforge.net/project/sox/sox/14.4.0/sox-14.4.0-macosx.zip?r=&ts=1357270265&use_mirror=iweb', 'sox.zip') result = svlgui.alert("To import sound you must install NumPy and SoX. This will take about 10 MB of space. Install?", confirm=True)
os.system('ditto -V -x -k --sequesterRsrc --rsrc sox.zip .') if not result:
os.system('mv sox-14.4.0 sox') return
os.system("""osascript -e 'do shell script "easy_install numpy" with administrator privileges'""")
import numpy as NP
urllib.urlretrieve('http://downloads.sourceforge.net/project/sox/sox/14.4.0/sox-14.4.0-macosx.zip?r=&ts=1357270265&use_mirror=iweb', 'sox.zip')
os.system('ditto -V -x -k --sequesterRsrc --rsrc sox.zip .')
os.system('mv sox-14.4.0 sox')
else:
try:
import numpy as NP
except:
result = svlgui.alert("To import sound you must install NumPy. This will take about 9 MB of space. Install?", confirm=True)
if not result:
return
os.system("""osascript -e 'do shell script "easy_install numpy" with administrator privileges'""")
import numpy as NP
SOX_EXEC = 'sox/sox'
elif "linux" in svlgui.PLATFORM:
import numpy as NP
SOX_EXEC = "sox"
svlgui.NP = NP
num_channels = 1
out_byps = 2 # Bytes per sample you want, must be 1, 2, 4, or 8
cmd = [SOX_EXEC,
thefile, # input filename
'-t','raw', # output file type raw
'-e','signed-integer', # output encode as signed ints
'-L', # output little endin
'-b',str(out_byps*8), # output bytes per sample
'-'] # output to stdout]
data = NP.fromstring(subprocess.check_output(cmd),'<i%d'%(out_byps))
data = data.reshape(len(data)/num_channels, num_channels)
info = subprocess.check_output([SOX_EXEC,'--i',thefile])
if i=="mp3":
sound = svlgui.Sound(data, name=thefile.split('/')[-1], path=theorigfile, info=info, type=i)
else: else:
try: sound = svlgui.Sound(data, name=thefile.split('/')[-1], path=thefile, info=info, type=i)
import numpy as NP root.descendItem().add(sound)
except: break
result = svlgui.alert("To import sound you must install NumPy. This will take about 9 MB of space. Install?", confirm=True)
if not result:
return
os.system("""osascript -e 'do shell script "easy_install numpy" with administrator privileges'""")
import numpy as NP
SOX_EXEC = 'sox/sox'
elif "linux" in svlgui.PLATFORM:
import numpy as NP
SOX_EXEC = "sox"
svlgui.NP = NP
num_channels = 1
out_byps = 2 # Bytes per sample you want, must be 1, 2, 4, or 8
cmd = [SOX_EXEC,
thefile, # input filename
'-t','raw', # output file type raw
'-e','signed-integer', # output encode as signed ints
'-L', # output little endin
'-b',str(out_byps*8), # output bytes per sample
'-'] # output to stdout]
data = NP.fromstring(subprocess.check_output(cmd),'<i%d'%(out_byps))
data = data.reshape(len(data)/num_channels, num_channels)
info = subprocess.check_output([SOX_EXEC,'--i',thefile])
sound = svlgui.Sound(data, name=thefile.split('/')[-1], path=thefile, info=info)
root.descendItem().add(sound)
MainWindow.stage.draw() MainWindow.stage.draw()
def import_to_library(widget=None): def import_to_library(widget=None):

View File

@ -1977,7 +1977,7 @@ class Text (object):
class Sound: class Sound:
"""Class for storing sounds in.""" """Class for storing sounds in."""
def __init__(self, data, name, path, info): def __init__(self, data, name, path, info, type):
global Library global Library
Library.append(self) Library.append(self)
self.data = data self.data = data
@ -1989,6 +1989,7 @@ class Sound:
self.yscale = 0 self.yscale = 0
self.path = path self.path = path
self.iname = None self.iname = None
self.type = type
reading_comments_flag = False reading_comments_flag = False
other = '' other = ''
for l in info.splitlines(): for l in info.splitlines():