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
61
62
63
64
65
66
67
68
69
70
71
72
# 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

  @information="en pause \n"
  self.setDuree options[:dur]

  @adsr=[]
  if options[:adsr].nil?
    then self.setADSR 0.2,1,0.9,0.4
    else  
    selfADSR options[:adsr]      
  end

  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"
    p "pan!"
  else
   self.setInstrument options[:instrument]
  end

  if options[:dur]
    self.setDuree options[:dur]
  end

  SC.updateScore

end

Instance Attribute Details

#adsrObject (readonly)

Returns the value of attribute adsr.



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

def adsr
  @adsr
end

#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 (readonly)

Returns the value of attribute dur.



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

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



142
143
144
145
146
# File 'lib/rubySC/voix.rb', line 142

def play
  SC.updateScore
  SC.play @name
  @information="en train de jouer"
end

#setADSR(atk, dec, sus, rel) ⇒ Object



75
76
77
78
79
80
# File 'lib/rubySC/voix.rb', line 75

def setADSR atk, dec, sus, rel

  @adsr=[(atk/1.0), (dec/1.0), (sus/1.0), (rel/1.0)]
  SC.updateScore

end

#setDuree(duree) ⇒ Object

def setMarche intervalles

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

end



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
128
129
130
131
132
133
134
135
# File 'lib/rubySC/voix.rb', line 103

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

  SC.updateScore
end

#setInstrument(instrument) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/rubySC/voix.rb', line 82

def setInstrument instrument

  if instrument.is_a? Symbol  
  @information = "le sample utilisé actuellement est #{instrument} \n"
  SC.sample instrument.to_s
  @instrument="sampler"
  else
  @instrument=instrument
  end 

end

#stopObject



137
138
139
140
# File 'lib/rubySC/voix.rb', line 137

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