DEFAULT_BASE_FREQUENCY = 528

if __name__ == '__main__':
    scale_args = "The supported scales are: " + ", ".join(map(lambda x: x.__name__, scales.SCALES))

    parser = argparse.ArgumentParser(description='MSP homework 9 scale interval comparison')
    parser.add_argument('scale0', type=str, help=scale_args)
    parser.add_argument('scale1', type=str, help="Same as scale0")
    parser.add_argument('-f', '--basefreq', type=int, default=DEFAULT_BASE_FREQUENCY)
    parser.add_argument('-i', '-i0', '--intervals0', type=str,
                        help='List of interval for scale0. Default: all interval in an octave.')
    parser.add_argument('-i1', '--intervals1', type=str,
                        help='List of interval for scale1. Default: the same as intervals0')
    namespace = parser.parse_args()

    scale0 = scales.parse([namespace.scale0, namespace.basefreq])
    scale1 = scales.parse([namespace.scale1, namespace.basefreq])

    if namespace.intervals0:
        intervals0 = map(int, namespace.intervals0.split())
    else:
        intervals0 = range(len(scale0) + 1)

    if namespace.intervals1:
        intervals1 = map(int, namespace.intervals1.split())
        assert (len(intervals0) == len(intervals1))
    else:
        intervals1 = intervals0

    intervals = zip(intervals0, intervals1)
Beispiel #2
0
def parse(args, sample_rate, buffer_size):
    name = args[0]

    if name == ScaleSynth.__name__:
        scale = scales.parse(args[1:])
        instrument = ScaleSynth(sample_rate, buffer_size, scale)
        global scale_synth_cnt
        instrument.name_id = instrument.name_id + str(scale_synth_cnt)
        scale_synth_cnt += 1
        return instrument

    elif name == SingleSoundSampler.__name__:
        instrument = SingleSoundSampler(args[1])
        return instrument

    elif name == Sampler.__name__:
        instrument = Sampler(args[1:])
        global sampler_cnt
        instrument.name_id = instrument.name_id + str(sampler_cnt)
        sampler_cnt += 1
        return instrument

    elif name == PerfectTriads.__name__:
        scale = scales.parse(args[1:])
        instrument = PerfectTriads(sample_rate, buffer_size, scale)
        return instrument

    elif name == Drumset.__name__:
        kick = Drumset.KICK
        snare = Drumset.SNARE
        hihat = Drumset.HIHAT
        crash = Drumset.CRASH
        tom1 = Drumset.TOM1
        tom2 = Drumset.TOM2
        ride = Drumset.RIDE
        i = 0
        while i < len(args):
            if args[i] == 'kick':
                kick = args[i + 1]
                i += 1
            elif args[i] == 'snare':
                snare = args[i + 1]
                i += 1
            elif args[i] == 'hihat':
                hihat = args[i + 1]
                i += 1
            elif args[i] == 'crash':
                crash = args[i + 1]
                i += 1
            elif args[i] == 'tom1':
                tom1 = args[i + 1]
                i += 1
            elif args[i] == 'tom2':
                tom2 = args[i + 1]
                i += 1
            elif args[i] == 'ride':
                ride = args[i + 1]
                i += 1
            i += 1
            instrument = Drumset(kick=kick,
                                 snare=snare,
                                 tom1=tom1,
                                 tom2=tom2,
                                 hihat=hihat,
                                 crash=crash,
                                 ride=ride)
            global drumset_cnt
            instrument.name_id = instrument.name_id + str(drumset_cnt)
            drumset_cnt += 1
            return instrument


    raise Exception('Unknown instrument: %s' % name)