From b0af6a056b52392cccce6de07080bd371017cbb2 Mon Sep 17 00:00:00 2001 From: dashodanger Date: Wed, 3 Jul 2024 00:14:55 -0600 Subject: [PATCH] MIDI generator adjustments --- libraries/steve/src/Steve.cpp | 2 +- libraries/steve/src/creator/Drums.cpp | 9 +- modules/midi_generation.lua | 2 +- scripts/midi/{all.json => relaxed.json} | 0 scripts/midi/safe.json | 760 ++++++++++++++++++++++-- source/lib_midi.cc | 35 +- 6 files changed, 736 insertions(+), 72 deletions(-) rename scripts/midi/{all.json => relaxed.json} (100%) diff --git a/libraries/steve/src/Steve.cpp b/libraries/steve/src/Steve.cpp index 5f48d13c9..edacf83e5 100644 --- a/libraries/steve/src/Steve.cpp +++ b/libraries/steve/src/Steve.cpp @@ -102,7 +102,7 @@ void steve::add_note(Notes ¬es, 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, 127); + note.velocity = clamp(velocity + Rand::next_velocity_jitter(), 0, 96); note.duration = length; notes.insert(make_pair(start, note)); } diff --git a/libraries/steve/src/creator/Drums.cpp b/libraries/steve/src/creator/Drums.cpp index 25c74ce8a..d4e17ee3c 100644 --- a/libraries/steve/src/creator/Drums.cpp +++ b/libraries/steve/src/creator/Drums.cpp @@ -31,10 +31,11 @@ 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)); - NoteValue period_value = Rand::next(NoteValue::eighth, max_period); + //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(Rand::next(NoteValue::eighth, period_value)); + uintptr_t offset = ticks_for((period_value <= NoteValue::half) ? period_value : Rand::next(NoteValue::half, period_value)); if (i == 0 || Rand::next(0, 3) > 0) { offset = 0; @@ -44,7 +45,7 @@ Notes Drums::get(size_t, size_t size) const { if (_music->is_beat(j)) { - add_note(notes, _channel, tone, j, 1, 100); + add_note(notes, _channel, tone, j, 1, 64); } } } diff --git a/modules/midi_generation.lua b/modules/midi_generation.lua index 49f3a6fa1..0649f3420 100644 --- a/modules/midi_generation.lua +++ b/modules/midi_generation.lua @@ -3,7 +3,7 @@ MIDI_CONFIG = {} MIDI_CONFIG.CHOICES = { "safe", _("Safe Defaults"), - "all", _("Relaxed (May Sound Weird)") + "relaxed", _("Relaxed (May Sound Weird)") } function MIDI_CONFIG.setup(self) diff --git a/scripts/midi/all.json b/scripts/midi/relaxed.json similarity index 100% rename from scripts/midi/all.json rename to scripts/midi/relaxed.json diff --git a/scripts/midi/safe.json b/scripts/midi/safe.json index 286881831..43fe18e56 100644 --- a/scripts/midi/safe.json +++ b/scripts/midi/safe.json @@ -1,21 +1,183 @@ { "min_tempo": 80, - "max_tempo": 160, + "max_tempo": 100, "time_signatures": { - "2/2": { - "weight": 2 + "2/2":{}, "2/4":{}, "3/4":{}, "3/8": {}, "4/4":{}, "5/4":{}, "6/4":{}, "6/8":{}, "7/4":{}, "9/8":{}, "12/8": {} + }, + "chords": { + "Power": { + "suffix": "", + "tones": [7] + }, + "Major": { + "suffix": "maj", + "tones": [4, 7] + }, + "Minor": { + "suffix": "min", + "tones": [3, 7] + }, + "Augmented": { + "suffix": "aug", + "tones": [4, 8] + }, + "Diminished": { + "suffix": "dim", + "tones": [3, 6] + }, + "Suspended Second": { + "suffix": "sus2", + "tones": [2, 7] + }, + "Suspended Fourth": { + "suffix": "sus4", + "tones": [5, 7] + }, + "Major Seventh": { + "suffix": "maj7", + "tones": [4, 7, 11] + }, + "Minor Seventh": { + "suffix": "min7", + "tones": [3, 7, 10] + }, + "Dominant Seventh": { + "suffix": "dom7", + "tones": [4, 7, 10] + }, + "Minor Major Seventh": { + "suffix": "min/maj7", + "tones": [3, 7, 11] + }, + "Minor Seventh Flat Five": { + "suffix": "min7flat5", + "tones": [3, 6, 10] + }, + "Diminished Seventh": { + "suffix": "dim7", + "tones": [3, 6, 11] + }, + "Augmented Seventh": { + "suffix": "aug7", + "tones": [4, 8, 10] + }, + "Major Sixth": { + "suffix": "maj6", + "tones": [4, 7, 9] + }, + "Minor Sixth": { + "suffix": "min6", + "tones": [3, 7, 9] + }, + "Six-Nine": { + "suffix": "6/9", + "tones": [4, 7, 9, 14] + }, + "Minor Six-Nine": { + "suffix": "min6/9", + "tones": [3, 7, 9, 14] + }, + "Major Add Nine": { + "suffix": "maj+9", + "tones": [4, 7, 14] + }, + "Minor Add Nine": { + "suffix": "min+9", + "tones": [3, 7, 14] + }, + "Major Ninth": { + "suffix": "maj9", + "tones": [4, 11, 14] + }, + "Minor Ninth": { + "suffix": "min7", + "tones": [3, 10, 14] + }, + "Minor Major Ninth": { + "suffix": "min/maj9", + "tones": [3, 11, 14] + }, + "Dominant Ninth": { + "suffix": "dom9", + "tones": [4, 10, 14] + }, + "Dominant Seventh Sharp Nine": { + "suffix": "dom7#9", + "tones": [4, 10, 15] + }, + "Major Eleventh": { + "suffix": "maj11", + "tones": [11, 14, 17] }, - "2/4": { - "weight": 2 + "Minor Eleventh": { + "suffix": "min11", + "tones": [3, 10, 14, 17] }, - "4/4": { - "weight": 4 + "Dominant Eleventh": { + "suffix": "dom11", + "tones": [10, 14, 17] }, - "7/4": { - "weight": 0.5 + "Major Thirteenth": { + "suffix": "maj13", + "tones": [4, 11, 21] }, - "9/8": { - "weight": 0.1 + "Minor Thirteenth": { + "suffix": "min13", + "tones": [3, 10, 21] + }, + "Dominant Thirteenth": { + "suffix": "dom13", + "tones": [4, 10, 21] + } + }, + "scales": { + "Chromatic": { + "tones": [1,2,3,4,5,6,7,8,9,10,11] + }, + "Major": { + "tones": [2,4,5,7,9,11] + }, + "Harmonic Major": { + "tones": [2,4,5,7,8,11] + }, + "Minor": { + "tones": [2,3,5,7,8,10] + }, + "Harmonic Minor": { + "tones": [2,3,5,7,8,11] + }, + "Melodic Minor": { + "tones": [2,3,5,7,9,11] + }, + "Pentatonic Major": { + "tones": [2,4,7,9] + }, + "Pentatonic Minor": { + "tones": [3,5,7,10] + }, + "Major Blues": { + "tones": [2,3,4,7,9] + }, + "Minor Blues": { + "tones": [3,5,6,7,10] + }, + "Mixolydian": { + "tones": [2,4,5,7,9,10] + }, + "Lydian": { + "tones": [2,4,6,7,9,11] + }, + "Dorian": { + "tones": [2,3,5,7,9,10] + }, + "Byzantine": { + "tones": [1,4,5,7,8,11] + }, + "Whole Tone": { + "tones": [2,4,6,8,10] + }, + "Augmented": { + "tones": [3,4,7,8,11] } }, "creators": { @@ -40,28 +202,6 @@ "max_count": 3 } }, - "scales": { - "Major": { - "weight": 5 - }, - "Byzantine": { - "blacklist": true - }, - "Kumoi": { - "blacklist": true - }, - "Whole Tone": { - "blacklist": true - } - }, - "chords": { - "Major Sixth": { - "blacklist": true - }, - "Minor Sixth": { - "blacklist": true - } - }, "chord_changes": { // Allow everything but make it less likely "*": {"*": {"*": {"weight": 0.01}}}, @@ -89,64 +229,614 @@ } }, "instruments": { + "Acoustic Grand Piano": { + "index": 0, + "min_tone": "A0", + "max_tone": "C8", + "voices": 10 + }, + "Bright Acoustic Piano": { + "index": 1, + "min_tone": "A0", + "max_tone": "C8", + "voices": 10 + }, + "Electric Grand Piano": { + "index": 2, + "min_tone": "A0", + "max_tone": "C8", + "voices": 10 + }, + "Honky Tonk Piano": { + "index": 3, + "min_tone": "A0", + "max_tone": "C8", + "voices": 10 + }, + "Electric Piano 1": { + "index": 4, + "min_tone": "A0", + "max_tone": "C8", + "voices": 10 + }, + "Electric Piano 2": { + "index": 5, + "min_tone": "A0", + "max_tone": "C8", + "voices": 10 + }, + "Harpsichord": { + "index": 6, + "min_tone": "F1", + "max_tone": "F6", + "voices": 10 + }, + "Clavinet": { + "index": 7, + "min_tone": "A0", + "max_tone": "C8", + "voices": 10 + }, + "Celesta": { + "index": 8, + "min_tone": "C4", + "max_tone": "C8", + "voices": 10 + }, + "Glockenspiel": { + "index": 9, + "min_tone": "G5", + "max_tone": "C8" + }, + "Music Box": { + "index": 10, + "min_tone": "A0", + "max_tone": "C8", + "voices": 10 + }, + "Vibraphone": { + "index": 11, + "min_tone": "F3", + "max_tone": "F6" + }, + "Marimba": { + "index": 12, + "min_tone": "C2", + "max_tone": "C7" + }, + "Xylophone": { + "index": 13, + "min_tone": "F3", + "max_tone": "C8" + }, + "Tubular Bells": { + "index": 14, + "min_tone": "F3", + "max_tone": "G5" + }, + "Dulcimer": { + "index": 15, + "min_tone": "A2", + "max_tone": "A6" + }, + "Drawbar Organ": { + "index": 16, + "min_tone": "C2", + "max_tone": "C7", + "voices": 10 + }, + "Percussive Organ": { + "index": 17, + "min_tone": "C2", + "max_tone": "C7", + "voices": 10 + }, + "Rock Organ": { + "index": 18, + "min_tone": "C2", + "max_tone": "C7", + "voices": 10 + }, + "Church Organ": { + "index": 19, + "min_tone": "C-1", + "max_tone": "G9", + "voices": 10 + }, + "Reed Organ": { + "index": 20, + "min_tone": "C2", + "max_tone": "C7", + "voices": 10 + }, + "Accordion": { + "index": 21, + "min_tone": "D2", + "max_tone": "D8", + "voices": 5 + }, + "Harmonica": { + "index": 22, + "min_tone": "C2", + "max_tone": "C7" + }, + "Tango Accordion": { + "index": 23, + "min_tone": "C2", + "max_tone": "C7", + "voices": 5 + }, + "Acoustic Guitar (Nylon)": { + "index": 24, + "min_tone": "E2", + "max_tone": "C6", + "voices": 6 + }, + "Acoustic Guitar (Steel)": { + "index": 25, + "min_tone": "E2", + "max_tone": "C6", + "voices": 6 + }, + "Electric Guitar (Jazz)": { + "index": 26, + "min_tone": "E2", + "max_tone": "C6", + "voices": 6 + }, + "Electric Guitar (Clean)": { + "index": 27, + "min_tone": "E2", + "max_tone": "C6", + "voices": 6 + }, + "Electric Guitar (Muted)": { + "index": 28, + "min_tone": "E2", + "max_tone": "C6", + "voices": 6 + }, + "Overdriven Guitar": { + "index": 29, + "min_tone": "E2", + "max_tone": "C6", + "voices": 6 + }, + "Distorted Guitar": { + "index": 30, + "min_tone": "E2", + "max_tone": "C6", + "voices": 6 + }, + "Guitar Harmonics": { + "index": 31, + "min_tone": "E2", + "max_tone": "C6", + "voices": 6, + "blacklist": true + }, "Acoustic Bass": { + "index": 32, + "min_tone": "E1", + "max_tone": "G4", "voices": 1 }, "Electric Fingered Bass": { + "index": 33, + "min_tone": "E1", + "max_tone": "G4", "voices": 1 }, "Electric Picked Bass": { + "index": 34, + "min_tone": "E1", + "max_tone": "G4", "voices": 1 }, "Fretless Bass": { + "index": 35, + "min_tone": "E1", + "max_tone": "G4", "voices": 1 }, "Slap Bass 1": { + "index": 36, + "min_tone": "E1", + "max_tone": "G4", "voices": 1 }, "Slap Bass 2": { + "index": 37, + "min_tone": "E1", + "max_tone": "G4", "voices": 1 }, "Syn Bass 1": { + "index": 38, + "min_tone": "E1", + "max_tone": "G4", "voices": 1 }, "Syn Bass 2": { + "index": 39, + "min_tone": "E1", + "max_tone": "G4", "voices": 1 }, - "Guitar Harmonics": { - "blacklist": true + "Violin": { + "index": 40, + "min_tone": "G3", + "max_tone": "G7" + }, + "Viola": { + "index": 41, + "min_tone": "C3", + "max_tone": "C7" + }, + "Cello": { + "index": 42, + "min_tone": "C2", + "max_tone": "C6" + }, + "Contrabass": { + "index": 43, + "min_tone": "E1", + "max_tone": "D4" + }, + "Tremolo Strings": { + "index": 44, + "min_tone": "C3", + "max_tone": "C6" + }, + "Pizzicato Strings": { + "index": 45, + "min_tone": "C3", + "max_tone": "C6" + }, + "Orchestral Harp": { + "index": 46, + "min_tone": "B0", + "max_tone": "G7" + }, + "Timpani": { + "index": 47, + "min_tone": "D2", + "max_tone": "A3" + }, + "String Ensemble": { + "index": 48, + "min_tone": "G3", + "max_tone": "C5" + }, + "String Ensemble 2 (Slow)": { + "index": 49, + "min_tone": "G3", + "max_tone": "C5" + }, + "Syn Strings 1": { + "index": 50, + "min_tone": "G3", + "max_tone": "C5" + }, + "Syn Strings 2": { + "index": 51, + "min_tone": "G3", + "max_tone": "C5" + }, + "Choir Aahs": { + "index": 52, + "min_tone": "E2", + "max_tone": "A#5" + }, + "Voice Oohs": { + "index": 53, + "min_tone": "E2", + "max_tone": "A#5" + }, + "Syn Choir": { + "index": 54, + "min_tone": "E2", + "max_tone": "A#5" + }, + "Orchestral Hit": { + "index": 55, + "min_tone": "C3", + "max_tone": "C6" + }, + "Trumpet": { + "index": 56, + "min_tone": "E2", + "max_tone": "C6" + }, + "Trombone": { + "index": 57, + "min_tone": "B1", + "max_tone": "A#4" + }, + "Tuba": { + "index": 58, + "min_tone": "E1", + "max_tone": "F4" + }, + "Muted Trumpet": { + "index": 59, + "min_tone": "E2", + "max_tone": "C6" + }, + "French Horn": { + "index": 60, + "min_tone": "B1", + "max_tone": "F5" + }, + "Brass Section": { + "index": 61, + "min_tone": "E2", + "max_tone": "E4" + }, + "Synth Brass 1": { + "index": 62, + "min_tone": 28, + "max_tone": 67 + }, + "Synth Brass 2": { + "index": 63, + "min_tone": 28, + "max_tone": 67 + }, + "Soprano Sax": { + "index": 64, + "min_tone": "G#3", + "max_tone": "E6" + }, + "Alto Sax": { + "index": 65, + "min_tone": "C#3", + "max_tone": "G#5" + }, + "Tenor Sax": { + "index": 66, + "min_tone": "G#2", + "max_tone": "E5" + }, + "Baritone Sax": { + "index": 67, + "min_tone": "C2", + "max_tone": "A4" + }, + "Oboe": { + "index": 68, + "min_tone": "A#3", + "max_tone": "G6" + }, + "English Horn": { + "index": 69, + "min_tone": "E3", + "max_tone": "C6" + }, + "Bassoon": { + "index": 70, + "min_tone": "A#1", + "max_tone": "E5" + }, + "Clarinet": { + "index": 71, + "min_tone": "C#2", + "max_tone": "G6" + }, + "Piccolo": { + "index": 72, + "min_tone": "D5", + "max_tone": "C8" + }, + "Flute": { + "index": 73, + "min_tone": "C4", + "max_tone": "C7" + }, + "Recorder": { + "index": 74, + "min_tone": "F3", + "max_tone": "G7" + }, + "Pan Flute": { + "index": 75, + "min_tone": "B3", + "max_tone": "G7" }, "Bottle Blow": { + "index": 76, + "min_tone": 36, + "max_tone": 95, "blacklist": true }, + "Shakuhachi": { + "index": 77, + "min_tone": "D4", + "max_tone": "E6" + }, "Whistle": { + "index": 78, + "min_tone": 60, + "max_tone": 84, "blacklist": true }, + "Ocarina": { + "index": 79, + "min_tone": "C4", + "max_tone": "C7" + }, + "Lead 1 (Square)": { + "index": 80 + }, + "Lead 2 (Sawtooth)": { + "index": 81 + }, + "Lead 3 (Calliope)": { + "index": 82 + }, + "Lead 4 (Chiff)": { + "index": 83 + }, + "Lead 5 (Charang)": { + "index": 84 + }, + "Lead 6 (Voice)": { + "index": 85 + }, + "Lead 7 (Fifths)": { + "index": 86 + }, + "Lead 8 (Bass + Lead)": { + "index": 87 + }, + "Pad 1 (New Age)": { + "index": 88 + }, + "Pad 2 (Warm)": { + "index": 89 + }, + "Pad 3 (Polysynth)": { + "index": 90 + }, + "Pad 4 (Choir)": { + "index": 91 + }, + "Pad 5 (Bowed)": { + "index": 92 + }, + "Pad 6 (Metallic)": { + "index": 93 + }, + "Pad 7 (Halo)": { + "index": 94 + }, + "FX 1 (Rain)": { + "index": 96 + }, + "FX 2 (Soundtrack)": { + "index": 97 + }, + "FX 3 (Crystal)": { + "index": 98 + }, + "FX 4 (Atmosphere)": { + "index": 99 + }, + "FX 5 (Brightness)": { + "index": 100 + }, + "FX 6 (Goblins)": { + "index": 101 + }, + "FX 7 (Echoes)": { + "index": 102 + }, + "FX 8 (Sci-Fi)": { + "index": 103 + }, + "Sitar": { + "index": 104, + "min_tone": "C2", + "max_tone": "E5", + "voices": 7 + }, + "Banjo": { + "index": 105, + "min_tone": "C3", + "max_tone": "C6", + "voices": 5 + }, + "Shamisen": { + "index": 106, + "min_tone": "D4", + "max_tone": "F6", + "voices": 3 + }, + "Koto": { + "index": 107, + "min_tone": "A1", + "max_tone": "A7", + "voices": 17 + }, + "Kalimba": { + "index": 108, + "min_tone": "G3", + "max_tone": "D6" + }, + "Bag Pipe": { + "index": 109, + "min_tone": "A4", + "max_tone": "A#5" + }, + "Fiddle": { + "index": 110, + "min_tone": "G3", + "max_tone": "G7" + }, + "Shanai": { + "index": 111, + "min_tone": "A3", + "max_tone": "A5" + }, + "Tinkle Bell": { + "index": 112, + "min_tone": "C#4", + "max_tone": "A6" + }, + "Agogo": { + "index": 113 + }, + "Steel Drums": { + "index": 114, + "min_tone": "F1", + "max_tone": "G6" + }, + "Woodblock": { + "index": 115 + }, + "Taiko Drum": { + "index": 116 + }, + "Melodic Tom": { + "index": 117 + }, + "Synth Drum": { + "index": 118 + }, "Reverse Cymbal": { + "index": 119, "blacklist": true }, "Guitar Fret Noise": { + "index": 120, "blacklist": true }, "Breath Noise": { + "index": 121, "blacklist": true }, "Seashore": { + "index": 122, "blacklist": true }, "Bird Tweet": { + "index": 123, "blacklist": true }, "Telephone Ring": { + "index": 124, "blacklist": true }, "Helicopter": { + "index": 125, "blacklist": true }, "Applause": { + "index": 126, "blacklist": true }, "Gunshot": { + "index": 127, "blacklist": true } } diff --git a/source/lib_midi.cc b/source/lib_midi.cc index c2b313c19..9bc35783d 100644 --- a/source/lib_midi.cc +++ b/source/lib_midi.cc @@ -17,12 +17,11 @@ bool steve_generate(const char *config_file, const char *out_file) { steve::ConfigJson config; -// all.json must be read in regardless; load additional config afterwards if selected - PHYSFS_File *config_fp = PHYSFS_openRead("scripts/midi/all.json"); + PHYSFS_File *config_fp = PHYSFS_openRead(config_file); if (!config_fp) { - LogPrint("Unable to open MIDI generator config scripts/midi/all.json!\n"); + LogPrint("Unable to open MIDI generator config %s!\n", config_file); return false; } @@ -33,41 +32,15 @@ bool steve_generate(const char *config_file, const char *out_file) { { PHYSFS_close(config_fp); delete[] buf; - LogPrint("Unable to read MIDI generator config scripts/midi/all.json!!\n"); + LogPrint("Unable to read MIDI generator config %s!\n", config_file); return false; } PHYSFS_close(config_fp); config.parse_buffer((const char *)buf, len); - delete[] buf; - - if (GetFilename(config_file) != "all.json") - { - config_fp = PHYSFS_openRead(config_file); - if (!config_fp) - { - LogPrint("Unable to open MIDI generator config %s!\n", config_file); - return false; - } - len = PHYSFS_fileLength(config_fp); - buf = new uint8_t[len]; - - if (PHYSFS_readBytes(config_fp, buf, len) != len) - { - PHYSFS_close(config_fp); - delete[] buf; - LogPrint("Unable to read MIDI generator config %s!\n", config_file); - return false; - } - - PHYSFS_close(config_fp); - - config.parse_buffer((const char *)buf, len); - - delete[] buf; - } + delete[] buf; config.compute_cache();