jfdelnero / HxCModPlayer

A simple and lite MOD (music module) player.
The Unlicense
100 stars 20 forks source link

Reading row events while playing #8

Open sphaero opened 3 years ago

sphaero commented 3 years ago

First of all my compliments for this player. It works really great!!!

I'm using this player to play mod files while also using the row events to trigger stuff. I.e. I'm using it in demos.

However I feel it must be easier to do. I'm calculating the time and buffer size it takes for a single row to process:

2500/this->modctx.bpm)*this->modctx.song.speed

I then read the current data and send it out with osc:

    note *cur_note = modctx.patterndata[state->cur_pattern] + (state->cur_pattern_pos * 4);

    // acquire values, see http://www.aes.id.au/modformat.html for details
    muint sample = (cur_note->sampperiod & 0xF0) | (cur_note->sampeffect >> 4);
    muint period = ((cur_note->sampperiod & 0xF) << 8) | cur_note->period;
    muint effect = ((cur_note->sampeffect & 0xF) << 8) | cur_note->effect;
    muchar effect_op = cur_note->sampeffect & 0xF;
    muchar effect_param = cur_note->effect;
    char effect_param_hex[3];
    sprintf(effect_param_hex, "%02X", effect_param);
    //muchar effect_param_l = effect_param & 0x0F;
    //muchar effect_param_h = effect_param >> 4;

    zosc_t *oscm = zosc_create("/patternevent", "iiiiics",
                                      state->cur_pattern_table_pos, // song pos
                                      state->cur_pattern,           // pattern nr
                                      state->cur_pattern_pos,       // pattern row
                                      period,   // note
                                      sample,
                                      HEXCHAR[effect_op],
                                      effect_param_hex
                                     );

This is also done for the other channels.

However I run into the situation that sometimes rows are skipped somehow. Perhaps because of a jump in the song or by other means.

I was wondering if anybody had thoughts or hints about how to accomplish this.

WindowsNT commented 2 years ago

Did you manage to calculate the total time of the song ?

sphaero commented 2 years ago

Well that's pretty hard since the song can change it's speed during playing and many mods do this. So there's no easy calculation. You could do it by parsing all the patterns for speed changes and use these for calculation.

Then there's also the issue that many mods can loop forever. Pick your battles :smile: