NScumm.Sky.Music.MusicBase.LoadNewMusic C# (CSharp) Method

LoadNewMusic() protected method

protected LoadNewMusic ( ) : void
return void
        protected void LoadNewMusic()
        {
            ushort musicPos;
            if (_onNextPoll.MusicToProcess > _musicData[_musicDataLoc])
            {
                // TODO: error
                //error("Music %d requested but doesn't exist in file.", _onNextPoll.musicToProcess);
                return;
            }
            if (_currentMusic != 0)
                StopMusicInternal();

            _currentMusic = _onNextPoll.MusicToProcess;

            if (_currentMusic == 0)
                return;

            // Try playing digital audio first (from the Music Enhancement Project).
            // TODO: This always prefers digital music over the MIDI music types!
            byte section = _currentSection;
            byte song = _currentMusic;
            // handle duplicates
            if ((section == 2 && song == 1) || (section == 5 && song == 1))
            {
                section = 1;
                song = 1;
            }
            else if ((section == 2 && song == 4) || (section == 5 && song == 4))
            {
                section = 1;
                song = 4;
            }
            else if (section == 5 && song == 6)
            {
                section = 4;
                song = 4;
            }

            // TODO: SeekableAudioStream
            //var trackName = string.Format("music_{0}{1,02}", section, song);
            //var stream = SeekableAudioStream.OpenStreamFile(trackName);
            //if (stream)
            //{
            //    // not all tracks should loop
            //    bool loops = true;
            //    if ((section == 0 && song == 1)
            //     || (section == 1 && song == 1) || (section == 1 && song == 4)
            //     || (section == 2 && song == 1) || (section == 2 && song == 4)
            //     || (section == 4 && song == 2) || (section == 4 && song == 3)
            //     || (section == 4 && song == 5) || (section == 4 && song == 6)
            //     || (section == 4 && song == 11) || (section == 5 && song == 1)
            //     || (section == 5 && song == 3) || (section == 5 && song == 4))
            //        loops = false;
            //    _musicHandle = _mixer.PlayStream(SoundType.Music, new LoopingAudioStream(stream, loops ? 0 : 1));
            //    return;
            //}

            // no digital audio, resort to MIDI playback
            musicPos = _musicData.ToUInt16(_musicDataLoc + 1);
            musicPos += (ushort)(_musicDataLoc + ((_currentMusic - 1) << 1));
            musicPos = (ushort)(_musicData.ToUInt16(musicPos) + _musicDataLoc);

            _musicTempo0 = _musicData[musicPos];
            _musicTempo1 = _musicData[musicPos + 1];

            SetupChannels(_musicData, musicPos + 2);

            UpdateTempo();
        }