Top Level Namespace

Includes:
ObjectSpace

Defined Under Namespace

Modules: Echelle, Marche, Partition, RubySC, RubySC_CONST, Rythme, SoundFile Classes: Melodie, SC, Voix

Instance Method Summary collapse

Instance Method Details

#bicinium(consonances = [-2,2]) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rubySC/contrepoint.rb', line 33

def bicinium consonances=[-2,2]

a = Voix.new "cantusFirmus"
b = Voix.new "organum"

a.degree=creerMelodie
a.play ; b.play

l= lambda { |x, y|
tmp=harmoniser x.degree, consonances
y.set ({ "degree"=> tmp })
}

Thread.new do
20.times do
l.call a, b
sleep 2
l.call b, a
end
end


end

#consonnancesPossibles(consonnances, noteM, noteH, ecartMax) ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/rubySC/contrepoint.rb', line 1

def consonnancesPossibles consonnances, noteM, noteH, ecartMax

tmp=consonnances.reject	{|x|
((noteM+x) - noteH).abs > ecartMax
} 

if tmp==[] then
	p "attention écart à la règle !"
	tmp=consonnancesPossibles consonnances, noteM, noteH, ecartMax+1
end	

return tmp
end

#creerMelodie(nbNote = rand(10..30)) ⇒ Object



23
24
25
26
27
28
# File 'lib/rubySC/melodie/melodie.rb', line 23

def creerMelodie nbNote=rand(10..30)

  Array.new (nbNote) do |note|
    note=[0,0,1,1,2,3,3,3,3,4,4,4,4,5,6].sample   #manière un peu bourrine de "pondérer" les notes possibles
  end
end

#creerRythme(melodie = nil) ⇒ Object

analyse



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/rubySC/melodie/melodie.rb', line 158

def creerRythme melodie=nil  #analyse

  if melodie.nil?
  return  RubySC_CONST::Rythmes.sample
  end

  rythme = intervallesMel melodie
  rythme.map! { |inter|
    case inter.abs
      when 1
      note = 1

    else
      note=2
    end
  }
  rythme << 4

end

#deuxVoixObject



1
2
3
4
5
6
7
8
9
10
# File 'lib/rubySC/helper.rb', line 1

def deuxVoix

	a=Voix.new "voixUne", ({"degree"=> creerMelodie, "instrument" => "sax"})
	b=Voix.new "voixDeux"
	b.degree = harmoniser a.degree

	SC.updateScore
	SC.play

end

#harmoniser(melodie, consonnances = [0,2,4,5], ecartMax = 2) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rubySC/contrepoint.rb', line 16

def harmoniser melodie, consonnances=[0,2,4,5], ecartMax=2

	harmo=Array.new (melodie.size) 
	harmo[0]=melodie[0]+consonnances.sample
	harmo[1..-1].map.with_index(1) {  |a,i| 		
		harmo[i]=melodie[i]+(consonnancesPossibles consonnances, melodie[i], harmo[i-1], ecartMax).sample 
	}

	p "mel = #{melodie}"
	p "harmo = #{harmo}"

	return	harmo
	
end

#intervallesAbs(melodie) ⇒ Object



20
21
22
23
24
# File 'lib/rubySC/melodie/algos.rb', line 20

def intervallesAbs melodie

	(intervallesMel melodie).map { :abs  }
	
end

#intervallesBoucle(melodie) ⇒ Object



14
15
16
17
18
# File 'lib/rubySC/melodie/algos.rb', line 14

def intervallesBoucle melodie

	intervallesMel melodie << melodie[0]-melodie[-1]
	
end

#intervallesMel(melodie) ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
# File 'lib/rubySC/melodie/algos.rb', line 1

def intervallesMel melodie

  tmp=melodie.each_with_index.map{ |a, i|
    if melodie[i+1]
    then melodie[i+1]-a
    end
    }

  	tmp[0..-2]


end

#intervallesRel(melodie, note = 0) ⇒ Object



26
27
28
29
30
31
# File 'lib/rubySC/melodie/algos.rb', line 26

def intervallesRel melodie, note=0

	ptDepart = melodie[note]
	return melodie.map { |x| 
		x-= ptDepart }
end

#melodieCachee(melUn, melDeux) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rubySC/melodie/melodie.rb', line 34

def melodieCachee melUn, melDeux

  i=0  
    tmpDeux=melUn.map {|x| 
      if x == melDeux[i] then i +=1 ; true 
      else false
      end 
    }
    p tmpDeux
  
    if tmpDeux.count(true) == melDeux.size 
    then tmpDeux
    else  nil end
end

#organum(voix, typeHarmonisation = [-2,0,2,4]) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/rubySC/contrepoint.rb', line 57

def organum voix, typeHarmonisation=[-2,0,2,4]

a= Voix.new "harmonisationDe"+voix.name

a.degree= harmoniser voix.degree, typeHarmonisation
a.setDuree voix.dur

SC.updateScore
end

#orner(note, nbNote) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/rubySC/melodie/melodie.rb', line 128

def orner note, nbNote
  
appogiature = lambda { tmp=[note+1, note] }
mordant = lambda { tmp=[note, note-1, note] }
trille = lambda { tmp= [note-1, note, note+1, note] }

  case nbNote
  when 0
    return note
    when 1
     return appogiature.call
    when 2
     return  mordant.call
    when 3
     return  trille.call
  end
  if nbNote > 3 
    p "erreur !"
  end

end

#rejoindre(noteDepart, noteArrivee, nbTemps) ⇒ Object

end



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/rubySC/melodie/melodie.rb', line 111

def rejoindre noteDepart, noteArrivee, nbTemps

  intervalle=(noteArrivee-noteDepart).abs
  if intervalle == nbTemps then
    p'jkl'
    tmp =(Range.new noteDepart+1, noteArrivee-1).to_a
  else
    p'hj'
    tmp=[]  
   nbTemps.times { |x|
    tmp<<noteDepart+2*(x+1)
  }
  end
  return tmp
end

#transpose(melodie, deCombien) ⇒ Object



30
31
32
# File 'lib/rubySC/melodie/melodie.rb', line 30

def transpose melodie, deCombien
    melodie.map { |e| e+= deCombien }
end