feat: add bounded audio sample editor with waveform selection and source statistics
This commit is contained in:
parent
66e07776a4
commit
7a04c6d922
12 changed files with 364 additions and 8 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#include "../../src/gui/main_window.hpp"
|
||||
#include "../../src/gui/sample_editor.hpp"
|
||||
#include "../../src/gui/graph_widget.hpp"
|
||||
#include "../../src/gui/sequencer_widget.hpp"
|
||||
#include "../../src/gui/piano_roll.hpp"
|
||||
|
|
@ -188,8 +189,17 @@ xtc_result xtc_backend_set_recorder(xtc_backend *, xtc_recorder *recorder)
|
|||
void xtc_backend_collect(xtc_backend *backend)
|
||||
{ CHECK(backend == &handle && alive == 1U); ++collects; }
|
||||
}
|
||||
static int sample_editor_tests()
|
||||
{
|
||||
reset();
|
||||
MainWindow window(false,"");window.show();auto *s=timeline(&window);char path[4096];CHECK(realpath("examples/projects/original-pluck.wav",path));
|
||||
CHECK(window.import_audio(path)==XTC_OK);
|
||||
Fl::add_timeout(.1,[](void *){auto *e=dynamic_cast<SampleEditor *>(Fl::modal());CHECK(e!=nullptr);if(e){CHECK(e->select(10,100)==XTC_OK);CHECK(e->select(100,10)==XTC_ERR_INVALID_ARGUMENT);CHECK(e->view(10,8)==XTC_OK);CHECK(e->view(e->frames(),1)==XTC_ERR_INVALID_ARGUMENT);e->hide();}},nullptr);
|
||||
CHECK(window.open_sample_editor()==XTC_OK);CHECK(s->selected_clip()!=UINT64_MAX);window.do_callback();return failures ? 1 : 0;
|
||||
}
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if(std::getenv("XTC_TEST_SAMPLE_EDITOR_ONLY"))return sample_editor_tests();
|
||||
if(!std::getenv("XTC_TEST_MODERN_EDITING_ONLY")) {
|
||||
reset();
|
||||
{
|
||||
|
|
|
|||
22
tests/unit/test_sample.c
Normal file
22
tests/unit/test_sample.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#define _POSIX_C_SOURCE 200809L
|
||||
#include "xtc/xtc_sample.h"
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
int main(void)
|
||||
{
|
||||
char root[]="/tmp/xtc-sample-test-XXXXXX",path[256];float values[]={0,.25f,-.5f,.75f,0,0,.5f,-.25f};
|
||||
xtc_recorder *rec=NULL;xtc_sample *s=NULL,*sentinel=NULL;xtc_sample_stats stats;size_t frames;unsigned int rate;float v=123;
|
||||
assert(mkdtemp(root));snprintf(path,sizeof(path),"%s/source.wav",root);
|
||||
assert(xtc_recorder_create(path,8000,8,&rec)==XTC_OK);xtc_recorder_push(rec,values,8);assert(xtc_recorder_finish(rec)==XTC_OK);xtc_recorder_destroy(rec);
|
||||
assert(xtc_sample_load(path,&s)==XTC_OK && xtc_sample_info(s,&rate,&frames)==XTC_OK && rate==8000 && frames==8);
|
||||
assert(xtc_sample_analyze(s,0,8,&stats)==XTC_OK && stats.minimum==-.5f && stats.maximum==.75f && stats.mean==.09375);
|
||||
assert(fabs(stats.rms-sqrt(1.1875/8))<.000001);
|
||||
assert(xtc_sample_read(s,8,&v)==XTC_ERR_INVALID_ARGUMENT && v==123);
|
||||
assert(xtc_sample_read(s,2,&v)==XTC_OK && v==-.5f);
|
||||
assert(xtc_sample_analyze(s,2,2,&stats)==XTC_ERR_INVALID_ARGUMENT);
|
||||
assert(xtc_sample_load("/missing/xtc.wav",&sentinel)==XTC_ERR_IO && sentinel==NULL);
|
||||
xtc_sample_destroy(s);assert(unlink(path)==0 && rmdir(root)==0);puts("Sample editor core tests passed.");return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue