From fa95c3e63b30537159447d7fa3ffd1bb8474da6a Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sun, 11 Mar 2018 00:55:12 -0500 Subject: [PATCH] Serialize MIDI-TRIG/CC --- src/Core/MIDICCToCVInterface.cpp | 17 +++++++++++++++++ src/Core/MIDITriggerToCVInterface.cpp | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/Core/MIDICCToCVInterface.cpp b/src/Core/MIDICCToCVInterface.cpp index c92d2392..5029e609 100644 --- a/src/Core/MIDICCToCVInterface.cpp +++ b/src/Core/MIDICCToCVInterface.cpp @@ -74,11 +74,28 @@ struct MIDICCToCVInterface : Module { json_t *toJson() override { json_t *rootJ = json_object(); + + json_t *ccsJ = json_array(); + for (int i = 0; i < 16; i++) { + json_t *ccJ = json_integer(learnedCcs[i]); + json_array_append_new(ccsJ, ccJ); + } + json_object_set_new(rootJ, "ccs", ccsJ); + json_object_set_new(rootJ, "midi", midiInput.toJson()); return rootJ; } void fromJson(json_t *rootJ) override { + json_t *ccsJ = json_object_get(rootJ, "ccs"); + if (ccsJ) { + for (int i = 0; i < 16; i++) { + json_t *ccJ = json_array_get(ccsJ, i); + if (ccJ) + learnedCcs[i] = json_integer_value(ccJ); + } + } + json_t *midiJ = json_object_get(rootJ, "midi"); midiInput.fromJson(midiJ); } diff --git a/src/Core/MIDITriggerToCVInterface.cpp b/src/Core/MIDITriggerToCVInterface.cpp index 98dde0de..52b0cff0 100644 --- a/src/Core/MIDITriggerToCVInterface.cpp +++ b/src/Core/MIDITriggerToCVInterface.cpp @@ -104,11 +104,28 @@ struct MIDITriggerToCVInterface : Module { json_t *toJson() override { json_t *rootJ = json_object(); + + json_t *notesJ = json_array(); + for (int i = 0; i < 16; i++) { + json_t *noteJ = json_integer(learnedNotes[i]); + json_array_append_new(notesJ, noteJ); + } + json_object_set_new(rootJ, "notes", notesJ); + json_object_set_new(rootJ, "midi", midiInput.toJson()); return rootJ; } void fromJson(json_t *rootJ) override { + json_t *notesJ = json_object_get(rootJ, "notes"); + if (notesJ) { + for (int i = 0; i < 16; i++) { + json_t *noteJ = json_array_get(notesJ, i); + if (noteJ) + learnedNotes[i] = json_integer_value(noteJ) & 0x7f; + } + } + json_t *midiJ = json_object_get(rootJ, "midi"); midiInput.fromJson(midiJ); }