Пример #1
0
def extract_events(input_path):
    note_items, tempo_items = utils.read_items(input_path)
    note_items = utils.quantize_items(note_items)
    max_time = note_items[-1].end
    items = tempo_items + note_items
    groups = utils.group_items(items, max_time)
    events = utils.item2event(groups)
    return events
Пример #2
0
 def extract_events(self, input_path):
     note_items, tempo_items = utils.read_items(input_path)
     note_items = utils.quantize_items(note_items)
     max_time = note_items[-1].end
     if 'chord' in self.checkpoint_path:
         chord_items = utils.extract_chords(note_items)
         items = chord_items + tempo_items + note_items
     else:
         items = tempo_items + note_items
     groups = utils.group_items(items, max_time)
     events = utils.item2event(groups)
     return events
Пример #3
0
def extract_tuple_events(input_path):
    note_items, tempo_items = utils.read_items(input_path)
    note_items = note_items[
        0]  # assume there is only 1 track, so this get the first track
    note_items = utils.quantize_items(note_items)
    max_time = note_items[-1].end
    items = tempo_items + note_items
    groups = utils.group_items(items, max_time)
    # events = utils.item2event(groups)
    events = item2event(groups)
    # print(*events, sep='\n')
    events = convert_to_tuple_events(events, tempo_items)
    return events
Пример #4
0
def extract_events(input_path, extract_chords=True):
    try:
        note_items, tempo_items = utils.read_items(input_path)
        note_items = utils.quantize_items(note_items)
        max_time = note_items[-1].end
        if extract_chords:
            chord_items = utils.extract_chords(note_items)
            items = chord_items + tempo_items + note_items
        else:
            items = tempo_items + note_items
        groups = utils.group_items(items, max_time)
        events = utils.item2event(groups)
    except:
        return None
    return ['{}_{}'.format(e.name, e.value) for e in events]
Пример #5
0
    def extract_events(self, input_path, transposition_steps=0):
        if self.transpose_input_midi_to_key:
            transposition_steps = transpose.get_number_of_steps_for_transposition_to(
                input_path, self.transpose_input_midi_to_key)
        if transposition_steps != 0:
            print("Transposing {} steps to {}.".format(
                transposition_steps, self.transpose_input_midi_to_key))

        note_items, tempo_items = utils.read_items(
            input_path, transposition_steps=transposition_steps)
        note_items = utils.quantize_items(note_items)
        max_time = note_items[-1].end
        if self.use_chords:
            chord_items = utils.extract_chords(note_items)
            items = chord_items + tempo_items + note_items
        else:
            items = tempo_items + note_items
        groups = utils.group_items(items, max_time)
        events = utils.item2event(groups)
        return events
Пример #6
0
    def mtom_extract_events(self, input_path, ticks=120):
        """Parse midi file to extract events (e.g. Note On, Note Velocity, etc.).

        Args:
            input_path: path to current midi file.
            ticks: used to quantize timings of items in song.

        Return values:
            events: list of events for song.
            normal_six_seven_note_items: list of note items for normal 6/7's in
                                         song.
            raised_six_seven_note_items: list of note items for raised 6/7's in
                                         song.
        """
        note_items, \
        normal_six_seven_note_items, \
        raised_six_seven_note_items, \
        tempo_items = self.mtom_read_items(input_path)

        normal_six_seven_note_indices = self.get_six_seven_note_indices(note_items, normal_six_seven_note_items)
        raised_six_seven_note_indices = self.get_six_seven_note_indices(note_items, raised_six_seven_note_items)

        note_items = utils.quantize_items(note_items, ticks)

        normal_six_seven_note_items = [note_items[idx] for idx in normal_six_seven_note_indices]
        raised_six_seven_note_items = [note_items[idx] for idx in raised_six_seven_note_indices]

        max_time = note_items[-1].end
        if 'chord' in self.checkpoint_path:
            chord_items = utils.extract_chords(note_items)
            items = chord_items + tempo_items + note_items
        else:
            items = tempo_items + note_items

        groups = utils.group_items(items, max_time)
        events = utils.item2event(groups)

        return events, normal_six_seven_note_items, raised_six_seven_note_items
Пример #7
0
import miditoolkit
import utils

midi_obj = miditoolkit.midi.parser.MidiFile('../Audio-to-midi/output/054.mid')

# print(*midi_obj.instruments[0].notes, sep='\n')

# print(*midi_obj.tempo_changes[:10], sep='\n')

note_items, tempo_items = utils.read_items('../Audio-to-midi/output/054.mid')

# print(*note_items, sep='\n')

# print(*tempo_items[:10], sep='\n')

note_items = utils.quantize_items(note_items)

print(*note_items, sep='\n')

chord_items = utils.extract_chords(note_items)

print(*chord_items, sep='\n')

items = chord_items + tempo_items + note_items
max_time = note_items[-1].end
groups = utils.group_items(items, max_time)

for g in groups:
    print(*g, sep='\n')
    print()