Class: Kadryll::Drill

Inherits:
Object
  • Object
show all
Defined in:
lib/kadryll/drill.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, time, measures, options = {}) ⇒ Drill

Returns a new instance of Drill.



23
24
25
26
27
# File 'lib/kadryll/drill.rb', line 23

def initialize(name, time, measures, options = {})
  self.name = build_name(name, options[:prefix])
  self.time = time
  self.right_hand, self.left_hand, self.right_foot, self.left_foot = measures
end

Instance Attribute Details

#left_footObject

Returns the value of attribute left_foot.



22
23
24
# File 'lib/kadryll/drill.rb', line 22

def left_foot
  @left_foot
end

#left_handObject

Returns the value of attribute left_hand.



22
23
24
# File 'lib/kadryll/drill.rb', line 22

def left_hand
  @left_hand
end

#nameObject

Returns the value of attribute name.



22
23
24
# File 'lib/kadryll/drill.rb', line 22

def name
  @name
end

#right_footObject

Returns the value of attribute right_foot.



22
23
24
# File 'lib/kadryll/drill.rb', line 22

def right_foot
  @right_foot
end

#right_handObject

Returns the value of attribute right_hand.



22
23
24
# File 'lib/kadryll/drill.rb', line 22

def right_hand
  @right_hand
end

#timeObject

Returns the value of attribute time.



22
23
24
# File 'lib/kadryll/drill.rb', line 22

def time
  @time
end

Class Method Details

.from_string(template, options = {}) ⇒ Object



9
10
11
12
13
# File 'lib/kadryll/drill.rb', line 9

def from_string(template, options = {})
  drill = parse template, options
  drill.write
  drill
end

.lilypond_file(name) ⇒ Object



5
6
7
# File 'lib/kadryll/drill.rb', line 5

def lilypond_file(name)
  "#{Kadryll.input_dir}#{name}.ly"
end

.parse(template, options = {}) ⇒ Object



15
16
17
18
19
# File 'lib/kadryll/drill.rb', line 15

def parse(template, options = {})
  data, *measures = template.split("\n").map(&:strip)
  name, time = data.split(" ")
  new(name, time, measures, options)
end

Instance Method Details

#commandObject



29
30
31
# File 'lib/kadryll/drill.rb', line 29

def command
  "lilypond --png --output=#{output_to} #{lilypond_file}"
end

#generate_pngObject



33
34
35
36
# File 'lib/kadryll/drill.rb', line 33

def generate_png
  system(command)
  "#{output_to}.png"
end

#lilypond_fileObject



49
50
51
# File 'lib/kadryll/drill.rb', line 49

def lilypond_file
  Drill.lilypond_file(name)
end

#output_toObject



38
39
40
# File 'lib/kadryll/drill.rb', line 38

def output_to
  "#{Kadryll.output_dir}#{name}"
end

#templateObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/kadryll/drill.rb', line 53

def template
  <<-DRILL.gsub(/^\ {6}/, '')
  \\version "2.14.2"

  \\header {
    tagline = \\markup {
      \\fill-line {
        \\line { \\null }
        \\line { \\null }
        \\line { \\tiny \\with-color #(x11-color 'gray80) { #{Kadryll.copyright} \\char ##x00A9 } }

      }
    }
  }

  #(set! paper-alist (cons '("drill" . (cons (* 190 mm) (* 80 mm))) paper-alist))
  \\paper {
    #(set-paper-size "drill")
    #(define top-margin (* 7 mm))
    #(define line-width (* 140 mm))
  }

  signature = \\time #{time}

  rh = \\drummode { #{right_hand} }
  lh = \\drummode { #{left_hand} }
  rf = \\drummode { #{right_foot} }
  lf = \\drummode { #{left_foot} }

  #(define quake '((tamtam default #t 0)))
  quakestaff = {
    \\override DrumStaff.StaffSymbol #'line-positions = #'( 0 )
    \\override DrumStaff.BarLine #'bar-extent = #'(-1 . 1.5)
    \\override DrumStaff.InstrumentName #'self-alignment-X = #LEFT
    \\set DrumStaff.drumStyleTable = #(alist->hash-table quake)
    \\set fontSize = #-2
    \\signature
    \\override DrumStaff.Rest #'staff-position = #0
  }

  <<
  \\new DrumStaff {
    \\quakestaff
    \\set DrumStaff.instrumentName = "Right Hand "
    \\override Stem #'direction = #UP
    \\rh | \\rh | \\rh | \\rh |
  }
  \\new DrumStaff {
    \\quakestaff
    \\set DrumStaff.instrumentName = \\markup \\left-column {
      "Left Hand "
    }
    \\override Stem #'direction = #DOWN
    \\lh | \\lh | \\lh | \\lh |
  }
  \\new DrumStaff {
    \\quakestaff
    \\set DrumStaff.instrumentName = \\markup \\left-column {
      "Right Foot "
    }
    \\override Stem #'direction = #UP
    \\rf | \\rf | \\rf | \\rf |
  }
  \\new DrumStaff {
    \\quakestaff
    \\set DrumStaff.instrumentName = \\markup \\left-column {
      "Left Foot "
    }
    \\override Stem #'direction = #DOWN
    \\lf | \\lf | \\lf | \\lf |
  }
  >>

  DRILL
end

#writeObject



42
43
44
45
46
47
# File 'lib/kadryll/drill.rb', line 42

def write
  Kadryll.initialize
  File.open(lilypond_file, 'w') do |file|
    file.write template
  end
end