Ejemplo n.º 1
0
char*
waveform_ensure_peakfile__sync (Waveform* w)
{
    if(!wf_create_cache_dir()) return NULL;

    char* filename = g_path_is_absolute(w->filename) ? g_strdup(w->filename) : g_build_filename(g_get_current_dir(), w->filename, NULL);

    gchar* peak_filename = waveform_get_peak_filename(filename);
    if(!peak_filename) goto out;

    if(g_file_test(peak_filename, G_FILE_TEST_EXISTS)) {
        dbg (1, "peak file exists. (%s)", peak_filename);

        /*
        note that this test will fail to detect a modified file, if an older file is now stored at this location.

        The freedesktop thumbnailer spec identifies modifications by comparing with both url and mtime stored in the thumbnail.
        This will mostly work, but strictly speaking still won't identify a changed file in all cases.
        */
        if(w->offline || wf_file_is_newer(peak_filename, filename)) return peak_filename;

        dbg(1, "peakfile is too old");
    }

    if(!wf_peakgen__sync(filename, peak_filename)) {
        g_free0(peak_filename);
        goto out;
    }

out:
    g_free(filename);

    return peak_filename;
}
Ejemplo n.º 2
0
/*
 *  Check the load callback gets called if loading fails
 */
void
test_bad_wav()
{
	START_TEST;
	if(__test_idx == -1) printf("\n"); // stop compiler warning

	bool a = wf_peakgen__sync("bad.wav", "bad.peak", NULL);
	assert(!a, "peakgen was expected to fail");

	GError* error = NULL;
	a = wf_peakgen__sync("bad.wav", "bad.peak", &error);
	assert(error, "expected error");
	g_error_free(error);

	void callback(Waveform* w, GError* error, gpointer _c)
	{
		PF0;
		WfTest* c = _c;

		assert(error, "GError not set")

		WF_TEST_FINISH;
	}
Ejemplo n.º 3
0
void
test_peakgen()
{
	START_TEST;

	if(!wf_peakgen__sync(WAV, WAV ".peak")){
		FAIL_TEST("local peakgen failed");
	}

	//create peakfile in the cache directory
	Waveform* w = waveform_new(WAV);
	char* p = waveform_ensure_peakfile__sync(w);
	assert(p, "cache dir peakgen failed");

	FINISH_TEST;
}
Ejemplo n.º 4
0
void
waveform_peakgen(Waveform* w, const char* peak_filename, WfCallback2 callback, gpointer user_data)
{
    if(!peakgen.msg_queue) wf_worker_init(&peakgen);

    typedef struct {
        char*         infilename;
        const char*   peak_filename;
        struct {
            bool          failed; // returned true if peakgen failed
        }             out;
        WfCallback2   callback;
        void*         user_data;
    } PeakJob;

    PeakJob* job = g_new0(PeakJob, 1);
    *job = (PeakJob) {
        .infilename = g_path_is_absolute(w->filename) ? g_strdup(w->filename) : g_build_filename(g_get_current_dir(), w->filename, NULL),
         .peak_filename = peak_filename,
          .callback = callback,
           .user_data = user_data,
    };

    void peakgen_execute_job(Waveform* w, gpointer _job)
    {
        // runs in worker thread
        PeakJob* job = _job;

        if(!wf_peakgen__sync(job->infilename, job->peak_filename)) {
#ifdef DEBUG
            if(wf_debug) gwarn("peakgen failed");
#endif
            job->out.failed = true; // writing to object owned by main thread
        }
    }

    void peakgen_free(gpointer item)
    {
        PeakJob* job = item;
        g_free0(job->infilename);
        g_free(job);
    }
Ejemplo n.º 5
0
void
test_peakgen()
{
	START_TEST;

	char* filename = find_wav(WAV);
	assert(filename, "cannot find file %s", WAV);

	if(!wf_peakgen__sync(filename, WAV ".peak", NULL)){
		FAIL_TEST("local peakgen failed");
	}

	// create peakfile in the cache directory
	Waveform* w = waveform_new(filename);
	g_free(filename);
	char* p = waveform_ensure_peakfile__sync(w);
	assert(p, "cache dir peakgen failed");

	FINISH_TEST;
}