初始化内容
This commit is contained in:
Vendored
+161
@@ -0,0 +1,161 @@
|
||||
//
|
||||
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
|
||||
// Creation Date: Mon Feb 16 12:26:32 PST 2015 Adapted from binasc program.
|
||||
// Last Modified: Sat Apr 21 10:52:19 PDT 2018 Removed using namespace std;
|
||||
// Filename: midifile/include/Binasc.h
|
||||
// Website: http://midifile.sapp.org
|
||||
// Syntax: C++11
|
||||
// vim: ts=3 noexpandtab
|
||||
//
|
||||
// description: Interface to convert bytes between binary and ASCII forms.
|
||||
//
|
||||
|
||||
#ifndef _BINASC_H_INCLUDED
|
||||
#define _BINASC_H_INCLUDED
|
||||
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace smf {
|
||||
|
||||
typedef unsigned char uchar;
|
||||
typedef unsigned short ushort;
|
||||
typedef unsigned long ulong;
|
||||
|
||||
class Binasc {
|
||||
|
||||
public:
|
||||
Binasc (void);
|
||||
|
||||
~Binasc ();
|
||||
|
||||
// functions for setting options:
|
||||
int setLineLength (int length);
|
||||
int getLineLength (void);
|
||||
int setLineBytes (int length);
|
||||
int getLineBytes (void);
|
||||
void setComments (int state);
|
||||
void setCommentsOn (void);
|
||||
void setCommentsOff (void);
|
||||
int getComments (void);
|
||||
void setBytes (int state);
|
||||
void setBytesOn (void);
|
||||
void setBytesOff (void);
|
||||
int getBytes (void);
|
||||
void setMidi (int state);
|
||||
void setMidiOn (void);
|
||||
void setMidiOff (void);
|
||||
int getMidi (void);
|
||||
|
||||
// functions for converting into a binary file:
|
||||
int writeToBinary (const std::string& outfile,
|
||||
const std::string& infile);
|
||||
int writeToBinary (const std::string& outfile,
|
||||
std::istream& input);
|
||||
int writeToBinary (std::ostream& out,
|
||||
const std::string& infile);
|
||||
int writeToBinary (std::ostream& out,
|
||||
std::istream& input);
|
||||
|
||||
// functions for converting into an ASCII file with hex bytes:
|
||||
int readFromBinary (const std::string&
|
||||
outfile,
|
||||
const std::string& infile);
|
||||
int readFromBinary (const std::string& outfile,
|
||||
std::istream& input);
|
||||
int readFromBinary (std::ostream& out,
|
||||
const std::string& infile);
|
||||
int readFromBinary (std::ostream& out,
|
||||
std::istream& input);
|
||||
|
||||
// static functions for writing ordered bytes:
|
||||
static std::ostream& writeLittleEndianUShort (std::ostream& out,
|
||||
ushort value);
|
||||
static std::ostream& writeBigEndianUShort (std::ostream& out,
|
||||
ushort value);
|
||||
static std::ostream& writeLittleEndianShort (std::ostream& out,
|
||||
short value);
|
||||
static std::ostream& writeBigEndianShort (std::ostream& out,
|
||||
short value);
|
||||
static std::ostream& writeLittleEndianULong (std::ostream& out,
|
||||
ulong value);
|
||||
static std::ostream& writeBigEndianULong (std::ostream& out,
|
||||
ulong value);
|
||||
static std::ostream& writeLittleEndianLong (std::ostream& out,
|
||||
long value);
|
||||
static std::ostream& writeBigEndianLong (std::ostream& out,
|
||||
long value);
|
||||
static std::ostream& writeLittleEndianFloat (std::ostream& out,
|
||||
float value);
|
||||
static std::ostream& writeBigEndianFloat (std::ostream& out,
|
||||
float value);
|
||||
static std::ostream& writeLittleEndianDouble (std::ostream& out,
|
||||
double value);
|
||||
static std::ostream& writeBigEndianDouble (std::ostream& out,
|
||||
double value);
|
||||
|
||||
static std::string keyToPitchName (int key);
|
||||
|
||||
protected:
|
||||
int m_bytesQ; // option for printing hex bytes in ASCII output.
|
||||
int m_commentsQ; // option for printing comments in ASCII output.
|
||||
int m_midiQ; // output ASCII data as parsed MIDI file.
|
||||
int m_maxLineLength;// number of character in ASCII output on a line.
|
||||
int m_maxLineBytes; // number of hex bytes in ASCII output on a line.
|
||||
|
||||
private:
|
||||
// helper functions for reading ASCII content to conver to binary:
|
||||
int processLine (std::ostream& out,
|
||||
const std::string& input,
|
||||
int lineNum);
|
||||
int processAsciiWord (std::ostream& out,
|
||||
const std::string& input,
|
||||
int lineNum);
|
||||
int processStringWord (std::ostream& out,
|
||||
const std::string& input,
|
||||
int lineNum);
|
||||
int processBinaryWord (std::ostream& out,
|
||||
const std::string& input,
|
||||
int lineNum);
|
||||
int processDecimalWord (std::ostream& out,
|
||||
const std::string& input,
|
||||
int lineNum);
|
||||
int processHexWord (std::ostream& out,
|
||||
const std::string& input,
|
||||
int lineNum);
|
||||
int processVlvWord (std::ostream& out,
|
||||
const std::string& input,
|
||||
int lineNum);
|
||||
int processMidiPitchBendWord(std::ostream& out,
|
||||
const std::string& input,
|
||||
int lineNum);
|
||||
int processMidiTempoWord (std::ostream& out,
|
||||
const std::string& input,
|
||||
int lineNum);
|
||||
|
||||
// helper functions for reading binary content to convert to ASCII:
|
||||
int outputStyleAscii (std::ostream& out, std::istream& input);
|
||||
int outputStyleBinary (std::ostream& out, std::istream& input);
|
||||
int outputStyleBoth (std::ostream& out, std::istream& input);
|
||||
int outputStyleMidi (std::ostream& out, std::istream& input);
|
||||
|
||||
// MIDI parsing helper functions:
|
||||
int readMidiEvent (std::ostream& out, std::istream& infile,
|
||||
int& trackbytes, int& command);
|
||||
int getVLV (std::istream& infile, int& trackbytes);
|
||||
int getWord (std::string& word, const std::string& input,
|
||||
const std::string& terminators, int index);
|
||||
|
||||
static const char *GMinstrument[128];
|
||||
|
||||
};
|
||||
|
||||
} // end of namespace smf
|
||||
|
||||
#endif /* _BINASC_H_INCLUDED */
|
||||
|
||||
|
||||
|
||||
Vendored
+78
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
|
||||
// Creation Date: Sat Feb 14 21:47:39 PST 2015
|
||||
// Last Modified: Sat Apr 21 10:52:19 PDT 2018 Removed using namespace std;
|
||||
// Filename: midifile/include/MidiEvent.h
|
||||
// Website: http://midifile.sapp.org
|
||||
// Syntax: C++11
|
||||
// vim: ts=3 noexpandtab
|
||||
//
|
||||
// Description: A class which stores a MidiMessage and a timestamp
|
||||
// for the MidiFile class.
|
||||
//
|
||||
|
||||
#ifndef _MIDIEVENT_H_INCLUDED
|
||||
#define _MIDIEVENT_H_INCLUDED
|
||||
|
||||
#include "MidiMessage.h"
|
||||
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace smf {
|
||||
|
||||
class MidiEvent : public MidiMessage {
|
||||
public:
|
||||
MidiEvent (void);
|
||||
MidiEvent (int command);
|
||||
MidiEvent (int command, int param1);
|
||||
MidiEvent (int command, int param1, int param2);
|
||||
MidiEvent (const MidiMessage& message);
|
||||
MidiEvent (const MidiEvent& mfevent);
|
||||
MidiEvent (int aTime, int aTrack,
|
||||
std::vector<uchar>& message);
|
||||
|
||||
~MidiEvent ();
|
||||
|
||||
MidiEvent& operator= (const MidiEvent& mfevent);
|
||||
MidiEvent& operator= (const MidiMessage& message);
|
||||
MidiEvent& operator= (const std::vector<uchar>& bytes);
|
||||
MidiEvent& operator= (const std::vector<char>& bytes);
|
||||
MidiEvent& operator= (const std::vector<int>& bytes);
|
||||
|
||||
void clearVariables (void);
|
||||
|
||||
// functions related to event linking (note-ons to note-offs).
|
||||
void unlinkEvent (void);
|
||||
void unlinkEvents (void);
|
||||
void linkEvent (MidiEvent* mev);
|
||||
void linkEvents (MidiEvent* mev);
|
||||
void linkEvent (MidiEvent& mev);
|
||||
void linkEvents (MidiEvent& mev);
|
||||
int isLinked (void) const;
|
||||
MidiEvent* getLinkedEvent (void);
|
||||
const MidiEvent* getLinkedEvent (void) const;
|
||||
int getTickDuration (void) const;
|
||||
double getDurationInSeconds (void) const;
|
||||
|
||||
int tick; // delta or absolute MIDI ticks
|
||||
int track; // [original] track number of event in MIDI file
|
||||
double seconds; // calculated time in sec. (after doTimeAnalysis())
|
||||
int seq; // sorting sequence number of event
|
||||
|
||||
private:
|
||||
MidiEvent* m_eventlink; // used to match note-ons and note-offs
|
||||
|
||||
};
|
||||
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, MidiEvent& event);
|
||||
|
||||
|
||||
} // end of namespace smf
|
||||
|
||||
#endif /* _MIDIEVENT_H_INCLUDED */
|
||||
|
||||
|
||||
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
|
||||
// Creation Date: Sat Feb 14 21:55:38 PST 2015
|
||||
// Last Modified: Sat Apr 21 10:52:19 PDT 2018 Removed using namespace std;
|
||||
// Filename: midifile/include/MidiEventList.h
|
||||
// Website: http://midifile.sapp.org
|
||||
// Syntax: C++11
|
||||
// vim: ts=3 noexpandtab
|
||||
//
|
||||
// Description: A class that stores a MidiEvents for a MidiFile track.
|
||||
//
|
||||
|
||||
#ifndef _MIDIEVENTLIST_H_INCLUDED
|
||||
#define _MIDIEVENTLIST_H_INCLUDED
|
||||
|
||||
#include "MidiEvent.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace smf {
|
||||
|
||||
class MidiEventList {
|
||||
public:
|
||||
MidiEventList (void);
|
||||
MidiEventList (const MidiEventList& other);
|
||||
MidiEventList (MidiEventList&& other);
|
||||
|
||||
~MidiEventList ();
|
||||
|
||||
MidiEventList& operator= (MidiEventList& other);
|
||||
MidiEvent& operator[] (int index);
|
||||
const MidiEvent& operator[] (int index) const;
|
||||
|
||||
MidiEvent& back (void);
|
||||
const MidiEvent& back (void) const;
|
||||
MidiEvent& last (void);
|
||||
const MidiEvent& last (void) const;
|
||||
MidiEvent& getEvent (int index);
|
||||
const MidiEvent& getEvent (int index) const;
|
||||
void clear (void);
|
||||
void reserve (int rsize);
|
||||
int getEventCount (void) const;
|
||||
int getSize (void) const;
|
||||
int size (void) const;
|
||||
void removeEmpties (void);
|
||||
int linkNotePairs (void);
|
||||
int linkEventPairs (void);
|
||||
void clearLinks (void);
|
||||
void clearSequence (void);
|
||||
int markSequence (int sequence = 1);
|
||||
|
||||
int push (MidiEvent& event);
|
||||
int push_back (MidiEvent& event);
|
||||
int append (MidiEvent& event);
|
||||
|
||||
// careful when using these, intended for internal use in MidiFile class:
|
||||
void detach (void);
|
||||
int push_back_no_copy (MidiEvent* event);
|
||||
|
||||
// access to the list of MidiEvents for sorting with an external function:
|
||||
MidiEvent** data (void);
|
||||
|
||||
protected:
|
||||
std::vector<MidiEvent*> list;
|
||||
|
||||
private:
|
||||
void sort (void);
|
||||
|
||||
// MidiFile class calls sort()
|
||||
friend class MidiFile;
|
||||
};
|
||||
|
||||
|
||||
int eventcompare(const void* a, const void* b);
|
||||
|
||||
} // end of namespace smf
|
||||
|
||||
#endif /* _MIDIEVENTLIST_H_INCLUDED */
|
||||
|
||||
|
||||
|
||||
Vendored
+332
@@ -0,0 +1,332 @@
|
||||
//
|
||||
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
|
||||
// Creation Date: Fri Nov 26 14:12:01 PST 1999
|
||||
// Last Modified: Mon Jan 18 20:54:04 PST 2021 Added readSmf().
|
||||
// Filename: midifile/include/MidiFile.h
|
||||
// Website: http://midifile.sapp.org
|
||||
// Syntax: C++11
|
||||
// vim: ts=3 noexpandtab
|
||||
//
|
||||
// Description: A class that can read/write Standard MIDI files.
|
||||
// MIDI data is stored by track in an array.
|
||||
//
|
||||
|
||||
#ifndef _MIDIFILE_H_INCLUDED
|
||||
#define _MIDIFILE_H_INCLUDED
|
||||
|
||||
#include "MidiEventList.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <istream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace smf {
|
||||
|
||||
enum {
|
||||
TRACK_STATE_SPLIT = 0, // Tracks are separated into separate vector postions.
|
||||
TRACK_STATE_JOINED = 1 // Tracks are merged into a single vector position,
|
||||
}; // like a Type-0 MIDI file, but reversible.
|
||||
|
||||
enum {
|
||||
TIME_STATE_DELTA = 0, // MidiMessage::ticks are in delta time format (like MIDI file).
|
||||
TIME_STATE_ABSOLUTE = 1 // MidiMessage::ticks are in absolute time format (0=start time).
|
||||
};
|
||||
|
||||
class _TickTime {
|
||||
public:
|
||||
int tick;
|
||||
double seconds;
|
||||
};
|
||||
|
||||
|
||||
class MidiFile {
|
||||
public:
|
||||
MidiFile (void);
|
||||
MidiFile (const std::string& filename);
|
||||
MidiFile (std::istream& input);
|
||||
MidiFile (const MidiFile& other);
|
||||
MidiFile (MidiFile&& other);
|
||||
|
||||
~MidiFile ();
|
||||
|
||||
MidiFile& operator= (const MidiFile& other);
|
||||
MidiFile& operator= (MidiFile&& other);
|
||||
|
||||
// Reading/writing functions:
|
||||
|
||||
// Auto-detected SMF or ASCII-encoded SMF (decoded with Binasc class):
|
||||
bool read (const std::string& filename);
|
||||
bool read (std::istream& instream);
|
||||
bool readBase64 (const std::string& base64data);
|
||||
bool readBase64 (std::istream& instream);
|
||||
|
||||
// Only allow Standard MIDI File input:
|
||||
bool readSmf (const std::string& filename);
|
||||
bool readSmf (std::istream& instream);
|
||||
|
||||
bool write (const std::string& filename);
|
||||
bool write (std::ostream& out);
|
||||
bool writeBase64 (const std::string& out, int width = 0);
|
||||
bool writeBase64 (std::ostream& out, int width = 0);
|
||||
std::string getBase64 (int width = 0);
|
||||
bool writeHex (const std::string& filename, int width = 25);
|
||||
bool writeHex (std::ostream& out, int width = 25);
|
||||
bool writeBinasc (const std::string& filename);
|
||||
bool writeBinasc (std::ostream& out);
|
||||
bool writeBinascWithComments (const std::string& filename);
|
||||
bool writeBinascWithComments (std::ostream& out);
|
||||
bool status (void) const;
|
||||
|
||||
// track-related functions:
|
||||
const MidiEventList& operator[] (int aTrack) const;
|
||||
MidiEventList& operator[] (int aTrack);
|
||||
int getTrackCount (void) const;
|
||||
int getNumTracks (void) const;
|
||||
int size (void) const;
|
||||
void removeEmpties (void);
|
||||
|
||||
// tick-related functions:
|
||||
void makeDeltaTicks (void);
|
||||
void deltaTicks (void);
|
||||
void makeAbsoluteTicks (void);
|
||||
void absoluteTicks (void);
|
||||
int getTickState (void) const;
|
||||
bool isDeltaTicks (void) const;
|
||||
bool isAbsoluteTicks (void) const;
|
||||
|
||||
// join/split track functionality:
|
||||
void joinTracks (void);
|
||||
void splitTracks (void);
|
||||
void splitTracksByChannel (void);
|
||||
int getTrackState (void) const;
|
||||
int hasJoinedTracks (void) const;
|
||||
int hasSplitTracks (void) const;
|
||||
int getSplitTrack (int track, int index) const;
|
||||
int getSplitTrack (int index) const;
|
||||
|
||||
// track sorting funcionality:
|
||||
void sortTrack (int track);
|
||||
void sortTracks (void);
|
||||
void markSequence (void);
|
||||
void markSequence (int track, int sequence = 1);
|
||||
void clearSequence (void);
|
||||
void clearSequence (int track);
|
||||
|
||||
// track manipulation functionality:
|
||||
int addTrack (void);
|
||||
int addTrack (int count);
|
||||
int addTracks (int count);
|
||||
void deleteTrack (int aTrack);
|
||||
void mergeTracks (int aTrack1, int aTrack2);
|
||||
int getTrackCountAsType1 (void);
|
||||
|
||||
// ticks-per-quarter related functions:
|
||||
void setMillisecondTicks (void);
|
||||
int getTicksPerQuarterNote (void) const;
|
||||
int getTPQ (void) const;
|
||||
void setTicksPerQuarterNote (int ticks);
|
||||
void setTPQ (int ticks);
|
||||
|
||||
// physical-time analysis functions:
|
||||
void doTimeAnalysis (void);
|
||||
double getTimeInSeconds (int aTrack, int anIndex);
|
||||
double getTimeInSeconds (int tickvalue);
|
||||
double getAbsoluteTickTime (double starttime);
|
||||
int getFileDurationInTicks (void);
|
||||
double getFileDurationInQuarters (void);
|
||||
double getFileDurationInSeconds (void);
|
||||
|
||||
// note-analysis functions:
|
||||
int linkNotePairs (void);
|
||||
int linkEventPairs (void);
|
||||
void clearLinks (void);
|
||||
|
||||
// filename functions:
|
||||
void setFilename (const std::string& aname);
|
||||
const char* getFilename (void) const;
|
||||
|
||||
// event functionality:
|
||||
MidiEvent* addEvent (int aTrack, int aTick,
|
||||
std::vector<uchar>& midiData);
|
||||
MidiEvent* addEvent (MidiEvent& mfevent);
|
||||
MidiEvent* addEvent (int aTrack, MidiEvent& mfevent);
|
||||
MidiEvent& getEvent (int aTrack, int anIndex);
|
||||
const MidiEvent& getEvent (int aTrack, int anIndex) const;
|
||||
int getEventCount (int aTrack) const;
|
||||
int getNumEvents (int aTrack) const;
|
||||
void allocateEvents (int track, int aSize);
|
||||
void erase (void);
|
||||
void clear (void);
|
||||
void clear_no_deallocate (void);
|
||||
|
||||
// MIDI message adding convenience functions:
|
||||
MidiEvent* addNoteOn (int aTrack, int aTick,
|
||||
int aChannel, int key,
|
||||
int vel);
|
||||
MidiEvent* addNoteOff (int aTrack, int aTick,
|
||||
int aChannel, int key,
|
||||
int vel);
|
||||
MidiEvent* addNoteOff (int aTrack, int aTick,
|
||||
int aChannel, int key);
|
||||
MidiEvent* addController (int aTrack, int aTick,
|
||||
int aChannel, int num,
|
||||
int value);
|
||||
MidiEvent* addPatchChange (int aTrack, int aTick,
|
||||
int aChannel, int patchnum);
|
||||
MidiEvent* addTimbre (int aTrack, int aTick,
|
||||
int aChannel, int patchnum);
|
||||
MidiEvent* addPitchBend (int aTrack, int aTick,
|
||||
int aChannel, double amount);
|
||||
|
||||
// RPN settings:
|
||||
void setPitchBendRange (int aTrack, int aTick,
|
||||
int aChannel, double range);
|
||||
|
||||
// Controller message adding convenience functions:
|
||||
MidiEvent* addSustain (int aTrack, int aTick,
|
||||
int aChannel, int value);
|
||||
MidiEvent* addSustainPedal (int aTrack, int aTick,
|
||||
int aChannel, int value);
|
||||
MidiEvent* addSustainOn (int aTrack, int aTick,
|
||||
int aChannel);
|
||||
MidiEvent* addSustainPedalOn (int aTrack, int aTick,
|
||||
int aChannel);
|
||||
MidiEvent* addSustainOff (int aTrack, int aTick,
|
||||
int aChannel);
|
||||
MidiEvent* addSustainPedalOff (int aTrack, int aTick,
|
||||
int aChannel);
|
||||
|
||||
// Meta-event adding convenience functions:
|
||||
MidiEvent* addMetaEvent (int aTrack, int aTick,
|
||||
int aType,
|
||||
std::vector<uchar>& metaData);
|
||||
MidiEvent* addMetaEvent (int aTrack, int aTick,
|
||||
int aType,
|
||||
const std::string& metaData);
|
||||
MidiEvent* addText (int aTrack, int aTick,
|
||||
const std::string& text);
|
||||
MidiEvent* addCopyright (int aTrack, int aTick,
|
||||
const std::string& text);
|
||||
MidiEvent* addTrackName (int aTrack, int aTick,
|
||||
const std::string& name);
|
||||
MidiEvent* addInstrumentName (int aTrack, int aTick,
|
||||
const std::string& name);
|
||||
MidiEvent* addLyric (int aTrack, int aTick,
|
||||
const std::string& text);
|
||||
MidiEvent* addMarker (int aTrack, int aTick,
|
||||
const std::string& text);
|
||||
MidiEvent* addCue (int aTrack, int aTick,
|
||||
const std::string& text);
|
||||
MidiEvent* addTempo (int aTrack, int aTick,
|
||||
double aTempo);
|
||||
MidiEvent* addKeySignature (int aTrack, int aTick,
|
||||
int fifths, bool mode = 0);
|
||||
MidiEvent* addTimeSignature (int aTrack, int aTick,
|
||||
int top, int bottom,
|
||||
int clocksPerClick = 24,
|
||||
int num32dsPerQuarter = 8);
|
||||
MidiEvent* addCompoundTimeSignature(int aTrack, int aTick,
|
||||
int top, int bottom,
|
||||
int clocksPerClick = 36,
|
||||
int num32dsPerQuarter = 8);
|
||||
|
||||
uchar readByte (std::istream& input);
|
||||
|
||||
// static functions:
|
||||
static ushort readLittleEndian2Bytes (std::istream& input);
|
||||
static ulong readLittleEndian4Bytes (std::istream& input);
|
||||
static std::ostream& writeLittleEndianUShort (std::ostream& out,
|
||||
ushort value);
|
||||
static std::ostream& writeBigEndianUShort (std::ostream& out,
|
||||
ushort value);
|
||||
static std::ostream& writeLittleEndianShort (std::ostream& out,
|
||||
short value);
|
||||
static std::ostream& writeBigEndianShort (std::ostream& out,
|
||||
short value);
|
||||
static std::ostream& writeLittleEndianULong (std::ostream& out,
|
||||
ulong value);
|
||||
static std::ostream& writeBigEndianULong (std::ostream& out,
|
||||
ulong value);
|
||||
static std::ostream& writeLittleEndianLong (std::ostream& out,
|
||||
long value);
|
||||
static std::ostream& writeBigEndianLong (std::ostream& out,
|
||||
long value);
|
||||
static std::ostream& writeLittleEndianFloat (std::ostream& out,
|
||||
float value);
|
||||
static std::ostream& writeBigEndianFloat (std::ostream& out,
|
||||
float value);
|
||||
static std::ostream& writeLittleEndianDouble (std::ostream& out,
|
||||
double value);
|
||||
static std::ostream& writeBigEndianDouble (std::ostream& out,
|
||||
double value);
|
||||
static std::string getGMInstrumentName (int patchIndex);
|
||||
|
||||
protected:
|
||||
// m_events == Lists of MidiEvents for each MIDI file track.
|
||||
std::vector<MidiEventList*> m_events;
|
||||
|
||||
// m_ticksPerQuarterNote == A value for the MIDI file header
|
||||
// which represents the number of ticks in a quarter note
|
||||
// that are used as units for the delta times for MIDI events
|
||||
// in MIDI file track data.
|
||||
int m_ticksPerQuarterNote = 120;
|
||||
|
||||
// m_theTrackState == state variable for whether the tracks
|
||||
// are joined or split.
|
||||
int m_theTrackState = TRACK_STATE_SPLIT;
|
||||
|
||||
// m_theTimeState == state variable for whether the MidiEvent::tick
|
||||
// variable contain absolute ticks since the start of the file's
|
||||
// time, or delta ticks since the last MIDI event in the track.
|
||||
int m_theTimeState = TIME_STATE_ABSOLUTE;
|
||||
|
||||
// m_readFileName == the filename of the last file read into
|
||||
// the object.
|
||||
std::string m_readFileName;
|
||||
|
||||
// m_timemapvalid ==
|
||||
bool m_timemapvalid = false;
|
||||
|
||||
// m_timemap ==
|
||||
std::vector<_TickTime> m_timemap;
|
||||
|
||||
// m_rwstatus == True if last read was successful, false if a problem.
|
||||
bool m_rwstatus = true;
|
||||
|
||||
// m_linkedEventQ == True if link analysis has been done.
|
||||
bool m_linkedEventsQ = false;
|
||||
|
||||
private:
|
||||
int extractMidiData (std::istream& inputfile,
|
||||
std::vector<uchar>& array,
|
||||
uchar& runningCommand);
|
||||
ulong readVLValue (std::istream& inputfile);
|
||||
ulong unpackVLV (uchar a = 0, uchar b = 0,
|
||||
uchar c = 0, uchar d = 0,
|
||||
uchar e = 0);
|
||||
void writeVLValue (long aValue,
|
||||
std::vector<uchar>& data);
|
||||
int makeVLV (uchar *buffer, int number);
|
||||
static int ticksearch (const void* A, const void* B);
|
||||
static int secondsearch (const void* A, const void* B);
|
||||
void buildTimeMap (void);
|
||||
double linearTickInterpolationAtSecond (double seconds);
|
||||
double linearSecondInterpolationAtTick (int ticktime);
|
||||
std::string base64Encode (const std::string &input);
|
||||
std::string base64Decode (const std::string &input);
|
||||
|
||||
static const std::string encodeLookup;
|
||||
static const std::vector<int> decodeLookup;
|
||||
static const char *GMinstrument[128];
|
||||
};
|
||||
|
||||
} // end of namespace smf
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, smf::MidiFile& aMidiFile);
|
||||
|
||||
#endif /* _MIDIFILE_H_INCLUDED */
|
||||
|
||||
|
||||
|
||||
Vendored
+219
@@ -0,0 +1,219 @@
|
||||
//
|
||||
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
|
||||
// Creation Date: Sat Feb 14 20:36:32 PST 2015
|
||||
// Last Modified: Sat Apr 21 10:52:19 PDT 2018 Removed using namespace std;
|
||||
// Filename: midifile/include/MidiMessage.h
|
||||
// Website: http://midifile.sapp.org
|
||||
// Syntax: C++11
|
||||
// vim: ts=3 noexpandtab
|
||||
//
|
||||
// Description: Storage for bytes of a MIDI message for use in MidiFile
|
||||
// class.
|
||||
//
|
||||
|
||||
#ifndef _MIDIMESSAGE_H_INCLUDED
|
||||
#define _MIDIMESSAGE_H_INCLUDED
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace smf {
|
||||
|
||||
typedef unsigned char uchar;
|
||||
typedef unsigned short ushort;
|
||||
typedef unsigned long ulong;
|
||||
|
||||
class MidiMessage : public std::vector<uchar> {
|
||||
|
||||
public:
|
||||
MidiMessage (void);
|
||||
MidiMessage (int command);
|
||||
MidiMessage (int command, int p1);
|
||||
MidiMessage (int command, int p1, int p2);
|
||||
MidiMessage (const MidiMessage& message);
|
||||
MidiMessage (const std::vector<uchar>& message);
|
||||
MidiMessage (const std::vector<char>& message);
|
||||
MidiMessage (const std::vector<int>& message);
|
||||
|
||||
~MidiMessage ();
|
||||
|
||||
MidiMessage& operator= (const MidiMessage& message);
|
||||
MidiMessage& operator= (const std::vector<uchar>& bytes);
|
||||
MidiMessage& operator= (const std::vector<char>& bytes);
|
||||
MidiMessage& operator= (const std::vector<int>& bytes);
|
||||
|
||||
void sortTrack (void);
|
||||
void sortTrackWithSequence(void);
|
||||
|
||||
static std::vector<uchar> intToVlv (int value);
|
||||
static double frequencyToSemitones (double frequency, double a4frequency = 440.0);
|
||||
|
||||
// data access convenience functions (returns -1 if not present):
|
||||
int getP0 (void) const;
|
||||
int getP1 (void) const;
|
||||
int getP2 (void) const;
|
||||
int getP3 (void) const;
|
||||
void setP0 (int value);
|
||||
void setP1 (int value);
|
||||
void setP2 (int value);
|
||||
void setP3 (int value);
|
||||
|
||||
int getSize (void) const;
|
||||
void setSize (int asize);
|
||||
int setSizeToCommand (void);
|
||||
int resizeToCommand (void);
|
||||
|
||||
// note-message convenience functions:
|
||||
int getKeyNumber (void) const;
|
||||
int getVelocity (void) const;
|
||||
void setKeyNumber (int value);
|
||||
void setVelocity (int value);
|
||||
void setSpelling (int base7, int accidental);
|
||||
void getSpelling (int& base7, int& accidental);
|
||||
|
||||
// controller-message convenience functions:
|
||||
int getControllerNumber (void) const;
|
||||
int getControllerValue (void) const;
|
||||
|
||||
int getCommandNibble (void) const;
|
||||
int getCommandByte (void) const;
|
||||
int getChannelNibble (void) const;
|
||||
int getChannel (void) const;
|
||||
|
||||
void setCommandByte (int value);
|
||||
void setCommand (int value);
|
||||
void setCommand (int value, int p1);
|
||||
void setCommand (int value, int p1, int p2);
|
||||
void setCommandNibble (int value);
|
||||
void setChannelNibble (int value);
|
||||
void setChannel (int value);
|
||||
void setParameters (int p1, int p2);
|
||||
void setParameters (int p1);
|
||||
void setMessage (const std::vector<uchar>& message);
|
||||
void setMessage (const std::vector<char>& message);
|
||||
void setMessage (const std::vector<int>& message);
|
||||
|
||||
// message-type convenience functions:
|
||||
bool isMetaMessage (void) const;
|
||||
bool isMeta (void) const;
|
||||
bool isNote (void) const;
|
||||
bool isNoteOff (void) const;
|
||||
bool isNoteOn (void) const;
|
||||
bool isAftertouch (void) const;
|
||||
bool isController (void) const;
|
||||
bool isSustain (void) const; // controller 64
|
||||
bool isSustainOn (void) const;
|
||||
bool isSustainOff (void) const;
|
||||
bool isSoft (void) const; // controller 67
|
||||
bool isSoftOn (void) const;
|
||||
bool isSoftOff (void) const;
|
||||
bool isPatchChange (void) const;
|
||||
bool isTimbre (void) const;
|
||||
bool isPressure (void) const;
|
||||
bool isPitchbend (void) const;
|
||||
bool isEmpty (void) const; // see MidiFile::removeEmpties()
|
||||
|
||||
// helper functions to create various MidiMessages:
|
||||
void makeNoteOn (int channel, int key, int velocity);
|
||||
void makeNoteOff (int channel, int key, int velocity);
|
||||
void makeNoteOff (int channel, int key);
|
||||
void makeNoteOff (void);
|
||||
void makePatchChange (int channel, int patchnum);
|
||||
void makeTimbre (int channel, int patchnum);
|
||||
void makeController (int channel, int num, int value);
|
||||
void makePitchBend (int channel, int lsb, int msb);
|
||||
void makePitchBend (int channel, int value);
|
||||
void makePitchBendDouble (int channel, double value);
|
||||
void makePitchbend (int channel, int lsb, int msb) { makePitchBend(channel, lsb, msb); }
|
||||
void makePitchbend (int channel, int value) { makePitchBend(channel, value); }
|
||||
void makePitchbendDouble (int channel, double value) { makePitchBendDouble(channel, value); }
|
||||
|
||||
// helper functions to create various continuous controller messages:
|
||||
void makeSustain (int channel, int value);
|
||||
void makeSustainPedal (int channel, int value);
|
||||
void makeSustainOn (int channel);
|
||||
void makeSustainPedalOn (int channel);
|
||||
void makeSustainOff (int channel);
|
||||
void makeSustainPedalOff (int channel);
|
||||
|
||||
// meta-message creation and helper functions:
|
||||
void makeMetaMessage (int mnum, const std::string& data);
|
||||
void makeText (const std::string& name);
|
||||
void makeCopyright (const std::string& text);
|
||||
void makeTrackName (const std::string& name);
|
||||
void makeInstrumentName (const std::string& name);
|
||||
void makeLyric (const std::string& text);
|
||||
void makeMarker (const std::string& text);
|
||||
void makeCue (const std::string& text);
|
||||
void makeKeySignature (int fifths, bool mode = 0);
|
||||
void makeTimeSignature (int top, int bottom,
|
||||
int clocksPerClick = 24,
|
||||
int num32dsPerQuarter = 8);
|
||||
|
||||
void makeTempo (double tempo) { setTempo(tempo); }
|
||||
int getTempoMicro (void) const;
|
||||
int getTempoMicroseconds (void) const;
|
||||
double getTempoSeconds (void) const;
|
||||
double getTempoBPM (void) const;
|
||||
double getTempoTPS (int tpq) const;
|
||||
double getTempoSPT (int tpq) const;
|
||||
|
||||
int getMetaType (void) const;
|
||||
bool isText (void) const;
|
||||
bool isCopyright (void) const;
|
||||
bool isTrackName (void) const;
|
||||
bool isInstrumentName (void) const;
|
||||
bool isLyricText (void) const;
|
||||
bool isMarkerText (void) const;
|
||||
bool isTempo (void) const;
|
||||
bool isTimeSignature (void) const;
|
||||
bool isKeySignature (void) const;
|
||||
bool isEndOfTrack (void) const;
|
||||
|
||||
std::string getMetaContent (void);
|
||||
void setMetaContent (const std::string& content);
|
||||
void setTempo (double tempo);
|
||||
void setTempoMicroseconds (int microseconds);
|
||||
void setMetaTempo (double tempo);
|
||||
|
||||
|
||||
void makeSysExMessage (const std::vector<uchar>& data);
|
||||
|
||||
// helper functions to create MTS tunings by key (real-time sysex)
|
||||
|
||||
// MTS type 2: Real-time frequency assignment to a arbitrary list of MIDI key numbers.
|
||||
// See page 2 of: https://docs.google.com/viewer?url=https://www.midi.org/component/edocman/midi-tuning-updated/fdocument?Itemid=9999
|
||||
void makeMts2_KeyTuningByFrequency (int key, double frequency, int program = 0);
|
||||
void makeMts2_KeyTuningsByFrequency (int key, double frequency, int program = 0);
|
||||
void makeMts2_KeyTuningsByFrequency (std::vector<std::pair<int, double>>& mapping, int program = 0);
|
||||
void makeMts2_KeyTuningBySemitone (int key, double semitone, int program = 0);
|
||||
void makeMts2_KeyTuningsBySemitone (int key, double semitone, int program = 0);
|
||||
void makeMts2_KeyTuningsBySemitone (std::vector<std::pair<int, double>>& mapping, int program = 0);
|
||||
|
||||
// MTS type 9: Real-time octave temperaments by +/- 100 cents deviation from ET
|
||||
// See page 7 of: https://docs.google.com/viewer?url=https://www.midi.org/component/edocman/midi-tuning-updated/fdocument?Itemid=9999
|
||||
void makeMts9_TemperamentByCentsDeviationFromET (std::vector<double>& mapping, int referencePitchClass = 0, int channelMask = 0b1111111111111111);
|
||||
void makeTemperamentEqual(int referencePitchClass = 0, int channelMask = 0b1111111111111111);
|
||||
void makeTemperamentBad(double maxDeviationCents = 100.0, int referencePitchClass = 0, int channelMask = 0b1111111111111111);
|
||||
void makeTemperamentPythagorean(int referencePitchClass = 2, int channelMask = 0b1111111111111111);
|
||||
void makeTemperamentMeantone(double fraction = 0.25, int referencePitchClass = 2, int channelMask = 0b1111111111111111);
|
||||
void makeTemperamentMeantoneCommaQuarter(int referencePitchClass = 2, int channelMask = 0b1111111111111111);
|
||||
void makeTemperamentMeantoneCommaThird(int referencePitchClass = 2, int channelMask = 0b1111111111111111);
|
||||
void makeTemperamentMeantoneCommaHalf(int referencePitchClass = 2, int channelMask = 0b1111111111111111);
|
||||
|
||||
};
|
||||
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, MidiMessage& event);
|
||||
|
||||
|
||||
} // end of namespace smf
|
||||
|
||||
|
||||
#endif /* _MIDIMESSAGE_H_INCLUDED */
|
||||
|
||||
|
||||
|
||||
Vendored
+157
@@ -0,0 +1,157 @@
|
||||
//
|
||||
// Copyright 1998-2018 by Craig Stuart Sapp, All Rights Reserved.
|
||||
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
|
||||
// Creation Date: Sun Apr 5 13:07:18 PDT 1998
|
||||
// Last Modified: Mon Jan 18 18:25:23 PST 2021 Some cleanup
|
||||
// Filename: midifile/include/Options.h
|
||||
// Web Address: http://midifile.sapp.org
|
||||
// Syntax: C++11
|
||||
// vim: ts=3 noexpandtab
|
||||
//
|
||||
// Description: Interface for command-line options.
|
||||
//
|
||||
|
||||
#ifndef _OPTIONS_H_INCLUDED
|
||||
#define _OPTIONS_H_INCLUDED
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define OPTION_TYPE_unknown '\0'
|
||||
#define OPTION_TYPE_boolean 'b'
|
||||
#define OPTION_TYPE_char 'c'
|
||||
#define OPTION_TYPE_double 'd'
|
||||
#define OPTION_TYPE_float 'f'
|
||||
#define OPTION_TYPE_int 'i'
|
||||
#define OPTION_TYPE_string 's'
|
||||
|
||||
|
||||
namespace smf {
|
||||
|
||||
class Option_register {
|
||||
public:
|
||||
Option_register (void);
|
||||
Option_register (const std::string& aDefinition,
|
||||
char aType,
|
||||
const std::string& aDefaultOption);
|
||||
Option_register (const std::string& aDefinition,
|
||||
char aType,
|
||||
const std::string& aDefaultOption,
|
||||
const std::string& aModifiedOption);
|
||||
|
||||
~Option_register ();
|
||||
|
||||
void clearModified (void);
|
||||
const std::string& getDefinition (void);
|
||||
const std::string& getDefault (void);
|
||||
const std::string& getOption (void);
|
||||
const std::string& getModified (void);
|
||||
const std::string& getDescription (void);
|
||||
bool isModified (void);
|
||||
char getType (void);
|
||||
void reset (void);
|
||||
void setDefault (const std::string& aString);
|
||||
void setDefinition (const std::string& aString);
|
||||
void setDescription (const std::string& aString);
|
||||
void setModified (const std::string& aString);
|
||||
void setType (char aType);
|
||||
std::ostream& print (std::ostream& out);
|
||||
|
||||
protected:
|
||||
std::string m_definition;
|
||||
std::string m_description;
|
||||
std::string m_defaultOption;
|
||||
std::string m_modifiedOption;
|
||||
bool m_modifiedQ;
|
||||
char m_type;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
class Options {
|
||||
public:
|
||||
Options (void);
|
||||
Options (int argc, char** argv);
|
||||
|
||||
~Options ();
|
||||
|
||||
int argc (void) const;
|
||||
const std::vector<std::string>& argv (void) const;
|
||||
int define (const std::string& aDefinition);
|
||||
int define (const std::string& aDefinition,
|
||||
const std::string& description);
|
||||
const std::string& getArg (int index);
|
||||
const std::string& getArgument (int index);
|
||||
int getArgCount (void);
|
||||
int getArgumentCount (void);
|
||||
const std::vector<std::string>& getArgList (void);
|
||||
const std::vector<std::string>& getArgumentList (void);
|
||||
bool getBoolean (const std::string& optionName);
|
||||
std::string getCommand (void);
|
||||
const std::string& getCommandLine (void);
|
||||
std::string getDefinition (const std::string& optionName);
|
||||
double getDouble (const std::string& optionName);
|
||||
char getFlag (void);
|
||||
char getChar (const std::string& optionName);
|
||||
float getFloat (const std::string& optionName);
|
||||
int getInt (const std::string& optionName);
|
||||
int getInteger (const std::string& optionName);
|
||||
std::string getString (const std::string& optionName);
|
||||
char getType (const std::string& optionName);
|
||||
int optionsArg (void);
|
||||
std::ostream& print (std::ostream& out);
|
||||
std::ostream& printOptionList (std::ostream& out);
|
||||
std::ostream& printOptionListBooleanState(std::ostream& out);
|
||||
void process (int error_check = 1, int suppress = 0);
|
||||
void process (int argc, char** argv, int error_check = 1,
|
||||
int suppress = 0);
|
||||
void reset (void);
|
||||
void xverify (int argc, char** argv,
|
||||
int error_check = 1,
|
||||
int suppress = 0);
|
||||
void xverify (int error_check = 1, int suppress = 0);
|
||||
void setFlag (char aFlag);
|
||||
void setModified (const std::string& optionName,
|
||||
const std::string& optionValue);
|
||||
void setOptions (int argc, char** argv);
|
||||
void appendOptions (int argc, char** argv);
|
||||
void appendOptions (const std::string& strang);
|
||||
void appendOptions (const std::vector<std::string>& argv);
|
||||
std::ostream& printRegister (std::ostream& out);
|
||||
bool isDefined (const std::string& name);
|
||||
|
||||
protected:
|
||||
int m_options_error_check; // verify command
|
||||
int m_oargc;
|
||||
std::vector<std::string> m_oargv;
|
||||
std::string m_commandString;
|
||||
char m_optionFlag;
|
||||
std::vector<std::string> m_argument;
|
||||
|
||||
std::vector<Option_register*> m_optionRegister;
|
||||
std::map<std::string, int> m_optionList;
|
||||
|
||||
bool m_processedQ;
|
||||
bool m_suppressQ; // prevent --options
|
||||
bool m_optionsArgument; // --options present
|
||||
|
||||
std::vector<std::string> m_extraArgv;
|
||||
std::vector<std::string> m_extraArgv_strings;
|
||||
|
||||
private:
|
||||
int getRegIndex (const std::string& optionName);
|
||||
int optionQ (const std::string& aString, int& argp);
|
||||
int storeOption (int gargp, int& position, int& running);
|
||||
|
||||
};
|
||||
|
||||
} // end of namespace smf
|
||||
|
||||
|
||||
#endif /* _OPTIONS_H_INCLUDED */
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user