Rix
2015年2月14日土曜日
RD-01
RD-01
Home
Edit
Volume :
1
Tempo :
120
ここにコード進行を記入してください。
Melody Algorithm
var MelodyModule = (function(){ var melodySoundType = 'triangle'; //音色。sine, sawtooth, square を選択可能 var h_octPlus = 0; // メロディーのオクターブの高さ var r_octPlus = 0; // メロディーのリズムの速さ function MelodyElement( f , d , p){ this.freq = f; // 音程の高さ。Hz単位で加算可能 this.duration = d; // 音の長さ。mSec単位で加算可能 this.pos = p; // ノートオンのタイミング。mSec単位で加算可能 } function m_chordation(){ var m_chord = []; var h_chord = HarmonyModule.getProperty().chord; var r_chord = RhythmModule.getProperty().chord; var oneBar = RhythmModule.getProperty().oneBar; for(var c in h_chord){ var h_noteInfo = compressToTwelveTone( h_chord[c] ); var h_freq = HarmonyModule.numToHz(HarmonyModule.getProperty().chordOct + h_octPlus , h_noteInfo[0] ); var r_noteInfo = compressToTwelveTone( r_chord[c] ); var r_freq = RhythmModule.numToHz(RhythmModule.getProperty().chordOct+ r_octPlus + r_noteInfo[1], r_noteInfo[0]); var oneBeat = oneBar / r_freq; m_chord[c] = new MelodyElement( h_freq, oneBeat , 0); } return m_chord; } function MelodyLane(){ this.count= 0; this.m_Elements= []; this.add = function(mEl){ this.m_Elements[this.count] = mEl; this.count++; }; this.getAfter = function(currentPhase){ for( var i in this.m_Elements){ if(currentPhase < this.m_Elements[i].pos){ return this.m_Elements[i]; } } return 'none'; }; } function loadMelodyLanes(m_chord){ var m_lanes =[]; var posTotal =0; var oneBar = RhythmModule.getProperty().oneBar; for(var c in m_chord){ m_lanes[c] = new MelodyLane(); while(posTotal < oneBar){ m_lanes[c].add( new MelodyElement(m_chord[c].freq, m_chord[c].duration, posTotal) ); posTotal += m_chord[c].duration; } posTotal=0; } return m_lanes; } var MelodyElementAssembly ={ arrangedLane: new MelodyLane(), arrange: function(m_lanes){ // この値以上離れている候補音をメロディーに含める。 var afterMargin = 0; var oneBar = RhythmModule.getProperty().oneBar; // 初期値は0番目レーンの0番目エレメント (変更は任意) var reservedElement = m_lanes[0].m_Elements[0]; var currentPhase =0; var next = []; while( currentPhase < oneBar){ var minPos = oneBar; var rightNum =-1; for( var i in m_lanes){ next[i] = m_lanes[i].getAfter(currentPhase + afterMargin); } for( var n in next){ if(next[n] == 'none'){ continue; } if(next[n].pos < minPos ){ minPos = next[n].pos; rightNum = n; } } if(rightNum == -1){ break; } if(currentPhase > oneBar){ reservedElement.duration = oneBar - currentPhase; }else{ reservedElement.duration = next[rightNum].pos - currentPhase; } currentPhase = next[rightNum].pos; this.arrangedLane.add(reservedElement); reservedElement = next[rightNum]; } }, launch: function(){ var mEl = null; var s = null; for(var e in this.arrangedLane.m_Elements){ mEl = this.arrangedLane.m_Elements[e]; s = new Sound(mEl.freq, mEl.duration, mEl.pos, melodySoundType, melodyGain); eSoundation(s); } this.arrangedLane = new MelodyLane(); } } // MelodyElementAssembly return { run: function(){ var m_chord = m_chordation(); var m_lanes = loadMelodyLanes(m_chord); MelodyElementAssembly.arrange(m_lanes); MelodyElementAssembly.launch(); } } })(); // MelodyModule
LOOP
Melody Gain
Rhythm Gain
前の投稿
ホーム
登録:
投稿 (Atom)