Class: Musicality::Link

Inherits:
Object
  • Object
show all
Includes:
Packable
Defined in:
lib/musicality/notation/model/link.rb

Overview

Connect one note pitch to the target pitch of the next note, via slur, legato, etc.

Direct Known Subclasses

TargetedLink, Tie

Defined Under Namespace

Classes: Glissando, Portamento, TargetedLink, Tie

Constant Summary

Constants included from Packable

Packable::PACKED_CLASS_KEY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Packable

#class_str, included, #init_params, #pack, pack_val, recover_class, unpack_val

Instance Attribute Details

#target_pitchPitch

Returns The pitch of the note which is being connected to.

Returns:

  • (Pitch)

    The pitch of the note which is being connected to.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/musicality/notation/model/link.rb', line 8

class Link
  include Packable
  
  def clone
    Marshal.load(Marshal.dump(self))
  end

  def transpose diff
    self.clone.transpose! diff
  end
  
  def transpose! diff
    return self
  end

  def ==(other)
    self.class == other.class
  end

  def to_s
    LINK_SYMBOLS[self.class]
  end

  class Tie < Link; end

  class TargetedLink < Link
    attr_accessor :target_pitch
    
    def initialize target_pitch
      @target_pitch = target_pitch
    end
    
    def ==(other)
      super && @target_pitch == other.target_pitch
    end
    
    def transpose diff
      self.clone.transpose! diff
    end
    
    def transpose! diff
      @target_pitch = @target_pitch.transpose(diff)
      return self
    end
    
    def to_s
      super + @target_pitch.to_s
    end
  end
  
  class Glissando < TargetedLink; end
  class Portamento < TargetedLink; end
end

Instance Method Details

#==(other) ⇒ Object



23
24
25
# File 'lib/musicality/notation/model/link.rb', line 23

def ==(other)
  self.class == other.class
end

#cloneObject



11
12
13
# File 'lib/musicality/notation/model/link.rb', line 11

def clone
  Marshal.load(Marshal.dump(self))
end

#to_sObject



27
28
29
# File 'lib/musicality/notation/model/link.rb', line 27

def to_s
  LINK_SYMBOLS[self.class]
end

#transpose(diff) ⇒ Object



15
16
17
# File 'lib/musicality/notation/model/link.rb', line 15

def transpose diff
  self.clone.transpose! diff
end

#transpose!(diff) ⇒ Object



19
20
21
# File 'lib/musicality/notation/model/link.rb', line 19

def transpose! diff
  return self
end