시리즈: Music
python
30 줄
· 업데이트 2026-02-03
getMidiNotes.py
Music/getMidiNotes.py
import mido
from collections import defaultdict
# Load MIDI file
midi_file = mido.MidiFile('./cs3-1pre.mid')
# Dictionary to store notes by channel
channel_notes = defaultdict(list)
# Track time to keep absolute time
absolute_time = 0
# Parse each message in each track
for i, track in enumerate(midi_file.tracks):
time = 0
for msg in track:
time += msg.time
if msg.type == 'note_on' and msg.velocity > 0:
channel_notes[msg.channel].append({
'note': msg.note,
'velocity': msg.velocity,
'time': time,
'track': i
})
# Print results
for channel, notes in channel_notes.items():
print(f"\nChannel {channel}:")
for note in notes:
print(f" Track {note['track']}, Note {note['note']}, Velocity {note['velocity']}, Time {note['time']}")
관련 글
Music
python
업데이트 2026-02-03
essentia.py
essentia.py — python source code from the Music learning materials (Music/essentia.py).
글 읽기 →
Music
python
업데이트 2026-02-03
ex01.py
ex01.py — python source code from the Music learning materials (Music/ex01.py).
글 읽기 →
Music
python
업데이트 2026-02-03
extract_midi_notes.py
extract_midi_notes.py — python source code from the Music learning materials (Music/extract_midi_notes.py).
글 읽기 →
Music
python
업데이트 2026-02-03
markovchain_v2.py
markovchain_v2.py — python source code from the Music learning materials (Music/markovchain_v2.py).
글 읽기 →
Music
python
업데이트 2026-02-03
musc5211.py
musc5211.py — python source code from the Music learning materials (Music/musc5211.py).
글 읽기 →
Music
python
업데이트 2026-02-03
music_ai_util.py
music_ai_util.py — python source code from the Music learning materials (Music/music_ai_util.py).
글 읽기 →