void G_parser::find_rule(vector<int>& seq_t){ //cout << "reached 1" << endl; //cout << "seq_t: " << seq_t[2] << " & " << seq_t[3] << endl; // if (previous (in left_str) is rootpitch) { search for its terminal equivalents; } //if IV in previous context (instead of iv) then lookup corresponding chords (IV = iv*, iv6*, iv7*) OR (IV = iv*) //what about IV instead of iv later? (what if already translated as iv from IV?) --> e.g. "IV I_3" ->... // if context not found, look for equivalent rootpitch // perhaps categorise IV as iv|iv6|iv7 bool rule_found = false; bool opt; rule r; int cont_size; vector<int> leftmost_t; //find (if) timed_rule //search existing_times for (int i=0; i<existing_times.size(); i++){//replace with while() //cout << "reached 2" << endl; if (seq_t[2]==existing_times[i][0] && seq_t[3]==existing_times[i][1]){//seq_t[2,3] for beat, bar.. //cout << "reached 3" << endl; //check context (match rule with current context) for (int j=0; j<timed_rules[{seq_t[2], seq_t[3]}].size(); j++){ //cout << "reached 4" << endl; //check_context(seq_t); //i6 could map to I etc. if context not found ? cont_size = timed_rules[{seq_t[2], seq_t[3]}][j].left_str.size(); leftmost_t = timed_rules[{seq_t[2], seq_t[3]}][j].leftmost_time; opt = timed_rules[{seq_t[2], seq_t[3]}][j].is_optional; vector<string> curr_cont = get_context(leftmost_t, cont_size); if (timed_rules[{seq_t[2], seq_t[3]}][j].is_optional){//timed and optional rule r = timed_rules[{seq_t[2], seq_t[3]}][j]; rule_found = check_optional(r, seq_t); if (rule_found) break; } else {//timed, but not optional //cout << "reached 11" << endl; if (curr_cont == timed_rules[{seq_t[2], seq_t[3]}][j].left_str){ //cout << "reached 12" << endl; rule_found = true; //expand to support optional too r = timed_rules[{seq_t[2], seq_t[3]}][j]; the_rule = r; //debug cout << "the_rule: "; for (int j=0; j<the_rule.left_str.size(); j++) cout << the_rule.left_str[j] << ", "; cout << endl; rewrite(r, seq_t); cout << "case 2" << endl;//timed, but not optional break; } } } break; } } //else find general_rule if(!rule_found) {//replace with while() //search general_rules (context again) for (int i=0; i<general_rules.size(); i++){ //check if context exists before or after current chord (elem) int c_off = - general_rules[i].left_str.size();//context offset (back n forth) cont_size = general_rules[i].left_str.size(); //leftmost_t = general_rules[i].leftmost_time;//is {0, 0} opt = general_rules[i].is_optional; //need to access specific general_rule for (int z = c_off; z < 0; z++){ general_rules[i].leftmost_time[1] = seq_t[3] + (z+1) / harm_rh; vector<string> curr_cont = get_context(general_rules[i].leftmost_time, cont_size); //check context if(general_rule[i].is_optional) if (opt){ r = general_rules[i]; rule_found = check_optional(r, seq_t); if (rule_found) break; } //check context if (!general_rule[i].is_optional) else if(get_context(general_rules[i].leftmost_time, cont_size) == general_rules[i].left_str){ rule_found = true; r = general_rules[i]; the_rule = r; //debug cout << "the_rule: "; for (int j=0; j<the_rule.left_str.size(); j++) cout << the_rule.left_str[j] << ", "; cout << endl; rewrite(r, seq_t); cout << "case 5" << endl;//general and not optional break; } } if (rule_found) break; } } cout << "is_terminal?: " << curr_cycle[seq_t[3]].name << endl << endl; //stop if terminal if (!is_terminal(seq_t)) find_rule(seq_t); //else return_terminal(curr_cycle[seq_t[3]].name); else translate_to_midi();//translate / spit out (return_terminal()) }
char* check_option(char **in,int n,int which,int type) { char test,*ret=NULL,wasfound=0,ok=1; int i; for (i=1;i<n;i++) { if (in[i] != NULL) { test= (in[i][0] == '-') && (in[i][1] == which); if (test) { wasfound=1; if (type != 'n') { if (strlen(in[i]) > 2) { switch(type) { case 'u': check_unsigned(in[i]+2,which);break; case 'd': check_integer(in[i]+2,which);break; case 'f': check_float(in[i]+2,which);break; case '2': check_two(in[i]+2,which);break; case '3': check_three(in[i]+2,which);break; } if (ret != NULL) free(ret); check_alloc(ret=(char*)calloc(strlen(in[i]+2)+1,(size_t)1)); strcpy(ret,in[i]+2); in[i]=NULL; } else { in[i]=NULL; i++; if (i < n) { if (in[i] != NULL) { switch(type) { case 'u': check_unsigned(in[i],which);break; case 'd': check_integer(in[i],which);break; case 'f': check_float(in[i],which);break; case '2': check_two(in[i],which);break; case '3': check_three(in[i]+2,which);break; case 'o': ok=check_optional(in[i],which);break; } if (ok) { if (ret != NULL) free(ret); check_alloc(ret=(char*)calloc(strlen(in[i])+1,(size_t)1)); strcpy(ret,in[i]); in[i]=NULL; } else { i--; if (ret != NULL) free(ret); ret=NULL; } } } else { if (ret != NULL) { free(ret); ret=NULL; } } } } else { in[i]=NULL; } } } } if (((type == 'o') || (type == 'n')) && (ret == NULL) && wasfound) return ""; if (wasfound && (ret == NULL)) { fprintf(stderr,"The option -%c needs some value. Exiting!\n",which); exit(CHECK_OPTION_C_NO_VALUE); } return ret; }