Ejemplo n.º 1
0
 def __init__(self):
     # needs at least 2 things to start for some reason
     self.queue = ["/Users/admin/Music/iTunes/iTunes Media/Music/Adrian Marcel/Unknown Album/2AM.mp3",
                   "/Users/admin/Music/iTunes/iTunes Media/Music/Penn Masala/Unknown Album/_Down.mp3"]
     self.player = musicplayer.createPlayer()
     self.player.outSamplerate = 96000  # support high quality :)
     self.player.queue = self.gen_song_queue()
     self.song_index = 1
Ejemplo n.º 2
0
 def __init__(self, app, outSamplerate=48000):
     self.app = app
     self.core = musicplayer.createPlayer()
     self.core.outSamplerate = outSamplerate
     self.core.queue = self.get_songs()
     self.core.peekQueue = self.peek_songs
     self.core.onSongChange = self._process_onSongChange
     self.songs = []
     self.curr_song = 0
     self.events = defaultdict(list)
Ejemplo n.º 3
0
 def __init__(self):
     # needs at least 2 things to start for some reason
     self.queue = [
         "test_resources/Bed Of Roses.mp3",
         "test_resources/Bed Of Roses.mp3"
     ]
     self.player = musicplayer.createPlayer()
     self.player.outSamplerate = 96000  # support high quality :)
     self.player.queue = self.gen_song_queue()
     self.song_index = 1
Ejemplo n.º 4
0
    def onMousePressed(self, event):
        if self.inSubScreen:
            cx, cy = event.x, event.y
            for i in xrange(len(self.songBalls)):  # chose a song ball
                if self.isInside((cx, cy), self.posSongBalls[i]):
                    self.onPlay = self.songBalls[i]

            if self.isInsideCircle((cx, cy), self.nextArrowPos, 28):  # chose next arrow
                self.enterAudScreen()

        if self.inAudScreen:
            cx, cy = event.x, event.y
            loadSqure = (self.loadPos[0] - 14, self.loadPos[1] - 28,
                         self.loadPos[0] + 14, self.loadPos[1] + 28)
            if self.isInside((cx, cy), loadSqure):
                filePath = tkFileDialog.askopenfilename()
                if filePath == "":
                    print "lalalala"
                elif not ".wav" in filePath:  # This is modified from lecture notes
                    message = "Only accept '.wav' files."
                    title = "Warning"
                    tkMessageBox.showinfo(title, message)
                else:
                    self.onPlay.setWav(filePath)
                    self.isProcessing = True
                    self.drawProcessing()
                    # (self.lyrics, self.references, self.stamps) = ([[1, "a"]], [[[1, 0]]], [[[1, 0]]])
                    (self.lyrics, self.references, self.stamps) = self.onPlay.song.align_subtitle()
                    self.enterAnimationScreen()
                    # set Animation start time
                    self.animationStartTime = time.time()
                    print "start time: %f" % self.animationStartTime

                    # play song
                    self.songList = [self.onPlay.song.url]
                    self.player = createPlayer()
                    self.player.outSamplerate = 96000
                    self.player.queue = self.songs()
                    self.player.peekQueue = self.peekSongs
                    self.player.playing = True
Ejemplo n.º 5
0
def loadPlayer(state):
    import musicplayer

    from appinfo import args, config
    import TaskSystem
    if args.debug and TaskSystem.isMainProcess:
        musicplayer.enableDebugLog(True)

    player = musicplayer.createPlayer()
    player.outSamplerate = config.sampleRate
    player.preferredSoundDevice = config.preferredSoundDevice
    for e in [m for m in dir(PlayerEventCallbacks) if not m.startswith("_")]:
        cb = getattr(PlayerEventCallbacks, e)
        assert cb
        setattr(player, e, cb)
    player.queue = songsQueue(state)
    player.peekQueue = songsPeekQueue()
    player.volume = state.volume

    player.startWorkerThread()

    return player
Ejemplo n.º 6
0
def loadPlayer(state):
	import musicplayer

	from appinfo import args, config
	import TaskSystem
	if args.debug and TaskSystem.isMainProcess:
		musicplayer.enableDebugLog(True)

	player = musicplayer.createPlayer()
	player.outSamplerate = config.sampleRate
	player.preferredSoundDevice = config.preferredSoundDevice
	for e in [m for m in dir(PlayerEventCallbacks) if not m.startswith("_")]:
		cb = getattr(PlayerEventCallbacks, e)
		assert cb
		setattr(player, e, cb)
	player.queue = songsQueue(state)
	player.peekQueue = songsPeekQueue()
	player.volume = state.volume

	player.startWorkerThread()

	return player
Ejemplo n.º 7
0
def songs():
    global i, files
    while True:
        yield Song(files[i])
        i += 1
        if i >= len(files): i = 0


def peekSongs(n):
    nexti = i + 1
    if nexti >= len(files): nexti = 0
    return map(Song, (files[nexti:] + files[:nexti])[:n])


# Create our Music Player.
player = musicplayer.createPlayer()
player.outSamplerate = 96000  # support high quality :)
player.queue = songs()
player.peekQueue = peekSongs

# Setup a simple GUI.
window = Tkinter.Tk()
window.title("Music Player")
songName = Tkinter.StringVar()
songTime = Tkinter.StringVar()
songLabel = Tkinter.StringVar()


def onSongChange(**kwargs):
    songName.set(os.path.basename(player.curSong.url))
    songLabel.set(pprint.pformat(player.curSongMetadata))
i = 0

def songs():
	global i, files
	while True:
		yield Song(files[i])
		i += 1
		if i >= len(files): i = 0

def peekSongs(n):
	nexti = i + 1
	if nexti >= len(files): nexti = 0
	return map(Song, (files[nexti:] + files[:nexti])[:n])

player = musicplayer.createPlayer()
player.outSamplerate = 48000
player.queue = songs()
player.peekQueue = peekSongs
player.playing = True

def formatTime(t):
	if t is None: return "?"
	mins = long(t // 60)
	t -= mins * 60
	hours = mins // 60
	mins -= hours * 60
	if hours: return "%02i:%02i:%02.0f" % (hours,mins,t)
	return "%02i:%02.0f" % (mins,t)

import termios
def main():
    class Song:
        def __init__(self, fn):
            self.url = fn
            self.f = open(fn)

        # `__eq__` is used for the peek stream management
        def __eq__(self, other):
            return self.url == other.url

        # this is used by the player as the data interface
        def readPacket(self, bufSize):
            return self.f.read(bufSize)

        def seekRaw(self, offset, whence):
            r = self.f.seek(offset, whence)
            return self.f.tell()

    def getFiles(path):
        for f in sorted(os.listdir(path), key=lambda k: random.random()):
            f = os.path.join(path, f)
            if os.path.isdir(f):
                getFiles(f)  # recurse
            if len(files) > 1000:
                break  # break if we have enough
            if fnmatch.fnmatch(f, '*.mp3'): files.append(f)

    getFiles(os.path.expanduser("0000_Mucke/WORKFLOW/dr_dna/"))
    random.shuffle(files)  # shuffle some more

    def songs():
        global i, files
        while True:
            yield Song(files[i])
            i += 1
            if i >= len(files): i = 0

    def peekSongs(n):
        nexti = i + 1
        if nexti >= len(files): nexti = 0
        return map(Song, (files[nexti:] + files[:nexti])[:n])

    # Create our Music Player.
    player = musicplayer.createPlayer()
    player.outSamplerate = 96000  # support high quality :)
    player.queue = songs()
    player.peekQueue = peekSongs

    # Setup a simple GUI.
    window = Tkinter.Tk()
    window.title("Music Player")
    songLabel = Tkinter.StringVar()

    def onSongChange(**kwargs):
        songLabel.set(pprint.pformat(player.curSongMetadata))

    def cmdPlayPause(*args):
        player.playing = not player.playing

    def cmdNext(*args):
        player.nextSong()

    Tkinter.Label(window, textvariable=songLabel).pack()
    Tkinter.Button(window, text="Play/Pause", command=cmdPlayPause).pack()
    Tkinter.Button(window, text="Next", command=cmdNext).pack()

    player.onSongChange = onSongChange
    player.playing = True  # start playing
    window.mainloop()