~ubuntu-branches/ubuntu/precise/lilypond/precise

« back to all changes in this revision

Viewing changes to lily/tab-note-heads-engraver.cc

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Bushnell, BSG
  • Date: 2006-12-19 10:18:12 UTC
  • mfrom: (3.1.4 feisty)
  • Revision ID: james.westby@ubuntu.com-20061219101812-7awtjkp0i393wxty
Tags: 2.8.7-3
scripts/midi2ly.py: When setting DATADIR, find Lilypond python files
in the @TOPLEVEL_VERSION@ directory, not 'current'.  Patch thanks to
Chris Lamb (chris@chris-lamb.co.uk).  (Closes: #400550)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
  head-grav.cc -- part of GNU LilyPond
3
 
 
4
 
  (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 
2
  tab-note-heads-engraver.cc -- part of GNU LilyPond
 
3
 
 
4
  based on note-heads-engraver.cc, by Jean-Baptiste Lamy <jiba@tuxfamily.org>,
 
5
 
 
6
  (c) 2002--2006
5
7
*/
6
 
#include <ctype.h>
7
 
#include <stdio.h>
 
8
 
 
9
#include <cctype>
 
10
#include <cstdio>
 
11
using namespace std;
8
12
 
9
13
#include "rhythmic-head.hh"
10
 
#include "paper-def.hh"
11
 
#include "event.hh"
 
14
#include "output-def.hh"
 
15
#include "music.hh"
12
16
#include "dots.hh"
13
17
#include "dot-column.hh"
14
18
#include "staff-symbol-referencer.hh"
15
19
#include "item.hh"
16
20
#include "score-engraver.hh"
17
21
#include "warn.hh"
 
22
#include "duration.hh"
18
23
 
19
24
/**
20
25
   make (guitar-like) tablature note
21
26
*/
22
27
class Tab_note_heads_engraver : public Engraver
23
28
{
24
 
  Link_array<Item> notes_;
25
 
  
26
 
  Link_array<Item> dots_;
27
 
  Link_array<Music> note_events_;
28
 
  Link_array<Music> tabstring_events_;
 
29
  vector<Item*> notes_;
 
30
 
 
31
  vector<Item*> dots_;
 
32
  vector<Music*> note_events_;
 
33
  vector<Music*> tabstring_events_;
29
34
public:
30
35
  TRANSLATOR_DECLARATIONS (Tab_note_heads_engraver);
31
36
 
32
37
protected:
33
 
  virtual bool try_music (Music *event) ;
34
 
  virtual void process_music ();
 
38
  virtual bool try_music (Music *event);
 
39
  void process_music ();
35
40
 
36
 
  virtual void stop_translation_timestep ();
 
41
  void stop_translation_timestep ();
37
42
};
38
43
 
39
 
 
40
44
Tab_note_heads_engraver::Tab_note_heads_engraver ()
41
45
{
42
46
}
43
47
 
44
48
bool
45
 
Tab_note_heads_engraver::try_music (Music *m) 
 
49
Tab_note_heads_engraver::try_music (Music *m)
46
50
{
47
51
  if (m->is_mus_type ("note-event"))
48
52
    {
49
 
      note_events_.push (m);
 
53
      note_events_.push_back (m);
50
54
      return true;
51
55
    }
52
56
  else if (m->is_mus_type ("string-number-event"))
53
57
    {
54
 
      tabstring_events_.push (m);
 
58
      tabstring_events_.push_back (m);
55
59
      return true;
56
60
    }
57
61
  else if (m->is_mus_type ("busy-playing-event"))
58
 
    {
59
 
      return note_events_.size ();
60
 
    }
61
 
  
 
62
    return note_events_.size ();
 
63
 
62
64
  return false;
63
65
}
64
66
 
65
 
 
66
67
void
67
68
Tab_note_heads_engraver::process_music ()
68
69
{
69
 
  int j = 0; 
70
 
  for (int i=0; i < note_events_.size (); i++)
 
70
  vsize j = 0;
 
71
  for (vsize i = 0; i < note_events_.size (); i++)
71
72
    {
72
73
      SCM stringTunings = get_property ("stringTunings");
73
 
      int number_of_strings = ((int) gh_length (stringTunings));
 
74
      int number_of_strings = ((int) ly_length (stringTunings));
74
75
      bool high_string_one = to_boolean (get_property ("highStringOne"));
75
76
 
76
 
      Item * note  = make_item ("TabNoteHead");
77
 
      
78
 
      Music * event = note_events_[i];
79
 
 
80
 
      
81
 
      Music * tabstring_event=0;
82
 
 
83
 
      for (SCM s =event->get_property ("articulations");
84
 
           !tabstring_event && gh_pair_p (s); s = gh_cdr (s))
 
77
      Music *event = note_events_[i];
 
78
      Item *note = make_item ("TabNoteHead", event->self_scm ());
 
79
 
 
80
      Music *tabstring_event = 0;
 
81
 
 
82
      for (SCM s = event->get_property ("articulations");
 
83
           !tabstring_event && scm_is_pair (s); s = scm_cdr (s))
85
84
        {
86
 
          Music * art = unsmob_music (gh_car (s));
 
85
          Music *art = unsmob_music (scm_car (s));
87
86
 
88
87
          if (art->is_mus_type ("string-number-event"))
89
88
            tabstring_event = art;
90
89
        }
91
90
 
92
 
      if (!tabstring_event  && j < tabstring_events_.size ())
 
91
      if (!tabstring_event && j < tabstring_events_.size ())
93
92
        {
94
93
          tabstring_event = tabstring_events_[j];
95
 
          if (j +1 <  tabstring_events_.size ())
 
94
          if (j + 1 < tabstring_events_.size ())
96
95
            j++;
97
96
        }
98
97
 
100
99
      bool string_found;
101
100
      if (tabstring_event)
102
101
        {
103
 
          tab_string = gh_scm2int (tabstring_event->get_property ("string-number"));
 
102
          tab_string = scm_to_int (tabstring_event->get_property ("string-number"));
104
103
          string_found = true;
105
104
        }
106
105
      else
108
107
          tab_string = high_string_one ? 1 : number_of_strings;
109
108
          string_found = false;
110
109
        }
111
 
      
 
110
 
112
111
      Duration dur = *unsmob_duration (event->get_property ("duration"));
113
112
      note->set_property ("duration-log",
114
 
                               gh_int2scm (dur.duration_log ()));
 
113
                          scm_from_int (dur.duration_log ()));
115
114
 
116
115
      if (dur.dot_count ())
117
116
        {
118
 
          Item * d = make_item ("Dots");
 
117
          Item *d = make_item ("Dots", event->self_scm ());
119
118
          Rhythmic_head::set_dots (note, d);
120
 
          
 
119
 
121
120
          if (dur.dot_count ()
122
 
              != gh_scm2int (d->get_property ("dot-count")))
123
 
            d->set_property ("dot-count", gh_int2scm (dur.dot_count ()));
 
121
              != scm_to_int (d->get_property ("dot-count")))
 
122
            d->set_property ("dot-count", scm_from_int (dur.dot_count ()));
124
123
 
125
124
          d->set_parent (note, Y_AXIS);
126
 
          announce_grob (d, SCM_EOL);
127
 
          dots_.push (d);
 
125
 
 
126
          dots_.push_back (d);
128
127
        }
129
 
      
130
 
      
 
128
 
131
129
      SCM scm_pitch = event->get_property ("pitch");
132
 
      SCM proc      = get_property ("tablatureFormat");
 
130
      SCM proc = get_property ("tablatureFormat");
133
131
      SCM min_fret_scm = get_property ("minimumFret");
134
 
      int min_fret = gh_number_p (min_fret_scm) ? gh_scm2int (min_fret_scm) : 0;
 
132
      int min_fret = scm_is_number (min_fret_scm) ? scm_to_int (min_fret_scm) : 0;
135
133
 
136
134
      while (!string_found)
137
135
        {
138
136
          int fret = unsmob_pitch (scm_pitch)->semitone_pitch ()
139
 
            - gh_scm2int (gh_list_ref (stringTunings,gh_int2scm (tab_string-1)));
140
 
          if (fret<min_fret)
 
137
            - scm_to_int (scm_list_ref (stringTunings, scm_from_int (tab_string - 1)));
 
138
          if (fret < min_fret)
141
139
            tab_string += high_string_one ? 1 : -1;
142
140
          else
143
141
            string_found = true;
144
142
        }
145
143
 
146
 
      SCM text = gh_call3 (proc, gh_int2scm (tab_string), stringTunings, scm_pitch);
 
144
      SCM text = scm_call_3 (proc, scm_from_int (tab_string), stringTunings, scm_pitch);
147
145
 
148
146
      int pos = 2 * tab_string - number_of_strings - 1; // No tab-note between the string !!!
149
147
      if (to_boolean (get_property ("stringOneTopmost")))
150
148
        pos = -pos;
151
 
      
152
 
      note->set_property ("text", text);      
153
 
      
154
 
      note->set_property ("staff-position", gh_int2scm (pos));
155
 
      announce_grob (note, event->self_scm ());
156
 
      notes_.push (note);
 
149
 
 
150
      note->set_property ("text", text);
 
151
 
 
152
      note->set_property ("staff-position", scm_from_int (pos));
 
153
      notes_.push_back (note);
157
154
    }
158
155
}
159
156
 
160
157
void
161
158
Tab_note_heads_engraver::stop_translation_timestep ()
162
159
{
163
 
  for (int i=0; i < notes_.size (); i++)
164
 
    {
165
 
      typeset_grob (notes_[i]);
166
 
    }
167
 
 
168
160
  notes_.clear ();
169
 
  for (int i=0; i < dots_.size (); i++)
170
 
    {
171
 
      typeset_grob (dots_[i]);
172
 
    }
173
 
  
174
161
  dots_.clear ();
175
162
  note_events_.clear ();
176
163
  tabstring_events_.clear ();
177
164
}
178
165
 
 
166
#include "translator.icc"
179
167
 
180
 
ENTER_DESCRIPTION (Tab_note_heads_engraver,
181
 
/* descr */       "Generate one or more tablature noteheads from Music of type NoteEvent.",
182
 
/* creats*/       "TabNoteHead Dots",
183
 
/* accepts */     "note-event string-number-event busy-playing-event",
184
 
/* acks  */      "",
185
 
/* reads */       "middleCPosition stringTunings minimumFret tablatureFormat highStringOne stringOneTopmost",
186
 
/* write */       "");
 
168
ADD_TRANSLATOR (Tab_note_heads_engraver,
 
169
                /* doc */ "Generate one or more tablature noteheads from Music of type NoteEvent.",
 
170
                /* create */ "TabNoteHead Dots",
 
171
                /* accept */ "note-event string-number-event busy-playing-event",
 
172
                /* read */ "middleCPosition stringTunings minimumFret tablatureFormat highStringOne stringOneTopmost",
 
173
                /* write */ "");
187
174