Phase 18: preserve portable project media paths and verify format migrations
This commit is contained in:
parent
440e98f2b5
commit
1369e4d463
15 changed files with 329 additions and 13 deletions
14
tests/fixtures/project-plugin-v5.xtc
vendored
Normal file
14
tests/fixtures/project-plugin-v5.xtc
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
XTC_PROJECT 5
|
||||
APP 0 1 0
|
||||
TEMPO 120000
|
||||
IDS 0 0
|
||||
GRAPH 1 1 1 0
|
||||
NODE 0 8 00000000
|
||||
PLUGIN 900000 0 1 1 7874635f746573745f6761696e
|
||||
MODULE 2f6d697373696e672f746573742e736f
|
||||
CONTROL 2 3f800000
|
||||
TRACKS 0
|
||||
CLIPS 0
|
||||
NOTES 0 0
|
||||
AUTOMATION 0
|
||||
END
|
||||
16
tests/fixtures/project-plugin-v6.xtc
vendored
Normal file
16
tests/fixtures/project-plugin-v6.xtc
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
XTC_PROJECT 6
|
||||
APP 0 1 0
|
||||
TEMPO 120000
|
||||
IDS 0 0
|
||||
GRAPH 1 1 1 0
|
||||
NODE 0 8 00000000
|
||||
PLUGIN 900000 0 1 1 7874635f746573745f6761696e
|
||||
MODULE 2f6d697373696e672f746573742e736f
|
||||
CONTROL 2 3f800000
|
||||
PLUGIN_AUTOMATION 1
|
||||
PARAM 960 2 0 3f000000
|
||||
TRACKS 0
|
||||
CLIPS 0
|
||||
NOTES 0 0
|
||||
AUTOMATION 0
|
||||
END
|
||||
13
tests/fixtures/project-v1.xtc
vendored
Normal file
13
tests/fixtures/project-v1.xtc
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
XTC_PROJECT 1
|
||||
APP 0 1 0
|
||||
TEMPO 120000
|
||||
IDS 1 1
|
||||
GRAPH 1 2 2 1
|
||||
NODE 0 1 3f000000
|
||||
NODE 1 4 00000000
|
||||
EDGE 0 1
|
||||
TRACKS 1
|
||||
TRACK 0 4b657973
|
||||
CLIPS 1
|
||||
CLIP 0 0 0 960 0 960 5665727365
|
||||
END
|
||||
14
tests/fixtures/project-v2.xtc
vendored
Normal file
14
tests/fixtures/project-v2.xtc
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
XTC_PROJECT 2
|
||||
APP 0 1 0
|
||||
TEMPO 120000
|
||||
IDS 1 1
|
||||
GRAPH 1 2 2 1
|
||||
NODE 0 1 3f000000
|
||||
NODE 1 4 00000000
|
||||
EDGE 0 1
|
||||
TRACKS 1
|
||||
TRACK 0 4b657973
|
||||
CLIPS 1
|
||||
CLIP 0 0 0 960 0 960 5665727365
|
||||
ASSET -
|
||||
END
|
||||
17
tests/fixtures/project-v3.xtc
vendored
Normal file
17
tests/fixtures/project-v3.xtc
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
XTC_PROJECT 3
|
||||
APP 0 1 0
|
||||
TEMPO 120000
|
||||
IDS 1 1
|
||||
GRAPH 1 2 2 1
|
||||
NODE 0 1 3f000000
|
||||
NODE 1 4 00000000
|
||||
EDGE 0 1
|
||||
TRACKS 1
|
||||
TRACK 0 4b657973
|
||||
CLIPS 1
|
||||
CLIP 0 0 0 960 0 960 5665727365
|
||||
ASSET -
|
||||
MIDI 1
|
||||
NOTES 1 1
|
||||
NOTE 0 0 0 480 69 100 0
|
||||
END
|
||||
20
tests/fixtures/project-v4.xtc
vendored
Normal file
20
tests/fixtures/project-v4.xtc
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
XTC_PROJECT 4
|
||||
APP 0 1 0
|
||||
TEMPO 120000
|
||||
IDS 1 1
|
||||
GRAPH 1 2 2 1
|
||||
NODE 0 1 3f000000
|
||||
NODE 1 4 00000000
|
||||
EDGE 0 1
|
||||
TRACKS 1
|
||||
TRACK 0 4b657973
|
||||
MIX 3f800000 00000000 0 0
|
||||
CLIPS 1
|
||||
CLIP 0 0 0 960 0 960 5665727365
|
||||
ASSET -
|
||||
MIDI 1
|
||||
NOTES 1 1
|
||||
NOTE 0 0 0 480 69 100 0
|
||||
AUTOMATION 1
|
||||
POINT 0 0 0 3f800000
|
||||
END
|
||||
20
tests/fixtures/project-v5.xtc
vendored
Normal file
20
tests/fixtures/project-v5.xtc
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
XTC_PROJECT 5
|
||||
APP 0 1 0
|
||||
TEMPO 120000
|
||||
IDS 1 1
|
||||
GRAPH 1 2 2 1
|
||||
NODE 0 1 3f000000
|
||||
NODE 1 4 00000000
|
||||
EDGE 0 1
|
||||
TRACKS 1
|
||||
TRACK 0 4b657973
|
||||
MIX 3f800000 00000000 0 0
|
||||
CLIPS 1
|
||||
CLIP 0 0 0 960 0 960 5665727365
|
||||
ASSET -
|
||||
MIDI 1
|
||||
NOTES 1 1
|
||||
NOTE 0 0 0 480 69 100 0
|
||||
AUTOMATION 1
|
||||
POINT 0 0 0 3f800000
|
||||
END
|
||||
20
tests/fixtures/project-v6.xtc
vendored
Normal file
20
tests/fixtures/project-v6.xtc
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
XTC_PROJECT 6
|
||||
APP 0 1 0
|
||||
TEMPO 120000
|
||||
IDS 1 1
|
||||
GRAPH 1 2 2 1
|
||||
NODE 0 1 3f000000
|
||||
NODE 1 4 00000000
|
||||
EDGE 0 1
|
||||
TRACKS 1
|
||||
TRACK 0 4b657973
|
||||
MIX 3f800000 00000000 0 0
|
||||
CLIPS 1
|
||||
CLIP 0 0 0 960 0 960 5665727365
|
||||
ASSET -
|
||||
MIDI 1
|
||||
NOTES 1 1
|
||||
NOTE 0 0 0 480 69 100 0
|
||||
AUTOMATION 1
|
||||
POINT 0 0 0 3f800000
|
||||
END
|
||||
80
tests/integration/test_portability.c
Normal file
80
tests/integration/test_portability.c
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
#define _XOPEN_SOURCE 700
|
||||
#include "xtc/xtc_audio.h"
|
||||
#include "xtc/xtc_mixer.h"
|
||||
#include "xtc/xtc_midi.h"
|
||||
#include "xtc/xtc_plugin.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
int main(void)
|
||||
{
|
||||
char root[] = "/tmp/xtc-portable-XXXXXX", moved[512], file[512], media[512], old[512];
|
||||
xtc_project *p = NULL; unsigned version; uint64_t track, clip;
|
||||
float in[64], expected[64], actual[64]; size_t i;
|
||||
xtc_recorder *rec = NULL; xtc_audio_plan *audio = NULL;
|
||||
assert(mkdtemp(root));
|
||||
assert(xtc_project_create(&p) == XTC_OK);
|
||||
snprintf(file,sizeof(file),"%s/migration.xtc",root);
|
||||
for (version = 1; version <= 6; ++version) {
|
||||
xtc_track_info t; xtc_clip_info c; size_t notes, points;
|
||||
snprintf(old,sizeof(old),"tests/fixtures/project-v%u.xtc",version);
|
||||
assert(xtc_project_load(p,old) == XTC_OK);
|
||||
assert(xtc_project_get_track(p,0,&t) == XTC_OK && !strcmp(t.name,"Keys") && t.gain == 1);
|
||||
assert(xtc_project_get_clip(p,0,&c) == XTC_OK && c.midi == (version >= 3));
|
||||
assert(xtc_project_note_count(p,¬es) == XTC_OK && notes == (size_t)(version >= 3));
|
||||
assert(xtc_project_automation_count(p,&points) == XTC_OK && points == (size_t)(version >= 4));
|
||||
assert(xtc_project_save(p,file) == XTC_OK && xtc_project_load(p,file) == XTC_OK);
|
||||
}
|
||||
for (version = 5; version <= 6; ++version) {
|
||||
xtc_plugin_spec spec; xtc_plan *plan = NULL;
|
||||
snprintf(old,sizeof(old),"tests/fixtures/project-plugin-v%u.xtc",version);
|
||||
assert(xtc_project_load(p,old) == XTC_OK);
|
||||
assert(xtc_graph_get_plugin(xtc_project_graph(p),0,&spec) == XTC_OK && spec.tempo == 120000 && spec.point_count == version-5);
|
||||
assert(xtc_project_save(p,file) == XTC_OK && xtc_project_load(p,file) == XTC_OK);
|
||||
{ xtc_result r = xtc_graph_compile(xtc_project_graph(p),48000,64,&plan);
|
||||
assert((r == XTC_ERR_NOT_FOUND || r == XTC_ERR_UNSUPPORTED) && !plan); }
|
||||
}
|
||||
xtc_project_destroy(p); p = NULL;
|
||||
assert(xtc_project_create(&p) == XTC_OK && xtc_project_add_track(p,"Audio",&track) == XTC_OK);
|
||||
snprintf(media,sizeof(media),"%s/media.wav",root);
|
||||
for (i = 0; i < 64; ++i) in[i] = (float)i / 100;
|
||||
assert(xtc_recorder_create(media,48000,64,&rec) == XTC_OK);
|
||||
xtc_recorder_push(rec,in,64); assert(xtc_recorder_finish(rec) == XTC_OK); xtc_recorder_destroy(rec);
|
||||
assert(xtc_project_import_audio(p,track,media,0,&clip) == XTC_OK);
|
||||
assert(xtc_audio_plan_create(p,48000,&audio) == XTC_OK);
|
||||
assert(xtc_audio_plan_render(audio,0,expected,64) == XTC_OK); xtc_audio_plan_destroy(audio);
|
||||
assert(xtc_project_save(p,file) == XTC_OK);
|
||||
{ FILE *f = fopen(file,"r"); char text[4096]; size_t n; assert(f);
|
||||
n = fread(text,1,sizeof(text)-1,f); text[n] = 0; fclose(f);
|
||||
assert(strstr(text,"ASSET 6d656469612e776176\n")); }
|
||||
{
|
||||
char sub[512], copy[512]; xtc_clip_info c;
|
||||
snprintf(sub,sizeof(sub),"%s/elsewhere",root); assert(mkdir(sub,0700) == 0);
|
||||
snprintf(copy,sizeof(copy),"%s/elsewhere/copy.xtc",root);
|
||||
assert(xtc_project_save(p,copy) == XTC_OK && xtc_project_load(p,copy) == XTC_OK);
|
||||
assert(xtc_project_find_clip(p,clip,&c) == XTC_OK && !strcmp(c.asset_path,media));
|
||||
unlink(copy); rmdir(sub);
|
||||
}
|
||||
snprintf(moved,sizeof(moved),"%s-moved",root); assert(rename(root,moved) == 0);
|
||||
snprintf(file,sizeof(file),"%s-moved/migration.xtc",root);
|
||||
assert(xtc_project_load(p,file) == XTC_OK);
|
||||
{ char *cwd = getcwd(NULL,0); assert(cwd && chdir("/") == 0);
|
||||
assert(xtc_audio_plan_create(p,48000,&audio) == XTC_OK && xtc_audio_plan_issues(audio,NULL) == 0);
|
||||
assert(xtc_audio_plan_render(audio,0,actual,64) == XTC_OK);
|
||||
for (i = 0; i < 64; ++i) assert(expected[i] == actual[i]);
|
||||
xtc_audio_plan_destroy(audio); assert(chdir(cwd) == 0); free(cwd); }
|
||||
snprintf(media,sizeof(media),"%s-moved/media.wav",root); assert(unlink(media) == 0);
|
||||
assert(xtc_project_save(p,file) == XTC_OK && xtc_project_load(p,file) == XTC_OK);
|
||||
assert(xtc_audio_plan_create(p,48000,&audio) == XTC_OK && xtc_audio_plan_issues(audio,NULL) == 1);
|
||||
xtc_audio_plan_destroy(audio);
|
||||
/* Unknown records/versions fail without discarding the retained clip. */
|
||||
{ FILE *f = fopen(file,"a"); assert(f); fputs("FUTURE 1\n",f); fclose(f);
|
||||
assert(xtc_project_load(p,file) == XTC_ERR_FORMAT);
|
||||
{ xtc_clip_info c; assert(xtc_project_find_clip(p,clip,&c) == XTC_OK && c.asset_path[0]); } }
|
||||
xtc_project_destroy(p); unlink(file); rmdir(moved);
|
||||
puts("v1-v6 migration, v7 folder relocation, cwd independence and missing-media preservation passed.");
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -190,6 +190,12 @@ int main(void)
|
|||
assert(fgets(line, sizeof(line), f));
|
||||
assert(fputs("XTC_PROJECT 3\n", legacy) >= 0);
|
||||
while (fgets(line, sizeof(line), f)) {
|
||||
/* Old formats use absolute assets, unlike the v7 writer. */
|
||||
if (!strncmp(line,"ASSET ",6) && line[6] != '-') {
|
||||
size_t k; fputs("ASSET ",legacy);
|
||||
for (k = 0; wave[k]; ++k) fprintf(legacy,"%02x",(unsigned char)wave[k]);
|
||||
fputc('\n',legacy); continue;
|
||||
}
|
||||
if (strncmp(line, "MIX ", 4) && strncmp(line, "AUTOMATION ", 11) &&
|
||||
strncmp(line, "POINT ", 6))
|
||||
assert(fputs(line, legacy) >= 0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue