int main(int argc, char **argv) { printf("read index files\n"); open_index("test1.idx", &name1,0); printf("List the keys in each index file in ascending order:\n\n"); uplist(&name1); printf("List the keys for each index file in decending order\n\n"); downlist(&name1); /* always close all files */ close_index(&name1); }
// {string name, int32 start_sec, int32 start_nano, // int32 end_sec, int32 end_nano}[] // = archiver.names(int32 key, string pattern) xmlrpc_value *get_names(xmlrpc_env *env, xmlrpc_value *args, void *user) { #ifdef LOGFILE LOG_MSG("archiver.names\n"); #endif // Get args, maybe setup pattern AutoPtr<RegularExpression> regex; xmlrpc_int32 key; char *pattern = 0; size_t pattern_len = 0; xmlrpc_parse_value(env, args, "(is#)", &key, &pattern, &pattern_len); if (env->fault_occurred) return 0; // Create result AutoXmlRpcValue result(xmlrpc_build_value(env, "()")); if (env->fault_occurred) return 0; try { if (pattern_len > 0) regex.assign(new RegularExpression(pattern)); // Open Index stdString directory; AutoPtr<Index> index(open_index(env, key)); if (env->fault_occurred) return 0; // Put all names in binary tree Index::NameIterator ni; BinaryTree<ChannelInfo> channels; ChannelInfo info; bool ok; for (ok = index->getFirstChannel(ni); ok; ok = index->getNextChannel(ni)) { if (regex && !regex->doesMatch(ni.getName())) continue; // skip what doesn't match regex info.name = ni.getName(); AutoPtr<RTree> tree(index->getTree(info.name, directory)); if (tree) tree->getInterval(info.start, info.end); else // Is this an error? info.start = info.end = nullTime; channels.add(info); } index->close(); // Sorted dump of names ChannelInfo::UserArg user_arg; user_arg.env = env; user_arg.result = result; channels.traverse(ChannelInfo::add_name_to_result, (void *)&user_arg); #ifdef LOGFILE LOG_MSG("get_names(%d, '%s') -> %d names\n", key, (pattern ? pattern : "<no pattern>"), xmlrpc_array_size(env, result)); #endif } catch (GenericException &e) { xmlrpc_env_set_fault_formatted(env, ARCH_DAT_SERV_FAULT, (char *) e.what()); return 0; } return result.release(); }
// Return the data for all the names[], start .. end etc. // as get_values() is supposed to return them. // // Returns raw values if interpol <= 0.0. // Returns 0 on error. xmlrpc_value *get_sheet_data(xmlrpc_env *env, int key, const stdVector<stdString> names, const epicsTime &start, const epicsTime &end, long count, ReaderFactory::How how, double delta) { try { #ifdef LOGFILE stdString txt; LOG_MSG("get_sheet_data\n"); LOG_MSG("Start : %s\n", epicsTimeTxt(start, txt)); LOG_MSG("End : %s\n", epicsTimeTxt(end, txt)); LOG_MSG("Method: %s\n", ReaderFactory::toString(how, delta)); #endif AutoPtr<Index> index(open_index(env, key)); if (env->fault_occurred) return 0; AutoPtr<SpreadsheetReader> sheet(new SpreadsheetReader(*index, how, delta)); AutoXmlRpcValue results(xmlrpc_build_value(env, "()")); if (env->fault_occurred) return 0; long name_count = names.size(); AutoArrayPtr<AutoXmlRpcValue> meta (new AutoXmlRpcValue[name_count]); AutoArrayPtr<AutoXmlRpcValue> values (new AutoXmlRpcValue[name_count]); AutoArrayPtr<xmlrpc_int32> xml_type (new xmlrpc_int32[name_count]); AutoArrayPtr<xmlrpc_int32> xml_count(new xmlrpc_int32[name_count]); AutoArrayPtr<size_t> ch_vals (new size_t[name_count]); bool ok = sheet->find(names, &start); long i; // Per-channel meta-info. for (i=0; i<name_count; ++i) { #ifdef LOGFILE LOG_MSG("Handling '%s'\n", names[i].c_str()); #endif ch_vals[i] = 0; values[i] = xmlrpc_build_value(env, "()"); if (env->fault_occurred) return 0; if (sheet->found(i)) { // Fix meta/type/count based on first value meta[i] = encode_ctrl_info(env, &sheet->getInfo(i)); dbr_type_to_xml_type(sheet->getType(i), sheet->getCount(i), xml_type[i], xml_count[i]); #if 0 LOG_MSG("Ch %lu: type, count = %d, %d\n", i, (int)xml_type[i], (int)xml_count[i]); #endif } else { // Channel exists, but has no data meta[i] = encode_ctrl_info(env, 0); xml_type[i] = XML_ENUM; xml_count[i] = 1; } } // Collect values long num_vals = 0; while (ok && num_vals < count && sheet->getTime() < end) { for (i=0; i<name_count; ++i) { if (sheet->get(i)) { ++ch_vals[i]; encode_value(env, sheet->getType(i), sheet->getCount(i), sheet->getTime(), sheet->get(i), xml_type[i], xml_count[i], values[i]); } else { // Encode as no value, but one of them ;-) // to avoid confusion w/ viewers that like to see some data in any case. encode_value(env, 0, 1, sheet->getTime(), 0, xml_type[i], xml_count[i], values[i]); } } ++num_vals; ok = sheet->next(); } // Assemble result = { name, meta, type, count, values } for (i=0; i<name_count; ++i) { AutoXmlRpcValue result( xmlrpc_build_value(env, "{s:s,s:V,s:i,s:i,s:V}", "name", names[i].c_str(), "meta", meta[i].get(), "type", xml_type[i], "count", xml_count[i], "values", values[i].get())); // Add to result array xmlrpc_array_append_item(env, results, result); #ifdef LOGFILE LOG_MSG("Ch %lu: %zu values\n", i, ch_vals[i]); #endif } #ifdef LOGFILE LOG_MSG("%ld values total\n", num_vals); #endif return results.release(); } catch (GenericException &e) { #ifdef LOGFILE LOG_MSG("Error:\n%s\n", e.what()); #endif xmlrpc_env_set_fault_formatted(env, ARCH_DAT_DATA_ERROR, "%s", e.what()); } return 0; }
// Return the data for all the names[], start .. end etc. // as get_values() is supposed to return them. // Returns 0 on error. xmlrpc_value *get_channel_data(xmlrpc_env *env, int key, const stdVector<stdString> names, const epicsTime &start, const epicsTime &end, long count, ReaderFactory::How how, double delta) { AutoXmlRpcValue results; try { #ifdef LOGFILE stdString txt; LOG_MSG("get_channel_data\n"); LOG_MSG("Method: %s\n", ReaderFactory::toString(how, delta)); LOG_MSG("Start: %s\n", epicsTimeTxt(start, txt)); LOG_MSG("End : %s\n", epicsTimeTxt(end, txt)); #endif AutoPtr<Index> index(open_index(env, key)); if (env->fault_occurred) return 0; AutoPtr<DataReader> reader(ReaderFactory::create(*index, how, delta)); results = xmlrpc_build_value(env, "()"); if (env->fault_occurred) return 0; long i, name_count = names.size(); for (i=0; i<name_count; ++i) { #ifdef LOGFILE LOG_MSG("Handling '%s'\n", names[i].c_str()); #endif long num_vals = 0; AutoXmlRpcValue values(xmlrpc_build_value(env, "()")); if (env->fault_occurred) return 0; const RawValue::Data *data = reader->find(names[i], &start); AutoXmlRpcValue meta; xmlrpc_int32 xml_type, xml_count; if (data == 0) { // No exception from file error etc., just no data. meta = encode_ctrl_info(env, 0); xml_type = XML_ENUM; xml_count = 1; } else { // Fix meta/type/count based on first value meta = encode_ctrl_info(env, &reader->getInfo()); dbr_type_to_xml_type(reader->getType(), reader->getCount(), xml_type, xml_count); while (num_vals < count && data && RawValue::getTime(data) < end) { encode_value(env, reader->getType(), reader->getCount(), RawValue::getTime(data), data, xml_type, xml_count, values); ++num_vals; data = reader->next(); } } // Assemble result = { name, meta, type, count, values } AutoXmlRpcValue result(xmlrpc_build_value( env, "{s:s,s:V,s:i,s:i,s:V}", "name", names[i].c_str(), "meta", (xmlrpc_value *)meta, "type", xml_type, "count", xml_count, "values", (xmlrpc_value *)values)); // Add to result array xmlrpc_array_append_item(env, results, result); #ifdef LOGFILE LOG_MSG("%ld values\n", num_vals); #endif } // for ( .. name .. ) } catch (GenericException &e) { #ifdef LOGFILE LOG_MSG("Error:\n%s\n", e.what()); #endif xmlrpc_env_set_fault_formatted(env, ARCH_DAT_DATA_ERROR, "%s", e.what()); return 0; } return results.release(); }
int freenect_process_events(freenect_context *ctx) { /* This is where the magic happens. We read 1 update from the index per call, so this needs to be called in a loop like usual. If the index line is a Depth/RGB image the provided callback is called. If the index line is accelerometer data, then it is used to update our internal state. If you query for the accelerometer data you get the last sensor reading that we have. The time delays are compensated as best as we can to match those from the original data and current run conditions (e.g., if it takes longer to run this code then we wait less). */ if (!index_fp) open_index(); char type; double record_cur_time; unsigned int timestamp, data_size; char *data = NULL; if (parse_line(&type, &record_cur_time, ×tamp, &data_size, &data)) return -1; // Sleep an amount that compensates for the original and current delays // playback_ is w.r.t. the current time // record_ is w.r.t. the original time period during the recording if (record_prev_time != 0. && playback_prev_time != 0.) sleep_highres((record_cur_time - record_prev_time) - (get_time() - playback_prev_time)); record_prev_time = record_cur_time; switch (type) { case 'd': if (cur_depth_cb && depth_running) { void *cur_depth = skip_line(data); if (depth_buffer) { memcpy(depth_buffer, cur_depth, freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT).bytes); cur_depth = depth_buffer; } cur_depth_cb(fake_dev, cur_depth, timestamp); } break; case 'r': if (cur_rgb_cb && rgb_running) { void *cur_rgb = skip_line(data); if (rgb_buffer) { memcpy(rgb_buffer, cur_rgb, freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB).bytes); cur_rgb = rgb_buffer; } cur_rgb_cb(fake_dev, cur_rgb, timestamp); } break; case 'a': if (data_size == sizeof(state)) { memcpy(&state, data, sizeof(state)); } else if (!already_warned) { already_warned = 1; printf("\n\nWarning: Accelerometer data has an unexpected" " size [%u] instead of [%u]. The acceleration " "and tilt data will be substituted for dummy " "values. This data was probably made with an " "older version of record (the upstream interface " "changed).\n\n", data_size, (unsigned int)sizeof state); } break; } free(data); playback_prev_time = get_time(); return 0; }
int main(int argc, char **argv) { int i; const char *filename; const char *indexname = NULL; char name[256], *p; FILE *f; printf("/* This file was generated automatically by cptoqe */\n"); printf("\n" "/*" "\n" " * More Charsets and Tables for QEmacs" "\n" " *" "\n" " * Copyright (c) 2002 Fabrice Bellard." "\n" " * Copyright (c) 2002-2008 Charlie Gordon." "\n" " *" "\n" " * This library is free software; you can redistribute it and/or" "\n" " * modify it under the terms of the GNU Lesser General Public" "\n" " * License as published by the Free Software Foundation; either" "\n" " * version 2 of the License, or (at your option) any later version." "\n" " *" "\n" " * This library is distributed in the hope that it will be useful," "\n" " * but WITHOUT ANY WARRANTY; without even the implied warranty of" "\n" " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU" "\n" " * Lesser General Public License for more details." "\n" " *" "\n" " * You should have received a copy of the GNU Lesser General Public" "\n" " * License along with this library; if not, write to the Free Software" "\n" " * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA" "\n" " */" "\n" "" "\n" "#include \"qe.h\"" "\n" ""); add_init("int charset_more_init(void)\n{\n"); for (i = 1; i < argc; i++) { filename = argv[i]; if (!strcmp(filename, "-i")) { if (++i >= argc) { fprintf(stderr, "cptoqe: missing index name after -i\n"); exit(2); } indexname = argv[i]; continue; } pstrcpy(name, sizeof(name), get_basename(filename)); strip_extension(name); for (p = name; *p; p++) { if (*p == '_') *p = '-'; else *p = tolower((unsigned char)*p); } f = open_index(indexname, name); if (!f) { f = fopen(filename, "r"); if (!f) { perror(filename); exit(1); } } handle_cp(f, name, filename); fclose(f); } add_init("\n return 0;\n}\n\n" "qe_module_init(charset_more_init);\n"); printf("%s", module_init); return 0; }
int main(int argc, char **argv) { int c=1; while (c < argc) { if (strcmp(argv[c],"-ffmpeg")==0) use_ffmpeg = 1; else if (strcmp(argv[c],"-ffmpeg-opts")==0) { if (++c < argc) ffmpeg_opts = argv[c]; } else if (strcmp(argv[c],"-h")==0) usage(); else out_dir = argv[c]; c++; } if (!out_dir) usage(); signal(SIGINT, signal_cleanup); if (use_ffmpeg) { FILE *f; char *index_fn = malloc(strlen(out_dir) + 50); sprintf(index_fn, "%s-index.txt", out_dir); index_fp = open_index(index_fn); free(index_fn); if (!index_fp) return 1; depth_name = malloc(strlen(out_dir) + 50); rgb_name = malloc(strlen(out_dir) + 50); sprintf(depth_name, "%s-depth.avi", out_dir); sprintf(rgb_name, "%s-rgb.avi", out_dir); f = fopen(depth_name, "r"); if (f) { printf("Error: %s already exists, to avoid overwriting " "use a different name.\n", depth_name); fclose(f); exit(1); } f = fopen(rgb_name, "r"); if (f) { printf("Error: %s already exists, to avoid overwriting " "use a different name.\n", depth_name); fclose(f); exit(1); } init(); free(depth_name); free(rgb_name); if (depth_stream) fclose(depth_stream); if (rgb_stream) fclose(rgb_stream); fclose(index_fp); } else { #ifdef _WIN32 _mkdir(out_dir); #else mkdir(out_dir, S_IRWXU | S_IRWXG | S_IRWXO); #endif char *fn = malloc(strlen(out_dir) + 50); sprintf(fn, "%s/INDEX.txt", out_dir); index_fp = open_index(fn); free(fn); if (!index_fp) { fclose(index_fp); return 1; } init(); fclose(index_fp); } return 0; }
/* get the next entry of a scan returns the RID of the next record that meets all the conditions returns (rid_t) -1 in case we are out of records */ RID hf_scan_next(CURSOR *cur, void *record){ if (cur->index == -1){ long long schema_space = 2*cur->hf->n_fields; long long record_space = (cur->hf->n_records) * hf_record_length(cur->hf); long long file_size = sizeof(long long) + sizeof(int) + schema_space + record_space; if (cur->current >= file_size) return -1; hf_record(cur->hf, cur->current, record); cur->current += hf_record_length(cur->hf); // if the current record doesn't meet all the conditions, fetch and check the next while (filter(record, cur->con, cur->conditions, cur->hf) == 0){ if (cur->current >= file_size) return -1; hf_record(cur->hf, cur->current, record); cur->current += hf_record_length(cur->hf); } return cur->current - hf_record_length(cur->hf); } else { INDEX_FILE *index_file; index_file = open_index(cur->con[cur->index].field-1, cur->hf); void *buf2 = calloc(105,sizeof(char)); int zero = 0; if (buf2==NULL){ printf("Malloc failed"); exit(1); } if (cur->index_current_bucket == -1){ (*encode[cur->hf->schema_array[cur->con[cur->index].field-1]])(buf2, (char*)cur->con[cur->index].value, &zero,atoi((cur->hf->schema[cur->con[cur->index].field-1])+1)); zero = 0; cur->index_current_bucket = (*calculate_index[cur->hf->schema_array[cur->con[cur->index].field-1]])(buf2,index_file->s,index_file->n,0); } int i = cur->con[cur->index].field-1; int original_offset; int original_usage; void *original_bucket = calloc(BSIZE,sizeof(char)); //void *bucket; //bucket = calloc(BSIZE,sizeof(char)); if (original_bucket==NULL){ printf("Malloc failed"); exit(1); } void *buf = calloc(105,sizeof(char)); if (buf==NULL){ printf("Malloc failed"); exit(1); } if (cur->index_mo == 0){ read_bucket(original_bucket, cur->index_current_bucket, index_file->main_path); } else { read_bucket(original_bucket, cur->index_current_bucket, index_file->overflow_path); } original_usage = ((int*)original_bucket)[0]; for (original_offset = cur->index_bucket_offset; original_offset < original_usage; original_offset += atoi((cur->hf->schema[i])+1)+sizeof(long long)){ RID rid = (*read_keypair[cur->hf->schema_array[i]])(original_bucket, buf, original_offset, atoi((cur->hf->schema[i])+1)); hf_record(cur->hf, rid, record); if (filter(record, cur->con, cur->conditions, cur->hf) == 1){ cur->index_bucket_offset = original_offset + atoi((cur->hf->schema[i])+1)+sizeof(long long); free(original_bucket); free(buf); return rid; } } while (((long long*)(original_bucket+4))[0]!=-1){ int current_bucket = ((long long*)(original_bucket+4))[0]; read_bucket(original_bucket, ((long long*)(original_bucket+4))[0], index_file->overflow_path); original_usage = ((int*)original_bucket)[0]; for (original_offset = 12; original_offset < original_usage; original_offset += atoi((cur->hf->schema[i])+1)+sizeof(long long)){ RID rid = (*read_keypair[cur->hf->schema_array[i]])(original_bucket, buf, original_offset, atoi((cur->hf->schema[i])+1)); hf_record(cur->hf, rid, record); if (filter(record, cur->con, cur->conditions, cur->hf) == 1){ cur->index_bucket_offset = original_offset + atoi((cur->hf->schema[i])+1)+sizeof(long long); cur->index_current_bucket = current_bucket; cur->index_mo = 1; free(original_bucket); free(buf); return rid; } } } free(original_bucket); free(buf); free(buf2); return -1; } }
char task_output::run (char state) { //*p_serial_comp << endl << "Out State " << state << endl; switch(state) { // Wait for output change case(0): if (flag_stop_motors) { return(3); } else if (flag_start_motors) { return(5); } else if(flag_init_motors) { return(7); } else if(flag_output_change) { flag_output_change = false; return(1); // Go to state 1 (Check for interferences) } else { flag_ready_to_output = true; return(STL_NO_TRANSITION); } return(STL_NO_TRANSITION); break; // Check for interferences case(1): flag_ready_to_output = false; if(flag_interference_thumb) { open_thumb(); flag_interference_thumb = false; } if(flag_interference_index) { open_index(); flag_interference_index = false; } if(flag_interference_middle) { open_middle(); flag_interference_middle = false; } if(flag_interference_ring) { open_ring(); flag_interference_ring = false; } if(flag_interference_pinky) { open_pinky(); flag_interference_pinky = false; } return(2); break; // Process outputs case(2): if (!flag_motors_enabled) { flag_motors_enabled = true; } // Parse character switch(character_to_output) { case('0'): case('O'): case('o'): thumb_curl(); index_curl(); middle_curl(); ring_curl(); pinky_curl(); wrist_default(); return(0); break; case('1'): thumb_flat_up(); index_stretch(); middle_clench(); ring_clench(); pinky_clench(); wrist_default(); return(0); break; case('2'): thumb_flat_up(); index_stretch(); middle_stretch(); ring_clench(); pinky_clench(); wrist_default(); return(0); break; case('3'): thumb_stretch(); index_stretch(); middle_stretch(); ring_clench(); pinky_clench(); wrist_default(); return(0); break; case('4'): case('b'): case('B'): switch(character_step) { case(1): thumb_fold_out(); index_stretch(); middle_stretch(); ring_stretch(); pinky_stretch(); wrist_default(); character_step++; return(STL_NO_TRANSITION); case(2): thumb_fold_in(); flag_interference_thumb = true; character_step = 1; return(0); default: *p_serial_comp << endl << "Error character " << character_to_output << " step " << character_step << endl; } break; case('5'): thumb_stretch(); index_stretch(); middle_stretch(); ring_stretch(); pinky_stretch(); wrist_default(); return(0); break; case('6'): case('W'): case('w'): switch(character_step) { case(1): thumb_fold_out(); index_stretch(); middle_stretch(); ring_stretch(); pinky_clench(); wrist_default(); character_step++; return(STL_NO_TRANSITION); case(2): thumb_fold_in(); flag_interference_thumb = true; character_step = 1; return(0); default: *p_serial_comp << endl << "Error character " << character_to_output << " step " << character_step << endl; } break; case('7'): switch(character_step) { case(1): thumb_fold_out(); index_stretch(); middle_stretch(); ring_clench(); pinky_stretch(); wrist_default(); character_step++; return(STL_NO_TRANSITION); case(2): thumb_fold_in(); flag_interference_thumb = true; character_step = 1; return(0); default: *p_serial_comp << endl << "Error character " << character_to_output << " step " << character_step << endl; } break; case('8'): switch(character_step) { case(1): thumb_fold_out(); index_stretch(); middle_clench(); ring_stretch(); pinky_stretch(); wrist_default(); character_step++; return(STL_NO_TRANSITION); case(2): thumb_fold_in(); flag_interference_thumb = true; character_step = 1; return(0); default: *p_serial_comp << endl << "Error character " << character_to_output << " step " << character_step << endl; } break; case('9'): thumb_flat_up(); index_clench(); middle_stretch(); ring_stretch(); pinky_stretch(); wrist_default(); return(0); break; case('A'): case('a'): thumb_flat_up(); index_clench(); middle_clench(); ring_clench(); pinky_clench(); wrist_default(); return(0); break; case('C'): case('c'): thumb_fold_out(); index_curl(); middle_curl(); ring_curl(); pinky_clench(); wrist_default(); return(0); break; case('D'): case('d'): thumb_curl(); index_stretch(); middle_curl(); ring_curl(); pinky_clench(); wrist_default(); return(0); break; case('E'): case('e'): switch(character_step) { case(1): thumb_fold_out(); index_stretch(); middle_stretch(); ring_stretch(); pinky_stretch(); wrist_default(); character_step++; return(STL_NO_TRANSITION); case(2): thumb_fold_in(); index_curl(); middle_curl(); ring_curl(); pinky_curl(); flag_interference_thumb = true; flag_interference_index = true; flag_interference_middle = true; flag_interference_ring = true; flag_interference_pinky = true; character_step = 1; return(0); default: *p_serial_comp << endl << "Error character " << character_to_output << " step " << character_step << endl; } break; case('F'): case('f'): thumb_flat_up(); index_clench(); middle_stretch(); ring_stretch(); pinky_stretch(); wrist_default(); return(0); break; case('G'): case('g'): thumb_flat_up(); index_stretch(); middle_clench(); ring_clench(); pinky_clench(); wrist_bent(); return(0); break; case('H'): case('h'): thumb_flat_up(); index_stretch(); middle_stretch(); ring_clench(); pinky_clench(); wrist_bent(); return(0); break; case('I'): case('i'): thumb_flat_up(); index_clench(); middle_clench(); ring_clench(); pinky_stretch(); wrist_default(); return(0); break; case('J'): case('j'): switch(character_step) { case(1): thumb_flat_up(); index_clench(); middle_clench(); ring_clench(); pinky_stretch(); wrist_default(); character_step++; return(STL_NO_TRANSITION); case(2): wrist_bent(); character_step++; return(STL_NO_TRANSITION); case(3): wrist_bent_and_twisted(); character_step++; return(STL_NO_TRANSITION); case(4): wrist_twisted(); character_step = 1; return(0); } break; case('K'): case('k'): switch(character_step) { case(1): thumb_flat_up(); index_stretch(); middle_stretch(); ring_clench(); pinky_clench(); wrist_default(); character_step++; return(STL_NO_TRANSITION); case(2): thumb_fold_in(); flag_interference_thumb = true; character_step = 1; return(0); default: *p_serial_comp << endl << "Error character " << character_to_output << " step " << character_step << endl; } break; case('L'): case('l'): thumb_stretch(); index_stretch(); middle_clench(); ring_clench(); pinky_clench(); wrist_default(); return(0); break; case('M'): case('m'): switch(character_step) { case(1): thumb_fold_in(); index_stretch(); middle_stretch(); ring_stretch(); pinky_clench(); wrist_default(); character_step++; return(STL_NO_TRANSITION); case(2): index_vert_clench(); middle_vert_clench(); ring_curl(); flag_interference_thumb = true; flag_interference_index = true; flag_interference_middle = true; flag_interference_ring = true; character_step = 1; return(0); default: *p_serial_comp << endl << "Error character " << character_to_output << " step " << character_step << endl; } break; case('N'): case('n'): switch(character_step) { case(1): thumb_fold_in(); index_stretch(); middle_stretch(); ring_clench(); pinky_clench(); wrist_default(); character_step++; return(STL_NO_TRANSITION); case(2): index_vert_clench(); middle_vert_clench(); flag_interference_thumb = true; flag_interference_index = true; flag_interference_middle = true; character_step = 1; return(0); default: *p_serial_comp << endl << "Error character " << character_to_output << " step " << character_step << endl; } break; case('P'): case('p'): thumb_fold_up(); index_stretch(); middle_fold(); ring_clench(); pinky_clench(); wrist_bent(); flag_interference_thumb = true; flag_interference_middle = true; return(0); break; case('Q'): case('q'): thumb_fold_out(); index_fold(); middle_clench(); ring_clench(); pinky_clench(); wrist_bent(); return(0); break; case('R'): case('r'): thumb_flat_up(); index_cross(); middle_clench(); ring_clench(); pinky_clench(); wrist_default(); flag_interference_index = true; return(0); break; case('S'): case('s'): switch(character_step) { case(1): thumb_fold_out(); index_clench(); middle_clench(); ring_clench(); pinky_clench(); wrist_default(); character_step++; return(STL_NO_TRANSITION); case(2): thumb_fold_in(); flag_interference_thumb = true; character_step = 1; return(0); default: *p_serial_comp << endl << "Error character " << character_to_output << " step " << character_step << endl; } break; case('T'): case('t'): switch(character_step) { case(1): thumb_flat_up(); index_vert_clench(); middle_clench(); ring_clench(); pinky_clench(); wrist_default(); character_step++; return(STL_NO_TRANSITION); case(2): thumb_fold_in(); flag_interference_thumb = true; flag_interference_index = true; character_step = 1; return(0); default: *p_serial_comp << endl << "Error character " << character_to_output << " step " << character_step << endl; } break; case('U'): case('u'): switch(character_step) { case(1): thumb_flat_up(); index_stretch(); middle_stretch(); ring_clench(); pinky_clench(); wrist_default(); character_step++; return(STL_NO_TRANSITION); case(2): index_u(); flag_interference_thumb = true; flag_interference_index = true; character_step = 1; return(0); default: *p_serial_comp << endl << "Error character " << character_to_output << " step " << character_step << endl; } break; case('X'): case('x'): switch(character_step) { case(1): thumb_fold_out(); index_stretch(); middle_clench(); ring_clench(); pinky_clench(); wrist_default(); character_step++; return(STL_NO_TRANSITION); case(2): thumb_fold_in(); index_vert_clench(); flag_interference_thumb = true; flag_interference_index = true; character_step = 1; return(0); default: *p_serial_comp << endl << "Error character " << character_to_output << " step " << character_step << endl; } case('Y'): case('y'): thumb_stretch(); index_clench(); middle_clench(); ring_clench(); pinky_stretch(); wrist_default(); break; case('Z'): case('z'): switch(character_step) { case(1): thumb_flat_up(); index_clench(); middle_clench(); ring_clench(); pinky_stretch(); wrist_z1(); character_step++; return(STL_NO_TRANSITION); case(2): wrist_z2(); character_step++; return(STL_NO_TRANSITION); case(3): wrist_z3(); character_step++; return(STL_NO_TRANSITION); case(4): wrist_bent(); character_step = 1; return(0); default: *p_serial_comp << endl << "Error character " << character_to_output << " step " << character_step << endl; } } return(0); // Go to state 2 (output) when done break; // Send Stop Command to a Motor case(3): flag_stop_motors = false; p_slave_chooser->choose(motor_to_stop); if(p_serial_slave->ready_to_send()) { *p_serial_slave << "S"; } return(4); break; // Wait for confirmation on stop command case(4): if(p_serial_slave->check_for_char()) { input_character = p_serial_slave->getchar(); if (input_character == 's') *p_serial_comp << endl << "Motor " << motor_to_stop << " stopped"; else *p_serial_comp << endl << "Motor stop error " << motor_to_stop << endl; if (motor_to_stop == 10) { motor_to_stop = 1; return(0); } else { motor_to_stop++; return(3); } } else { return(STL_NO_TRANSITION); } // Send Start Command to a Motor case(5): flag_start_motors = false; p_slave_chooser->choose(motor_to_start); if(p_serial_slave->ready_to_send()) { *p_serial_slave << "G"; } return(6); break; // Wait for confirmation on start command case(6): if(p_serial_slave->check_for_char()) { input_character = p_serial_slave->getchar(); if (input_character == 'g') *p_serial_comp << endl << "Motor " << motor_to_start << " enabled"; else *p_serial_comp << endl << "Motor start error " << motor_to_start << endl; if (motor_to_start == 10) { motor_to_start = 1; return(0); } else { motor_to_start++; return(5); } } else { return(STL_NO_TRANSITION); } // Send initialization command to one motor case(7): p_slave_chooser->choose(motor_to_init); if(p_serial_slave->ready_to_send()) { if (motor_to_init > 0 && motor_to_init < 10) character_to_output = motor_to_init + 0x30; else if (motor_to_init == 10) character_to_output = '0'; else *p_serial_comp << endl << "Motor conf error " << motor_to_init << endl; *p_serial_slave << character_to_output; return(8); } break; // Wait for initialization response from motor case(8): if(p_serial_slave->check_for_char()) { input_character = p_serial_slave->getchar(); if (input_character == '!') *p_serial_comp << endl << "Motor " << motor_to_init << " initialized"; else *p_serial_comp << endl << "Motor init error " << motor_to_init << endl; if (motor_to_init == 10) { motor_to_init = 1; return(0); } else { motor_to_init++; return(7); } } else { return(STL_NO_TRANSITION); } break; default: return(0); break; } // If we get here, no transition is called for return (STL_NO_TRANSITION); }
int IndexFile::create_index(Asset *asset, MainProgressBar *progress) { int result = 0; this->mwindow = mwindow; this->asset = asset; interrupt_flag = 0; // open the source file File source; if(open_source(&source)) return 1; get_index_filename(source_filename, mwindow->preferences->index_directory, index_filename, asset->path); // Test for index in stream table of contents if(!source.get_index(index_filename)) { printf("IndexFile::create_index 1\n"); redraw_edits(1); } else // Build index from scratch { asset->index_zoom = get_required_scale(&source); // Indexes are now built for everything since it takes too long to draw // from CDROM source. // total length of input file int64_t length_source = source.get_audio_length(0); // get amount to read at a time in floats int64_t buffersize = 65536; char string[BCTEXTLEN]; sprintf(string, _("Creating %s."), index_filename); progress->update_title(string); progress->update_length(length_source); redraw_timer->update(); // thread out index thread IndexThread *index_thread = new IndexThread(mwindow, this, asset, index_filename, buffersize, length_source); index_thread->start_build(); // current sample in source file int64_t position = 0; int64_t fragment_size = buffersize; int current_buffer = 0; // pass through file once while(position < length_source && !result) { if(length_source - position < fragment_size && fragment_size == buffersize) fragment_size = length_source - position; index_thread->input_lock[current_buffer]->lock("IndexFile::create_index 1"); index_thread->input_len[current_buffer] = fragment_size; int cancelled = progress->update(position); if(cancelled || index_thread->interrupt_flag || interrupt_flag) { result = 3; } for(int channel = 0; !result && channel < asset->channels; channel++) { source.set_audio_position(position, 0); source.set_channel(channel); // Read from source file if(source.read_samples(index_thread->buffer_in[current_buffer][channel], fragment_size, 0)) result = 1; } // Release buffer to thread if(!result) { index_thread->output_lock[current_buffer]->unlock(); current_buffer++; if(current_buffer >= TOTAL_BUFFERS) current_buffer = 0; position += fragment_size; } else { index_thread->input_lock[current_buffer]->unlock(); } } // end thread cleanly index_thread->input_lock[current_buffer]->lock("IndexFile::create_index 2"); index_thread->last_buffer[current_buffer] = 1; index_thread->output_lock[current_buffer]->unlock(); index_thread->stop_build(); delete index_thread; } source.close_file(); open_index(asset); close_index(); mwindow->edl->set_index_file(asset); return 0; }
int IndexFile::open_index(MWindow *mwindow, Asset *asset) { return open_index(asset); }