Esempio n. 1
0
    /*
     *      Spawns a soundblock with specific values
     */
    public void SpawnSoundBlock(Vector3 position, int blockID, int clipId, bool isLooping)
    {
        Debug.Log("Spawning Soundblock " + blockID + " with " + clipId);
        GameObject blockGO = GameObject.Instantiate(SoundBlockPrefab, Vector3.zero, Quaternion.identity);

        blockGO.transform.SetParent(AppManager.Instance.GUIManager.scenarioOrigin, false);
        blockGO.transform.localPosition = position;

        // Set the audio on the soundblock
        SoundBlock soundBlock = blockGO.GetComponent <SoundBlock>();

        soundBlock.UpdateSoundlist();
        soundBlock.soundblockId = blockID;

        AudioSource source = soundBlock.GetComponent <AudioSource>();

        source.loop = isLooping;

        if (clipId != -1)
        {
            soundBlock.SetClip(AppManager.Instance.ResourcesManager.GetResource(clipId).Name);
        }

        // check if soundblock is the first, if so it is the entry point of the scenario
        if (blocks.Count == 0)
        {
            firstBlock = soundBlock;
            firstBlock.GetComponent <Image>().color = Color.green;
            firstBlock.rear.gameObject.SetActive(false);
        }

        blocks.Add(soundBlock);
        Debug.Log("Spawned Soundblock " + blockID);
    }
Esempio n. 2
0
    public void DrawLink(SoundBlock soundBlock)
    {
        if (!firstSoundblockClick)
        {
            firstSoundblockClick = soundBlock;
            GameObject go = GameObject.Instantiate(LinkPrefab, Vector3.zero, Quaternion.identity);
            go.transform.SetParent(firstSoundblockClick.transform);

            Link link = go.GetComponent <Link>();
            firstSoundblockClick.link = link;

            if (!firstSoundblockClick.source.loop)
            {
                firstSoundblockClick.link.IsActive = true;
            }
            else
            {
                firstSoundblockClick.link.IsActive = false;
            }

            link.previousBlock = firstSoundblockClick;
        }
        else if (firstSoundblockClick != soundBlock)
        {
            firstSoundblockClick.nextBlock      = soundBlock;
            firstSoundblockClick.link.nextBlock = soundBlock;

            StopDrawLink();
        }
    }
Esempio n. 3
0
    public void PlayScenario()
    {
        if (AudioListener.pause)
        {
            AudioListener.pause = false;
            return;
        }

        StopScenario();

        AudioSource audioSource = GetFreeAudioSource();

        if (!audioSource)
        {
            Debug.LogError("no free sequencer");
            return;
        }

        activeSoundblock  = scenarioManager.GetSoundBlock(scenarioManager.FirstBlock.soundblockId);
        activeAudiosource = audioSource;

        AudioClip clip = resourcesManager.GetResource(activeSoundblock.clipId).Clip;

        if (!clip)
        {
            Debug.LogError("no clip found for " + activeSoundblock.clipId);
            return;
        }

        audioSource.clip = clip;
        audioSource.Play();
        isPlaying = true;

        PrepareNextBlock();
    }
Esempio n. 4
0
    /*
     *      Draw a transition link between to soundblocks
     */
    public void DrawLink(SoundBlock FromSoundBlock, SoundBlock ToSoundBlock, LinkType linkType)
    {
        // Spawns link
        GameObject go = GameObject.Instantiate(LinkPrefab, Vector3.zero, Quaternion.identity);

        go.transform.SetParent(FromSoundBlock.transform, false);

        Link link = go.GetComponent <Link>();

        FromSoundBlock.link = link;

        link.previousBlock = FromSoundBlock;
        link.nextBlock     = ToSoundBlock;
        link.linkType      = linkType;

        // if the FROM block is looping, disable automatic transition
        if (!FromSoundBlock.source.loop)
        {
            FromSoundBlock.link.IsActive = true;
        }
        else
        {
            FromSoundBlock.link.IsActive = false;
        }

        FromSoundBlock.nextBlock = ToSoundBlock;
    }
Esempio n. 5
0
 public void SoundblockClicked(SoundBlock soundBlock)
 {
     if (IsDrawingLink)
     {
         DrawLink(soundBlock);
     }
 }
Esempio n. 6
0
    public void ClearScenario()
    {
        blocks.Clear();

        firstBlock = null;

        nextID = 0;
    }
Esempio n. 7
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="SoundPlaceSendEvent" /> class.
        /// </summary>
        /// <param name="layer">The layer.</param>
        /// <param name="x">The x-coordinate.</param>
        /// <param name="y">The y-coordinate.</param>
        /// <param name="block">The block.</param>
        /// <param name="soundId">The sound identifier.</param>
        public SoundPlaceSendEvent(Layer layer, int x, int y, SoundBlock block, uint soundId)
        {
            this.Block = block;
            this.X = x;
            this.Y = y;
            this.Layer = BlockUtils.CorrectLayer((Block)block, layer);

            this.SoundId = soundId;
        }
Esempio n. 8
0
    void Update()
    {
        if (AudioSettings.dspTime > nextTransitionTime && isPlaying)
        {
            Debug.Log("update");
            activeSoundblock  = nextSoundBlock;
            activeAudiosource = nextAudiosource;

            guiManager.ToggleNextPhaseButton(activeSoundblock.isLooping);

            nextTransitionTime = double.MaxValue;

            PrepareNextBlock();
        }
    }
Esempio n. 9
0
    public void StopScenario()
    {
        activeSoundblock   = null;
        activeAudiosource  = null;
        nextSoundBlock     = null;
        nextAudiosource    = null;
        nextTransitionTime = double.MaxValue;

        isPlaying = false;

        foreach (AudioSource audioSource in audioSources)
        {
            audioSource.Stop();
            audioSource.volume = 1;
            audioSource.clip   = null;
        }
    }
Esempio n. 10
0
    public void PrepareNextBlock()
    {
        if (activeSoundblock.nextBlock != null)
        {
            Debug.Log("prepare next block");

            nextAudiosource = GetFreeAudioSource();
            nextSoundBlock  = scenarioManager.GetSoundBlock(activeSoundblock.nextBlock.soundblockId);

            nextAudiosource.loop = nextSoundBlock.isLooping;
            nextAudiosource.clip = resourcesManager.GetResource(nextSoundBlock.clipId).Clip;

            if (!activeSoundblock.isLooping)
            {
                NextBlock();
            }
        }
    }
Esempio n. 11
0
    public void CreateSoundBlock(int blockID, int resourceID, bool isLooping)
    {
        Debug.Log("Spawning Soundblock " + blockID + " with " + resourceID);

        SoundBlock soundBlock = new SoundBlock();

        soundBlock.soundblockId = blockID;
        soundBlock.isLooping    = isLooping;
        soundBlock.clipId       = resourceID;

        if (blocks.Count == 0)
        {
            firstBlock = soundBlock;
        }

        blocks.Add(soundBlock);

        Debug.Log("Spawned Soundblock " + blockID);
    }
Esempio n. 12
0
    public void ResetScenario()
    {
        for (int i = 0; i < blocks.Count; i++)
        {
            if (blocks[i].link)
            {
                Destroy(blocks[i].link);
            }

            Destroy(blocks[i].gameObject);
        }

        blocks.Clear();

        AppManager.Instance.ResourcesManager.ClearResources();

        firstBlock       = null;
        activeSoundBlock = null;

        nextID = 0;
    }
Esempio n. 13
0
        private void _downFile(string filename, SoundBlock sb)
        {
            var result = Dos.Common.HttpHelper.Post <SFResult>(new Dos.Common.HttpParam()
            {
                Url     = @"https://user.api.hudunsoft.com/v1/alivoice/texttoaudio",
                Headers = new Dictionary <string, string>()
                {
                    { "origin", @"http://voice-pc.xunjiepdf.com" },
                    { "user-agent", @"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) voicedesktop/2.0.4 Chrome/66.0.3359.181 Electron/3.0.11 Safari/537.36" },
                    { "content-type", "application/x-www-form-urlencoded " }
                },
                PostParam = new
                {
                    client       = "pc",
                    source       = "335",
                    soft_version = "V2.0.4.0",
                    text         = sb.Content,
                    bgid         = 0,
                    bg_volume    = 1,
                    format       = "mp3",
                    voice        = "aimei",
                    volume       = sb.Volume,
                    speech_rate  = sb.Rate,
                    title        = sb.Content
                }
            });

            if (result != null && !string.IsNullOrWhiteSpace(result.data.file_link))
            {
                var r = Dos.Common.HttpHelper.GetStream(result.data.file_link);
                var s = System.IO.File.Create(filename);
                r.CopyTo(s);


                r.Close();
                s.Flush();
                s.Close();
            }
        }
Esempio n. 14
0
    private void PlayBlock(int blockId, BEAT_TIMING timing, Action callbackAtSoundBeginning = null)
    {
        SequencerOneshot shot = GetFreeSequencer();

        if (!shot)
        {
            Debug.LogError("no free sequencer");
            return;
        }

        activeSequencer = shot;

        actualBlock = scenarioManager.GetSoundBlock(blockId);
        AudioClip clip = resourcesManager.GetResource(actualBlock.clipId).Clip;

        if (!clip)
        {
            Debug.LogError("no clip for " + actualBlock.clipId);
            return;
        }

        shot.sequence[(int)timing] = true;
        shot.SetAudioClip(clip);
        shot.SetLoop(actualBlock.isLooping);
        shot.OnAnyStep += () => { Debug.Log("onanystep"); };
        shot.OnBeat    += () => { Debug.Log("onbeat"); };

        if (callbackAtSoundBeginning != null)
        {
            //shot.SetSoundBeginCallback(action);
        }

        if (actualBlock.nextBlock != null)
        {
            //shot.SetNextSoundCallback(NextSoundblock, BEAT_TIMING.ON_2);
        }
    }
Esempio n. 15
0
 public void UploadSound(int x, int y, SoundBlock block, PercussionId soundId)
 {
     this.Events.Raise(this.GetSound(x, y, block, soundId));
 }
Esempio n. 16
0
 public void DoLink(SoundBlock fromBlock, SoundBlock toBlock, LinkType linkType)
 {
     fromBlock.nextBlock = toBlock;
     fromBlock.linkType  = linkType;
 }
Esempio n. 17
0
 private void StopBlock(int blockId)
 {
     actualBlock = scenarioManager.GetSoundBlock(blockId);
     activeSequencer.Mute(true, 1.0f);
 }
Esempio n. 18
0
 public void StopDrawLink()
 {
     IsDrawingLink        = false;
     firstSoundblockClick = null;
 }
Esempio n. 19
0
        internal void SetSound(SoundBlock block, uint soundId)
        {
            this.BlockType = BlockType.Sound;
            this.Block = (Block)block;

            this._data = new BlockData
            {
                SoundId = soundId
            };
        }
Esempio n. 20
0
    public void SaveScenario()
    {
        ScenarioSave scenario = new ScenarioSave();

        scenario.resources = new ResourceData[AppManager.Instance.ResourcesManager.Count()];
        for (int i = 0; i < scenario.resources.Length; ++i)
        {
            ResourceData resourceData = new ResourceData();
            resourceData.id       = AppManager.Instance.ResourcesManager.Resources[i].Id;
            scenario.resources[i] = resourceData;
        }

        scenario.soundblocks = new SoundBlockData[blocks.Count];
        int linkCount = 0;

        for (int i = 0; i < blocks.Count; i++)
        {
            SoundBlockData blockData = new SoundBlockData();
            SoundBlock     block     = blocks[i];
            blockData.blockId = block.soundblockId;
            if (block.source.clip != null)
            {
                blockData.clipId = AppManager.Instance.ResourcesManager.GetResource(block.source.clip.name).Id;
            }
            else
            {
                blockData.clipId = -1;
            }

            if (firstBlock == block)
            {
                blockData.isFirstBlock = true;
            }

            blockData.isLooping = block.source.loop;
            blockData.position  = block.transform.localPosition;

            if (block.link != null)
            {
                linkCount++;
            }

            scenario.soundblocks[i] = blockData;
        }

        scenario.links = new LinkData[linkCount];
        int nextLinkIndex = 0;

        for (int i = 0; i < blocks.Count; i++)
        {
            if (blocks[i].link != null)
            {
                LinkData link = new LinkData();
                link.fromSoundblock = blocks[i].soundblockId;
                link.toSoundblock   = blocks[i].nextBlock.soundblockId;
                link.linkType       = blocks[i].link.linkType;
                link.isActive       = blocks[i].link.IsActive;

                scenario.links[nextLinkIndex] = link;
                nextLinkIndex++;
            }
        }

        scenario.soundBlockNextId = nextID;
        scenario.resourceNextId   = AppManager.Instance.ResourcesManager.nextResourceID;

        XmlSerializer writer = new XmlSerializer(scenario.GetType());

        using (FileStream stream = File.Create("structure"))
        {
            writer.Serialize(stream, scenario);
            stream.Close();
        }

        ZipFile zip = ZipFile.Read(scenarioUrl);

        zip.RemoveEntry("structure");
        zip.AddFile("structure");
        zip.Save(scenarioUrl);

        File.Delete("structure");

        Debug.Log("Saved Project " + scenarioUrl);
    }
Esempio n. 21
0
 public void StartSoundTrack()
 {
     firstBlock.PlaySound();
     activeSoundBlock = firstBlock;
     isPlaying        = true;
 }
Esempio n. 22
0
 public void SetActiveSoundBlock(SoundBlock active)
 {
     activeSoundBlock = active;
 }
Esempio n. 23
0
 public UploadRequestEvent GetSound(int x, int y, SoundBlock block, uint soundId)
 {
     var e = new SoundPlaceSendEvent(Layer.Foreground, x, y, block, soundId);
     return new UploadRequestEvent(e);
 }
Esempio n. 24
0
 public UploadRequestEvent GetSound(int x, int y, SoundBlock block, PercussionId soundId)
 {
     return this.GetSound(x, y, block, (uint)soundId);
 }
Esempio n. 25
0
 public void StopScenario()
 {
     actualBlock = null;
     driver.Stop();
 }