kqt_Handle kqt_new_Handle(void) { Handle* handle = memory_alloc_item(Handle); if (handle == NULL) { Handle_set_error(0, ERROR_MEMORY, "Couldn't allocate memory"); return 0; } if (!Handle_init(handle)) { memory_free(handle); return 0; } kqt_Handle id = add_handle(handle); if (id == 0) { Handle_deinit(handle); memory_free(handle); return 0; } return id; }
bool Handle_init(Handle* handle) { assert(handle != NULL); handle->data_is_valid = true; handle->data_is_validated = true; handle->module = NULL; handle->error = *ERROR_AUTO; handle->validation_error = *ERROR_AUTO; memset(handle->position, '\0', POSITION_LENGTH); handle->player = NULL; handle->length_counter = NULL; // int buffer_count = SONG_DEFAULT_BUF_COUNT; // int voice_count = 256; handle->module = new_Module(); if (handle->module == NULL) { Handle_set_error(NULL, ERROR_MEMORY, "Couldn't allocate memory"); Handle_deinit(handle); return false; } // Create players handle->player = new_Player( handle->module, DEFAULT_AUDIO_RATE, 2048, 16384, 256); handle->length_counter = new_Player(handle->module, 1000000000L, 0, 0, 0); if (handle->player == NULL || handle->length_counter == NULL) { Handle_set_error(NULL, ERROR_MEMORY, "Couldn't allocate memory"); Handle_deinit(handle); return false; } Handle_stop(handle); //kqt_Handle_set_position(handle, 0, 0); return true; }
void kqt_del_Handle(kqt_Handle handle) { check_handle_void(handle); Handle* h = get_handle(handle); if (!remove_handle(handle)) { Handle_set_error(NULL, ERROR_ARGUMENT, "Invalid Kunquat Handle: %d", handle); return; } Handle_deinit(h); memory_free(h); return; }