Class: Music::Transcription::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/music-transcription/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, Legato, Portamento, Slur, TargetedLink, Tie

Instance Attribute Summary collapse

Instance Method Summary collapse

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.



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
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/music-transcription/model/link.rb', line 9

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

  class Tie < Link
    def initialize; end
    
    def ==(other)
      self.class == other.class
    end
    
    def transpose diff
      self.clone.transpose! diff
    end
    
    def transpose! diff
      return self
    end
    
    def to_s; "="; end
  end
  
  class TargetedLink < Link
    attr_accessor :target_pitch
    
    def initialize target_pitch
      @target_pitch = target_pitch
    end
    
    def ==(other)
      self.class == other.class && @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
      link_char + @target_pitch.to_s
    end
  end
  
  class Glissando < TargetedLink
    def link_char; "~"; end
  end
  
  class Portamento < TargetedLink
    def link_char; "/"; end
  end
  
  class Slur < TargetedLink
    def link_char; "="; end
  end
  
  class Legato < TargetedLink
    def link_char; "|"; end
  end
end

Instance Method Details

#cloneObject



10
11
12
# File 'lib/music-transcription/model/link.rb', line 10

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