Gregory MIDI Parser Usage Examples

Table of Contents

  1. Basic Workflows
  2. Production Scenarios
  3. Data Analysis
  4. Automation Scripts
  5. Troubleshooting Workflows
  6. Advanced Techniques

Basic Workflows

Example 1: Quick File Inspection

Scenario: You receive a MIDI file and want to quickly see what's in it.

Command:

midiparser.exe song.mid --summary

Output:

MIDI Format:    1 (Multiple tracks, synchronous)
Track Count:    16
MIDI Mode:      Roland GS (extended GM)
Division:       480 ticks per quarter note

TRACK 0
Track Name:     Piano
Event Count:    1523

Active Channels:
  Channel  1: [Bank:0] Acoustic Grand Piano  Vol:100 (79%) Pan:Center

TRACK 1
Track Name:     Bass
Event Count:    892

Active Channels:
  Channel  2: [Bank:0] Acoustic Bass  Vol:90 (71%) Pan:Center

What you learned:


Example 2: Identifying Instruments

Scenario: You need to know which instruments are used in a MIDI arrangement.

Command:

midiparser.exe arrangement.mid --summary > instruments.txt

Analysis:
Open instruments.txt and search for "Active Channels" sections. You'll see:

Channel  1: Acoustic Grand Piano
Channel  2: Electric Bass (finger)
Channel  3: Violin
Channel  4: Cello
Channel 10: Standard Kit (drums)

Use Case: Helps you understand orchestration before importing into DAW.


Example 3: Finding Tempo Changes

Scenario: You suspect a MIDI file has tempo changes and want to locate them.

Command:

midiparser.exe song.mid --control | findstr "Tempo"

Output:

[00:00.000] Meta: Tempo  120.00 BPM
  [00:45.123] Meta: Tempo  140.00 BPM
  [02:30.456] Meta: Tempo  120.00 BPM

What you learned:

Use Case: Identifying tempo maps for synchronization or analysis.


Example 4: Analyzing Drum Patterns

Scenario: You want to see what drum hits are used in a pattern.

Command:

midiparser.exe drums.mid

Output (first 30 events):

TRACK 0
Track Name:     Drums
Event Count:    2456

Active Channels:
  Channel 10: Standard Kit  Vol:127 (100%)

Events:
  [00:00.000] Ch10: Note On  Bass Drum 1  Vel:100 (79%)
  [00:00.125] Ch10: Note On  Closed Hi-Hat  Vel:80 (63%)
  [00:00.250] Ch10: Note On  Closed Hi-Hat  Vel:80 (63%)
  [00:00.375] Ch10: Note On  Closed Hi-Hat  Vel:80 (63%)
  [00:00.500] Ch10: Note On  Acoustic Snare  Vel:95 (75%)
  [00:00.500] Ch10: Note On  Closed Hi-Hat  Vel:80 (63%)

What you learned:

Use Case: Understanding drum programming before re-creating in sequencer.


Production Scenarios

Example 5: Preparing for DAW Import

Scenario: You're importing a MIDI file into your DAW and want to know the setup beforehand.

Step 1 - Get Overview:

midiparser.exe project.mid --summary

Step 2 - Export Setup Events:

midiparser.exe project.mid --control --csv setup.csv

Step 3 - Open setup.csv in Excel:

Track AbsoluteTime Channel EventType Description
0 0 0 ProgramChange Program 0 (Acoustic Grand Piano)
0 0 0 ControlChange CC 7 (Volume) Value: 100
1 0 1 ProgramChange Program 33 (Electric Bass finger)
2 0 2 ProgramChange Program 40 (Violin)

What you learned:

Use Case: Ensures smooth DAW import with correct instruments loaded.


Example 6: Troubleshooting Silent Channels

Scenario: After importing MIDI into your DAW, channel 5 is silent.

Command:

midiparser.exe problem.mid --control

Look for:

TRACK 4
Active Channels:
  Channel  5: [Bank:0] Strings  Vol:0 (0%) Pan:Center

Problem Found: Volume is set to 0!

Solution:

Use Case: Quickly diagnose common MIDI import issues.


Example 7: Verifying MIDI Mode for Playback

Scenario: You have a MIDI file that sounds wrong on GM-only devices.

Command:

midiparser.exe file.mid --summary

Output:

MIDI Mode:      Yamaha XG (extended GM)

Channel  3: [Bank:8192] Cutting Noise  Vol:80

What you learned:

Use Case: Understanding compatibility issues before performance.


Data Analysis

Example 8: Counting Note Events

Scenario: You want to know how many notes are in each track for complexity analysis.

Step 1 - Export to CSV:

midiparser.exe complex.mid --csv events.csv

Step 2 - Open in Excel and create pivot table:

Result:

Track NoteOn Count
0 1234
1 892
2 2345
10 5678

What you learned:

Use Case: Analyzing arrangement complexity and density.


Example 9: Creating a Tempo Map

Scenario: You need to create a tempo map for video editing synchronization.

Step 1 - Extract tempo events:

midiparser.exe soundtrack.mid --control > tempos.txt

Step 2 - Filter for tempo changes:

findstr "Tempo" tempos.txt > tempo_map.txt

Result (tempo_map.txt):

[00:00.000] Meta: Tempo  100.00 BPM
  [00:30.000] Meta: Tempo  120.00 BPM
  [01:45.000] Meta: Tempo  90.00 BPM
  [03:00.000] Meta: Tempo  120.00 BPM

Use Case: Synchronizing MIDI playback with video timecode.


Example 10: Analyzing Controller Usage

Scenario: You want to know which controllers are actively used (not just set once).

Command:

midiparser.exe expressive.mid --statistics

Output:

Total Events:    15234

Event Type Breakdown:
  Note On:       4523 (29.7%)
  Note Off:      4523 (29.7%)
  Control Change: 3421 (22.4%)
  Program Change:  16 (0.1%)
  Pitch Bend:     512 (3.4%)

Controllers Used: 1, 7, 10, 11, 64, 91, 93

Notes Per Channel:
  Channel  1: 1234 notes
  Channel  2: 892 notes
  Channel  3: 1523 notes

What you learned:

Use Case: Understanding performance data before editing or quantization.


Automation Scripts

Example 11: Batch Processing MIDI Files

Scenario: You have a folder of 100 MIDI files and want to export to multiple formats.

Batch Script (convert_all.bat):

@echo off
if not exist json mkdir json
if not exist xml mkdir xml
if not exist csv mkdir csv

for %%f in (*.mid) do (
    echo Processing %%f...
    midiparser.exe "%%f" --json "json\%%~nf.json" --xml "xml\%%~nf.xml" --csv "csv\%%~nf.csv"
)

echo Done! Processed all files.

Usage:

cd C:\MidiLibrary
convert_all.bat

Result: 100 files in each format (JSON, XML, CSV) in separate subfolders.

Use Case: Preparing MIDI library for multiple platforms (web app uses JSON, enterprise system uses XML, analysis uses CSV).


Example 12: Creating Track Summary Reports

Scenario: You manage a MIDI library and need summary reports for each file.

PowerShell Script (generate_reports.ps1):

Get-ChildItem -Filter *.mid | ForEach-Object {
    $reportFile = "reports\$($_.BaseName)_report.txt"
    Write-Host "Generating report for $($_.Name)..."

    & midiparser.exe $_.FullName --summary --no-color |
        Out-File -FilePath $reportFile -Encoding UTF8
}

Usage:

New-Item -ItemType Directory -Path reports -Force
.\generate_reports.ps1

Result: Text reports for each MIDI file in reports\ folder.

Use Case: Creating searchable documentation for large MIDI collections.


Example 13: Filtering GS Files

Scenario: You want to separate GS files from GM files in your library.

PowerShell Script (sort_by_mode.ps1):

New-Item -ItemType Directory -Path GM -Force
New-Item -ItemType Directory -Path GS -Force
New-Item -ItemType Directory -Path XG -Force

Get-ChildItem -Filter *.mid | ForEach-Object {
    $output = & midiparser.exe $_.FullName --summary --no-color
    $mode = ($output | Select-String "MIDI Mode:").ToString()

    if ($mode -match "Roland GS") {
        Copy-Item $_.FullName -Destination "GS\"
        Write-Host "$($_.Name) -> GS"
    }
    elseif ($mode -match "Yamaha XG") {
        Copy-Item $_.FullName -Destination "XG\"
        Write-Host "$($_.Name) -> XG"
    }
    else {
        Copy-Item $_.FullName -Destination "GM\"
        Write-Host "$($_.Name) -> GM"
    }
}

Result: Files organized by MIDI mode in separate folders.

Use Case: Organizing library by synthesizer compatibility.


Example 14: Extracting Metadata to Database

Scenario: You're building a MIDI search engine and need to populate a database.

Python Script (extract_metadata.py):

import json
import sqlite3
import subprocess
import os

conn = sqlite3.connect('midi_catalog.db')
cursor = conn.cursor()

cursor.execute('''
    CREATE TABLE IF NOT EXISTS midi_files (
        filename TEXT,
        format INTEGER,
        tracks INTEGER,
        division INTEGER,
        midi_mode TEXT,
        instruments TEXT
    )
''')

for midi_file in os.listdir('.'):
    if not midi_file.endswith('.mid'):
        continue

    json_file = f"{midi_file}.json"
    subprocess.run(['midiparser.exe', midi_file, '--json', json_file])

    with open(json_file, 'r') as f:
        data = json.load(f)

    # Extract instruments from tracks
    instruments = set()
    # ... (parse tracks and extract instrument names)

    cursor.execute('''
        INSERT INTO midi_files VALUES (?, ?, ?, ?, ?, ?)
    ''', (midi_file, data['format'], data['tracks_count'],
          data['division'], data['midi_mode'], ','.join(instruments)))

    os.remove(json_file)  # Clean up

conn.commit()
conn.close()

Use Case: Building searchable MIDI library with full-text search.


Example 14b: Processing XML with PowerShell

Scenario: You need to process XML exports in a .NET/Windows environment.

PowerShell Script (process_xml.ps1):

# Export MIDI file to XML
& midiparser.exe song.mid --xml song.xml

# Load XML using PowerShell's native XML support
[xml]$midiData = Get-Content song.xml

# Access data using dot notation
$format = $midiData.midifile.header.format
$trackCount = $midiData.midifile.header.tracks_count
$midiMode = $midiData.midifile.header.midi_mode

Write-Host "Format: $format"
Write-Host "Tracks: $trackCount"
Write-Host "MIDI Mode: $midiMode"

# Process each track
foreach ($track in $midiData.midifile.tracks.track) {
    $trackNum = $track.number
    $eventCount = $track.event_count
    Write-Host "Track $trackNum has $eventCount events"

    # Access individual events
    foreach ($event in $track.events.event) {
        if ($event.status -eq "0x90" -and [int]$event.data2 -gt 0) {
            # Note On event
            $note = $event.data1
            $velocity = $event.data2
            $time = $event.absolute_time
            Write-Host "  Note On: $note (vel=$velocity) at tick $time"
        }
    }
}

Usage:

.\process_xml.ps1

Output:

Format: 1
Tracks: 16
MIDI Mode: GS
Track 0 has 1523 events
  Note On: 60 (vel=100) at tick 0
  Note On: 62 (vel=95) at tick 480
...

Use Case: Enterprise integration, automated report generation, .NET application processing.


Example 14c: XML Schema Validation

Scenario: You want to ensure XML exports conform to a defined schema.

XSD Schema (midifile.xsd):

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="midifile">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="header">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="format" type="xs:unsignedShort"/>
              <xs:element name="tracks_count" type="xs:unsignedShort"/>
              <xs:element name="division" type="xs:unsignedShort"/>
              <xs:element name="midi_mode" type="xs:string"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="tracks">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="track" maxOccurs="unbounded">
                <!-- Track definition... -->
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

PowerShell Validation:

# Export to XML
& midiparser.exe song.mid --xml song.xml

# Validate against schema
$xml = [xml](Get-Content song.xml)
$schemaSet = New-Object System.Xml.Schema.XmlSchemaSet
$schemaSet.Add("", "midifile.xsd")

$xml.Schemas = $schemaSet
try {
    $xml.Validate({throw $args[1].Message})
    Write-Host "XML is valid!" -ForegroundColor Green
} catch {
    Write-Host "XML validation error: $_" -ForegroundColor Red
}

Use Case: Quality assurance for automated MIDI processing pipelines.


Troubleshooting Workflows

Example 15: Diagnosing Wrong Drum Sounds

Scenario: Drums play wrong sounds on your GM device.

Step 1 - Check drum setup:

midiparser.exe drums.mid --summary

Output:

MIDI Mode:      Roland GS (extended GM)

Channel 10: [Bank:8] Brush Kit  Vol:127

Problem Found: File uses GS bank 8 (Brush Kit), but your device only supports bank 0 (Standard Kit).

Solution: Edit MIDI to remove bank select (CC 0, CC 32) for channel 10, or use GS-compatible device.


Example 16: Finding Note Range

Scenario: Some notes don't play on your 61-key keyboard (C2-C7).

Step 1 - Export to CSV:

midiparser.exe melody.mid --csv notes.csv

Step 2 - Open in Excel and filter:

Results:

Problem Found: Song uses notes outside your keyboard range.

Solution: Transpose MIDI file or play on 88-key keyboard.


Example 17: Checking for Stuck Notes

Scenario: MIDI playback has hanging notes that never stop.

Step 1 - Export to CSV:

midiparser.exe problem.mid --csv events.csv

Step 2 - Analysis in Excel:

  1. Filter for single channel
  2. Count NoteOn events: 1234
  3. Count NoteOff events: 1230

Problem Found: 4 missing NoteOff events!

Solution: Edit MIDI file to add missing NoteOff events, or use "All Notes Off" (CC 123).


Advanced Techniques

Example 18: Comparing Two Arrangements

Scenario: You have original.mid and remix.mid and want to see differences.

Step 1 - Export both to JSON:

midiparser.exe original.mid --json original.json
midiparser.exe remix.mid --json remix.json

Step 2 - Use jq to compare:

jq '.tracks[0].event_count' original.json  # 1234
jq '.tracks[0].event_count' remix.json     # 1567

What you learned:

Use Case: Analyzing arrangement variations.


Example 19: Extracting Controller Automation

Scenario: You want to visualize volume automation in a DAW.

Step 1 - Export to CSV:

midiparser.exe automation.mid --csv data.csv

Step 2 - Filter in Excel:

Step 3 - Create chart:

Result: Line graph showing volume changes over time.

Use Case: Understanding dynamics before mixing.


Example 20: Analyzing SMPTE-Based Files

Scenario: You have a MIDI file synchronized to 30fps video.

Command:

midiparser.exe soundtrack.mid

Output:

Division:       -30 fps, 80 ticks per frame (SMPTE)

Events:
  [00:00.000] Meta: Tempo  (SMPTE mode - tempo ignored)
  [00:00.033] Ch 1: Note On  C4  Vel:100
  [00:01.000] Ch 1: Note Off C4

What you learned:

Use Case: Working with film scoring and video synchronization.


Example 21: Building a Practice Tool

Scenario: You want to extract only the melody line for practice.

Step 1 - Identify melody track:

midiparser.exe song.mid --summary

Output:

TRACK 2
Track Name:     Melody
Active Channels:
  Channel  3: Flute

Step 2 - Export to CSV:

midiparser.exe song.mid --csv full.csv

Step 3 - Filter in Excel:

Step 4 - Save filtered data and import to MIDI editor.

Use Case: Creating practice backing tracks.


Example 22: Detecting Quantization

Scenario: You want to know if a file is quantized or has human timing.

Step 1 - Export to CSV:

midiparser.exe performance.mid --csv timing.csv

Step 2 - Analyze DeltaTime column:

Quantized file:

DeltaTime values: 120, 120, 120, 240, 120, 120 (all multiples of 120)

Human performance:

DeltaTime values: 118, 122, 119, 238, 121, 117 (slight variations)

Use Case: Determining if MIDI is programmed or performed.


Example 23: Creating Instrument Usage Statistics

Scenario: You manage a studio and want to know which GM instruments are most used in your MIDI library.

PowerShell Script (instrument_stats.ps1):

$instruments = @{}

Get-ChildItem -Filter *.mid | ForEach-Object {
    $output = & midiparser.exe $_.FullName --summary --no-color
    $output | Select-String "Channel.*:" | ForEach-Object {
        if ($_ -match ': (.+?)\s+Vol:') {
            $instrument = $matches[1]
            if ($instruments.ContainsKey($instrument)) {
                $instruments[$instrument]++
            } else {
                $instruments[$instrument] = 1
            }
        }
    }
}

$instruments.GetEnumerator() | Sort-Object Value -Descending |
    Format-Table Name, Value -AutoSize

Result:

Name                      Value
----                      -----
Acoustic Grand Piano        45
Electric Bass (finger)      38
Standard Kit                35
Strings                     28
Flute                       12

Use Case: Understanding library composition and popular instruments.


Example 24: Validating MIDI Files Before Mastering

Scenario: Before mastering MIDI files for distribution, you want to ensure they meet standards.

Checklist Script (validate.bat):

@echo off
echo Validating %1...
echo.

echo Checking format...
midiparser.exe %1 --summary | findstr "Format"

echo.
echo Checking for tempo...
midiparser.exe %1 --control | findstr "Tempo" | findstr /C:"[00:00.000]"
if errorlevel 1 echo WARNING: No initial tempo found!

echo.
echo Checking for stuck notes...
midiparser.exe %1 --csv temp.csv
REM (Add CSV analysis for NoteOn/NoteOff balance)

echo.
echo Checking channel usage...
midiparser.exe %1 --statistics

del temp.csv

Use Case: Automated quality assurance for MIDI production.


Summary of Use Cases

Example Use Case Best Tool/Format
1-4 Quick inspection --summary, --control
5-7 Production setup --summary, --control, CSV
8-10 Data analysis --statistics, CSV
11-14 Batch automation JSON, XML, scripting
14b-14c Enterprise integration XML, PowerShell, XSD
15-17 Troubleshooting --summary, CSV, Excel
18-24 Advanced analysis JSON, CSV, scripting

Pro Tips:

  1. Use --no-color when redirecting to files or piping to other commands
  2. Use CSV export for quantitative analysis in Excel or Python
  3. Use JSON export for programmatic processing and web applications
  4. Use XML export for enterprise systems, .NET/Java integration, and schema validation
  5. Use --summary for quick overviews without event spam
  6. Use --control to focus on setup without note data
  7. Use --statistics for high-level metrics and complexity analysis

Last Updated: 2025
See Also: USER_GUIDE.md, API_REFERENCE.md