• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

コミットメタ情報

リビジョンb9e532e6acd0b93a5960405adcc3eb1b6d959bb2 (tree)
日時2019-09-05 10:50:33
作者Starg <starg@user...>
コミッターStarg

ログメッセージ

Add support for round robin

変更サマリ

差分

--- a/timidity/instrum.c
+++ b/timidity/instrum.c
@@ -940,6 +940,14 @@ static void apply_bank_parameter(Instrument *ip, ToneBankElement *tone)
940940 }
941941 }
942942 }
943+ if (tone->seq_length > 0)
944+ for (i = 0; i < ip->samples; i++) {
945+ ip->sample[i].seq_length = tone->seq_length;
946+ }
947+ if (tone->seq_position > 0)
948+ for (i = 0; i < ip->samples; i++) {
949+ ip->sample[i].seq_position = tone->seq_position;
950+ }
943951 }
944952
945953 #define READ_CHAR(thing) { \
@@ -2458,6 +2466,8 @@ static void init_tone_bank_element(ToneBankElement *tone)
24582466 tone->sample_pan = -1;
24592467 tone->sample_width = -1;
24602468 tone->vfxe_num = 0;
2469+ tone->seq_length = 0;
2470+ tone->seq_position = 0;
24612471 }
24622472
24632473 ///r
--- a/timidity/instrum.h
+++ b/timidity/instrum.h
@@ -77,7 +77,10 @@ typedef struct _Sample {
7777 int vfx[VOICE_EFFECT_NUM][VOICE_EFFECT_PARAM_NUM];
7878 int8 keep_voice;
7979 int8 def_pan;
80- FLOAT_T sample_pan;
80+ FLOAT_T sample_pan;
81+
82+ int32 seq_length; /* length of the round robin, 0 == disabled */
83+ int32 seq_position; /* 1-based position within the round robin, 0 == disabled */
8184 } Sample;
8285
8386 ///r
@@ -203,6 +206,8 @@ typedef struct {
203206 int8 element_num;
204207 int8 def_pan;
205208 int sample_pan, sample_width;
209+ int32 seq_length;
210+ int32 seq_position;
206211 } ToneBankElement;
207212
208213 #define MAGIC_ERROR_INSTRUMENT ((Instrument *)(-1))
--- a/timidity/playmidi.c
+++ b/timidity/playmidi.c
@@ -377,7 +377,7 @@ static double compensation_ratio = 1.0; /* compensation ratio */
377377 static int32 compute_skip_count = -1; // def use do_compute_data_midi()
378378
379379 static int find_samples(MidiEvent *, int *);
380-static int select_play_sample(Sample *, int, int *, int *, MidiEvent *, int);
380+static int select_play_sample(Sample *, int, int *, int *, MidiEvent *, int, int);
381381 static double get_play_note_ratio(int, int);
382382 static int find_voice(MidiEvent *);
383383 static void finish_note(int i);
@@ -719,6 +719,14 @@ void free_playmidi(void)
719719 }
720720 }
721721 #endif
722+
723+ for(i = 0; i < MAX_CHANNELS; i++){
724+ for (int j = 0; j < MAX_ELEMENT; j++) {
725+ safe_free(channel[i].seq_counters[j]);
726+ channel[i].seq_counters[j] = NULL;
727+ channel[i].seq_num_counters[j] = 0;
728+ }
729+ }
722730
723731 #ifdef VOICE_EFFECT
724732 if (!voice)
@@ -1243,6 +1251,11 @@ static void initialize_controllers(int c)
12431251 memset(channel[c].reverb_part_param, 0, sizeof(channel[c].reverb_part_param));
12441252 channel[c].reverb_part_efx_level = 100;
12451253
1254+ for (int i = 0; i < MAX_ELEMENT; i++) {
1255+ safe_free(channel[c].seq_counters[i]);
1256+ channel[c].seq_counters[i] = NULL;
1257+ channel[c].seq_num_counters[i] = 0;
1258+ }
12461259 }
12471260
12481261 /* Process the Reset All Controllers event CC#121 */
@@ -3138,7 +3151,7 @@ static int find_samples(MidiEvent *e, int *vlist)
31383151 }
31393152 note = e->a + channel[ch].key_shift + note_key_offset;
31403153 note = (note < 0) ? 0 : ((note > 127) ? 127 : note);
3141- return select_play_sample(s->sample, s->samples, &note, vlist, e, nv);
3154+ return select_play_sample(s->sample, s->samples, &note, vlist, e, nv, 0);
31423155 }
31433156 bank = channel[ch].bank;
31443157 if (ISDRUMCHANNEL(ch)) {
@@ -3164,7 +3177,7 @@ static int find_samples(MidiEvent *e, int *vlist)
31643177 if (ip->sample->note_to_use)
31653178 note = ip->sample->note_to_use;
31663179 nvo = nv;
3167- nv = select_play_sample(ip->sample, ip->samples, &note, vlist, e, nv);
3180+ nv = select_play_sample(ip->sample, ip->samples, &note, vlist, e, nv, elm);
31683181 nvt += nv;
31693182 /* Replace the sample if the sample is cached. */
31703183 if (! prescanning_flag) {
@@ -3189,7 +3202,7 @@ static int find_samples(MidiEvent *e, int *vlist)
31893202 ip = default_instrument;
31903203 note = ((ip->sample->note_to_use) ? ip->sample->note_to_use : e->a) + channel[ch].key_shift + note_key_offset;
31913204 note = (note < 0) ? 0 : ((note > 127) ? 127 : note);
3192- nv = select_play_sample(ip->sample, ip->samples, &note, vlist, e, nv);
3205+ nv = select_play_sample(ip->sample, ip->samples, &note, vlist, e, nv, 0);
31933206 nvt += nv;
31943207 } else {
31953208 instrument_map(channel[ch].mapID, &bank, &prog);
@@ -3206,7 +3219,7 @@ static int find_samples(MidiEvent *e, int *vlist)
32063219 note = ((ip->sample->note_to_use) ? ip->sample->note_to_use : e->a) + channel[ch].key_shift + note_key_offset;
32073220 note = (note < 0) ? 0 : ((note > 127) ? 127 : note);
32083221 nvo = nv;
3209- nv = select_play_sample(ip->sample, ip->samples, &note, vlist, e, nv);
3222+ nv = select_play_sample(ip->sample, ip->samples, &note, vlist, e, nv, elm);
32103223 nvt += nv;
32113224 /* Replace the sample if the sample is cached. */
32123225 if (! prescanning_flag) {
@@ -3257,7 +3270,7 @@ elm_max :
32573270 }
32583271 ///r
32593272 static int select_play_sample(Sample *splist,
3260- int nsp, int *note, int *vlist, MidiEvent *e, int nv)
3273+ int nsp, int *note, int *vlist, MidiEvent *e, int nv, int elm)
32613274 {
32623275 int ch = e->channel, kn = e->a & 0x7f, vel = e->b;
32633276 int32 f, fs, ft, fst, fc, fr, cdiff, diff, sample_link;
@@ -3340,6 +3353,15 @@ static int select_play_sample(Sample *splist,
33403353 vel = rvel;
33413354 }
33423355 #endif
3356+
3357+ // allocate round robin counters
3358+ if (channel[ch].seq_num_counters[elm] == 0) {
3359+ channel[ch].seq_num_counters[elm] = nsp;
3360+ channel[ch].seq_counters[elm] = (int32 *)safe_malloc(sizeof(int32) * nsp);
3361+ for (int i = 0; i < nsp; i++)
3362+ channel[ch].seq_counters[elm][i] = 1;
3363+ }
3364+
33433365 #if 1
33443366 /*
33453367 ƒTƒ“ƒvƒ‹Žw’è‚Í ƒm[ƒiƒ“ƒo[,ƒxƒƒVƒeƒB ‚ªŠeƒŒƒ“ƒW“à‚É‚ ‚é‚à‚Ì‘S‚Ä
@@ -3348,6 +3370,18 @@ static int select_play_sample(Sample *splist,
33483370 for (i = 0, sp = splist; i < nsp; i++, sp++) {
33493371 if (((sp->low_key <= *note && sp->high_key >= *note))
33503372 && sp->low_vel <= vel && sp->high_vel >= vel) {
3373+
3374+ if (sp->seq_length > 0) {
3375+ int32 seq_count = channel[ch].seq_counters[elm][i];
3376+ channel[ch].seq_counters[elm][i]++;
3377+
3378+ if (channel[ch].seq_counters[elm][i] > sp->seq_length)
3379+ channel[ch].seq_counters[elm][i] = 1;
3380+
3381+ if (seq_count != sp->seq_position)
3382+ continue;
3383+ }
3384+
33513385 /* GUS/SF2 - Scale Tuning */
33523386 if ((sf = sp->scale_factor) != 1024) {
33533387 sn = sp->scale_freq;
@@ -5855,6 +5889,13 @@ void midi_program_change(int ch, int prog)
58555889 newbank = channel[ch].bank_msb;
58565890 break;
58575891 }
5892+
5893+ for (int i = 0; i < MAX_ELEMENT; i++) {
5894+ safe_free(channel[ch].seq_counters[i]);
5895+ channel[ch].seq_counters[i] = NULL;
5896+ channel[ch].seq_num_counters[i] = 0;
5897+ }
5898+
58585899 if (dr) {
58595900 channel[ch].bank = prog; // newbank is ignored
58605901 channel[ch].program = prog;
--- a/timidity/playmidi.h
+++ b/timidity/playmidi.h
@@ -484,6 +484,8 @@ typedef struct {
484484 uint8 detune_param;
485485 FLOAT_T detune; /* in Hz */
486486
487+ int32 *seq_counters[MAX_ELEMENT];
488+ int seq_num_counters[MAX_ELEMENT];
487489 } Channel;
488490
489491 /* Causes the instrument's default panning to be used. */
--- a/timidity/sfz.cpp
+++ b/timidity/sfz.cpp
@@ -827,6 +827,8 @@ enum class OpCodeKind
827827 Pan,
828828 PitchKeyCenter,
829829 Sample,
830+ SequenceLength,
831+ SequencePosition,
830832 Transpose,
831833 Trigger,
832834 Tune,
@@ -989,6 +991,8 @@ public:
989991 case OpCodeKind::LoVelocity:
990992 case OpCodeKind::Offset:
991993 case OpCodeKind::Pan:
994+ case OpCodeKind::SequenceLength:
995+ case OpCodeKind::SequencePosition:
992996 case OpCodeKind::Transpose:
993997 case OpCodeKind::Tune:
994998 case OpCodeKind::Volume:
@@ -1136,6 +1140,8 @@ private:
11361140 {"pan"sv, OpCodeKind::Pan},
11371141 {"pitch_keycenter"sv, OpCodeKind::PitchKeyCenter},
11381142 {"sample"sv, OpCodeKind::Sample},
1143+ {"seq_length"sv, OpCodeKind::SequenceLength},
1144+ {"seq_position"sv, OpCodeKind::SequencePosition},
11391145 {"transpose"sv, OpCodeKind::Transpose},
11401146 {"trigger"sv, OpCodeKind::Trigger},
11411147 {"tune"sv, OpCodeKind::Tune},
@@ -1609,6 +1615,50 @@ private:
16091615 // convert percent to rate
16101616 std::fill(std::begin(s.envelope_velf), std::end(s.envelope_velf), std::clamp(ampVelTrack.value() * 0.01, -1.0, 1.0) * 1200.0 / 127.0);
16111617 }
1618+
1619+ if (auto seqLen = flatSection.GetAs<double>(OpCodeKind::SequenceLength))
1620+ {
1621+ s.seq_length = std::clamp(static_cast<int32>(std::round(seqLen.value())), 1, 100);
1622+
1623+ if (auto seqPos = flatSection.GetAs<double>(OpCodeKind::SequencePosition))
1624+ {
1625+ s.seq_position = std::clamp(static_cast<int32>(std::round(seqPos.value())), 1, 100);
1626+
1627+ if (s.seq_length < s.seq_position)
1628+ {
1629+ auto loc = flatSection.GetLocationForOpCode(OpCodeKind::SequencePosition);
1630+ ctl->cmsg(
1631+ CMSG_WARNING,
1632+ VERB_VERBOSE,
1633+ "%s(%u): 'seq_position' is larger than 'seq_length'; this region will never be played",
1634+ std::string(m_Parser.GetPreprocessor().GetFileNameFromID(loc.FileID)).c_str(),
1635+ loc.Line
1636+ );
1637+ }
1638+ }
1639+ else
1640+ {
1641+ auto loc = flatSection.GetLocationForOpCode(OpCodeKind::SequenceLength);
1642+ ctl->cmsg(
1643+ CMSG_WARNING,
1644+ VERB_VERBOSE,
1645+ "%s(%u): 'seq_length' was specified but 'seq_position' was not; this region will never be played",
1646+ std::string(m_Parser.GetPreprocessor().GetFileNameFromID(loc.FileID)).c_str(),
1647+ loc.Line
1648+ );
1649+ }
1650+ }
1651+ else if (auto seqPos = flatSection.GetAs<double>(OpCodeKind::SequencePosition))
1652+ {
1653+ auto loc = flatSection.GetLocationForOpCode(OpCodeKind::SequencePosition);
1654+ ctl->cmsg(
1655+ CMSG_WARNING,
1656+ VERB_VERBOSE,
1657+ "%s(%u): 'seq_position' was specified but 'seq_length' was not",
1658+ std::string(m_Parser.GetPreprocessor().GetFileNameFromID(loc.FileID)).c_str(),
1659+ loc.Line
1660+ );
1661+ }
16121662 }
16131663
16141664 return pSampleInstrument;
--- a/timidity/smplfile.c
+++ b/timidity/smplfile.c
@@ -1496,6 +1496,9 @@ static void initialize_sample(Instrument *inst, int frames, int sample_bits, int
14961496 sample->modenv_rate[4] = convert_envelope_rate(64);
14971497 sample->modenv_offset[5] = 0;
14981498 sample->modenv_rate[5] = convert_envelope_rate(64);
1499+
1500+ sample->seq_length = 0;
1501+ sample->seq_position = 0;
14991502 }
15001503 if (samples <= 6 && (panning = gen_pan_list[samples - 1]) != NULL)
15011504 {
--- a/timidity/timidity.c
+++ b/timidity/timidity.c
@@ -1705,6 +1705,10 @@ static int set_gus_patchconf_opts(const char *name,
17051705 tone->rx_note_off = atoi(cp);
17061706 else if (! strcmp(opts, "lpf")) /* lpf type */
17071707 tone->lpf_type = atoi(cp);
1708+ else if (! strcmp(opts, "seqlen"))
1709+ tone->seq_length = atoi(cp);
1710+ else if (! strcmp(opts, "seqpos"))
1711+ tone->seq_position = atoi(cp);
17081712 else if (! strcmp(opts, "hpf")){ /* hpf */
17091713 if(tone->hpfnum)
17101714 free_ptr_list(tone->hpf, tone->hpfnum);