From b053638dac19bed7f8d2f8b8b0231b3611c17fde Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Wed, 23 Aug 2006 20:43:29 +0000 Subject: [PATCH] * lily/smobs.cc (protect_smob): switch off fancy smob protection for now. * lily/include/performer.hh (class Performer): strip get_tempo() method. * lily/midi-def.cc: strip file. * lily/lexer.ll (Lily_lexer): don't protect hash key separately. * lily/include/context-def.hh (struct Context_def): use VIRTUAL_COPY_CONSTRUCTOR(). * lily/source-file.cc: smobification. * lily/include/source-file.hh (class Source_file): smobify Source_file. Trim redundant members. * lily/parser.yy (Lily_lexer::try_special_identifiers): unprotect clones after creation. This plugs a huge memory leak. * python/convertrules.py (FatalConversionError.sub_tempo): complete rule for \midi{ \tempo } * input/mutopia/J.S.Bach/wtk1-fugue2.ly (bassdux): idem. * input/mutopia/F.Schubert/morgenlied.ly (pianoLH): update tempo. --- ChangeLog | 32 ++++- THANKS | 3 + input/mutopia/F.Schubert/morgenlied.ly | 7 +- input/mutopia/J.S.Bach/wtk1-fugue2.ly | 5 +- lily/binary-source-file.cc | 4 + lily/context-def.cc | 7 -- lily/include/context-def.hh | 3 +- lily/include/input.hh | 1 - lily/include/ly-smobs.icc | 4 +- lily/include/output-def.hh | 3 - lily/include/performer-group.hh | 1 - lily/include/performer.hh | 1 - lily/include/score-performer.hh | 1 - lily/include/smobs.hh | 2 +- lily/include/source-file.hh | 46 +++----- lily/input-smob.cc | 9 +- lily/lexer.ll | 4 +- lily/lily-guile.cc | 6 +- lily/metronome-engraver.cc | 6 +- lily/midi-def.cc | 46 -------- lily/parser.yy | 31 ++--- lily/performance.cc | 6 - lily/performer-group.cc | 12 -- lily/performer.cc | 6 - lily/pfb.cc | 9 +- lily/prob.cc | 1 + lily/score-performer.cc | 6 - lily/smobs.cc | 38 +++--- lily/source-file.cc | 157 +++++++++++++------------ lily/source.cc | 5 +- lily/staff-performer.cc | 8 +- lily/tfm-reader.cc | 28 ++++- python/convertrules.py | 14 +-- 33 files changed, 245 insertions(+), 267 deletions(-) diff --git a/ChangeLog b/ChangeLog index fa82ee28f6..5fefaf8d20 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,32 @@ +2006-08-23 Han-Wen Nienhuys + + * lily/smobs.cc (protect_smob): switch off fancy smob protection + for now. + + * lily/include/performer.hh (class Performer): strip get_tempo() method. + + * lily/midi-def.cc: strip file. + + * lily/lexer.ll (Lily_lexer): don't protect hash key separately. + + * lily/include/context-def.hh (struct Context_def): use + VIRTUAL_COPY_CONSTRUCTOR(). + + * lily/source-file.cc: smobification. + + * lily/include/source-file.hh (class Source_file): smobify + Source_file. Trim redundant members. + + * lily/parser.yy (Lily_lexer::try_special_identifiers): unprotect + clones after creation. This plugs a huge memory leak. + + * python/convertrules.py (FatalConversionError.sub_tempo): + complete rule for \midi{ \tempo } + + * input/mutopia/J.S.Bach/wtk1-fugue2.ly (bassdux): idem. + + * input/mutopia/F.Schubert/morgenlied.ly (pianoLH): update tempo. + 2006-08-22 Han-Wen Nienhuys * python/convertrules.py (conv): warning on \tempo{} @@ -16,7 +45,8 @@ * lily/parser.yy (output_def_body): disallow \tempo in \midi{} - * lily/duration-scheme.cc (LY_DEFINE): ly:duration-length: new function. + * lily/duration-scheme.cc (LY_DEFINE): ly:duration-length: new + function. * scm/lily.scm (define-scheme-options): alphabetize, add eps-pad-boxes. diff --git a/THANKS b/THANKS index c9af7de1b0..8be5301cbf 100644 --- a/THANKS +++ b/THANKS @@ -1,6 +1,7 @@ Release 2.9 *********** + DEVELOPMENT TEAM Han-Wen Nienhuys - Core development @@ -8,6 +9,7 @@ Jan Nieuwenhuizen - Core development Graham Percival - Documentation Editor Mats Bengtsson - Support Guru + CONTRIBUTORS Angelo Contardi @@ -18,6 +20,7 @@ Guido Amoruso Heikki Junes Joe Neeman + SPONSORS Andrew Sidwell diff --git a/input/mutopia/F.Schubert/morgenlied.ly b/input/mutopia/F.Schubert/morgenlied.ly index 18cd30924a..d34939a15d 100644 --- a/input/mutopia/F.Schubert/morgenlied.ly +++ b/input/mutopia/F.Schubert/morgenlied.ly @@ -160,7 +160,7 @@ pianoLH = \relative c'' \repeat volta 2 { \lyricsto "singer" \new Lyrics \firstVerse \lyricsto "singer" \new Lyrics \secondVerse \new PianoStaff << - \set PianoStaff.instrument = \markup { + \set PianoStaff.instrumentName = \markup { \bold \bigger\bigger\bigger\bigger \huge "2. " } \new Staff \pianoRH @@ -186,7 +186,10 @@ pianoLH = \relative c'' \repeat volta 2 { } } \midi { - \tempo 4 = 70 + \context { + \Score + tempoWholesPerMinute = #(ly:make-moment 70 4) + } } } } diff --git a/input/mutopia/J.S.Bach/wtk1-fugue2.ly b/input/mutopia/J.S.Bach/wtk1-fugue2.ly index 22406fd1e6..38ee277e1b 100644 --- a/input/mutopia/J.S.Bach/wtk1-fugue2.ly +++ b/input/mutopia/J.S.Bach/wtk1-fugue2.ly @@ -219,7 +219,10 @@ bassdux = \context Voice = "three" \relative c' { } \layout {} \midi { - \tempo 4 =84 + \context { + \Score + tempoWholesPerMinute = #(ly:make-moment 84 4) + } } } \paper { diff --git a/lily/binary-source-file.cc b/lily/binary-source-file.cc index 90d4a4ac02..3a8728694c 100644 --- a/lily/binary-source-file.cc +++ b/lily/binary-source-file.cc @@ -61,7 +61,11 @@ Binary_source_file::get_line (char const *pos_str0) const U8 Binary_source_file::get_U8 () { +#if 0 // FIXME return *(U8 *)forward_str0 (1); +#endif + assert (false); + return 0; } U16 diff --git a/lily/context-def.cc b/lily/context-def.cc index f15a1ab141..b856486dba 100644 --- a/lily/context-def.cc +++ b/lily/context-def.cc @@ -262,13 +262,6 @@ Context_def::instantiate (SCM ops, Object_key const *key) return context; } -SCM -Context_def::clone_scm () const -{ - Context_def *t = new Context_def (*this); - return t->unprotect (); -} - SCM Context_def::make_scm () { diff --git a/lily/include/context-def.hh b/lily/include/context-def.hh index df69f257dd..a92ad4fee5 100644 --- a/lily/include/context-def.hh +++ b/lily/include/context-def.hh @@ -43,6 +43,8 @@ public: SCM get_translator_group_type () const { return translator_group_type_; } void set_acceptor (SCM accepts, bool add); + VIRTUAL_COPY_CONSTRUCTOR(Context_def, Context_def); + vector path_to_acceptable_context (SCM type_string, Output_def *) const; Context *instantiate (SCM extra_ops, Object_key const *); @@ -50,7 +52,6 @@ public: SCM to_alist () const; static SCM make_scm (); - SCM clone_scm () const; void apply_default_property_operations (Context *); private: diff --git a/lily/include/input.hh b/lily/include/input.hh index e211dc15c3..f7224ec7d3 100644 --- a/lily/include/input.hh +++ b/lily/include/input.hh @@ -20,7 +20,6 @@ class Input char const *start_; char const *end_; Source_file *source_file_; - public: Source_file *get_source_file () const; char const *start () const; diff --git a/lily/include/ly-smobs.icc b/lily/include/ly-smobs.icc index 2475b8ca75..99c09fc043 100644 --- a/lily/include/ly-smobs.icc +++ b/lily/include/ly-smobs.icc @@ -74,8 +74,8 @@ void \ CL::smobify_self () \ { \ - self_scm_ = unprotected_smobify_self (); \ protection_cons_ = SCM_EOL; \ + self_scm_ = unprotected_smobify_self (); \ protect (); \ } \ void \ @@ -86,7 +86,7 @@ SCM \ CL::unprotect () \ { \ - unprotect_smob (&protection_cons_); \ + unprotect_smob (self_scm_, &protection_cons_); \ return self_scm_; \ } \ SCM \ diff --git a/lily/include/output-def.hh b/lily/include/output-def.hh index 7d5563d474..de190a7c86 100644 --- a/lily/include/output-def.hh +++ b/lily/include/output-def.hh @@ -67,9 +67,6 @@ SCM get_font_table (Output_def *def); void assign_context_def (Output_def *m, SCM transdef); SCM find_context_def (Output_def const *m, SCM name); -int get_tempo (Output_def*def, Moment moment); -void set_tempo (Output_def*def, Moment moment, int count_per_minute_i); - Interval line_dimensions_int (Output_def*def, int); diff --git a/lily/include/performer-group.hh b/lily/include/performer-group.hh index f5c1256a22..b12a73c586 100644 --- a/lily/include/performer-group.hh +++ b/lily/include/performer-group.hh @@ -21,7 +21,6 @@ public: void do_announces (); virtual void announce_element (Audio_element_info); virtual void play_element (Audio_element *p); - virtual int get_tempo () const; protected: vector announce_infos_; diff --git a/lily/include/performer.hh b/lily/include/performer.hh index 658a822b03..b97cea1926 100644 --- a/lily/include/performer.hh +++ b/lily/include/performer.hh @@ -25,7 +25,6 @@ protected: virtual void announce_element (Audio_element_info); virtual void acknowledge_audio_element (Audio_element_info); virtual void create_audio_elements (); - virtual int get_tempo () const; virtual void play_element (Audio_element *elem); }; diff --git a/lily/include/score-performer.hh b/lily/include/score-performer.hh index 0987ef7d68..32344aa3a9 100644 --- a/lily/include/score-performer.hh +++ b/lily/include/score-performer.hh @@ -32,7 +32,6 @@ protected: virtual void disconnect_from_context (); virtual void initialize (); virtual void announce_element (Audio_element_info); - virtual int get_tempo () const; virtual void play_element (Audio_element *p); virtual void derived_mark () const; private: diff --git a/lily/include/smobs.hh b/lily/include/smobs.hh index be08a073b0..dd384786ed 100644 --- a/lily/include/smobs.hh +++ b/lily/include/smobs.hh @@ -138,7 +138,7 @@ #define DECLARE_TYPE_P(CL) extern SCM CL ## _type_p_proc void protect_smob (SCM smob, SCM *prot_cons); -void unprotect_smob (SCM *prot_cons); +void unprotect_smob (SCM smob, SCM *prot_cons); #endif /* SMOBS_HH */ diff --git a/lily/include/source-file.hh b/lily/include/source-file.hh index 33b4051c4c..05fd73359f 100644 --- a/lily/include/source-file.hh +++ b/lily/include/source-file.hh @@ -12,7 +12,7 @@ #include "flower-proto.hh" #include "std-vector.hh" #include "lily-proto.hh" -#include "protected-scm.hh" +#include "smobs.hh" #include using namespace std; @@ -27,12 +27,21 @@ using namespace std; class Source_file { + vector newline_locations_; + istream *istream_; + vector characters_; + SCM str_port_; + + char const *contents_str0 () const; + void load_stdin (); + void init_port (); + void init (); + + DECLARE_SMOBS(Source_file, bla); public: Source_file (string fn); Source_file (string, string); - virtual ~Source_file (); - char const *c_str () const; virtual string quote_input (char const *pos_str0) const; istream *get_istream (); @@ -43,46 +52,19 @@ public: string name_string () const; string file_line_column_string (char const *str0) const; - // return start + n - char const *seek_str0 (int n); - - int tell () const; - // return here + n bytes - char const *forward_str0 (int n); - char const *pos_str0 () { return pos_str0_; } - string get_string (int n); - void set_pos (char const *pos_str0); public: Slice line_slice (char const *pos_str0) const; string line_string (char const *pos_str0) const; void get_counts (char const *pos_str0, int *, int *, int *) const; - - /* - JUNKME. - - This thing doubles as a file-storage/file-iterator object. - */ - char const *pos_str0_; - + SCM get_port () const; string name_; protected: int line_offset_; - -private: - vector newline_locations_; - istream *istream_; - char *contents_str0_; - vector chs_; - int length_; - void load_stdin (); - void init_port (); - - Protected_scm str_port_; }; -char *gulp_file (string fn, int *len); +vector gulp_file (string fn, int desired); #endif /* SOURCE_FILE_HH */ diff --git a/lily/input-smob.cc b/lily/input-smob.cc index e3bc5d275d..72b293f10c 100644 --- a/lily/input-smob.cc +++ b/lily/input-smob.cc @@ -7,7 +7,7 @@ */ #include "input-smob.hh" - +#include "source-file.hh" #include "std-string.hh" #include "ly-smobs.icc" @@ -18,8 +18,13 @@ Input dummy_input_global; static long input_tag; static -SCM mark_smob (SCM) +SCM mark_smob (SCM s) { + Input *sc = (Input *) SCM_CELL_WORD_1 (s); + + if (Source_file *sf = sc->get_source_file ()) + return sf->self_scm (); + return SCM_EOL; } diff --git a/lily/lexer.ll b/lily/lexer.ll index 2fd018ff1b..98332a1eb3 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -338,7 +338,7 @@ BOM_UTF8 \357\273\277 } yylval.scm = sval; - return SCM_T; + return SCM_TOKEN; } { \<\< { @@ -912,7 +912,7 @@ static void init_signature_hash_table () }; for (int i = 0; sigs[i].symbol; i++) - scm_hashq_set_x (signature_hash_table, scm_gc_protect_object (ly_symbol2scm (sigs[i].symbol)), + scm_hashq_set_x (signature_hash_table, ly_symbol2scm (sigs[i].symbol), scm_from_int (sigs[i].token_type)); } diff --git a/lily/lily-guile.cc b/lily/lily-guile.cc index f7938cfc21..971063e54e 100644 --- a/lily/lily-guile.cc +++ b/lily/lily-guile.cc @@ -105,10 +105,8 @@ gulp_file_to_string (string fn, bool must_exist, int size) if (be_verbose_global) progress_indication ("[" + s); - int n = size; - char *str = gulp_file (s, &n); - string result (str, n); - delete[] str; + vector chars = gulp_file (s, size); + string result (&chars[0], chars.size ()); if (be_verbose_global) progress_indication ("]"); diff --git a/lily/metronome-engraver.cc b/lily/metronome-engraver.cc index 40be81e221..cfae9a5ee8 100644 --- a/lily/metronome-engraver.cc +++ b/lily/metronome-engraver.cc @@ -85,10 +85,10 @@ Metronome_mark_engraver::process_music () context ()->self_scm ()); text_->set_property ("text", result); - - last_duration_ = duration; - last_count_ = count; } + + last_duration_ = duration; + last_count_ = count; } #include "translator.icc" diff --git a/lily/midi-def.cc b/lily/midi-def.cc index c3b80dbeae..e69de29bb2 100644 --- a/lily/midi-def.cc +++ b/lily/midi-def.cc @@ -1,46 +0,0 @@ -/* - midi-def.cc -- implement midi output def functions - - source file of the GNU LilyPond music typesetter - - (c) 1997--2006 Jan Nieuwenhuizen -*/ - - -#include "misc.hh" -#include "output-def.hh" -#include "moment.hh" -#include "warn.hh" -#include "scm-hash.hh" - -int -get_tempo (Output_def *def, - Moment one_beat_mom) -{ - SCM wis = ly_symbol2scm ("whole-in-seconds"); - Moment *w = unsmob_moment (def->lookup_variable (wis)); - - Moment wholes_per_min = Moment (60); - if (!w) - { - programming_error ("wholes-in-seconds not set."); - wholes_per_min /= 4; - } - else - wholes_per_min /= *w; - - Rational beats_per_min = (wholes_per_min / one_beat_mom).main_part_; - return beats_per_min.to_int (); -} - -void -set_tempo (Output_def *def, - Moment one_beat_mom, - int beats_per_minute_i) -{ - Moment beats_per_second = Moment (beats_per_minute_i) / Moment (60); - - Moment m = Moment (1) / Moment (beats_per_second * one_beat_mom); - def->set_variable (ly_symbol2scm ("whole-in-seconds"), m.smobbed_copy ()); -} - diff --git a/lily/parser.yy b/lily/parser.yy index 7c04cb0c26..c9dbb79f98 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -250,7 +250,6 @@ If we give names, Bison complains. %token CHORDMODIFIERS %token LYRIC_MARKUP %token MULTI_MEASURE_REST -%token SCM_T %token DIGIT @@ -301,7 +300,7 @@ If we give names, Bison complains. %token REAL %token RESTNAME %token SCM_IDENTIFIER -%token SCM_T +%token SCM_TOKEN %token SCORE_IDENTIFIER %token STRING %token STRING_IDENTIFIER @@ -504,7 +503,7 @@ toplevel_expression: ; embedded_scm: - SCM_T + SCM_TOKEN | SCM_IDENTIFIER ; @@ -535,15 +534,6 @@ assignment_id: assignment: assignment_id '=' identifier_init { - if (! is_regular_identifier ($1)) - { -#if 0 - /* no longer valid with dashes in \paper{} block. */ - @1.warning (_ ("identifier should have alphabetic characters only")); -#endif - } - - PARSER->lexer_->set_identifier ($1, $3); /* @@ -2360,17 +2350,26 @@ Lily_lexer::try_special_identifiers (SCM *destination, SCM sid) *destination = sid; return STRING_IDENTIFIER; } else if (unsmob_book (sid)) { - *destination = unsmob_book (sid)->clone ()->self_scm (); + Book *book = unsmob_book (sid)->clone (); + *destination = book->self_scm (); + book->unprotect (); + return BOOK_IDENTIFIER; } else if (scm_is_number (sid)) { *destination = sid; return NUMBER_IDENTIFIER; } else if (unsmob_context_def (sid)) { - *destination = unsmob_context_def (sid)->clone_scm (); + Context_def *def= unsmob_context_def (sid)->clone (); + + *destination = def->self_scm (); + def->unprotect (); + return CONTEXT_DEF_IDENTIFIER; } else if (unsmob_score (sid)) { Score *score = new Score (*unsmob_score (sid)); *destination = score->self_scm (); + + score->unprotect (); return SCORE_IDENTIFIER; } else if (Music *mus = unsmob_music (sid)) { mus = mus->clone (); @@ -2381,6 +2380,7 @@ Lily_lexer::try_special_identifiers (SCM *destination, SCM sid) bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types")) != SCM_BOOL_F; + mus->unprotect (); return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER; } else if (unsmob_duration (sid)) { *destination = unsmob_duration (sid)->smobbed_copy (); @@ -2388,8 +2388,9 @@ Lily_lexer::try_special_identifiers (SCM *destination, SCM sid) } else if (unsmob_output_def (sid)) { Output_def *p = unsmob_output_def (sid); p = p->clone (); - + *destination = p->self_scm (); + p->unprotect (); return OUTPUT_DEF_IDENTIFIER; } else if (Text_interface::is_markup (sid)) { *destination = sid; diff --git a/lily/performance.cc b/lily/performance.cc index f765a31937..35d47e2ebc 100644 --- a/lily/performance.cc +++ b/lily/performance.cc @@ -129,12 +129,6 @@ Performance::output_header_track (Midi_stream &midi_stream) Midi_text track_name (&track_name_a); midi_track.add (Moment (0), &track_name); - - // Some sequencers read track 0 last. - // Audio_tempo tempo_a (midi_->get_tempo (Moment (Rational (1, 4)))); - // Midi_tempo tempo (&tempo_a); - // midi_track.add (Moment (0), &tempo); - midi_stream << midi_track; } diff --git a/lily/performer-group.cc b/lily/performer-group.cc index 9e71c6e762..990f478bf8 100644 --- a/lily/performer-group.cc +++ b/lily/performer-group.cc @@ -96,15 +96,3 @@ Performer_group::play_element (Audio_element *e) } } -int -Performer_group::get_tempo () const -{ - Context *c = context_->get_parent_context (); - if (c) - { - Performer_group *pgp = dynamic_cast (c->implementation ()); - return pgp->get_tempo (); - } - return 60; -} - diff --git a/lily/performer.cc b/lily/performer.cc index af896f23dd..28726bc7ef 100644 --- a/lily/performer.cc +++ b/lily/performer.cc @@ -17,12 +17,6 @@ Performer::play_element (Audio_element *p) get_daddy_performer ()->play_element (p); } -int -Performer::get_tempo () const -{ - return get_daddy_performer ()->get_tempo (); -} - Performer_group * Performer::get_daddy_performer () const { diff --git a/lily/pfb.cc b/lily/pfb.cc index 678e480b90..a96aac7761 100644 --- a/lily/pfb.cc +++ b/lily/pfb.cc @@ -78,17 +78,16 @@ LY_DEFINE (ly_pfb_to_pfa, "ly:pfb->pfa", SCM_ARG1, __FUNCTION__, "string"); string file_name = ly_scm2string (pfb_file_name); - int len = -1; if (be_verbose_global) progress_indication ("[" + file_name); - char *str = gulp_file (file_name, &len); - char *pfa = pfb2pfa ((Byte *)str, len); - + vector pfb_string = gulp_file (file_name, 0); + char *pfa = pfb2pfa ((Byte *) &pfb_string[0], pfb_string.size ()); + SCM pfa_scm = scm_makfrom0str (pfa); free (pfa); - delete str; + if (be_verbose_global) progress_indication ("]"); diff --git a/lily/prob.cc b/lily/prob.cc index 5a1caca155..2640bdf870 100644 --- a/lily/prob.cc +++ b/lily/prob.cc @@ -25,6 +25,7 @@ Prob::Prob (SCM type, SCM immutable_init) smobify_self (); } + Prob::~Prob () { } diff --git a/lily/score-performer.cc b/lily/score-performer.cc index a0b0c7d17e..7252b0cff7 100644 --- a/lily/score-performer.cc +++ b/lily/score-performer.cc @@ -124,12 +124,6 @@ Score_performer::one_time_step (SCM) precomputed_recurse_over_translators (context (), STOP_TRANSLATION_TIMESTEP, UP); } -int -Score_performer::get_tempo () const -{ - return ::get_tempo (performance_->midi_, Moment (Rational (1, 4))); -} - void Score_performer::derived_mark () const { diff --git a/lily/smobs.cc b/lily/smobs.cc index a6fdc76b9e..9629ed45ee 100644 --- a/lily/smobs.cc +++ b/lily/smobs.cc @@ -11,51 +11,58 @@ /* The CDR contains the actual protected list. */ -static SCM smob_protection_list; +static SCM smob_protection_list = SCM_EOL; void init_smob_protection () { - smob_protection_list = scm_cons (SCM_UNDEFINED, SCM_EOL); - scm_permanent_object (smob_protection_list); + smob_protection_list = scm_cons (SCM_BOOL_F, SCM_EOL); + scm_gc_protect_object (smob_protection_list); } ADD_SCM_INIT_FUNC (init_smob_protection, init_smob_protection); LY_DEFINE(ly_smob_protects, "ly:smob-protects", - 0,0,0, (), + 0, 0, 0, (), "Return lily's internal smob protection list") { - return scm_cdr (smob_protection_list); + return scm_is_pair (smob_protection_list) + ? scm_cdr (smob_protection_list) + : SCM_EOL; } - - - void protect_smob (SCM smob, SCM *prot_cons) { +#if 0 SCM s = scm_cdr (smob_protection_list); - while (scm_is_pair (s) && scm_car (s) == SCM_UNDEFINED) - s = scm_cdr (s); - + while (scm_is_pair (s) && scm_car (s) == SCM_BOOL_F) + { + s = scm_cdr (s); + } SCM prot = scm_cons (smob, s); scm_set_cdr_x (smob_protection_list, prot); *prot_cons = prot; +#else + scm_gc_protect_object (smob); +#endif } void -unprotect_smob (SCM *prot_cons) +unprotect_smob (SCM smob, SCM *prot_cons) { +#if 1 + scm_gc_unprotect_object (smob); +#else SCM next = scm_cdr (*prot_cons); if (next == SCM_EOL) - scm_set_car_x (*prot_cons, SCM_UNDEFINED); + scm_set_car_x (*prot_cons, SCM_BOOL_F); else { - scm_set_car_x (*prot_cons, SCM_UNDEFINED); + scm_set_car_x (*prot_cons, SCM_BOOL_F); while (scm_is_pair (next) - && scm_car (next) == SCM_UNDEFINED) + && scm_car (next) == SCM_BOOL_F) next = scm_cdr (next); @@ -63,4 +70,5 @@ unprotect_smob (SCM *prot_cons) } *prot_cons = SCM_EOL; +#endif } diff --git a/lily/source-file.cc b/lily/source-file.cc index b44066f267..cfa66b628f 100644 --- a/lily/source-file.cc +++ b/lily/source-file.cc @@ -34,19 +34,16 @@ using namespace std; void Source_file::load_stdin () { - length_ = 0; - chs_.clear (); + characters_.clear (); int c; while ((c = fgetc (stdin)) != EOF) - chs_.push_back (c); + characters_.push_back (c); - chs_.push_back (0); - length_ = chs_.size (); - contents_str0_ = &chs_[0]; + characters_.push_back (0); } -char * -gulp_file (string filename, int *filesize) +vector +gulp_file (string filename, int desired_size) { /* "b" must ensure to open literally, avoiding text (CR/LF) conversions. */ @@ -54,15 +51,17 @@ gulp_file (string filename, int *filesize) if (!f) { warning (_f ("can't open file: `%s'", filename.c_str ())); - return 0; + + vector cxx_arr; + return cxx_arr; } fseek (f, 0, SEEK_END); int real_size = ftell (f); int read_count = real_size; - if (*filesize >= 0) - read_count = min (read_count, *filesize); + if (desired_size > 0) + read_count = min (read_count, desired_size); rewind (f); @@ -74,62 +73,81 @@ gulp_file (string filename, int *filesize) warning (_f ("expected to read %d characters, got %d", bytes_read, read_count)); fclose (f); - *filesize = bytes_read; - return str; + int filesize = bytes_read; + + vector cxx_arr; + cxx_arr.resize (filesize); + + /* ugh, how to do neatly in STL? */ + memcpy (&cxx_arr[0], str, filesize); + + free (str); + return cxx_arr; } -Source_file::Source_file (string filename, string data) +char const * +Source_file::contents_str0 () const +{ + return &characters_[0]; +} + +void +Source_file::init () { - name_ = filename; istream_ = 0; line_offset_ = 0; - length_ = data.length (); - contents_str0_ = string_copy (data); - pos_str0_ = c_str (); + str_port_ = SCM_EOL; + self_scm_ = SCM_EOL; + smobify_self (); +} + +Source_file::Source_file (string filename, string data) +{ + init (); + + name_ = filename; + + characters_.resize (data.length ()); + + /* ugh, how to do neatly in STL? */ + memcpy ((&characters_[0]), data.c_str (), data.length ()); + init_port (); - for (int i = 0; i < length_; i++) - if (contents_str0_[i] == '\n') - newline_locations_.push_back (contents_str0_ + i); + for (vsize i = 0; i < characters_.size (); i++) + if (characters_[i] == '\n') + newline_locations_.push_back (&characters_[0] + i); } Source_file::Source_file (string filename_string) { + init (); + name_ = filename_string; - istream_ = 0; - line_offset_ = 0; - contents_str0_ = 0; if (filename_string == "-") load_stdin (); else { - length_ = -1; - contents_str0_ = gulp_file (filename_string, &length_); + characters_ = gulp_file (filename_string, -1); + characters_.push_back (0); } - - pos_str0_ = c_str (); init_port (); - for (int i = 0; i < length_; i++) - if (contents_str0_[i] == '\n') - newline_locations_.push_back (contents_str0_ + i); + for (vsize i = 0; i < characters_.size (); i++) + if (characters_[i] == '\n') + newline_locations_.push_back (&characters_[0] + i); } void Source_file::init_port () { - SCM str = scm_makfrom0str (contents_str0_); + SCM str = scm_makfrom0str (contents_str0 ()); str_port_ = scm_mkstrport (SCM_INUM0, str, SCM_OPN | SCM_RDNG, __FUNCTION__); scm_set_port_filename_x (str_port_, scm_makfrom0str (name_.c_str ())); } -int -Source_file::tell () const -{ - return pos_str0_ - contents_str0_; -} istream * Source_file::get_istream () @@ -189,7 +207,6 @@ Source_file::~Source_file () { delete istream_; istream_ = 0; - delete[] contents_str0_; } Slice @@ -346,60 +363,48 @@ Source_file::set_line (char const *pos_str0, int line) int Source_file::length () const { - return length_; + return characters_.size (); } char const * Source_file::c_str () const { - return contents_str0_; + return &characters_[0]; } -void -Source_file::set_pos (char const *pos_str0) +SCM +Source_file::get_port () const { - if (contains (pos_str0)) - pos_str0_ = pos_str0; - else - error (quote_input (pos_str0) + "invalid pos"); + return str_port_; } -char const * -Source_file::seek_str0 (int n) -{ - char const *new_str0 = c_str () + n; - if (n < 0) - new_str0 += length (); - if (contains (new_str0)) - pos_str0_ = new_str0; - else - error (quote_input (new_str0) + "seek past eof"); +/****************************************************************/ - return pos_str0_; -} +#include "ly-smobs.icc" -char const * -Source_file::forward_str0 (int n) +IMPLEMENT_SMOBS(Source_file); +IMPLEMENT_DEFAULT_EQUAL_P(Source_file); +IMPLEMENT_TYPE_P(Source_file, "ly:source-file?"); + +SCM +Source_file::mark_smob (SCM smob) { - char const *old_pos = pos_str0_; - char const *new_str0 = pos_str0_ + n; - if (contains (new_str0)) - pos_str0_ = new_str0; - else - error (quote_input (new_str0) + "forward past eof"); + Source_file *sc = (Source_file *) SCM_CELL_WORD_1 (smob); - return old_pos; + return sc->str_port_; } -string -Source_file::get_string (int n) -{ - string str = string ((char const *)forward_str0 (n), n); - return str; -} -SCM -Source_file::get_port () const +int +Source_file::print_smob (SCM smob, SCM port, scm_print_state *) { - return str_port_; + Source_file *sc = (Source_file *) SCM_CELL_WORD_1 (smob); + + scm_puts ("#name_.c_str (), port); + + /* Do not print properties, that is too much hassle. */ + scm_puts (" >", port); + return 1; } + diff --git a/lily/source.cc b/lily/source.cc index 002768038c..9d978d4fae 100644 --- a/lily/source.cc +++ b/lily/source.cc @@ -58,7 +58,10 @@ Sources::add (Source_file *sourcefile) Sources::~Sources () { - junk_pointers (sourcefiles_); + for (vsize i = 0; i < sourcefiles_.size (); i++) + { + sourcefiles_[i]->unprotect (); + } } Source_file * diff --git a/lily/staff-performer.cc b/lily/staff-performer.cc index b8facd2364..54a57b9451 100644 --- a/lily/staff-performer.cc +++ b/lily/staff-performer.cc @@ -64,7 +64,13 @@ Staff_performer::initialize () { audio_staff_ = new Audio_staff; name_ = new Audio_text (Audio_text::TRACK_NAME, context ()->id_string ()); - tempo_ = new Audio_tempo (get_tempo ()); + + Rational r = robust_scm2moment (get_property ("tempoWholesPerMinute"), + Moment (15,1)).main_part_; + + r *= Rational (4,1); + + tempo_ = new Audio_tempo (r.to_int ()); audio_staff_->add_audio_item (name_); audio_staff_->add_audio_item (tempo_); diff --git a/lily/tfm-reader.cc b/lily/tfm-reader.cc index b416301134..58e5b124d3 100644 --- a/lily/tfm-reader.cc +++ b/lily/tfm-reader.cc @@ -58,8 +58,12 @@ Tex_font_metric_reader::get_U32_fix_scaled () string Tex_font_metric_reader::get_bcpl_string () { - U8 length_u8 = input_.get_U8 (); + string str; + +#if 0 // FIXME. + U8 length_u8 = input_.get_U8 (); string str = input_.get_string (length_u8); +#endif return str; } @@ -131,8 +135,12 @@ Tex_font_metric_reader::read_params () //brrr /* Move to the beginning of the parameter table in the file. */ - input_.seek_str0 (-4 * header_.param_word_count); +#if 0 + // FIXME. + input_.seek_str0 (-4 * header_.param_word_count); +#endif + /* It's unlikely but possible that this TFM file has more fontdimens than we can deal with. */ if (header_.param_word_count > TFM_MAX_FONTDIMENS) @@ -181,10 +189,12 @@ Tex_font_metric_reader::read_char_metric (Char_code code) if (code < info_.first_charcode || code > info_.last_charcode) return tfm_char; +#if 0 // FIXME. //brr /* Move to the appropriate place in the `char_info' array. */ input_.seek_str0 (header_.char_info_pos + (code - info_.first_charcode) * 4); - +#endif + /* Read the character. */ tfm_char = read_char (); @@ -217,10 +227,11 @@ Tex_font_metric_reader::read_char () Tex_font_char_metric tfm_char; + // FIXME. #define GET_CHAR_DIMEN(d) \ if (d##_index != 0) \ { \ - input_.seek_str0 (header_.d##_pos + d##_index * 4); \ + /* input_.seek_str0 (header_.d##_pos + d##_index * 4);*/ \ tfm_char.d##_fix_ = input_.get_U32 (); \ tfm_char.d##_ = fix_to_real (tfm_char.d##_fix_) \ * info_.design_size; \ @@ -239,7 +250,9 @@ Tex_font_metric_reader::read_char () if (tag == 1) { +#if 0 // FIXME. input_.seek_str0 (header_.lig_kern_pos + remainder * 4); +#endif read_lig_kern_program (&tfm_char.ligatures_, &tfm_char.kerns_); } @@ -272,10 +285,15 @@ Tex_font_metric_reader::read_lig_kern_program (vector *ligatures, Tfm_kern kern_element; kern_element.character = next_char; +#if 0 char const *old_pos = input_.pos_str0 (); input_.seek_str0 (header_.kern_pos + remainder * 4); +#endif + kern_element.kern = get_U32_fix_scaled (); - input_.set_pos (old_pos); + + // FIXME + /// input_.set_pos (old_pos); kerns->push_back (kern_element); } diff --git a/python/convertrules.py b/python/convertrules.py index 3f10e386fb..4eed7ace8b 100644 --- a/python/convertrules.py +++ b/python/convertrules.py @@ -2834,8 +2834,8 @@ conversions.append (((2, 9, 13), conv, """instrument -> instrumentName, instr -> def conv (str): - m = re.search (r'\\tempo ([0-9]+)\s*([.]*)\s*=\s*([0-9]+)', str) - if m and re.search (r'\\midi', str): + + def sub_tempo (m): dur = int (m.group (1)) dots = len (m.group (2)) count = int (m.group (3)) @@ -2848,10 +2848,7 @@ def conv (str): den = (1 << dots) * (1 << log2) num = ((1 << (dots+1)) - 1) - error_file.write (r""" - -\tempo in \midi is no longer supported. Use - + return """ \midi { \context { \Score @@ -2859,8 +2856,9 @@ def conv (str): } } -""" % (num*count, den)) - +""" % (num*count, den) + + str = re.sub (r'\\midi\s*{\s*\\tempo ([0-9]+)\s*([.]*)\s*=\s*([0-9]+)\s*}', sub_tempo, str) return str conversions.append (((2, 9, 16), conv, """deprecate \\tempo in \\midi""")) -- 2.39.2