Esempio n. 1
0
File: song.py Progetto: tewe/canta
    def write_line_to_midi(self, out_file='midiout.mid'):
        """Creates a midi file and write current line to it"""
        midi = MidiOutFile(out_file)

        #format: 0, nTracks: 1, division: 480
        #----------------------------------
        #
        #Start - track #0
        #sequence_name: Type 0
        #tempo: 500000
        #time_signature: 4 2 24 8
        #note_on  - ch:00,  note:48,  vel:64 time:0
        #note_off - ch:00,  note:48,  vel:40 time:480
        #End of track
        #
        #End of file

        midi.header(0, 1, 480)

        midi.start_of_track()
        midi.sequence_name('Type 0')
        midi.tempo(int(60000000. / self.info['bpm']))
        midi.time_signature(4, 2, 24, 8)
        ch = 0
        i = 0
        line = self.lines[self.line_nr]
        for i, segment in enumerate(line.segments[:-1]):
            midi.note_on(ch, segment.pitch + 60, 0x64)
            #96 is 4x midi clock which is one hole note
            midi.update_time(96 * segment.duration)
            midi.note_off(ch, segment.pitch + 60, 0x40)
            midi.update_time(96  * (line.segments[i+1].time_stamp \
                            - segment.time_stamp - segment.duration))

        midi.note_on(ch, line.segments[-1].pitch + 60, 0x64)
        midi.update_time(96 * line.segments[-1].duration)
        midi.note_off(ch, line.segments[-1].pitch + 60, 0x40)
        midi.update_time(0)
        midi.end_of_track()
        midi.eof(
        )  # currently optional, should it do the write instead of write??
        midi.write()
Esempio n. 2
0
File: song.py Progetto: tewe/canta
    def write_line_to_midi(self, out_file = 'midiout.mid'):
        """Creates a midi file and write current line to it"""
        midi = MidiOutFile(out_file)

        #format: 0, nTracks: 1, division: 480
        #----------------------------------
        #
        #Start - track #0
        #sequence_name: Type 0
        #tempo: 500000
        #time_signature: 4 2 24 8
        #note_on  - ch:00,  note:48,  vel:64 time:0
        #note_off - ch:00,  note:48,  vel:40 time:480
        #End of track
        #
        #End of file


        midi.header(0, 1, 480)

        midi.start_of_track()
        midi.sequence_name('Type 0')
        midi.tempo(int(60000000. / self.info['bpm']))
        midi.time_signature(4, 2, 24, 8)
        ch = 0
        i = 0
        line = self.lines[self.line_nr]
        for i, segment in enumerate(line.segments[:-1]):
            midi.note_on(ch, segment.pitch+60, 0x64)
            #96 is 4x midi clock which is one hole note
            midi.update_time(96 * segment.duration)
            midi.note_off(ch, segment.pitch+60, 0x40)
            midi.update_time(96	 * (line.segments[i+1].time_stamp \
                            - segment.time_stamp - segment.duration))

        midi.note_on(ch, line.segments[-1].pitch+60, 0x64)
        midi.update_time(96 * line.segments[-1].duration)
        midi.note_off(ch, line.segments[-1].pitch+60, 0x40)
        midi.update_time(0)
        midi.end_of_track()
        midi.eof() # currently optional, should it do the write instead of write??
        midi.write()
Esempio n. 3
0
File: song.py Progetto: tewe/canta
    def write_tone_to_midi(self, line_nr, tone_nr, out_file='midiout.mid'):
        """Creates a midi file and write one tone to it

        Keyword arguments:
        line_nr  -- line_nr of the tone
        tone_nr  -- tone_nr in line
        out_file -- output midi file

        """
        midi = MidiOutFile(out_file)

        #format: 0, nTracks: 1, division: 480
        #----------------------------------
        #
        #Start - track #0
        #sequence_name: Type 0
        #tempo: 500000
        #time_signature: 4 2 24 8
        #note_on  - ch:00,  note:48,  vel:64 time:0
        #note_off - ch:00,  note:48,  vel:40 time:480
        #End of track
        #
        #End of file

        midi.header(0, 1, 480)
        midi.start_of_track()
        midi.sequence_name('Type 0')
        midi.tempo(int(60000000. / self.info['bpm']))
        midi.time_signature(4, 2, 24, 8)
        ch = 0
        i = 0
        midi.note_on(ch, self.lines[line_nr].segments[tone_nr].pitch + 60,
                     0x64)
        midi.update_time(96 * self.lines[line_nr].segments[tone_nr].duration)
        midi.note_off(ch, self.lines[line_nr].segments[tone_nr].pitch + 60,
                      0x40)
        midi.update_time(0)
        midi.update_time(0)
        midi.end_of_track()
        midi.eof(
        )  # currently optional, should it do the write instead of write??
        midi.write()
Esempio n. 4
0
File: song.py Progetto: tewe/canta
    def write_tone_to_midi(self, line_nr, tone_nr, out_file = 'midiout.mid'):
        """Creates a midi file and write one tone to it

        Keyword arguments:
        line_nr  -- line_nr of the tone
        tone_nr  -- tone_nr in line
        out_file -- output midi file

        """
        midi = MidiOutFile(out_file)

        #format: 0, nTracks: 1, division: 480
        #----------------------------------
        #
        #Start - track #0
        #sequence_name: Type 0
        #tempo: 500000
        #time_signature: 4 2 24 8
        #note_on  - ch:00,  note:48,  vel:64 time:0
        #note_off - ch:00,  note:48,  vel:40 time:480
        #End of track
        #
        #End of file

        midi.header(0, 1, 480)
        midi.start_of_track()
        midi.sequence_name('Type 0')
        midi.tempo(int(60000000. / self.info['bpm']))
        midi.time_signature(4, 2, 24, 8)
        ch = 0
        i = 0
        midi.note_on(ch, self.lines[line_nr].segments[tone_nr].pitch+60, 0x64)
        midi.update_time(96*self.lines[line_nr].segments[tone_nr].duration)
        midi.note_off(ch, self.lines[line_nr].segments[tone_nr].pitch+60, 0x40)
        midi.update_time(0)
        midi.update_time(0)
        midi.end_of_track()
        midi.eof() # currently optional, should it do the write instead of write??
        midi.write()