File: midifile.h

package info (click to toggle)
musescore2 2.3.2%2Bdfsg3-11~bpo9%2B1
  • links: PTS, VCS
  • area: main
  • in suites: stretch-backports-sloppy
  • size: 192,432 kB
  • sloc: cpp: 262,278; xml: 176,707; sh: 3,376; ansic: 1,384; python: 356; makefile: 229; perl: 82; pascal: 78
file content (99 lines) | stat: -rw-r--r-- 2,929 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//=============================================================================
//  MuseScore
//  Music Composition & Notation
//
//  Copyright (C) 2002-2011 Werner Schweer
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License version 2
//  as published by the Free Software Foundation and appearing in
//  the file LICENCE.GPL
//=============================================================================

#ifndef __MIDIFILE_H__
#define __MIDIFILE_H__

#include <map>
#include <list>
#include <QString>
#include <QIODevice>

#include "midievent.h"
#include "tempomap.h"

class MidiFile;

//---------------------------------------------------------
//   MidiTrack
//---------------------------------------------------------

class MidiTrack {
      MidiFile* mf;
      std::multimap<int, MidiEvent> _events;

   public:
      MidiTrack(MidiFile*);
      ~MidiTrack();

      const std::multimap<int, MidiEvent>& events() const { return _events;     }
      std::multimap<int, MidiEvent>& events() { return _events;     }
      };

//---------------------------------------------------------
//   MidiFile
//---------------------------------------------------------

class MidiFile {
      TempoMap _tempoMap;
      QIODevice* fp;
      std::list<MidiTrack*> _tracks;
      int _division;
      int _format;               ///< midi file format (0-2)

      int status;                ///< running status
      int sstatus;               ///< running status (not reset after meta or sysex events)
      int click;                 ///< current tick position in file
      qint64 curPos;             ///< current file byte position

   protected:
      // read
      void read(void*, qint64);
      int getvl();
      int readShort();
      int readLong();
      int readEvent(MidiEvent*);
      bool readTrack();
      void skip(qint64);

      // write
      bool write(const void*, qint64);
      void writeShort(int);
      void writeLong(int);
      bool writeTrack(const MidiTrack*);
      void writeEvent(const MidiEvent&);
      void putvl(unsigned);
      void put(unsigned char c) { write(&c, 1); }
      void writeStatus(MidiEventType, int channel);

      void resetRunningStatus() { status = -1; }

   public:
      MidiFile();
      bool read(const QString& path);
      bool read(QIODevice*);

      bool write(const QString& path);
      bool write(QIODevice*);

      const std::list<MidiTrack*>& tracks() const { return _tracks;   }
      std::list<MidiTrack*>& tracks()             { return _tracks;   }

      int format() const                { return _format;   }
      void setFormat(int fmt)           { _format = fmt;    }
      int division() const              { return _division; }
      void setDivision(int val)         { _division = val;  }
      const TempoMap& tempoMap() const  { return _tempoMap; }
      };

#endif