void G_parser::get_form_length(string& nc){
    if (nc=="form_length"){
        nc = get_nc();
        form_length = atoi(nc.c_str());
        //cout << "form_length is: " << form_length << endl;
    }
}
void G_parser::get_harm_rh(string& nc){
    if (nc=="harmonic_rhythm"){
        nc = get_nc();
        harm_rh = atoi(nc.c_str());
        //cout << "harm_rh is: " << harm_rh << endl;
    }
}
Example #3
0
static void js_close(struct v7 *v7, struct v7_val *obj,
                     struct v7_val *result,
                     struct v7_val *args, int num_args) {
  struct ns_connection *nc = get_nc(obj);
  (void) v7; (void) result; (void) args; (void) num_args;
  nc->flags |= NSF_CLOSE_IMMEDIATELY;
}
void G_parser::get_time_signature(string& nc){
    if (nc=="time_signature"){
        nc = get_nc();
        t_sign = atoi(nc.c_str());
        //cout << "t_sign is: " << nc << endl;
    }
}
Example #5
0
static void js_discard(struct v7 *v7, struct v7_val *this_obj,
                       struct v7_val *result,
                       struct v7_val **args, int num_args) {
  struct ns_connection *nc = get_nc(this_obj);
  (void) v7; (void) result;
  if (num_args == 1 && args[0]->type == V7_NUM) {
    iobuf_remove(&nc->recv_iobuf, args[0]->v.num);
  }
}
G_parser::G_parser() : grammar(grammar_path, std::ifstream::in){

    //"int main(){}"
    
    //grammar_path = "/Users/christodoulosaspromallis/Desktop/UCL/PhD Year 2/Development/OF/of_v0.9.1_osx_release/apps/midiWorkspace/blues/parser_project/bin/data/blues_grammar.txt";
    //cout << "CONTRUCTOR" << endl;
    
    grammar_path = "/Users/christodoulosaspromallis/Desktop/UCL/PhD Year 2/Development/OF/of_v0.9.1_osx_release/apps/midiWorkspace/blues/parser_project/bin/data/blues_grammar.txt";
    
    //ifstream grammar(grammar_path, ifstream::in);
    grammar.open(grammar_path);
    
    if (grammar.fail()){
        cerr << "Error Opening File";
        exit(1);
    };
    
    //cout << "setting up" << endl;
    
    //get main grammar elements
    while(!grammar.fail()){//z<12//!grammar.eof() //or while(grammar)
        nc = get_nc();
        //c = grammar.get();
        //cout << z << "_1: " << nc << endl;
        get_time_signature(nc);
        //cout << z << "_2: " << nc << endl;
        get_form_length(nc);
        //cout << z << "_3: " << nc << endl;
        get_harm_rh(nc);
        //cout << z << "_4: " << nc << endl;
        get_basic_vectors(nc);
        //cout << z << "_5: " << nc << endl;
        store_rules(nc);//normally will finish the significant bit of text file (i.e. the rules are last)
        //cout << z << "_6: " << nc << endl;
        
    }
    //restart reading from top (for next loop)
    grammar.clear();
    grammar.seekg(0, ios::beg);
    
    //initialise curr_cycle with tonics (rootpitch level)
    for(int i=0; i<harm_rh*form_length; i++) {
        
        curr_cycle.push_back(elem_ID());
        curr_cycle[i].time = {0, i};// {beat, harm_rh next..}
        curr_cycle[i].name = "i";
    }
    
    //place decs for the 1st cycle
    vector<int> t_aux = {0, 0, 0, 11, 0};
    update_dec(t_aux);
    
    grammar.close();
    
}
Example #7
0
static void js_send(struct v7 *v7, struct v7_val *this_obj,
                    struct v7_val *result,
                    struct v7_val **args, int num_args) {
  struct ns_connection *nc = get_nc(this_obj);
  int i;
  (void) v7; (void) result;
  for (i = 0; i < num_args; i++) {
    if (args[i]->type != V7_STR) continue;
    ns_send(nc, args[i]->v.str.buf, args[i]->v.str.len);
  }
}
Example #8
0
static void js_write(struct v7 *v7, struct v7_val *obj,
                     struct v7_val *result,
                     struct v7_val *args, int num_args) {
  int i;
  struct ns_connection *nc = get_nc(obj);
  (void) v7;
  result->type = V7_NUM;
  result->v.num = 0;
  for (i = 0; i < num_args; i++) {
    if (args[i].type != V7_STR) continue;
    ns_send(nc, args[i].v.str.buf, args[i].v.str.len);
  }
}
void G_parser::get_basic_vectors(string& nc){//perhaps get all namespace and categorize/throw ERROR if unrecognised?
    bool test = (nc=="decision_bars"||nc=="cadence_bars"||nc=="optimal_form"||nc=="rootpitch"||nc=="type"||nc=="inversion"||nc=="position"||nc=="terminals");
    if (test){
        string v_name = nc;
        nc = get_nc();
        if (nc=="{"){
            nc = get_nc();
            while(nc!="}"){
                if (v_name=="decision_bars"){
                    int curr_bar = atoi(nc.c_str()) - 1;//only if nc=="decision_bars"
                    dec_bars.push_back(curr_bar);
                }
                else if (v_name=="cadence_bars"){
                    int curr_bar = atoi(nc.c_str()) - 1;//only if nc=="decision_bars"
                    cad_bars.push_back(curr_bar);
                }
                else basic_vector[v_name].push_back(nc);
                nc = get_nc();
            }
            sort(dec_bars.begin(), dec_bars.end());
            sort(cad_bars.begin(), cad_bars.end());
        }
    }
}
void G_parser::store_rules(string& nc){
    
    //new rule
    if (nc=="rule:"){
        //cout << "rules: entered and harn_rh==" << harm_rh << " and form_length==" << form_length << endl;
        all_rules.push_back(rule());
        all_rules[rule_pop].is_optional = false;
        
        nc = get_nc();
        
        //left side
        while(nc!="->"){
            all_rules[rule_pop].left_str.push_back(nc);
            store_opt_data(nc);
            nc = get_nc();
        }
        
        //if (nc!="->") cout << "ERROR in line " << i << ": arrow required" << endl;
        int prod_pop=0;//production population
        
        while(nc!=":end_rule"){//store right_side
            all_rules[rule_pop].right_side.push_back(right_s());
            nc = get_nc();//production probability
            all_rules[rule_pop].right_side[prod_pop].prob = atof(nc.c_str());
            nc = get_nc();
            
            //store right_str
            while(nc!="->" && nc!=":end_rule"){
                all_rules[rule_pop].right_side[prod_pop].right_str.push_back(nc);//={"STR1", "STR2"};//
                nc = get_nc();
            }
            
            prod_pop++;
        }
        
        bool is_timed = false;
        vector<int> rule_time = {0, 0};//{beat, bar}
        
        //categorise (timed vs general)
        for (int i=0; i<all_rules[rule_pop].left_str.size(); i++) {
            
            for (int j=0; j<all_rules[rule_pop].left_str[i].length(); j++){
                
                if (all_rules[rule_pop].left_str[i][j]=='_'){
                    
                    is_timed = true;
                    int left_centre = i;
                    
                    //rule_time.clear();
                    
                    string bar_time_str, beat_time_str; // rule_semiq_str;//could be one variable only
                    j++;
                    
                    while(all_rules[rule_pop].left_str[i][j] != '_' && j<all_rules[rule_pop].left_str[i].length()){
                        bar_time_str.push_back(all_rules[rule_pop].left_str[i][j]);
                        j++;
                    }
                    
                    rule_time[1] = atoi(bar_time_str.c_str()) - 1;
                    
                    if (all_rules[rule_pop].left_str[i][j] == '_'){
                        
                        while (j<all_rules[rule_pop].left_str[i].length()){
                            j++;
                            beat_time_str.push_back(all_rules[rule_pop].left_str[i][j]);
                        }
                        
                        rule_time[0] = atoi(beat_time_str.c_str()) - 1;
                        
                    } else rule_time[0] = 0;
                    
                    all_rules[rule_pop].leftmost_time =  {rule_time[0], rule_time[1] - (i / harm_rh)};
                    
                    //exclude "_*.."
                    all_rules[rule_pop].left_str[i] = exclude_time(all_rules[rule_pop].left_str[i]);
                    
                    //existing_rules.push_back();
                    break;
                    
                } else all_rules[rule_pop].leftmost_time = {0, 0};
                
            }
            
            if (is_timed) break;
            
        }
        
        all_rules[rule_pop].timed = is_timed;
        
        if (is_timed) {
            //cout << "rule_time: " << rule_time[0] << " " << rule_time[1] << endl;
            existing_times.push_back(rule_time);//to test existence of rule_time, ELSE general_rules
            timed_rules[rule_time].push_back(all_rules[rule_pop]);
            
        } else {
            
            general_rules.push_back(all_rules[rule_pop]);
            //cout << "general rule" << endl;
        }
        
        rule_pop++;
    }
}