Ejemplo n.º 1
0
    // loads and plays song
    private IEnumerator LoadTrack(string path, SongParser.Metadata _metadata)
    {
        Debug.Log(path);
        string _url = string.Format("file://{0}", path);
        //UnityWebRequest _unityWebRequest = new UnityWebRequest(_url);

        //while (!_unityWebRequest.isDone)
        //{
        //    yield return null;
        //}

        //_unityWebRequest = UnityWebRequestMultimedia.GetAudioClip(_url, AudioType.MPEG);
        //audioSource.clip = DownloadHandlerAudioClip.GetContent(_unityWebRequest);

        WWW _www = new WWW(_url);

        while (!_www.isDone)
        {
            yield return(null);
        }

        AudioClip _clip = NAudioPlayer.FromMp3Data(_www.bytes);

        audioSource.clip = _clip;

        Debug.Log("Loaded.");

        songLoaded = true;

        audioSource.Play();

        GameObject _controller = GameObject.FindGameObjectWithTag("GameController");

        _controller.GetComponent <NoteGenerator>().InitNotes(_metadata);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Writes the .mn file using the provided song data.
    /// </summary>
    /// <param name="songData">Song data to write the notes to.</param>
    /// <param name="targetPath">Target path to write the song to.</param>
    public void Write(SongParser.Metadata songData, string targetPath)
    {
        List <string> _fileData = new List <string>();

        string _currLine = "";

        // write title
        _currLine = "#TITLE:" + songData.title + ";";
        _fileData.Add(_currLine);

        // write subtitle
        _currLine = "#SUBTITLE:" + songData.subtitle + ";";
        _fileData.Add(_currLine);

        // write artist
        _currLine = "#ARTIST:" + songData.artist + ";";
        _fileData.Add(_currLine);

        // write banner path
        _currLine = "#BANNER:" + songData.bannerPath + ";";
        _fileData.Add(_currLine);

        // write background path
        _currLine = "#BACKGROUND:" + songData.backgroundPath + ";";
        _fileData.Add(_currLine);

        // write music path
        _currLine = "#MUSIC:" + songData.musicPath + ";";
        _fileData.Add(_currLine);

        // write offset
        _currLine = "#OFFSET:" + songData.offset + ";";
        _fileData.Add(_currLine);

        // write sample start
        _currLine = "#SAMPLESTART:" + songData.sampleStart + ";";
        _fileData.Add(_currLine);

        // write sample length
        _currLine = "#SAMPLELENGTH:" + songData.sampleLength + ";";
        _fileData.Add(_currLine);

        // write bpm
        _currLine = "#BPM:" + songData.bpm + ";";
        _fileData.Add(_currLine);

        _currLine = Environment.NewLine;
        _fileData.Add(_currLine);

        // write notes
        List <string> _fileDataNotes = WriteNotes(songData.noteData);

        _fileData.AddRange(_fileDataNotes);

        targetPath = targetPath + "/" + songData.musicPath.Remove(songData.musicPath.Length - 4) + ".mn";

        File.WriteAllLines(targetPath, _fileData.ToArray());
    }
Ejemplo n.º 3
0
    // Start is called before the first frame update
    private void Start()
    {
        audioSource = GetComponent <AudioSource>();

        SongParser.Metadata _metadata = GameData.chosenSongData;

        StartCoroutine(LoadTrack(_metadata.musicPath, _metadata));

        isPaused = false;
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Initialises and starts recording.
    /// </summary>
    /// <param name="_songData">Song data to write the notes to.</param>
    /// <param name="_targetPath">Target path to write the song to.</param>
    public void InitRecording(SongParser.Metadata _songData, string _targetPath)
    {
        barTime = (60.0f / _songData.bpm) * 4.0f;

        songData   = _songData;
        targetPath = _targetPath;

        StartCoroutine(Record());

        promptText.text = "RECORDING";
    }
Ejemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            SongParser.Metadata _tempSongData = new SongParser.Metadata();

            _tempSongData.title          = "JOURNEI";
            _tempSongData.subtitle       = "";
            _tempSongData.artist         = "Hans";
            _tempSongData.bannerPath     = "";
            _tempSongData.backgroundPath = "";
            _tempSongData.musicPath      = "JOURNEI.mp3";
            _tempSongData.offset         = 0.0f;
            _tempSongData.sampleStart    = 97.33f;
            _tempSongData.sampleLength   = 10.58f;
            _tempSongData.bpm            = 125;

            SongParser.NoteData     _tempNoteData = new SongParser.NoteData();
            List <SongParser.Notes> _tempBar      = new List <SongParser.Notes>();
            SongParser.Notes        _tempNotes    = new SongParser.Notes();

            _tempNotes.bottom = 0;
            _tempNotes.middle = SongParser.NoteType.Air;
            _tempNotes.top    = 0;

            _tempBar.Add(_tempNotes);

            _tempNoteData.bars = new List <List <SongParser.Notes> >();
            _tempNoteData.bars.Add(_tempBar);

            _tempSongData.noteData = _tempNoteData;

            SongWriter _songWriter = new SongWriter();
            _songWriter.Write(_tempSongData, Application.persistentDataPath);

            Debug.Log("Song should be written now.");
        }
    }
Ejemplo n.º 6
0
    // iniatialises variables and sets arrow speed
    public void InitNotes(SongParser.Metadata newSongData)
    {
        songData = newSongData;
        isInit   = true;
        // Debug.Log("isInit set to: " + isInit);

        // estimate how many seconds a single 'bar' will be in the
        // song using the bpm in song data
        // Debug.Log("BPM: " + songData.bpm);
        barTime = (60.0f / songData.bpm) * 4.0f;
        Debug.Log("barTime: " + barTime);

        distance = originalDistance;
        // Debug.Log("distance: " + distance);

        // TO-DO: Integrate note speed into song data
        // how fast the arrow will be going
        if (noteSpeed <= 0.0f)
        {
            noteSpeed = 0.05f;
        }
        // noteSpeed = 0.009f; // TEMPORARY MAGIC NUMBER
        noteData = songData.noteData;
    }
Ejemplo n.º 7
0
    private void OnGUI()
    {
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Audio Source");
        audioSource = (AudioSource)EditorGUILayout.ObjectField(audioSource, typeof(AudioSource), true);
        EditorGUILayout.EndHorizontal();

        if (audioSource != null)
        {
            if (EditorApplication.isPlaying)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Note Recorder");
                noteRecorder = (NoteRecorder)EditorGUILayout.ObjectField(noteRecorder, typeof(NoteRecorder), true);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Music File");
                musicClip = (AudioClip)EditorGUILayout.ObjectField(musicClip, typeof(AudioClip), false);
                EditorGUILayout.EndHorizontal();

                if (audioSource.clip != musicClip)
                {
                    audioSource.clip = musicClip;
                }

                if (GUILayout.Button("Load Music"))
                {
                    musicPath = EditorUtility.OpenFilePanel("Load Music File", "", "mp3");

                    if (musicPath.Length != 0)
                    {
                        musicClip = LoadMusic(musicPath);
                    }
                }

                if (musicClip != null && noteRecorder != null)
                {
                    DrawMNFileSettings();

                    if (IsMNDataValid())
                    {
                        if (GUILayout.Button("Start Recording"))
                        {
                            songData                = new SongParser.Metadata();
                            songData.title          = songTitle;
                            songData.subtitle       = subtitle;
                            songData.artist         = artist;
                            songData.bannerPath     = bannerPath;
                            songData.backgroundPath = backgroundPath;
                            songData.musicPath      = Path.GetFileName(musicPath);
                            songData.offset         = offset;
                            songData.sampleStart    = sampleStart;
                            songData.sampleLength   = sampleLength;
                            songData.bpm            = bpm;

                            string _targetPath = musicPath.Replace(Path.GetFileName(musicPath), "");

                            audioSource.Play();
                            noteRecorder.InitRecording(songData, _targetPath);
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("Song title, artist, and BPM must be valid to start recording.", MessageType.Warning);
                    }
                }
                else
                {
                    if (musicClip == null)
                    {
                        EditorGUILayout.HelpBox("Load a music file to start recording.", MessageType.Info);
                    }

                    if (noteRecorder == null)
                    {
                        EditorGUILayout.HelpBox("A Note Recorder from the scene is required.", MessageType.Info);
                    }
                }
            }
            else
            {
                EditorGUILayout.HelpBox("Enter Playmode to start recording.", MessageType.Info);
            }
        }
        else
        {
            EditorGUILayout.HelpBox("An Audio Source from the scene is required.", MessageType.Info);
        }
    }
Ejemplo n.º 8
0
    // a method to parse all song files in directory
    private void Parse()
    {
        Debug.Log("Parsing.");
        DirectoryInfo _info = new DirectoryInfo(GameData.songDirectory);

        FileInfo[] _mnFiles = _info.GetFiles("*.mn", SearchOption.AllDirectories);
        Debug.Log("Parsing Directory: " + GameData.songDirectory + " | Amount: " + _mnFiles.Length);

        for (int i = 0; i < _mnFiles.Length; i++)
        {
            SongParser _parser = new SongParser();
            Debug.Log("Full name: " + _mnFiles[i].FullName);
            SongParser.Metadata _songData = _parser.Parse(_mnFiles[i].FullName);

            audioStartTime = _songData.sampleStart;
            audioLength    = _songData.sampleLength;

            if (!_songData.valid)
            {
                Debug.Log("Song data is not valid.");
                // song data isn't valid
                continue;
            }
            else
            {
                GameObject _songObj = (GameObject)Instantiate(songSelectionPrefab, songSelectionList.transform.position, Quaternion.identity);
                _songObj.GetComponentInChildren <TMP_Text>().text = _songData.title + " - " + _songData.artist;
                // _songObj.transform.parent = songSelectionList.transform;
                _songObj.transform.SetParent(songSelectionList.transform, false);
                _songObj.transform.localScale = new Vector3(1, 1, 1); // reset scale just in case scale changes

                // get access to button control
                Button _songButton = _songObj.GetComponentInChildren <Button>();
                if (File.Exists(_songData.bannerPath))
                {
                    Texture2D texture = new Texture2D(766, 182);
                    texture.LoadImage(File.ReadAllBytes(_songData.bannerPath));
                    Debug.Log(_songData.bannerPath);
                    _songButton.image.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100.0f);
                }

                _songButton.onClick.AddListener(delegate { StartSong(_songData); });

                EventTrigger.Entry entry = new EventTrigger.Entry();
                entry.eventID = EventTriggerType.PointerEnter;
                entry.callback.AddListener(eventData => { if (_songData.musicPath != currentSongPath)
                                                          {
                                                              StartCoroutine(PreviewTrack(_songData.musicPath));
                                                          }
                                           });

                _songButton.GetComponent <EventTrigger>().triggers.Add(entry);

                // check if a highscore for this song exists
                // if not, create it
                if (!GameData.currentSavedData.highscores.ContainsKey(_songData.title))
                {
                    GameData.currentSavedData.highscores.Add(_songData.title, 0.0f);
                }

                _songObj.GetComponentInChildren <TMP_Text>().text += string.Format("{0}Highscore: {1}", '\n', GameData.currentSavedData.highscores[_songData.title]);
            }
        }
    }
Ejemplo n.º 9
0
 // transitions from song selection to in-game
 private void StartSong(SongParser.Metadata songData)
 {
     Debug.Log(songData.title + " chosen.");
     GameData.chosenSongData = songData;
     SceneManager.LoadScene("InGame");
 }