コード例 #1
0
 def Scale2MIDI(self):  # method to produce a scale
     MyMIDI = MIDIFile(1)  # create a midifile
     self.tracks = (0, 1)
     start_time = 0  # starting time is initialized to be 0
     MyMIDI.addTrackName(self.tracks[0], start_time, "Scale")
     MyMIDI.addTempo(self.tracks[0], start_time, 80)
     self.channels = (0, 1)
     volume_On = 95  # on-beats are accentuated
     volume_Off = 80  # off-beats are attenuated
     if self.flavor == "Major":
         music = class_Keys.Majors(self.Key)
     elif self.flavor == "Minor":
         music = class_Keys.Minors(self.Key)  # write the music on the key that the user has specified
     i = 0
     while i < len(music.output):  # remember music.output is a big list of ''lists of pitch numbers''
         j = 0
         while j < len(music.output[i]):
             if j == 0:  # accentuate the on the beats
                 MyMIDI.addNote(self.tracks[0], self.channels[0], music.output[i][j], start_time, 1 / 3, volume_On)
                 start_time += 1 / 3
                 j += 1
             else:  # off-beats attenuation
                 MyMIDI.addNote(self.tracks[0], self.channels[0], music.output[i][j], start_time, 1 / 3, volume_Off)
                 start_time += 1 / 3
                 j += 1
         i += 1
     binfile = open("Scale.mid", 'wb')  # write the scale to a file named "Scale.mid"
     MyMIDI.writeFile(binfile)
     binfile.close()
     print('A file named Scale.mid has been generated for you. This file contains the entire scales of the key chosen.')
コード例 #2
0
def write_to_midi(composition, comp_name, tempo=120):
    MyMIDI = MIDIFile(1)
    track = 0
    time = 0
    channel = 0
    MyMIDI.addTrackName(track, time, "Composition")
    MyMIDI.addTempo(track, time, tempo)

    for note in composition:
        if note.value != 'silence':
            MyMIDI.addNote(track, channel,
                           convert_pitch_to_MIDI(note.value, note.octave),
                           note.start_time, note.duration, note.volume)

    binfile = open(comp_name + ".mid", 'wb')
    MyMIDI.writeFile(binfile)
    binfile.close()
コード例 #3
0
 def __init__(self):  # these values are all entered by the user via the GUI
     self.TimeSig = None  # get the time signature
     self.Key = None  # on which key should the music be written? gathered from user
     self.Form = None  # for later use if we try to write certain forms of music (Sonata, Concerto, Ritornello, etc.)
     self.Genre = None  # for later use if we try to include playing techniques related to certain genre (add syncopations for Jazz, etc)
     self.flavor = None
     self.instrs = dict([('piano', 0), ('harpsichord', 6), ('glock', 9), ('vibes', 11),
                         ('marimba', 12), ('organ', 19), ('guitar', 24), ('bass', 32),
                         ('violin', 40), ('viola', 41), ('cello', 42), ('contrabass', 43), ('harp', 46), ('timps', 47),
                         ('voice', 54), ('trumpet', 56), ('tuba', 58), ('horn', 60),
                         ('alto sax', 65), ('oboe', 68), ('bassoon', 70), ('clarinet', 71),
                         ('flute', 73), ('recorder', 74), ('bottle', 75), ('whistle', 78),
                         ('fifths', 96), ('halo', 94), ('goblins', 101), ('koto', 107),
                         ('bagpipe', 109), ('taiko', 116), ('toms', 117), ('breath', 121),
                         ('seashore', 122), ('bird', 123), ('phone', 124), ('applause', 126)])  # dictionary of possible instruments, linking the string name of the instrument to its number so that it can be accessed in the Midi file
     self.MyMIDI = MIDIFile(1) 
     self.tracks = (0, 1)
     self.channels = (0, 1, 2, 3)  # four channels, (one for Soprano, Alto, Tenor, Bass)
     self.length = 20  # 20 as the default number of measures
コード例 #4
0
      
      8 : ("b3", 59),
      9 : ("a3", 57),
     10 : ("g3", 55),
     11 : ("f3", 53),
     12 : ("e3", 52),
     13 : ("d3", 50),
     14 : ("c3", 48),
     
     15 : ("b2", 47),
     16 : ("a2", 45),
     17 : ("f2", 53),
}
"""
# Create the MIDIFile Object
MyMIDI = MIDIFile(1)


# Add track name and tempo. The first argument to addTrackName and
# addTempo is the time to write the event.
def newNote(time, duration, pitch):
    track = 0
    MyMIDI.addTrackName(track, time, "Sample Track")
    MyMIDI.addTempo(track, time, 120)
    channel = 0
    volume = 100
    MyMIDI.addNote(track, channel, pitch, time, duration, volume)


newNote(0, 1, 60)  #do
newNote(1, 1, 60)  #do
コード例 #5
0
'''
Created on Jul 30, 2013
modified from the single-note-example form midiutil
@author: bailey
'''
############################################################################
# A sample program to create a multi-track MIDI file, add notes,
# and write to disk.
############################################################################

#Import the library
from MidiFile3 import MIDIFile

# Create the MIDIFile Object
MyMIDI = MIDIFile(2)  ### the integer = the number of parallel tracks available

# Add track names and tempo. The first argument to addTrackName and
# addTempo is the time to write the event. This initialises the tracks.
tracks = (0, 1)
start_time = 0

MyMIDI.addTrackName(tracks[0], start_time, "Piano")
MyMIDI.addTempo(tracks[0], start_time, 120)
#MyMIDI.addTrackName(tracks[1],start_time,"Cello")
#MyMIDI.addTempo(tracks[1],start_time, 120)

# Each track can hold multiple channels, we'll use two for now
channels = (0, 1)

# Add a note. addNote expects the following information:
#channel = some integer >= 0