1
0
Fork 0

Compare commits

...

3 Commits

Author SHA1 Message Date
drelbszoomer 19453fca0e
Merge 7edc18c977 into 7c8759552a 2025-07-28 04:48:32 +00:00
translators 7c8759552a Update: Translations from eints
japanese: 40 changes by akaregi
hungarian: 6 changes by nemesbala
2025-07-28 04:48:20 +00:00
drelbszoomer 7edc18c977 Feature: Add ALSA midi output support 2025-02-20 22:47:39 -05:00
20 changed files with 10513 additions and 21 deletions

View File

@ -144,6 +144,7 @@ if(NOT OPTION_DEDICATED)
find_package(Freetype) find_package(Freetype)
find_package(SDL2) find_package(SDL2)
find_package(Fluidsynth) find_package(Fluidsynth)
find_package(ALSA)
if(Freetype_FOUND) if(Freetype_FOUND)
find_package(Fontconfig) find_package(Fontconfig)
endif() endif()
@ -326,6 +327,7 @@ if(NOT OPTION_DEDICATED)
link_package(ICU_i18n) link_package(ICU_i18n)
link_package(ICU_uc) link_package(ICU_uc)
link_package(OpusFile TARGET OpusFile::opusfile) link_package(OpusFile TARGET OpusFile::opusfile)
link_package(ALSA)
if(SDL2_FOUND AND OPENGL_FOUND AND UNIX) if(SDL2_FOUND AND OPENGL_FOUND AND UNIX)
# SDL2 dynamically loads OpenGL if needed, so do not link to OpenGL when # SDL2 dynamically loads OpenGL if needed, so do not link to OpenGL when

View File

@ -0,0 +1,76 @@
#[=======================================================================[.rst:
FindALSA
--------
Find Advanced Linux Sound Architecture (ALSA)
Find the alsa libraries (``asound``)
IMPORTED Targets
^^^^^^^^^^^^^^^^
.. versionadded:: 3.12
This module defines :prop_tgt:`IMPORTED` target ``ALSA::ALSA``, if
ALSA has been found.
Result Variables
^^^^^^^^^^^^^^^^
This module defines the following variables:
``ALSA_FOUND``
True if ALSA_INCLUDE_DIR & ALSA_LIBRARY are found
``ALSA_LIBRARIES``
List of libraries when using ALSA.
``ALSA_INCLUDE_DIRS``
Where to find the ALSA headers.
Cache variables
^^^^^^^^^^^^^^^
The following cache variables may also be set:
``ALSA_INCLUDE_DIR``
the ALSA include directory
``ALSA_LIBRARY``
the absolute path of the asound library
#]=======================================================================]
find_package(PkgConfig QUIET)
pkg_check_modules(PC_ALSA QUIET alsa)
find_path(ALSA_INCLUDE_DIR NAMES alsa/asoundlib.h
DOC "The ALSA (asound) include directory"
)
find_library(ALSA_LIBRARY NAMES asound
DOC "The ALSA (asound) library"
)
if(ALSA_INCLUDE_DIR AND EXISTS "${ALSA_INCLUDE_DIR}/alsa/version.h")
file(STRINGS "${ALSA_INCLUDE_DIR}/alsa/version.h" alsa_version_str REGEX "^#define[\t ]+SND_LIB_VERSION_STR[\t ]+\".*\"")
string(REGEX REPLACE "^.*SND_LIB_VERSION_STR[\t ]+\"([^\"]*)\".*$" "\\1" ALSA_VERSION_STRING "${alsa_version_str}")
unset(alsa_version_str)
endif()
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(ALSA
REQUIRED_VARS ALSA_LIBRARY ALSA_INCLUDE_DIR
VERSION_VAR ALSA_VERSION_STRING)
if(ALSA_FOUND)
set( ALSA_LIBRARIES ${ALSA_LIBRARY} )
set( ALSA_INCLUDE_DIRS ${ALSA_INCLUDE_DIR} )
if(NOT TARGET ALSA::ALSA)
add_library(ALSA::ALSA UNKNOWN IMPORTED)
set_target_properties(ALSA::ALSA PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${ALSA_INCLUDE_DIRS}")
set_property(TARGET ALSA::ALSA APPEND PROPERTY IMPORTED_LOCATION "${ALSA_LIBRARY}")
endif()
endif()
mark_as_advanced(ALSA_INCLUDE_DIR ALSA_LIBRARY)

View File

@ -7,3 +7,4 @@ add_subdirectory(squirrel)
add_subdirectory(nlohmann) add_subdirectory(nlohmann)
add_subdirectory(opengl) add_subdirectory(opengl)
add_subdirectory(openttd_social_integration_api) add_subdirectory(openttd_social_integration_api)
add_subdirectory(midifile)

2012
src/3rdparty/midifile/Binasc.cpp vendored 100644

File diff suppressed because it is too large Load Diff

161
src/3rdparty/midifile/Binasc.h vendored 100644
View File

@ -0,0 +1,161 @@
//
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
// Creation Date: Mon Feb 16 12:26:32 PST 2015 Adapted from binasc program.
// Last Modified: Sat Apr 21 10:52:19 PDT 2018 Removed using namespace std;
// Filename: midifile/include/Binasc.h
// Website: http://midifile.sapp.org
// Syntax: C++11
// vim: ts=3 noexpandtab
//
// description: Interface to convert bytes between binary and ASCII forms.
//
#ifndef _BINASC_H_INCLUDED
#define _BINASC_H_INCLUDED
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
namespace smf {
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned long ulong;
class Binasc {
public:
Binasc (void);
~Binasc ();
// functions for setting options:
int setLineLength (int length);
int getLineLength (void);
int setLineBytes (int length);
int getLineBytes (void);
void setComments (int state);
void setCommentsOn (void);
void setCommentsOff (void);
int getComments (void);
void setBytes (int state);
void setBytesOn (void);
void setBytesOff (void);
int getBytes (void);
void setMidi (int state);
void setMidiOn (void);
void setMidiOff (void);
int getMidi (void);
// functions for converting into a binary file:
int writeToBinary (const std::string& outfile,
const std::string& infile);
int writeToBinary (const std::string& outfile,
std::istream& input);
int writeToBinary (std::ostream& out,
const std::string& infile);
int writeToBinary (std::ostream& out,
std::istream& input);
// functions for converting into an ASCII file with hex bytes:
int readFromBinary (const std::string&
outfile,
const std::string& infile);
int readFromBinary (const std::string& outfile,
std::istream& input);
int readFromBinary (std::ostream& out,
const std::string& infile);
int readFromBinary (std::ostream& out,
std::istream& input);
// static functions for writing ordered bytes:
static std::ostream& writeLittleEndianUShort (std::ostream& out,
ushort value);
static std::ostream& writeBigEndianUShort (std::ostream& out,
ushort value);
static std::ostream& writeLittleEndianShort (std::ostream& out,
short value);
static std::ostream& writeBigEndianShort (std::ostream& out,
short value);
static std::ostream& writeLittleEndianULong (std::ostream& out,
ulong value);
static std::ostream& writeBigEndianULong (std::ostream& out,
ulong value);
static std::ostream& writeLittleEndianLong (std::ostream& out,
long value);
static std::ostream& writeBigEndianLong (std::ostream& out,
long value);
static std::ostream& writeLittleEndianFloat (std::ostream& out,
float value);
static std::ostream& writeBigEndianFloat (std::ostream& out,
float value);
static std::ostream& writeLittleEndianDouble (std::ostream& out,
double value);
static std::ostream& writeBigEndianDouble (std::ostream& out,
double value);
static std::string keyToPitchName (int key);
protected:
int m_bytesQ; // option for printing hex bytes in ASCII output.
int m_commentsQ; // option for printing comments in ASCII output.
int m_midiQ; // output ASCII data as parsed MIDI file.
int m_maxLineLength;// number of character in ASCII output on a line.
int m_maxLineBytes; // number of hex bytes in ASCII output on a line.
private:
// helper functions for reading ASCII content to conver to binary:
int processLine (std::ostream& out,
const std::string& input,
int lineNum);
int processAsciiWord (std::ostream& out,
const std::string& input,
int lineNum);
int processStringWord (std::ostream& out,
const std::string& input,
int lineNum);
int processBinaryWord (std::ostream& out,
const std::string& input,
int lineNum);
int processDecimalWord (std::ostream& out,
const std::string& input,
int lineNum);
int processHexWord (std::ostream& out,
const std::string& input,
int lineNum);
int processVlvWord (std::ostream& out,
const std::string& input,
int lineNum);
int processMidiPitchBendWord(std::ostream& out,
const std::string& input,
int lineNum);
int processMidiTempoWord (std::ostream& out,
const std::string& input,
int lineNum);
// helper functions for reading binary content to convert to ASCII:
int outputStyleAscii (std::ostream& out, std::istream& input);
int outputStyleBinary (std::ostream& out, std::istream& input);
int outputStyleBoth (std::ostream& out, std::istream& input);
int outputStyleMidi (std::ostream& out, std::istream& input);
// MIDI parsing helper functions:
int readMidiEvent (std::ostream& out, std::istream& infile,
int& trackbytes, int& command);
int getVLV (std::istream& infile, int& trackbytes);
int getWord (std::string& word, const std::string& input,
const std::string& terminators, int index);
static const char *GMinstrument[128];
};
} // end of namespace smf
#endif /* _BINASC_H_INCLUDED */

View File

@ -0,0 +1,12 @@
add_files(
Binasc.cpp
Binasc.h
MidiEvent.cpp
MidiEvent.h
MidiEventList.cpp
MidiEventList.h
MidiFile.cpp
MidiFile.h
MidiMessage.cpp
MidiMessage.h
)

View File

@ -0,0 +1,22 @@
Copyright (c) 1999-2018, Craig Stuart Sapp
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
and the following disclaimer in the documentation and/or other materials
provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,298 @@
//
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
// Creation Date: Sat Feb 14 21:40:14 PST 2015
// Last Modified: Sat Apr 21 10:52:19 PDT 2018 Removed using namespace std;
// Filename: midifile/src/MidiEvent.cpp
// Website: http://midifile.sapp.org
// Syntax: C++11
// vim: ts=3 noexpandtab
//
// Description: A class which stores a MidiMessage and a timestamp
// for the MidiFile class.
//
#include "MidiEvent.h"
#include <cstdlib>
namespace smf {
//////////////////////////////
//
// MidiEvent::MidiEvent -- Constructor classes
//
MidiEvent::MidiEvent(void) : MidiMessage() {
clearVariables();
}
MidiEvent::MidiEvent(int command) : MidiMessage(command) {
clearVariables();
}
MidiEvent::MidiEvent(int command, int p1) : MidiMessage(command, p1) {
clearVariables();
}
MidiEvent::MidiEvent(int command, int p1, int p2)
: MidiMessage(command, p1, p2) {
clearVariables();
}
MidiEvent::MidiEvent(int aTime, int aTrack, vector<uchar>& message)
: MidiMessage(message) {
track = aTrack;
tick = aTime;
seconds = 0.0;
seq = 0;
m_eventlink = NULL;
}
MidiEvent::MidiEvent(const MidiEvent& mfevent) : MidiMessage() {
track = mfevent.track;
tick = mfevent.tick;
seconds = mfevent.seconds;
seq = mfevent.seq;
m_eventlink = NULL;
this->resize(mfevent.size());
for (int i=0; i<(int)this->size(); i++) {
(*this)[i] = mfevent[i];
}
}
//////////////////////////////
//
// MidiEvent::~MidiEvent -- MidiFile Event destructor
//
MidiEvent::~MidiEvent() {
track = -1;
tick = -1;
seconds = -1.0;
seq = -1;
this->resize(0);
m_eventlink = NULL;
}
//////////////////////////////
//
// MidiEvent::clearVariables -- Clear everything except MidiMessage data.
//
void MidiEvent::clearVariables(void) {
track = 0;
tick = 0;
seconds = 0.0;
seq = 0;
m_eventlink = NULL;
}
//////////////////////////////
//
// MidiEvent::operator= -- Copy the contents of another MidiEvent.
//
MidiEvent& MidiEvent::operator=(const MidiEvent& mfevent) {
if (this == &mfevent) {
return *this;
}
tick = mfevent.tick;
track = mfevent.track;
seconds = mfevent.seconds;
seq = mfevent.seq;
m_eventlink = NULL;
this->resize(mfevent.size());
for (int i=0; i<(int)this->size(); i++) {
(*this)[i] = mfevent[i];
}
return *this;
}
MidiEvent& MidiEvent::operator=(const MidiMessage& message) {
if (this == &message) {
return *this;
}
clearVariables();
this->resize(message.size());
for (int i=0; i<(int)this->size(); i++) {
(*this)[i] = message[i];
}
return *this;
}
MidiEvent& MidiEvent::operator=(const vector<uchar>& bytes) {
clearVariables();
this->resize(bytes.size());
for (int i=0; i<(int)this->size(); i++) {
(*this)[i] = bytes[i];
}
return *this;
}
MidiEvent& MidiEvent::operator=(const vector<char>& bytes) {
clearVariables();
setMessage(bytes);
return *this;
}
MidiEvent& MidiEvent::operator=(const vector<int>& bytes) {
clearVariables();
setMessage(bytes);
return *this;
}
//////////////////////////////
//
// MidiEvent::unlinkEvent -- Disassociate this event with another.
// Also tell the other event to disassociate from this event.
//
void MidiEvent::unlinkEvent(void) {
if (m_eventlink == NULL) {
return;
}
MidiEvent* mev = m_eventlink;
m_eventlink = NULL;
mev->unlinkEvent();
}
//////////////////////////////
//
// MidiEvent::linkEvent -- Make a link between two messages.
// Unlinking
//
void MidiEvent::linkEvent(MidiEvent* mev) {
if (mev->m_eventlink != NULL) {
// unlink other event if it is linked to something else;
mev->unlinkEvent();
}
// if this is already linked to something else, then unlink:
if (m_eventlink != NULL) {
m_eventlink->unlinkEvent();
}
unlinkEvent();
mev->m_eventlink = this;
m_eventlink = mev;
}
void MidiEvent::linkEvent(MidiEvent& mev) {
linkEvent(&mev);
}
//////////////////////////////
//
// MidiEvent::getLinkedEvent -- Returns a linked event. Usually
// this is the note-off message for a note-on message and vice-versa.
// Returns null if there are no links.
//
MidiEvent* MidiEvent::getLinkedEvent(void) {
return m_eventlink;
}
const MidiEvent* MidiEvent::getLinkedEvent(void) const {
return m_eventlink;
}
//////////////////////////////
//
// MidiEvent::isLinked -- Returns true if there is an event which is not
// NULL. This function is similar to getLinkedEvent().
//
int MidiEvent::isLinked(void) const {
return m_eventlink == NULL ? 0 : 1;
}
//////////////////////////////
//
// MidiEvent::getTickDuration -- For linked events (note-ons and note-offs),
// return the absolute tick time difference between the two events.
// The tick values are presumed to be in absolute tick mode rather than
// delta tick mode. Returns 0 if not linked.
//
int MidiEvent::getTickDuration(void) const {
const MidiEvent* mev = getLinkedEvent();
if (mev == NULL) {
return 0;
}
int tick2 = mev->tick;
if (tick2 > tick) {
return tick2 - tick;
} else {
return tick - tick2;
}
}
//////////////////////////////
//
// MidiEvent::getDurationInSeconds -- For linked events (note-ons and
// note-offs), return the duration of the note in seconds. The
// seconds analysis must be done first; otherwise the duration will be
// reported as zero.
//
double MidiEvent::getDurationInSeconds(void) const {
const MidiEvent* mev = getLinkedEvent();
if (mev == NULL) {
return 0;
}
double seconds2 = mev->seconds;
if (seconds2 > seconds) {
return seconds2 - seconds;
} else {
return seconds - seconds2;
}
}
//////////////////////////////
//
// operator<<(MidiMessage) -- Print tick value followed by MIDI bytes for event.
// The tick value will be either relative or absolute depending on the state
// of the MidiFile object containing it.
//
std::ostream& operator<<(std::ostream& out, MidiEvent& event) {
out << event.tick << '(' << static_cast<MidiMessage&>(event) << ')';
return out;
}
} // end namespace smf

View File

@ -0,0 +1,78 @@
//
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
// Creation Date: Sat Feb 14 21:47:39 PST 2015
// Last Modified: Sat Apr 21 10:52:19 PDT 2018 Removed using namespace std;
// Filename: midifile/include/MidiEvent.h
// Website: http://midifile.sapp.org
// Syntax: C++11
// vim: ts=3 noexpandtab
//
// Description: A class which stores a MidiMessage and a timestamp
// for the MidiFile class.
//
#ifndef _MIDIEVENT_H_INCLUDED
#define _MIDIEVENT_H_INCLUDED
#include "MidiMessage.h"
#include <ostream>
#include <vector>
namespace smf {
class MidiEvent : public MidiMessage {
public:
MidiEvent (void);
MidiEvent (int command);
MidiEvent (int command, int param1);
MidiEvent (int command, int param1, int param2);
MidiEvent (const MidiMessage& message);
MidiEvent (const MidiEvent& mfevent);
MidiEvent (int aTime, int aTrack,
std::vector<uchar>& message);
~MidiEvent ();
MidiEvent& operator= (const MidiEvent& mfevent);
MidiEvent& operator= (const MidiMessage& message);
MidiEvent& operator= (const std::vector<uchar>& bytes);
MidiEvent& operator= (const std::vector<char>& bytes);
MidiEvent& operator= (const std::vector<int>& bytes);
void clearVariables (void);
// functions related to event linking (note-ons to note-offs).
void unlinkEvent (void);
void unlinkEvents (void);
void linkEvent (MidiEvent* mev);
void linkEvents (MidiEvent* mev);
void linkEvent (MidiEvent& mev);
void linkEvents (MidiEvent& mev);
int isLinked (void) const;
MidiEvent* getLinkedEvent (void);
const MidiEvent* getLinkedEvent (void) const;
int getTickDuration (void) const;
double getDurationInSeconds (void) const;
int tick; // delta or absolute MIDI ticks
int track; // [original] track number of event in MIDI file
double seconds; // calculated time in sec. (after doTimeAnalysis())
int seq; // sorting sequence number of event
private:
MidiEvent* m_eventlink; // used to match note-ons and note-offs
};
std::ostream& operator<<(std::ostream& out, MidiEvent& event);
} // end of namespace smf
#endif /* _MIDIEVENT_H_INCLUDED */

View File

@ -0,0 +1,623 @@
//
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
// Creation Date: Sat Feb 14 21:55:38 PST 2015
// Last Modified: Sat Apr 21 10:52:19 PDT 2018 Removed using namespace std;
// Filename: midifile/src/MidiEventList.cpp
// Website: http://midifile.sapp.org
// Syntax: C++11
// vim: ts=3 noexpandtab
//
// Description: A class which stores a MidiEvents for a MidiFile track.
//
#include "MidiEventList.h"
#include <algorithm>
#include <cstdlib>
#include <iterator>
#include <utility>
#include <vector>
namespace smf {
//////////////////////////////
//
// MidiEventList::MidiEventList -- Constructor.
//
MidiEventList::MidiEventList(void) {
reserve(1000);
}
//////////////////////////////
//
// MidiEventList::MidiEventList(MidiEventList&) -- Copy constructor.
//
MidiEventList::MidiEventList(const MidiEventList& other) {
list.reserve(other.list.size());
auto it = other.list.begin();
std::generate_n(std::back_inserter(list), other.list.size(), [&]() -> MidiEvent* {
return new MidiEvent(**it++);
});
}
//////////////////////////////
//
// MidiEventList::MidiEventList(MidiEventList&&) -- Move constructor.
//
MidiEventList::MidiEventList(MidiEventList&& other) {
list = std::move(other.list);
other.list.clear();
}
//////////////////////////////
//
// MidiEventList::~MidiEventList -- Deconstructor. Deallocate all stored
// data.
//
MidiEventList::~MidiEventList() {
clear();
}
//////////////////////////////
//
// MidiEventList::operator[] --
//
MidiEvent& MidiEventList::operator[](int index) {
return *list[index];
}
const MidiEvent& MidiEventList::operator[](int index) const {
return *list[index];
}
//////////////////////////////
//
// MidiEventList::back -- Return the last element in the list.
//
MidiEvent& MidiEventList::back(void) {
return *list.back();
}
const MidiEvent& MidiEventList::back(void) const {
return *list.back();
}
//
// MidiEventList::last -- Alias for MidiEventList::back().
//
MidiEvent& MidiEventList::last(void) {
return back();
}
const MidiEvent& MidiEventList::last(void) const {
return back();
}
//////////////////////////////
//
// MidiEventList::getEvent -- The same thing as operator[], for
// internal use when operator[] would look more messy.
//
MidiEvent& MidiEventList::getEvent(int index) {
return *list[index];
}
const MidiEvent& MidiEventList::getEvent(int index) const {
return *list[index];
}
//////////////////////////////
//
// MidiEventList::clear -- De-allocate any MidiEvents present in the list
// and set the size of the list to 0.
//
void MidiEventList::clear(void) {
for (auto& item : list) {
if (item != NULL) {
delete item;
item = NULL;
}
}
list.resize(0);
}
//////////////////////////////
//
// MidiEventList::data -- Return the low-level array of MidiMessage
// pointers. This is useful for applying your own sorting
// function to the list.
//
MidiEvent** MidiEventList::data(void) {
return list.data();
}
//////////////////////////////
//
// MidiEventList::reserve -- Pre-allocate space in the list for storing
// elements.
//
void MidiEventList::reserve(int rsize) {
if (rsize > (int)list.size()) {
list.reserve(rsize);
}
}
//////////////////////////////
//
// MidiEventList::getSize -- Return the number of MidiEvents stored
// in the list.
//
int MidiEventList::getSize(void) const {
return (int)list.size();
}
//
// MidiEventList::size -- Alias for MidiEventList::getSize().
//
int MidiEventList::size(void) const {
return getSize();
}
//
// MidiEventList::getEventCount -- Alias for MidiEventList::getSize().
//
int MidiEventList::getEventCount(void) const {
return getSize();
}
//////////////////////////////
//
// MidiEventList::append -- add a MidiEvent at the end of the list. Returns
// the index of the appended event.
//
int MidiEventList::append(MidiEvent& event) {
MidiEvent* ptr = new MidiEvent(event);
list.push_back(ptr);
return (int)list.size()-1;
}
//
// MidiEventList::push -- Alias for MidiEventList::append().
//
int MidiEventList::push(MidiEvent& event) {
return append(event);
}
//
// MidiEventList::push_back -- Alias for MidiEventList::append().
//
int MidiEventList::push_back(MidiEvent& event) {
return append(event);
}
//////////////////////////////
//
// MidiEventList::removeEmpties -- Remove any MIDI message which contain no
// bytes. This function first deallocates any empty MIDI events, and then
// removes them from the list of events.
//
void MidiEventList::removeEmpties(void) {
int count = 0;
for (auto& item : list) {
if (item->empty()) {
delete item;
item = NULL;
count++;
}
}
if (count == 0) {
return;
}
std::vector<MidiEvent*> newlist;
newlist.reserve(list.size() - count);
for (auto& item : list) {
if (item) {
newlist.push_back(item);
}
}
list.swap(newlist);
}
//////////////////////////////
//
// MidiEventList::linkNotePairs -- Match note-ones and note-offs together
// There are two models that can be done if two notes are overlapping
// on the same pitch: the first note-off affects the last note-on,
// or the first note-off affects the first note-on. Currently the
// first note-off affects the last note-on, but both methods could
// be implemented with user selectability. The current state of the
// track is assumed to be in time-sorted order. Returns the number
// of linked notes (note-on/note-off pairs).
//
int MidiEventList::linkEventPairs(void) {
return linkNotePairs();
}
int MidiEventList::linkNotePairs(void) {
// Note-on states:
// dimension 1: MIDI channel (0-15)
// dimension 2: MIDI key (0-127) (but 0 not used for note-ons)
// dimension 3: List of active note-ons or note-offs.
std::vector<std::vector<std::vector<MidiEvent*>>> noteons;
noteons.resize(16);
for (auto& noteon : noteons) {
noteon.resize(128);
}
// Controller linking: The following General MIDI controller numbers are
// also monitored for linking within the track (but not between tracks).
// hex dec name range
// 40 64 Hold pedal (Sustain) on/off 0..63=off 64..127=on
// 41 65 Portamento on/off 0..63=off 64..127=on
// 42 66 Sustenuto Pedal on/off 0..63=off 64..127=on
// 43 67 Soft Pedal on/off 0..63=off 64..127=on
// 44 68 Legato Pedal on/off 0..63=off 64..127=on
// 45 69 Hold Pedal 2 on/off 0..63=off 64..127=on
// 50 80 General Purpose Button 0..63=off 64..127=on
// 51 81 General Purpose Button 0..63=off 64..127=on
// 52 82 General Purpose Button 0..63=off 64..127=on
// 53 83 General Purpose Button 0..63=off 64..127=on
// 54 84 Undefined on/off 0..63=off 64..127=on
// 55 85 Undefined on/off 0..63=off 64..127=on
// 56 86 Undefined on/off 0..63=off 64..127=on
// 57 87 Undefined on/off 0..63=off 64..127=on
// 58 88 Undefined on/off 0..63=off 64..127=on
// 59 89 Undefined on/off 0..63=off 64..127=on
// 5A 90 Undefined on/off 0..63=off 64..127=on
// 7A 122 Local Keyboard On/Off 0..63=off 64..127=on
// first keep track of whether the controller is an on/off switch:
std::vector<std::pair<int, int>> contmap;
contmap.resize(128);
std::pair<int, int> zero(0, 0);
std::fill(contmap.begin(), contmap.end(), zero);
contmap[64].first = 1; contmap[64].second = 0;
contmap[65].first = 1; contmap[65].second = 1;
contmap[66].first = 1; contmap[66].second = 2;
contmap[67].first = 1; contmap[67].second = 3;
contmap[68].first = 1; contmap[68].second = 4;
contmap[69].first = 1; contmap[69].second = 5;
contmap[80].first = 1; contmap[80].second = 6;
contmap[81].first = 1; contmap[81].second = 7;
contmap[82].first = 1; contmap[82].second = 8;
contmap[83].first = 1; contmap[83].second = 9;
contmap[84].first = 1; contmap[84].second = 10;
contmap[85].first = 1; contmap[85].second = 11;
contmap[86].first = 1; contmap[86].second = 12;
contmap[87].first = 1; contmap[87].second = 13;
contmap[88].first = 1; contmap[88].second = 14;
contmap[89].first = 1; contmap[89].second = 15;
contmap[90].first = 1; contmap[90].second = 16;
contmap[122].first = 1; contmap[122].second = 17;
// dimensions:
// 1: mapped controller (0 to 17)
// 2: channel (0 to 15)
std::vector<std::vector<MidiEvent*>> contevents;
contevents.resize(18);
std::vector<std::vector<int>> oldstates;
oldstates.resize(18);
for (int i=0; i<18; i++) {
contevents[i].resize(16);
std::fill(contevents[i].begin(), contevents[i].end(), nullptr);
oldstates[i].resize(16);
std::fill(oldstates[i].begin(), oldstates[i].end(), -1);
}
// Now iterate through the MidiEventList keeping track of note and
// select controller states and linking notes/controllers as needed.
int channel;
int key;
int contnum;
int contval;
int conti;
int contstate;
int counter = 0;
MidiEvent* mev;
MidiEvent* noteon;
for (int i=0; i<getSize(); i++) {
mev = &getEvent(i);
mev->unlinkEvent();
if (mev->isNoteOn()) {
// store the note-on to pair later with a note-off message.
key = mev->getKeyNumber();
channel = mev->getChannel();
noteons[channel][key].push_back(mev);
} else if (mev->isNoteOff()) {
key = mev->getKeyNumber();
channel = mev->getChannel();
if (noteons[channel][key].size() > 0) {
noteon = noteons[channel][key].back();
noteons[channel][key].pop_back();
noteon->linkEvent(mev);
counter++;
}
} else if (mev->isController()) {
contnum = mev->getP1();
if (contmap[contnum].first) {
conti = contmap[contnum].second;
channel = mev->getChannel();
contval = mev->getP2();
contstate = contval < 64 ? 0 : 1;
if ((oldstates[conti][channel] == -1) && contstate) {
// a newly initialized onstate was detected, so store for
// later linking to an off state.
contevents[conti][channel] = mev;
oldstates[conti][channel] = contstate;
} else if (oldstates[conti][channel] == contstate) {
// the controller state is redundant and will be ignored.
} else if ((oldstates[conti][channel] == 0) && contstate) {
// controller is currently off, so store on-state for next link
contevents[conti][channel] = mev;
oldstates[conti][channel] = contstate;
} else if ((oldstates[conti][channel] == 1) && (contstate == 0)) {
// controller has just been turned off, so link to
// stored on-message.
contevents[conti][channel]->linkEvent(mev);
oldstates[conti][channel] = contstate;
// not necessary, but maybe use for something later:
contevents[conti][channel] = mev;
}
}
}
}
return counter;
}
//////////////////////////////
//
// MidiEventList::clearLinks -- remove all note-on/note-off links.
//
void MidiEventList::clearLinks(void) {
for (int i=0; i<(int)getSize(); i++) {
getEvent(i).unlinkEvent();
}
}
//////////////////////////////
//
// MidiEventList::clearSequence -- Remove any sequence serial numbers from
// MidiEvents in the list. This will cause the default ordering by
// sortTracks() to be used, in which case the ordering of MidiEvents
// occurring at the same tick may switch their ordering.
//
void MidiEventList::clearSequence(void) {
for (int i=0; i<getEventCount(); i++) {
getEvent(i).seq = 0;
}
}
//////////////////////////////
//
// MidiEventList::markSequence -- Assign a sequence serial number to
// every MidiEvent in the event list. This is useful if you want
// to preseve the order of MIDI messages in a track when they occur
// at the same tick time. Particularly for use with joinTracks()
// or sortTracks(). markSequence will be done automatically when
// a MIDI file is read, in case the ordering of events occurring at
// the same time is important. Use clearSequence() to use the
// default sorting behavior of sortTracks() when events occur at the
// same time. Returns the next serial number that has not yet been
// used.
// default value: sequence = 1.
//
int MidiEventList::markSequence(int sequence) {
for (int i=0; i<getEventCount(); i++) {
getEvent(i).seq = sequence++;
}
return sequence;
}
///////////////////////////////////////////////////////////////////////////
//
// protected functions --
//
//////////////////////////////
//
// MidiEventList::detach -- De-allocate any MidiEvents present in the list
// and set the size of the list to 0.
//
void MidiEventList::detach(void) {
list.resize(0);
}
//////////////////////////////
//
// MidiEventList::push_back_no_copy -- add a MidiEvent at the end of
// the list. The event is not copied, but memory from the
// remote location is used. Returns the index of the appended event.
//
int MidiEventList::push_back_no_copy(MidiEvent* event) {
list.push_back(event);
return (int)list.size()-1;
}
//////////////////////////////
//
// MidiEventList::operator=(MidiEventList) -- Assignment.
//
MidiEventList& MidiEventList::operator=(MidiEventList& other) {
list.swap(other.list);
return *this;
}
///////////////////////////////////////////////////////////////////////////
//
// private functions
//
//////////////////////////////
//
// MidiEventList::sort -- Private because the MidiFile class keeps
// track of delta versus absolute tick states of the MidiEventList,
// and sorting is only allowed in absolute tick state (The MidiEventList
// does not know about delta/absolute tick states of its contents).
//
void MidiEventList::sort(void) {
qsort(data(), getEventCount(), sizeof(MidiEvent*), eventcompare);
}
///////////////////////////////////////////////////////////////////////////
//
// external functions
//
//////////////////////////////
//
// eventcompare -- Event comparison function for sorting tracks.
//
// Sorting rules:
// (1) sort by (absolute) tick value; otherwise, if tick values are the same:
// (2) end-of-track meta message is always last.
// (3) other meta-messages come before regular MIDI messages.
// (4) note-offs come after all other regular MIDI messages except note-ons.
// (5) note-ons come after all other regular MIDI messages.
//
int eventcompare(const void* a, const void* b) {
MidiEvent& aevent = **((MidiEvent**)a);
MidiEvent& bevent = **((MidiEvent**)b);
if (aevent.tick > bevent.tick) {
// aevent occurs after bevent
return +1;
} else if (aevent.tick < bevent.tick) {
// aevent occurs before bevent
return -1;
} else if ((aevent.seq != 0) && (bevent.seq != 0) && (aevent.seq > bevent.seq)) {
// aevent sequencing state occurs after bevent
// see MidiEventList::markSequence()
return +1;
} else if ((aevent.seq != 0) && (bevent.seq != 0) && (aevent.seq < bevent.seq)) {
// aevent sequencing state occurs before bevent
// see MidiEventList::markSequence()
return -1;
} else if (aevent.getP0() == 0xff && aevent.getP1() == 0x2f) {
// end-of-track meta-message should always be last (but won't really
// matter since the writing function ignores all end-of-track messages
// and writes its own.
return +1;
} else if (bevent.getP0() == 0xff && bevent.getP1() == 0x2f) {
// end-of-track meta-message should always be last (but won't really
// matter since the writing function ignores all end-of-track messages
// and writes its own.
return -1;
} else if (aevent.getP0() == 0xff && bevent.getP0() != 0xff) {
// other meta-messages are placed before real MIDI messages
return -1;
} else if (aevent.getP0() != 0xff && bevent.getP0() == 0xff) {
// other meta-messages are placed before real MIDI messages
return +1;
} else if (((aevent.getP0() & 0xf0) == 0x90) && (aevent.getP2() != 0)) {
// note-ons come after all other types of MIDI messages
return +1;
} else if (((bevent.getP0() & 0xf0) == 0x90) && (bevent.getP2() != 0)) {
// note-ons come after all other types of MIDI messages
return -1;
} else if (((aevent.getP0() & 0xf0) == 0x90) || ((aevent.getP0() & 0xf0) == 0x80)) {
// note-offs come after all other MIDI messages (except note-ons)
return +1;
} else if (((bevent.getP0() & 0xf0) == 0x90) || ((bevent.getP0() & 0xf0) == 0x80)) {
// note-offs come after all other MIDI messages (except note-ons)
return -1;
} else if (((aevent.getP0() & 0xf0) == 0xb0) && ((bevent.getP0() & 0xf0) == 0xb0)) {
// both events are continuous controllers. Sort them by controller number
if (aevent.getP1() > bevent.getP1()) {
return +1;
} if (aevent.getP1() < bevent.getP1()) {
return -1;
} else {
// same controller number, so sort by data value
if (aevent.getP2() > bevent.getP2()) {
return +1;
} if (aevent.getP2() < bevent.getP2()) {
return -1;
} else {
return 0;
}
}
} else {
return 0;
}
}
} // end namespace smf

View File

@ -0,0 +1,82 @@
//
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
// Creation Date: Sat Feb 14 21:55:38 PST 2015
// Last Modified: Sat Apr 21 10:52:19 PDT 2018 Removed using namespace std;
// Filename: midifile/include/MidiEventList.h
// Website: http://midifile.sapp.org
// Syntax: C++11
// vim: ts=3 noexpandtab
//
// Description: A class that stores a MidiEvents for a MidiFile track.
//
#ifndef _MIDIEVENTLIST_H_INCLUDED
#define _MIDIEVENTLIST_H_INCLUDED
#include "MidiEvent.h"
#include <vector>
namespace smf {
class MidiEventList {
public:
MidiEventList (void);
MidiEventList (const MidiEventList& other);
MidiEventList (MidiEventList&& other);
~MidiEventList ();
MidiEventList& operator= (MidiEventList& other);
MidiEvent& operator[] (int index);
const MidiEvent& operator[] (int index) const;
MidiEvent& back (void);
const MidiEvent& back (void) const;
MidiEvent& last (void);
const MidiEvent& last (void) const;
MidiEvent& getEvent (int index);
const MidiEvent& getEvent (int index) const;
void clear (void);
void reserve (int rsize);
int getEventCount (void) const;
int getSize (void) const;
int size (void) const;
void removeEmpties (void);
int linkNotePairs (void);
int linkEventPairs (void);
void clearLinks (void);
void clearSequence (void);
int markSequence (int sequence = 1);
int push (MidiEvent& event);
int push_back (MidiEvent& event);
int append (MidiEvent& event);
// careful when using these, intended for internal use in MidiFile class:
void detach (void);
int push_back_no_copy (MidiEvent* event);
// access to the list of MidiEvents for sorting with an external function:
MidiEvent** data (void);
protected:
std::vector<MidiEvent*> list;
private:
void sort (void);
// MidiFile class calls sort()
friend class MidiFile;
};
int eventcompare(const void* a, const void* b);
} // end of namespace smf
#endif /* _MIDIEVENTLIST_H_INCLUDED */

3465
src/3rdparty/midifile/MidiFile.cpp vendored 100644

File diff suppressed because it is too large Load Diff

332
src/3rdparty/midifile/MidiFile.h vendored 100644
View File

@ -0,0 +1,332 @@
//
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
// Creation Date: Fri Nov 26 14:12:01 PST 1999
// Last Modified: Mon Jan 18 20:54:04 PST 2021 Added readSmf().
// Filename: midifile/include/MidiFile.h
// Website: http://midifile.sapp.org
// Syntax: C++11
// vim: ts=3 noexpandtab
//
// Description: A class that can read/write Standard MIDI files.
// MIDI data is stored by track in an array.
//
#ifndef _MIDIFILE_H_INCLUDED
#define _MIDIFILE_H_INCLUDED
#include "MidiEventList.h"
#include <fstream>
#include <istream>
#include <string>
#include <vector>
namespace smf {
enum {
TRACK_STATE_SPLIT = 0, // Tracks are separated into separate vector postions.
TRACK_STATE_JOINED = 1 // Tracks are merged into a single vector position,
}; // like a Type-0 MIDI file, but reversible.
enum {
TIME_STATE_DELTA = 0, // MidiMessage::ticks are in delta time format (like MIDI file).
TIME_STATE_ABSOLUTE = 1 // MidiMessage::ticks are in absolute time format (0=start time).
};
class _TickTime {
public:
int tick;
double seconds;
};
class MidiFile {
public:
MidiFile (void);
MidiFile (const std::string& filename);
MidiFile (std::istream& input);
MidiFile (const MidiFile& other);
MidiFile (MidiFile&& other);
~MidiFile ();
MidiFile& operator= (const MidiFile& other);
MidiFile& operator= (MidiFile&& other);
// Reading/writing functions:
// Auto-detected SMF or ASCII-encoded SMF (decoded with Binasc class):
bool read (const std::string& filename);
bool read (std::istream& instream);
bool readBase64 (const std::string& base64data);
bool readBase64 (std::istream& instream);
// Only allow Standard MIDI File input:
bool readSmf (const std::string& filename);
bool readSmf (std::istream& instream);
bool write (const std::string& filename);
bool write (std::ostream& out);
bool writeBase64 (const std::string& out, int width = 0);
bool writeBase64 (std::ostream& out, int width = 0);
std::string getBase64 (int width = 0);
bool writeHex (const std::string& filename, int width = 25);
bool writeHex (std::ostream& out, int width = 25);
bool writeBinasc (const std::string& filename);
bool writeBinasc (std::ostream& out);
bool writeBinascWithComments (const std::string& filename);
bool writeBinascWithComments (std::ostream& out);
bool status (void) const;
// track-related functions:
const MidiEventList& operator[] (int aTrack) const;
MidiEventList& operator[] (int aTrack);
int getTrackCount (void) const;
int getNumTracks (void) const;
int size (void) const;
void removeEmpties (void);
// tick-related functions:
void makeDeltaTicks (void);
void deltaTicks (void);
void makeAbsoluteTicks (void);
void absoluteTicks (void);
int getTickState (void) const;
bool isDeltaTicks (void) const;
bool isAbsoluteTicks (void) const;
// join/split track functionality:
void joinTracks (void);
void splitTracks (void);
void splitTracksByChannel (void);
int getTrackState (void) const;
int hasJoinedTracks (void) const;
int hasSplitTracks (void) const;
int getSplitTrack (int track, int index) const;
int getSplitTrack (int index) const;
// track sorting funcionality:
void sortTrack (int track);
void sortTracks (void);
void markSequence (void);
void markSequence (int track, int sequence = 1);
void clearSequence (void);
void clearSequence (int track);
// track manipulation functionality:
int addTrack (void);
int addTrack (int count);
int addTracks (int count);
void deleteTrack (int aTrack);
void mergeTracks (int aTrack1, int aTrack2);
int getTrackCountAsType1 (void);
// ticks-per-quarter related functions:
void setMillisecondTicks (void);
int getTicksPerQuarterNote (void) const;
int getTPQ (void) const;
void setTicksPerQuarterNote (int ticks);
void setTPQ (int ticks);
// physical-time analysis functions:
void doTimeAnalysis (void);
double getTimeInSeconds (int aTrack, int anIndex);
double getTimeInSeconds (int tickvalue);
double getAbsoluteTickTime (double starttime);
int getFileDurationInTicks (void);
double getFileDurationInQuarters (void);
double getFileDurationInSeconds (void);
// note-analysis functions:
int linkNotePairs (void);
int linkEventPairs (void);
void clearLinks (void);
// filename functions:
void setFilename (const std::string& aname);
const char* getFilename (void) const;
// event functionality:
MidiEvent* addEvent (int aTrack, int aTick,
std::vector<uchar>& midiData);
MidiEvent* addEvent (MidiEvent& mfevent);
MidiEvent* addEvent (int aTrack, MidiEvent& mfevent);
MidiEvent& getEvent (int aTrack, int anIndex);
const MidiEvent& getEvent (int aTrack, int anIndex) const;
int getEventCount (int aTrack) const;
int getNumEvents (int aTrack) const;
void allocateEvents (int track, int aSize);
void erase (void);
void clear (void);
void clear_no_deallocate (void);
// MIDI message adding convenience functions:
MidiEvent* addNoteOn (int aTrack, int aTick,
int aChannel, int key,
int vel);
MidiEvent* addNoteOff (int aTrack, int aTick,
int aChannel, int key,
int vel);
MidiEvent* addNoteOff (int aTrack, int aTick,
int aChannel, int key);
MidiEvent* addController (int aTrack, int aTick,
int aChannel, int num,
int value);
MidiEvent* addPatchChange (int aTrack, int aTick,
int aChannel, int patchnum);
MidiEvent* addTimbre (int aTrack, int aTick,
int aChannel, int patchnum);
MidiEvent* addPitchBend (int aTrack, int aTick,
int aChannel, double amount);
// RPN settings:
void setPitchBendRange (int aTrack, int aTick,
int aChannel, double range);
// Controller message adding convenience functions:
MidiEvent* addSustain (int aTrack, int aTick,
int aChannel, int value);
MidiEvent* addSustainPedal (int aTrack, int aTick,
int aChannel, int value);
MidiEvent* addSustainOn (int aTrack, int aTick,
int aChannel);
MidiEvent* addSustainPedalOn (int aTrack, int aTick,
int aChannel);
MidiEvent* addSustainOff (int aTrack, int aTick,
int aChannel);
MidiEvent* addSustainPedalOff (int aTrack, int aTick,
int aChannel);
// Meta-event adding convenience functions:
MidiEvent* addMetaEvent (int aTrack, int aTick,
int aType,
std::vector<uchar>& metaData);
MidiEvent* addMetaEvent (int aTrack, int aTick,
int aType,
const std::string& metaData);
MidiEvent* addText (int aTrack, int aTick,
const std::string& text);
MidiEvent* addCopyright (int aTrack, int aTick,
const std::string& text);
MidiEvent* addTrackName (int aTrack, int aTick,
const std::string& name);
MidiEvent* addInstrumentName (int aTrack, int aTick,
const std::string& name);
MidiEvent* addLyric (int aTrack, int aTick,
const std::string& text);
MidiEvent* addMarker (int aTrack, int aTick,
const std::string& text);
MidiEvent* addCue (int aTrack, int aTick,
const std::string& text);
MidiEvent* addTempo (int aTrack, int aTick,
double aTempo);
MidiEvent* addKeySignature (int aTrack, int aTick,
int fifths, bool mode = 0);
MidiEvent* addTimeSignature (int aTrack, int aTick,
int top, int bottom,
int clocksPerClick = 24,
int num32dsPerQuarter = 8);
MidiEvent* addCompoundTimeSignature(int aTrack, int aTick,
int top, int bottom,
int clocksPerClick = 36,
int num32dsPerQuarter = 8);
uchar readByte (std::istream& input);
// static functions:
static ushort readLittleEndian2Bytes (std::istream& input);
static ulong readLittleEndian4Bytes (std::istream& input);
static std::ostream& writeLittleEndianUShort (std::ostream& out,
ushort value);
static std::ostream& writeBigEndianUShort (std::ostream& out,
ushort value);
static std::ostream& writeLittleEndianShort (std::ostream& out,
short value);
static std::ostream& writeBigEndianShort (std::ostream& out,
short value);
static std::ostream& writeLittleEndianULong (std::ostream& out,
ulong value);
static std::ostream& writeBigEndianULong (std::ostream& out,
ulong value);
static std::ostream& writeLittleEndianLong (std::ostream& out,
long value);
static std::ostream& writeBigEndianLong (std::ostream& out,
long value);
static std::ostream& writeLittleEndianFloat (std::ostream& out,
float value);
static std::ostream& writeBigEndianFloat (std::ostream& out,
float value);
static std::ostream& writeLittleEndianDouble (std::ostream& out,
double value);
static std::ostream& writeBigEndianDouble (std::ostream& out,
double value);
static std::string getGMInstrumentName (int patchIndex);
protected:
// m_events == Lists of MidiEvents for each MIDI file track.
std::vector<MidiEventList*> m_events;
// m_ticksPerQuarterNote == A value for the MIDI file header
// which represents the number of ticks in a quarter note
// that are used as units for the delta times for MIDI events
// in MIDI file track data.
int m_ticksPerQuarterNote = 120;
// m_theTrackState == state variable for whether the tracks
// are joined or split.
int m_theTrackState = TRACK_STATE_SPLIT;
// m_theTimeState == state variable for whether the MidiEvent::tick
// variable contain absolute ticks since the start of the file's
// time, or delta ticks since the last MIDI event in the track.
int m_theTimeState = TIME_STATE_ABSOLUTE;
// m_readFileName == the filename of the last file read into
// the object.
std::string m_readFileName;
// m_timemapvalid ==
bool m_timemapvalid = false;
// m_timemap ==
std::vector<_TickTime> m_timemap;
// m_rwstatus == True if last read was successful, false if a problem.
bool m_rwstatus = true;
// m_linkedEventQ == True if link analysis has been done.
bool m_linkedEventsQ = false;
private:
int extractMidiData (std::istream& inputfile,
std::vector<uchar>& array,
uchar& runningCommand);
ulong readVLValue (std::istream& inputfile);
ulong unpackVLV (uchar a = 0, uchar b = 0,
uchar c = 0, uchar d = 0,
uchar e = 0);
void writeVLValue (long aValue,
std::vector<uchar>& data);
int makeVLV (uchar *buffer, int number);
static int ticksearch (const void* A, const void* B);
static int secondsearch (const void* A, const void* B);
void buildTimeMap (void);
double linearTickInterpolationAtSecond (double seconds);
double linearSecondInterpolationAtTick (int ticktime);
std::string base64Encode (const std::string &input);
std::string base64Decode (const std::string &input);
static const std::string encodeLookup;
static const std::vector<int> decodeLookup;
static const char *GMinstrument[128];
};
} // end of namespace smf
std::ostream& operator<<(std::ostream& out, smf::MidiFile& aMidiFile);
#endif /* _MIDIFILE_H_INCLUDED */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,219 @@
//
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
// Creation Date: Sat Feb 14 20:36:32 PST 2015
// Last Modified: Sat Apr 21 10:52:19 PDT 2018 Removed using namespace std;
// Filename: midifile/include/MidiMessage.h
// Website: http://midifile.sapp.org
// Syntax: C++11
// vim: ts=3 noexpandtab
//
// Description: Storage for bytes of a MIDI message for use in MidiFile
// class.
//
#ifndef _MIDIMESSAGE_H_INCLUDED
#define _MIDIMESSAGE_H_INCLUDED
#include <iostream>
#include <string>
#include <utility>
#include <vector>
namespace smf {
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned long ulong;
class MidiMessage : public std::vector<uchar> {
public:
MidiMessage (void);
MidiMessage (int command);
MidiMessage (int command, int p1);
MidiMessage (int command, int p1, int p2);
MidiMessage (const MidiMessage& message);
MidiMessage (const std::vector<uchar>& message);
MidiMessage (const std::vector<char>& message);
MidiMessage (const std::vector<int>& message);
~MidiMessage ();
MidiMessage& operator= (const MidiMessage& message);
MidiMessage& operator= (const std::vector<uchar>& bytes);
MidiMessage& operator= (const std::vector<char>& bytes);
MidiMessage& operator= (const std::vector<int>& bytes);
void sortTrack (void);
void sortTrackWithSequence(void);
static std::vector<uchar> intToVlv (int value);
static double frequencyToSemitones (double frequency, double a4frequency = 440.0);
// data access convenience functions (returns -1 if not present):
int getP0 (void) const;
int getP1 (void) const;
int getP2 (void) const;
int getP3 (void) const;
void setP0 (int value);
void setP1 (int value);
void setP2 (int value);
void setP3 (int value);
int getSize (void) const;
void setSize (int asize);
int setSizeToCommand (void);
int resizeToCommand (void);
// note-message convenience functions:
int getKeyNumber (void) const;
int getVelocity (void) const;
void setKeyNumber (int value);
void setVelocity (int value);
void setSpelling (int base7, int accidental);
void getSpelling (int& base7, int& accidental);
// controller-message convenience functions:
int getControllerNumber (void) const;
int getControllerValue (void) const;
int getCommandNibble (void) const;
int getCommandByte (void) const;
int getChannelNibble (void) const;
int getChannel (void) const;
void setCommandByte (int value);
void setCommand (int value);
void setCommand (int value, int p1);
void setCommand (int value, int p1, int p2);
void setCommandNibble (int value);
void setChannelNibble (int value);
void setChannel (int value);
void setParameters (int p1, int p2);
void setParameters (int p1);
void setMessage (const std::vector<uchar>& message);
void setMessage (const std::vector<char>& message);
void setMessage (const std::vector<int>& message);
// message-type convenience functions:
bool isMetaMessage (void) const;
bool isMeta (void) const;
bool isNote (void) const;
bool isNoteOff (void) const;
bool isNoteOn (void) const;
bool isAftertouch (void) const;
bool isController (void) const;
bool isSustain (void) const; // controller 64
bool isSustainOn (void) const;
bool isSustainOff (void) const;
bool isSoft (void) const; // controller 67
bool isSoftOn (void) const;
bool isSoftOff (void) const;
bool isPatchChange (void) const;
bool isTimbre (void) const;
bool isPressure (void) const;
bool isPitchbend (void) const;
bool isEmpty (void) const; // see MidiFile::removeEmpties()
// helper functions to create various MidiMessages:
void makeNoteOn (int channel, int key, int velocity);
void makeNoteOff (int channel, int key, int velocity);
void makeNoteOff (int channel, int key);
void makeNoteOff (void);
void makePatchChange (int channel, int patchnum);
void makeTimbre (int channel, int patchnum);
void makeController (int channel, int num, int value);
void makePitchBend (int channel, int lsb, int msb);
void makePitchBend (int channel, int value);
void makePitchBendDouble (int channel, double value);
void makePitchbend (int channel, int lsb, int msb) { makePitchBend(channel, lsb, msb); }
void makePitchbend (int channel, int value) { makePitchBend(channel, value); }
void makePitchbendDouble (int channel, double value) { makePitchBendDouble(channel, value); }
// helper functions to create various continuous controller messages:
void makeSustain (int channel, int value);
void makeSustainPedal (int channel, int value);
void makeSustainOn (int channel);
void makeSustainPedalOn (int channel);
void makeSustainOff (int channel);
void makeSustainPedalOff (int channel);
// meta-message creation and helper functions:
void makeMetaMessage (int mnum, const std::string& data);
void makeText (const std::string& name);
void makeCopyright (const std::string& text);
void makeTrackName (const std::string& name);
void makeInstrumentName (const std::string& name);
void makeLyric (const std::string& text);
void makeMarker (const std::string& text);
void makeCue (const std::string& text);
void makeKeySignature (int fifths, bool mode = 0);
void makeTimeSignature (int top, int bottom,
int clocksPerClick = 24,
int num32dsPerQuarter = 8);
void makeTempo (double tempo) { setTempo(tempo); }
int getTempoMicro (void) const;
int getTempoMicroseconds (void) const;
double getTempoSeconds (void) const;
double getTempoBPM (void) const;
double getTempoTPS (int tpq) const;
double getTempoSPT (int tpq) const;
int getMetaType (void) const;
bool isText (void) const;
bool isCopyright (void) const;
bool isTrackName (void) const;
bool isInstrumentName (void) const;
bool isLyricText (void) const;
bool isMarkerText (void) const;
bool isTempo (void) const;
bool isTimeSignature (void) const;
bool isKeySignature (void) const;
bool isEndOfTrack (void) const;
std::string getMetaContent (void) const;
void setMetaContent (const std::string& content);
void setTempo (double tempo);
void setTempoMicroseconds (int microseconds);
void setMetaTempo (double tempo);
void makeSysExMessage (const std::vector<uchar>& data);
// helper functions to create MTS tunings by key (real-time sysex)
// MTS type 2: Real-time frequency assignment to a arbitrary list of MIDI key numbers.
// See page 2 of: https://docs.google.com/viewer?url=https://www.midi.org/component/edocman/midi-tuning-updated/fdocument?Itemid=9999
void makeMts2_KeyTuningByFrequency (int key, double frequency, int program = 0);
void makeMts2_KeyTuningsByFrequency (int key, double frequency, int program = 0);
void makeMts2_KeyTuningsByFrequency (std::vector<std::pair<int, double>>& mapping, int program = 0);
void makeMts2_KeyTuningBySemitone (int key, double semitone, int program = 0);
void makeMts2_KeyTuningsBySemitone (int key, double semitone, int program = 0);
void makeMts2_KeyTuningsBySemitone (std::vector<std::pair<int, double>>& mapping, int program = 0);
// MTS type 9: Real-time octave temperaments by +/- 100 cents deviation from ET
// See page 7 of: https://docs.google.com/viewer?url=https://www.midi.org/component/edocman/midi-tuning-updated/fdocument?Itemid=9999
void makeMts9_TemperamentByCentsDeviationFromET (std::vector<double>& mapping, int referencePitchClass = 0, int channelMask = 0b1111111111111111);
void makeTemperamentEqual(int referencePitchClass = 0, int channelMask = 0b1111111111111111);
void makeTemperamentBad(double maxDeviationCents = 100.0, int referencePitchClass = 0, int channelMask = 0b1111111111111111);
void makeTemperamentPythagorean(int referencePitchClass = 2, int channelMask = 0b1111111111111111);
void makeTemperamentMeantone(double fraction = 0.25, int referencePitchClass = 2, int channelMask = 0b1111111111111111);
void makeTemperamentMeantoneCommaQuarter(int referencePitchClass = 2, int channelMask = 0b1111111111111111);
void makeTemperamentMeantoneCommaThird(int referencePitchClass = 2, int channelMask = 0b1111111111111111);
void makeTemperamentMeantoneCommaHalf(int referencePitchClass = 2, int channelMask = 0b1111111111111111);
};
std::ostream& operator<<(std::ostream& out, MidiMessage& event);
} // end of namespace smf
#endif /* _MIDIMESSAGE_H_INCLUDED */

View File

@ -697,8 +697,11 @@ STR_GRAPH_CARGO_TOOLTIP_DISABLE_ALL :{BLACK}Ne mutas
STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO :{BLACK}Adott rakomány grafikonjának mutatása be/ki STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO :{BLACK}Adott rakomány grafikonjának mutatása be/ki
STR_GRAPH_CARGO_PAYMENT_CARGO :{TINY_FONT}{BLACK}{STRING} STR_GRAPH_CARGO_PAYMENT_CARGO :{TINY_FONT}{BLACK}{STRING}
STR_GRAPH_INDUSTRY_CAPTION :{WHITE}{INDUSTRY} - Rakománytörténet
STR_GRAPH_INDUSTRY_RANGE_PRODUCED :Előállított STR_GRAPH_INDUSTRY_RANGE_PRODUCED :Előállított
STR_GRAPH_INDUSTRY_RANGE_TRANSPORTED :Szállítva STR_GRAPH_INDUSTRY_RANGE_TRANSPORTED :Szállítva
STR_GRAPH_INDUSTRY_RANGE_DELIVERED :Leszállítva
STR_GRAPH_INDUSTRY_RANGE_WAITING :Várakozik
STR_GRAPH_PERFORMANCE_DETAIL_TOOLTIP :{BLACK}Részletes teljesítményértékelés mutatása STR_GRAPH_PERFORMANCE_DETAIL_TOOLTIP :{BLACK}Részletes teljesítményértékelés mutatása
@ -4087,6 +4090,8 @@ STR_INDUSTRY_VIEW_PRODUCTION_LAST_MONTH_TITLE :{BLACK}Múlt ha
STR_INDUSTRY_VIEW_PRODUCTION_LAST_MINUTE_TITLE :{BLACK}Termelés az elmúlt percben: STR_INDUSTRY_VIEW_PRODUCTION_LAST_MINUTE_TITLE :{BLACK}Termelés az elmúlt percben:
STR_INDUSTRY_VIEW_TRANSPORTED :{YELLOW}{CARGO_LONG}{STRING}{BLACK} ({COMMA}% elszállítva) STR_INDUSTRY_VIEW_TRANSPORTED :{YELLOW}{CARGO_LONG}{STRING}{BLACK} ({COMMA}% elszállítva)
STR_INDUSTRY_VIEW_LOCATION_TOOLTIP :{BLACK}A fő nézetet a gazdasági épületre állítja. Ctrl+kattintással új nézet nyílik a gazdasági épület helyzeténél STR_INDUSTRY_VIEW_LOCATION_TOOLTIP :{BLACK}A fő nézetet a gazdasági épületre állítja. Ctrl+kattintással új nézet nyílik a gazdasági épület helyzeténél
STR_INDUSTRY_VIEW_CARGO_GRAPH :{BLACK}Rakomány grafikon
STR_INDUSTRY_VIEW_CARGO_GRAPH_TOOLTIP :{BLACK}Megmutatja az iparág rakománytörténetének grafikonját
STR_INDUSTRY_VIEW_PRODUCTION_LEVEL :{BLACK}Termelési szint: {YELLOW}{COMMA}% STR_INDUSTRY_VIEW_PRODUCTION_LEVEL :{BLACK}Termelési szint: {YELLOW}{COMMA}%
STR_INDUSTRY_VIEW_INDUSTRY_ANNOUNCED_CLOSURE :{YELLOW}A gyár bejelentette a közelgő bezárását! STR_INDUSTRY_VIEW_INDUSTRY_ANNOUNCED_CLOSURE :{YELLOW}A gyár bejelentette a közelgő bezárását!
@ -5062,6 +5067,7 @@ STR_ERROR_FLAT_LAND_REQUIRED :{WHITE}Sima tal
STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION :{WHITE}Rossz irányba lejt a föld STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION :{WHITE}Rossz irányba lejt a föld
STR_ERROR_CAN_T_DO_THIS :{WHITE}Nem teheted ezt... STR_ERROR_CAN_T_DO_THIS :{WHITE}Nem teheted ezt...
STR_ERROR_BUILDING_MUST_BE_DEMOLISHED :{WHITE}Előbb le kell rombolnod az épületet STR_ERROR_BUILDING_MUST_BE_DEMOLISHED :{WHITE}Előbb le kell rombolnod az épületet
STR_ERROR_BUILDING_IS_PROTECTED :{WHITE}... a(z) épület védett
STR_ERROR_CAN_T_CLEAR_THIS_AREA :{WHITE}Nem tisztíthatod meg ezt a területet... STR_ERROR_CAN_T_CLEAR_THIS_AREA :{WHITE}Nem tisztíthatod meg ezt a területet...
STR_ERROR_SITE_UNSUITABLE :{WHITE}... nem alkalmas rá a hely STR_ERROR_SITE_UNSUITABLE :{WHITE}... nem alkalmas rá a hely
STR_ERROR_ALREADY_BUILT :{WHITE}... már van itt STR_ERROR_ALREADY_BUILT :{WHITE}... már van itt

View File

@ -437,6 +437,7 @@ STR_SETTINGS_MENU_NEWGRF_SETTINGS :NewGRFの設定
STR_SETTINGS_MENU_TRANSPARENCY_OPTIONS :透過表示設定 STR_SETTINGS_MENU_TRANSPARENCY_OPTIONS :透過表示設定
STR_SETTINGS_MENU_TOWN_NAMES_DISPLAYED :街名を表示 STR_SETTINGS_MENU_TOWN_NAMES_DISPLAYED :街名を表示
STR_SETTINGS_MENU_STATION_NAMES_DISPLAYED :駅名を表示 STR_SETTINGS_MENU_STATION_NAMES_DISPLAYED :駅名を表示
STR_SETTINGS_MENU_STATION_NAMES_BUS :バス停
STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED :中継駅名を表示 STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED :中継駅名を表示
STR_SETTINGS_MENU_SIGNS_DISPLAYED :標識を表示 STR_SETTINGS_MENU_SIGNS_DISPLAYED :標識を表示
STR_SETTINGS_MENU_SHOW_COMPETITOR_SIGNS :競争者の標識と名前を表示 STR_SETTINGS_MENU_SHOW_COMPETITOR_SIGNS :競争者の標識と名前を表示
@ -522,6 +523,7 @@ STR_ABOUT_MENU_ABOUT_OPENTTD :OpenTTDにつ
STR_ABOUT_MENU_SPRITE_ALIGNER :スプライトを整列 STR_ABOUT_MENU_SPRITE_ALIGNER :スプライトを整列
STR_ABOUT_MENU_TOGGLE_BOUNDING_BOXES :バウンディングボックスの表示切替 STR_ABOUT_MENU_TOGGLE_BOUNDING_BOXES :バウンディングボックスの表示切替
STR_ABOUT_MENU_TOGGLE_DIRTY_BLOCKS :ダーティーブロックの色付け切替 STR_ABOUT_MENU_TOGGLE_DIRTY_BLOCKS :ダーティーブロックの色付け切替
STR_ABOUT_MENU_TOGGLE_WIDGET_OUTLINES :ウィジェットの枠線の表示切替
###length 31 ###length 31
STR_DAY_NUMBER_1ST :1 STR_DAY_NUMBER_1ST :1
@ -1203,12 +1205,14 @@ STR_CONFIG_SETTING_HORIZONTAL_POS_CENTER :中央
STR_CONFIG_SETTING_HORIZONTAL_POS_RIGHT :右 STR_CONFIG_SETTING_HORIZONTAL_POS_RIGHT :右
STR_CONFIG_SETTING_INFINITE_MONEY :無限の資金: {STRING}
STR_CONFIG_SETTING_INFINITE_MONEY_HELPTEXT :無制限の支出を許容し、会社の破産も無効にします
STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN :初期の借入最大額: {STRING} STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN :初期の借入最大額: {STRING}
STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_HELPTEXT :初期の借入限度額を設定します (インフレは考慮されません) STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_HELPTEXT :初期の借入限度額を設定します (インフレは考慮されません)。「借入金なし」に設定した場合、ゲームスクリプトか「無限の資金」オプションによる提供がない限り、資金は利用できなくなります。
STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_VALUE :{CURRENCY_LONG} STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_VALUE :{CURRENCY_LONG}
###setting-zero-is-special ###setting-zero-is-special
STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_DISABLED :借入金なし {RED}ゲームスクリプトで資金を受給する必要があります STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_DISABLED :借入金なし
STR_CONFIG_SETTING_INTEREST_RATE :金利: {STRING} STR_CONFIG_SETTING_INTEREST_RATE :金利: {STRING}
STR_CONFIG_SETTING_INTEREST_RATE_HELPTEXT :借入利率を設定します (インフレ設定を有効にしたときのインフレ率にも影響します) STR_CONFIG_SETTING_INTEREST_RATE_HELPTEXT :借入利率を設定します (インフレ設定を有効にしたときのインフレ率にも影響します)
@ -1247,7 +1251,7 @@ STR_CONFIG_SETTING_TRAIN_REVERSING_HELPTEXT :設定を有効
STR_CONFIG_SETTING_DISASTERS :災害: {STRING} STR_CONFIG_SETTING_DISASTERS :災害: {STRING}
STR_CONFIG_SETTING_DISASTERS_HELPTEXT :設定を有効にすると時折、乗り物や交通インフラを遮断・破壊する災害が起きるようになります STR_CONFIG_SETTING_DISASTERS_HELPTEXT :設定を有効にすると時折、乗り物や交通インフラを遮断・破壊する災害が起きるようになります
STR_CONFIG_SETTING_CITY_APPROVAL :議会の姿勢: {STRING} STR_CONFIG_SETTING_CITY_APPROVAL :地方自治体の姿勢: {STRING}
STR_CONFIG_SETTING_CITY_APPROVAL_HELPTEXT :会社が街で引き起こした騒音(主に空港)や環境破壊がどの程度、街での評価や更なる建設行為に影響するかを設定します STR_CONFIG_SETTING_CITY_APPROVAL_HELPTEXT :会社が街で引き起こした騒音(主に空港)や環境破壊がどの程度、街での評価や更なる建設行為に影響するかを設定します
STR_CONFIG_SETTING_MAP_HEIGHT_LIMIT :マップ高さ限界: {STRING} STR_CONFIG_SETTING_MAP_HEIGHT_LIMIT :マップ高さ限界: {STRING}
@ -1351,10 +1355,10 @@ STR_CONFIG_SETTING_AUTOSCROLL_MAIN_VIEWPORT_FULLSCREEN :する (フル
STR_CONFIG_SETTING_AUTOSCROLL_MAIN_VIEWPORT :する STR_CONFIG_SETTING_AUTOSCROLL_MAIN_VIEWPORT :する
STR_CONFIG_SETTING_AUTOSCROLL_EVERY_VIEWPORT :する (ビューポートでも有効) STR_CONFIG_SETTING_AUTOSCROLL_EVERY_VIEWPORT :する (ビューポートでも有効)
STR_CONFIG_SETTING_BRIBE :議会の買収: {STRING} STR_CONFIG_SETTING_BRIBE :地方自治体の贈賄: {STRING}
###length 2 ###length 2
STR_CONFIG_SETTING_BRIBE_HELPTEXT :街で議会買収を企てられるようになります。成功すれば街での評判が良くなりますが、地元当局に事が発覚した場合罰金を受けた上評判が悪くなり、その上その街では半年間何もできなくなります STR_CONFIG_SETTING_BRIBE_HELPTEXT :地方自治体への贈賄を企てられるようにします。もし当局に事が発覚した場合、贈賄を試みた会社は当該自治体では半年間何もできなくなります
STR_CONFIG_SETTING_BRIBE_HELPTEXT_MINUTES :会社が議会買収を企てられるようにします。もし当局に事が発覚した場合、買収した会社は当該自治体では半年間何もできなくなります STR_CONFIG_SETTING_BRIBE_HELPTEXT_MINUTES :地方自治体への贈賄を企てられるようにします。もし当局に事が発覚した場合、贈賄を試みた会社は当該自治体では半年間何もできなくなります
STR_CONFIG_SETTING_ALLOW_EXCLUSIVE :独占運送契約の締結: {STRING} STR_CONFIG_SETTING_ALLOW_EXCLUSIVE :独占運送契約の締結: {STRING}
###length 2 ###length 2
@ -1424,6 +1428,7 @@ STR_CONFIG_SETTING_NEVER_EXPIRE_VEHICLES_HELPTEXT :有効にする
###setting-zero-is-special ###setting-zero-is-special
STR_CONFIG_SETTING_CARGO_SCALE_VALUE :{NUM}%
STR_CONFIG_SETTING_AUTORENEW_VEHICLE :老朽車両の自動交換: {STRING} STR_CONFIG_SETTING_AUTORENEW_VEHICLE :老朽車両の自動交換: {STRING}
STR_CONFIG_SETTING_AUTORENEW_VEHICLE_HELPTEXT :有効にすると、耐用年数を越えた輸送機器は自動で更新されるようになります(交換には一度格納施設に戻る必要があります)。具体的な交換時期は下の設定で変更できます。 STR_CONFIG_SETTING_AUTORENEW_VEHICLE_HELPTEXT :有効にすると、耐用年数を越えた輸送機器は自動で更新されるようになります(交換には一度格納施設に戻る必要があります)。具体的な交換時期は下の設定で変更できます。
@ -1858,7 +1863,7 @@ STR_CONFIG_SETTING_ALLOW_TOWN_ROADS_HELPTEXT :街の自治体
STR_CONFIG_SETTING_ALLOW_TOWN_LEVEL_CROSSINGS :街路との平面交差を許可: {STRING} STR_CONFIG_SETTING_ALLOW_TOWN_LEVEL_CROSSINGS :街路との平面交差を許可: {STRING}
STR_CONFIG_SETTING_ALLOW_TOWN_LEVEL_CROSSINGS_HELPTEXT :有効にすると、会社が作る道路と街路とが交差できるようになります STR_CONFIG_SETTING_ALLOW_TOWN_LEVEL_CROSSINGS_HELPTEXT :有効にすると、会社が作る道路と街路とが交差できるようになります
STR_CONFIG_SETTING_NOISE_LEVEL :空港建設に対する街の騒音レベル規制: {STRING} STR_CONFIG_SETTING_NOISE_LEVEL :騒音レベルに基づいた空港建設の制限: {STRING}
STR_CONFIG_SETTING_NOISE_LEVEL_HELPTEXT :この設定を無効にすると、街に作れる空港は最大2つまでになります。有効にした場合は、各空港の騒音レベルの総和が街の騒音許容レベル以下になるようにしか建てられません。騒音レベルは空港の大きさ・街からの距離により、騒音許容レベルは街の人口により左右されます STR_CONFIG_SETTING_NOISE_LEVEL_HELPTEXT :この設定を無効にすると、街に作れる空港は最大2つまでになります。有効にした場合は、各空港の騒音レベルの総和が街の騒音許容レベル以下になるようにしか建てられません。騒音レベルは空港の大きさ・街からの距離により、騒音許容レベルは街の人口により左右されます
STR_CONFIG_SETTING_TOWN_FOUNDING :ゲーム中での街新設: {STRING} STR_CONFIG_SETTING_TOWN_FOUNDING :ゲーム中での街新設: {STRING}
@ -1936,9 +1941,9 @@ STR_CONFIG_SETTING_CITY_SIZE_MULTIPLIER :初期の都市
STR_CONFIG_SETTING_CITY_SIZE_MULTIPLIER_HELPTEXT :ゲーム開始時に都市が普通の街に比べて平均して何倍の人口規模になるかを設定します STR_CONFIG_SETTING_CITY_SIZE_MULTIPLIER_HELPTEXT :ゲーム開始時に都市が普通の街に比べて平均して何倍の人口規模になるかを設定します
STR_CONFIG_SETTING_LINKGRAPH_RECALC_INTERVAL :行先分配グラフを{STRING}秒毎に更新 STR_CONFIG_SETTING_LINKGRAPH_RECALC_INTERVAL :行先分配グラフを{STRING}秒毎に更新
STR_CONFIG_SETTING_LINKGRAPH_RECALC_INTERVAL_HELPTEXT :行先分配グラフの更新の間の待ち時間。各更新はグラフの一部だけのルートを再計算します。即ち、この設定を〇〇秒に指定する場合、全グラフが〇〇秒毎に更新されるのではありません。間隔が短ければ短いほどCPU時間を消費します。長ければ長いほど貨物流通の新規ルートの行先分配に時間がかかります。 STR_CONFIG_SETTING_LINKGRAPH_RECALC_INTERVAL_HELPTEXT :行先分配グラフの再計算間隔。各計算タイミングでは一部のグラフのみが再計算されます。よって、ここ設定した X 秒ごとにグラフ全体が更新されるというわけではありません。再計算の間隔が短ければ短いほどCPU時間を消費します。長ければ長いほど貨物流通の新規ルートの行先分配に時間がかかります。
STR_CONFIG_SETTING_LINKGRAPH_RECALC_TIME :行先分配の更新に{STRING}秒を割り当て STR_CONFIG_SETTING_LINKGRAPH_RECALC_TIME :行先分配の更新に{STRING}秒を割り当て
STR_CONFIG_SETTING_LINKGRAPH_RECALC_TIME_HELPTEXT :行先分配グラフの更新に割り当てられる時間。更新が始まると、スレッドが生成されて、指定の時間に実行させられます。短ければ短いほど間に合わない可能性が高まります。その場合、ゲームは停止して計算完了を待ちます。長ければ長いほどルート変更の際に行先分配の更新に時間がかかります。 STR_CONFIG_SETTING_LINKGRAPH_RECALC_TIME_HELPTEXT :行先分配グラフの再計算に割り当てられる時間。再計算が始まると、グラフの処理のために指定した生存秒数だけ実行可能なスレッドが作られます。生存秒数が短ければ短いほど再計算が間に合わない可能性が高まります。その際、ゲームは一時停止して計算完了を待ちます。生存秒数が長ければ長いほど、ルート変更の際に行先分配の更新に時間がかかります。
STR_CONFIG_SETTING_DISTRIBUTION_PAX :旅客の行先分配法: {STRING} STR_CONFIG_SETTING_DISTRIBUTION_PAX :旅客の行先分配法: {STRING}
STR_CONFIG_SETTING_DISTRIBUTION_PAX_HELPTEXT :旅客がどのように行き先別に分配されるかを設定します。「対称」ではAからBへ向かう乗客とほぼ同数が、BからAに向かうようになります。 「非対称」ではそれぞれの方向に向かう旅客数は独立に決められます。「無効」では行き先別分配をしなくなります。 STR_CONFIG_SETTING_DISTRIBUTION_PAX_HELPTEXT :旅客がどのように行き先別に分配されるかを設定します。「対称」ではAからBへ向かう乗客とほぼ同数が、BからAに向かうようになります。 「非対称」ではそれぞれの方向に向かう旅客数は独立に決められます。「無効」では行き先別分配をしなくなります。
@ -1954,7 +1959,7 @@ STR_CONFIG_SETTING_DISTRIBUTION_ASYMMETRIC :非対称
STR_CONFIG_SETTING_DISTRIBUTION_SYMMETRIC :対称 STR_CONFIG_SETTING_DISTRIBUTION_SYMMETRIC :対称
STR_CONFIG_SETTING_LINKGRAPH_ACCURACY :分配精度: {STRING} STR_CONFIG_SETTING_LINKGRAPH_ACCURACY :分配精度: {STRING}
STR_CONFIG_SETTING_LINKGRAPH_ACCURACY_HELPTEXT :この値を高くすると、リンクグラフ演算の為CPUへの負荷が大きくなります。演算に時間がかかりすぎると、目に見えてタイムラグが起こる場合があります。しかし低い値に設定すると、分配が不正確になり、望まれる場所に貨物が送られなくなる場合があります STR_CONFIG_SETTING_LINKGRAPH_ACCURACY_HELPTEXT :この設定値を高く設定すればするほど、行先分配グラフの計算に要するCPU時間が長くなります。計算に時間がかかりすぎると遅延が発生する可能性があります。一方、設定値を低く設定すると分配が不正確になり、荷物が意図された場所に送られない場合があります。
STR_CONFIG_SETTING_DEMAND_DISTANCE :距離効果: {STRING} STR_CONFIG_SETTING_DEMAND_DISTANCE :距離効果: {STRING}
STR_CONFIG_SETTING_DEMAND_DISTANCE_HELPTEXT :0より大きい値に設定すると、ある貨物の生産先Aと受取可能先Bとの距離がAからBへ送られる貨物量に影響を及ぼすようになります。高い値を設定すればするほど、遠い施設に送られる貨物量は少なくなり、近場の施設に送られる量が大きくなります STR_CONFIG_SETTING_DEMAND_DISTANCE_HELPTEXT :0より大きい値に設定すると、ある貨物の生産先Aと受取可能先Bとの距離がAからBへ送られる貨物量に影響を及ぼすようになります。高い値を設定すればするほど、遠い施設に送られる貨物量は少なくなり、近場の施設に送られる量が大きくなります
@ -2058,8 +2063,10 @@ STR_CONFIG_ERROR_INVALID_BASE_MUSIC_NOT_FOUND :{WHITE}ファ
# Video initalization errors # Video initalization errors
STR_VIDEO_DRIVER_ERROR :{WHITE}ビデオ設定にエラーがあります... STR_VIDEO_DRIVER_ERROR :{WHITE}ビデオ設定にエラーがあります...
STR_VIDEO_DRIVER_ERROR_NO_HARDWARE_ACCELERATION :{WHITE}... 対応する GPU が見つかりません。ハードウェアアクセラレーションは無効になります。 STR_VIDEO_DRIVER_ERROR_NO_HARDWARE_ACCELERATION :{WHITE}... 対応する GPU が見つかりません。ハードウェアアクセラレーションは無効になります。
STR_VIDEO_DRIVER_ERROR_HARDWARE_ACCELERATION_CRASH :{WHITE}... GPUドライバーがゲームをクラッシュさせました。ハードウェアアクセラレーションは無効になりました
# Intro window # Intro window
STR_INTRO_CAPTION :{WHITE}OpenTTD
STR_INTRO_NEW_GAME :{BLACK}新しいゲーム STR_INTRO_NEW_GAME :{BLACK}新しいゲーム
STR_INTRO_LOAD_GAME :{BLACK}ロード STR_INTRO_LOAD_GAME :{BLACK}ロード
@ -2070,6 +2077,7 @@ STR_INTRO_MULTIPLAYER :{BLACK}マル
STR_INTRO_GAME_OPTIONS :{BLACK}基本設定 STR_INTRO_GAME_OPTIONS :{BLACK}基本設定
STR_INTRO_HIGHSCORE :{BLACK}ハイスコア STR_INTRO_HIGHSCORE :{BLACK}ハイスコア
STR_INTRO_HELP :{BLACK}ヘルプとマニュアル
STR_INTRO_ONLINE_CONTENT :{BLACK}オンラインコンテンツの確認 STR_INTRO_ONLINE_CONTENT :{BLACK}オンラインコンテンツの確認
STR_INTRO_QUIT :{BLACK}終了 STR_INTRO_QUIT :{BLACK}終了
@ -2121,14 +2129,14 @@ STR_HELP_WINDOW_COMMUNITY :{BLACK}コミ
STR_CHEATS :{WHITE}サンドボックスのオプション STR_CHEATS :{WHITE}サンドボックスのオプション
STR_CHEAT_MONEY :{LTBLUE}預金残高を{CURRENCY_LONG}増やす STR_CHEAT_MONEY :{LTBLUE}預金残高を{CURRENCY_LONG}増やす
STR_CHEAT_CHANGE_COMPANY :{LTBLUE}会社: {ORANGE}{COMMA}を乗っ取ってプレイする STR_CHEAT_CHANGE_COMPANY :{LTBLUE}会社: {ORANGE}{COMMA}を乗っ取ってプレイする
STR_CHEAT_EXTRA_DYNAMITE :{LTBLUE}魔法のブルドーザー(産業拠点等、何でも撤去できる): {ORANGE}{STRING} STR_CHEAT_EXTRA_DYNAMITE :{LTBLUE}魔法のブルドーザー(産業拠点など何でも撤去可能): {ORANGE}{STRING}
STR_CHEAT_CROSSINGTUNNELS :{LTBLUE}トンネルの平面交差を許容: {ORANGE}{STRING} STR_CHEAT_CROSSINGTUNNELS :{LTBLUE}トンネルの平面交差を許容: {ORANGE}{STRING}
STR_CHEAT_NO_JETCRASH :{LTBLUE}ジェット機の小型空港での墜落率を減少: {ORANGE}{STRING} STR_CHEAT_NO_JETCRASH :{LTBLUE}ジェット機の小型空港での墜落率を減少: {ORANGE}{STRING}
STR_CHEAT_EDIT_MAX_HL :{LTBLUE}マップの最高高度を変更: {ORANGE}{NUM} STR_CHEAT_EDIT_MAX_HL :{LTBLUE}マップの最高高度を変更: {ORANGE}{NUM}
STR_CHEAT_EDIT_MAX_HL_QUERY_CAPT :{WHITE}マップの最大高度 STR_CHEAT_EDIT_MAX_HL_QUERY_CAPT :{WHITE}マップの最大高度
STR_CHEAT_CHANGE_DATE :{LTBLUE}日付を変更: {ORANGE}{DATE_SHORT} STR_CHEAT_CHANGE_DATE :{LTBLUE}日付を変更: {ORANGE}{DATE_SHORT}
STR_CHEAT_CHANGE_DATE_QUERY_CAPT :{WHITE}現在日時を変更 STR_CHEAT_CHANGE_DATE_QUERY_CAPT :{WHITE}現在日時を変更
STR_CHEAT_SETUP_PROD :{LTBLUE}生産量変更: {ORANGE}{STRING} STR_CHEAT_SETUP_PROD :{LTBLUE}産業の生産量変更を有効化: {ORANGE}{STRING}
# Livery window # Livery window
STR_LIVERY_CAPTION :{WHITE}{COMPANY} - 配色 STR_LIVERY_CAPTION :{WHITE}{COMPANY} - 配色
@ -2457,6 +2465,7 @@ STR_NETWORK_SERVER_MESSAGE_GAME_REASON_LINK_GRAPH :リンクグラ
STR_NETWORK_MESSAGE_CLIENT_LEAVING :退出 STR_NETWORK_MESSAGE_CLIENT_LEAVING :退出
STR_NETWORK_MESSAGE_CLIENT_JOINED :*** {STRING} が参加してきました STR_NETWORK_MESSAGE_CLIENT_JOINED :*** {STRING} が参加してきました
STR_NETWORK_MESSAGE_CLIENT_JOINED_ID :*** {STRING} がゲームに参加してきました (クライアント #{NUM}) STR_NETWORK_MESSAGE_CLIENT_JOINED_ID :*** {STRING} がゲームに参加してきました (クライアント #{NUM})
STR_NETWORK_MESSAGE_CLIENT_COMPANY_JOIN :*** {0:STRING} が{STRING}の経営に参画してきました
STR_NETWORK_MESSAGE_CLIENT_COMPANY_SPECTATE :*** {STRING} がゲームを観覧し始めました STR_NETWORK_MESSAGE_CLIENT_COMPANY_SPECTATE :*** {STRING} がゲームを観覧し始めました
STR_NETWORK_MESSAGE_CLIENT_COMPANY_NEW :*** {STRING} が新会社 (#{NUM}) を設立しました STR_NETWORK_MESSAGE_CLIENT_COMPANY_NEW :*** {STRING} が新会社 (#{NUM}) を設立しました
STR_NETWORK_MESSAGE_CLIENT_LEFT :*** {STRING} が退出しました({STRING}) STR_NETWORK_MESSAGE_CLIENT_LEFT :*** {STRING} が退出しました({STRING})
@ -2672,6 +2681,7 @@ STR_SELECT_ROAD_BRIDGE_CAPTION :{WHITE}道路
STR_SELECT_BRIDGE_SELECTION_TOOLTIP :{BLACK}建設したい橋の種類をクリックしてください STR_SELECT_BRIDGE_SELECTION_TOOLTIP :{BLACK}建設したい橋の種類をクリックしてください
STR_SELECT_BRIDGE_INFO_NAME :{GOLD}{STRING} STR_SELECT_BRIDGE_INFO_NAME :{GOLD}{STRING}
STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED :{GOLD}{STRING}{} {VELOCITY} STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED :{GOLD}{STRING}{} {VELOCITY}
STR_SELECT_BRIDGE_INFO_NAME_COST :{GOLD}{STRING}{} {WHITE}{CURRENCY_LONG}
STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED_COST :{GOLD}{STRING}{} {VELOCITY} {WHITE}{CURRENCY_LONG} STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED_COST :{GOLD}{STRING}{} {VELOCITY} {WHITE}{CURRENCY_LONG}
STR_BRIDGE_NAME_SUSPENSION_STEEL :吊橋(S造) STR_BRIDGE_NAME_SUSPENSION_STEEL :吊橋(S造)
STR_BRIDGE_NAME_GIRDER_STEEL :桁橋(S造) STR_BRIDGE_NAME_GIRDER_STEEL :桁橋(S造)
@ -3458,7 +3468,7 @@ STR_LOCAL_AUTHORITY_ACTION_ROAD_RECONSTRUCTION :道路補修に
STR_LOCAL_AUTHORITY_ACTION_STATUE_OF_COMPANY :社長の彫像を建設 STR_LOCAL_AUTHORITY_ACTION_STATUE_OF_COMPANY :社長の彫像を建設
STR_LOCAL_AUTHORITY_ACTION_NEW_BUILDINGS :市街地開発に出資 STR_LOCAL_AUTHORITY_ACTION_NEW_BUILDINGS :市街地開発に出資
STR_LOCAL_AUTHORITY_ACTION_EXCLUSIVE_TRANSPORT :独占運送契約を締結 STR_LOCAL_AUTHORITY_ACTION_EXCLUSIVE_TRANSPORT :独占運送契約を締結
STR_LOCAL_AUTHORITY_ACTION_BRIBE :議会を買収 STR_LOCAL_AUTHORITY_ACTION_BRIBE :地方自治体への贈賄
###next-name-looks-similar ###next-name-looks-similar
STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING :{PUSH_COLOUR}{YELLOW}旅客と貨物を確保する為に、街で新聞広告を実施します。{}より多くの旅客と貨物が自社の交通網を利用するようになります。{}{POP_COLOUR}費用: {CURRENCY_LONG} STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING :{PUSH_COLOUR}{YELLOW}旅客と貨物を確保する為に、街で新聞広告を実施します。{}より多くの旅客と貨物が自社の交通網を利用するようになります。{}{POP_COLOUR}費用: {CURRENCY_LONG}
@ -3466,7 +3476,7 @@ STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_MEDIUM_ADVERTISING :{PUSH_COLOUR}{Y
STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_LARGE_ADVERTISING :{PUSH_COLOUR}{YELLOW}旅客と貨物を確保する為に、街でTV-CMを開始します{}街の中心部の大範囲にある駅の評価が一時的に高まります。{}{POP_COLOUR}費用: {CURRENCY_LONG} STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_LARGE_ADVERTISING :{PUSH_COLOUR}{YELLOW}旅客と貨物を確保する為に、街でTV-CMを開始します{}街の中心部の大範囲にある駅の評価が一時的に高まります。{}{POP_COLOUR}費用: {CURRENCY_LONG}
STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_STATUE_OF_COMPANY :{PUSH_COLOUR}{YELLOW}社を称える彫像を建設します{}この街の駅の評価を恒久的に高めます。{}{POP_COLOUR}費用: {CURRENCY_LONG} STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_STATUE_OF_COMPANY :{PUSH_COLOUR}{YELLOW}社を称える彫像を建設します{}この街の駅の評価を恒久的に高めます。{}{POP_COLOUR}費用: {CURRENCY_LONG}
STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_NEW_BUILDINGS :{PUSH_COLOUR}{YELLOW}市街地の開発に出資します{}街の成長速度が一時的に早まります。{}{POP_COLOUR}費用: {CURRENCY_LONG} STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_NEW_BUILDINGS :{PUSH_COLOUR}{YELLOW}市街地の開発に出資します{}街の成長速度が一時的に早まります。{}{POP_COLOUR}費用: {CURRENCY_LONG}
STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_BRIBE :{PUSH_COLOUR}{YELLOW}買収を行い、議会内の評判を高めます。注意: 露見した場合は処罰されます{}{POP_COLOUR}費用: {CURRENCY_LONG} STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_BRIBE :{PUSH_COLOUR}{YELLOW}贈賄を通じて地方自治体内の評判を高めます。注意: 露見した場合は処罰されます{}{POP_COLOUR}費用: {CURRENCY_LONG}
# Goal window # Goal window
STR_GOALS_CAPTION :{WHITE}{COMPANY} 目標 STR_GOALS_CAPTION :{WHITE}{COMPANY} 目標
@ -4374,6 +4384,7 @@ STR_ORDER_REFIT_STOP_ORDER :({STRING}に改
STR_ORDER_STOP_ORDER :(運用停止) STR_ORDER_STOP_ORDER :(運用停止)
STR_ORDER_GO_TO_STATION :{STRING} {STATION}
STR_ORDER_GO_TO_STATION_CAN_T_USE_STATION :{PUSH_COLOUR}{RED}(駅を使用できません){POP_COLOUR} {STRING} {STATION} STR_ORDER_GO_TO_STATION_CAN_T_USE_STATION :{PUSH_COLOUR}{RED}(駅を使用できません){POP_COLOUR} {STRING} {STATION}
STR_ORDER_IMPLICIT :(自動) STR_ORDER_IMPLICIT :(自動)
@ -4432,6 +4443,7 @@ STR_TIMETABLE_TOOLTIP :{BLACK}ダイ
STR_TIMETABLE_NO_TRAVEL :運行計画無 STR_TIMETABLE_NO_TRAVEL :運行計画無
STR_TIMETABLE_NOT_TIMETABLEABLE :該当区間を運行 (次の手動指令により自動設定) STR_TIMETABLE_NOT_TIMETABLEABLE :該当区間を運行 (次の手動指令により自動設定)
STR_TIMETABLE_TRAVEL_NOT_TIMETABLED :該当区間を運行 (ダイヤ設定無) STR_TIMETABLE_TRAVEL_NOT_TIMETABLED :該当区間を運行 (ダイヤ設定無)
STR_TIMETABLE_TRAVEL_NOT_TIMETABLED_SPEED :最高速度{VELOCITY}で該当区間を運行 (ダイヤ設定無)
STR_TIMETABLE_TRAVEL_FOR :{STRING}で該当区間を運行 STR_TIMETABLE_TRAVEL_FOR :{STRING}で該当区間を運行
STR_TIMETABLE_TRAVEL_FOR_SPEED :{STRING}で該当区間を運行(最高速度{VELOCITY}) STR_TIMETABLE_TRAVEL_FOR_SPEED :{STRING}で該当区間を運行(最高速度{VELOCITY})
STR_TIMETABLE_TRAVEL_FOR_ESTIMATED :運行({0:STRING}・ダイヤ設定無) STR_TIMETABLE_TRAVEL_FOR_ESTIMATED :運行({0:STRING}・ダイヤ設定無)
@ -4525,14 +4537,14 @@ STR_AI_CONFIG_MOVE_DOWN :{BLACK}下に
STR_AI_CONFIG_MOVE_DOWN_TOOLTIP :{BLACK}選択したAIの順位を下げる STR_AI_CONFIG_MOVE_DOWN_TOOLTIP :{BLACK}選択したAIの順位を下げる
STR_AI_CONFIG_GAMESCRIPT :{SILVER}ゲームスクリプト STR_AI_CONFIG_GAMESCRIPT :{SILVER}ゲームスクリプト
STR_AI_CONFIG_GAMESCRIPT_PARAM :{SILVER}パラメータ STR_AI_CONFIG_GAMESCRIPT_PARAM :{SILVER}パラメータ
STR_AI_CONFIG_AI :{SILVER}AI STR_AI_CONFIG_AI :{SILVER}AI
STR_AI_CONFIG_CHANGE_AI :{BLACK}AIを選択 STR_AI_CONFIG_CHANGE_AI :{BLACK}AIを選択
STR_AI_CONFIG_CHANGE_GAMESCRIPT :{BLACK}ゲームスクリプトを選択 STR_AI_CONFIG_CHANGE_GAMESCRIPT :{BLACK}ゲームスクリプトを選択
STR_AI_CONFIG_CHANGE_TOOLTIP :{BLACK}他のスクリプトをロードします。Ctrl+クリックで全ての利用可能バージョンを表示します STR_AI_CONFIG_CHANGE_TOOLTIP :{BLACK}他のスクリプトをロードします。Ctrl+クリックで全ての利用可能バージョンを表示します
STR_AI_CONFIG_CONFIGURE :{BLACK}設定 STR_AI_CONFIG_CONFIGURE :{BLACK}設定
STR_AI_CONFIG_CONFIGURE_TOOLTIP :{BLACK}スクリプトのパラメータを設定します STR_AI_CONFIG_CONFIGURE_TOOLTIP :{BLACK}スクリプトのパラメータを設定します
# Available AIs window # Available AIs window
STR_AI_LIST_CAPTION :{WHITE}使用可能な{STRING} STR_AI_LIST_CAPTION :{WHITE}使用可能な{STRING}
@ -4556,8 +4568,8 @@ STR_SCREENSHOT_HEIGHTMAP_SCREENSHOT :{BLACK}ハイ
STR_SCREENSHOT_MINIMAP_SCREENSHOT :{BLACK}ミニマップのスクリーンショット STR_SCREENSHOT_MINIMAP_SCREENSHOT :{BLACK}ミニマップのスクリーンショット
# Script Parameters # Script Parameters
STR_AI_SETTINGS_CAPTION_AI :AI STR_AI_SETTINGS_CAPTION_AI :{WHITE}AIのパラメーター
STR_AI_SETTINGS_CAPTION_GAMESCRIPT :ゲームスクリプト STR_AI_SETTINGS_CAPTION_GAMESCRIPT :{WHITE}ゲームスクリプトのパラメーター
STR_AI_SETTINGS_RESET :{BLACK}リセット STR_AI_SETTINGS_RESET :{BLACK}リセット
STR_AI_SETTINGS_SETTING :{STRING}: {ORANGE}{STRING} STR_AI_SETTINGS_SETTING :{STRING}: {ORANGE}{STRING}
@ -4638,6 +4650,7 @@ STR_ERROR_SCREENSHOT_FAILED :{WHITE}スク
# Error message titles # Error message titles
STR_ERROR_MESSAGE_CAPTION :{YELLOW}メッセージ STR_ERROR_MESSAGE_CAPTION :{YELLOW}メッセージ
STR_ERROR_MESSAGE_CAPTION_OTHER_COMPANY :{YELLOW}{COMPANY}からのメッセージ
# Generic construction errors # Generic construction errors
STR_ERROR_OFF_EDGE_OF_MAP :{WHITE}マップからはみ出します STR_ERROR_OFF_EDGE_OF_MAP :{WHITE}マップからはみ出します
@ -4656,12 +4669,13 @@ STR_ERROR_TERRAFORM_LIMIT_REACHED :{WHITE}一度
STR_ERROR_CLEARING_LIMIT_REACHED :{WHITE}一度にできる撤去量を越えています STR_ERROR_CLEARING_LIMIT_REACHED :{WHITE}一度にできる撤去量を越えています
STR_ERROR_TREE_PLANT_LIMIT_REACHED :{WHITE}木の本数が多すぎます STR_ERROR_TREE_PLANT_LIMIT_REACHED :{WHITE}木の本数が多すぎます
STR_ERROR_NAME_MUST_BE_UNIQUE :{WHITE}名前は重複してはいけません STR_ERROR_NAME_MUST_BE_UNIQUE :{WHITE}名前は重複してはいけません
STR_ERROR_GENERIC_OBJECT_IN_THE_WAY :{WHITE}{STRING}があります
STR_ERROR_NOT_ALLOWED_WHILE_PAUSED :{WHITE}ポーズ中にはできない行動です STR_ERROR_NOT_ALLOWED_WHILE_PAUSED :{WHITE}ポーズ中にはできない行動です
# Local authority errors # Local authority errors
STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS :{WHITE}{TOWN}議会が反対しています STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS :{WHITE}{TOWN}の地方自治体が反対しています
STR_ERROR_LOCAL_AUTHORITY_REFUSES_AIRPORT :{WHITE}{TOWN}議会はこれ以上の空港建設を認可しない方針です STR_ERROR_LOCAL_AUTHORITY_REFUSES_AIRPORT :{WHITE}{TOWN}の地方自治体はこれ以上の空港建設を許可しません
STR_ERROR_LOCAL_AUTHORITY_REFUSES_NOISE :{WHITE}{TOWN}の地元民が騒音公害を理由に空港建設に反対しています STR_ERROR_LOCAL_AUTHORITY_REFUSES_NOISE :{WHITE}{TOWN}の地方自治体は騒音公害の懸念から空港建設を許可しません
STR_ERROR_BRIBE_FAILED :{WHITE}あなたの行った贈収賄が地元当局に露見しました! STR_ERROR_BRIBE_FAILED :{WHITE}あなたの行った贈収賄が地元当局に露見しました!
# Levelling errors # Levelling errors
@ -5535,3 +5549,8 @@ STR_SHIP :{BLACK}{SHIP}
STR_TOOLBAR_RAILTYPE_VELOCITY :{STRING} ({VELOCITY}) STR_TOOLBAR_RAILTYPE_VELOCITY :{STRING} ({VELOCITY})
STR_BADGE_CONFIG_MENU_TOOLTIP :バッジ設定を開く
STR_BADGE_CONFIG_RESET :リセット
STR_BADGE_CONFIG_ICONS :{WHITE}バッジのアイコン
STR_BADGE_CONFIG_FILTERS :{WHITE}バッジのフィルター
STR_BADGE_CONFIG_NAME :名前

View File

@ -37,6 +37,12 @@ if(NOT OPTION_DEDICATED)
CONDITION HAIKU CONDITION HAIKU
) )
add_files(
alsamidi.cpp
alsamidi.h
CONDITION ALSA_FOUND
)
add_files( add_files(
midi.h midi.h
midifile.cpp midifile.cpp

View File

@ -0,0 +1,604 @@
/*
* This file is part of OpenTTD.
* 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.
* 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.
* 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/>.
*/
/** @file alsamidi.cpp Support for ALSA Linux MIDI. */
#include "../stdafx.h"
#include "../openttd.h"
#include "alsamidi.h"
#include "../base_media_base.h"
#include "midifile.hpp"
#include "../debug.h"
#include "midi.h"
#include <chrono>
#include <thread>
#include "../safeguards.h"
/** Factory for ALSA MIDI player. */
static FMusicDriver_AlsaMidi iFMusicDriver_AlsaMidi;
std::optional<std::string_view> MusicDriver_AlsaMidi::Start(const StringList &parm)
{
this->playing.store(false);
Debug(driver, 2, "ALSA MIDI: Start");
this->dev_port = (uint)GetDriverParamInt(parm, "port", UINT_MAX);
Debug(driver, 2, "ALSA MIDI: using MIDI device at port {}", dev_port);
// Open sequencer
if (snd_seq_open(&this->seq, "default", SND_SEQ_OPEN_OUTPUT, 0) < 0) {
return "Failed to open ALSA sequencer";
}
snd_seq_set_client_name(this->seq, "OpenTTD MIDI Out");
// Create port
this->seq_port = snd_seq_create_simple_port(this->seq, "MIDI Out",
SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_SUBS_READ,
SND_SEQ_PORT_TYPE_MIDI_GENERIC|SND_SEQ_PORT_TYPE_APPLICATION);
if (this->seq_port < 0) {
return "Failed to create ALSA sequencer port";
}
// Create event queue
Debug(driver, 2, "ALSA MIDI: Creating sequencer event queue");
this->queue_id = snd_seq_alloc_named_queue(seq, "OpenTTD Sequencer Queue");
if (this->queue_id < 0) {
return "Failed to create ALSA sequencer event queue";
}
// Set a slightly larger event output buffer than normal
snd_seq_set_client_pool_output(this->seq, 1000);
snd_seq_set_client_pool_output_room(this->seq, 1000);
snd_seq_set_output_buffer_size(this->seq, 1000);
// Turn on nonblocking mode
snd_seq_nonblock(this->seq, 1);
snd_seq_addr_t sender, dest;
// Setup event port
sender.client = snd_seq_client_id(this->seq);
sender.port = this->seq_port;
dest.client = this->dev_port;
dest.port = this->seq_port;
snd_seq_port_subscribe_t* subs;
snd_seq_port_subscribe_alloca(&subs);
snd_seq_port_subscribe_set_sender(subs, &sender);
snd_seq_port_subscribe_set_dest(subs, &dest);
if (snd_seq_subscribe_port(this->seq, subs) < 0) {
return "Failed to connect to port";
}
Debug(driver, 2, "ALSA MIDI: opened sequencer port {}", this->seq_port);
this->InitMidiVolume();
return std::nullopt;
}
void MusicDriver_AlsaMidi::Stop()
{
Debug(driver, 2, "ALSA MIDI: stopping");
this->StopSong();
if (this->queue_id) {
Debug(driver, 2, "ALSA MIDI: freeing sequencer event queue");
snd_seq_free_queue(this->seq, this->queue_id);
}
if (this->seq) {
Debug(driver, 2, "ALSA MIDI: closing sequencer handle");
snd_seq_close(this->seq);
}
}
void MusicDriver_AlsaMidi::PlaySong(const MusicSongInfo &song)
{
Debug(driver, 2, "ALSA MIDI: PlaySong");
std::string filename = MidiFile::GetSMFFile(song);
smf::MidiFile midifile;
Debug(driver, 2, "ALSA MIDI: reading SMFFile");
if (!filename.empty()) {
if (!midifile.read(filename)) {
Debug(driver, 2, "ALSA MIDI: error reading SMFFile");
}
}
// Sort
midifile.sortTracks();
// Convert MIDI ticks to absolute seconds
midifile.doTimeAnalysis();
// Merge > 1 tracks into single track for easier queueing.
// (WriteSMF only creates single-track MIDIs, other packs may be multitrack)
midifile.joinTracks();
if (this->playing.load() == true) {
this->StopSong();
}
Debug(driver, 2, "ALSA MIDI: starting playback of {}", song.songname);
Debug(driver, 2, "ALSA MIDI: SMF filename {}", filename);
// ALSA does not allow setting PPQ on started queues, so do this first.
// Tempo may be adjusted later, on a started/running queue.
int ppq = midifile.getTPQ();
this->SetPPQ(ppq);
this->SetupPolling();
snd_seq_start_queue(this->seq, this->queue_id, nullptr);
snd_seq_drain_output(this->seq);
this->playing.store(true);
StartNewThread(&this->_queue_thread, "ottd:alsamidi", &StartQueue, this, std::move(midifile));
}
void MusicDriver_AlsaMidi::SetupPolling()
{
int poll_fd_cnt = snd_seq_poll_descriptors_count(this->seq, POLLOUT);
this->poll_fds.resize(poll_fd_cnt);
snd_seq_poll_descriptors(this->seq, this->poll_fds.data(), poll_fd_cnt, POLLOUT);
}
/**
* Starts the ALSA sequencer queue, iterates through the MIDI events in the file,
* converts them to ALSA sequencer events, and pushes them onto the queue.
*
* This function is blocking and expects to be run in a thread. It will block
* until either it is signaled to stop (in which case it will purge the ALSA queue,
* send a GM RESET, and terminate), or it has enqueued all events in the MIDI file,
* and waited for the queue to finish processing them all.
*
* @param drv Pointer to `this` instance of the class
* @param midifile The previously-loaded, sorted, and time-corrected STD MIDI file.
*
* @see Stopping()
* @see StopSong()
* @see WaitForFinish()
*/
static void StartQueue(MusicDriver_AlsaMidi *drv, const smf::MidiFile midifile)
{
Debug(driver, 2, "ALSA MIDI: queue thread started");
unsigned int last_tick;
// Push all events for all tracks to the sequencer queue
for (int track = 0; track < midifile.getNumTracks(); track++) {
std::vector<uint8_t> sysex_buffer;
for (int event = 0; event < midifile[track].size(); event++) {
auto& ev = midifile[track][event];
last_tick = static_cast<unsigned int>(ev.tick);
if (drv->Stopping()) {
Debug(driver, 2, "ALSA MIDI: Looks like we are stopping, bailing out of queue thread");
drv->SendResetEvent();
drv->StopQueue();
sysex_buffer.clear();
return;
}
if (ev.isTempo()) {
// Handle tempo change here, as we have to change it for the whole queue
Debug(driver, 2, "ALSA MIDI: Got tempo change event in queue thread");
int tempo_uspq = ev.getTempoMicroseconds();
drv->UpdateTempo(tempo_uspq);
continue;
}
// Handle SYSEX events
// SYSEX events may
// 1. Be a complete SYSEX event (begin with F0 and end with F7)
// 2. Be a "middle" SYSEX event (a previous message began with F0)
// 3. Be an "end" SYSEX event (a previous message began with F0, and this one ends with F7)
// This basically means you need an accumulator. Split SYSEX messages are *rare* but exist.
if (ev.getCommandByte() == MIDIST_SYSEX) {
Debug(driver, 2, "ALSA MIDI: got SYSEX message");
sysex_buffer.clear();
// If this is is a complete (not partial) SYSEX message, send it
// Otherwise, accumulate it as a partial and continue to the next
if (ev.back() == MIDIST_ENDSYSEX) {
Debug(driver, 2, "ALSA MIDI: complete SYSEX, sending");
sysex_buffer.insert(sysex_buffer.end(), ev.begin() + 1, ev.end() -1);
drv->SendSysexEvent(sysex_buffer);
sysex_buffer.clear();
} else {
sysex_buffer.insert(sysex_buffer.end(), ev.begin() + 1, ev.end());
}
continue;
}
if (!sysex_buffer.empty() && ev.back() == MIDIST_ENDSYSEX) {
Debug(driver, 2, "ALSA MIDI: partial SYSEX completed, sending");
sysex_buffer.insert(sysex_buffer.end(), ev.begin(), ev.end() -1);
drv->SendSysexEvent(sysex_buffer);
sysex_buffer.clear();
continue;
}
if (!sysex_buffer.empty()) {
Debug(driver, 2, "ALSA MIDI: partial SYSEX continuing");
sysex_buffer.insert(sysex_buffer.end(), ev.begin(), ev.end());
continue;
}
// At this point, it's just a regular event - handle it.
drv->SendEvent(ev);
}
}
Debug(driver, 2, "ALSA MIDI: queue thread finished, waiting for events");
drv->WaitForFinish(last_tick);
drv->StopQueue();
}
/**
* Stops the ALSA sequencer queue, and sets `playing` to false.
*
* Note that this does not clear or drop any pending events in the queue
* before stopping it.
*
* @see SendResetEvent()
*/
void MusicDriver_AlsaMidi::StopQueue()
{
Debug(driver, 2, "ALSA MIDI: stopping current queue!");
snd_seq_stop_queue(this->seq, this->queue_id, nullptr);
snd_seq_drain_output(this->seq);
this->poll_fds.clear();
this->playing.store(false);
}
/**
* Sends a SYSEX GM reset message, after dropping all pending events in the
* queue.
*
* Does not stop the queue.
*
* @see StopQueue()
*/
void MusicDriver_AlsaMidi::SendResetEvent()
{
// Drop anything still in the queue, this is a disruptive reset.
snd_seq_drop_output(this->seq);
std::vector<unsigned char> sysex_rst_msg = {0x7E, 0x7F, 0x09, 0x01};
this->SendSysexEvent(sysex_rst_msg);
}
/**
* Generic helper for sending SYSEX messages.
*
* Note that this sends all SYSEX messages as "direct"/unscheduled events
* (skips tick queue).
*
* @param data The SYSEX message data (excluding 0xF0/0xF7 begin/end markers).
*
* @see SendEvent()
*/
void MusicDriver_AlsaMidi::SendSysexEvent(const std::vector<uint8_t> data)
{
snd_seq_event_t seqev;
snd_seq_ev_clear(&seqev);
snd_seq_ev_set_source(&seqev, this->seq_port);
snd_seq_ev_set_subs(&seqev);
std::vector<uint8_t> complete_message;
complete_message.reserve(data.size() + 2);
complete_message.push_back(0xF0); // Start of SysEx
complete_message.insert(complete_message.end(), data.begin(), data.end());
complete_message.push_back(0xF7); // End of SysEx
snd_seq_ev_set_sysex(&seqev, complete_message.size(), complete_message.data());
// TODO this assumes all SYSEX msgs are immediate, and not queued with a tick
// this is correct for SYSEX GM RESET (all this is currently used for) but
// might not be globally correct.
snd_seq_ev_set_direct(&seqev);
this->PushEvent(seqev);
}
/**
* Generic helper for sending non-SYSEX messages.
*
* Converts MIDI events from the file into ALSA-specific sequencer queue events,
* and schedules them on the tick-based sequencer queue.
*
* @param ev The raw MIDI event from the file.
*
* @see SendSysexEvent()
*/
void MusicDriver_AlsaMidi::SendEvent(const smf::MidiEvent& ev)
{
snd_seq_event_t seqev;
snd_seq_ev_clear(&seqev);
unsigned int ticks = static_cast<unsigned int>(ev.tick);
if (ev.isNoteOn()) {
snd_seq_ev_set_noteon(&seqev, ev.getChannel(), ev[1], ev[2]);
} else if (ev.isNoteOff()) {
snd_seq_ev_set_noteoff(&seqev, ev.getChannel(), ev[1], ev[2]);
} else if (ev.isController()) {
if (ev[1] == MIDI_CTL_MSB_MAIN_VOLUME) {
this->UpdateChannelVolume(ev.getChannel(), ev[2]);
snd_seq_ev_set_controller(&seqev, ev.getChannel(), ev[1], this->vol_state.current_volume[ev.getChannel()]);
}
snd_seq_ev_set_controller(&seqev, ev.getChannel(), ev[1], ev[2]);
} else if (ev.isPatchChange()) {
snd_seq_ev_set_pgmchange(&seqev, ev.getChannel(), ev[1]);
} else if (ev.isPitchbend()) {
snd_seq_ev_set_pitchbend(&seqev, ev.getChannel(), ((ev[2] << 7) | ev[1]) - 8192);
} else if (ev.isPressure()) {
snd_seq_ev_set_chanpress(&seqev, ev.getChannel(), ev[1]);
} else if (ev.isAftertouch()) {
snd_seq_ev_set_keypress(&seqev, ev.getChannel(), ev[1], ev[2]);
} else if (ev.getCommandNibble() == 0xF0 && ev.getCommandByte() == MIDIST_SYSRESET) {
Debug(driver, 2, "ALSA MIDI: reset event");
snd_seq_ev_set_fixed(&seqev);
seqev.type = SND_SEQ_EVENT_RESET;
} else if (ev.isMeta()) {
Debug(driver, 2, "ALSA MIDI: ignoring meta message");
return;
} else {
Debug(driver, 2, "ALSA MIDI: unknown message: {}", ev.getCommandNibble());
return;
}
// Schedule event
snd_seq_ev_schedule_tick(&seqev, this->queue_id, 0, ticks);
snd_seq_ev_set_source(&seqev, this->seq_port);
snd_seq_ev_set_subs(&seqev);
this->PushEvent(seqev);
}
/**
* Waits until either:
*
* 1. The ALSA sequencer finishes processing up to the last event
* that was enqueued, as measured by comparing the tick value of the
* last event against the current tick value of the ALSA queue state.
*
* 2. `Stopping()` returns true, signaling early exit (don't wait for playback to finish).
*
* @param last_event_tick Tick value of the last event that was added to the queue.
*
* @see Stopping()
*/
void MusicDriver_AlsaMidi::WaitForFinish(const unsigned int last_event_tick)
{
Debug(driver, 2, "ALSA MIDI: waiting for events finish");
// First wait for queue to drain
int res = 0;
do {
res = snd_seq_drain_output(this->seq);
if (res != 0) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
} while (res != 0);
// Now get queue status and wait until we've passed the last scheduled tick
snd_seq_queue_status_t *status;
snd_seq_queue_status_alloca(&status);
do {
snd_seq_get_queue_status(this->seq, this->queue_id, status);
const snd_seq_tick_time_t current_tick = snd_seq_queue_status_get_tick_time(status);
if (this->Stopping()) {
Debug(driver, 2, "ALSA MIDI: got stop signal, not waiting for events to finish");
this->SendResetEvent();
break;
}
if (current_tick >= last_event_tick) {
// This is necessarily imprecise, just because the queue has processed the last
// tick event doesn't mean whatever output device in use has played it yet,
// but in practice this is good enough to not cut off the last few notes.
std::this_thread::sleep_for(std::chrono::milliseconds(500));
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(10));
} while(true);
Debug(driver, 2, "ALSA MIDI: events finished");
}
/**
* Pushes an ALSA sequencer event onto the ALSA sequencer queue.
*
* If the push fails because the output buffer is full, uses `poll()`
* to wait until there's space/device is ready.
*
* @param seqev ALSA sequencer event to push.
*/
void MusicDriver_AlsaMidi::PushEvent(snd_seq_event_t seqev)
{
// Wait for space in the queue via `poll()`
while (snd_seq_event_output_direct(this->seq, &seqev) < 0) {
poll(this->poll_fds.data(), this->poll_fds.size(), 100); // 100ms timeout
}
}
/**
* Signals the queue thread to terminate and joins it.
*/
void MusicDriver_AlsaMidi::StopSong()
{
this->stopping.store(true);
Debug(driver, 2, "ALSA MIDI: StopSong waiting for queue thread");
if (this->_queue_thread.joinable()) {
this->_queue_thread.join();
}
Debug(driver, 2, "ALSA MIDI: stopping current queue");
this->stopping.store(false);
Debug(driver, 2, "ALSA MIDI: stopped song");
}
bool MusicDriver_AlsaMidi::Stopping()
{
return this->stopping.load();
}
bool MusicDriver_AlsaMidi::IsSongPlaying()
{
return this->playing.load();
}
/**
* Sets the desired volume for the MIDI sequencer (from the UI thread)
*
* Note that this implementation will internally debounce rapid subsequent calls to
* SetVolume(), to avoid overwhelming the sequencer and its queues and buffers with
* incremental volume updates. The magnitude of the volume change is taken into account
* for this.
*
*/
void MusicDriver_AlsaMidi::SetVolume(uint8_t vol)
{
Debug(driver, 2, "ALSA MIDI: got volume level update {}", vol);
// Adaptive debounce: small changes need more time between updates
auto now = std::chrono::steady_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(now - this->last_volume_update);
int current_vol = this->current_vol.load();
int change_magnitude = std::abs(vol - current_vol);
int required_ms = change_magnitude < 5 ? SMALL_VOL_DEBOUNCE :
change_magnitude < 15 ? MED_VOL_DEBOUNCE :
LARGE_VOL_DEBOUNCE;
if (elapsed.count() >= required_ms || current_vol == 127) {
Debug(driver, 2, "ALSA MIDI: got volume level update {}", vol);
if (vol != current_vol) {
this->SetScaledVolume(vol);
this->last_volume_update = now;
}
}
}
/**
* Initializes the volume state for the player.
*
* @see UpdateChannelVolume()
* @see SetScaledVolume()
*/
void MusicDriver_AlsaMidi::InitMidiVolume()
{
this->last_volume_update = std::chrono::steady_clock::now();
this->vol_state.master_scale = 127;
for (int i = 0; i < MIDI_CHANNELS; i++) {
this->vol_state.base_volume[i] = 127;
this->vol_state.current_volume[i] = 127;
}
}
/**
* Scales current volume level for each channel according to the scale
* factor provided. This is to maintain the relative volume levels between
* channels as set by the midi file, while scaling up or down.
*
* @param channel to update the volume for.
* @param value requested volume level to scale selected channel volume against.
*/
void MusicDriver_AlsaMidi::UpdateChannelVolume(int channel, int value)
{
std::lock_guard<std::mutex> lock(this->vol_state.mutex);
this->vol_state.base_volume[channel] = value;
this->vol_state.current_volume[channel] = (value * this->vol_state.master_scale) / 127;
Debug(driver, 2, "ALSA MIDI: upading volume for channel {} to {}, base: {}, scale {}", channel, this->vol_state.current_volume[channel], this->vol_state.base_volume[channel], this->vol_state.master_scale);
}
/**
* Scales current volume level for each channel according to the scale
* factor provided. This is to maintain the relative volume levels between
* channels as set by the midi file, while scaling up or down.
*
* @param value requested volume level (0-127) to scale all channel volume levels against.
*/
void MusicDriver_AlsaMidi::SetScaledVolume(int value)
{
std::lock_guard<std::mutex> lock(this->vol_state.mutex);
this->vol_state.master_scale = (value > 127) ? 127 : (value < 0) ? 0 : value;
for (int i = 0; i < MIDI_CHANNELS; i++) {
this->vol_state.current_volume[i] = ( this->vol_state.base_volume[i] * this->vol_state.master_scale) / 127;
snd_seq_event_t vol_ev;
snd_seq_ev_clear(&vol_ev);
Debug(driver, 2, "ALSA MIDI: setting volume for channel {} to {}, master: {} base: {}", i, this->vol_state.current_volume[i], this->vol_state.master_scale, this->vol_state.base_volume[i]);
snd_seq_ev_set_controller(&vol_ev, i, MIDI_CTL_MSB_MAIN_VOLUME, this->vol_state.current_volume[i]);
snd_seq_ev_set_source(&vol_ev, this->seq_port);
snd_seq_ev_set_subs(&vol_ev);
snd_seq_ev_set_direct(&vol_ev);
this->PushEvent(vol_ev);
}
this->current_vol.store(value);
}
/**
* Updates the tempo of the current (started) ALSA sequencer queue.
*
* @param tempo_uspq Tempo value in units per quarter note.
*/
void MusicDriver_AlsaMidi::UpdateTempo(const int tempo_uspq)
{
if (snd_seq_change_queue_tempo(this->seq, this->queue_id, tempo_uspq, nullptr) < 0) {
throw std::runtime_error("Failed to update queue tempo");
}
snd_seq_drain_output(this->seq);
}
/**
* Updates the Pulses Per Quarternote (PPQ) of the current ALSA sequencer queue.
*
* Note that the PPQ of an ALSA sequencer queue cannot be changed after it is started.
*
* @param ppq Pulse per quarter note value.
*
* @see StopQueue()
*/
void MusicDriver_AlsaMidi::SetPPQ(const int ppq)
{
Debug(driver, 2, "ALSA MIDI: setting PPQ to {}", ppq);
snd_seq_queue_tempo_t* tempo;
snd_seq_queue_tempo_alloca(&tempo);
snd_seq_queue_tempo_set_ppq(tempo, ppq);
snd_seq_queue_tempo_set_tempo(tempo, 1000000); // 60 BPM
snd_seq_queue_status_t *status;
snd_seq_queue_status_alloca(&status);
snd_seq_get_queue_status(seq, queue_id, status);
if (snd_seq_queue_status_get_status(status) == 0) {
if (snd_seq_set_queue_tempo(this->seq, this->queue_id, tempo) < 0) {
throw std::runtime_error("Failed to set queue PPQ");
}
snd_seq_drain_output(this->seq);
} else {
Debug(driver, 2, "ALSA MIDI: tried to set PPQ on non-stopped queue!");
}
}

View File

@ -0,0 +1,93 @@
/*
* This file is part of OpenTTD.
* 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.
* 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.
* 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/>.
*/
/** @file alsamidi.h Base of Alsa MIDI support. */
#ifndef MUSIC_ALSAMIDI_H
#define MUSIC_ALSAMIDI_H
#include "music_driver.hpp"
#include <alsa/asoundlib.h>
#include "../3rdparty/midifile/MidiFile.h"
#include "../../thread.h"
#include <atomic>
const int SMALL_VOL_DEBOUNCE = 200; // Tiny changes: 200ms
const int MED_VOL_DEBOUNCE = 50; // Small changes: 50ms
const int LARGE_VOL_DEBOUNCE = 10; // Large changes: 10ms
/** The midi player for ALSA on Linux. */
class MusicDriver_AlsaMidi : public MusicDriver {
public:
std::optional<std::string_view> Start(const StringList &param) override;
void Stop() override;
void PlaySong(const MusicSongInfo &song) override;
void StopSong() override;
bool IsSongPlaying() override;
void SetVolume(uint8_t vol) override;
std::string_view GetName() const override { return "alsamidi"; }
void WaitForFinish(const unsigned int last_tick);
void StopQueue();
void SendEvent(const smf::MidiEvent& event);
void SendSysexEvent(const std::vector<uint8_t> data);
void SendResetEvent();
void UpdateTempo(const int tempo_uspq);
bool Stopping();
private:
typedef struct
{
int base_volume[MIDI_CHANNELS];
int master_scale;
int current_volume[MIDI_CHANNELS];
std::mutex mutex;
}MidiVolume;
MidiVolume vol_state;
snd_seq_t* seq;
int queue_id;
int seq_port;
int dev_port;
std::vector<struct pollfd> poll_fds;
std::thread _queue_thread;
std::atomic<bool> playing{false};
std::atomic<bool> stopping{false};
std::atomic<uint8_t> current_vol{127};
std::chrono::time_point<std::chrono::steady_clock> last_volume_update;
void SetPPQ(const int ppq);
void SetScaledVolume(int value);
void SetupPolling();
void PushEvent(snd_seq_event_t seqev);
void InitMidiVolume();
void UpdateChannelVolume(int channel, int value);
void VolumeAdjust (const uint8_t new_vol);
};
/** Factory for the Linux ALSA midi player. */
class FMusicDriver_AlsaMidi : public DriverFactoryBase {
public:
FMusicDriver_AlsaMidi() : DriverFactoryBase(Driver::DT_MUSIC, 10, "alsamidi", "ALSA Linux MIDI Driver") {}
Driver *CreateInstance() const override { return new MusicDriver_AlsaMidi(); }
};
static void StartQueue(MusicDriver_AlsaMidi *drv, const smf::MidiFile midifile);
#endif /* MUSIC_ALSAMIDI_H */