{
    "mode": "perldoc",
    "parameter": "MIDI",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/MIDI/json",
    "generated": "2026-06-17T13:18:23Z",
    "synopsis": "use MIDI;\nuse strict;\nuse warnings;\nmy @events = (\n['textevent',0, 'MORE COWBELL'],\n['settempo', 0, 450000], # 1qn = .45 seconds\n);\nfor (1 .. 20) {\npush @events,\n['noteon' , 90,  9, 56, 127],\n['noteoff',  6,  9, 56, 127],\n;\n}\nforeach my $delay (reverse(1..96)) {\npush @events,\n['noteon' ,      0,  9, 56, 127],\n['noteoff', $delay,  9, 56, 127],\n;\n}\nmy $cowbelltrack = MIDI::Track->new({ 'events' => \\@events });\nmy $opus = MIDI::Opus->new(\n{ 'format' => 0, 'ticks' => 96, 'tracks' => [ $cowbelltrack ] } );\n$opus->writetofile( 'cowbell.mid' );",
    "sections": {
        "NAME": {
            "content": "MIDI - read, compose, modify, and write MIDI files\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use MIDI;\nuse strict;\nuse warnings;\nmy @events = (\n['textevent',0, 'MORE COWBELL'],\n['settempo', 0, 450000], # 1qn = .45 seconds\n);\n\nfor (1 .. 20) {\npush @events,\n['noteon' , 90,  9, 56, 127],\n['noteoff',  6,  9, 56, 127],\n;\n}\nforeach my $delay (reverse(1..96)) {\npush @events,\n['noteon' ,      0,  9, 56, 127],\n['noteoff', $delay,  9, 56, 127],\n;\n}\n\nmy $cowbelltrack = MIDI::Track->new({ 'events' => \\@events });\nmy $opus = MIDI::Opus->new(\n{ 'format' => 0, 'ticks' => 96, 'tracks' => [ $cowbelltrack ] } );\n$opus->writetofile( 'cowbell.mid' );\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This suite of modules provides routines for reading, composing, modifying, and writing MIDI\nfiles.\n\nFrom FOLDOC (\"http://wombat.doc.ic.ac.uk/foldoc/\"):\n\nMIDI, Musical Instrument Digital Interface\n\n<multimedia, file format> (MIDI /mi'-dee/, /mee'-dee/) A hardware specification and protocol\nused to communicate note and effect information between synthesisers, computers, music\nkeyboards, controllers and other electronic music devices. [...]\n\nThe basic unit of information is a \"note on/off\" event which includes a note number (pitch)\nand key velocity (loudness). There are many other message types for events such as pitch\nbend, patch changes and synthesizer-specific events for loading new patches etc.\n\nThere is a file format for expressing MIDI data which is like a dump of data sent over a\nMIDI port. [...]\n",
            "subsections": []
        },
        "COMPONENTS": {
            "content": "The MIDI-Perl suite consists of these modules:\n\nMIDI (which you're looking at), MIDI::Opus, MIDI::Track, MIDI::Event, MIDI::Score, and\nMIDI::Simple. All of these contain documentation in pod format. You should read all of these\npods.\n\nThe order you want to read them in will depend on what you want to do with this suite of\nmodules: if you are focused on manipulating the guts of existing MIDI files, read the pods in\nthe order given above.\n\nBut if you aim to compose music with this suite, read this pod, then MIDI::Score and\nMIDI::Simple, and then skim the rest.\n",
            "subsections": []
        },
        "INTRODUCTION": {
            "content": "This suite of modules is basically object-oriented, with the exception of MIDI::Simple. MIDI\nopuses (\"songs\") are represented as objects belonging to the class MIDI::Opus. An opus contains\ntracks, which are objects belonging to the class MIDI::Track. A track will generally contain a\nlist of events, where each event is a list consisting of a command, a delta-time, and some\nnumber of parameters. In other words, opuses and tracks are objects, and the events in a track\ncomprise a LoL (and if you don't know what an LoL is, you must read perllol).\n\nFurthermore, for some purposes it's useful to analyze the totality of a track's events as a\n\"score\" -- where a score consists of notes where each event is a list consisting of a command, a\ntime offset from the start of the track, and some number of parameters. This is the level of\nabstraction that MIDI::Score and MIDI::Simple deal with.\n\nWhile this suite does provide some functionality accessible only if you're comfortable with\nvarious kinds of references, and while there are some options that deal with the guts of MIDI\nencoding, you can (I hope) get along just fine with just a basic grasp of the MIDI \"standard\",\nand a command of LoLs. I have tried, at various points in this documentation, to point out what\nthings are not likely to be of use to the casual user.\n",
            "subsections": []
        },
        "GOODIES": {
            "content": "The bare module MIDI.pm doesn't *do* much more than \"use\" the necessary component submodules\n(i.e., all except MIDI::Simple). But it does provide some hashes you might find useful:\n\n%MIDI::note2number and %MIDI::number2note\n%MIDI::number2note corresponds MIDI note numbers to a more comprehensible representation\n(e.g., 68 to 'Gs4', for G-sharp, octave 4); %MIDI::note2number is the reverse. Have a look\nat the source to see the contents of the hash.\n\n%MIDI::patch2number and %MIDI::number2patch\n%MIDI::number2patch corresponds General MIDI patch numbers (0 to 127) to English names\n(e.g., 79 to 'Ocarina'); %MIDI::patch2number is the reverse. Have a look at the source to\nsee the contents of the hash.\n\n%MIDI::notenum2percussion and %MIDI::percussion2notenum\n%MIDI::notenum2percussion corresponds General MIDI Percussion Keys to English names (e.g.,\n56 to 'Cowbell') -- but note that only numbers 35 to 81 (inclusive) are defined;\n%MIDI::percussion2notenum is the reverse. Have a look at the source to see the contents of\nthe hash.\n",
            "subsections": []
        },
        "BRIEF GLOSSARY": {
            "content": "This glossary defines just a few terms, just enough so you can (hopefully) make some sense of\nthe documentation for this suite of modules. If you're going to do anything serious with these\nmodules, however, you *should really* invest in a good book about the MIDI standard -- see the\nReferences.\n\nchannel: a logical channel to which control changes and patch changes apply, and in which MIDI\n(note-related) events occur.\n\ncontrol: one of the various numeric parameters associated with a given channel. Like S registers\nin Hayes-set modems, MIDI controls consist of a few well-known registers, and beyond that, it's\npatch-specific and/or sequencer-specific.\n\ndelta-time: the time (in ticks) that a sequencer should wait between playing the previous event\nand playing the current event.\n\nmeta-event: any of a mixed bag of events whose common trait is merely that they are similarly\nencoded. Most meta-events apply to all channels, unlike events, which mostly apply to just one\nchannel.\n\nnote: my oversimplistic term for items in a score structure.\n\nopus: the term I prefer for a piece of music, as represented in MIDI. Most specs use the term\n\"song\", but I think that this falsely implies that MIDI files represent vocal pieces.\n\npatch: an electronic model of the sound of a given notional instrument.\n\nrunning status: a form of modest compression where an event lacking an event command byte (a\n\"status\" byte) is to be interpreted as having the same event command as the preceding event --\nwhich may, in turn, lack a status byte and may have to be interpreted as having the same event\ncommand as *its* previous event, and so on back.\n\nscore: a structure of notes like an event structure, but where notes are represented as single\nitems, and where timing of items is absolute from the beginning of the track, instead of being\nrepresented in delta-times.\n\nsong: what some MIDI specs call a song, I call an opus.\n\nsequencer: a device or program that interprets and acts on MIDI data. This prototypically refers\nto synthesizers or drum machines, but can also refer to more limited devices, such as mixers or\neven lighting control systems.\n\nstatus: a synonym for \"event\".\n\nsysex: a chunk of binary data encapsulated in the MIDI data stream, for whatever purpose.\n\ntext event: any of the several meta-events (one of which is actually called 'textevent') that\nconveys text. Most often used to just label tracks, note the instruments used for a track, or to\nprovide metainformation about copyright, performer, and piece title and author.\n\ntick: the timing unit in a MIDI opus.\n\nvariable-length encoding: an encoding method identical to what Perl calls the 'w' (BER, Basic\nEncoding Rules) pack/unpack format for integers.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "<http://interglacial.com/~sburke/midi-perl/> -- the MIDI-Perl homepage on the Interwebs!\n\n<http://search.cpan.org/search?m=module&q=MIDI&n=100> -- All the MIDI things in CPAN!\n",
            "subsections": []
        },
        "REFERENCES": {
            "content": "Christian Braut. *The Musician's Guide to Midi.* ISBN 0782112854. [This one is indispensible,\nbut sadly out of print. Look at abebooks.com for it maybe --SMB]\n\nLangston, Peter S. 1998. \"Little Music Languages\", p.587-656 in: Salus, Peter H,. editor in\nchief, /Handbook of Programming Languages/, vol. 3. MacMillan Technical, 1998. [The volume it's\nin is probably not worth the money, but see if you can at least glance at this article anyway.\nIt's not often you see 70 pages written on music languages. --SMB]\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright (c) 1998-2005 Sean M. Burke. All rights reserved.\n\nThis library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "Sean M. Burke \"sburke@cpan.org\" (until 2010)\n\nDarrell Conklin \"conklin@cpan.org\" (from 2010)\n",
            "subsections": []
        }
    },
    "summary": "MIDI - read, compose, modify, and write MIDI files",
    "flags": [],
    "examples": [],
    "see_also": []
}