Ejemplo n.º 1
0
def remixing():
    in_transcript = reader.load_transcript(file1)
    in_transcript2 = reader.load_transcript(file2)
    ngram = MultiInstrumentNGram(nsize)
    ngram.build_from_transcript(in_transcript)
    ngram.build_from_transcript(in_transcript2)
    scheduled_tracks = Generator.generate_multi_instrument_tracks(ngram, ticks)
    return PatternSchedule(scheduled_tracks=scheduled_tracks, meta=in_transcript.get_transcript_meta())
Ejemplo n.º 2
0
def run_from_eminem_music():
    files = listdir("music/Eminem")
    ignored = ["music/Eminem/business.mid", "music/Eminem/forgotaboutdre.mid", "music/Eminem/purple pills.mid"]
               # "music/Eminem/Under_The_Influence.mid"]
    ngram = MultiInstrumentNGram(nsize)
    last_transcript = None
    for file in files:
        path = "music/Eminem/" + file
        if path not in ignored:
            print path
            transcript = reader.load_transcript(path)
            ngram.build_from_transcript(transcript)
            last_transcript = transcript
    scheduled_tracks = Generator.generate_multi_instrument_tracks(ngram, ticks)
    return PatternSchedule(scheduled_tracks=scheduled_tracks, meta=last_transcript.get_transcript_meta())
Ejemplo n.º 3
0
def generate(input_file, ticks, folder='default', nsize=2, policy='random'):
    # properties that should be on the website:
    if policy == 'random':
        Policies.frame_selection_policy = FrameSelectionPolicy.RANDOM
    elif policy == 'highest':
        Policies.frame_selection_policy = FrameSelectionPolicy.HIGHEST_COUNT
    elif policy == 'prob':
        Policies.frame_selection_policy = FrameSelectionPolicy.PROB
    elif policy == 'experimental':
        Policies.frame_selection_policy = FrameSelectionPolicy.EXPERIMENTAL
    else:
        Policies.frame_selection_policy = FrameSelectionPolicy.RANDOM

    # generation code
    name = input_file.split('.')[0]
    output_file_name = "%s/output-%s.mid" % (folder, name)
    in_transcript = reader.load_transcript("%s/%s" % (folder, input_file))
    ngram = MultiInstrumentNGram(nsize)
    ngram.build_from_transcript(in_transcript)
    scheduled_tracks = generate_multi_instrument_tracks(ngram, ticks)
    pattern_schedule = PatternSchedule(scheduled_tracks=scheduled_tracks, meta=in_transcript.get_transcript_meta())
    MidiFileWriter(pattern_schedule).save_to_file(output_file_name)
Ejemplo n.º 4
0
from graphmodel.NGram import MultiInstrumentNGram
from graphmodel.appio import reader
from graphmodel.appio.scheduler import PatternSchedule
from graphmodel.appio.writer import MidiFileWriter

# constants
from graphmodel.model import Policies

nsize = 10
ticks = 10000
Policies.frame_selection_policy = Policies.FrameSelectionPolicy.RANDOM
input_midi_file_name = "music/bach.mid"
output_midi_file_name = "music/bach-out.mid"

# Create a transcript, this encapsulates the midi data into instrument tracks, where each track contains Note objects
transcript = reader.load_transcript(input_midi_file_name)

# Build the ngram from the track
ngram = MultiInstrumentNGram(nsize)
ngram.build_from_transcript(transcript)

# Generate tracks
scheduled_tracks = Generator.generate_multi_instrument_tracks(ngram, ticks)

# Create a Pattern Schedule
pattern_schedule = PatternSchedule(scheduled_tracks=scheduled_tracks, meta=transcript.get_transcript_meta())

# Convert the Pattern Schedule to an actual Midi Pattern and write it to file
MidiFileWriter(pattern_schedule).save_to_file(output_midi_file_name)

# Play the generated music
 def setUp(self):
     file1 = "../music/mary.mid"
     self.transcript = reader.load_transcript(file1)
 def test_merge_tracks(self):
     f = "music/bach.mid"
     transcript2 = reader.load_transcript(f)
Ejemplo n.º 7
0
def reproduce():
    transcript = reader.load_transcript("music/Eminem/forgotaboutdre.mid")
    ngram = MultiInstrumentNGram(nsize)
    ngram.build_from_transcript(transcript)
    scheduled_tracks = Generator.generate_multi_instrument_tracks(ngram, ticks)
    return PatternSchedule(scheduled_tracks=scheduled_tracks, meta=transcript.get_transcript_meta())