チェンジセット 3504

差分発生行の前後
無視リスト:
コミット日時:
2010/03/08 23:12:32 (2 年前)
コミッタ:
keim
ログメッセージ:

SiON ver0.59 updated. This version is only for development.

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • as3/SiOPM/trunk/src/org/si/sion/effector/SiEffectModule.as

    r3480 r3504  
    7474    //-------------------------------------------------------------------------------- 
    7575        /** Initialize all effectors. This function is called from SiONDriver.play() with the 2nd argment true.  
    76         *  When you want to connect effectors by code, you have to call this first, then call connect() and SiONDriver.play() with the 2nd argment false. 
     76        *  When you want to connect effectors by code, you have to call this first, then call connect() and SiONDriver.play() with the 2nd argment false. 
    7777         */ 
    7878        public function initialize() : void 
     
    142142        _sion_internal function _endProcess() : void 
    143143        { 
    144             var i:int, slot:int, buffer:Vector.<Number>, 
     144            var i:int, slot:int, buffer:Vector.<Number>, effect:SiEffectStream,  
    145145                bufferLength:int = _module.bufferLength, 
    146146                output:Vector.<Number> = _module.output, 
     
    154154            // global effect (slot1-slot7) 
    155155            for (slot=1; slot<SiOPMModule.STREAM_SEND_SIZE; slot++) { 
    156                 if (_globalEffects[slot]) { 
    157                     _globalEffects[slot].process(0, bufferLength, false); 
     156                effect = _globalEffects[slot]; 
     157                if (effect) { 
     158                    effect.process(0, bufferLength, false); 
     159                    buffer = effect._stream.buffer; 
    158160                    for (i=0; i<imax; i++) output[i] += buffer[i]; 
    159161                } 
     
    229231        { 
    230232            if (_globalEffects[slot] == null) _globalEffects[slot] = _allocStream(); 
    231             _globalEffects[slot].connect(effector); 
     233            _globalEffects[slot].chain.push(effector); 
    232234        } 
    233235         
     
    253255        { 
    254256            if (_globalEffects[slot] == null) return null; 
    255             return _globalEffects[slot].getEffector(index); 
     257            var chain:Vector.<SiEffectBase> = _globalEffects[slot].chain; 
     258            return (index<chain.length) ? chain[index] : null; 
    256259        } 
    257260         
  • as3/SiOPM/trunk/src/org/si/sion/effector/SiEffectStream.as

    r3480 r3504  
    1515    // valiables 
    1616    //-------------------------------------------------------------------------------- 
     17        /** effector chain */ 
     18        public var chain:Vector.<SiEffectBase> = new Vector.<SiEffectBase>(); 
     19         
    1720        /** @private [internal] streaming buffer */ 
    1821        internal var _stream:SiOPMStream; 
    19          
    20         // effector chain 
    21         private var _chain:Vector.<SiEffectBase> = new Vector.<SiEffectBase>(); 
    2222         
    2323        // module 
     
    5757    // setting 
    5858    //-------------------------------------------------------------------------------- 
     59        /** set all stream send levels by Vector.<int>. 
     60         *  @param param Vector.<int>(8) of all volumes[0-128]. 
     61         */ 
     62        public function setAllStreamSendLevels(param:Vector.<int>) : void 
     63        { 
     64            var i:int, imax:int = SiOPMModule.STREAM_SEND_SIZE, v:int; 
     65            for (i=0; i<imax; i++) { 
     66                v = param[i]; 
     67                _volumes[i] = (v != int.MIN_VALUE) ? (v * 0.0078125) : 0; 
     68            } 
     69            for (_hasEffectSend=false, i=1; i<imax; i++) { 
     70                if (_volumes[i] > 0) _hasEffectSend = true; 
     71            } 
     72        } 
     73         
     74         
    5975        /** set stream send. 
    6076         *  @param streamNum stream number[0-7]. The streamNum of 0 means master volume. 
     
    99115        public function reset() : void 
    100116        { 
     117            var i:int; 
    101118            _stream.buffer.length = _module.bufferLength<<1; 
    102             for (var i:int=0; i<SiOPMModule.STREAM_SEND_SIZE; i++) { 
     119            _stream.clear(); 
     120             
     121            for (i=0; i<SiOPMModule.STREAM_SEND_SIZE; i++) { 
    103122                _volumes[i] = 0; 
    104123                _outputStreams[i] = null; 
     
    113132        public function free() : void 
    114133        { 
    115             for each (var e:SiEffectBase in _chain) e._isFree = true; 
    116             _chain.length = 0; 
     134            for each (var e:SiEffectBase in chain) e._isFree = true; 
     135            chain.length = 0; 
    117136        } 
    118137         
     
    121140        public function prepareProcess() : int 
    122141        { 
    123             if (_chain.length == 0) return 0; 
    124             _stream.channels = _chain[0].prepareProcess(); 
    125             for (var i:int=1; i<_chain.length; i++) _chain[i].prepareProcess(); 
     142            if (chain.length == 0) return 0; 
     143            _stream.channels = chain[0].prepareProcess(); 
     144            for (var i:int=1; i<chain.length; i++) chain[i].prepareProcess(); 
    126145            return _stream.channels; 
    127146        } 
     
    133152            var i:int, imax:int, effect:SiEffectBase, stream:SiOPMStream, 
    134153                buffer:Vector.<Number> = _stream.buffer, channels:int = _stream.channels; 
    135             imax = _chain.length; 
     154            imax = chain.length; 
    136155            for (i=0; i<imax; i++) { 
    137                 channels = _chain[i].process(channels, buffer, startIndex, length); 
     156                channels = chain[i].process(channels, buffer, startIndex, length); 
    138157            } 
    139158             
     
    161180    // effector connection 
    162181    //-------------------------------------------------------------------------------- 
    163         /** Connect effector at tail. 
    164          *  @param effector Effector instance. 
    165          */ 
    166         public function connect(effector:SiEffectBase) : void 
    167         { 
    168             _chain.push(effector); 
    169         } 
    170          
    171          
    172182        /** Parse MML for effector  
    173183         *  @param mml MML string. 
     
    205215                if (e) { 
    206216                    e.mmlCallback(args); 
    207                     connect(e); 
     217                    chain.push(e); 
    208218                } 
    209219            } 
     
    214224            } 
    215225        } 
    216          
    217  
    218         /** Get connected effector 
    219          *  @param slot Effector slot number. 
    220          *  @param index The index of connected effector. 
    221          *  @return Effector instance. 
    222          */ 
    223         public function getEffector(index:int) : SiEffectBase  
    224         { 
    225             return (index < _chain.length) ? _chain[index] : null; 
    226         } 
    227226    } 
    228227} 
  • as3/SiOPM/trunk/src/org/si/sion/module/SiOPMChannelParam.as

    r3480 r3504  
    191191            function $2(p:String, i:int, q:String, j:int) : void { str += "  " + p + "=" + String(i) + " / " + q + "=" + String(j) + "\n"; } 
    192192        } 
     193         
     194         
     195        /** Set voice by OPM's register value 
     196         *  @param channel pseudo OPM channel number 
     197         *  @param addr register address 
     198         *  @param data register data 
     199         */ 
     200        public function setByOPMRegister(channel:int, addr:int, data:int) : SiOPMChannelParam 
     201        { 
     202            var v:int, pms:int, ams:int, opp:SiOPMOperatorParam; 
     203             
     204            if (addr < 0x20) {  // Module parameter 
     205                switch(addr) { 
     206                case 15: // NOIZE:7 FREQ:4-0 for channel#7 
     207                    if (channel == 7 && data & 128) { 
     208                        operatorParam[3].setPGType(SiOPMTable.PG_NOISE_PULSE); 
     209                        operatorParam[3].fixedPitch = ((data & 31) << 6) + 2048; 
     210                    } 
     211                    break; 
     212                case 24: // LFO FREQ:7-0 for all 8 channels 
     213                    lfoFreqStep = SiOPMTable.instance.lfo_timerSteps[data]; 
     214                    break; 
     215                case 25: // A(0)/P(1):7 DEPTH:6-0 for all 8 channels 
     216                    if (data & 128) pmd = data & 127; 
     217                    else            amd = data & 127; 
     218                    break; 
     219                case 27: // LFO WS:10 for all 8 channels 
     220                    lfoWaveShape = data & 3 
     221                    break; 
     222                } 
     223            } else { 
     224                if (channel == (addr&7)) { 
     225                    if (addr < 0x40) { 
     226                        // Channel parameter 
     227                        switch((addr-0x20) >> 3) { 
     228                        case 0: // L:7 R:6 FB:5-3 ALG:2-0 
     229                            v = data >> 6; 
     230                            volumes[0] = (v) ? 0.5 : 0; 
     231                            pan = (v==1) ? 128 : (v==2) ? 0 : 64; 
     232                            fb  = (data >> 3) & 7; 
     233                            alg = (data     ) & 7; 
     234                            break; 
     235                        case 1: // KC:6-0 
     236                            break; 
     237                        case 2: // KF:6-0 
     238                            break; 
     239                        case 3: // PMS:6-4 AMS:10 
     240                            pms = (data >> 4) & 7; 
     241                            ams = (data     ) & 3; 
     242                            //pmd = (pms<6) ? (_pmd >> (6-pms)) : (_pmd << (pms-5)); 
     243                            //amd = (ams>0) ? (_amd << (ams-1)) : 0; 
     244                            break; 
     245                        } 
     246                    } else { 
     247                        // Operator parameter 
     248                        opp = operatorParam[[0,2,1,3][(addr >> 3) & 3]]; 
     249                        switch((addr-0x40) >> 5) { 
     250                        case 0: // DT1:6-4 MUL:3-0 
     251                            opp.dt1 = (data >> 4) & 7; 
     252                            opp.mul = (data     ) & 15; 
     253                            break; 
     254                        case 1: // TL:6-0 
     255                            opp.tl = data & 127; 
     256                            break; 
     257                        case 2: // KS:76 AR:4-0 
     258                            opp.ksr = (data >> 6) & 3; 
     259                            opp.ar  = (data & 31) << 1; 
     260                            break; 
     261                        case 3: // AMS:7 DR:4-0 
     262                            opp.ams = ((data >> 7) & 1)<<1; 
     263                            opp.dr  = (data & 31) << 1; 
     264                            break; 
     265                        case 4: // DT2:76 SR:4-0 
     266                            opp.detune = [0, 384, 500, 608][(data >> 6) & 3]; 
     267                            opp.sr     = (data & 31) << 1; 
     268                            break; 
     269                        case 5: // SL:7-4 RR:3-0 
     270                            opp.sl = (data >> 4) & 15; 
     271                            opp.rr = (data & 15) << 2; 
     272                            break; 
     273                        } 
     274                    } 
     275                } 
     276            } 
     277            return this; 
     278        } 
     279         
     280         
     281        /** Set voice by OPNA's register value */ 
     282        public function setByOPNARegister(addr:int, data:int) : SiOPMChannelParam { 
     283            throw new Error("SiOPMChannelParam.setByOPNARegister(): Sorry, this function is not available."); 
     284            return this; 
     285        } 
    193286    } 
    194287} 
  • as3/SiOPM/trunk/src/org/si/sion/module/channels/SiOPMChannelFM.as

    r3480 r3504  
    7979        /** LFO_TIMER_INITIAL * freq_ratio */  protected var _lfo_timer_initial:int; 
    8080         
     81        /** register map type */ 
     82        _sion_internal var registerMapType:int; 
    8183         
    8284         
     
    326328         
    327329         
     330        /** set register */ 
     331        override public function setRegister(addr:int, data:int) : void 
     332        { 
     333            switch(_sion_internal::registerMapType) { 
     334            case 1:  
     335                _setByOPMRegister(addr, data); 
     336                break; 
     337            case 0: 
     338            default: 
     339                _setBy2A03Register(addr, data); 
     340                break; 
     341            } 
     342        } 
     343         
     344         
     345        // 2A03 register value 
     346        private function _setBy2A03Register(addr:int, data:int) : void 
     347        { 
     348        } 
     349         
     350         
     351        // OPM register value 
     352        private function _setByOPMRegister(addr:int, data:int) : void 
     353        { 
     354        } 
     355         
     356         
    328357         
    329358         
     
    490519            operator[0].initialize(); 
    491520            _isNoteOn = false; 
     521            _sion_internal::registerMapType = 0; 
    492522             
    493523            // initialize sound channel 
  • as3/SiOPM/trunk/src/org/si/sion/utils/Translator.as

    r3450 r3504  
    88    import org.si.sion.module.*; 
    99    import org.si.sion.sequencer.SiMMLTable; 
     10    import org.si.sion.effector.SiEffectModule; 
     11    import org.si.sion.effector.SiEffectBase; 
    1012     
    1113     
     
    335337         
    336338         
     339    // Effector 
     340    //-------------------------------------------------- 
     341    // parse effector MML string 
     342    //-------------------------------------------------- 
     343        /** parse effector mml */ 
     344        static public function parseEffectorMML(mml:String, postfix:String="") : Array 
     345        { 
     346            var ret:Array, res:*, rex:RegExp = /([a-zA-Z_]+|,)\s*([.\-\d]+)?/g, i:int, 
     347                cmd:String = "", argc:int = 0, args:Vector.<Number> = new Vector.<Number>(16, true); 
     348             
     349            // clear 
     350            ret = []; 
     351            _clearArgs(); 
     352             
     353            // parse mml 
     354            res = rex.exec(mml); 
     355            while (res) { 
     356                if (res[1] == ",") { 
     357                    args[argc++] = Number(res[2]); 
     358                } else { 
     359                    _connectEffect(); 
     360                    cmd = res[1]; 
     361                    _clearArgs(); 
     362                    args[0] = Number(res[2]); 
     363                    argc = 1; 
     364                } 
     365                res = rex.exec(mml); 
     366            } 
     367            _connectEffect(); 
     368             
     369            return ret; 
     370             
     371            // connect new effector 
     372            function _connectEffect() : void { 
     373                if (argc == 0) return; 
     374                var e:SiEffectBase = SiEffectModule.getInstance(cmd); 
     375                if (e) { 
     376                    e.mmlCallback(args); 
     377                    ret.push(e); 
     378                } 
     379            } 
     380             
     381            // clear arguments 
     382            function _clearArgs() : void { 
     383                for (var i:int=0; i<16; i++) args[i]=Number.NaN; 
     384            } 
     385        } 
     386         
     387         
     388         
     389         
    337390    // FM parameters 
    338391    //-------------------------------------------------- 
  • as3/SiOPM/trunk/src/org/si/sound/Note.as

    r3480 r3504  
    1010    public class Note 
    1111    { 
    12         /** Note number[-1-127], -1 sets playing with sequencers default note. */ 
     12    // variables 
     13    //-------------------------------------------------- 
     14        /** Note number[-1-127], -1 (or all negatives) sets playing with sequencers default note. */ 
    1315        public var note:int = 0; 
    14         /** Velocity[-1-128], -1 sets playing with sequencers default velocity, 0 sets no note (rest). */ 
     16        /** Velocity[-1-128], -1 (or all negatives) sets playing with sequencers default velocity, 0 sets no note (rest). */ 
    1517        public var velocity:int = 0; 
    1618        /** Length in 16th beat [16 for whole tone], Number.NaN sets playing with sequencers default length. */ 
    1719        public var length:Number = 0; 
     20        /** Voice index refering from PatternSequencer.voiceList, -1 (or all negatives) sets no voice changing. @see si.org.sound.PatternSequencer.voiceList */ 
     21        public var voiceIndex:Number = 0; 
    1822         
    1923         
     24         
     25         
     26    // constructor 
     27    //-------------------------------------------------- 
    2028        /** constructor 
    2129         *  @param note Note number[-1-127], -1 sets playing with sequencer's default note. 
    2230         *  @param velocity Velocity[-1-128], -1 sets playing with sequencer's default velocity, 0 sets no note (rest). 
    2331         *  @param length Length in 16th beat [16 for whole tone], Number.NaN sets playing with sequencers default length. 
     32         *  @param voiceIndex Voice index refering from PatternSequencer.voiceList, -1 (or all negatives) sets no voice changing. @see si.org.sound.PatternSequencer.voiceList. 
    2433         */ 
    25         function Note(note:int=-1, velocity:int=0, length:Number=Number.NaN
     34        function Note(note:int=-1, velocity:int=0, length:Number=Number.NaN, voiceIndex:int=-1
    2635        { 
    27             setNote(note, velocity, length); 
     36            this.note = note; 
     37            this.velocity = velocity; 
     38            this.length = length; 
     39            this.voiceIndex = voiceIndex; 
    2840        } 
    2941 
    3042         
     43         
     44         
     45    // operations 
     46    //-------------------------------------------------- 
    3147        /** Set note. 
    3248         *  @param note Note number[-1-127], -1 sets playing with sequencer's default note. 
    3349         *  @param velocity Velocity[-1-128], -1 sets playing with sequencer's default velocity, 0 sets no note (rest). 
    3450         *  @param length Length in 16th beat [16 for whole tone], Number.NaN sets playing with sequencers default length. 
     51         *  @param voiceIndex Voice index refering from PatternSequencer.voiceList, -1 (or all negatives) sets no voice changing. @see si.org.sound.PatternSequencer.voiceList. 
    3552         *  @return this instance. 
    3653         */ 
    37         public function setNote(note:int=-1, velocity:int=-1, length:Number=Number.NaN) : Note 
     54        public function setNote(note:int=-1, velocity:int=-1, length:Number=Number.NaN, voiceIndex:int=-1) : Note 
    3855        { 
    3956            this.note = note; 
    4057            this.velocity = velocity; 
    4158            this.length = length; 
     59            this.voiceIndex = voiceIndex; 
    4260            return this; 
    4361        } 
     
    5068            return this; 
    5169        } 
     70         
     71         
     72        /** Copy from another note. 
     73         *  @param src source note instnace. 
     74         *  @return this instance 
     75         */ 
     76        public function copyFrom(src:Note) : Note { 
     77            if (src == null) return setRest(); 
     78            note = src.note; 
     79            velocity = src.velocity; 
     80            length = src.length; 
     81            voiceIndex = src.voiceIndex; 
     82            return this; 
     83        } 
     84         
     85         
     86        /** return new instance copied parameters from this note. 
     87         *  @return new clone instance 
     88         */ 
     89        public function clone() : Note { 
     90            return new Note(note, velocity, length, voiceIndex); 
     91        } 
    5292    } 
    5393} 
  • as3/SiOPM/trunk/src/org/si/sound/PatternSequencer.as

    r3480 r3504  
    2525        /** note pattern */ 
    2626        public var pattern:Vector.<Note>; 
     27        /** voice list refered by Note.voiceIndex. @see org.si.sound.Note.voiceIndex */ 
     28        public var voiceList:Array; 
    2729         
    2830        /** portament */ 
     
    4850        protected var _currentNote:Note; 
    4951         
     52        /** default pattern, this pattern is used when notes or velocities propertiy is called */ 
     53        protected var _defaultPattern:Vector.<Note>; 
     54         
    5055         
    5156         
     
    6772         
    6873         
    69         /** note. */ 
     74        /** curent note */ 
    7075        override public function get note() : int { 
    71             if (_currentNote==null || _currentNote.note==-1) return _note; 
     76            if (_currentNote==null || _currentNote.note<0) return _note; 
    7277            return _currentNote.note; 
    7378        } 
     
    7782         
    7883         
    79         /** velocity. */ 
     84        /** curent note's velocity. */ 
    8085        public function get velocity() : int { 
    81             if (_currentNote==null || _currentNote.velocity==-1) return _velocity; 
     86            if (_currentNote==null || _currentNote.velocity<0) return _velocity; 
    8287            return _currentNote.velocity; 
    8388        } 
    8489        public function set velocity(v:int) : void { 
    8590            _velocity = v; 
     91        } 
     92         
     93         
     94        /** Array of sequence's notes. */ 
     95        public function set notes(list:Array) : void { 
     96            var i:int, pi:int, li:int; 
     97            if (pattern && pattern !== _defaultPattern) { 
     98                for (i=0; i<16; i++) { 
     99                    pi = i % pattern.length; 
     100                    _defaultPattern[i].copyFrom(pattern[pi]); 
     101                } 
     102            } 
     103            for (i=0; i<16; i++) { 
     104                li = i % list.length; 
     105                _defaultPattern[i].note = list[li]; 
     106            } 
     107            pattern = _defaultPattern; 
     108        } 
     109         
     110         
     111        /** Array of sequence's velocities */ 
     112        public function set velocities(list:Array) : void { 
     113            var i:int, pi:int, li:int; 
     114            if (pattern && pattern !== _defaultPattern) { 
     115                for (i=0; i<16; i++) { 
     116                    pi = i % pattern.length; 
     117                    _defaultPattern[i].copyFrom(pattern[pi]); 
     118                } 
     119            } 
     120            for (i=0; i<16; i++) { 
     121                li = i % list.length; 
     122                _defaultPattern[i].velocity = list[li]; 
     123            } 
     124            pattern = _defaultPattern; 
     125        } 
     126         
     127         
     128        /** Array of sequence's voice indicies */ 
     129        public function set voiceIndicies(list:Array) : void { 
     130            var i:int, pi:int, li:int; 
     131            if (pattern && pattern !== _defaultPattern) { 
     132                for (i=0; i<16; i++) { 
     133                    pi = i % pattern.length; 
     134                    _defaultPattern[i].copyFrom(pattern[pi]); 
     135                } 
     136            } 
     137            for (i=0; i<16; i++) { 
     138                li = i % list.length; 
     139                _defaultPattern[i].voiceIndex = list[li]; 
     140            } 
     141            pattern = _defaultPattern; 
    86142        } 
    87143         
     
    112168            super("Pattern sequencer"); 
    113169            pattern = null; 
     170            voiceList = null; 
    114171            onEnterSegument = null; 
    115172            _data = new SiONData(); 
     
    129186            _currentNote = null; 
    130187            quantize = 16; 
     188 
     189            _defaultPattern = new Vector.<Note>(16); 
     190            for (var i:int=0; i<16; i++) _defaultPattern[i] = new Note(); 
    131191             
    132192            this.division = division; 
     
    177237                if (_currentNote && _currentNote.velocity > 0) { 
    178238                    var sampleLength:int = driver.sequencer.calcSampleLength(length); 
    179                     _track.setNote(note, sampleLength, (_portament>0)); 
    180                     _track.velocity = velocity; 
    181239                    if (onNoteOn != null) onNoteOn(); 
     240                    // voice change 
     241                    if (voiceList && _currentNote.voiceIndex >= 0) { 
     242                        voice = voiceList[_currentNote.voiceIndex]; 
     243                    } 
    182244                    if (_synthesizer._synthesizer_internal::_requireVoiceUpdate) { 
    183245                        _synthesizer.setTrackVoice(_track); 
    184                     } 
     246                    }  
     247                    _track.velocity = velocity; 
     248                    _track.setNote(note, sampleLength, (_portament>0)); 
    185249                } 
    186250                _pointer++; 
  • as3/SiOPM/trunk/src/org/si/sound/RhythmBox.as

    r3480 r3504  
    2929        public var hihat:PatternSequencer; 
    3030         
    31         protected var _closeHHPattern:Vector.<int>; 
    32         protected var _openHHPattern:Vector.<int>; 
    33         protected var _hhVoiceIndex:Vector.<int>; 
    34         protected var _hhVoices:Vector.<SiONVoice>; 
    35         protected var _currentHHIndex:int; 
    36          
    3731         
    3832         
     
    4034    // properties 
    4135    //---------------------------------------- 
    42         /** bass drum velocity pattern */ 
    43         public function set bassPattern(pat:Array) : void 
     36        /** bass drum pattern number */ 
     37        public function set bassPattern(index:int) : void 
    4438        { 
    45             var i:int, len:int = pat.length; 
    46             for (i=0; i<16; i++) { 
    47                 bass.pattern[i].velocity = pat[i % len]; 
    48             } 
    4939        } 
    5040         
    5141         
    52         /** snare drum velocity pattern */ 
    53         public function set snarePattern(pat:Array) : void 
     42        /** snare drum pattern number */ 
     43        public function set snarePattern(index:int) : void 
    5444        { 
    55             var i:int, len:int = pat.length; 
    56             for (i=0; i<16; i++) { 
    57                 snare.pattern[i].velocity = pat[i % len]; 
    58             } 
    5945        } 
    6046         
    6147         
    62         /** close hi-hat cymbal velocity pattern */ 
    63         public function set closeHHPattern(pat:Array) : void 
     48        /** close hi-hat cymbal pattern number */ 
     49        public function set hihatPattern(index:int) : void 
    6450        { 
    65             var i:int, len:int = pat.length; 
    66             for (i=0; i<16; i++) _closeHHPattern[i] = pat[i % len]; 
    67             _updateHHPatterns(); 
    68         } 
    69          
    70          
    71         /** open hi-hat cymbal velocity pattern */ 
    72         public function set openHHPattern(pat:Array) : void 
    73         { 
    74             var i:int, len:int = pat.length; 
    75             for (i=0; i<16; i++) _openHHPattern[i] = pat[i % len]; 
    76             _updateHHPatterns(); 
    77         } 
    78          
    79          
    80         /** close hi-hat cymbal voice */ 
    81         public function set closeHHVoice(v:SiONVoice) : void 
    82         { 
    83             _hhVoices[0] = v; 
    84             hihat.voice = v; 
    85         } 
    86          
    87  
    88         /** open hi-hat cymbal voice */ 
    89         public function set openHHVoice(v:SiONVoice) : void 
    90         { 
    91             _hhVoices[1] = v; 
    9251        } 
    9352         
     
    10261            super("RhythmBox"); 
    10362            _interruptStep = 120; 
    104             _closeHHPattern = new Vector.<int>(16, true); 
    105             _openHHPattern  = new Vector.<int>(16, true); 
    106             _hhVoiceIndex   = new Vector.<int>(16, true); 
    107             _hhVoices       = new Vector.<SiONVoice>(2, true); 
    10863            addChild(bass  = new PatternSequencer(16, 36, 255, 1)); 
    10964            addChild(snare = new PatternSequencer(16, 68, 128, 1)); 
    11065            addChild(hihat = new PatternSequencer(16, 68, 64,  1)); 
    111             bass.pattern = new Vector.<Note>(); 
    112             snare.pattern = new Vector.<Note>(); 
    113             hihat.pattern = new Vector.<Note>(); 
    114             hihat.onNoteOn = _onNoteOnHH; 
    115             for (var i:int=0; i<16; i++) { 
    116                 bass.pattern[i]  = new Note(); 
    117                 snare.pattern[i] = new Note(); 
    118                 hihat.pattern[i] = new Note(); 
    119                 _hhVoiceIndex[i] = 0; 
    120             } 
    121         } 
    122          
    123          
    124          
    125          
    126     // settings 
    127     //---------------------------------------- 
    128         /** Get track volume */ 
    129         public function getTrackVolume(trackIndex:int) : Number { 
    130             return _soundList[trackIndex].volume; 
    131         } 
    132          
    133          
    134         /** Set track volume */ 
    135         public function setTrackVolume(trackIndex:int, v:Number) : void { 
    136             _soundList[trackIndex].volume = v; 
    137         } 
    138          
    139          
    140         /** Get track voice */ 
    141         public function getTrackVoice(trackIndex:int) : SiONVoice { 
    142             return _soundList[trackIndex].voice; 
    143         } 
    144          
    145          
    146         /** Set track voice */ 
    147         public function setTrackVoice(trackIndex:int, v:SiONVoice) : void { 
    148             _soundList[trackIndex].voice = v; 
    149         } 
    150          
    151          
    152          
    153          
    154     // operations 
    155     //---------------------------------------- 
    156         /** @inhriteDoc */ 
    157         override public function play() : void { 
    158             _currentHHIndex = 0; 
    159             super.play(); 
    160         } 
    161          
    162          
    163          
    164          
    165     // internal 
    166     //---------------------------------------- 
    167         /** call after updating hi-hat patterns */ 
    168         protected function _updateHHPatterns() : void { 
    169             var i:int, vel:int; 
    170             for (i=0; i<16; i++) { 
    171                 if (_openHHPattern[i] > 0) { 
    172                     vel = _openHHPattern[i]; 
    173                     _hhVoiceIndex[i] = 2; 
    174                 } else { 
    175                     vel = _closeHHPattern[i]; 
    176                     _hhVoiceIndex[i] = (vel==0) ? 0 : 1; 
    177                 } 
    178                 hihat.pattern[i].velocity = vel; 
    179             } 
    180         } 
    181          
    182          
    183         /** handler for hi-hat note on */ 
    184         private function _onNoteOnHH() : void { 
    185             var voiceIndex:int = _hhVoiceIndex[hihat.frameCount]; 
    186             if (voiceIndex != 0 && voiceIndex != _currentHHIndex) { 
    187                 hihat.voice = _hhVoices[voiceIndex-1]; 
    188                 _currentHHIndex = voiceIndex; 
    189             } 
    19066        } 
    19167    } 
  • as3/SiOPM/trunk/src/org/si/sound/base/SoundObject.as

    r3480 r3504  
    88package org.si.sound.base { 
    99    import org.si.sion.*; 
     10    import org.si.sion.utils.Translator; 
    1011    import org.si.sion.module.SiOPMModule; 
     12    import org.si.sion.effector.SiEffectBase; 
    1113    import org.si.sion.sequencer.SiMMLTrack; 
    1214    import org.si.sound.synthesizer.SynthesizerBase; 
     
    3638        /** Synthesizer instance to use SiONVoice  */ 
    3739        protected var _defaultSynthesizer:SynthesizerBase; 
     40        /** Effect chain instance */ 
     41        protected var _effectChain:EffectChain; 
    3842        /** track for noteOn() */ 
    3943        protected var _track:SiMMLTrack; 
     
    225229         
    226230         
     231        /** Effectors to process this sound object's output. You can set effectors by SiEffectBase, Array of SiEffectBase, EffecChain or effector MML String. 
     232         */ 
     233        public function get effectors() : * { 
     234            return _effectChain.effectList; 
     235        } 
     236        public function set effectors(obj:*) :void { 
     237            if (_effectChain) _effectChain.free(); 
     238            if (obj == null) { 
     239                _effectChain = null; 
     240            } else  
     241            if (obj is SiEffectBase) { 
     242                _effectChain = EffectChain.alloc([obj]); 
     243            } else  
     244            if (obj is Array) { 
     245                _effectChain = EffectChain.alloc(obj as Array); 
     246            } else  
     247            if (obj is String) { 
     248                var list:Array = Translator.parseEffectorMML(obj as String); 
     249                _effectChain = EffectChain.alloc(list); 
     250            } else  
     251            if (obj is EffectChain) { 
     252                _effectChain = obj as EffectChain; 
     253            } 
     254        } 
     255         
     256         
    227257        // counter to asign unique track id 
    228258        static private var _uniqueTrackID:int = 0; 
     
    240270            _synthesizer = _defaultSynthesizer = new SynthesizerBase(); 
    241271            _synthesizer._synthesizer_internal::_owner = this; 
     272            _effectChain = null; 
    242273            _track = null; 
    243274            _tracks = null; 
     
    286317            _quantize = 1; 
    287318             
     319            _effectChain = null; 
    288320            _volumes[0] = 64; 
    289321            for (var i:int=1; i<SiOPMModule.STREAM_SEND_SIZE; i++) _volumes[i] = 0; 
     
    303335            _thisPan = 0; 
    304336            _thisMute = false; 
    305        
     337       
    306338         
    307339         
     
    370402            var v:SiONVoice = voice, 
    371403                t:SiMMLTrack = driver.noteOn(note, v, _length, _delay, _quantize, _trackID, isDisposable); 
    372             t.channel.setAllStreamSendLevels(_volumes); 
     404            if (_effectChain && _effectChain.effectList.length > 0) { 
     405                _effectChain._activateLocalEffect(); 
     406                _effectChain.setAllStreamSendLevels(_volumes); 
     407                t.channel.masterVolume = 128; 
     408                t.channel.setStreamBuffer(0, _effectChain.streamingBuffer); 
     409            } else { 
     410                t.channel.setAllStreamSendLevels(_volumes); 
     411            } 
    373412            t.channel.pan       = _pan; 
    374413            t.channel.mute      = _mute; 
     
    389428        { 
    390429            if (!driver) return null; 
     430            if (_effectChain) _effectChain._inactivateLocalEffect(); 
    391431            return driver.noteOff(note, _trackID, _delay, _quantize, stopImmediately); 
    392432        } 
     
    403443            if (!driver) return null; 
    404444            var len:Number = (applyLength) ? _length : 0; 
    405             var v:SiONVoice = voice, 
     445            var v:SiONVoice = voice, effectActive:Boolean = false, 
    406446                list:Vector.<SiMMLTrack> = driver.sequenceOn(data, v, len, _delay, _quantize, _trackID, isDisposable), 
    407447                t:SiMMLTrack, ps:int = _pitchShift * 64, pb:int = _pitchBend * 64; 
     448            if (_effectChain && _effectChain.effectList.length > 0) { 
     449                _effectChain._activateLocalEffect(); 
     450                _effectChain.setAllStreamSendLevels(_volumes); 
     451                effectActive = true; 
     452            } 
    408453            for each (t in list) { 
    409                 t.channel.setAllStreamSendLevels(_volumes); 
     454                if (effectActive) { 
     455                    t.channel.masterVolume = 128; 
     456                    t.channel.setStreamBuffer(0, _effectChain.streamingBuffer); 
     457                } else { 
     458                    t.channel.setAllStreamSendLevels(_volumes); 
     459                } 
    410460                t.channel.pan       = _pan; 
    411461                t.channel.mute      = _mute; 
     
    414464                t.pitchShift = ps; 
    415465                t.setEventTrigger(_eventTriggerID, _noteOnTrigger, _noteOffTrigger); 
    416                 if (isNaN(v.gateTime)) t.quantRatio = _gateTime; 
     466                if (v && isNaN(v.gateTime)) t.quantRatio = _gateTime; 
    417467            } 
    418468            return list; 
     
    427477        { 
    428478            if (!driver) return null; 
     479            if (_effectChain) _effectChain._inactivateLocalEffect(); 
    429480            return driver.sequenceOff(_trackID, 0, _quantize, stopImmediately); 
    430481        } 
  • as3/SiOPM/trunk/src/org/si/sound/smf/SMFData.as

    r3480 r3504  
    1414package org.si.sound.smf { 
    1515    import flash.utils.ByteArray; 
    16     import org.si.sound.smf.*; 
    1716     
    1817