Пример #1
0
END_TEST


START_TEST(Characters_past_specified_length_are_ignored)
{
    static struct
    {
        const char* str;
        int len;
    }
    nums[] =
    {
        { "123456", 3 },
        { "123 456", 4 },
        { "12 3456", 4 },
    };

    for (size_t i = 0; i < arr_size(nums); ++i)
    {
        Streader* sr = Streader_init(STREADER_AUTO, nums[i].str, nums[i].len);

        fail_if(!Streader_match_char(sr, '1'),
                "Could not match '1' in \"%s\"", nums[i].str);
        fail_if(!Streader_match_char(sr, '2'),
                "Could not match '2' in \"%s\"", nums[i].str);
        fail_if(!Streader_match_char(sr, '3'),
                "Could not match '3' in \"%s\"", nums[i].str);

        fail_if(Streader_match_char(sr, '4'),
                "Matched '4' located in \"%s\" after given length %d",
                nums[i].str,
                nums[i].len);
    }
}
Пример #2
0
END_TEST


START_TEST(Fire_with_complex_bind_can_be_processed_with_multiple_receives)
{
    set_mix_volume(0);
    setup_debug_instrument();
    setup_debug_single_pulse();

    const int event_count = 2048;
    setup_complex_bind(event_count);

    pause();
    kqt_Handle_fire_event(handle, 0, "[\"#\", \"\"]");
    check_unexpected_error();

    // Receive and make sure all events are found
    const char* events = kqt_Handle_receive_events(handle);
    int32_t expected = 0;
    int loop_count = 0;
    while (strcmp("[]", events) != 0)
    {
        Streader* sr = Streader_init(STREADER_AUTO, events, (int64_t)strlen(events));
        fail_if(!Streader_read_list(sr, read_received_events_bind, &expected),
                "Event list reading failed: %s",
                Streader_get_error_desc(sr));

        events = kqt_Handle_receive_events(handle);
        ++loop_count;
    }

    fail_if(loop_count <= 1,
            "Test did not fill the event buffer, increase event count!");

    fail_if(expected != event_count,
            "Read %" PRId32 " instead of %d events",
            expected, event_count);

    // Continue playing
    kqt_Handle_play(handle, 10);
    fail_if(kqt_Handle_get_frames_available(handle) != 10,
            "Kunquat handle rendered %ld instead of 10 frames",
            kqt_Handle_get_frames_available(handle));

    // FIXME: We can only check for 512 notes as we run out of voices :-P
    const float expected_buf[10] = { min((float)event_count, 512) };
    const float* actual_buf = kqt_Handle_get_audio(handle, 0);
    check_buffers_equal(expected_buf, actual_buf, 10, 0.0f);
}
Пример #3
0
int kqt_Handle_fire_event(kqt_Handle handle, int channel, const char* event)
{
    check_handle(handle, 0);

    Handle* h = get_handle(handle);
    check_data_is_valid(h, 0);
    check_data_is_validated(h, 0);

    if (channel < 0 || channel >= KQT_COLUMNS_MAX)
    {
        Handle_set_error(h, ERROR_ARGUMENT, "Invalid channel number: %d", channel);
        return 0;
    }
    if (event == NULL)
    {
        Handle_set_error(h, ERROR_ARGUMENT, "No event description given");
        return 0;
    }

    const size_t length = strlen(event);
    if (length > 4096)
    {
        Handle_set_error(h, ERROR_ARGUMENT, "Event description is too long");
        return 0;
    }

    Streader* sr = Streader_init(STREADER_AUTO, event, (int64_t)length);
    if (!Player_fire(h->player, channel, sr))
    {
        rassert(Streader_is_error_set(sr));
        Handle_set_error(
                h,
                ERROR_ARGUMENT,
                "Invalid event description `%s`: %s",
                event, Streader_get_error_desc(sr));
        return 0;
    }

    return 1;
}
Пример #4
0
Module* new_Module(void)
{
    Module* module = memory_alloc_item(Module);
    if (module == NULL)
        return NULL;

    if (!Device_init(&module->parent, false))
    {
        memory_free(module);
        return NULL;
    }

    Device_set_existent(&module->parent, true);

    // Clear fields
    module->random_seed = 0;
    module->songs = NULL;
    module->album_is_existent = false;
    module->track_list = NULL;
    module->ch_defs = NULL;
    module->pats = NULL;
    module->au_map = NULL;
    module->au_controls = NULL;
    module->au_table = NULL;
    module->connections = NULL;
    module->is_dc_blocker_enabled = true;
    module->mix_vol_dB = COMP_DEFAULT_MIX_VOL;
    module->mix_vol = exp2(module->mix_vol_dB / 6);
    module->force_shift = 0;
    module->env = NULL;
    module->bind = NULL;
    for (int i = 0; i < KQT_SONGS_MAX; ++i)
        module->order_lists[i] = NULL;
    for (int i = 0; i < KQT_TUNING_TABLES_MAX; ++i)
        module->tuning_tables[i] = NULL;

    // Create fields
    module->songs = new_Song_table();
    module->pats = new_Pat_table(KQT_PATTERNS_MAX);
    module->au_controls = new_Bit_array(KQT_CONTROLS_MAX);
    module->au_table = new_Au_table(KQT_AUDIO_UNITS_MAX);
    if (module->songs == NULL           ||
            module->pats == NULL        ||
            module->au_controls == NULL ||
            module->au_table == NULL)
    {
        del_Module(module);
        return NULL;
    }

    module->env = new_Environment();
    if (module->env == NULL)
    {
        del_Module(module);
        return NULL;
    }

    Streader* conn_sr = Streader_init(STREADER_AUTO, NULL, 0);
    module->connections =
        new_Connections_from_string(conn_sr, false, module->au_table, &module->parent);
    if (module->connections == NULL)
    {
        del_Module(module);
        return NULL;
    }

    return module;
}