Exemple #1
0
 def __init__(self, algorithm, listener, profile, interpreter, debug=False):
     self._matcher = Matcher(algorithm, interpreter, self._position_changed,
         debug)
     self._capturer = Capturer(listener, self._handle_buckets)
     self._display = None
     self._running = False
     self._debug = debug
Exemple #2
0
    profile = None
    if options.profile:
        try:
            profile = load_profile(options.profile)
        except IOError, e:
            if e.errno == 2:
                print "Creating new profile."
                profile_name = options.profile.capitalize().replace("-", " ")
                path = os.path.join(get_profile_storage_dir(), "%s.json" % options.profile)
                profile = Profile(profile_name, path=path)
            else:
                raise
        except ProfileReadError, e:
            parser.error("invalid profile: %s" % e)

    capturer = Capturer(create_listener(options))

    targets = []
    is_range = False
    for arg in args:
        if arg == "-":
            is_range = True
            continue

        note = Note.parse(arg)
        if is_range:
            start = targets[-1].semitone + 1
            for i in xrange(start, note.semitone + 1):
                targets.append(Note.from_semitone(i))
        else:
            targets.append(note)
Exemple #3
0
class MusicStand(object):
    """
    An intelligent digital music stand.
    """
    
    def __init__(self, algorithm, listener, profile, interpreter, debug=False):
        self._matcher = Matcher(algorithm, interpreter, self._position_changed,
            debug)
        self._capturer = Capturer(listener, self._handle_buckets)
        self._display = None
        self._running = False
        self._debug = debug
        
    def run(self):
        """
        Runs the music stand.
        
        This method will not return until the application exits.
        """
        
        callbacks = dict(song_loaded=self._start_song,
            song_stopped=self._abort_song, song_restarted=self._restart_song)
        
        self._capturer.start() # also starts the listener
        self._matcher.start()
        
        try:
            self._running = True
            
            root = Tk()
            self._display = Display(root, callbacks, self._debug)
            
            # run the Tkinter event loop
            root.mainloop()
        except KeyboardInterrupt:
            print
        finally:
            self._running = False
            self._matcher.shutdown()
            self._capturer.stop() # similarly, also stops the listener
    
    def _start_song(self, lilypond_file):
        if self._debug:
            print 'Song loaded: %s' % lilypond_file
        
        notes = parse_file(lilypond_file)
        self._matcher.load_piece(notes)
    
    def _abort_song(self):
        self._matcher.stop_piece()
    
    def _restart_song(self):
        self._display.reset_song_positions()
        self._display.reset_sheetmusic()
        self._matcher.restart_piece()
    
    def _handle_buckets(self, buckets):
        # XXX: this is dumb
        notes = [p[0] for p in sorted(buckets, key=lambda b: b[1],
            reverse=True)]
        
        self._matcher.add(notes)
    
    def _position_changed(self, matcher):
        if matcher.intervals is None:
            return
        
        self._display.update_position(matcher)
        
        if matcher.current_location >= (len(matcher.intervals) - 1):
            if self._debug:
                print 'Done with the piece!'
Exemple #4
0
    
    tracker = ComponentTracker(callback)
    
    if options.track:
        # print note headings
        for note in watched:
            print color('black!', '%-3s%s', note, ' ' * 11),
        print
        for note in watched:
            print color('black!', '=' * 14),
        print
    
    if options.recording:
        # read the FFT results from a file created by audio/test.py
        with open(options.recording, 'rb') as stream:
            recording = pickle.load(stream)
        
        if isinstance(recording, dict) and 'results' in recording:
            results = recording['results']
        else:
            results = recording
        
        for buckets in results:
            buckets = [(Note.from_frequency(freq), intensity)
                for freq, intensity in buckets]
            tracker.update(buckets)
    else:
        # capture live
        capturer = Capturer(create_listener(options), tracker.update)
        capturer.run_until_interrupt()