Class: Voix

Inherits:
Object
  • Object
show all
Defined in:
lib/rubySC/voix.rb

Overview

sorte de classe privée pour garder en mémoire ce qui se passe dans les ‘voix’…

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nom = nil, options = {}) ⇒ Voix

Returns a new instance of Voix.



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/rubySC/voix.rb', line 9

def initialize nom=nil, options={}

  @information=nil ## cette information sert juste à stocker tout ce
                   ## qui pourrait être utile, principalement dans
                   ## les Marches et autres transformations de
                   ## mélodie. Cette variable ne sert qu'à donner
                   ## une indication

  @name=nom
  if nom.nil?
    puts "choisis un nom"
    nomTmp=gets.chomp
    @name=nomTmp
  end

  SC.listeVoix[@name]=self

  self.setDuree options["dur"]

  if options[:degree].nil?
    then @degree=Array.new(rand(1..5)) do |x| x=rand(12) end
  else
    @degree=options[:degree]
  end

  if options["octave"].nil?
    then @octave=4
  else
    @octave=options["octave"]
  end

  if options["scale"].nil?
    then @scale = "major"
  else
    @scale=options["scale"]
  end
  if options["amp"].nil?
    then @amp = "Pwhite(0.2,0.8)"
  else
    @amp=options["amp"]
  end

  if options["instrument"].nil?
    then @instrument = "default"
  else
    @instrument=options["instrument"].to_s
  end

  self.setMarche options["marche"]
  SC.updateScore

end

Instance Attribute Details

#ampObject

Returns the value of attribute amp.



7
8
9
# File 'lib/rubySC/voix.rb', line 7

def amp
  @amp
end

#degreeObject

Returns the value of attribute degree.



7
8
9
# File 'lib/rubySC/voix.rb', line 7

def degree
  @degree
end

#durObject

Returns the value of attribute dur.



7
8
9
# File 'lib/rubySC/voix.rb', line 7

def dur
  @dur
end

#informationObject

Returns the value of attribute information.



7
8
9
# File 'lib/rubySC/voix.rb', line 7

def information
  @information
end

#instrumentObject

Returns the value of attribute instrument.



7
8
9
# File 'lib/rubySC/voix.rb', line 7

def instrument
  @instrument
end

#marcheObject

Returns the value of attribute marche.



7
8
9
# File 'lib/rubySC/voix.rb', line 7

def marche
  @marche
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/rubySC/voix.rb', line 7

def name
  @name
end

#octaveObject

Returns the value of attribute octave.



7
8
9
# File 'lib/rubySC/voix.rb', line 7

def octave
  @octave
end

#scaleObject

Returns the value of attribute scale.



7
8
9
# File 'lib/rubySC/voix.rb', line 7

def scale
  @scale
end

Instance Method Details

#playObject



124
125
126
127
128
# File 'lib/rubySC/voix.rb', line 124

def play
  SC.play @name
  @information="en train de jouer".colorize (:blue)

end

#set(options) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/rubySC/voix.rb', line 62

def set options
  options.each do |key, value|
    if value.is_a? Symbol
      value=value.to_s
    end
    case key
    when "dur"
      self.setDuree value
    when "marche"
      self.setMarche value
    else
      self.instance_variable_set "@#{key}", value
    end
  end
  SC.updateScore
end

#setDuree(duree) ⇒ Object



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
# File 'lib/rubySC/voix.rb', line 87

def setDuree (duree)

 if duree.nil?
    then @dur=[4, [1]] ## valeur de base, tout en ronde, cantus
                       ## firmus style, io!
  else
    if duree.is_a? Array
      if duree.length == 2 and duree[1].is_a? Array
        then
        @dur=duree ## quelqu'un a fait un vrai objet en RTM notation
      else
        tmp = true
        duree.each {
          |x|
          unless x.is_a? Fixnum
            tmp = false
          end
        }
        if tmp then
          @dur = [4, duree]  ## on a juste mis un rythme pour la
                             ## durée d'une mesure
        else
          begin
            raise ArgumentError
          rescue "mauvais argument pour la durée"
          end
        end
      end
    end
  end
end

#setMarche(intervalles) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/rubySC/voix.rb', line 79

def setMarche intervalles
  if intervalles.nil?
    @root=0
  else
    @root="Pstutter(#{self.degree.size}, Pseq(#{intervalles}, inf))"
  end
end

#stopObject



119
120
121
122
# File 'lib/rubySC/voix.rb', line 119

def stop
  SC.stop @name
  @information=nil
end