- use the intended interface to pass some data to the player.

This commit is contained in:
Christoph Oelckers 2018-02-20 21:52:45 +01:00
parent a8283ffdd6
commit cbcfea99cb
7 changed files with 48 additions and 86 deletions

View file

@ -48,6 +48,7 @@
#include "timiditypp/timidity.h" #include "timiditypp/timidity.h"
#include "timiditypp/instrum.h" #include "timiditypp/instrum.h"
#include "timiditypp/playmidi.h"
class TimidityPPMIDIDevice : public SoftSynthMIDIDevice class TimidityPPMIDIDevice : public SoftSynthMIDIDevice
{ {
@ -65,7 +66,7 @@ public:
void TimidityVolumeChanged(); void TimidityVolumeChanged();
protected: protected:
//TimidityPlus::Player *Renderer; TimidityPlus::Player *Renderer;
void HandleEvent(int status, int parm1, int parm2); void HandleEvent(int status, int parm1, int parm2);
void HandleLongEvent(const uint8_t *data, int len); void HandleLongEvent(const uint8_t *data, int len);
@ -118,7 +119,7 @@ TimidityPPMIDIDevice::TimidityPPMIDIDevice(const char *args)
} }
if (instruments != nullptr) if (instruments != nullptr)
{ {
//Renderer = new TimidityPlus::Player(timidity_frequency, instruments); Renderer = new TimidityPlus::Player(timidity_frequency, instruments);
} }
} }
@ -148,7 +149,7 @@ TimidityPPMIDIDevice::~TimidityPPMIDIDevice ()
namespace TimidityPlus namespace TimidityPlus
{ {
int load_midi_file(FileReader *fr, TimidityPlus::Instruments *inst); int load_midi_file(FileReader *fr, TimidityPlus::Player *p);
void run_midi(int samples); void run_midi(int samples);
void timidity_close(); void timidity_close();
} }
@ -158,7 +159,7 @@ bool TimidityPPMIDIDevice::Preprocess(MIDIStreamer *song, bool looping)
// Write MIDI song to temporary file // Write MIDI song to temporary file
song->CreateSMF(midi, looping ? 0 : 1); song->CreateSMF(midi, looping ? 0 : 1);
MemoryReader fr((char*)&midi[0], midi.Size()); MemoryReader fr((char*)&midi[0], midi.Size());
return !TimidityPlus::load_midi_file(&fr, instruments); return !TimidityPlus::load_midi_file(&fr, Renderer);
} }
//========================================================================== //==========================================================================
@ -230,10 +231,8 @@ void TimidityPPMIDIDevice::HandleLongEvent(const uint8_t *data, int len)
void TimidityPPMIDIDevice::ComputeOutput(float *buffer, int len) void TimidityPPMIDIDevice::ComputeOutput(float *buffer, int len)
{ {
Printf("Committing slice\n");
TimidityPlus::run_midi(len / 8); // bytes to samples TimidityPlus::run_midi(len / 8); // bytes to samples
memset(buffer, len, 0); // to do memset(buffer, len, 0); // to do
Printf("Done\n");
//Renderer->ComputeOutput(buffer, len); //Renderer->ComputeOutput(buffer, len);
} }

View file

@ -38,25 +38,6 @@
#include "c_cvars.h" #include "c_cvars.h"
#include "tables.h" #include "tables.h"
namespace TimidityPlus
{
int32_t control_ratio = 44;
}
// CVARs may not be placed in namespaces (but the above variable needs to.)
CUSTOM_CVAR(Int, playback_rate, 44100, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
{
const int CONTROLS_PER_SECOND = 1000;
const int MAX_CONTROL_RATIO = 255;
TimidityPlus::control_ratio = playback_rate / CONTROLS_PER_SECOND;
if (TimidityPlus::control_ratio < 1)
TimidityPlus::control_ratio = 1;
else if (TimidityPlus::control_ratio > MAX_CONTROL_RATIO)
TimidityPlus::control_ratio = MAX_CONTROL_RATIO;
}
CVAR(Bool, opt_modulation_wheel, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, opt_modulation_wheel, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Bool, opt_portamento, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, opt_portamento, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Bool, opt_nrpn_vibrato, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, opt_nrpn_vibrato, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
@ -109,8 +90,9 @@ CUSTOM_CVAR(Float, tempo_adjust, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
namespace TimidityPlus namespace TimidityPlus
{ {
// These two variables need to remain global or things will get messy because they get accessed from non-class code.
extern Instruments *instruments; int32_t control_ratio = 44;
int32_t playback_rate = 44100;
#define PLAY_INTERLEAVE_SEC 1.0 #define PLAY_INTERLEAVE_SEC 1.0
#define PORTAMENTO_TIME_TUNING (1.0 / 5000.0) #define PORTAMENTO_TIME_TUNING (1.0 / 5000.0)
@ -123,13 +105,25 @@ extern Instruments *instruments;
#define DEFAULT_AMPLIFICATION 70 #define DEFAULT_AMPLIFICATION 70
#define VIBRATO_DEPTH_MAX 384 /* 600 cent */ #define VIBRATO_DEPTH_MAX 384 /* 600 cent */
Player::Player() Player::Player(int freq, Instruments *instr)
{ {
const int CONTROLS_PER_SECOND = 1000;
const int MAX_CONTROL_RATIO = 255;
memset(this, 0, sizeof(*this));
playback_rate = freq;
control_ratio = playback_rate / CONTROLS_PER_SECOND;
if (control_ratio < 1)
control_ratio = 1;
else if (control_ratio > MAX_CONTROL_RATIO)
control_ratio = MAX_CONTROL_RATIO;
// init one-time global stuff - this should go to the device class once it exists. // init one-time global stuff - this should go to the device class once it exists.
instruments = instr;
initialize_resampler_coeffs(); initialize_resampler_coeffs();
init_tables(); init_tables();
memset(this, 0, sizeof(*this));
new_midi_file_info(); new_midi_file_info();
init_mblock(&playmidi_pool); init_mblock(&playmidi_pool);

View file

@ -523,7 +523,11 @@ public:
ChannelBitMask drumchannel_mask; ChannelBitMask drumchannel_mask;
ChannelBitMask drumchannels; ChannelBitMask drumchannels;
double *vol_table; double *vol_table;
int playback_rate;
int control_ratio;
// make this private later
Instruments *instruments;
private: private:
Recache *recache; Recache *recache;
Mixer *mixer; Mixer *mixer;
@ -701,7 +705,7 @@ private:
public: public:
Player(); Player(int freq, Instruments *);
~Player(); ~Player();
bool ISDRUMCHANNEL(int c) bool ISDRUMCHANNEL(int c)

View file

@ -268,28 +268,6 @@ const char *string_to_quantity(const char *string, Quantity *quantity, uint16_t
return number_to_quantity(number_i, suffix_i, number_f, suffix_f, quantity, type); return number_to_quantity(number_i, suffix_i, number_f, suffix_f, quantity, type);
} }
void int_to_quantity(int32_t number, Quantity *quantity, uint16_t type)
{
/* pass suffix_f NULL to warn if unit type is float type */
if (number_to_quantity(number, "", number, NULL, quantity, type) != NULL) /* error */
{
quantity->type = QUANTITY_UNIT_TYPE(DIRECT_INT);
quantity->unit = QUANTITY_UNIT_NAME(DIRECT_INT_NUM);
quantity->value.i = 0;
}
}
void float_to_quantity(double number, Quantity *quantity, uint16_t type)
{
/* pass suffix_i NULL to warn if unit type is integer type */
if (number_to_quantity(number, NULL, number, "", quantity, type) != NULL) /* error */
{
quantity->type = QUANTITY_UNIT_TYPE(DIRECT_FLOAT);
quantity->unit = QUANTITY_UNIT_NAME(DIRECT_FLOAT_NUM);
quantity->value.f = 0;
}
}
static int GetQuantityConvertProc(const Quantity *quantity, QuantityConvertProc *proc) static int GetQuantityConvertProc(const Quantity *quantity, QuantityConvertProc *proc)
{ {
QuantityHint units[MAX_QUANTITY_UNITS_PER_UNIT_TYPES], *unit; QuantityHint units[MAX_QUANTITY_UNITS_PER_UNIT_TYPES], *unit;

View file

@ -63,8 +63,6 @@ typedef struct Quantity_ {
} Quantity; } Quantity;
extern const char *string_to_quantity(const char *string, Quantity *quantity, uint16_t type); extern const char *string_to_quantity(const char *string, Quantity *quantity, uint16_t type);
extern void int_to_quantity(int32_t number, Quantity *quantity, uint16_t type);
extern void float_to_quantity(double number, Quantity *quantity, uint16_t type);
extern int32_t quantity_to_int(const Quantity *quantity, int32_t param); extern int32_t quantity_to_int(const Quantity *quantity, int32_t param);
extern double quantity_to_float(const Quantity *quantity, int32_t param); extern double quantity_to_float(const Quantity *quantity, int32_t param);

View file

@ -69,7 +69,6 @@ static MBlockList mempool;
static int current_read_track; static int current_read_track;
static int karaoke_format, karaoke_title_flag; static int karaoke_format, karaoke_title_flag;
static MidiEvent timesig[256]; static MidiEvent timesig[256];
extern Instruments *instruments;
extern void free_readmidi(void); extern void free_readmidi(void);
@ -388,7 +387,7 @@ MidiEvent *groom_list(int32_t divisions, int32_t *eventsp, int32_t *samplesp)
current_set[j] = 0; current_set[j] = 0;
else else
{ {
if (instruments->toneBank(newbank) == NULL) if (gplayer->instruments->toneBank(newbank) == NULL)
{ {
if (warn_tonebank[newbank] == 0) if (warn_tonebank[newbank] == 0)
{ {
@ -403,7 +402,7 @@ MidiEvent *groom_list(int32_t divisions, int32_t *eventsp, int32_t *samplesp)
bank_lsb[j] = bank_msb[j] = 0; bank_lsb[j] = bank_msb[j] = 0;
if (play_system_mode == XG_SYSTEM_MODE && j % 16 == 9) if (play_system_mode == XG_SYSTEM_MODE && j % 16 == 9)
bank_msb[j] = 127; /* Use MSB=127 for XG */ bank_msb[j] = 127; /* Use MSB=127 for XG */
current_program[j] = instruments->defaultProgram(j); current_program[j] = gplayer->instruments->defaultProgram(j);
} }
memset(warn_drumset, 0, sizeof(warn_drumset)); memset(warn_drumset, 0, sizeof(warn_drumset));
@ -454,13 +453,13 @@ MidiEvent *groom_list(int32_t divisions, int32_t *eventsp, int32_t *samplesp)
else else
current_set[j] = default_tonebank; current_set[j] = default_tonebank;
if (instruments->toneBank(current_set[j]) == NULL) if (gplayer->instruments->toneBank(current_set[j]) == NULL)
current_set[j] = 0; current_set[j] = 0;
} }
bank_lsb[j] = bank_msb[j] = 0; bank_lsb[j] = bank_msb[j] = 0;
if (play_system_mode == XG_SYSTEM_MODE && j % 16 == 9) if (play_system_mode == XG_SYSTEM_MODE && j % 16 == 9)
bank_msb[j] = 127; /* Use MSB=127 for XG */ bank_msb[j] = 127; /* Use MSB=127 for XG */
current_program[j] = instruments->defaultProgram(j); current_program[j] = gplayer->instruments->defaultProgram(j);
} }
break; break;
@ -572,9 +571,9 @@ MidiEvent *groom_list(int32_t divisions, int32_t *eventsp, int32_t *samplesp)
{ {
newbank = current_set[ch]; newbank = current_set[ch];
newprog = meep->event.a; newprog = meep->event.a;
instruments->instrument_map(mapID[ch], &newbank, &newprog); gplayer->instruments->instrument_map(mapID[ch], &newbank, &newprog);
if (!instruments->drumSet(newbank)) /* Is this a defined drumset? */ if (!gplayer->instruments->drumSet(newbank)) /* Is this a defined drumset? */
{ {
if (warn_drumset[newbank] == 0) if (warn_drumset[newbank] == 0)
{ {
@ -586,7 +585,7 @@ MidiEvent *groom_list(int32_t divisions, int32_t *eventsp, int32_t *samplesp)
} }
/* Mark this instrument to be loaded */ /* Mark this instrument to be loaded */
instruments->mark_drumset(newbank, newprog); gplayer->instruments->mark_drumset(newbank, newprog);
} }
else else
{ {
@ -594,8 +593,8 @@ MidiEvent *groom_list(int32_t divisions, int32_t *eventsp, int32_t *samplesp)
break; break;
newbank = current_set[ch]; newbank = current_set[ch];
newprog = current_program[ch]; newprog = current_program[ch];
instruments->instrument_map(mapID[ch], &newbank, &newprog); gplayer->instruments->instrument_map(mapID[ch], &newbank, &newprog);
if (instruments->toneBank(newbank) == NULL) if (gplayer->instruments->toneBank(newbank) == NULL)
{ {
if (warn_tonebank[newbank] == 0) if (warn_tonebank[newbank] == 0)
{ {
@ -607,7 +606,7 @@ MidiEvent *groom_list(int32_t divisions, int32_t *eventsp, int32_t *samplesp)
} }
/* Mark this instrument to be loaded */ /* Mark this instrument to be loaded */
instruments->mark_instrument(newbank, newprog); gplayer->instruments->mark_instrument(newbank, newprog);
} }
break; break;
@ -769,8 +768,8 @@ static void insert_note_steps(void)
static void free_readmidi(void) static void free_readmidi(void)
{ {
reuse_mblock(&mempool); reuse_mblock(&mempool);
instruments->free_userdrum(); gplayer->instruments->free_userdrum();
instruments->free_userinst(); gplayer->instruments->free_userinst();
} }
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
@ -882,12 +881,12 @@ static int read_sysex_event(int32_t at, int me, int32_t len,
reuse_mblock(&tmpbuffer); reuse_mblock(&tmpbuffer);
return -1; return -1;
} }
if (sc.parse_sysex_event(val, len, &ev, instruments)) if (sc.parse_sysex_event(val, len, &ev, gplayer->instruments))
{ {
ev.time = at; ev.time = at;
readmidi_add_event(&ev); readmidi_add_event(&ev);
} }
if ((ne = sc.parse_sysex_event_multi(val, len, evm, instruments))) if ((ne = sc.parse_sysex_event_multi(val, len, evm, gplayer->instruments)))
{ {
for (i = 0; i < ne; i++) { for (i = 0; i < ne; i++) {
evm[i].time = at; evm[i].time = at;
@ -1509,17 +1508,17 @@ static int play_midi_load_file(FileReader *fr,
//if (!opt_realtime_playing) //if (!opt_realtime_playing)
{ {
rc = RC_OK; rc = RC_OK;
instruments->load_missing_instruments(&rc); gplayer->instruments->load_missing_instruments(&rc);
if (RC_IS_SKIP_FILE(rc)) if (RC_IS_SKIP_FILE(rc))
{ {
/* Instrument loading is terminated */ /* Instrument loading is terminated */
instruments->clear_magic_instruments(); gplayer->instruments->clear_magic_instruments();
return rc; return rc;
} }
} }
} }
else else
instruments->clear_magic_instruments(); /* Clear load markers */ gplayer->instruments->clear_magic_instruments(); /* Clear load markers */
return RC_OK; return RC_OK;
} }
@ -1530,7 +1529,7 @@ Instruments *instruments;
CRITICAL_SECTION critSect; CRITICAL_SECTION critSect;
int load_midi_file(FileReader *fr, TimidityPlus::Instruments *inst) int load_midi_file(FileReader *fr, TimidityPlus::Player *p)
{ {
int rc; int rc;
static int last_rc = RC_OK; static int last_rc = RC_OK;
@ -1538,16 +1537,13 @@ int load_midi_file(FileReader *fr, TimidityPlus::Instruments *inst)
int32_t nsamples; int32_t nsamples;
gplayer = p;
InitializeCriticalSection(&critSect); InitializeCriticalSection(&critSect);
if (play_mode->open_output() < 0) if (play_mode->open_output() < 0)
{ {
return RC_ERROR; return RC_ERROR;
} }
instruments = inst;
gplayer = new Player;
/* Set current file information */ /* Set current file information */
auto current_file_info = gplayer->get_midi_file_info("zdoom", 1); auto current_file_info = gplayer->get_midi_file_info("zdoom", 1);
@ -1578,7 +1574,6 @@ void run_midi(int msec)
void timidity_close() void timidity_close()
{ {
delete gplayer;
play_mode->close_output(); play_mode->close_output();
DeleteCriticalSection(&critSect); DeleteCriticalSection(&critSect);
free_global_mblock(); free_global_mblock();

View file

@ -38,16 +38,8 @@
#endif #endif
EXTERN_CVAR(Int, playback_rate)
EXTERN_CVAR(Int, key_adjust) EXTERN_CVAR(Int, key_adjust)
EXTERN_CVAR(Float, tempo_adjust) EXTERN_CVAR(Float, tempo_adjust)
namespace TimidityPlus
{
extern int32_t control_ratio; // derived from playback_rate
}
EXTERN_CVAR(Bool, opt_modulation_wheel) EXTERN_CVAR(Bool, opt_modulation_wheel)
EXTERN_CVAR(Bool, opt_portamento) EXTERN_CVAR(Bool, opt_portamento)
EXTERN_CVAR(Bool, opt_nrpn_vibrato) EXTERN_CVAR(Bool, opt_nrpn_vibrato)
@ -145,6 +137,8 @@ EXTERN_CVAR(Bool, opt_modulation_envelope)
namespace TimidityPlus namespace TimidityPlus
{ {
extern int32_t playback_rate;
extern int32_t control_ratio; // derived from playback_rate
enum play_system_modes enum play_system_modes
{ {