Esempio n. 1
0
        public IHttpActionResult PutSONG(int id, SONG sONG)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != sONG.ID)
            {
                return(BadRequest());
            }

            db.Entry(sONG).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SONGExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 2
0
    bool TransitionSong()
    {
        bool  anyValueChange = false;
        float speed          = Time.deltaTime * songTransitionSpeed;

        for (int i = 0; i < allSong.Count - 1; i--)
        {
            SONG song = allSong[i];
            if (song == activeSong)
            {
                if (song.volume < song.maxVolume)
                {
                    song.volume    = smoothTransition ? Mathf.Lerp(song.volume, song.maxVolume, speed) : Mathf.MoveTowards(song.volume, song.maxVolume, speed);
                    anyValueChange = true;
                }
            }
            else
            {
                if (song.volume > 0f)
                {
                    song.volume    = smoothTransition ? Mathf.Lerp(song.volume, 0f, speed) : Mathf.MoveTowards(song.volume, 0f, speed);
                    anyValueChange = true;
                }
                else
                {
                    allSong.RemoveAt(i);
                    song.destroySong();
                    continue;
                }
            }
        }
        return(anyValueChange);
    }
Esempio n. 3
0
    public void PlaySong(AudioClip song, float maxVolume = 1f, float pitch = 1f, float startingVolume = 0f, bool playOnStart = true, bool loop = true)
    {
        if (song != null)
        {
            for (int i = 0; i < allSongs.Count; i++)
            {
                SONG s = allSongs[i];
                if (s.clip == song)
                {
                    activeSong = s;
                    break;
                }
            }
            if (activeSong == null || activeSong.clip != song)
            {
                activeSong = new SONG(song, maxVolume, pitch, startingVolume, playOnStart, loop);
            }
        }
        else
        {
            activeSong = null;
        }

        StopAllCoroutines();
        StartCoroutine(VolumeLeveling());
    }
Esempio n. 4
0
    bool TransitionSongs()
    {
        bool anyValueChanged = false;

        float speed = songTransitionSpeed * Time.deltaTime;

        for (int i = allSongs.Count - 1; i >= 0; i--)
        {
            SONG song = allSongs[i];
            if (song == activeSong)
            {
                if (song.volume < song.maxVolume)
                {
                    song.volume     = songSmoothTransitions ? Mathf.Lerp(song.volume, song.maxVolume, speed) : Mathf.MoveTowards(song.volume, song.maxVolume, speed);
                    anyValueChanged = true;
                }
            }
            else
            {
                if (song.volume > 0.001f)
                {
                    song.volume     = songSmoothTransitions ? Mathf.Lerp(song.volume, 0f, speed) : Mathf.MoveTowards(song.volume, 0f, speed);
                    anyValueChanged = true;
                }
                else
                {
                    allSongs.RemoveAt(i);
                    song.DestroySong();
                    continue;
                }
            }
        }

        return(anyValueChanged);
    }
Esempio n. 5
0
        public static bool TagsComplete(this SONG song)
        {
            bool ret = true;

            try
            {
                if (string.IsNullOrEmpty(song.ALBUM))
                {
                    ret = false;
                }
                if (string.IsNullOrEmpty(song.ARTIST))
                {
                    ret = false;
                }
                if (string.IsNullOrEmpty(song.GENRE))
                {
                    ret = false;
                }
                if (string.IsNullOrEmpty(song.LOCATION))
                {
                    ret = false;
                }
                if (string.IsNullOrEmpty(song.TITLE))
                {
                    ret = false;
                }
            }
            catch (Exception ex)
            {
                Debug.Write(ex.Message);
            }
            return(ret);
        }
Esempio n. 6
0
        public void SyncSongUploadedStatusWithBlobs()
        {
            AzureService                azureService = new AzureService(Settings.Default.AzureAccountName, Settings.Default.AzureAccountKey);
            MusicDao                    musicDao     = GetMusicDao();
            CloudBlobClient             blobClient   = azureService.GetCloudBlobContainer();
            CloudBlobContainer          container    = blobClient.GetContainerReference(containerName);
            IEnumerable <IListBlobItem> blobs        = container.ListBlobs();

            foreach (IListBlobItem blob in blobs)
            {
                testContextInstance.WriteLine("{0}", blob.Uri);
                String[] s   = blob.Uri.ToString().Split(new char[] { '/' });
                String   key = s[s.Length - 1];
                s = key.Split(new char[] { '.' });
                testContextInstance.WriteLine("{0}", s[0]);
                try
                {
                    int id   = Convert.ToInt32(s[0]);
                    var song = new SONG()
                    {
                        ID = id, UPLOADED = true
                    };
                    musicDao.UpdateSongUploadStatus(song);
                }
                catch (Exception ex)
                {
                    testContextInstance.WriteLine("{0} {1}", ex.Message, ex.StackTrace);
                }
            }
        }
Esempio n. 7
0
        public void DeleteDuplicateSongs()
        {
            var dataContext = new MusicEntities1();

            // Delete songs with the same hash code
            IQueryable <SONG> songQuery = from s in dataContext.SONG
                                          orderby s.HASH
                                          where s.HASH != null
                                          select s;

            SONG previousSong = null;

            foreach (SONG song in songQuery)
            {
                if ((previousSong != null) && (previousSong.HASH == song.HASH))
                {
                    testContextInstance.WriteLine("{0} : {1}", previousSong.LOCATION, song.LOCATION);

                    if (previousSong.ID < song.ID)
                    {
                        dataContext.SONG.Remove(previousSong);
                        dataContext.SaveChanges();
                    }
                    else
                    {
                        dataContext.SONG.Remove(song);
                        dataContext.SaveChanges();
                    }
                }
                previousSong = song;
            }

            // Delete songs with the same location
            songQuery = from s in dataContext.SONG
                        orderby s.LOCATION
                        where s.LOCATION != null
                        select s;

            previousSong = null;
            foreach (SONG song in songQuery)
            {
                if ((previousSong != null) && (previousSong.LOCATION == song.LOCATION))
                {
                    testContextInstance.WriteLine("{0} : {1}", previousSong.LOCATION, song.LOCATION);
                    if (previousSong.ID < song.ID)
                    {
                        dataContext.SONG.Remove(previousSong);
                        dataContext.SaveChanges();
                    }
                    else
                    {
                        dataContext.SONG.Remove(song);
                        dataContext.SaveChanges();
                    }
                }
                previousSong = song;
            }
            dataContext.SaveChanges();
        }
Esempio n. 8
0
        public static SONG CalculateModificationDate(this SONG song)
        {
            var fileInfo = new FileInfo(song.LOCATION);

            song.UPDATED = fileInfo.LastWriteTime;

            return(song);
        }
Esempio n. 9
0
        public void AddIdToFilename()
        {
            SONG song = new SONG();

            song.LOCATION = @"E:\Gdrive\Music\Franz Ferdinand\Right Thoughts\Ulysses.mp3";
            song.ID       = 99;
            song.AddIdToFilename();
        }
Esempio n. 10
0
 public bool Ambient(SONG song)
 {
     if (song.GENRE == null)
     {
         return(false);
     }
     return(song.GENRE.ToUpper().Contains("AMBIENT"));
 }
Esempio n. 11
0
 public void SetSong(SONG song)
 {
     this.song     = song;
     this.Title    = song.TITLE;
     this.Artist   = song.ARTIST;
     this.Genre    = song.GENRE;
     this.Rating   = song.RATING;
     this.Location = song.LOCATION;
 }
Esempio n. 12
0
        public void DownloadAllSongBlobs()
        {
            AzureService                azureService = new AzureService(Settings.Default.AzureAccountName, Settings.Default.AzureAccountKey);
            MusicDao                    musicDao     = GetMusicDao();
            CloudBlobClient             blobClient   = azureService.GetCloudBlobContainer();
            CloudBlobContainer          container    = blobClient.GetContainerReference(containerName);
            IEnumerable <IListBlobItem> blobs        = container.ListBlobs();

            foreach (IListBlobItem blob in blobs)
            {
                testContextInstance.WriteLine("{0}", blob.Uri);
                String[] s   = blob.Uri.ToString().Split(new char[] { '/' });
                String   key = s[s.Length - 1];
                s = key.Split(new char[] { '.' });
                testContextInstance.WriteLine("{0}", s[0]);
                try
                {
                    int      id       = Convert.ToInt32(s[0]);
                    SONG     song     = musicDao.GetSongById(id);
                    FileInfo fileInfo = new FileInfo(song.LOCATION);
                    s = song.LOCATION.Split(new char[] { '\\' });
                    String artistFolder = null;
                    String name         = fileInfo.Name;
                    String fileName     = null;
                    if (s.Length > 3)
                    {
                        artistFolder = targetFolder;
                        for (int i = 2; i < s.Length - 1; i++)
                        {
                            artistFolder = artistFolder + "\\" + s[i];
                            DirectoryInfo directoryInfo = new DirectoryInfo(artistFolder);
                            if (!directoryInfo.Exists)
                            {
                                Directory.CreateDirectory(artistFolder);
                            }
                        }
                        fileName = String.Format("{0}\\{1}", artistFolder, name);
                    }
                    else
                    {
                        fileName = String.Format("{0}\\{1}", targetFolder, name);
                    }

                    if (!File.Exists(fileName))
                    {
                        string key1 = String.Format("{0}.mp3", song.ID);
                        azureService.DownloadFile(containerName, fileName, key1);
                    }
                }
                catch (Exception ex)
                {
                    testContextInstance.WriteLine("{0} {1}", ex.Message, ex.StackTrace);
                    throw;
                }
            }
        }
Esempio n. 13
0
        public void PopulateSongTable1()
        {
            var    gDriveServiceContainer = new GDriveService();
            var    gdriveService          = gDriveServiceContainer.GetService();
            var    songRepository         = new SongRepository(new Repository("log"));
            int    maxSongs   = 10;
            int    songCount  = 0;
            string tempFolder = @"C:\temp2\";

            FilesResource.ListRequest request = gdriveService.Files.List();
            var fileList = new List <File>();

            try
            {
                FileList files = request.Execute();
                fileList.AddRange(files.Items);
                request.PageToken = files.NextPageToken;
                foreach (var file in fileList)
                {
                    try
                    {
                        testContextInstance.WriteLine("{0}", file.WebContentLink);
                        WebClient webClient = new WebClient();
                        string    filename  = tempFolder + file.OriginalFilename;
                        webClient.DownloadFile(file.WebContentLink, filename);

                        // Extract mp3 tags
                        SONG song = new SONG();
                        song.LOCATION = filename;
                        if (song.IsMp3File())
                        {
                            song.Populate();

                            testContextInstance.WriteLine(song.GENRE);
                            songRepository.Add(file.Id, file.WebContentLink, file.OriginalFilename, file.FileSize, song.TITLE, song.ARTIST, song.ALBUM, song.GENRE, song.LOCATION, song.RATING, song.TrackNumber);
                        }

                        System.IO.File.Delete(filename);
                    }
                    catch (Exception ex1)
                    {
                        testContextInstance.WriteLine("Error: {0}", ex1.Message);
                    }

/*					songCount++;
 *                                      if (songCount>maxSongs)
 *                                      {
 *                                              return;
 *                                      } */
                }
            }
            catch (Exception e)
            {
                testContextInstance.WriteLine("Error: {0}", e.Message);
            }
        }
Esempio n. 14
0
 internal GenericMusicItem(SONG s)
 {
     InnerType    = MediaType.Song;
     ContextualID = s.ID;
     Title        = s.Title;
     Description  = s.Album;
     Addtional    = s.Performers.IsNullorEmpty() ? Consts.UnknownArtists : string.Join(Consts.CommaSeparator, s.Performers.Split(new string[] { Consts.ArraySeparator }, StringSplitOptions.RemoveEmptyEntries));
     IDs          = new int[] { s.ID };
     PicturePath  = s.PicturePath;
 }
Esempio n. 15
0
        public IHttpActionResult GetSONG(int id)
        {
            SONG sONG = db.SONGS.Find(id);

            if (sONG == null)
            {
                return(NotFound());
            }

            return(Ok(sONG));
        }
Esempio n. 16
0
        public IHttpActionResult PostSONG(SONG sONG)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.SONGS.Add(sONG);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = sONG.ID }, sONG));
        }
Esempio n. 17
0
 public void SetSong(MellowSongs mellowSong)
 {
     this.song        = new SONG();
     this.song.TITLE  = mellowSong.TITLE;
     this.song.ARTIST = mellowSong.ARTIST;
     this.song.GENRE  = mellowSong.GENRE;
     this.Title       = mellowSong.TITLE;
     this.Artist      = mellowSong.ARTIST;
     this.Genre       = mellowSong.GENRE;
     this.Rating      = song.RATING;
     this.Location    = song.LOCATION;
 }
Esempio n. 18
0
        public void PopulateSongTable2()
        {
            var         gDriveServiceContainer = new GDriveService();
            var         gdriveService          = gDriveServiceContainer.GetService();
            List <File> fileList = new List <File>();

            FilesResource.ListRequest request = gdriveService.Files.List();
            string tempFolder     = @"E:\MusicTemp\";
            var    songRepository = new SongRepository(new Repository("log"));

            do
            {
                try
                {
                    FileList files = request.Execute();
                    fileList.AddRange(files.Items);
                    request.PageToken = files.NextPageToken;
                    foreach (var file in fileList)
                    {
                        try
                        {
                            testContextInstance.WriteLine("{0}", file.WebContentLink);
                            WebClient webClient = new WebClient();
                            string    filename  = tempFolder + file.OriginalFilename;
                            webClient.DownloadFile(file.WebContentLink, filename);

                            // Extract mp3 tags
                            SONG song = new SONG();
                            song.LOCATION = filename;
                            if (song.IsMp3File())
                            {
                                song.Populate();

                                testContextInstance.WriteLine(song.GENRE);
                                songRepository.Add(file.Id, file.WebContentLink, file.OriginalFilename, file.FileSize, song.TITLE, song.ARTIST, song.ALBUM, song.GENRE, song.LOCATION, song.RATING, song.TrackNumber);
                            }

                            System.IO.File.Delete(filename);
                        }
                        catch (Exception ex1)
                        {
                            testContextInstance.WriteLine("Error: {0}", ex1.Message);
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("An error occurred: " + e.Message);
                    request.PageToken = null;
                }
            } while (!String.IsNullOrEmpty(request.PageToken));
        }
Esempio n. 19
0
 static void DownloadSong(string filename, SONG song)
 {
     Trace.WriteLine(String.Format("Downloading {0}", filename));
     try
     {
         String key = String.Format("{0}.mp3", song.ID);
         azureService.DownloadFile("public", filename, key);
     }
     catch (Exception)
     {
         Trace.TraceError("Unable to download blob {0} {1}", song.ID, filename);
     }
 }
Esempio n. 20
0
        public IList <SONG> GetSongs(string genre, string sequence, int skip, string artist, string location)
        {
            var songList = new List <SONG>();
            var song     = new SONG();

            song.TITLE    = "Test title";
            song.ARTIST   = "Test artist";
            song.GENRE    = "Test genre";
            song.LOCATION = "Test location";
            songList.Add(song);

            return(songList);
        }
Esempio n. 21
0
        public static int GetFilenameId(this SONG song)
        {
            int ret     = -1;
            var re      = new Regex(@"\\s\d*s");
            var matches = re.Matches(song.LOCATION);

            if (matches.Count > 0)
            {
                ret = Convert.ToInt32(matches[0].Value);
            }

            return(ret);
        }
Esempio n. 22
0
 public void PlayMusic(SONG songToplay)
 {
     if ((int)songToplay < Songs.Count)
     {
         if (Songs[(int)songToplay] != null)
         {
             Speaker.Stop();
             Speaker.clip = Songs[(int)songToplay];
             Speaker.loop = true;
             Speaker.Play();
         }
     }
 }
Esempio n. 23
0
 public SongDto(SONG song)
 {
     Id          = song.ID;
     Title       = song.NAME;
     Artist      = song.ARTIST_NAME;
     TitleArtist = Title + "/" + Artist;
     Album       = song.ALBUM_NAME;
     foreach (var songGenre in song.SONG_GENRES)
     {
         Genre = Genre != null ? Genre + "/" + songGenre.GENRE.DESCRIPTION : songGenre.GENRE.DESCRIPTION;
     }
     Year = song.YEAR;
 }
Esempio n. 24
0
        public SongView(SONG song)
        {
            this.ALBUM    = song.ALBUM;
            this.ARTIST   = song.ARTIST;
            this.COMMENTS = song.COMMENTS;
            this.GENRE    = song.GENRE;
            this.ID       = song.ID;
            this.LOCATION = song.LOCATION;
            this.TITLE    = song.TITLE;
            this.RATING   = song.RATING;

            this.Location = musicBlobUrl + "/" + song.ID + ".mp3";
        }
Esempio n. 25
0
        public static bool HasIdInFilename(this SONG song)
        {
            bool ret     = false;
            var  re      = new Regex(@"\\s\d*s");
            var  matches = re.Matches(song.LOCATION);

            if (matches.Count > 0)
            {
                ret = true;
                string matchValue = matches[0].Value;
            }

            return(ret);
        }
Esempio n. 26
0
        public SONG ConvertToSong()
        {
            SONG song = new SONG();

            song.ALBUM    = this.ALBUM;
            song.ARTIST   = this.ARTIST;
            song.COMMENTS = this.COMMENTS;
            song.GENRE    = this.GENRE;
            song.ID       = this.ID;
            song.LOCATION = this.LOCATION;
            song.TITLE    = this.TITLE;
            song.RATING   = this.RATING;
            return(song);
        }
Esempio n. 27
0
        public IHttpActionResult DeleteSONG(int id)
        {
            SONG sONG = db.SONGS.Find(id);

            if (sONG == null)
            {
                return(NotFound());
            }

            db.SONGS.Remove(sONG);
            db.SaveChanges();

            return(Ok(sONG));
        }
Esempio n. 28
0
 internal Song(SONG song)
 {
     ID                         = song.ID;
     LastModified               = song.LastModified;
     IsOnedrive                 = song.IsOneDrive;
     Duration                   = song.Duration;
     BitRate                    = song.BitRate;
     Rating                     = song.Rating;
     FilePath                   = song.FilePath;
     MusicBrainzArtistId        = song.MusicBrainzArtistId;
     MusicBrainzDiscId          = song.MusicBrainzDiscId;
     MusicBrainzReleaseArtistId = song.MusicBrainzReleaseArtistId;
     MusicBrainzReleaseCountry  = song.MusicBrainzReleaseCountry;
     MusicBrainzReleaseId       = song.MusicBrainzReleaseId;
     MusicBrainzReleaseStatus   = song.MusicBrainzReleaseStatus;
     MusicBrainzReleaseType     = song.MusicBrainzReleaseType;
     MusicBrainzTrackId         = song.MusicBrainzTrackId;
     MusicIpId                  = song.MusicIpId;
     BeatsPerMinute             = song.BeatsPerMinute;
     Album                      = song.Album;
     AlbumArtists               = song.AlbumArtists.Split(new string[] { Consts.ArraySeparator }, StringSplitOptions.RemoveEmptyEntries);
     AlbumArtistsSort           = song.AlbumArtistsSort.Split(new string[] { Consts.ArraySeparator }, StringSplitOptions.RemoveEmptyEntries);
     AlbumSort                  = song.AlbumSort;
     AmazonId                   = song.AmazonId;
     Title                      = song.Title;
     TitleSort                  = song.TitleSort;
     Track                      = song.Track;
     TrackCount                 = song.TrackCount;
     ReplayGainTrackGain        = song.ReplayGainTrackGain;
     ReplayGainTrackPeak        = song.ReplayGainTrackPeak;
     ReplayGainAlbumGain        = song.ReplayGainAlbumGain;
     ReplayGainAlbumPeak        = song.ReplayGainAlbumPeak;
     Comment                    = song.Comment;
     Disc                       = song.Disc;
     Composers                  = song.Composers.Split(new string[] { Consts.ArraySeparator }, StringSplitOptions.RemoveEmptyEntries);
     ComposersSort              = song.ComposersSort.Split(new string[] { Consts.ArraySeparator }, StringSplitOptions.RemoveEmptyEntries);
     Conductor                  = song.Conductor;
     DiscCount                  = song.DiscCount;
     Copyright                  = song.Copyright;
     Genres                     = song.Genres.Split(new string[] { Consts.ArraySeparator }, StringSplitOptions.RemoveEmptyEntries);
     Grouping                   = song.Grouping;
     Lyrics                     = song.Lyrics;
     Performers                 = song.Performers.Split(new string[] { Consts.ArraySeparator }, StringSplitOptions.RemoveEmptyEntries);
     PerformersSort             = song.PerformersSort.Split(new string[] { Consts.ArraySeparator }, StringSplitOptions.RemoveEmptyEntries);
     Year                       = song.Year;
     PicturePath                = song.PicturePath;
     SampleRate                 = song.SampleRate;
     AudioChannels              = song.AudioChannels;
 }
Esempio n. 29
0
 public void PickRandomSong()
 {
     try
     {
         MusicDao musicDao = new MusicDao();
         musicDao.Initialize();
         SONG song = musicDao.PickRandomSong();
         Console.WriteLine(song.TITLE);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         Console.WriteLine(ex.StackTrace);
     }
 }
Esempio n. 30
0
 public static SONG AddIdToFilename(this SONG song)
 {
     try
     {
         FileInfo fileInfo = new FileInfo(song.LOCATION);
         song.FILESIZE = fileInfo.Length;
         string newFilename = string.Format("{0}\\s{1}s {2}", fileInfo.DirectoryName, song.ID, fileInfo.Name);
         fileInfo.CopyTo(newFilename, true);
         File.Delete(song.LOCATION);
         song.LOCATION = newFilename;
     }
     catch (Exception ex)
     {
         Debug.WriteLine(string.Format("Error: {0}", ex.Message));
     }
     return(song);
 }