Skip to content

Commit

Permalink
MIDI updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dashodanger committed Jul 26, 2024
1 parent 5dd0234 commit 064cf18
Show file tree
Hide file tree
Showing 6 changed files with 678 additions and 481 deletions.
2 changes: 1 addition & 1 deletion libraries/steve/src/Steve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void steve::add_note(Notes &notes, uint8_t channel, uint8_t tone, size_t start,
Note note;
note.channel = channel;
note.tone = tone;
note.velocity = clamp(velocity + Rand::next_velocity_jitter(), 0, 96);
note.velocity = clamp(velocity + Rand::next_velocity_jitter(), 0, 127);
note.duration = length;
notes.insert(make_pair(start, note));
}
Expand Down
5 changes: 1 addition & 4 deletions libraries/steve/src/creator/Bass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ Bass::Bass(Music *music) : Creator(music)
void Bass::init()
{
Creator::init();

_min_tone = 36;
_max_tone = _min_tone + 12;
}
Notes Bass::get(size_t start, size_t size) const
{
Expand All @@ -34,5 +31,5 @@ Notes Bass::get(size_t start, size_t size) const
}
bool Bass::is_valid_instrument(const Instrument &instrument) const
{
return instrument.midi_id >= 33 && instrument.midi_id <= 40;
return instrument.midi_id >= 32 && instrument.midi_id <= 39;
}
55 changes: 48 additions & 7 deletions libraries/steve/src/creator/Drums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

using namespace steve;

static const std::vector<uint8_t> bass = {35, 36};
static const std::vector<uint8_t> snare = {38, 40};
static const std::vector<uint8_t> tom = {41,43,45,47,48,50};
static const std::vector<uint8_t> hi_hat = {42,44,46};
static const std::vector<uint8_t> cymbal = {49,51,55,57,59};

Drums::Drums(Music *music) : Creator(music)
{
}
Expand All @@ -31,21 +37,56 @@ Notes Drums::get(size_t, size_t size) const
uint32_t layers(Rand::next(2, 5));
for (uint32_t i(0); i < layers; i++)
{
//uint8_t tone(Rand::next(35, 59));
uint8_t tone(Rand::next(35, 36));
NoteValue period_value = (max_period <= NoteValue::half) ? max_period : Rand::next(NoteValue::half, max_period);
uintptr_t period = ticks_for(period_value);
uintptr_t offset = ticks_for((period_value <= NoteValue::half) ? period_value : Rand::next(NoteValue::half, period_value));
uint8_t tone;
NoteValue period_value; // = (max_period <= NoteValue::quarter) ? max_period : Rand::next(NoteValue::quarter, max_period);
//NoteValue period_value = Rand::next(NoteValue::eighth, max_period);
uintptr_t period;// = ticks_for(period_value);
//uintptr_t offset = ticks_for(Rand::next(NoteValue::eighth, period_value));
uintptr_t offset;// = ticks_for((period_value <= NoteValue::quarter) ? period_value : Rand::next(NoteValue::quarter, period_value));
switch (i)
{
case 0:
tone = Rand::in(bass);
period_value = (max_period <= NoteValue::half) ? max_period : Rand::next(NoteValue::half, max_period);
period = ticks_for(period_value);
offset = ticks_for((period_value <= NoteValue::quarter) ? period_value : Rand::next(NoteValue::quarter, period_value));
break;
case 1:
tone = Rand::in(snare);
period_value = (max_period <= NoteValue::quarter) ? max_period : Rand::next(NoteValue::quarter, max_period);
period = ticks_for(period_value);
offset = ticks_for((period_value <= NoteValue::eighth) ? period_value : Rand::next(NoteValue::eighth, period_value));
break;
case 2:
tone = Rand::in(tom);
period_value = (max_period <= NoteValue::eighth) ? max_period : Rand::next(NoteValue::eighth, max_period);
period = ticks_for(period_value);
offset = ticks_for((period_value <= NoteValue::sixteenth) ? period_value : Rand::next(NoteValue::sixteenth, period_value));
break;
case 3:
tone = Rand::in(hi_hat);
period_value = (max_period <= NoteValue::eighth) ? max_period : Rand::next(NoteValue::eighth, max_period);
period = ticks_for(period_value);
offset = ticks_for((period_value <= NoteValue::sixteenth) ? period_value : Rand::next(NoteValue::sixteenth, period_value));
break;
case 4:
tone = Rand::in(cymbal);
period_value = (max_period <= NoteValue::eighth) ? max_period : Rand::next(NoteValue::eighth, max_period);
period = ticks_for(period_value);
offset = ticks_for((period_value <= NoteValue::sixteenth) ? period_value : Rand::next(NoteValue::sixteenth, period_value));
break;
default:
break;
}
if (i == 0 || Rand::next(0, 3) > 0)
{
offset = 0;
}

for (uintptr_t j(offset); j < size; j += period)
{
if (_music->is_beat(j))
{
add_note(notes, _channel, tone, j, 1, 64);
add_note(notes, _channel, tone, j, 1, 100);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions modules/midi_generation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ end

function MIDI_CONFIG.all_done()
for _,song in pairs(GAME.RESOURCES.MUSIC_LUMPS) do
gui.prog_step("Generating MIDI...")
if gui.generate_midi_track("scripts/midi/" .. PARAM.midi_config_selection .. ".json", "temp/" .. song .. ".mid") == 1 then
if ob_mod_enabled("compress_output") == 1 then
gui.pk3_insert_file("temp/" .. song .. ".mid", "music/" .. song .. ".mid")
Expand Down
Loading

0 comments on commit 064cf18

Please sign in to comment.