Exemple #1
0
        public DrumPlayer(AudioEngine audioEngine)
        {
            playing = new bool[NO_OF_INSTRUMENTS];
            switchFlag = true;
            random = new Random();
            int[][] loopTrace = new int[NO_OF_INSTRUMENTS][];
            for (int i = 0; i < NO_OF_INSTRUMENTS; i++)
            {
                loopTrace[i] = InitializeLoop(SIZE, 0, 1, 1);
            }

            loop = new DrumLoop(loopTrace);
            positionPointer = 0;
            this.audioEngine = audioEngine;
            drumSoundBank = new SoundBank(audioEngine, "Content/Drum Sound Bank.xsb");
            drumWaveBank = new WaveBank(audioEngine, "Content/Drum Bank.xwb");
        }
        public DrumPlayer(AudioEngine audioEngine)
        {
            barSizeInClicks = music.TimeSignature.number * music.ClicksPerBeat;
            random = new Random();

            #region Loading Drums
            instruments = new LinkedList<Instrument>();
            instruments.Add(new Instrument(200, "bassdrum"));
            instruments.Add(new Instrument(10, "tambourine"));
            instruments.Add(new Instrument(200, "kickdrum"));
            instruments.Add(new Instrument(200, "snaredrum"));
            instruments.Add(new Instrument(10, "kettledrum"));
            instruments.Add(new Instrument(10, "triangle"));
            instruments.Add(new Instrument(10, "rattle"));
            instruments.Add(new Instrument(100, "hihat"));
            instruments.Add(new Instrument(10, "cowbell"));
            #endregion
            #region DrumLoop initialization
            int[][] loopTrace = new int[NO_OF_INSTRUMENTS][];
            bool[] playing = new bool[NO_OF_INSTRUMENTS];
            for (int i = 0; i < NO_OF_INSTRUMENTS; i++)
            {
                loopTrace[i] = InitializeEmptyLoop(barSizeInClicks);
            }

            loopTrace[(int)InstrumentName.bassdrum] = InitializeLoop(barSizeInClicks, 1, (int)InstrumentName.bassdrum);
            playing[(int)InstrumentName.bassdrum] = true;

            int[][] futureLoopTrace = new int[loopTrace.Length][];
            bool[] futurePlaying = new bool[playing.Length];
            for (int i = 0; i < loopTrace.Length; i++)
            {
                futureLoopTrace[i] = new int[loopTrace[i].Length];
                Array.Copy(loopTrace[i], futureLoopTrace[i], loopTrace[i].Length);
            }
            Array.Copy(playing, futurePlaying, playing.Length);
            
            drumLoop = new DrumLoop(loopTrace, playing, futureLoopTrace, futurePlaying);
            #endregion



            this.audioEngine = audioEngine;
            soundBanks = new LinkedList<SoundBank>();
            soundBanks.Add(new SoundBank(audioEngine, "Content/Drum Sound.xsb"));

            //Calling onBar twice because of the needs to initialize the voices in the model and the drumLoop
            //both of these need to know what is going to happen next bar.
            OnBar();
            OnBar();

            audioEngine.GetCategory("Drums").SetVolume(drumVolume);
        }