Beispiel #1
0
def percussive_samples(mod):
    subsongs = linearize_subsongs(mod, 1)
    rows = flatten(r for (_, r) in subsongs)
    volumes = [header.volume for header in mod.sample_headers]
    notes = list(rows_to_mod_notes(rows, volumes))
    return {sample for (sample, p) in sample_props(mod, notes).items()
            if p.is_percussive}
Beispiel #2
0
def main():
    args = docopt(__doc__, version='MIDI file generator 1.0')
    SP.enabled = args['--verbose']

    # Parse
    mod_file = args['<mod>']
    programs = parse_programs(args['--programs'])

    mod_file = Path(mod_file)
    midi_mapping = args['--midi-mapping']
    if midi_mapping != 'auto':
        with open(midi_mapping, 'r') as f:
            midi_mapping = load(f)
        midi_mapping = {int(k): v for (k, v) in midi_mapping.items()}

    mod = load_file(mod_file)
    subsongs = linearize_subsongs(mod, 1)
    volumes = [header.volume for header in mod.sample_headers]
    for idx, (_, rows) in enumerate(subsongs):
        notes = rows_to_mod_notes(rows, volumes)
        if midi_mapping == 'auto':
            props = sample_props(mod, notes)
            samples = [(sample_idx, props.is_percussive, props.note_duration)
                       for (sample_idx, props) in props.items()]
            midi_mapping = assign_instruments(samples, programs)
        midi_file = 'test-%02d.mid' % idx
        notes_to_midi_file(notes, midi_file, midi_mapping)
Beispiel #3
0
def mod_file_to_patterns(mod_file):
    SP.print(str(mod_file))
    try:
        mod = load_file(mod_file)
    except PowerPackerModule:
        return []
    rows = linearize_rows(mod)
    volumes = [header.volume for header in mod.sample_headers]
    notes = rows_to_mod_notes(rows, volumes)
    percussive = {s for (s, p) in sample_props(mod, notes) if p.is_percussive}
    return [pattern_to_matrix(pat, percussive) for pat in mod.patterns]
Beispiel #4
0
def mod_file_to_piano_roll(file_path):
    SP.header('PARSING %s' % str(file_path))
    try:
        mod = load_file(file_path)
    except PowerPackerModule:
        SP.print('PowerPacker module.')
        return None
    rows = linearize_rows(mod)
    volumes = [header.volume for header in mod.sample_headers]
    notes = rows_to_mod_notes(rows, volumes)
    props = sample_props(mod, notes)
    mat = notes_to_matrix(notes, props, len(rows))
    SP.leave()
    return mat
Beispiel #5
0
def main():
    args = docopt(__doc__, version='MIDI file generator 1.0')
    SP.enabled = args['--verbose']
    file_path = args['<mod>']

    mod = load_file(file_path)
    rows = list(linearize_subsongs(mod, 1))[0][1]
    n_rows = len(rows)
    sample_headers = mod.sample_headers
    volumes = [header.volume for header in mod.sample_headers]
    notes = rows_to_mod_notes(rows, volumes)
    props = sample_props(mod, notes)
    mel_notes = {n for n in notes if not props[n.sample_idx].is_percussive}
    perc_notes = {n for n in notes if props[n.sample_idx].is_percussive}
    pitches = {n.pitch_idx for n in mel_notes}
    n_unique_mel_notes = len(pitches)
    pitch_range = max(pitches) - min(pitches)
    header = [
        '#', 'MC freq', 'Notes', 'Uniq', 'PCs', 'Longest rep', 'Size', 'Dur',
        'Repeat pct', 'Max ringout', 'Perc?'
    ]
    row_fmt = [
        '%2d', '%.2f', '%3d', '%2d', '%2d', '%3d', '%5d', '%2d', '%.2f',
        '%.2f', lambda x: 'T' if x else 'F'
    ]

    # Make a table
    rows = [(sample, ) + p for (sample, p) in props.items()]
    print_term_table(row_fmt, rows, header, 'rrrrrrrrrrc')

    n_chords, n_diss_chords = dissonant_chords(mel_notes)
    diss_frac = n_diss_chords / n_chords if n_chords else 0.0

    header = ['Item', 'Value']
    rows = [['Rows', n_rows], ['Melodic notes',
                               len(mel_notes)],
            ['Percussive notes', len(perc_notes)],
            ['Unique melodic notes', n_unique_mel_notes],
            ['Pitch range', pitch_range], ['Chords', n_chords],
            ['Chord dissonance', '%.2f' % diss_frac]]
    print_term_table(['%s', '%s'], rows, ['Key', 'Value'], 'lr')