-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4f2832
commit e84af24
Showing
8 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
cmake_minimum_required(VERSION 2.8.9) | ||
|
||
add_library(ptemidi | ||
midievent.cpp | ||
midieventlist.cpp | ||
midifile.cpp | ||
|
||
midievent.h | ||
midieventlist.h | ||
midifile.h | ||
) | ||
|
||
cotire(ptemidi) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (C) 2015 Cameron White | ||
* | ||
* This program 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, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "midievent.h" | ||
|
||
MidiEvent::MidiEvent(int tick, StatusByte status, std::vector<uint8_t> data, | ||
int system, int position, int player, int instrument) | ||
: myTick(tick), | ||
myStatusByte(status), | ||
myData(std::move(data)), | ||
mySystem(system), | ||
myPosition(position), | ||
myPlayer(player), | ||
myInstrument(instrument) | ||
{ | ||
} | ||
|
||
MidiEvent MidiEvent::endOfTrack(int tick) | ||
{ | ||
return MidiEvent(tick, StatusByte::MetaMessage, | ||
{ static_cast<uint8_t>(MetaType::TrackEnd), 0 }, -1, -1, | ||
-1, -1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (C) 2015 Cameron White | ||
* | ||
* This program 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, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef MIDI_MIDIEVENT_H | ||
#define MIDI_MIDIEVENT_H | ||
|
||
#include <cstdint> | ||
#include <vector> | ||
|
||
enum class StatusByte : uint8_t | ||
{ | ||
MetaMessage = 0xff | ||
}; | ||
|
||
enum class MetaType : uint8_t | ||
{ | ||
TrackEnd = 0x2f | ||
}; | ||
|
||
class MidiEvent | ||
{ | ||
public: | ||
MidiEvent(const MidiEvent &) = default; | ||
MidiEvent(MidiEvent &&) = default; | ||
|
||
int getTicks() const { return myTick; } | ||
StatusByte getStatusByte() const { return myStatusByte; } | ||
const std::vector<uint8_t> &getData() const { return myData; } | ||
|
||
static MidiEvent endOfTrack(int tick); | ||
|
||
private: | ||
MidiEvent(int tick, StatusByte status, std::vector<uint8_t> data, | ||
int system, int position, int player, int instrument); | ||
|
||
int myTick; // TODO - does this need to be 64-bit for absolute times? | ||
StatusByte myStatusByte; | ||
std::vector<uint8_t> myData; | ||
|
||
int mySystem; | ||
int myPosition; | ||
int myPlayer; | ||
int myInstrument; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (C) 2015 Cameron White | ||
* | ||
* This program 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, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "midieventlist.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (C) 2015 Cameron White | ||
* | ||
* This program 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, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef MIDI_MIDIEVENTLIST_H | ||
#define MIDI_MIDIEVENTLIST_H | ||
|
||
#include <midi/midievent.h> | ||
#include <vector> | ||
|
||
class MidiEventList | ||
{ | ||
public: | ||
typedef std::vector<MidiEvent>::iterator iterator; | ||
typedef std::vector<MidiEvent>::const_iterator const_iterator; | ||
|
||
void append(MidiEvent &&event) | ||
{ | ||
myEvents.push_back(std::forward<MidiEvent>(event)); | ||
} | ||
|
||
iterator begin() { return myEvents.begin(); } | ||
iterator end() { return myEvents.end(); } | ||
const_iterator begin() const { return myEvents.begin(); } | ||
const_iterator end() const { return myEvents.end(); } | ||
|
||
private: | ||
std::vector<MidiEvent> myEvents; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (C) 2015 Cameron White | ||
* | ||
* This program 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, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "midifile.h" | ||
|
||
static const int theDefaultPPQ = 480; | ||
|
||
MidiFile::MidiFile(const Score & score) | ||
: myTicksPerBeat(theDefaultPPQ) | ||
{ | ||
// For now, just add some empty event lists. | ||
MidiEventList temp; | ||
temp.append(MidiEvent::endOfTrack(0)); | ||
myTracks.push_back(temp); | ||
myTracks.push_back(temp); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (C) 2015 Cameron White | ||
* | ||
* This program 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, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef MIDI_MIDIFILE_H | ||
#define MIDI_MIDIFILE_H | ||
|
||
#include <midi/midieventlist.h> | ||
#include <vector> | ||
|
||
class Score; | ||
|
||
class MidiFile | ||
{ | ||
public: | ||
MidiFile(const Score &score); | ||
|
||
int getTicksPerBeat() const { return myTicksPerBeat; } | ||
const std::vector<MidiEventList> &getTracks() const { return myTracks; } | ||
|
||
private: | ||
int myTicksPerBeat; | ||
std::vector<MidiEventList> myTracks; | ||
}; | ||
|
||
#endif |