MuseScore  3.4
Music composition and notation
midifile.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2002-2011 Werner Schweer
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2
9 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
12 
13 #ifndef __MIDIFILE_H__
14 #define __MIDIFILE_H__
15 
16 #include "libmscore/sig.h"
17 #include "synthesizer/event.h"
18 
19 namespace Ms {
20 
21 const int MIDI_CHANNEL = 16;
22 
23 //---------------------------------------------------------
24 // MidiType
25 //---------------------------------------------------------
26 
27 enum class MidiType : char {
28  UNKNOWN = 0, GM = 1, GS = 2, XG = 4
29  };
30 
31 class MidiFile;
32 class Xml;
33 
34 //---------------------------------------------------------
35 // MidiTrack
36 //---------------------------------------------------------
37 
38 class MidiTrack {
39  std::multimap<int, MidiEvent> _events;
41  int _outPort;
42  bool _drumTrack;
43 
44  protected:
45  void readXml(XmlReader&);
46 
47  public:
48  MidiTrack();
49  ~MidiTrack();
50 
51  bool empty() const;
52  const std::multimap<int, MidiEvent>& events() const { return _events; }
53  std::multimap<int, MidiEvent>& events() { return _events; }
54 
55  int outChannel() const { return _outChannel; }
56  void setOutChannel(int n);
57  int outPort() const { return _outPort; }
58  void setOutPort(int n) { _outPort = n; }
59 
60  bool drumTrack() const { return _drumTrack; }
61 
62  void insert(int tick, const MidiEvent&);
63  void mergeNoteOnOffAndFindMidiType(MidiType *mt);
64  };
65 
66 //---------------------------------------------------------
67 // MidiFile
68 //---------------------------------------------------------
69 
70 class MidiFile {
71  QIODevice* fp;
72  QList<MidiTrack> _tracks;
73  int _division;
75  int _format;
78 
79  // values used during read()
80  int status;
81  int sstatus;
82  int click;
83  qint64 curPos;
84 
85  void writeEvent(const MidiEvent& event);
86 
87  protected:
88  // write
89  bool write(const void*, qint64);
90  void writeShort(int);
91  void writeLong(int);
92  bool writeTrack(const MidiTrack &);
93  void putvl(unsigned);
94  void put(unsigned char c) { write(&c, 1); }
95  void writeStatus(int type, int channel);
96 
97  // read
98  void read(void*, qint64);
99  int getvl();
100  int readShort();
101  int readLong();
102  bool readEvent(MidiEvent*);
103  bool readTrack();
104  void skip(qint64);
105 
106  void resetRunningStatus() { status = -1; }
107 
108  public:
109  MidiFile();
110  bool read(QIODevice*);
111  bool write(QIODevice*);
112  void readXml(XmlReader&);
113 
114  QList<MidiTrack>& tracks() { return _tracks; }
115  const QList<MidiTrack>& tracks() const { return _tracks; }
116 
117  MidiType midiType() const { return _midiType; }
118  void setMidiType(MidiType mt) { _midiType = mt; }
119 
120  int format() const { return _format; }
121  void setFormat(int fmt) { _format = fmt; }
122 
123  int division() const { return _division; }
124  bool isDivisionInTps() const { return _isDivisionInTps; }
125  void setDivision(int val) { _division = val; }
126  void separateChannel();
127  };
128 }
129 #endif
130 
bool _isDivisionInTps
ticks per second, alternative - ticks per beat
Definition: midifile.h:74
int outPort() const
Definition: midifile.h:57
int format() const
Definition: midifile.h:120
Definition: xml.h:67
void setFormat(int fmt)
Definition: midifile.h:121
void put(unsigned char c)
Definition: midifile.h:94
int outChannel() const
Definition: midifile.h:55
MidiType midiType() const
Definition: midifile.h:117
void setDivision(int val)
Definition: midifile.h:125
bool _drumTrack
Definition: midifile.h:42
Definition: midifile.h:38
int sstatus
running status (not reset after meta or sysex events)
Definition: midifile.h:81
int _outChannel
Definition: midifile.h:40
MidiType
Definition: midifile.h:27
void setOutPort(int n)
Definition: midifile.h:58
std::multimap< int, MidiEvent > _events
Definition: midifile.h:39
QList< MidiTrack > & tracks()
Definition: midifile.h:114
const QList< MidiTrack > & tracks() const
Definition: midifile.h:115
const std::multimap< int, MidiEvent > & events() const
Definition: midifile.h:52
int _format
midi file format (0-2)
Definition: midifile.h:75
Definition: midifile.h:70
int status
running status
Definition: midifile.h:80
void resetRunningStatus()
Definition: midifile.h:106
Definition: aeolus.cpp:26
std::multimap< int, MidiEvent > & events()
Definition: midifile.h:53
MidiType _midiType
Definition: midifile.h:77
void setMidiType(MidiType mt)
Definition: midifile.h:118
Definition: event.h:194
QList< MidiTrack > _tracks
Definition: midifile.h:72
int _division
Definition: midifile.h:73
QIODevice * fp
Definition: midifile.h:71
int _outPort
Definition: midifile.h:41
bool _noRunningStatus
do not use running status on output
Definition: midifile.h:76
qint64 curPos
current file byte position
Definition: midifile.h:83
bool drumTrack() const
Definition: midifile.h:60
int click
current tick position in file
Definition: midifile.h:82
int division() const
Definition: midifile.h:123
bool isDivisionInTps() const
Definition: midifile.h:124
const int MIDI_CHANNEL
Definition: midifile.h:21