From: fred Date: Sun, 24 Mar 2002 19:54:24 +0000 (+0000) Subject: lilypond-0.1.9 X-Git-Tag: release/1.5.59~4081 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=36bebd559705fd844f236cf277abd7245f84ed86;p=lilypond.git lilypond-0.1.9 --- diff --git a/lily/gourlay-breaking.cc b/lily/gourlay-breaking.cc index 85533c517b..90d07e6851 100644 --- a/lily/gourlay-breaking.cc +++ b/lily/gourlay-breaking.cc @@ -21,16 +21,17 @@ const HAPPY_DOTS_I = 3; Helper to trace back an optimal path */ struct Break_node { - /** this was the previous. If negative, this break should not be - considered: this path has infinite energy - - */ - int prev_break_i_; - Real energy_f_; - Col_hpositions line_config_; - Break_node() { - prev_break_i_ = -1; - } + /** this was the previous. If negative, this break should not be + considered: this path has infinite energy + + */ + int prev_break_i_; + Real energy_f_; + Col_hpositions line_config_; + Break_node() + { + prev_break_i_ = -1; + } }; /** @@ -41,141 +42,164 @@ Array Gourlay_breaking::do_solve()const { - Array optimal_paths; - Line_of_cols all = all_cols(); - Array breaks = find_break_indices(); - - optimal_paths.set_size (breaks.size()); + Array optimal_paths; + Line_of_cols all = all_cols(); + Array breaks = find_break_indices(); + + optimal_paths.set_size (breaks.size()); - Break_node first_node ; - first_node.prev_break_i_ = -1; - first_node.line_config_.energy_f_ = 0; - - optimal_paths[0] = first_node; - int break_idx=1; + Break_node first_node ; + first_node.prev_break_i_ = -1; + first_node.line_config_.energy_f_ = 0; + + optimal_paths[0] = first_node; + int break_idx=1; - for (; break_idx< breaks.size(); break_idx++) { - Array candidates; - Array candidate_lines; - Pointer_list spacer_p_list; + for (; break_idx< breaks.size(); break_idx++) + { + Array candidates; + Array candidate_lines; + Pointer_list spacer_p_list; - /* - start with a short line, add measures. At some point - the line becomes infeasible. Then we don't try to add more - */ - for (int start_idx = break_idx; start_idx--;){ - if (break_idx - start_idx > max_measures_i_) - break; - - if (optimal_paths[start_idx].prev_break_i_ < 0 - && optimal_paths[start_idx].line_config_.energy_f_) + /* + start with a short line, add measures. At some point + the line becomes infeasible. Then we don't try to add more + */ + for (int start_idx = break_idx; start_idx--;) + { + if (break_idx - start_idx > max_measures_i_) + break; + + if (optimal_paths[start_idx].prev_break_i_ < 0 + && optimal_paths[start_idx].line_config_.energy_f_) - continue; + continue; - Line_of_cols line = all.slice (breaks[start_idx], breaks[break_idx]+1); + Line_of_cols line = all.slice (breaks[start_idx], breaks[break_idx]+1); - line[0] = line[0]->postbreak_p_; - line.top() = line.top ()->prebreak_p_; + line[0] = line[0]->postbreak_p_; + line.top() = line.top ()->prebreak_p_; - if (!feasible (line)) - break; + if (!feasible (line)) + break; - Col_hpositions approx; - approx.cols = line; + Col_hpositions approx; + approx.cols = line; - approx.spacer_l_ = generate_spacing_problem (line); - spacer_p_list.bottom().add (approx.spacer_l_); + approx.spacer_l_ = generate_spacing_problem (line); + spacer_p_list.bottom().add (approx.spacer_l_); - ((Break_algorithm*)this)->approx_stats_.add (approx.cols); - approx.approximate_solve_line(); + ((Break_algorithm*)this)->approx_stats_.add (approx.cols); + approx.approximate_solve_line(); - if (approx.energy_f_ > energy_bound_f_){ - continue; + if (approx.energy_f_ > energy_bound_f_) + { + continue; } - // this is a likely candidate. Store it. - candidate_lines.push (approx); - candidates.push (start_idx); + // this is a likely candidate. Store it. + candidate_lines.push (approx); + candidates.push (start_idx); } - int minimal_j = -1; - Real minimal_energy = infinity_f; - for (int j=0; j < candidates.size(); j++) { - int start = candidates[j]; - if ( optimal_paths[start].line_config_.energy_f_ - + candidate_lines[j].energy_f_ > minimal_energy) + int minimal_j = -1; + Real minimal_energy = infinity_f; + for (int j=0; j < candidates.size(); j++) + { + int start = candidates[j]; + if ( optimal_paths[start].line_config_.energy_f_ + + candidate_lines[j].energy_f_ > minimal_energy) - continue; + continue; - if ( !candidate_lines[j].satisfies_constraints_b_) { - candidate_lines[j].solve_line(); - ((Break_algorithm*)this)->exact_stats_.add ( candidate_lines[j].cols); + if ( !candidate_lines[j].satisfies_constraints_b_) + { + candidate_lines[j].solve_line(); + ((Break_algorithm*)this)->exact_stats_.add ( candidate_lines[j].cols); } - Real this_energy - = optimal_paths[start].line_config_.energy_f_ - + candidate_lines[j].energy_f_ ; + Real this_energy + = optimal_paths[start].line_config_.energy_f_ + + candidate_lines[j].energy_f_ ; - if ( this_energy < minimal_energy) { - minimal_j = j; - minimal_energy = this_energy; + if ( this_energy < minimal_energy) + { + minimal_j = j; + minimal_energy = this_energy; } } - if (minimal_j < 0) { - optimal_paths[break_idx].prev_break_i_ = -1; - optimal_paths[break_idx].line_config_.energy_f_ = infinity_f; - } else { - optimal_paths[break_idx].prev_break_i_ = candidates[minimal_j]; - optimal_paths[break_idx].line_config_ = candidate_lines[minimal_j]; + if (minimal_j < 0) + { + optimal_paths[break_idx].prev_break_i_ = -1; + optimal_paths[break_idx].line_config_.energy_f_ = infinity_f; + } + else + { + optimal_paths[break_idx].prev_break_i_ = candidates[minimal_j]; + optimal_paths[break_idx].line_config_ = candidate_lines[minimal_j]; } - if ( !(break_idx % HAPPY_DOTS_I)) - *mlog << "[" << break_idx << "]"< final_breaks; + Array final_breaks; - Array lines; - /* skip 0-th element, since it is a "dummy" elt*/ - for (int i = optimal_paths.size()-1; i> 0;) { - final_breaks.push ( i); - assert ( i > optimal_paths[i].prev_break_i_); + Array lines; + Real min_energy_f_ = infinity_f; + Real max_energy_f_ = 0; + + /* skip 0-th element, since it is a "dummy" elt*/ + for (int i = optimal_paths.size()-1; i> 0;) + { + final_breaks.push ( i); + assert ( i > optimal_paths[i].prev_break_i_); + + // there was no "feasible path" + if (!optimal_paths[i].line_config_.config.size()) { + final_breaks.set_size (0); + break; + } + i = optimal_paths[i].prev_break_i_; + } - // there was no "feasible path" - if (!optimal_paths[i].line_config_.config.size()) - return lines; - i = optimal_paths[i].prev_break_i_; + print_stats(); + /* + TODO print variation in energy + */ + if (max_energy_f_ ) + { + ; } + + - for (int i= final_breaks.size(); i--;) - lines.push ( optimal_paths[final_breaks[i]].line_config_); + for (int i= final_breaks.size(); i--;) + lines.push ( optimal_paths[final_breaks[i]].line_config_); - - return lines; + + return lines; } Gourlay_breaking::Gourlay_breaking() { - get_line_spacer = Spring_spacer::constructor; - energy_bound_f_ = infinity_f; - max_measures_i_ = INT_MAX; + get_line_spacer = Spring_spacer::constructor; + energy_bound_f_ = infinity_f; + max_measures_i_ = INT_MAX; } void Gourlay_breaking::do_set_pscore() { - energy_bound_f_ = pscore_l_->paper_l_->get_var ("gourlay_energybound"); - max_measures_i_ =int (rint (pscore_l_->paper_l_->get_var ("gourlay_maxmeasures"))); + energy_bound_f_ = pscore_l_->paper_l_->get_var ("gourlay_energybound"); + max_measures_i_ =int (rint (pscore_l_->paper_l_->get_var ("gourlay_maxmeasures"))); } diff --git a/lily/local-key-grav.cc b/lily/local-key-grav.cc index b1e6cb6b90..82134c8608 100644 --- a/lily/local-key-grav.cc +++ b/lily/local-key-grav.cc @@ -17,15 +17,17 @@ Local_key_engraver::Local_key_engraver() { - key_C_ = 0; + key_C_ = 0; } void Local_key_engraver::do_pre_move_processing() { - Local_key_item *key_item_p = 0; - if (mel_l_arr_.size()) { - for (int i=0; i < mel_l_arr_.size(); i++) { + Local_key_item *key_item_p = 0; + if (mel_l_arr_.size()) + { + for (int i=0; i < mel_l_arr_.size(); i++) + { Item * support_l = support_l_arr_[i]; Note_req * note_l = mel_l_arr_[i]; @@ -37,10 +39,8 @@ Local_key_engraver::do_pre_move_processing() local_key_.oct (note_l->octave_i_).acc (note_l->notename_i_) == note_l->accidental_i_) continue; - - - - if (!key_item_p) { + if (!key_item_p) + { int c0_i=0; Staff_info inf = get_staff_info(); @@ -48,52 +48,61 @@ Local_key_engraver::do_pre_move_processing() c0_i = *get_staff_info().c0_position_i_l_; key_item_p = new Local_key_item (c0_i); - } + } key_item_p->add (note_l); key_item_p->add_support (support_l); local_key_.oct (note_l->octave_i_) .set (note_l->notename_i_, note_l->accidental_i_); - } + } } - if (key_item_p) { + if (key_item_p) + { for (int i=0; i < support_l_arr_.size(); i++) key_item_p->add_support (support_l_arr_[i]); announce_element (Score_elem_info (key_item_p, 0)); // ugh ugh ugh typeset_element (key_item_p); } - - mel_l_arr_.clear(); - tied_l_arr_.clear(); - support_l_arr_.clear(); - forced_l_arr_.clear(); + + mel_l_arr_.clear(); + tied_l_arr_.clear(); + support_l_arr_.clear(); + forced_l_arr_.clear(); } + /* whoah .. this looks hairy! */ void Local_key_engraver::acknowledge_element (Score_elem_info info) { - Score_elem * elem_l = info.elem_l_; - if (info.req_l_->musical() && info.req_l_->musical ()->note ()) { + Score_elem * elem_l = info.elem_l_; + if (info.req_l_->musical() && info.req_l_->musical ()->note ()) + { Note_req * note_l = info.req_l_->musical()->note (); Item * item_l = info.elem_l_->item(); mel_l_arr_.push (note_l); support_l_arr_.push (item_l); - } else if (info.req_l_->command() - && info.req_l_->command()->keychange ()) { + } + else if (info.req_l_->command() + && info.req_l_->command()->keychange ()) + { Key_engraver * key_grav_l = (Key_engraver*)info.origin_grav_l_arr_[0]; key_C_ = &key_grav_l->key_; local_key_ = *key_C_; - } else if (elem_l->name() == Key_item::static_name ()) { + } + else if (elem_l->name() == Key_item::static_name ()) + { Key_engraver * key_grav_l = (Key_engraver*)info.origin_grav_l_arr_[0]; key_C_ = &key_grav_l->key_; - } else if (elem_l->name() == Tie::static_name ()) { + } + else if (elem_l->name() == Tie::static_name ()) + { Tie * tie_l = (Tie*)elem_l->spanner(); if (tie_l->same_pitch_b_) tied_l_arr_.push (tie_l-> right_head_l_); @@ -103,8 +112,9 @@ Local_key_engraver::acknowledge_element (Score_elem_info info) void Local_key_engraver::do_process_requests() { - Time_description const * time_C_ = get_staff_info().time_C_; - if (time_C_ && !time_C_->whole_in_measure_){ + Time_description const * time_C_ = get_staff_info().time_C_; + if (time_C_ && !time_C_->whole_in_measure_) + { if (key_C_) local_key_= *key_C_; }