Exemple #1
0
def main():
    usage = "%prog [options] <in-file>"
    description = "Play music using the Harmonical. This allows you to "\
        "play music specified precisely in the tonal space. By default, "\
        "plays back the input, but can also output to a file."
    parser = OptionParser(usage=usage, description=description)
    parser.add_option('-o', '--output', dest="outfile", action="store", help="output the result to a wave file instead of playing back.")
    parser.add_option('-m', '--midi', dest="midi", action="store_true", help="generate midi data, not audio. Depends on the input format supporting midi file generation.")
    options, arguments = parse_args_with_config(parser)
    
    filename = arguments[0]
    
    # Load up the input file
    infile = HarmonicalInputFile.from_file(filename)
    if options.midi:
        midi = infile.render_midi()
        
        if options.outfile is not None:
            # Output a midi file
            write_midifile(midi, options.outfile)
            print >>sys.stderr, "Saved midi data to %s" % options.outfile
        else:
            print >>sys.stderr, "Playing..."
            play_stream(midi, block=True)
    else:
        print >>sys.stderr, "Generating audio..."
        audio = infile.render()
        
        if options.outfile is not None:
            # Output to a file instead of playing
            save_wave_data(audio, options.outfile)
            print >>sys.stderr, "Saved data to %s" % options.outfile
        else:
            print >>sys.stderr, "Playing..."
            play_audio(audio, wait_for_end=True)
Exemple #2
0
def main():
    usage = "%prog [options]"
    description = "Loads the interactive tonal space gui."
    parser = OptionParser(usage=usage, description=description)
    parser.add_option('-d', '--device', dest="device", action="store", type="int", help="select midi device to output to (run devices.py for a list)", default=0)
    parser.add_option('-i', '--instrument', dest="instrument", action="store", help="midi instrument number (0-127). Default: 16 (organ). Use 'N' not to set any instrument", default="16")
    parser.add_option('-f', '--font-size', dest="font_size", action="store", type="float", help="set the font size of the text in the labels")
    parser.add_option('--dims', '--dimensions', dest="dimensions", action="store", help="dimensions of the tonal space: left,bottom,right,top")
    parser.add_option('-c', '--chord-vocab', dest="chord_vocab", action="store", help="chord vocab file to load chord types from")
    parser.add_option('--hs', '--horiz-space', dest="hspace", action="store_true", help="leave space to the sides of the space if the window's big enough", default=False)
    parser.add_option('--vs', '--vert-space', dest="vspace", action="store_true", help="leave space to the top and bottom of the space if the window's big enough", default=False)
    parser.add_option('-t', '--tuner', dest="tuner", action="store_true", help="run the tonal space tuner")
    parser.add_option('--commands', dest="commands", action="store_true", help="display a list of commands available in the UI and instructions for use")
    options, arguments = parser.parse_args()
    
    if options.commands:
        print TonalSpaceWindow.HELP
        sys.exit(0)
    
    kwargs = {}
    if options.font_size is not None:
        kwargs['font_size'] = options.font_size
    if options.chord_vocab is not None:
        # Load chord types
        vocab = HarmonicalInputFile.from_file(options.chord_vocab, 
                                                    ['chord-vocab'])
        kwargs['chord_types'] = vocab.chords
        kwargs['chord_type_order'] = vocab.chord_names
    if options.instrument.lower() != 'n':
        kwargs['instrument'] = int(options.instrument)
    
    if options.dimensions is not None:
        dims = [int(dim) for dim in options.dimensions.split(",")]
        if len(dims) != 4:
            print >>sys.stderr, "Dimensions must be specified as four values: left,bottom,right,top"
            sys.exit(1)
        x0,y0,x1,y1 = dims
    else:
        x0,y0,x1,y1 = -4,-3,4,3
    
    # Output the midi device we're using
    midi_devs = get_midi_devices()
    if options.device >= len(midi_devs):
        print >>sys.stderr, "No midi device %d" % options.device
        sys.exit(1)
    else:
        print >>sys.stderr, "Sending midi events to device %d: %s" % (
                    options.device,
                    ", ".join(str(x) for x in midi_devs[options.device]))
    
    window = create_window(x0,y0,x1,y1, options.device, 
                    hfill=(not options.hspace), vfill=(not options.vspace), 
                    tuner=options.tuner, **kwargs)
    gtk.main()
Exemple #3
0
def main():
    usage = "%prog [options]"
    description = "Loads the interactive tonal space gui."
    parser = OptionParser(usage=usage, description=description)
    parser.add_option(
        '-d',
        '--device',
        dest="device",
        action="store",
        type="int",
        help="select midi device to output to (run devices.py for a list)",
        default=0)
    parser.add_option(
        '-i',
        '--instrument',
        dest="instrument",
        action="store",
        help=
        "midi instrument number (0-127). Default: 16 (organ). Use 'N' not to set any instrument",
        default="16")
    parser.add_option('-f',
                      '--font-size',
                      dest="font_size",
                      action="store",
                      type="float",
                      help="set the font size of the text in the labels")
    parser.add_option(
        '--dims',
        '--dimensions',
        dest="dimensions",
        action="store",
        help="dimensions of the tonal space: left,bottom,right,top")
    parser.add_option('-c',
                      '--chord-vocab',
                      dest="chord_vocab",
                      action="store",
                      help="chord vocab file to load chord types from")
    parser.add_option(
        '--hs',
        '--horiz-space',
        dest="hspace",
        action="store_true",
        help="leave space to the sides of the space if the window's big enough",
        default=False)
    parser.add_option(
        '--vs',
        '--vert-space',
        dest="vspace",
        action="store_true",
        help=
        "leave space to the top and bottom of the space if the window's big enough",
        default=False)
    parser.add_option('-t',
                      '--tuner',
                      dest="tuner",
                      action="store_true",
                      help="run the tonal space tuner")
    parser.add_option(
        '--commands',
        dest="commands",
        action="store_true",
        help=
        "display a list of commands available in the UI and instructions for use"
    )
    options, arguments = parser.parse_args()

    if options.commands:
        print TonalSpaceWindow.HELP
        sys.exit(0)

    kwargs = {}
    if options.font_size is not None:
        kwargs['font_size'] = options.font_size
    if options.chord_vocab is not None:
        # Load chord types
        vocab = HarmonicalInputFile.from_file(options.chord_vocab,
                                              ['chord-vocab'])
        kwargs['chord_types'] = vocab.chords
        kwargs['chord_type_order'] = vocab.chord_names
    if options.instrument.lower() != 'n':
        kwargs['instrument'] = int(options.instrument)

    if options.dimensions is not None:
        dims = [int(dim) for dim in options.dimensions.split(",")]
        if len(dims) != 4:
            print >> sys.stderr, "Dimensions must be specified as four values: left,bottom,right,top"
            sys.exit(1)
        x0, y0, x1, y1 = dims
    else:
        x0, y0, x1, y1 = -4, -3, 4, 3

    # Output the midi device we're using
    midi_devs = get_midi_devices()
    if options.device >= len(midi_devs):
        print >> sys.stderr, "No midi device %d" % options.device
        sys.exit(1)
    else:
        print >> sys.stderr, "Sending midi events to device %d: %s" % (
            options.device, ", ".join(
                str(x) for x in midi_devs[options.device]))

    window = create_window(x0,
                           y0,
                           x1,
                           y1,
                           options.device,
                           hfill=(not options.hspace),
                           vfill=(not options.vspace),
                           tuner=options.tuner,
                           **kwargs)
    gtk.main()