Esempio n. 1
0
    void alphabetizeByAlbum()
    {
        GameObject[] audioHolders = new GameObject[10000]; //temporary placeholder max size

        print (musicFiles.Count);

        foreach(FileInfo f in musicFiles) {
            //print("Loading "+f.FullName);
            GameObject audioHolder = new GameObject(f.Name);
            audioHolders[songIndex] = audioHolder;
            songIndex++;

            ID3v1 tagger = new ID3v1();

            FileStream mp3Stream = new FileStream(f.FullName, FileMode.Open);

            Mp3File currentMP3 = new Mp3File(f);

            currentMP3.Update();

            tagger.Deserialize(mp3Stream);

            mp3Stream.Close();

            string album = tagger.Album;

            //print ("album: " + album);

            for (int i = 0; i < alphabeticalTitles.Length; i++) {

                string firstChar = alphabeticalTitles.GetValue(i).ToString().Substring(5,1);

                if (album.StartsWith(firstChar)) {

                    audioHolder.transform.parent = alphabeticalTitles[i].transform;

                }

            }
        }

        return;
    }
        /// <summary>
        /// copy the newdata to the original.
        /// </summary>
        /// <param name="newData"></param>
        /// <param name="orig"></param>
        /// <returns>always true</returns>
        public static bool makeChangesAndContinue(TagHandlerUpdate newData,  Mp3File orig)
        {
            newData.copy(orig.TagHandler);

            var retrycount = 0;
            var maxretry = 10;
            retry:
            try
            {
                orig.Update();
            }
            catch (Exception ecp)
            {
                retrycount++;
                if (retrycount >= maxretry)
                {
                    MessageBox.Show("Changes could not be made-" + ecp.ToString());
                    return true;
                }
                System.Threading.Thread.Sleep(100);
                goto retry;
            }

            return true;
        }
        public void EditTag(string filename)
        {
            Mp3File mp3File = null;

            try
            {
                // create mp3 file wrapper; open it and read the tags
                mp3File = new Mp3File(filename);
            }
            catch (Exception e)
            {
                ExceptionMessageBox.Show(_form, e, "Error Reading Tag");
                return;
            }

            // create dialog and give it the ID3v2 block for editing
            // this is a bit sneaky; it uses the edit dialog straight out of TagScanner.exe as if it was a dll.
            TagEditor.ID3AdapterEdit id3Edit = new TagEditor.ID3AdapterEdit(mp3File);

            if (id3Edit.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    using( new CursorKeeper(Cursors.WaitCursor) )
                    {
                        mp3File.Update();
                    }
                }
                catch (Exception e)
                {
                    ExceptionMessageBox.Show(_form, e, "Error Writing Tag");
                }
            }
        }
Esempio n. 4
0
    // Update is called once per frame
    void Update()
    {
        if (boxIsMoving) {
            moveBox(interactable.transform.parent.gameObject, boxEndPosition);
        }

        if (folderIsMoving && !foldersOut) {
            int folderIndex = 0;
            foreach (Transform artistFolder in artistFolderContainer.transform) {
                moveFolder(artistFolder.gameObject, folderEndPositions[folderIndex]);
                folderIndex++;
            }
        }

        if (folderIsMoving && foldersOut) {
            int folderIndex = 0;
            foreach (Transform artistFolder in artistFolderContainer.transform) {
                moveFolder(artistFolder.gameObject, folderOriginalPositions[folderIndex]);
                folderIndex++;
            }
        }

        if (Input.GetKeyDown ("x") && !boxIsMoving && waitingForArtistSelection && !artistSelected) {
            boxIsMoving = true;
            boxEndPosition = boxOriginalPosition;
            foreach (Transform artistFolder in artistFolderContainer.transform) {
                Destroy(artistFolder.gameObject);
            }
            waitingForAlbumSelection = false;
            selectedFolder = 0;
        }

        if (interactable.transform.parent.transform.localPosition == boxOriginalPosition && waitingForArtistSelection) {
            raycaster.enabled = true;
            waitingForArtistSelection = false;
            boxIsMoving = false;
            boxIsOpen = false;
        }

        /*Artist selection*/
        try {
            if (foldersOut) {
                artistFolderContainer.transform.GetChild(selectedFolder).GetChild(2).GetComponent<MeshRenderer>().material.color = ToColor(16761477);

                selectedArtist = artistFolderContainer.transform.GetChild(selectedFolder).transform;

                if (Input.GetKeyDown ("s") && selectedFolder+1 < artistFolderContainer.transform.childCount && !waitingForAlbumSelection) {
                    artistFolderContainer.transform.GetChild(selectedFolder).GetChild(2).GetComponent<MeshRenderer>().material.color = folderDefaultColor;
                    selectedFolder++;
                }
                if (Input.GetKeyDown ("w") && selectedFolder-1 >= 0) {
                    artistFolderContainer.transform.GetChild(selectedFolder).GetChild(2).GetComponent<MeshRenderer>().material.color = folderDefaultColor;
                    selectedFolder--;
                }
                if (Input.GetKeyDown ("f") && !waitingForAlbumSelection) {
                    //Pull folders out of view, make appropriate albums visible, wait for album selection
                    folderIsMoving = true;
                    foldersLifted = false;
                    foldersOut = false;
                    artistSelected = true;
                    foreach (Transform artist in alphabeticalContainer.transform) {
                        if (selectedArtist.gameObject.name == artist.gameObject.name) {
                            selectedArtistContainer = artist;
                            foreach (Transform album in artist) {
                                album.gameObject.SetActive(true);
                                album.position = new Vector3(0, -7, 0);
                            }
                        }
                    }
                }
            }
        } catch (UnityException) {
            //There are no artists under that letter
        }

        /*Album selection*/
        try {
            if (artistSelected && !albumSelected) {

                selectedAlbum = selectedArtistContainer.transform.GetChild(selectedAlbumIndex);
                selectedAlbum.GetChild(0).GetComponent<MeshRenderer>().material.shader = GUI3DTextShader;
                selectedAlbum.GetChild(0).gameObject.SetActive(true);
                selectedAlbum.GetChild(0).GetComponent<TextMesh>().text = selectedAlbum.name;
                if (!foldersLifted || !waitingForAlbumSelection) {
                    foreach (Transform artistFolder in artistFolderContainer.transform) {
                        liftFolder(artistFolder.gameObject, artistFolder.position + new Vector3(0, 20, 0));
                    }
                    //Move albums into view
                    int albumIndex = 0;
                    Vector3 currentOffset;
                    float currentY = selectedArtistContainer.position.y;
                    if (!waitingForAlbumSelection) {
                        foreach (Transform album in selectedArtistContainer) {
                            currentOffset = new Vector3(folderEndPositions[0].x * -0.2f, 0, folderEndPositions[0].z * -0.2f);
                            albumEndPositions[albumIndex] = (new Vector3(folderEndPositions[0].x * 0.8f, currentY, folderEndPositions[0].z * 0.8f) - currentOffset*(currentY/-0.5f));
                            positionAlbum(album.gameObject, albumEndPositions[albumIndex]);
                            albumIndex++;
                            currentY -= 0.1f;
                        }
                    }
                }
                if (Input.GetKeyDown("x")) {
                    folderIsMoving = true;
                    artistSelected = false;
                    waitingForAlbumSelection = false;
                    //Move albums back, deactivate
                    foreach (Transform album in selectedArtistContainer) {
                        album.gameObject.SetActive(false);
                    }
                    albumsOut = false;
                    foldersLifted = false;
                }

                if (Input.GetKeyDown("w")) {
                    waitingForAlbumSelection = true;
                    if (selectedAlbumIndex > 0) {
                        selectedAlbum.GetChild(0).gameObject.SetActive(false);
                        selectedAlbumIndex--;

                        //Move albums down
                        albumLiftingDown = true;
                        previouslySelectedAlbum = selectedAlbum;
                        previouslySelectedAlbumIndex = previouslySelectedAlbum.GetSiblingIndex();
                        scrollTarget = selectedAlbum.parent.GetChild(previouslySelectedAlbumIndex-1).localPosition + new Vector3(0, -3, 0);
                    }
                }
                if (Input.GetKeyDown("s")) {
                    waitingForAlbumSelection = true;
                    if (selectedAlbumIndex < selectedArtistContainer.childCount-1) {
                        selectedAlbum.GetChild(0).gameObject.SetActive(false);
                        selectedAlbumIndex++;

                        //Move albums up
                        albumLiftingUp = true;
                        previouslySelectedAlbum = selectedAlbum;
                        previouslySelectedAlbumIndex = previouslySelectedAlbum.GetSiblingIndex();
                        scrollTarget = selectedAlbum.parent.GetChild(previouslySelectedAlbumIndex+1).localPosition + new Vector3(0, 3, 0);
                    }
                }
                if (Input.GetKeyDown("f") && albumsOut && !albumSelected) {
                    albumSelected = true;
                }
                selectedAlbum = selectedArtistContainer.transform.GetChild(selectedAlbumIndex);
                if (albumLiftingUp) {
                    liftAlbumUp(previouslySelectedAlbum.gameObject, scrollTarget);
                }
                if (albumLiftingDown) {
                    liftAlbumDown(selectedAlbum.gameObject, albumEndPositions[selectedAlbumIndex]);
                }

            }
        } catch (UnityException) {

        }

        /*Song selection*/
        try {
            if (albumSelected && !songSelected) {
                //print ("Album selected");
                //Generate song names
                folderIsMoving = false;

                if (!songsOut) {
                    songIndex = 0;
                    foreach (Transform song in selectedAlbum) {
                        selectedAlbum.gameObject.transform.GetChild(0).gameObject.SetActive(false);
                        if (song.gameObject.name != "AlbumTitle" &&
                           (song.gameObject.name.EndsWith(".mp3") ||
                         	song.gameObject.name.EndsWith(".wav") ||
                         	song.gameObject.name.EndsWith(".ogg"))) {

                            FileInfo f = new FileInfo(song.gameObject.name);
                            ID3v1 tagger = new ID3v1();
                            FileStream mp3Stream = new FileStream(f.FullName, FileMode.Open, FileAccess.Read, FileShare.None);
                            Mp3File currentMP3 = new Mp3File(f);

                            currentMP3.Update();

                            string songName = "";

                            try {
                                tagger.Deserialize(mp3Stream);
                                mp3Stream.Close();
                                songName = tagger.Song;
                            } catch (Id3Lib.Exceptions.TagNotFoundException ex) {
                                songName = "[Unknown track title]";
                                print(ex);
                            }

                            songHolders[songIndex] = new GameObject(song.gameObject.name);
                            songHolders[songIndex].transform.position = selectedAlbum.transform.GetChild(0).transform.position;
                            songHolders[songIndex].transform.eulerAngles = selectedAlbum.transform.GetChild(0).transform.eulerAngles;
                            //songHolders[songIndex].transform.eulerAngles -= new Vector3(0, -90, 0);
                            songHolders[songIndex].transform.position -= new Vector3(0, songIndex * 0.2f - 0.7f, 0);
                            songHolders[songIndex].AddComponent<TextMesh>();
                            songHolders[songIndex].GetComponent<TextMesh>().text = songName;
                            songHolders[songIndex].GetComponent<TextMesh>().fontSize = 60 - songName.Length;
                            songHolders[songIndex].GetComponent<TextMesh>().characterSize = .03f;

                            songHolders[songIndex].GetComponent<MeshRenderer>().material.shader = GUI3DTextShader;

                            songIndex++;
                        }
                    }
                    songHolders[0].GetComponent<MeshRenderer>().material.color = Color.yellow;
                    songsOut = true;
                }
                else {
                    songHolders[selectedSong].GetComponent<MeshRenderer>().material.color = Color.yellow;
                    if (Input.GetKeyDown("s") && (selectedSong < songIndex-1)) {
                        songHolders[selectedSong].GetComponent<MeshRenderer>().material.color = Color.white;
                        selectedSong++;
                    }
                    if (Input.GetKeyDown("w") && (selectedSong > 0)) {
                        songHolders[selectedSong].GetComponent<MeshRenderer>().material.color = Color.white;
                        selectedSong--;
                    }
                    if (Input.GetKeyDown("x")) {
                        selectedAlbum.GetChild(0).gameObject.SetActive(true);
                        for (int i = 0; i <= songIndex; i++) {
                            Destroy(songHolders[i]);
                        }
                        songsOut = false;
                        albumSelected = false;
                        selectedSong = 0;
                        songIndex = 0;
                    }
                    if (Input.GetKeyDown("f")) {
                        PreserveData p = selectedSongInfo.GetComponent<PreserveData>();
                        p.path = songHolders[selectedSong].name;
                        if (selectedAlbum.gameObject.GetComponent<Renderer>().material.mainTexture == null) {
                            print ("null here");
                        }
                        if (selectedAlbum.gameObject.GetComponent<Renderer>().material.mainTexture != null) {
                            Color[] albumColors = colorAnalyzer.findColorScheme(selectedAlbum.gameObject.GetComponent<Renderer>().material.mainTexture, colorDetail, colorTolerance);
                            p.colorScheme = albumColors;
                            /*for (int i = 0; i < colorDetail; i++) {
                                print (albumColors[i]);
                            }*/
                        };

                        //Application.LoadLevel("ParticleRoom");
                        Application.LoadLevel(levelToLoad);
                    }
                }

            }
        } catch (UnityException) {

        }
    }
Esempio n. 5
0
    void alphabetizeByArtist()
    {
        GameObject[] audioHolders = new GameObject[10000]; //temporary placeholder max size

        //print (musicFiles.Count);

        string artist = "No Artist";
        string album = "No Album";

        foreach(FileInfo f in musicFiles) {
            //print("Loading "+f.FullName);
            GameObject audioHolder = new GameObject(f.Name);
            audioHolder.name = f.FullName;
            audioHolders[songIndex] = audioHolder;
            songIndex++;
            if (!(f.FullName.EndsWith(".jpg") || f.FullName.EndsWith(".png"))) {
                ID3v1 tagger = new ID3v1();

                FileStream mp3Stream = new FileStream(f.FullName, FileMode.Open, FileAccess.Read, FileShare.None);

                Mp3File currentMP3 = new Mp3File(f);

                currentMP3.Update();

                try {
                    tagger.Deserialize(mp3Stream);
                    mp3Stream.Close();
                    artist = tagger.Artist;
                    album = tagger.Album;
                } catch (Id3Lib.Exceptions.TagNotFoundException ex) {
                    mp3Stream.Close();
                    album = "No Album";
                    artist = "No artist";
                    print(ex);
                }

            }

            for (int i = 0; i < alphabeticalTitles.Length; i++) {

                string firstChar = alphabeticalTitles.GetValue(i).ToString().Substring(5,1);

                //Organize into specific artists and albums
                if (artist.StartsWith(firstChar)) {

                    //if artist holder doesn't already exist, create - otherwise add song to artist holder
                    bool artistExists = false;
                    Transform currentArtistHolder = null;
                    foreach(Transform artistHolder in alphabeticalTitles[i].transform) {
                        if (artistHolder.name.Trim() == artist.Trim()) {
                            artistExists = true;
                            currentArtistHolder = artistHolder;
                        }
                    }
                    if (!artistExists) {
                        currentArtistHolder = new GameObject(artist).transform;
                        currentArtistHolder.transform.parent = alphabeticalTitles[i].transform;
                    }

                    //audioHolder.transform.parent = currentArtistHolder;

                    bool albumExists = false;
                    Transform currentAlbumHolder = null;
                    foreach(Transform albumHolder in currentArtistHolder.transform) {
                        if (albumHolder.name.Trim () == album.Trim()) {
                            albumExists = true;
                            currentAlbumHolder = albumHolder;
                        }
                    }
                    if (!albumExists) {
                        currentAlbumHolder = Instantiate(albumSleevePrefab).transform;
                        currentAlbumHolder.transform.parent = currentArtistHolder;
                        currentAlbumHolder.name = album;
                    }
                    /*if (!albumExists) {
                        currentAlbumHolder = new GameObject(album).transform;
                        currentAlbumHolder.transform.parent = currentArtistHolder;
                        currentAlbumHolder.gameObject.AddComponent<Renderer>();
                        currentAlbumHolder.gameObject.GetComponent<Renderer>().material.mainTexture = artGrabber.getAlbumArtAsTexture(audioHolder);
                    }*/

                    audioHolder.transform.parent = currentAlbumHolder;
                    currentAlbumHolder.gameObject.GetComponent<Renderer>().material.mainTexture = artGrabber.getAlbumArtAsTexture(audioHolder, f);
                    if (currentAlbumHolder.gameObject.GetComponent<Renderer>().material.mainTexture == null) {
                        currentAlbumHolder.gameObject.GetComponent<Renderer>().material.mainTexture = Resources.Load("defaultAlbumArt") as Texture2D;
                    }

                }

            }

        }

        return;
    }