コード例 #1
0
    public void GenerateTrack()
    {
        if (string.IsNullOrEmpty(songDataJsonString) || !audioSource.clip)
        {
            UIEventManager.FireAlert("NOT ALL FILES PRESENT", "ERROR");
            return;
        }

        //songPixelSize = Mathf.CeilToInt(audioSource.clip.length * secondInPixels);
        songPixelSize = Mathf.CeilToInt(audioSource.clip.length * TimetrackerPanelCtrl.SECOND_IN_PIXELS);
        int numOfChuncks   = Mathf.CeilToInt(audioSource.clip.length / secondsPerWavImage);
        int samplesInChunk = (int)sampleRate * secondsPerWavImage;
        //int chunkPixelSize = secondsPerWavImage * secondInPixels;
        int      chunkPixelSize = secondsPerWavImage * TimetrackerPanelCtrl.SECOND_IN_PIXELS;
        int      startSample    = 0;
        int      endSample      = 0;
        RawImage wavImageGO;

        for (int c = 0; c < numOfChuncks; c++)
        {
            startSample = samplesInChunk * c;
            endSample   = Mathf.Min(samplesInChunk * (c + 1), audioSource.clip.samples);
            //chunkPixelSize = Mathf.FloorToInt((endSample - startSample) / (sampleRate / secondInPixels));
            chunkPixelSize = Mathf.FloorToInt((endSample - startSample) / (sampleRate / TimetrackerPanelCtrl.SECOND_IN_PIXELS));
            wavImageGO     = Instantiate(wavImagePrefab, wavimagesPanel.transform, false) as RawImage;
            wavImageGO.rectTransform.sizeDelta = new Vector2(chunkPixelSize, wavImageHeight);
            wavImageGO.texture = AudioDrawer.CreateAudioTexturePiece(audioSource.clip, chunkPixelSize, wavImageHeight, Color.grey, startSample, endSample);
        }

        //wavImage.rectTransform.sizeDelta = new Vector2(songPixelSize, wavImageHeight);
        //wavImage.texture = AudioDrawer.CreateAudioTexture(audioSource.clip, songPixelSize, wavImageHeight, Color.grey);
        // wavImage.texture = AudioDrawer.CreateAudioTexturePiece(audioSource.clip, songPixelSize, wavImageHeight, Color.grey, 0, audioSource.clip.samples);

        float      pozX       = 0;
        float      pozY       = 0;
        int        numOfwords = songDataFromJson.wordsList.Length;
        Image      wordGO;
        Button     btn;
        WordButton wordButtonCls;

        for (int i = 0; i < numOfwords; i++)
        {
            // pozX = float.Parse(songDataFromJson.wordsList[i].time) * secondInPixels;
            pozX          = float.Parse(songDataFromJson.wordsList[i].time) * TimetrackerPanelCtrl.SECOND_IN_PIXELS;
            wordGO        = Instantiate(wordPrefabClickable, wordsHolder.transform, false);
            btn           = wordGO.transform.GetComponent <Button>();
            wordButtonCls = wordGO.transform.GetComponent <WordButton>();
            wordButtonCls.SetWordData(songDataFromJson.wordsList[i]);
            wordButtonCls.SetDurrationMarker(TimetrackerPanelCtrl.SECOND_IN_PIXELS);
            //wordButtonCls.wordData = songDataFromJson.wordsList[i];
            //wordButtonCls.label.text = wordButtonCls.wordData.text.ToString();
            wordGO.name = string.Format("{0}_{1}", songDataFromJson.wordsList[i].text, songDataFromJson.wordsList[i].time);
            pozY        = (150) + ((i % 3) * 20);
            wordGO.rectTransform.anchoredPosition = new Vector3(pozX, pozY, 0);
            wordGO.tag = "word";
        }
    }
コード例 #2
0
    IEnumerator ShowSaveDialogCoroutine(string jsonToSaveString)
    {
        yield return(FileBrowser.WaitForSaveDialog(false, null));

        if (FileBrowser.Success)
        {
            File.WriteAllText(FileBrowser.Result, jsonToSaveString);
            UIEventManager.FireAlert("Saved to: " + FileBrowser.Result, "SAVE SUCCESS");
        }
    }
コード例 #3
0
    // SAVING SONG

    public void OpenSaveDialog()
    {
        if (string.IsNullOrEmpty(songDataJsonString))
        {
            UIEventManager.FireAlert("NO DATA TO SAVE", "SAVE ERROR");
            return;
        }

        FileBrowser.SetDefaultFilter(".json");
        StartCoroutine(ShowSaveDialogCoroutine());
    }
コード例 #4
0
 public void PreviewSong()
 {
     if (songDataFromJson != null && audioSource.clip != null)
     {
         songPlayer.PreviewSong(audioSource, songDataFromJson, float.Parse(speedField.text));
     }
     else
     {
         UIEventManager.FireAlert("Load JSON and WAV!", "ERROR");
     }
 }
コード例 #5
0
    public void OnGenerateTrackButton()
    {
        if (string.IsNullOrEmpty(songDataJsonString) || !audioSource.clip)
        {
            UIEventManager.FireAlert("NOT ALL FILES PRESENT", "ERROR");
            return;
        }

        // Clear the visual representatives for words and wav
        ResetTrack();
        GenerateTrack();
    }
コード例 #6
0
    IEnumerator ShowLoadDialogCoroutine(string fileType)
    {
        yield return(FileBrowser.WaitForLoadDialog(false, null, "Open " + fileType, "Load"));

        if (FileBrowser.Success)
        {
            StartCoroutine(LoadFile(FileBrowser.Result, fileType));
        }
        else
        {
            UIEventManager.FireAlert("Error opening file", "ERROR");
            ResetFields();
        }
    }
コード例 #7
0
    public void CreateTracker()
    {
        if (string.IsNullOrEmpty(songDataJsonString) || !audioSource.clip)
        {
            UIEventManager.FireAlert("NOT ALL FILES PRESENT", "ERROR");
            return;
        }

        trackView.SetActive(true);
        beatSynchroniser.bpm        = (float)songDataFromJson.bpm;
        beatSynchroniser.startDelay = 1;
        beatCounter.beatValue       = SynchronizerData.BeatValue.SixteenthBeat;

        sixteenNoteToSecondsSize = (60f / (float)songDataFromJson.bpm) / 4f;
        onePixelToSeconds        = sixteenNoteToSecondsSize / sixteenNoteToPixelSize;
        Debug.Log("sixteenNoteToSecondsSize " + sixteenNoteToSecondsSize);
        Debug.Log("onePixelToSeconds " + onePixelToSeconds);

        //populate words
        //float pozX;
        //int numOfwords = songDataFromJson.words.Length;
        //for(int i = 0; i< numOfwords; i++)
        //{
        //    pozX = float.Parse(songDataFromJson.timestamps[i]) / onePixelToSeconds;
        //    Debug.Log(pozX);
        //    Instantiate(wordPrefab, wordsHolder.transform, false);
        //    wordPrefab.text = songDataFromJson.words[i].ToString();

        //    wordPrefab.rectTransform.anchoredPosition= new Vector3(pozX, 0, 0);
        //}


        beatCounter.StartCountingBeats();
        beatSynchroniser.StartSynchronisedMusic();



        rawImg.texture = AudioWaveForm(audioSource.clip, (int)Mathf.Floor(rawImg.rectTransform.rect.width), (int)Mathf.Floor(rawImg.rectTransform.rect.height), new Color(210, 210, 210));

        debugString = string.Empty;
        //float samplesPerQuarterNote = ((float)songDataFromJson.bpm / 60) * 44100;
        float samplesPerQuarterNote = Mathf.CeilToInt(44100 / ((float)songDataFromJson.bpm / 60));
        float samplesPerBar         = samplesPerQuarterNote * 4;
        float barInSong             = Mathf.Ceil((float)audioSource.clip.samples / (float)samplesPerBar);

        debugString    = string.Format("Song name: {0} \nSong BPM: {1} \nTotal Samples: {2} \nSamlpes per 1/4 note: {3} \nSamples per bar: {4} \nTotal Bar Count: {5} \nSong Time: {6} sec", songDataFromJson.songname, songDataFromJson.bpm, audioSource.clip.samples, samplesPerQuarterNote, samplesPerBar, barInSong, audioSource.clip.length);
        debugText.text = debugString;
    }
コード例 #8
0
    // SAVING SONG

    public void OpenSaveDialog()
    {
        if (wordsHolder.transform.childCount < 1 || wavimagesPanel.transform.childCount < 1)
        {
            UIEventManager.FireAlert("Generate track first", "SAVE ERROR");
            return;
        }


        if (string.IsNullOrEmpty(songDataJsonString))
        {
            UIEventManager.FireAlert("NO DATA TO SAVE", "SAVE ERROR");
            return;
        }

        FileBrowser.SetDefaultFilter(".json");
        StartCoroutine(ShowSaveDialogCoroutine());
    }
コード例 #9
0
    IEnumerator ShowSaveDialogCoroutine()
    {
        // Show a load file dialog and wait for a response from user
        // Load file/folder: file, Initial path: default (Documents), Title: "Load File", submit button text: "Load"
        yield return(FileBrowser.WaitForSaveDialog(false, null));

        // Dialog is closed
        // Print whether a file is chosen (FileBrowser.Success)
        // and the path to the selected file (FileBrowser.Result) (null, if FileBrowser.Success is false)
        //Debug.Log(FileBrowser.Success + " " + FileBrowser.Result);
        if (FileBrowser.Success)
        {
            string jsonToSave = JsonMapper.ToJson(songDataFromJson);
            //jsonOutputTxt.text = jsonToSave;
            string pathToSave = (IsStringEndsWith(FileBrowser.Result, ".json")) ? FileBrowser.Result : FileBrowser.Result + ".json";
            File.WriteAllText(FileBrowser.Result, jsonToSave.ToString());

            UIEventManager.FireAlert("Saved to: " + FileBrowser.Result, "SAVE SUCCESS");
        }
    }
コード例 #10
0
    // SAVING PART
    public void SaveToJson()
    {
        if (matchWords.Count < 1 || matchTimestamps.Count < 1)
        {
            UIEventManager.FireAlert("Please merge lyrics with text first", "NO LYRICS OR TIMESTAMPS");
            return;
        }
        if (string.IsNullOrEmpty(songNameTxt.text) || string.IsNullOrEmpty(songArtist.text) || string.IsNullOrEmpty(songBPMTxt.text))
        {
            UIEventManager.FireAlert("Please populate song name, artist and BPM", "NO SONG INFO FOUND");
            return;
        }

        SongData song = new SongData();

        song.songname     = songNameTxt.text;
        song.bpm          = int.Parse(songBPMTxt.text);
        song.artist       = songArtist.text;
        song.mp3dealy     = 0;
        song.timeOnScreen = 1;

        //song.words = songWords;
        //song.timestamps = songTimestamps;
        song.wordsList = wordsList;

        string jsonToSave = JsonMapper.ToJson(song);

        jsonOutputTxt.text = jsonToSave;

        FileBrowser.SetDefaultFilter(".json");
        StartCoroutine(ShowSaveDialogCoroutine(jsonToSave.ToString()));

        //File.WriteAllText(Application.persistentDataPath + "/" + song.artist + "_" + song.songname+".json", jsonToSave.ToString());

        //UIEventManager.FireAlert("File Saved to " + Application.persistentDataPath + "/" + song.artist + "_" + song.songname + ".json", "SUCCESS");
    }
コード例 #11
0
    public void MergeLyricsAndTimes()
    {
        if (string.IsNullOrEmpty(lyricsString))
        {
            UIEventManager.FireAlert("Not all files prsent !", "ALERT");
            return;
        }

        // remove first 5 lines and the last one;
        string[]      remN   = lyricsString.Split('\n');
        List <string> strLst = new List <string>(remN);

        strLst.RemoveRange(0, 5);
        strLst.RemoveRange(strLst.Count - 2, 2);
        string strFromLst = String.Join(" ", strLst.ToArray());

        // remove line breaks
        string stringOneLine = Regex.Replace(strFromLst, @"\r\n?|\n", String.Empty);

        // replace < and > for [ and ] and add one "[" at the end
        string strClean = StringExtention.clean(stringOneLine) + "[";

        jsonOutputTxt.text = strClean;

        // pull out all the timestamps from mm:ss.ss
        string patternTimestamps = @"\d\:\d{1,2}.\d{1,2}";

        matchTimestamps = Regex.Matches(strClean, patternTimestamps);

        // pull the words between ] and [
        string patternWords = @"\](.*?)\[";

        matchWords = Regex.Matches(strClean, patternWords);

        if (matchWords.Count != matchTimestamps.Count)
        {
            UIEventManager.FireAlert("Count doesn't match \n" + "lyrics lines: " + matchWords.Count + " - vs - " + "timestamps lines: " + matchTimestamps.Count, "WORD COUNT MISSMATCH");
            return;
        }

        //Debug.Log("All is OK... proceed");

        //songWords = new string[matchWords.Count];
        int i = 0;
        int w = matchWords.Count;
        // for (i = 0; i < w; i++)
        //{
        //songWords[i] = matchWords[i].ToString().TrimStart(']', ' ').TrimEnd('[');
        // }

        //songTimestamps = new string[matchTimestamps.Count];
        // int n = matchTimestamps.Count;
        //for (i = 0; i < n; i++)
        //{
        //songTimestamps[i] = formatTimeToSeconds(matchTimestamps[i].ToString());
        //}

        WordData word;
        string   clearedStr;
        string   trimedStr;

        wordsList = new WordData[matchWords.Count];
        for (i = 0; i < w; i++)
        {
            word         = new WordData();
            clearedStr   = matchWords[i].ToString().TrimStart(']', ' ').TrimEnd('[');
            trimedStr    = clearedStr.TrimEnd();
            word.text    = trimedStr;
            word.time    = formatTimeToSeconds(matchTimestamps[i].ToString());
            word.index   = i;
            wordsList[i] = word;
        }

        //// Proceed to Save
        SaveToJson();
    }