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 <map>
17 #include <list>
18 #include <QString>
19 #include <QIODevice>
20 
21 #include "midievent.h"
22 #include "tempomap.h"
23 
24 class MidiFile;
25 
26 //---------------------------------------------------------
27 // MidiTrack
28 //---------------------------------------------------------
29 
30 class MidiTrack {
32  std::multimap<int, MidiEvent> _events;
33 
34  public:
36  ~MidiTrack();
37 
38  const std::multimap<int, MidiEvent>& events() const { return _events; }
39  std::multimap<int, MidiEvent>& events() { return _events; }
40  };
41 
42 //---------------------------------------------------------
43 // MidiFile
44 //---------------------------------------------------------
45 
46 class MidiFile {
48  QIODevice* fp;
49  std::list<MidiTrack*> _tracks;
50  int _division;
51  int _format;
52 
53  int status;
54  int sstatus;
55  int click;
56  qint64 curPos;
57 
58  protected:
59  // read
60  void read(void*, qint64);
61  int getvl();
62  int readShort();
63  int readLong();
64  int readEvent(MidiEvent*);
65  bool readTrack();
66  void skip(qint64);
67 
68  // write
69  bool write(const void*, qint64);
70  void writeShort(int);
71  void writeLong(int);
72  bool writeTrack(const MidiTrack*);
73  void writeEvent(const MidiEvent&);
74  void putvl(unsigned);
75  void put(unsigned char c) { write(&c, 1); }
76  void writeStatus(MidiEventType, int channel);
77 
78  void resetRunningStatus() { status = -1; }
79 
80  public:
81  MidiFile();
82  bool read(const QString& path);
83  bool read(QIODevice*);
84 
85  bool write(const QString& path);
86  bool write(QIODevice*);
87 
88  const std::list<MidiTrack*>& tracks() const { return _tracks; }
89  std::list<MidiTrack*>& tracks() { return _tracks; }
90 
91  int format() const { return _format; }
92  void setFormat(int fmt) { _format = fmt; }
93  int division() const { return _division; }
94  void setDivision(int val) { _division = val; }
95  const TempoMap& tempoMap() const { return _tempoMap; }
96  };
97 
98 #endif
99 
QIODevice * fp
Definition: midifile.h:48
Definition: tempomap.h:22
Definition: midifile.h:30
const std::multimap< int, MidiEvent > & events() const
Definition: midifile.h:38
std::multimap< int, MidiEvent > _events
Definition: midifile.h:32
MidiTrack(MidiFile *)
Definition: midifile.cpp:200
void resetRunningStatus()
Definition: midifile.h:78
int click
current tick position in file
Definition: midifile.h:55
void setDivision(int val)
Definition: midifile.h:94
Definition: midievent.h:112
int format() const
Definition: midifile.h:91
std::list< MidiTrack * > _tracks
Definition: midifile.h:49
int _format
midi file format (0-2)
Definition: midifile.h:51
TempoMap _tempoMap
Definition: midifile.h:47
int status
running status
Definition: midifile.h:53
int division() const
Definition: midifile.h:93
std::list< MidiTrack * > & tracks()
Definition: midifile.h:89
const std::list< MidiTrack * > & tracks() const
Definition: midifile.h:88
qint64 curPos
current file byte position
Definition: midifile.h:56
Definition: midifile.h:46
void put(unsigned char c)
Definition: midifile.h:75
std::multimap< int, MidiEvent > & events()
Definition: midifile.h:39
MidiEventType
Definition: midievent.h:20
MidiFile * mf
Definition: midifile.h:31
void setFormat(int fmt)
Definition: midifile.h:92
int _division
Definition: midifile.h:50
const TempoMap & tempoMap() const
Definition: midifile.h:95
int sstatus
running status (not reset after meta or sysex events)
Definition: midifile.h:54