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

« back to all changes in this revision

Viewing changes to lily/arpeggio.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
2
  arpeggio.cc -- implement Arpeggio
3
3
 
4
4
  source file of the GNU LilyPond music typesetter
5
 
  
6
 
  (c) 2000--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7
 
 */
8
 
 
9
 
#include "stencil.hh"
10
 
#include "paper-def.hh"
 
5
 
 
6
  (c) 2000--2006 Jan Nieuwenhuizen <janneke@gnu.org>
 
7
*/
 
8
 
11
9
#include "arpeggio.hh"
12
 
#include "grob.hh"
 
10
 
 
11
#include "output-def.hh"
13
12
#include "stem.hh"
14
13
#include "staff-symbol-referencer.hh"
15
14
#include "staff-symbol.hh"
16
15
#include "warn.hh"
17
16
#include "font-interface.hh"
18
17
#include "lookup.hh"
19
 
 
 
18
#include "pointer-group-interface.hh"
20
19
 
21
20
MAKE_SCHEME_CALLBACK (Arpeggio, print, 1);
22
 
SCM 
23
 
Arpeggio::print (SCM smob) 
 
21
SCM
 
22
Arpeggio::print (SCM smob)
24
23
{
25
24
  Grob *me = unsmob_grob (smob);
26
 
  
27
 
  Grob * common = me;
28
 
  for (SCM s = me->get_property ("stems"); gh_pair_p (s); s = ly_cdr (s))
 
25
 
 
26
  Grob *common = me;
 
27
 
 
28
  extract_grob_set (me, "stems", stems);
 
29
  for (vsize i = 0; i < stems.size (); i++)
29
30
    {
30
 
      Grob * stem =  unsmob_grob (ly_car (s));
31
 
      common =  common->common_refpoint (Staff_symbol_referencer::get_staff_symbol (stem),
32
 
                                 Y_AXIS);
 
31
      Grob *stem = stems[i];
 
32
      common = common->common_refpoint (Staff_symbol_referencer::get_staff_symbol (stem),
 
33
                                        Y_AXIS);
33
34
    }
34
35
 
35
36
  /*
36
37
    TODO:
37
 
    
 
38
 
38
39
    Using stems here is not very convenient; should store noteheads
39
40
    instead, and also put them into the support. Now we will mess up
40
41
    in vicinity of a collision.
42
43
  */
43
44
  Interval heads;
44
45
  Real my_y = me->relative_coordinate (common, Y_AXIS);
45
 
      
46
 
  for (SCM s = me->get_property ("stems"); gh_pair_p (s); s = ly_cdr (s))
 
46
 
 
47
  for (vsize i = 0; i < stems.size (); i++)
47
48
    {
48
 
      Grob * stem = unsmob_grob (ly_car (s));
49
 
      Grob * ss = Staff_symbol_referencer::get_staff_symbol (stem);
50
 
      Interval iv =Stem::head_positions (stem);
51
 
      iv *= Staff_symbol::staff_space (ss)/2.0;
52
 
      
 
49
      Grob *stem = stems[i];
 
50
      Grob *ss = Staff_symbol_referencer::get_staff_symbol (stem);
 
51
      Interval iv = Stem::head_positions (stem);
 
52
      iv *= Staff_symbol::staff_space (ss) / 2.0;
 
53
 
53
54
      heads.unite (iv + ss->relative_coordinate (common, Y_AXIS)
54
55
                   - my_y);
55
56
    }
56
57
 
57
 
  if (heads.is_empty ())
 
58
  if (heads.is_empty () || heads.length () < 0.5)
58
59
    {
59
 
      /*
60
 
        Dumb blonde error
61
 
 
62
 
        :-)
63
 
       */
64
 
      programming_error ("Huh, no heads for arpeggio found.");
 
60
      programming_error ("no heads for arpeggio found?");
 
61
      me->suicide ();
65
62
      return SCM_EOL;
66
63
    }
67
64
 
68
65
  SCM ad = me->get_property ("arpeggio-direction");
69
66
  Direction dir = CENTER;
70
67
  if (is_direction (ad))
71
 
    {
72
 
      dir = to_dir (ad);
73
 
    }
74
 
  
 
68
    dir = to_dir (ad);
 
69
 
75
70
  Stencil mol;
76
 
  Font_metric *fm =Font_interface::get_default_font (me);
77
 
  Stencil squiggle = fm->find_by_name ("scripts-arpeggio");
 
71
  Font_metric *fm = Font_interface::get_default_font (me);
 
72
  Stencil squiggle = fm->find_by_name ("scripts.arpeggio");
78
73
 
79
 
  Stencil arrow ;  
 
74
  Stencil arrow;
80
75
  if (dir)
81
76
    {
82
 
      arrow = fm->find_by_name ("scripts-arpeggio-arrow-" + to_string (dir));
 
77
      arrow = fm->find_by_name ("scripts.arpeggio.arrow." + to_string (dir));
83
78
      heads[dir] -= dir * arrow.extent (Y_AXIS).length ();
84
79
    }
85
 
  
86
 
  for (Real  y= heads[LEFT] ; y < heads[RIGHT];
87
 
       y+= squiggle. extent (Y_AXIS).length ())
88
 
      mol.add_at_edge (Y_AXIS, UP,squiggle, 0.0, 0);
 
80
 
 
81
  for (Real y = heads[LEFT]; y < heads[RIGHT];
 
82
       y += squiggle.extent (Y_AXIS).length ())
 
83
    mol.add_at_edge (Y_AXIS, UP, squiggle, 0.0, 0);
89
84
 
90
85
  mol.translate_axis (heads[LEFT], Y_AXIS);
91
86
  if (dir)
92
 
    mol.add_at_edge (Y_AXIS, dir,arrow, 0,0);
93
 
  
94
 
  return mol.smobbed_copy () ;
 
87
    mol.add_at_edge (Y_AXIS, dir, arrow, 0, 0);
 
88
 
 
89
  return mol.smobbed_copy ();
95
90
}
96
91
 
97
 
/* Draws a vertical bracket to the left of a chord 
 
92
/* Draws a vertical bracket to the left of a chord
98
93
   Chris Jackson <chris@fluffhouse.org.uk> */
99
94
 
100
95
MAKE_SCHEME_CALLBACK (Arpeggio, brew_chord_bracket, 1);
101
 
SCM 
102
 
Arpeggio::brew_chord_bracket (SCM smob) 
 
96
SCM
 
97
Arpeggio::brew_chord_bracket (SCM smob)
103
98
{
104
99
  Grob *me = unsmob_grob (smob);
105
 
  
106
 
  Grob * common = me;
107
 
  for (SCM s = me->get_property ("stems"); gh_pair_p (s); s = ly_cdr (s))
 
100
  Grob *common = me;
 
101
 
 
102
  extract_grob_set (me, "stems", stems);
 
103
  for (vsize i = 0; i < stems.size (); i++)
108
104
    {
109
 
      Grob * stem =  unsmob_grob (ly_car (s));
110
 
      common =  common->common_refpoint (Staff_symbol_referencer::get_staff_symbol (stem),
111
 
                                 Y_AXIS);
 
105
      Grob *stem = stems[i];
 
106
      common = common->common_refpoint (Staff_symbol_referencer::get_staff_symbol (stem),
 
107
                                        Y_AXIS);
112
108
    }
113
109
 
114
110
  Interval heads;
115
111
  Real my_y = me->relative_coordinate (common, Y_AXIS);
116
 
      
117
 
  for (SCM s = me->get_property ("stems"); gh_pair_p (s); s = ly_cdr (s))
 
112
 
 
113
  for (vsize i = 0; i < stems.size (); i++)
118
114
    {
119
 
      Grob * stem = unsmob_grob (ly_car (s));
120
 
      Grob * ss = Staff_symbol_referencer::get_staff_symbol (stem);
 
115
      Grob *stem = stems[i];
 
116
      Grob *ss = Staff_symbol_referencer::get_staff_symbol (stem);
121
117
      Interval iv = Stem::head_positions (stem);
122
 
      iv *= Staff_symbol::staff_space (ss)/2.0;      
123
 
      heads.unite (iv  +  ss->relative_coordinate (common, Y_AXIS)  -  my_y);
 
118
      iv *= Staff_symbol::staff_space (ss) / 2.0;
 
119
      heads.unite (iv + ss->relative_coordinate (common, Y_AXIS) - my_y);
124
120
    }
125
121
 
126
 
  Real lt =  me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness"));
 
122
  Real lt = me->layout ()->get_dimension (ly_symbol2scm ("line-thickness"));
127
123
  Real sp = 1.5 * Staff_symbol_referencer::staff_space (me);
128
124
  Real dy = heads.length () + sp;
129
125
  Real x = 0.7;
130
126
 
131
127
  Stencil mol (Lookup::bracket (Y_AXIS, Interval (0, dy), lt, x, lt));
132
 
  mol.translate_axis (heads[LEFT] - sp/2.0, Y_AXIS);
 
128
  mol.translate_axis (heads[LEFT] - sp / 2.0, Y_AXIS);
133
129
  return mol.smobbed_copy ();
134
130
}
135
131
 
136
 
 
137
132
/*
138
133
  We have to do a callback, because print () triggers a
139
134
  vertical alignment if it is cross-staff.
140
135
*/
141
 
MAKE_SCHEME_CALLBACK (Arpeggio, width_callback,2);
 
136
MAKE_SCHEME_CALLBACK (Arpeggio, width, 1);
142
137
SCM
143
 
Arpeggio::width_callback (SCM smob, SCM axis)
 
138
Arpeggio::width (SCM smob)
144
139
{
145
 
  Grob * me = unsmob_grob (smob);
146
 
  Axis a = (Axis)gh_scm2int (axis);
147
 
  assert (a == X_AXIS);
148
 
  Stencil arpeggio = Font_interface::get_default_font (me)->find_by_name ("scripts-arpeggio");
 
140
  Grob *me = unsmob_grob (smob);
 
141
  Stencil arpeggio = Font_interface::get_default_font (me)->find_by_name ("scripts.arpeggio");
149
142
 
150
143
  return ly_interval2scm (arpeggio.extent (X_AXIS));
151
144
}
152
145
 
153
 
 
154
146
ADD_INTERFACE (Arpeggio, "arpeggio-interface",
155
 
  "Functions and settings for drawing an arpeggio symbol (a wavy line left to noteheads.",
156
 
  "stems arpeggio-direction");
 
147
               "Functions and settings for drawing an arpeggio symbol (a wavy line left to noteheads.",
 
148
 
 
149
               /* properties */
 
150
               "arpeggio-direction "
 
151
               "stems "
 
152
               );
157
153