Ejemplo n.º 1
0
def main(arguments):

    settings = None
    with open('settings.json') as jfile:
        settings = json.load(jfile)

    name = 'drumsets/' + arguments['<name>']
    if arguments['new']:
        if os.path.isdir(name):
            choice = input(
                "Are you sure you want to overwrite {0}?(y/N): ".format(name))
            if choice != 'y':
                return 0
            else:
                shutil.rmtree(name)

        os.mkdir(name)
        drumtools.setUpDrumset(name, settings["record_device"])

    # Select drumset
    drumset = drumtools.Drumset(name)

    choice = input("Drumset selected, are YOU ready to make a BEAT?(Y/n): ")
    if choice == 'n':
        return 0

    # record the drums. May need to import microphone
    amp_arr, sr = record(settings["record_device"])

    print("Great job! now lets make this beat rock more...")

    # Analyze and modify the track
    new_amp_arr = modify(amp_arr, sr, drumset)

    # Save the drums temporary:
    librosa.output.write_wav('.temp.wav', new_amp_arr, sr)

    no_choice = input("Press enter to hear the revised beat")

    play('.temp.wav', settings["playback_device"])

    choice = input("Save the beat?(Y/n): ")
    if choice == 'n':
        return 0

    name = None
    while name is None:
        name = input("Name the beat: ")
        name += ".wav"
        if os.path.exists(name):
            choice = input(
                "Are you sure you want to overwrite {0}?(y/N): ".format(name))
            if choice == 'n' or choice == 'N':
                name = None
                continue
        librosa.output.write_wav(name, new_amp_arr, sr)

    os.remove('.temp.wav')
Ejemplo n.º 2
0
def main():
    """Main function"""
    scale = Scale("A3", "major")
    params = Params()
    layers = music_algorithm.make_piece(params, scale.length)
    timeline_ = timeline.Timeline()
    render_timeline(timeline_, layers, params, scale)
    data = timeline_.render(volume=0.05)
    playback.play(data)
Ejemplo n.º 3
0
def main():
    parser = OptionParser("usage: %prog [options] filename")
    parser.add_option("", "--gui",
                      action="store_true", dest="gui", default=False,
                      help="Start the editor GUI (GTK)")
    parser.add_option("-p", "--play",
                      action="store_true", dest="play", default=False,
                      help="Play the score")
    parser.add_option("", "--shell",
                      action="store_true", dest="shell_mode", default=False,
                      help="Start a Python shell (for inspection)")
    parser.add_option("-w", "--width",
                      action="store", type="int", dest="width", default=40,
                      help="Maximum number of characters per line")
    (options, args) = parser.parse_args()
    if options.width < 8:
        parser.error("number of characters per line is too small")
    if options.gui:
        import gui
        inputfile = None
        if len(args)>0:
            inputfile = args[0]
        freedots = gui.Application(inputfile, width=options.width)
        freedots.run()
    else:
        if len(args) != 1:
            parser.error("incorrect number of arguments")
        inputfile = args[0]
        score = musicxml.Score(inputfile)
        if not score:
            parser.error("unable to parse input file %s (not a MusicXML file?)"
                         % inputfile)
        sys.stdout = codecs.getwriter('utf-8')(sys.stdout, 'replace')
        output = braillemusic.Embosser(width=options.width)
        output.format(score)
        sys.stdout.write(unicode(output)+"\n")
        if options.play:
            import playback
            playback.play(score)
            if not options.shell_mode:
                playback.spin()
        if options.shell_mode:
            import code
            del parser
            del args
            if options.play:
                play = playback.play
            else:
                try:
                    from playback import play
                except:
                    pass
            code.interact(banner="""FreeDots Python Shell
The variable 'score' holds an instance of your music.""",
                              local=locals())
Ejemplo n.º 4
0
 def key_press_cb(self, text_view, event):
     buffer = text_view.get_buffer()
     iter = buffer.get_iter_at_mark(buffer.get_insert())
     object = self.displayedObjects[iter.get_offset()]
     if event.keyval == gtk.keysyms.Return:
         if object:
             playback.play(object)
         return True
     else:
         self.status_bar.pop(0)
         self.status_bar.push(0, gtk.gdk.keyval_name(event.keyval))
     return False
Ejemplo n.º 5
0
def comma_pump(frequency):
    """Comma pump."""
    print("Demonstrating the syntonic comma. Starting at " + str(frequency) +
          " hz.")
    intervals = [3 / 2, 3 / 4, 3 / 2, 3 / 4, 4 / 5]
    stream = Stream()
    stream.set_intervals(intervals)
    notes = stream.play()
    print("Playing starting note: " + str(frequency) +
          " hz, again for comparison.")
    playback.play(playback.sine_wave(frequency, 4096), 1000)
    print("Hear the difference?")
    return notes
Ejemplo n.º 6
0
 def mark_set_cb(self, buffer, new_location, mark):
     object = self.displayedObjects[new_location.get_offset()]
     if object is not None:
         if object != self.lastFocusedObject:
             self.status_bar.pop(0)
             self.status_bar.push(0, `object`)
             playback.play(object)
             self.lastFocusedObject = object
             if hasattr(object, 'pitch') and object.pitch:
                 self.editPitchedActionGroup.set_sensitive(True)
             else:
                 self.editPitchedActionGroup.set_sensitive(False)
     else:
         self.editPitchedActionGroup.set_sensitive(False)
Ejemplo n.º 7
0
 def play(self):
     """Play."""
     # below line will be removed.
     self.frequency = 220.0
     print("Playing starting frequency: " + str(self.frequency) + " hz.")
     playback.play(playback.sine_wave(self.frequency, 4096), 1000)
     frequencies = [self.frequency]
     for interval in self.intervals:
         self.frequency *= interval
         print("Playing a " + str(interval) + " to: " +
               str(self.frequency) + " hz.")
         playback.play(playback.sine_wave(self.frequency, 4096), 1000)
         frequencies.append(self.frequency)
     return frequencies
Ejemplo n.º 8
0
 def alarm_time(self):
     print "ALARM TIME!!!"
     self.alarm = True
     playback.load_playlist()
     time.sleep(2)
     playback.play()
     while self.wakeup_period:
         st = playback.state()
         if (st == 'paused' or st == 'stopped'):
             self.snoozed = True
         while self.snoozed:
             snooze_time = self.snooze_time
             while snooze_time:
                 time.sleep(1)
                 snooze_time -= 1
                 self.wakeup_period -= 1
             self.snoozed = False
             playback.play()
         time.sleep(1)
         self.wakeup_period -= 1
         if self.wakeup_period < 0:
             self.wakeup_period = 0
     return
Ejemplo n.º 9
0
	def bang:
		# Plays the drum
		playback.play('drums', self.type)
Ejemplo n.º 10
0
 def play_cb(self, action):
     playback.play(self.score)