class Object
Public Instance Methods
bicinium(consonances=[-2,2])
click to toggle source
# 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)
click to toggle source
# 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))
click to toggle source
# File lib/rubySC/melodie/melodie.rb, line 93 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
deuxVoix()
click to toggle source
# 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)
click to toggle source
# 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
melodieCachee(melUn, melDeux)
click to toggle source
# File lib/rubySC/melodie/Schenker.rb, line 2 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])
click to toggle source
# 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)
click to toggle source
# File lib/rubySC/melodie/melodie.rb, line 122 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)
click to toggle source
# File lib/rubySC/melodie/melodie.rb, line 105 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)
click to toggle source
# File lib/rubySC/melodie/melodie.rb, line 100 def transpose melodie, deCombien melodie.map { |e| e+= deCombien } end