OpenTTD Source  1.11.2
midifile.hpp
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7 
8 /* @file midifile.hpp Parser for standard MIDI files */
9 
10 #ifndef MUSIC_MIDIFILE_HPP
11 #define MUSIC_MIDIFILE_HPP
12 
13 #include "../stdafx.h"
14 #include "../core/smallvec_type.hpp"
15 #include "midi.h"
16 #include <vector>
17 #include <string>
18 
19 struct MusicSongInfo;
20 
21 struct MidiFile {
22  struct DataBlock {
23  uint32 ticktime;
24  uint32 realtime;
25  std::vector<byte> data;
26  DataBlock(uint32 _ticktime = 0) : ticktime(_ticktime) { }
27  };
28  struct TempoChange {
29  uint32 ticktime;
30  uint32 tempo;
31  TempoChange(uint32 _ticktime, uint32 _tempo) : ticktime(_ticktime), tempo(_tempo) { }
32  };
33 
34  std::vector<DataBlock> blocks;
35  std::vector<TempoChange> tempos;
36  uint16 tickdiv;
37 
38  MidiFile();
39  ~MidiFile();
40 
41  bool LoadFile(const char *filename);
42  bool LoadMpsData(const byte *data, size_t length);
43  bool LoadSong(const MusicSongInfo &song);
44  void MoveFrom(MidiFile &other);
45 
46  bool WriteSMF(const char *filename);
47 
48  static std::string GetSMFFile(const MusicSongInfo &song);
49  static bool ReadSMFHeader(const char *filename, SMFHeader &header);
50  static bool ReadSMFHeader(FILE *file, SMFHeader &header);
51 };
52 
53 #endif /* MUSIC_MIDIFILE_HPP */
MidiFile::tempos
std::vector< TempoChange > tempos
list of tempo changes in file
Definition: midifile.hpp:35
MidiFile::TempoChange::ticktime
uint32 ticktime
tick number since start of file this tempo change occurs at
Definition: midifile.hpp:29
MidiFile
Definition: midifile.hpp:21
MidiFile::DataBlock::ticktime
uint32 ticktime
tick number since start of file this block should be triggered at
Definition: midifile.hpp:23
MidiFile::TempoChange
Definition: midifile.hpp:28
MidiFile::TempoChange::tempo
uint32 tempo
new tempo in microseconds per tick
Definition: midifile.hpp:30
MidiFile::ReadSMFHeader
static bool ReadSMFHeader(const char *filename, SMFHeader &header)
Read the header of a standard MIDI file.
Definition: midifile.cpp:415
MusicSongInfo
Metadata about a music track.
Definition: base_media_base.h:291
MidiFile::GetSMFFile
static std::string GetSMFFile(const MusicSongInfo &song)
Get the name of a Standard MIDI File for a given song.
Definition: midifile.cpp:1047
MidiFile::blocks
std::vector< DataBlock > blocks
sequential time-annotated data of file, merged to a single track
Definition: midifile.hpp:34
MidiFile::LoadFile
bool LoadFile(const char *filename)
Load a standard MIDI file.
Definition: midifile.cpp:457
MidiFile::MoveFrom
void MoveFrom(MidiFile &other)
Move data from other to this, and clears other.
Definition: midifile.cpp:873
MidiFile::DataBlock::data
std::vector< byte > data
raw midi data contained in block
Definition: midifile.hpp:25
SMFHeader
Header of a Stanard MIDI File.
Definition: midi.h:16
MidiFile::tickdiv
uint16 tickdiv
ticks per quarter note
Definition: midifile.hpp:36
MidiFile::DataBlock::realtime
uint32 realtime
real-time (microseconds) since start of file this block should be triggered at
Definition: midifile.hpp:24
MidiFile::DataBlock
Definition: midifile.hpp:22
MidiFile::LoadMpsData
bool LoadMpsData(const byte *data, size_t length)
Create MIDI data from song data for the original Microprose music drivers.
Definition: midifile.cpp:839
MidiFile::WriteSMF
bool WriteSMF(const char *filename)
Write a Standard MIDI File containing the decoded music.
Definition: midifile.cpp:917