Ejemplo n.º 1
0
        public void ApplyState(
            MidiSynthConfigProto props,
            MidiSynthConfigProto.SequenceConfigProto state
            )
        {
            this.props = props;
            this.state = state;

            leftText.text = string.Format(
                "Track {0} (Tk{0})\n" +
                "Channel {1} (Ch{1})\n" +
                "{3} (Prog{2})", state.track, state.channel, state.program,
                state.channel == MIDI_PERCUSSION_CHANNEL ? "Percussion Set " + state.program : MidiProgramOptionFiller.names[state.program]);
            programOverrideDropdown.GetComponent <MidiProgramOptionFiller>().Start();
            programOverrideDropdown.value = state.programOverride;
            iconText.text = state.channel == MIDI_PERCUSSION_CHANNEL ? FA_DRUM : FA_MUSIC;

            var v            = state.shouldUseInGame ? 1 : .2f;
            var trackColor   = Color.HSVToRGB((float)state.trackGroup / props.trackGroupCount, 1, v);
            var channelColor = Color.HSVToRGB((float)state.channelGroup / props.channelGroupCount, 1, v);

            previewStartColor    = trackColor;
            previewStartColor.a  = 0;
            previewEndColor      = channelColor;
            trackColor.a         = iconFrameImage.color.a;
            iconFrameImage.color = trackColor;
            channelColor.a       = itemFrameImage.color.a;
            itemFrameImage.color = channelColor;

            if (state.shouldUseInGame)
            {
                button1Text.Translate("using in game");
            }
            else
            {
                button1Text.Translate("not using in game");
            }

            muteButtonText.text = state.isMuted ? FA_VOLUME_MUTE : FA_VOLUME_UP;
            muteButtonText.SetAlpha(state.isMuted ? .2f : 1f);
            if (props.soloSequenceIndex == -1 || props.soloSequenceIndex == state.sequenceIndex)
            {
                soloButtonText.text = FA_MICROPHONE;
                soloButtonText.SetAlpha(1);
            }
            else
            {
                soloButtonText.text = FA_MICROPHONE_SLASH;
                soloButtonText.SetAlpha(.2f);
            }

            shouldMute = state.isMuted || (props.soloSequenceIndex != -1 && props.soloSequenceIndex != state.sequenceIndex);

            enableCallback = true;
        }
Ejemplo n.º 2
0
        public void Start()
        {
            configPageGroup.gameObject.SetActive(false);
            pausePageGroup.gameObject.SetActive(false);

            startTime = Time.time;

            game_ = GameScheduler.instance;
            anim_ = AnimationManager.instance;

            if (game_.backgroundTexture != null)
            {
                backgroundImage.texture = game_.backgroundTexture;
            }

            switch (game_.gameplayConfig.layoutPreset)
            {
            //case GameplayConfigProto.LAYOUT_PRESET_SCANNING_LINE: gameplayManager = scanningLineGameplayManagerV2; break;
            default: gameplayManager = oneOnlyGameplayManager; break;
            }

            hasStarted = false;

            sf2File = new Sf2File(Resources.Load <TextAsset>("sf2/GeneralUser GS v1.471").bytes);

            var audioConfig = AudioSettings.GetConfiguration();

            sampleRate = audioConfig.sampleRate;
            sf2Synth   = new Sf2Synth(sf2File, new Sf2Synth.Table(sampleRate), 128);
            sf2Synth.SetVolume(-10);

            infoText.text = string.Format("{1}\n{0}\n{2}", game_.title, game_.subtitle, ((GameplayConfigProto.DifficaultyPresetEnum)game_.gameplayConfig.difficultyPreset).ToString());

            midiFile           = game_.midiFile ?? new MidiFile(Resources.Load <TextAsset>(testMidiPath).bytes);
            sequenceCollection = game_.noteSequenceCollection ?? new NoteSequenceCollection(midiFile);

            midiFileSha256Hash = MiscHelper.GetBase64EncodedSha256Hash(midiFile.bytes);

            cacheTicks = cacheBeats * midiFile.ticksPerBeat;
            endTicks   = sequenceCollection.end + (game_.gameplayConfig.graceTime + endDelayBeats) * midiFile.ticksPerBeat;

            midiSequencer         = new MidiSequencer(midiFile, sf2Synth);
            midiSequencer.isMuted = true;

            synthConfig = MidiSynthConfigProto.LoadOrCreateDefault(game_, sequenceCollection, midiFileSha256Hash);
            foreach (var seqConfig in synthConfig.sequenceStateList)
            {
                sf2Synth.ProgramChange(seqConfig.channel, (byte)seqConfig.programOverride);
                if (seqConfig.shouldUseInGame)
                {
                    gameSequences.Add(sequenceCollection.sequences[seqConfig.sequenceIndex]);
                }
                else if (!seqConfig.isMuted)
                {
                    backgroundSequences.Add(sequenceCollection.sequences[seqConfig.sequenceIndex]);
                }
            }
            sf2Synth.ignoreProgramChange = true;

            pausePageGroup.gameObject.SetActive(false);

            if (shouldLoadGameplayConfig)
            {
                LoadGameplayConfig();
            }
            scoringManager.Init(this);
            gameplayManager.Init(this);

            backgroundTracks = new BackgroundTrack[backgroundSequences.Count];
            for (int i = 0; i < backgroundTracks.Length; i++)
            {
                backgroundTracks[i] = new BackgroundTrack();
            }
            Debug.LogFormat("background tracks: {0}, game tracks: {1}", backgroundSequences.Count, gameSequences.Count);

            ShowReadyAnimation();
        }
Ejemplo n.º 3
0
        public override void Enable()
        {
            base.Enable();
            var audioConfig = AudioSettings.GetConfiguration();

            sampleRate           = audioConfig.sampleRate;
            audioConfigText.text = string.Format(
                "Sample Rate: {0:N0} Hz\n" +
                "DSP Buffer Size: {1:N0}\n" +
                "DSP Theoratical Delay: {2:N1} ms ({4:N1} Hz)\n" +
                "{3:N0} Channels\n\n",
                sampleRate, audioConfig.dspBufferSize,
                (float)audioConfig.dspBufferSize / sampleRate * 1000,
                (int)audioConfig.speakerMode, sampleRate / (float)audioConfig.dspBufferSize) +
                                   string.Format(
                "Model: {0}\n" +
                "Name: {1}\n" +
                "OS: {2}\n" +
                "CPU: {3}\n" +
                "GPU: {4}\n",
                SystemInfo.deviceModel, SystemInfo.deviceName,
                SystemInfo.operatingSystem, SystemInfo.processorType, SystemInfo.graphicsDeviceType);

            sf2Synth = new Sf2Synth(sf2File, new Sf2Synth.Table(sampleRate), 128);
            sf2Synth.SetVolume(-10);

            if (midiFile != null && level.midiDetailPage.midiFile == midiFile)
            {
                return;
            }
            sf2Synth.Reset();

            midiFile           = level.midiDetailPage.midiFile ?? new MidiFile(Resources.Load <TextAsset>("test").bytes);
            sequenceCollection = level.midiDetailPage.sequenceCollection ?? new NoteSequenceCollection(midiFile);
            midiFileSha256Hash = MiscHelper.GetBase64EncodedSha256Hash(midiFile.bytes);

            previewTicks = previewBeats * midiFile.ticksPerBeat;

            midiSequencer         = new MidiSequencer(midiFile, sf2Synth);
            midiSequencer.isMuted = true;

            state = MidiSynthConfigProto.LoadOrCreateDefault(game, sequenceCollection, midiFileSha256Hash);

            sequenceConfigItems = new SequenceConfigItemController[sequenceCollection.sequences.Count];
            int childCount = scrollViewContentRect.childCount;

            for (int i = 0; i < sequenceCollection.sequences.Count; i++)
            {
                var instance = i < childCount?scrollViewContentRect.GetChild(i).gameObject : Instantiate(sequenceConfigItemPrefab, scrollViewContentRect);

                instance.SetActive(true);
                var item = instance.GetComponent <SequenceConfigItemController>();
                sequenceConfigItems[i] = item;
                item.previewTrack.Reset();

                item.button1Action = () => {
                    item.state.shouldUseInGame = !item.state.shouldUseInGame;
                    item.ApplyState(item.props, item.state);
                };

                item.muteButtonAction = () => {
                    item.state.isMuted = !item.state.isMuted;
                    item.ApplyState(item.props, item.state);
                };

                item.soloButtonAction = () => {
                    if (state.soloSequenceIndex == item.state.sequenceIndex)
                    {
                        state.soloSequenceIndex = -1;
                    }
                    else
                    {
                        state.soloSequenceIndex = item.state.sequenceIndex;
                    }
                    ApplyState();
                };

                item.onProgramOverrideSelectChanged = value => {
                    sf2Synth.ignoreProgramChange = false;
                    sf2Synth.ProgramChange(item.state.channel, (byte)value);
                    sf2Synth.ignoreProgramChange = true;
                };
            }

            for (int i = sequenceCollection.sequences.Count; i < childCount; i++)
            {
                scrollViewContentRect.GetChild(i).gameObject.SetActive(false);
            }

            ApplyState();
        }