13. cratedraw

Draws a waveform of a crate wav file to a btprnt region.

Returns non-zero on error.

<<sqlar_functions>>=
typedef struct btprnt_region btprnt_region;

int sqlar_wavdraw(sqlite3 *db,
                  const char *filename,
                  btprnt_region *r,
                  int c);

int sqlar_cratedraw(sqlite3 *db,
                    btprnt_region *r,
                    const char *uuid,
                    int c)
{
    int rc;
    sqlite3_stmt *stmt;
    int count;
    const char *filename;

    sqlite3_prepare_v2(db,
                       "SELECT value, COUNT(DISTINCT uuid) "
                       "from wikizet "
                       "WHERE uuid LIKE ?1 "
                       "AND value LIKE \"/%\";",
                       -1, &stmt, NULL);

    sqlite3_bind_text(stmt, 1, uuid, -1, NULL);
    rc = sqlite3_step(stmt);

    if (rc != SQLITE_ROW) {
        fprintf(stderr, "cratewav: %s\n", sqlite3_errmsg(db));
        sqlite3_finalize(stmt);
        return 1;
    }

    count = sqlite3_column_int(stmt, 1);

    if (count < 1) {
        fprintf(stderr, "Could not resolve id %s\n", uuid);
        sqlite3_finalize(stmt);
        return 2;
    } else if (count > 1) {
        fprintf(stderr, "id pattern %s not unique.\n", uuid);
        sqlite3_finalize(stmt);
        return 3;
    }

    filename = (const char *)sqlite3_column_text(stmt, 0);

    rc = sqlar_wavdraw(db, &filename[1], r, 1);

    if (!rc) {
        fprintf(stderr, "There were SQLar problems.\n");
        sqlite3_finalize(stmt);
        return 4;
    }

    sqlite3_finalize(stmt);
    return 0;
}



prev | home | next