root/as3/SiOPM/trunk/src/org/si/sound/MultiTrackSoundObject.as

リビジョン 4451, 6.4 kB (コミッタ: keim, コミット時期: 1 年 前)

sion ver0.62 updated

Line 
1 //----------------------------------------------------------------------------------------------------
2 // Multi track Sound object
3 //  Copyright (c) 2009 keim All rights reserved.
4 //  Distributed under BSD-style license (see org.si.license.txt).
5 //----------------------------------------------------------------------------------------------------
6
7
8 package org.si.sound {
9     import org.si.sion.*;
10     import org.si.sion.sequencer.SiMMLTrack;
11     import org.si.sound.namespaces._sound_object_internal;
12     import org.si.sound.synthesizers.*;
13    
14    
15     /** The MultiTrackSoundObject class is the base class for all objects that can control plural tracks.
16      */
17     public class MultiTrackSoundObject extends SoundObject
18     {
19     // namespace
20     //----------------------------------------
21         use namespace _sound_object_internal;
22        
23        
24        
25        
26     // valiables
27     //----------------------------------------
28         /** @private [protected] mask for tracks operation. */
29         protected var _trackOperationMask:uint;
30        
31        
32        
33        
34     // properties
35     //----------------------------------------
36         /** Returns the number of tracks. */
37         public function get trackCount() : int { return (_tracks) ? _tracks.length : 0; }
38        
39        
40        
41        
42     // properties
43     //----------------------------------------
44         /** @private */
45         override public function get isPlaying() : Boolean { return (_tracks != null); }
46        
47        
48         /** @private */
49         override public function set coarseTune(n:int) : void {
50             super.coarseTune = n;
51             if (_tracks) {
52                 var i:int, f:uint, imax:int = _tracks.length;
53                 for (i=0, f=_trackOperationMask; i<imax; i++, f>>=1) {
54                     if ((f&1)==0) _tracks[i].noteShift = _noteShift;
55                 }
56             }
57         }
58        
59         /** @private */
60         override public function set fineTune(p:Number) : void {
61             super.fineTune = p;
62             if (_tracks) {
63                 var i:int, f:uint, imax:int = _tracks.length, ps:int = _pitchShift*64;
64                 for (i=0, f=_trackOperationMask; i<imax; i++, f>>=1) {
65                     if ((f&1)==0) _tracks[i].pitchShift = ps;
66                 }
67             }
68         }
69        
70         /** @private */
71         override public function set gateTime(g:Number) : void {
72             super.gateTime = g;
73             if (_tracks) {
74                 var i:int, f:uint, imax:int = _tracks.length;
75                 for (i=0, f=_trackOperationMask; i<imax; i++, f>>=1) {
76                     if ((f&1)==0) _tracks[i].quantRatio = _gateTime;
77                 }
78             }
79         }
80        
81         /** @private */
82         override public function set eventMask(m:int) : void {
83             super.eventMask = m;
84             if (_tracks) {
85                 var i:int, f:uint, imax:int = _tracks.length;
86                 for (i=0, f=_trackOperationMask; i<imax; i++, f>>=1) {
87                     if ((f&1)==0) _tracks[i].eventMask = _eventMask;
88                 }
89             }
90         }
91        
92         /** @private */
93         override public function set mute(m:Boolean) : void {
94             super.mute = m;
95             if (_tracks) {
96                 var i:int, f:uint, imax:int = _tracks.length;
97                 for (i=0, f=_trackOperationMask; i<imax; i++, f>>=1) {
98                     if ((f&1)==0) _tracks[i].channel.mute = _mute;
99                 }
100             }
101         }
102        
103         /** @private */
104         override public function set pan(p:Number) : void {
105             super.pan = p;
106             if (_tracks) {
107                 var i:int, f:uint, imax:int = _tracks.length;
108                 for (i=0, f=_trackOperationMask; i<imax; i++, f>>=1) {
109                     if ((f&1)==0) _tracks[i].channel.pan = _pan*64;
110                 }
111             }
112         }
113        
114        
115         /** @private */
116         override public function set pitchBend(p:Number) : void {
117             super.pitchBend = p;
118             if (_tracks) {
119                 var i:int, f:uint, pb:int = p*64, imax:int = _tracks.length;
120                 for (i=0, f=_trackOperationMask; i<imax; i++, f>>=1) {
121                     if ((f&1)==0) _tracks[i].pitchBend = pb;
122                 }
123             }
124         }
125        
126        
127        
128        
129     // constructor
130     //----------------------------------------
131         /** @private [protected] constructor */
132         function MultiTrackSoundObject(name:String = null, synth:VoiceReference = null) {
133             super(name, synth);
134             _tracks = null;
135             _trackOperationMask = 0;
136         }
137        
138        
139        
140        
141     // operations
142     //----------------------------------------
143         /** @private [protected] Reset */
144         override public function reset() : void
145         {
146             super.reset();
147             _trackOperationMask = 0;
148         }
149        
150        
151         /** you cannot call play() in MultiTrackSoundObject. */
152         override public function play() : void {
153             _errorNotAvailable("play()");
154         }
155        
156        
157         /** you cannot call stop() in MultiTrackSoundObject. */
158         override public function stop() : void {
159             _errorNotAvailable("stop()");
160         }
161        
162        
163         /** @private [protected] Stop all sound belonging to this sound object. */
164         protected function _stopAllTracks() : void {
165             if (_tracks) {
166                 for each (var t:SiMMLTrack in _tracks) {
167                     _synthesizer._unregisterTracks(t);
168                     t.setDisposable();
169                 }
170                 _tracks = null;
171             }
172             _stopEffect();
173         }
174        
175        
176         /** @private [protected] update stream send level */
177         override protected function _updateStreamSend(streamNum:int, level:Number) : void {
178             if (_tracks) {
179                 if (_effectChain) _effectChain.setStreamSend(streamNum, level);
180                 else {
181                     var i:int, f:uint, imax:int = _tracks.length;
182                     for (i=0, f=_trackOperationMask; i<imax; i++, f>>=1) {
183                         if ((f&1)==0) _tracks[i].channel.setStreamSend(streamNum, level);
184                     }
185                 }
186             }
187         }
188     }
189 }
190
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。