Пример #1
0
static bool Connections_is_cyclic(const Connections* graph)
{
    rassert(graph != NULL);

    // Reset testing states
    {
        AAiter* iter = AAiter_init(AAITER_AUTO, graph->nodes);

        Device_node* node = AAiter_get_at_least(iter, "");
        while (node != NULL)
        {
            Device_node_reset_cycle_test_state(node);
            node = AAiter_get_next(iter);
        }
    }

    // Test for cycles
    {
        AAiter* iter = AAiter_init(AAITER_AUTO, graph->nodes);

        Device_node* node = AAiter_get_at_least(iter, "");
        while (node != NULL)
        {
            if (Device_node_cycle_in_path(node))
                return true;

            node = AAiter_get_next(iter);
        }
    }

    return false;
}
Пример #2
0
const char* Environment_iter_get_next_name(Environment_iter* iter)
{
    assert(iter != NULL);

    const char* next = iter->next;
    iter->next = AAiter_get_next(&iter->iter);

    return next;
}
Пример #3
0
void Event_cache_reset(Event_cache* cache)
{
    rassert(cache != NULL);

    AAiter* iter = AAiter_init(AAITER_AUTO, cache->cache);
    Event_state* es = AAiter_get_at_least(iter, "");
    while (es != NULL)
    {
        Event_state_reset(es);
        es = AAiter_get_next(iter);
    }

    return;
}
Пример #4
0
void Channel_cv_state_reset(Channel_cv_state* state)
{
    rassert(state != NULL);

    const Entry* key = Entry_init(ENTRY_AUTO, "");

    AAiter* iter = AAiter_init(AAITER_AUTO, state->tree);

    Entry* entry = AAiter_get_at_least(iter, key);
    while (entry != NULL)
    {
        entry->is_set = false;
        entry->carry = false;

        entry = AAiter_get_next(iter);
    }

    return;
}
Пример #5
0
bool Connections_check_connections(
        const Connections* graph, char err[DEVICE_CONNECTION_ERROR_LENGTH_MAX])
{
    rassert(graph != NULL);
    rassert(err != NULL);

    AAiter* iter = AAiter_init(AAITER_AUTO, graph->nodes);

    Device_node* node = AAiter_get_at_least(iter, "");
    while (node != NULL)
    {
        if (!Device_node_check_connections(node, err))
            return false;

        node = AAiter_get_next(iter);
    }

    return true;
}
Пример #6
0
bool Input_map_is_valid(const Input_map* im, const Bit_array* existents)
{
    rassert(im != NULL);
    rassert(existents != NULL);

    const Entry* key = ENTRY_KEY(0);
    AAiter* iter = AAiter_init(AAITER_AUTO, im->map);

    const Entry* pair = AAiter_get_at_least(iter, key);
    while (pair != NULL)
    {
        if (!Bit_array_get(existents, pair->input))
            return false;

        pair = AAiter_get_next(iter);
    }

    return true;
}
Пример #7
0
const Sample_entry* Note_map_get_entry(
        const Note_map* map,
        double cents,
        double force,
        Random* random)
{
    assert(map != NULL);
    assert(isfinite(cents));
    assert(isfinite(force) || (isinf(force) && force < 0));
    assert(random != NULL);

    Random_list* key =
        &(Random_list){ .force = force, .freq = NAN, .cents = cents };
    Random_list* estimate_low = AAiter_get_at_most(map->iter, key);
    Random_list* choice = NULL;
    double choice_d = INFINITY;

    if (estimate_low != NULL)
    {
        choice = estimate_low;
        choice_d = distance(choice, key);
        double min_tone = key->cents - choice_d;
        Random_list* candidate = AAiter_get_prev(map->iter);
        while (candidate != NULL && candidate->cents >= min_tone)
        {
            double d = distance(candidate, key);
            if (d < choice_d)
            {
                choice = candidate;
                choice_d = d;
                min_tone = key->cents - choice_d;
            }
            candidate = AAiter_get_prev(map->iter);
        }
    }

    Random_list* estimate_high = AAiter_get_at_least(map->iter, key);
    if (estimate_high != NULL)
    {
        double d = distance(estimate_high, key);
        if (choice == NULL || choice_d > d)
        {
            choice = estimate_high;
            choice_d = d;
        }

        double max_tone = key->cents + choice_d;
        Random_list* candidate = AAiter_get_next(map->iter);
        while (candidate != NULL && candidate->cents <= max_tone)
        {
            d = distance(candidate, key);
            if (d < choice_d)
            {
                choice = candidate;
                choice_d = d;
                max_tone = key->cents + choice_d;
            }
            candidate = AAiter_get_next(map->iter);
        }
    }

    if (choice == NULL)
    {
//        fprintf(stderr, "empty map\n");
        return NULL;
    }

    assert(choice->entry_count > 0);
    assert(choice->entry_count < NOTE_MAP_RANDOMS_MAX);
//    state->middle_tone = choice->freq;
    int index = Random_get_index(random, choice->entry_count);
    assert(index >= 0);
//    fprintf(stderr, "%d\n", index);

    return &choice->entries[index];
}