Changeset 20421

Show
Ignore:
Timestamp:
10/02/08 01:32:37 (3 months ago)
Author:
tekisuke
Message:

lang/actionscript/flmml/: マクロを再帰的定義したときのバグをとりあえず修正。FM音源はまだ封印。

Location:
lang/actionscript/flmml/trunk/src
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MChannel.as

    r15293 r20421  
    2626        private var m_lpfRes:Number; 
    2727        private var m_volMode:int; 
     28        private var m_inSens:int; 
     29        private var m_inPipe:int; 
     30        private var m_outMode:int; 
     31        private var m_outPipe:int; 
    2832        public    static var PITCH_RESOLUTION:int = 100; 
    2933        protected static var s_init:int = 0; 
     
    3337        protected static var s_volumeLen:int; 
    3438        protected static var s_samples:Array; 
     39        protected static var s_pipeArr:Array; 
    3540 
    3641        public function MChannel() { 
     
    5863            m_lpfRes   = 0; 
    5964            m_volMode  = 0; 
     65            setInput(0, 0); 
     66            setOutput(0, 0); 
    6067        } 
    6168        public static function boot(numSamples:int):void { 
     
    7582            } 
    7683            s_samples = new Array(numSamples); 
     84        } 
     85        public static function createPipes(num:int):void { 
     86            s_pipeArr = new Array(num); 
     87            for (var i:int = 0; i < num; i++) { 
     88                s_pipeArr[i] = new Array(s_samples.length); 
     89                for (var j:int = 0; j < s_samples.length; j++) { 
     90                    var arr:Array = s_pipeArr[i]; 
     91                    arr[j] = 0; 
     92                } 
     93            } 
    7794        } 
    7895        public static function getFrequency(freqNo:int):Number { 
     
    169186        public function setVolMode(m:int):void { 
    170187            m_volMode = m; 
     188        } 
     189        public function setInput(i:int, p:int):void { 
     190            m_inSens = i * 100; 
     191            m_inPipe = p; 
     192        } 
     193        public function setOutput(o:int, p:int):void { 
     194            m_outMode = o; 
     195            m_outPipe = p; 
    171196        } 
    172197        protected function getNextSampleLinear():Number { 
     
    189214            var freqNo:int; 
    190215            var i:int; 
     216            var arr:Array; 
    191217            if (end >= max) end = max; 
    192218            var key:Number = m_oscillator1.getFrequency(); 
    193             if (m_osc2Connect == 0) { 
    194                 // no LFO 
    195                 m_oscillator1.getSamples(s_samples, start, end); 
    196                 if (m_volMode == 0) m_envelope1.ampSamplesLinear(s_samples, start, end, m_velocity); 
    197                 else m_envelope1.ampSamplesNonLinear(s_samples, start, end, m_velocity); 
    198             } 
     219            if (m_inSens == 0) { 
     220                if (m_osc2Connect == 0) { 
     221                    // no input, no LFO 
     222                    m_oscillator1.getSamples(s_samples, start, end); 
     223                    if (m_volMode == 0) m_envelope1.ampSamplesLinear(s_samples, start, end, m_velocity); 
     224                    else m_envelope1.ampSamplesNonLinear(s_samples, start, end, m_velocity); 
     225                } 
     226                else { 
     227                    // no input, with LFO, linear 
     228                    if (m_volMode == 0) { 
     229                        for(i = start; i < end; i++) { 
     230                            freqNo = m_freqNo; 
     231                            if (m_onCounter >= m_lfoDelay && (m_lfoEnd == 0 || m_onCounter < m_lfoEnd)) { 
     232                                freqNo += m_oscillator2.getNextSample() * m_osc2Sign * m_lfoDepth; 
     233                            } 
     234                            m_oscillator1.setFrequency(getFrequency(freqNo)); 
     235                            s_samples[i] = getNextSampleLinear(); 
     236                            m_onCounter++; 
     237                        } 
     238                    } 
     239                    // no input, with LFO, non linear 
     240                    else { 
     241                        for(i = start; i < end; i++) { 
     242                            freqNo = m_freqNo; 
     243                            if (m_onCounter >= m_lfoDelay && (m_lfoEnd == 0 || m_onCounter < m_lfoEnd)) { 
     244                                freqNo += m_oscillator2.getNextSample() * m_osc2Sign * m_lfoDepth; 
     245                            } 
     246                            m_oscillator1.setFrequency(getFrequency(freqNo)); 
     247                            s_samples[i] = getNextSampleNonLinear(); 
     248                            m_onCounter++; 
     249                        } 
     250                    } 
     251                } 
     252            } 
     253            // with input 
    199254            else { 
    200                 // with LFO, linear 
    201                 if (m_volMode == 0) { 
    202                     for(i = start; i < end; i++) { 
    203                         freqNo = m_freqNo; 
    204                         if (m_onCounter >= m_lfoDelay && (m_lfoEnd == 0 || m_onCounter < m_lfoEnd)) { 
    205                             freqNo += m_oscillator2.getNextSample() * m_osc2Sign * m_lfoDepth; 
    206                         } 
    207                         m_oscillator1.setFrequency(getFrequency(freqNo)); 
    208                         s_samples[i] = getNextSampleLinear(); 
    209                         m_onCounter++; 
    210                     } 
    211                 } 
    212                 // with LFO, non linear 
     255                //trace("input "+m_inPipe); 
     256                if (m_osc2Connect == 0) { 
     257                    // with input, no LFO 
     258                    arr = s_pipeArr[m_inPipe]; 
     259                    freqNo = getFrequency(m_freqNo); 
     260                    if (m_volMode == 0) { 
     261                        for(i = start; i < end; i++) { 
     262                            m_oscillator1.setFrequency(freqNo + arr[i] * m_inSens); 
     263                            s_samples[i] = getNextSampleLinear(); 
     264                        } 
     265                    } 
     266                    else { 
     267                        for(i = start; i < end; i++) { 
     268                            m_oscillator1.setFrequency(freqNo + arr[i] * m_inSens); 
     269                            s_samples[i] = getNextSampleNonLinear(); 
     270                        } 
     271                    } 
     272                } 
    213273                else { 
    214                     for(i = start; i < end; i++) { 
    215                         freqNo = m_freqNo; 
    216                         if (m_onCounter >= m_lfoDelay && (m_lfoEnd == 0 || m_onCounter < m_lfoEnd)) { 
    217                             freqNo += m_oscillator2.getNextSample() * m_osc2Sign * m_lfoDepth; 
    218                         } 
    219                         m_oscillator1.setFrequency(getFrequency(freqNo)); 
    220                         s_samples[i] = getNextSampleNonLinear(); 
    221                         m_onCounter++; 
     274                    // with input, with LFO, linear 
     275                    if (m_volMode == 0) { 
     276                        arr = s_pipeArr[m_inPipe]; 
     277                        for(i = start; i < end; i++) { 
     278                            freqNo = m_freqNo; 
     279                            if (m_onCounter >= m_lfoDelay && (m_lfoEnd == 0 || m_onCounter < m_lfoEnd)) { 
     280                                freqNo += m_oscillator2.getNextSample() * m_osc2Sign * m_lfoDepth; 
     281                            } 
     282                            m_oscillator1.setFrequency(getFrequency(freqNo) + arr[i] * m_inSens); 
     283                            s_samples[i] = getNextSampleLinear(); 
     284                            m_onCounter++; 
     285                        } 
     286                    } 
     287                    // with input, with LFO, non linear 
     288                    else { 
     289                        arr = s_pipeArr[m_inPipe]; 
     290                        for(i = start; i < end; i++) { 
     291                            freqNo = m_freqNo; 
     292                            if (m_onCounter >= m_lfoDelay && (m_lfoEnd == 0 || m_onCounter < m_lfoEnd)) { 
     293                                freqNo += m_oscillator2.getNextSample() * m_osc2Sign * m_lfoDepth; 
     294                            } 
     295                            m_oscillator1.setFrequency(getFrequency(freqNo) + arr[i] * m_inSens); 
     296                            s_samples[i] = getNextSampleNonLinear(); 
     297                            m_onCounter++; 
     298                        } 
    222299                    } 
    223300                } 
     
    225302            m_formant.run(s_samples, start, end); 
    226303            m_filter.run(s_samples, start, end, m_envelope2, m_lpfFrq, m_lpfAmt, m_lpfRes, key); 
    227             for(i = start; i < end; i++) { 
    228                 amplitude = s_samples[i]; 
    229                 sample = samples[i]; 
    230                 sample.left  += amplitude * m_panL; 
    231                 sample.right += amplitude * m_panR; 
     304            switch(m_outMode) { 
     305            case 0: 
     306                //trace("output audio"); 
     307                for(i = start; i < end; i++) { 
     308                    amplitude = s_samples[i]; 
     309                    sample = samples[i]; 
     310                    sample.left  += amplitude * m_panL; 
     311                    sample.right += amplitude * m_panR; 
     312                } 
     313                break; 
     314            case 1: // overwrite 
     315                //trace("output "+m_outPipe); 
     316                arr = s_pipeArr[m_outPipe]; 
     317                for(i = start; i < end; i++) { 
     318                    arr[i] = s_samples[i]; 
     319                } 
     320                break; 
     321            case 2: // add 
     322                arr = s_pipeArr[m_outPipe]; 
     323                for(i = start; i < end; i++) { 
     324                    arr[i] += s_samples[i]; 
     325                } 
     326                break; 
     327            default: 
     328                break; 
    232329            } 
    233330        } 
  • lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MEvent.as

    r15293 r20421  
    4040        public function setClose():void                       { set(MStatus.CLOSE, 0, 0); } 
    4141        public function setVolMode(m:int):void                { set(MStatus.VOL_MODE, m, 0); } 
     42        public function setInput(sens:int, pipe:int):void     { set(MStatus.INPUT, sens, pipe); } 
     43        public function setOutput(mode:int, pipe:int):void    { set(MStatus.OUTPUT, mode, pipe); } 
    4244        public function setDelta(delta:int):void              { m_delta = delta; } 
    4345        public function getStatus():int     { return m_status; } 
     
    6870        public function getLPFRes():int     { return m_data1; } 
    6971        public function getVolMode():int    { return m_data0; } 
     72        public function getInputSens():int  { return m_data0; } 
     73        public function getInputPipe():int  { return m_data1; } 
     74        public function getOutputMode():int { return m_data0; } 
     75        public function getOutputPipe():int { return m_data1; } 
    7076    } 
    7177} 
  • lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MML.as

    r19331 r20421  
    2121        protected var m_noteShift:int; 
    2222        protected var m_warning:String; 
     23        protected var m_maxPipe:int; 
     24        protected static var MAX_PIPE:int = 3; 
    2325 
    2426        public function MML() { 
     
    191193                m_tracks[m_trackNo].recGate2(getUInt(2) * 2); // '*2' according to TSSCP 
    192194                break; 
     195                /*case 'i': // Input 
     196                { 
     197                    var sens:int = 0; 
     198                    next(); 
     199                    sens = getUInt(sens); 
     200                    if (getChar() == ',') { 
     201                        next(); 
     202                        a = getUInt(a); 
     203                        if (a > m_maxPipe) a = m_maxPipe; 
     204                    } 
     205                    m_tracks[m_trackNo].recInput(sens, a); 
     206                } 
     207                // @i[n],[m]   m:pipe no 
     208                // if (n == 0) off 
     209                // else sensitivity = n (max:8) 
     210                break; 
     211            case 'o': // Output 
     212                { 
     213                    var mode:int = 0; 
     214                    next(); 
     215                    mode = getUInt(mode); 
     216                    if (getChar() == ',') { 
     217                        next(); 
     218                        a = getUInt(a); 
     219                        if (a > m_maxPipe) { 
     220                            m_maxPipe = a; 
     221                            if (m_maxPipe >= MAX_PIPE) m_maxPipe = a = MAX_PIPE; 
     222                        } 
     223                    } 
     224                    m_tracks[m_trackNo].recOutput(mode, a); 
     225                } 
     226                // @o[n],[m]   m:pipe no 
     227                // if (n == 0) off 
     228                // if (n == 1) overwrite 
     229                // if (n == 2) add 
     230                break;*/ 
    193231            default: 
    194232                m_form = getUInt(m_form); 
     
    436474        } 
    437475 
    438         protected function macroInMacro(str:String, idArr:Array, valArr:Array):String { 
     476        protected function macroInMacro(str:String, idArr:Array, valArr:Array, id0:String):String { 
     477            var idx:int; 
    439478            for(var i:int = 0; i < idArr.length; i++) { 
    440479                var id:String = "$"+idArr[i]; 
    441480                //trace("id:"+id); 
    442                 var idx:int = str.indexOf(id); 
     481                idx = str.indexOf(id); 
    443482                while(idx >= 0) { 
    444483                    str = str.substring(0, idx) + valArr[i] + str.substring(idx + id.length); 
    445484                    idx = str.indexOf(id, idx); 
    446485                } 
     486            } 
     487            // recursive call is prevented. 
     488            id0 = "$" + id0; 
     489            idx = str.indexOf(id0); 
     490            while(idx >= 0) { 
     491                str = str.substring(0, idx) + valArr[i] + str.substring(idx + id0.length); 
     492                idx = str.indexOf(id0, idx); 
     493                warning(MWarning.RECURSIVE_MACRO, id0); 
    447494            } 
    448495            return str; 
     
    454501            var idArr:Array = new Array(); 
    455502            var valArr:Array = new Array(); 
    456             var i:int; 
    457503            var last:int; 
    458504            // [a-zA-Z][a-zA-Z0-9#\+\(\)_]* 
     
    483529                                        // first definition 
    484530                                        if (idx < 0) { 
    485                                             token[1] = macroInMacro(token[1], idArr, valArr); 
     531                                            token[1] = macroInMacro(token[1], idArr, valArr, id[0]); 
    486532                                            //trace("define $"+id[i]+"="+token[1]); 
    487                                             insertLenOrder(idArr, valArr, id[i], token[1]); 
     533                                            insertLenOrder(idArr, valArr, id[0], token[1]); 
    488534                                        } 
    489535                                        // macro redefinition 
    490536                                        else { 
    491                                             token[1] = macroInMacro(token[1], idArr, valArr); 
     537                                            token[1] = macroInMacro(token[1], idArr, valArr, id[0]); 
    492538                                            //trace("redefine $"+id[i]+"="+token[1]); 
    493539                                            valArr[idx] = token[1]; 
     
    592638            m_form = MOscillator.PULSE; 
    593639            m_noteShift = 0; 
     640            m_maxPipe = 0; 
    594641 
    595642            processComment(str); 
     
    616663                m_sequencer.connect(m_tracks[i]); 
    617664            } 
     665            m_sequencer.createPipes(m_maxPipe+1); 
    618666 
    619667            // dispatch event 
  • lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MSequencer.as

    r15293 r20421  
    157157            //trace((endtime.getTime() - starttime.getTime()) + "msec."); 
    158158        } 
     159 
     160        public function createPipes(num:int):void { 
     161            MChannel.createPipes(num); 
     162        } 
    159163    } 
    160164} 
  • lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MStatus.as

    r18579 r20421  
    2525        public static const ENVELOPE2_AD:int = 22; 
    2626        public static const ENVELOPE2_SR:int = 23; 
     27        public static const INPUT:int        = 24; 
     28        public static const OUTPUT:int       = 25; 
    2729    } 
    2830} 
  • lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MTrack.as

    r19332 r20421  
    128128                                m_ch.setVolMode(e.getVolMode()); 
    129129                                break; 
     130                            case MStatus.INPUT: 
     131                                m_ch.setInput(e.getInputSens(), e.getInputPipe()); 
     132                                break; 
     133                            case MStatus.OUTPUT: 
     134                                m_ch.setOutput(e.getOutputMode(), e.getOutputPipe()); 
     135                                break; 
    130136                            case MStatus.CLOSE: 
    131137                                m_ch.close(); 
     
    345351            recDelta(e); 
    346352            e.setVolMode(m); 
     353            m_events.push(e); 
     354        } 
     355 
     356        public function recInput(sens:int, pipe:int):void { 
     357            var e:MEvent = new MEvent(); 
     358            recDelta(e); 
     359            e.setInput(sens, pipe); 
     360            m_events.push(e); 
     361        } 
     362 
     363        public function recOutput(mode:int, pipe:int):void { 
     364            var e:MEvent = new MEvent(); 
     365            recDelta(e); 
     366            e.setOutput(mode, pipe); 
    347367            m_events.push(e); 
    348368        } 
  • lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MWarning.as

    r2293 r20421  
    55        public static const UNOPENED_COMMENT:int = 2; 
    66        public static const UNCLOSED_COMMENT:int = 3; 
     7        public static const RECURSIVE_MACRO:int  = 4; 
    78        public static const s_string:Array = [ 
    89                                              "対応していないコマンド '%s' があります。", 
    910                                              "終わりが見つからない繰り返しがあります。", 
    1011                                              "始まりが見つからないコメントがあります。", 
    11                                               "終わりが見つからないコメントがあります。" 
     12                                              "終わりが見つからないコメントがあります。", 
     13                                              "マクロが再帰的に呼び出されています。", 
    1214                                              ]; 
    1315        public static function getString(warnId:int, str:String):String {