Ejemplo n.º 1
0
    def gui(self, stdscr):
        seq = self.seq
        my, mx = stdscr.getmaxyx()

        #curses.mousemask(curses.BUTTON1_CLICKED)
        curses.halfdelay(1)
        y = x = 0
        scale = 10
        time = 0.0
        tracks = None
        length = None
        viewpos = 0
        trackview = None
        viewwidth = mx - 9 - 3
        maxscale = 100
        speed = 1.0
        following = True
        name = None
        while True:
            if not seq.running:
                pass
                #break
            stdscr.clear()
            curses.curs_set(0)
            stdscr.addstr(0, 0, '[(p)lay/pause] [(s)top] [choose (f)ile] [choose (t)rack] [choose (o)utput] [((j/k) slower/faster)] [toggle (F)ollowing]')
            stdscr.addstr(1, 0, '[(e)dit alignment] [e(x)port track]')
            if seq.midifile:
                stdscr.addstr(4, 3, 'File: {0}'.format(seq.midifile.name))
                stdscr.addstr(5, 3, 'Midi Device: {0}'.format(seq.device_info()))
                stdscr.addstr(6, 3, 'Midi Track: {0}'.format(seq.currenttrack))
            stdscr.addstr(7, 3, 'Player status: {0}'.format(seq.status))

            stdscr.refresh()

            time = self.seq.time

            # Load tracks once the midifile is loaded
            if self.seq.midifile and name is not self.seq.midifile.name:
                name = self.seq.midifile.name
                tracks = []
                for t in self.seq.midifile.values():
                    if len(t) > 0:
                        tracks.append(t)
                tracks = sorted(tracks, key=lambda x: x.n)
                length = max([t.length() for t in tracks])
                length /= 1000000.0
                trackview = None

            # Paint the trackview
            if tracks and not trackview:
                trackview = \
                  cgui.trackview(stdscr, tracks, ypos=9, xpos=3, width=viewwidth, scale=scale)
                viewpos = 0

            if tracks and trackview:
                if seq.mode == seq.PLAYING and following:
                    if time*scale < round(viewwidth/2.0):
                        viewpos = 0
                    elif time*scale > length*scale - round(viewwidth/2.0):
                        viewpos = length*scale - viewwidth
                    else:
                        viewpos = time*scale - round(viewwidth/2.0)

                cgui.updatetracks(stdscr, viewpos, time, trackview, ypos=9, xpos=3, width=mx-10, scale=scale, currenttrack=seq.currenttrack)
                stdscr.addstr(len(tracks)+1+9, 3, 'Time: {0:.2f}\tTime left: {1:.2f}\tTrackview scale: {2}\tSpeed: {3}' .format(time, length-time, scale, speed))

            c = stdscr.getch()

#      if c == curses.KEY_MOUSE:
#        (id, x, y, z, state) = curses.getmouse()
#        if state == curses.BUTTON1_CLICKED:
#          pass
#
            if c == ord('q'):
                self.seq.control(self.seq.QUIT, None)
                break
            elif c == ord('F'):
                if following:
                    following = False
                else:
                    following = True
            elif c == ord('s'):
                seq.control(seq.STOP, None)
            elif c == ord('N'):
                seq.control(seq.NEXTNOTE, None)
            elif c == ord('p'):
                if seq.mode == seq.PLAYING:
                    seq.control(seq.PAUSE, None)
                else:
                    seq.control(seq.PLAY, None)
            elif c == ord('t'):
                if seq.midifile:
                    choice = cgui.menu(stdscr, 'Choose a track',\
                        ['Track #{0}\tName: {1}\tNumber of notes: {2}'.format(\
                        seq.midifile[t].n, seq.midifile[t].name, len(seq.midifile[t]))\
                        for t in seq.tracklist()])
                    if choice < 0: continue
                    seq.control(seq.LOADTRACK, seq.tracklist()[choice])
            elif c == ord('j'):
                if speed > 0:
                    speed -= 0.01
                seq.control(seq.SETSPEED, speed)
            elif c == ord('k'):
                speed += 0.01
                seq.control(seq.SETSPEED, speed)
            elif c == ord('h'):
                seq.control(seq.SETTIME, seq.time-1)
            elif c == ord('l'):
                seq.control(seq.SETTIME, seq.time+1)
            elif c == ord('f'):
                level = 1
                midifile = None
                while level > 0:
                    if level == 1:
                        choice = cgui.menu(stdscr, 'Choose collection', midicorpus.collections())
                        if choice == -1:
                            level -= 1
                            continue
                        else: level += 1
                        collection = midicorpus.collections()[choice]
                    elif level == 2:
                        choice = cgui.menu(stdscr, 'Choose song', midicorpus.songs(collection=collection))
                        if choice == -1:
                            level -= 1
                            continue
                        else: level += 1
                        song = midicorpus.songs(collection=collection)[choice]
                    elif level == 3:
                        choice = cgui.menu(stdscr, 'Choose version', midicorpus.versions(song, collection=collection))
                        if choice == -1:
                            level -= 1
                            continue
                        else: level += 1
                        version = midicorpus.versions(song, collection=collection)[choice]
                    elif level == 4:
                        singletrack = False
                        track = 0
                        if len(midicorpus.tracks(song, version, collection=collection)) > 0:
                            singletrack = True
                            choice = cgui.menu(stdscr, 'Choose track', midicorpus.tracks(song, version, collection=collection))
                            if choice == -1:
                                level -= 1
                                continue
                            track = midicorpus.tracks(song, version, collection=collection)[choice]
                        else: level += 1
                        midifile = midicorpus.load(song, version, track, singletrack, collection=collection)
                        break
                if not midifile: continue
                cgui.alert(stdscr, 'Loading file', block=False)
                seq.control(seq.LOADFILE, midifile)
                time = 0
            elif c == ord('o'):
                choice = cgui.menu(stdscr, 'Choose a midi device', seq.devicelist())
                if choice < 0: continue
                seq.control(seq.SETOUTPUT, choice)
            elif c == curses.KEY_LEFT:
                if viewpos > 0:
                    viewpos -= 1
            elif c == curses.KEY_RIGHT:
                if viewpos < length*scale - viewwidth:
                    viewpos += 1
            elif c == curses.KEY_UP:
                if scale < maxscale and trackview:
                    scale += 1
                    trackview = \
                      cgui.trackview(stdscr, tracks, ypos=9, xpos=3, width=viewwidth, scale=scale)
            elif c == curses.KEY_DOWN:
                if scale > 1 and trackview:
                    scale -= 1
                    trackview = \
                      cgui.trackview(stdscr, tracks, ypos=9, xpos=3, width=viewwidth, scale=scale)
        curses.endwin()
Ejemplo n.º 2
0
def collections(path=annotationspath):
    return midi.collections(path=path)