[go: nahoru, domu]

Skip to content

Commit

Permalink
save set list after loading; command line args fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jimm committed Jul 13, 2021
1 parent 136ecd3 commit e38bbe8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 35 deletions.
42 changes: 21 additions & 21 deletions src/kronos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "set_list.h"
#include "utils.h"

#define SYSEX_HEADER SYSEX, KORG_MANUFACTURER_ID, static_cast<byte>(0x30 + channel), KRONOS_DEVICE_ID
#define MIDI_BUFSIZ 1024
#define SYSEX_BUF_EVENTS 1024

Expand Down Expand Up @@ -194,8 +195,7 @@ const char * const Kronos::error_reply_message() {
// Returns a newly allocated KString.
KString * Kronos::read_current_string(int obj_type, byte pad) {
const byte request_sysex[] = {
SYSEX, KORG_MANUFACTURER_ID,
static_cast<byte>(0x30 + channel), KRONOS_DEVICE_ID,
SYSEX_HEADER,
FUNC_CODE_CURR_OBJ_DUMP_REQ, static_cast<byte>(obj_type),
EOX
};
Expand All @@ -222,8 +222,7 @@ void Kronos::read_set_list(int n, SetList &set_list) {
goto_set_list(n);

const byte request_sysex[] = {
SYSEX, KORG_MANUFACTURER_ID,
static_cast<byte>(0x30 + channel), KRONOS_DEVICE_ID,
SYSEX_HEADER,
FUNC_CODE_CURR_OBJ_DUMP_REQ, static_cast<byte>(OBJ_TYPE_SET_LIST),
EOX
};
Expand All @@ -242,8 +241,7 @@ void Kronos::read_set_list(int n, SetList &set_list) {
void Kronos::write_current_string(int obj_type, KString *kstr) {
byte request_sysex[kstr->midi_len + 8];
const byte request_sysex_header[] = {
SYSEX, KORG_MANUFACTURER_ID,
static_cast<byte>(0x30 + channel), KRONOS_DEVICE_ID,
SYSEX_HEADER,
FUNC_CODE_CURR_OBJ_DUMP, static_cast<byte>(obj_type), 0
};

Expand All @@ -268,40 +266,43 @@ void Kronos::write_set_list(int n, SetList &set_list) {

MIDIData midi_data(MD_INIT_INTERNAL, (byte *)&set_list, sizeof(SetList));

byte request_sysex[midi_data.midi_len + 8];
const byte request_sysex_header[] = {
SYSEX, KORG_MANUFACTURER_ID,
static_cast<byte>(0x30 + channel), KRONOS_DEVICE_ID,
FUNC_CODE_CURR_OBJ_DUMP, static_cast<byte>(OBJ_TYPE_SET_LIST), 0
SYSEX_HEADER,
FUNC_CODE_OBJ_DUMP, static_cast<byte>(OBJ_TYPE_SET_LIST),
(byte)0, // bank
(byte)((n >> 7) & 0x7f), (byte)(n & 0x7f), // idH, idL
0 // version
};
size_t header_size = sizeof(request_sysex_header);
byte request_sysex[header_size + midi_data.midi_len + 1];

memcpy(request_sysex, request_sysex_header, 7); // start of sysex
memcpy(request_sysex + 7, midi_data.midi_bytes, midi_data.midi_len);
request_sysex[7 + midi_data.midi_len] = EOX; // end of sysex
memcpy(request_sysex, request_sysex_header, header_size); // header
memcpy(request_sysex + header_size, midi_data.midi_bytes, midi_data.midi_len); // data
request_sysex[header_size + midi_data.midi_len] = EOX; // end of sysex

get(request_sysex, "write_current_set_list");

save_current_set_list();
}

// ================ saving objects to non-volatile storage ================

void Kronos::save_current_set_list() {
byte request_sysex[8];
const byte request_sysex_header[] = {
SYSEX, KORG_MANUFACTURER_ID,
static_cast<byte>(0x30 + channel), KRONOS_DEVICE_ID,
const byte request_sysex[] = {
SYSEX_HEADER,
FUNC_CODE_STORE_BANK_REQ,
static_cast<byte>(OBJ_TYPE_SET_LIST), 0,
EOX
};

get(request_sysex, "save_current_set_list");
}

// ================ mode and movement commands ================

KronosMode Kronos::mode() {
const byte request_sysex[] = {
SYSEX, KORG_MANUFACTURER_ID,
static_cast<byte>(0x30 + channel), KRONOS_DEVICE_ID,
SYSEX_HEADER,
FUNC_CODE_MODE_REQ, EOX
};
get(request_sysex, "mode");
Expand All @@ -310,8 +311,7 @@ KronosMode Kronos::mode() {

void Kronos::set_mode(KronosMode mode) {
const byte request_sysex[] = {
SYSEX, KORG_MANUFACTURER_ID,
static_cast<byte>(0x30 + channel), KRONOS_DEVICE_ID,
SYSEX_HEADER,
FUNC_CODE_MODE_CHANGE, (byte)mode, EOX
};
get(request_sysex, "set_mode");
Expand Down
17 changes: 3 additions & 14 deletions src/kronut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ void list_all_devices() {
int main(int argc, char * const *argv) {
struct opts opts;
const char *prog_name = argv[0];
char *path;

parse_command_line(argc, argv, opts);
argc -= optind;
Expand Down Expand Up @@ -178,29 +177,19 @@ int main(int argc, char * const *argv) {
int status = 0;
char command = argv[0][0];
int set_list_num = atoi(argv[1]);
char *path = argv[2];
Kronos kronos(opts.channel, opts.input_num, opts.output_num);
init_midi();
Editor editor(opts.format);

switch (command) {
case 'l':
if (editor.load_set_list_from_file(argv[1]) == 0) {
if (editor.load_set_list_from_file(path) == 0)
kronos.write_set_list(set_list_num, editor.set_list());

// FIXME I don't know why this doesn't save the set list on the
// Kronos. Instead, it erases/resets it. The docs in
// KRONOS_MIDI_SysEx.txt say that sending the set list via the Object
// Dump message then calling Store Bank Request should work. I'm
// sending a Current Object Dump, maybe that's it.
//
// Also, for some reason the reply doesn't come from the Kronos.

// kronos.save_current_set_list();
}
break;
case 's':
kronos.read_set_list(set_list_num, editor.set_list());
editor.save_set_list_to_file(argv[1]);
editor.save_set_list_to_file(path);
break;
default:
usage(prog_name);
Expand Down

0 comments on commit e38bbe8

Please sign in to comment.