static hash_t *get_hash(const hash_t *hash, const char *key, int i){ hash_element_t *element = HASH_get(hash,key,i,HASH_TYPE); if(element==NULL) return NULL; if (element->a.hash==NULL){ RError("element->hash==NULL. key: %s, i: %d\n", key, i); return HASH_create(1); } return element->a.hash; }
hash_t *HASH_get_keys_in_hash(const hash_t *hash){ hash_t *keys = HASH_create(hash->num_elements); int pos=0; int i; for(i=0;i<hash->elements_size;i++){ hash_element_t *element = hash->elements[i]; while(element!=NULL){ HASH_put_chars_at(keys,"key",pos++,element->key); element=element->next; } } return keys; }
// Can also be used to rehash hash_t *HASH_copy(const hash_t *hash){ hash_t *ret = HASH_create(hash->num_elements); ret->version = hash->version; int i; for(i=0;i<hash->elements_size;i++){ hash_element_t *element = hash->elements[i]; while(element!=NULL){ hash_element_t *element_copy = copy_element(element); put2(ret, element->key, element->i, element_copy); element=element->next; } } return ret; }
static void *Undo_Do_Sample( struct Tracker_Windows *window, struct WBlocks *wblock, struct WTracks *wtrack, int realline, void *pointer ){ struct Undo_Sample *undo_ae=pointer; SoundPlugin *plugin = undo_ae->patch->patchdata; hash_t *new_state = HASH_create(3); plugin->type->create_state(plugin, new_state); //printf("Calling Undo_do for %d. Current value: %f. Now setting it back to %f\n",undo_ae->effect_num,new_value,undo_ae->value); plugin->type->recreate_from_state(plugin, undo_ae->state); GFX_update_instrument_widget(undo_ae->patch); undo_ae->state = new_state; return undo_ae; }
static void Undo_Sample( struct Tracker_Windows *window, struct WBlocks *wblock, struct Patch *patch ) { struct Undo_Sample *undo_ae=talloc(sizeof(struct Undo_Sample)); SoundPlugin *plugin = patch->patchdata; undo_ae->patch = patch; undo_ae->state = HASH_create(3); plugin->type->create_state(plugin,undo_ae->state); Undo_Add_dont_stop_playing( window->l.num, wblock->l.num, wblock->wtrack->l.num, wblock->curr_realline, undo_ae, Undo_Do_Sample ); }
hash_t *HASH_load(disk_t *file){ wchar_t *line = L""; while(STRING_starts_with(line, "#") || STRING_equals2(STRING_trim(line), L"")) line = READ_LINE(file); int version; if(STRING_equals(line,">> HASH MAP BEGIN")){ version = 1; } else if (STRING_equals(line,">> HASH MAP V2 BEGIN")){ version = 2; } else if (STRING_equals(line,">> HASH MAP V3 BEGIN")){ version = 3; } else if (STRING_starts_with(line, ">> HASH MAP V")){ version = 3; vector_t v = {0}; int try_anyway = VECTOR_push_back(&v, "Try anyway (program might crash and/or behave unstable)"); int ok = VECTOR_push_back(&v, "Ok"); int res = GFX_Message(&v, "Need a newer version of Radium to load this file"); if (res!=try_anyway) return NULL; (void)ok; } else { GFX_Message(NULL, "Trying to load something which is not a hash map. First line: \"%S\"", line); return NULL; } line = READ_LINE(file); int elements_size = STRING_get_int(line); hash_t *hash=HASH_create(elements_size); hash->version = version; line = READ_LINE(file); while(!STRING_equals(line,"<< HASH MAP END") && !STRING_equals(line,"<< HASH MAP V2 END") && !STRING_equals(line,"<< HASH MAP V3 END")){ const char *key = STRING_get_chars(line); int i = 0; if(version > 1){ line = READ_LINE(file); i = STRING_get_int(line); int new_size = i+1; if(new_size > hash->num_array_elements) hash->num_array_elements = new_size; } else if(!strncmp(key,"<int hash>",strlen("<int hash>"))) { sscanf(key, "<int hash> %d", &i); key = ""; hash->num_array_elements++; } bool success; dyn_t dyn = DYN_load(file, &success); if (!success) return NULL; put_dyn(hash, key, i, dyn); line = READ_LINE(file); } return hash; }