Fix: Don't allow right-click to close world generation progress window. (#13084)
[openttd-github.git] / src / music / midifile.hpp
blobaed05b4feb5261c08877fc59c0986499871d39a2
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 */
8 /* @file midifile.hpp Parser for standard MIDI files */
10 #ifndef MUSIC_MIDIFILE_HPP
11 #define MUSIC_MIDIFILE_HPP
13 #include "../stdafx.h"
14 #include "../fileio_type.h"
15 #include "midi.h"
17 struct MusicSongInfo;
19 struct MidiFile {
20 struct DataBlock {
21 uint32_t ticktime; ///< tick number since start of file this block should be triggered at
22 uint32_t realtime = 0; ///< real-time (microseconds) since start of file this block should be triggered at
23 std::vector<uint8_t> data; ///< raw midi data contained in block
24 DataBlock(uint32_t _ticktime = 0) : ticktime(_ticktime) { }
26 struct TempoChange {
27 uint32_t ticktime; ///< tick number since start of file this tempo change occurs at
28 uint32_t tempo; ///< new tempo in microseconds per tick
29 TempoChange(uint32_t _ticktime, uint32_t _tempo) : ticktime(_ticktime), tempo(_tempo) { }
32 std::vector<DataBlock> blocks; ///< sequential time-annotated data of file, merged to a single track
33 std::vector<TempoChange> tempos; ///< list of tempo changes in file
34 uint16_t tickdiv; ///< ticks per quarter note
36 MidiFile();
37 ~MidiFile();
39 bool LoadFile(const std::string &filename);
40 bool LoadMpsData(const uint8_t *data, size_t length);
41 bool LoadSong(const MusicSongInfo &song);
42 void MoveFrom(MidiFile &other);
44 bool WriteSMF(const std::string &filename);
46 static std::string GetSMFFile(const MusicSongInfo &song);
47 static bool ReadSMFHeader(const std::string &filename, SMFHeader &header);
48 static bool ReadSMFHeader(FileHandle &file, SMFHeader &header);
51 #endif /* MUSIC_MIDIFILE_HPP */