Example #1
0
def createTrack(iterations):
    # seed_array = seed()
    universe = initializeUniverse()

    for i in range(iterations):
        generation(universe)
    midi_file_out.write_Track("test.mid", t, 300)
Example #2
0
def write_midi_files(name,data):
    tracks = make_tracks(data)
    ret = []
    for i in xrange(len(tracks)):
        filename = name + ('.%s.mid' % i)
        ret.append(filename)
        write_Track(filename, tracks[i], 180, repeat=1)
    return ret
def vector_to_midi(arr, filename="nice.midi"):
  track = Track()
  for note_arr in arr:
    note_num = int(np.argmax(note_arr))
    note = Note()
    note.from_int(note_num - 3)
    track.add_notes(note)
  write_Track(filename, track)
  print("Done!")
 def saveTrack(self, filename):
     """
     save track in piano class to file
     :param filename: name of file
     :return: none
     """
     track = self.track
     path = "static/library/"
     file = path + filename + ".mid"
     midi_file_out.write_Track(file, track)
Example #5
0
    def to_midi(self, fp=''):
        if len(fp)>0:
            outf = r'C:\Users\Sam\Documents\Sidewinder\local files\\'+f'{fp}.mid'
        else:
            outf = r'C:\Users\Sam\Documents\Sidewinder\local files\midi_out.mid'

        if type(self.source) == Composition:
            midi_file_out.write_Composition(outf, self.source, repeat=0, verbose=True)
        elif type(self.passage) == Track:
            midi_file_out.write_Track(outf, self.passage, repeat=0, verbose=True)
 def saveComposition(self, filename, track):
     """
     function to save customized composition to file
     :param filename: name of file
     :param track: Track() object to save
     :return: none
     """
     path = "static/library/"
     file = path + filename + ".mid"
     midi_file_out.write_Track(file, track)
Example #7
0
def track_to_midi(t, name='midi_out\\untitled', save=True, timestamp=True):
    '''
    Saves a mingus Track t to a midi file {name}.mid (automatically adds a timestamp)
    Returns name of the created file
    '''
    if timestamp:
        name += datetime.now().strftime('%Y%m%d%H%M%S')

    if save:
        midi_file_out.write_Track(f'{name}.mid', t)
        print(f'Saved: {name}.mid')
        return name

    return None
def generate_and_write_music(
        output_file,
        music_length,
        lengths_distribution,
        bpm,
        ):
    import mingus.core.notes as notes
    from mingus.containers.note import Note
    from mingus.containers.track import Track
    from mingus.midi import midi_file_out

    track = Track()

    for note, length in generate_music(music_length, lengths_distribution, note_base=36):
        n = Note()
        n.from_int(note)
        track.add_notes(n, length)

    midi_file_out.write_Track(output_file, track, bpm=bpm)
Example #9
0
def generate_track(g, n, name):
    root = np.random.randint(0, n)
    edges = nx.bfs_edges(g.G, root)
    nodes = [root] + [v for u, v in edges]
    m = MidiInstrument(4)
    t = Track()
    track = []
    t.instrument = m
    nNotes = 0
    print("##### Creating Tracks")
    for x in nodes:
        value = t.add_notes(NoteContainer(g.G.nodes[x]["note"]),
                            g.G.nodes[x]["duration"])
        t.bars[-1].set_meter((n, 1))
        track.append(g.G.nodes[x]["note"])
        nNotes = nNotes + 1
    print("##### Notes Generated:")
    print(*t)
    print("##### Number of notes:")
    print(nNotes)
    midi_file_out.write_Track(name + ".mid", t)
    return t
Example #10
0
def main():
    track = generate()
    filename = "out.midi"
    mmmfo.write_Track(filename, track)
    subprocess.run(["musescore", filename])
from mingus.midi import fluidsynth, midi_file_out
from mingus.midi.fluidsynth import FluidSynthSequencer
from mingus.containers import Bar, Track, Composition
from mingus.containers.instrument import MidiInstrument
from midi2audio import FluidSynth

ins = MidiInstrument()
ins.instrument_nr = 1
player = FluidSynthSequencer()
fluidsynth.init('Timbre.sf2', player)
t = Track()
t.add_notes("C-3", 4)
t.instrument = ins
midi_file_out.write_Track('instrumenttest1.mid', t, bpm=500)
FluidSynth("Timbre.sf2").midi_to_audio('instrumenttest1.mid',
                                       'instrumenttest1.wav')
Example #12
0
def play(file_name):
    for i in itertools.count():
        path = os.getcwd() + "/musicpiece" + str(i)
        if os.path.exists(path):
            pass
        else:
            os.mkdir(path)
            break
    fluidsynth.init("Timbre.sf2", snareplayer, file=path + '/snare.wav')
    snareplayer.main_volume(channel=9, value=70)
    snareplayer.play_Track(finalpercussion.snaretrack, channel=9, bpm=100)
    fluidsynth.initialized = False
    fluidsynth.init("Timbre.sf2", highhatplayer, file=path + '/highhat.wav')
    highhatplayer.main_volume(channel=9, value=50)
    highhatplayer.play_Track(finalpercussion.highhattrack, channel=9, bpm=100)
    fluidsynth.initialized = False
    fluidsynth.init("Timbre.sf2", cymbalplayer, file=path + '/cymbal.wav')
    cymbalplayer.main_volume(channel=9, value=70)
    cymbalplayer.play_Track(finalpercussion.cymbaltrack, channel=9, bpm=100)
    fluidsynth.initialized = False
    fluidsynth.init("Timbre.sf2", tomplayer, file=path + '/tom.wav')
    tomplayer.main_volume(channel=9, value=70)
    tomplayer.play_Track(finalpercussion.tomtrack, channel=9, bpm=100)
    fluidsynth.initialized = False
    fluidsynth.init("Timbre.sf2", baseplayer, file=path + '/base.wav')
    baseplayer.main_volume(channel=9, value=100)
    baseplayer.play_Track(finalpercussion.basetrack, channel=9, bpm=100)
    fluidsynth.initialized = False
    fluidsynth.init("Timbre.sf2", lefthandplayer, file=path + '/lefthand.wav')
    lefthandplayer.main_volume(channel=1, value=70)
    lefthandplayer.play_Track(lefthandtrack2, channel=1, bpm=100)
    midi_file_out.write_Track(path + '/guitar.mid',
                              guitartrack1,
                              bpm=timeconstant)
    FluidSynth('Timbre.sf2').midi_to_audio(path + '/guitar.mid',
                                           path + '/guitar.wav')
    midi_file_out.write_Track(path + '/string.mid',
                              strintrack1,
                              bpm=timeconstant)
    FluidSynth('Timbre.sf2').midi_to_audio(path + '/string.mid',
                                           path + '/string.wav')
    midi_file_out.write_Track(path + '/basse.mid',
                              bassetrack1,
                              bpm=timeconstant)
    FluidSynth('Timbre.sf2').midi_to_audio(path + '/basse.mid',
                                           path + '/basse.wav')
    midi_file_out.write_Track(path + '/brass.mid',
                              brasstrack1,
                              bpm=timeconstant)
    FluidSynth('Timbre.sf2').midi_to_audio(path + '/brass.mid',
                                           path + '/brass.wav')
    midi_file_out.write_Track(path + '/electricguitar.mid',
                              electricguitartrack1,
                              bpm=timeconstant)
    FluidSynth('Timbre.sf2').midi_to_audio(path + '/electricguitar.mid',
                                           path + '/electricguitar.wav')
    midi_file_out.write_Track(path + '/synth.mid',
                              synthtrack1,
                              bpm=timeconstant)
    FluidSynth('Timbre.sf2').midi_to_audio(path + '/synth.mid',
                                           path + '/synth.wav')
    midi_file_out.write_Track(path + '/frhorn.mid',
                              frhorntrack1,
                              bpm=timeconstant)
    FluidSynth('Timbre.sf2').midi_to_audio(path + '/frhorn.mid',
                                           path + '/frhorn.wav')
    midi_file_out.write_Track(path + '/righthand.mid',
                              righthandtrack1,
                              bpm=timeconstant)
    FluidSynth('Timbre.sf2').midi_to_audio(path + '/righthand.mid',
                                           path + '/righthand.wav')
    sound1 = AudioSegment.from_wav(path + "/righthand.wav")
    sound1 += 5
    sound2 = AudioSegment.from_wav(path + "/lefthand.wav")
    sound3 = AudioSegment.from_wav(path + "/snare.wav")
    sound4 = AudioSegment.from_wav(path + "/base.wav")
    sound5 = AudioSegment.from_wav(path + "/highhat.wav")
    sound6 = AudioSegment.from_wav(path + "/cymbal.wav")
    sound7 = AudioSegment.from_wav(path + "/tom.wav")
    sound8 = AudioSegment.from_wav(path + "/guitar.wav")
    sound9 = AudioSegment.from_wav(path + "/string.wav")
    sound9 -= 4
    sound10 = AudioSegment.from_wav(path + "/basse.wav")
    sound10 -= 3
    sound11 = AudioSegment.from_wav(path + "/brass.wav")
    sound11 -= 3
    sound12 = AudioSegment.from_wav(path + "/electricguitar.wav")
    sound12 -= 7
    sound13 = AudioSegment.from_wav(path + "/synth.wav")
    sound13 -= 12
    sound14 = AudioSegment.from_wav(path + "/frhorn.wav")

    combined = sound2.overlay(
        sound1.overlay(
            sound3.overlay(
                sound4.overlay(
                    sound5.overlay(
                        sound6.overlay(
                            sound7.overlay(
                                sound8.overlay(
                                    sound9.overlay(
                                        sound10.overlay(
                                            sound11.overlay(
                                                sound12.overlay(
                                                    sound13.overlay(
                                                        sound14)))))))))))))
    combined.export(path + "/" + file_name, format='wav')
    print "the file name is " + file_name
Example #13
0
def exportToWav(melody):
    MidiFileOut.write_Track(OUTMID, melody.notes, melody.tempo)
    sf = SOUNDFONT_PATH + melody.instrument + ".sf2"
    fs = FluidSynth(sf)
    fs.midi_to_audio(OUTMID, OUTWAV)
Example #14
0
def to_midi(filename, track, bpm = 120):
    midi_file_out.write_Track(filename, track, bpm)
    print "Written", filename
Example #15
0
            leadBar.place_notes(n, lastNoteLength)
        else:
            # add a rest
            leadBar.place_rest(choice(noteLengths))

    lead.append(leadBar)

    for note in container:
        note = note.octave_down()

    noteLengths = [1]
    bar = Bar(key, meter)
    bar.place_notes(container, choice(noteLengths))
    comp.append(bar)

track = Track()
for bar in comp:
    track.add_bar(bar)

leadTrack = Track()
for bar in lead:
    leadTrack.add_bar(bar)

composition = Composition()
composition.add_track(track)
# composition.add_track(leadTrack)

MidiFile.write_Composition("musgen.mid", composition)
MidiFile.write_Track("musgenLead.mid", leadTrack)
Example #16
0
def to_midi(filename, track, bpm=120):
    midi_file_out.write_Track(filename, track, bpm)
    print "Written", filename
Example #17
0
    name = note_string[0:1].upper()
    number = name_to_number.NOTES.index(name)
    acc = accidentals(note_string)
    return mod12(number + acc)


name_to_number.NOTES = "C . D . E F . G . A . B".split()

if __name__ == '__main__':
    import argparse
    import random
    # from mingus.containers.bar import Bar
    from mingus.containers.track import Track

    notes = [0]
    for t in range(30):
        note = notes[-1]
        notes.append(note + random.randint(0, 12))

    t = Track()
    notes = map(note_name, notes)
    for n in notes:
        t.add_notes(n)

    parser = argparse.ArgumentParser()
    parser.add_argument('--output', type=str, default='out.mid')
    args = parser.parse_args()

    from mingus.midi import midi_file_out
    midi_file_out.write_Track(args.output, t)
Example #18
0
        return diatonic
    
    def get_meter_from_rhythm(self,rhythm):

        rhythm_16 = []
        for i in rhythm:
            if i == 16 :
                rhythm_16.append(i)
            elif i == 8 :
                rhythm_16.extend([16,16]) 
            elif i == 4 :
                rhythm_16.extend([16,16,16,16]) 
            elif i == 2 :
                rhythm_16.extend([16,16,16,16,16,16,16,16]) 
        #2/4   2 note de patrimi
        meter = (len(rhythm_16),16)
        
        return meter



    



trackin = GenerateTrack()
trackin = trackin.generate()


midi.write_Track("drums1.mid",trackin,bpm=100)
Example #19
0
#### Create midi file:
#Combine Notes_r and Notes_l from the df into 1 congomerate
combined_notes = []
for i in range(df.shape[0]):
    try:
        combined_notes.append(df.iloc[i]["Notes_l"] + df.iloc[i]["Notes_r"])
    except:
        if df.iloc[i]["Notes_l"] != "":
            combined_notes.append(df.iloc[i]["Notes_l"])
        else:
            combined_notes.append(df.iloc[i]["Notes_r"])
df["Notes_both"] = combined_notes

#Now create a track by adding these notes from both hands
t_both = Track()
for i in set(df["Measure"].unique()[:-1]):
    b = Bar(key=keysig)
    subset = df[df["Measure"] == i]
    for j, k in zip(subset["Notes_both"], subset["Diff"]):
        if j:  #If note is not NaN
            nc = NoteContainer(j)  #Define the note
            b.place_notes(nc, k)  #Add note to bar with length
    t_both + b
MidiFileOut.write_Track(outputname + ".mid", t_both, bpm=bpm)  #Create midi

#Display first page of composition
try:
    Image(filename=outputname + ".png")
except:
    Image(filename=outputname + "-page1.png")
Example #20
0
def write_midi_files(data):
    tracks = make_tracks(data)
    for i in xrange(len(tracks)):
        write_Track('track%s.mid' % i, tracks[i], 180, repeat=1)
Example #21
0
from mingus.containers import Composition
from mingus.containers import Track
from mingus.containers import Bar
from mingus.containers import Note, NoteContainer

from mingus.midi import midi_file_out

drum_scale = {
  "snare": Note("E", 2),
  "bass": Note("C", 2),
  "hightom": Note("B", 2),
  "midtom": Note("A", 2),
  "lowtom": Note("G", 2),
  "crash": Note("A", 3),
  "hatclosed": Note("G#", 2),
  "hatopen": Note("A#", 2),
  "ride": Note("B", 3),
  }

values = [value.quarter, value.eighth, value.sixteenth, value.triplet(value.eighth), value.triplet(value.sixteenth)]
#for i in range(0, 24):
#  bar =
drum_track = Track()

for note in drum_scale:
  drum_track.add_notes(drum_scale[note])

print(drum_track)
midi_file_out.write_Track("drum_scale.mid", drum_track)