Skip to content

Commit

Permalink
Unit dump option added
Browse files Browse the repository at this point in the history
  • Loading branch information
dukesrg committed Sep 30, 2021
1 parent 068eb12 commit 5e42a90
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 1 deletion.
98 changes: 98 additions & 0 deletions .vscode/dumpunit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* File: dumpunit.cpp
*
* logue sdk user unit SysEx dump payload extractor
*
* 2021 (c) Oleg Burdaev
* mailto: dukesrg@gmail.com
*
*/

#include <stdio.h>
#include <sys/stat.h>
#include "userprg.h"

int main(int argc, char *argv[]) {
if (argc < 2) {
printf("Usage: %s <logue unit sysex dump file>\n", argv[0]);
return 1;
};

FILE *fp = fopen(argv[1], "rb");
unsigned char data[65536];
char name[USER_PRG_NAME_LEN+1+14];
user_prg_header_t *header = (user_prg_header_t *)&data[8];
unsigned int *id = (unsigned int *)&data[0];
unsigned int i, j = 0;
unsigned char h, l = 0;

fread(&data, 1, 10, fp);
if (id[0] != 0x003042F0 || (id[1] & 0x00FF00FF) != 0x004A0001 || data[9] == 0xF7) {
printf("No logue unit dump detected!\n", argv[0]);
fclose(fp);
return 1;
}

while (fread(&h, sizeof h, 1, fp) > 0) {
for (i = 0; i < 7 && fread(&l, sizeof l, 1, fp) > 0; i++)
data[j++] = l | ((h & (1 << i)) ? 0x80 : 0);
}
fclose(fp);

mkdir(header->name, 0777);

sprintf(name, "%s/manifest.json", header->name);
fp = fopen(name, "w");
fprintf(fp, "{\n");
fprintf(fp, " \"header\" :\n");
fprintf(fp, " {\n");
fprintf(fp, " \"platform\" : \"");
switch(header->target & USER_TARGET_PLATFORM_MASK) {
case k_user_target_prologue:
fprintf(fp, "prologue");
break;
case k_user_target_miniloguexd:
fprintf(fp, "minilogue-xd");
break;
case k_user_target_nutektdigital:
fprintf(fp, "nutekt-digital");
break;
}
fprintf(fp, "\",\n");
fprintf(fp, " \"module\" : \"");
switch(header->target & USER_TARGET_MODULE_MASK) {
case k_user_module_modfx:
fprintf(fp, "modfx");
break;
case k_user_module_delfx:
fprintf(fp, "delfx");
break;
case k_user_module_revfx:
fprintf(fp, "revfx");
break;
case k_user_module_osc:
fprintf(fp, "osc");
break;
}
printf("%s/%s\n%s/%s\n", header->name, "manifest.json", header->name, "payload.bin");
fprintf(fp, "\",\n");
fprintf(fp, " \"api\" : \"%d.%d-%d\",\n", USER_API_MAJOR(header->api), USER_API_MINOR(header->api), USER_API_PATCH(header->api));
fprintf(fp, " \"dev_id\" : %u,\n", header->dev_id);
fprintf(fp, " \"prg_id\" : %u,\n", header->prg_id);
fprintf(fp, " \"version\" : \"%d.%d-%d\",\n", USER_API_MAJOR(header->version), USER_API_MINOR(header->version), USER_API_PATCH(header->version));
fprintf(fp, " \"name\" : \"%s\",\n", header->name);
fprintf(fp, " \"num_param\" : %d,\n", header->num_param);
fprintf(fp, " \"params\" : [\n");
for (i = 0; i < header->num_param; i++)
fprintf(fp, " [\"%s\", %d, %d, \"%s\"]%s\n", header->params[i].name, header->params[i].min, header->params[i].max, header->params[i].type == k_user_prg_param_type_select ? "" : "%", i < (header->num_param - 1) ? "," : "");
fprintf(fp, " ]\n");
fprintf(fp, " }\n");
fprintf(fp, "}\n");
fclose(fp);

sprintf(name, "%s/payload.bin", header->name);
fp = fopen(name, "wb");
for (i = sizeof(user_prg_header_t) + 8; i < sizeof(user_prg_header_t) + 8 + header->load_size; i++)
fwrite(&data[i], 1, 1, fp);
fclose(fp);
}
26 changes: 26 additions & 0 deletions .vscode/dumpunits.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
declare -A DEVICEIDS=(["prologue"]="73" ["minilogue xd"]="81" ["NTS-1 digital kit"]="87")
declare -A EXTENSIONS=(["73"]="prlgunit" ["81"]="mnlgxdunit" ["87"]="ntkdigunit")
declare -A MAXSLOTS=(["modfx"]="15" ["delfx"]="7" ["revfx"]="7" ["osc"]="15")
declare -A UNITINDEX=(["modfx"]="1" ["delfx"]="2" ["revfx"]="3" ["osc"]="4")
declare -A UNITNAMES=(["modfx"]="Modulation FX" ["delfx"]="Delay FX" ["revfx"]="Reverb FX" ["osc"]="Oscillator")
SENDPORT=$(sendmidi list | grep -E "(prologue|minilogue xd|NTS-1 digital kit) SOUND" | head -n1)
RECEIVEPORT=$(receivemidi list | grep -E "(prologue|minilogue xd|NTS-1 digital kit) KBD/KNOB" | head -n1)
([ -z "$SENDPORT" ] || [ -z "$RECEIVEPORT" ]) && echo $PORTNAME Synthesizer is not connected && exit 1
DEVICEID=${DEVICEIDS[${SENDPORT% SOUND}]}
[ -f ".vscode/dumpunit" ] || gcc .vscode/dumpunit.cpp -o.vscode/dumpunit -Ilogue-sdk/platform/inc
echo -e "Dumping ${SENDPORT% SOUND} units...\n"
for UNITTYPE in modfx delfx revfx osc; do
INDEX=0
while [[ $INDEX -le ${MAXSLOTS[$UNITTYPE]} ]] ; do
echo -n "${UNITNAMES[$UNITTYPE]} ${INDEX}: "
receivemidi dev "$RECEIVEPORT" syx | sed -E "s/system-exclusive hex (.*) dec/F0 \1 F7/" | xxd -r -p > ${UNITTYPE}${INDEX}.syx &
sendmidi dev "$SENDPORT" syx 66 48 0 1 $DEVICEID 26 ${UNITINDEX[$UNITTYPE]} $INDEX
sleep 2
kill $(ps | awk '/receivemidi/{print $1}')
NAME=$(.vscode/dumpunit ${UNITTYPE}${INDEX}.syx | head -n1 | cut -d/ -f1)
([ -d "$NAME" ] && echo -n "\"${NAME}\" " && mv ${UNITTYPE}${INDEX}.syx "$NAME-$UNITTYPE.syx" && echo -n "$NAME-$UNITTYPE.syx " && zip -r -m -q "$NAME-$UNITTYPE.${EXTENSIONS[$DEVICEID]}" "$NAME" && echo $NAME-$UNITTYPE.${EXTENSIONS[$DEVICEID]}) || echo free.
(( INDEX += 1 ))
done
echo
done
11 changes: 11 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@
"${file}"
]
},
{
"type": "shell",
"label": "Dump all units",
"command": [
"bash"
],
"args": [
"${workspaceFolder}/.vscode/dumpunits.sh"
],
"problemMatcher": []
},
{
"type": "shell",
"label": "Update SVD files",
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Build system is based on my fork of logue-sdk, but can be easily retargeted to v
### Setup
Follow logue-sdk initialization procedure described in the corresponding documentation.
In order to perform automated unit load and selection you need to install [logue-cli](logue-sdk/tools/logue-cli) from logue-sdk and [SendMIDI](https://github.com/gbevin/SendMIDI) and make sure to put them somewhere accessible with PATH variable.
For dumping option both [SendMIDI](https://github.com/gbevin/SendMIDI) and [ReceiveMIDI](https://github.com/gbevin/ReceiveMIDI) are required to be installed.
Open folder in VSCode, then you will be proposed to download dependent plugins, which is stated in [extensions.json](.vscode/extensions.json)

### Build options
Expand All @@ -29,6 +30,7 @@ Open folder in VSCode, then you will be proposed to download dependent plugins,
* Build prologue units : build all units for prologue only.
* Clean all : delete all intermediat build files and unit files.
* Load unit : load selected unit to the last slot of the compatible synth and select it.
* Dump all units : download all units from the first connected synth.
* Update SVD files : download System View Description files which is needed for debug on the real synth.

### Debugging
Expand Down
2 changes: 1 addition & 1 deletion logue-sdk

0 comments on commit 5e42a90

Please sign in to comment.