Example #1
0
        /*
         * Function to attempt log in to a user account
         * @PARAMETERS: - song: the song to add
         * @RETURNS: The User who has been logged in - null if unsuccesful
         * @AUTHORS: Andrew Davis and Matt Malone
         * NOTE - Commented code left in by Matt - just in case it breaks
         */
        public bool doInsertTrack(Song song, ISession session)
        {
            try
            {
                // Call to initialise cluster connection
                //init();

                ///

                Guid tid = song.getSongID();
                String artist = song.getArtist();
                String album = song.getAlbum();
                int year = song.getYear();
                String genre = song.getGenre();
                String file_loc = song.getFileLocation();
                int length = song.getLength();
                String trackname = song.getTrackName();

                // Connect to cluster
                //ISession session = cluster.Connect("maltmusic");

                //Guid tid = Guid.NewGuid();

                // Prepare and bind statement passing in username
                String todo = ("insert into tracks (\n" +
                  "track_id, artist, album, year,genre, file_loc,length,track_name)\n" +
                 "values (:tid, :art,:alb,:yr,:gnr,:floc,:len,:tnm) if not exists");

                PreparedStatement ps = session.Prepare(todo);

                BoundStatement bs = ps.Bind(tid, artist, album, year, genre, file_loc, length, trackname);

                // Execute Query
                session.Execute(bs);
                //session.Dispose();
                return true;

                // Catch exceptions
            }
            catch (Exception ex)
            {
                Console.WriteLine("SOMETHING WENT WRONG in INSERT TRACK: " + ex.Message);
                return false;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="playlist"></param>
        /// <param name="song"></param>
        /// <returns></returns>
        public bool addSongToPlaylist(Playlist playlist, Song song)
        {
            try
            {
                // Call to initialise cluster connection
                //init();

                // Connect to cluster
                ISession session = cluster.Connect("maltmusic");

                // Prepare and bind statement passing in the relevant fields
                String todo = ("insert into playlist (track_id,playlist_id,track_pos)\n" +
                 "values (:tid, :pid,:tpos) if not exists;");
                PreparedStatement ps = session.Prepare(todo);

                // Getting Appropriate ID's for query
                Guid tid = song.getSongID();
                Guid pid = playlist.getID();

                // Matt - change this
                // done
                int pos = getListPos(session, tid, pid);

                BoundStatement bs = ps.Bind(tid, pid, pos);

                // Execute Query
                session.Execute(bs);

                return true;

                // Catch exceptions
            }
            catch (Exception ex)
            {
                Console.WriteLine("SOMETHING WENT WRONG add to playlist: " + ex.Message);
                return false;
            }
        }
Example #3
0
        private void cmdAddSongToPlaylist_Click(object sender, EventArgs e)
        {
            String plName = Microsoft.VisualBasic.Interaction.InputBox("Playlist Name:");
            String owner = Microsoft.VisualBasic.Interaction.InputBox("Owner:");

            PlaylistModel playlistModel = new PlaylistModel();
            Playlist thePlaylist = playlistModel.getPlaylist(plName, owner);

            SongModel songModel = new SongModel();
            String artist = Microsoft.VisualBasic.Interaction.InputBox("Search for Artist: ");
            List<Song> songs = songModel.getSongsByArtist(artist);

            Song theSong = new Song();

            if (songs.Count > 0)
            {
                theSong = songs[0];
                if (thePlaylist != null)
                {
                    playlistModel.addSongToPlaylist(thePlaylist, theSong);
                }
            }
        }
Example #4
0
        //Plays the song the user selected
        private void lblPlay_Click(object sender, EventArgs e)
        {
            Song toAdd = new Song();

            //Parse song
            String[] tmp = selectedSong.Split(',');
            int x = int.Parse(tmp[0]);
            int y = int.Parse(tmp[1]);

            String songName = songLabelsName[x][y].Text;

            for (int i = 0; i < songs.Count; i++)
            {
                if (songs[i].getTrackName().Equals(songName))
                {
                    toAdd = songs[i];
                    break;
                }
            }

            if (toAdd.getTrackName() != null && toAdd.getTrackName() != "")
            {
                //Stop currently playing song
                String filePath = toAdd.getFileLocation();
                musicPlayer.stopSong();

                //Load album art
                String imagePath = "../../tracks/" + toAdd.getArtist() + "/" + toAdd.getAlbum() + "/" + toAdd.getAlbum() + ".jpg";

                //Send song to music player
                Playlist toPlay = new Playlist();
                toPlay.addSongs(toAdd);
                musicPlayer.setPlaylist(toPlay, 0);
                musicPlayer.playCurrentSong();

            }
            pnlOptions.Visible = false;
        }
Example #5
0
        //Adding song to playlist
        private void addSongToPlaylist(object sender, EventArgs e)
        {
            //Get the playlist
            int playListIndex;

            Label theLabel = (Label)sender;
            playListIndex = int.Parse(theLabel.Tag.ToString());

            Playlist thePlaylist = usersPlaylists[playListIndex];

            String[] tmp = selectedSong.Split(',');
            int x = int.Parse(tmp[0]);
            int y = int.Parse(tmp[1]);

            String songName = songLabelsName[x][y].Text;

            Song toAdd = new Song();

            for (int i = 0; i < songs.Count; i++)
            {
                if (songs[i].getTrackName().Equals(songName))
                {
                    toAdd = songs[i];
                    break;
                }
            }

            //This part does the actual adding
            if (toAdd.getTrackName() != null && toAdd.getTrackName() != "")
            {
                PlaylistModel playlistModel = new PlaylistModel();

                playlistModel.addSongToPlaylist(thePlaylist, toAdd);
            }

            pnlOptions.Visible = false;
            pnlPlaylists.Visible = false;
        }
        public void removeSongFromPlaylist(Playlist playlist, Song song)
        {
            try
            {
                //init();
                // Connect to cluster
                ISession session = cluster.Connect("maltmusic");

                // get playlist id
                // get track id
                Guid play_id = playlist.getID();
                Guid track_id = song.getSongID();

                String todo = "delete from playlist where playlist_id = :pid and track_id = :tid";
                PreparedStatement ps = session.Prepare(todo);
                BoundStatement bs = ps.Bind(play_id, track_id);
                session.Execute(bs);
            }
            catch (Exception e)
            {
                Console.WriteLine("Removing from a plist broke " + e);
            }
        }
        /// <summary>
        ///     Get the songs from a playlist
        /// </summary>
        /// <param name="pid">the id of the playlist</param>
        /// <param name="session">the session for connecting to Cassandra</param>
        /// <returns></returns>
        public List<Song> getTracksInPlist(Guid pid, ISession session)
        {
            List<Song> songs = new List<Song>();
            List<int> positions = new List<int>();

            String todo = ("select * from playlist where playlist_id = :pid");
            PreparedStatement ps = session.Prepare(todo);
            BoundStatement bs = ps.Bind(pid);
            // Execute Query
            RowSet rows = session.Execute(bs);
            foreach (Row row in rows)
            {
                //under duress i do this
                Guid tid = (Guid)row["track_id"];

                int pos = (int)row["track_pos"];
                positions.Add(pos);

                String things = ("select * from tracks where track_id = :tid");
                PreparedStatement prep = session.Prepare(things);
                BoundStatement bound = prep.Bind(tid);
                // Execute Query
                RowSet rows2 = session.Execute(bound);

                foreach (Row rowset in rows2)
                {
                    //this one
                    //public Song(String artist, String location, String name, Guid tid)
                    String name = (String)rowset["track_name"];
                    String artist = (String)rowset["artist"];
                    String file_loc = (String)rowset["file_loc"];
                    int length = (int)rowset["length"];
                    int year = (int)rowset["year"];
                    String album = rowset["album"].ToString();
                    String genre = rowset["genre"].ToString();

                    Song toadd = new Song(artist, album, year, genre, file_loc, length, name, tid);
                    songs.Add(toadd);
                }
            }

            // SORT

            List<Song> sortedSongs = new List<Song>();

            while (positions.Count > 0 && songs.Count > 0)
            {
                int currentLowest = positions[0];
                int lowestIndex = 0;

                for (int i = 0; i < positions.Count; i++)
                {
                    if (positions[i] < currentLowest)
                    {
                        currentLowest = positions[i];
                        lowestIndex = i;
                    }
                }

                sortedSongs.Add(songs[lowestIndex]);

                songs.RemoveAt(lowestIndex);
                positions.RemoveAt(lowestIndex);

            }

            return sortedSongs;
        }
Example #8
0
 public void newSong(Song theSong)
 {
     if (viewPlaylist.Visible) { viewPlaylist.newSongStarted(theSong); }
 }
Example #9
0
 public void addSong(Song song)
 {
     this.songs.Add(song);
 }
Example #10
0
        //Play song in music player
        private void lblPlay_Click(object sender, EventArgs e)
        {
            //Get song
            Song toAdd = new Song();
            String songName = songLabels[selectedSong].Text;

            for (int i = 0; i < songs.Count; i++)
            {
                if (songs[i].getTrackName().Equals(songName))
                {
                    toAdd = songs[i];
                    break;
                }
            }

            //Play in music player
            if (toAdd.getTrackName() != null && toAdd.getTrackName() != "")
            {
                //Get filepath of song, stop currently playing song
                String filePath = toAdd.getFileLocation();
                musicPlayer.stopSong();

                //Play song at path
                //String imagePath = "../../tracks/" + toAdd.getArtist() + "/" + toAdd.getAlbum() + "/" + toAdd.getAlbum() + ".jpg";
                //musicPlayer.setSongPath(@"" + filePath, imagePath);
                musicPlayer.setPlaylist(thePlaylist, selectedSong);

                musicPlayer.playCurrentSong();
            }

            pnlOptions.Visible = false;
        }
Example #11
0
        public void songAdded(Song song)
        {
            thePlaylist.addSongs(song);
            int count = thePlaylist.getSongs().Count - 1;

            #region Song Name Label
            Label theSongLabel = new Label();

            theSongLabel.Text = song.getTrackName();
            theSongLabel.Size = new Size(344, 30);
            theSongLabel.Location = new Point(423, 156 + (33 * count));
            theSongLabel.Tag = count.ToString();
            theSongLabel.UseMnemonic = false;
            theSongLabel.MouseEnter += hoverEvent;
            theSongLabel.MouseLeave += leaveEvent;
            theSongLabel.Click += setSelected;
            theSongLabel.ForeColor = Color.FromArgb(225, 225, 225);
            theSongLabel.TextAlign = ContentAlignment.MiddleLeft;
            theSongLabel.Font = new System.Drawing.Font("Franklin Gothic Medium", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

            if (count % 2 == 0)
            {
                theSongLabel.BackColor = Color.FromArgb(60, 60, 60);
            }
            else
            {
                theSongLabel.BackColor = Color.FromArgb(40, 40, 40);
            }

            songLabels.Add(theSongLabel);

            this.Controls.Add(songLabels[count]);
            #endregion

            #region Position Label
            Label thePositionLabel = new Label();

            thePositionLabel.Text = (count + 1).ToString();
            thePositionLabel.Size = new Size(50, 30);
            thePositionLabel.Location = new Point(370, 156 + (33 * count));
            thePositionLabel.Tag = count.ToString();
            thePositionLabel.UseMnemonic = false;
            thePositionLabel.MouseEnter += hoverEvent;
            thePositionLabel.MouseLeave += leaveEvent;
            thePositionLabel.Click += setSelected;
            thePositionLabel.ForeColor = Color.FromArgb(225, 225, 225);
            thePositionLabel.TextAlign = ContentAlignment.MiddleLeft;
            thePositionLabel.Font = new System.Drawing.Font("Franklin Gothic Medium", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

            if (count % 2 == 0)
            {
                thePositionLabel.BackColor = Color.FromArgb(60, 60, 60);
            }
            else
            {
                thePositionLabel.BackColor = Color.FromArgb(40, 40, 40);
            }

            positionLabels.Add(thePositionLabel);

            this.Controls.Add(positionLabels[count]);
            #endregion

            #region Artist Label
            LinkLabel theArtistLabel = new LinkLabel();

            theArtistLabel.Text = songs[count].getArtist();
            theArtistLabel.Size = new Size(250, 30);
            theArtistLabel.Location = new Point(770, 156 + (33 * count));
            theArtistLabel.Tag = count.ToString();
            theArtistLabel.UseMnemonic = false;
            theArtistLabel.MouseEnter += hoverEvent;
            theArtistLabel.MouseLeave += leaveEvent;
            theArtistLabel.Click += setSelected;
            theArtistLabel.LinkClicked += goToArtist;
            theArtistLabel.LinkColor = Color.White;
            theArtistLabel.VisitedLinkColor = Color.White;
            theArtistLabel.ForeColor = Color.FromArgb(225, 225, 225);
            theArtistLabel.TextAlign = ContentAlignment.MiddleLeft;
            theArtistLabel.Font = new System.Drawing.Font("Franklin Gothic Medium", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

            if (count % 2 == 0)
            {
                theArtistLabel.BackColor = Color.FromArgb(60, 60, 60);
            }
            else
            {
                theArtistLabel.BackColor = Color.FromArgb(40, 40, 40);
            }

            artistLabels.Add(theArtistLabel);

            this.Controls.Add(artistLabels[count]);
            #endregion

            PictureBox removeIcon = new PictureBox();

            removeIcon.Size = new Size(20, 20);
            removeIcon.Location = new Point(1025, 161 + (33 * count));
            removeIcon.BackgroundImage = Properties.Resources.removeFromPlaylist;
            removeIcon.BackgroundImageLayout = ImageLayout.Stretch;
            removeIcon.Tag = count.ToString();
            removeIcon.Click += removeSong;
            removeIcon.ForeColor = Color.FromArgb(225, 225, 225);

            removeLabels.Add(removeIcon);

            this.Controls.Add(removeLabels[count]);
        }
Example #12
0
 public void newSongStarted(Song theSong)
 {
     this.currentlyPlaying = theSong;
     displayWhichSongIsPlaying();
 }
Example #13
0
        public List<Song> searchSongs(String searchText)
        {
            List<Song> songs = new List<Song>();

            try
            {
                // Call to initialise cluster connection
                //init();

                // Connect to cluster
                ISession session = cluster.Connect("maltmusic");

                // Prepare and bind statement passing in username
                String todo = ("SELECT * FROM tracks");

                PreparedStatement ps = session.Prepare(todo);

                BoundStatement bs = ps.Bind();

                // Execute Query
                RowSet rows = session.Execute(bs);
                foreach (Row r in rows)
                {

                    String trackName = r["track_name"].ToString();

                    if (trackName.ToLower().Contains(searchText.ToLower()))
                    {
                        Guid id = (Guid)r["track_id"];
                        String album = r["album"].ToString();
                        String artist = r["artist"].ToString();
                        String fileLocation = r["file_loc"].ToString();
                        int year = (int)r["year"];
                        int length = (int)r["length"];
                        String genre = r["genre"].ToString();

                        Song theSong = new Song(artist, album, year, genre, fileLocation, length, trackName, id);

                        songs.Add(theSong);

                    }
                }

                return songs;

                // Catch exceptions
            }
            catch (Exception ex)
            {
                Console.WriteLine("SOMETHING WENT WRONG in GET BY ARTIST: " + ex.Message);
                return songs;
            }
        }
Example #14
0
        public bool populateDB()
        {
            try
            {
                string[] lines = System.IO.File.ReadAllLines("../../tracks/populate.txt");
                ISession session = cluster.Connect("maltmusic");

                foreach (string line in lines)
                {
                    // Use a tab to indent each line of the file.
                    //Console.WriteLine("\t" + line);
                    char[] delimiterChars = { '|' };
                    //System.Console.WriteLine("Original text: '{0}'", line);
                    string[] text = line.Split(delimiterChars);

                    //Guid sid = new Guid();
                    Guid sid = new Guid(text[0]);
                    String artist = text[1].Trim();
                    String album = text[2].Trim();
                    int year = int.Parse(text[3]);
                    String genre = text[4].Trim();
                    int length = int.Parse(text[5]);
                    String tname = text[6].Trim();

                    String file_loc = ("../../tracks/" + artist + "/" + album + "/" + tname + ".mp3");
                    Song toAdd = new Song(artist, album, year, genre, file_loc, length, tname, sid);
                    doInsertTrack(toAdd, session);
                    //doInsertTrack(toAdd);
                }
                populateTags(session);
                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine("Broke while reading data to base" + e);
                return false;
            }
        }
Example #15
0
        public Song getTrackByID(Guid tid)
        {
            try
            {
                ISession session = cluster.Connect("maltmusic");

                // Prepare and bind statement passing in username
                String todo = ("select * from tracks where track_id = :tid");
                PreparedStatement ps = session.Prepare(todo);
                BoundStatement bs = ps.Bind(tid);

                // Execute Query
                RowSet rows = session.Execute(bs);
                foreach (Row r in rows)
                {
                    String artist = r["artist"].ToString();
                    String trackName = r["track_name"].ToString();
                    Guid id = (Guid)r["track_id"];
                    String album = r["album"].ToString();
                    String fileLocation = r["file_loc"].ToString();
                    int year = (int)r["year"];
                    int length = (int)r["length"];
                    String genre = r["genre"].ToString();

                    Song theSong = new Song(artist, album, year, genre, fileLocation, length, trackName, id);

                    return theSong;

                }
                return null;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error in getting track by id " + e);
                return null;
            }
        }
Example #16
0
 public void updateCurrentSong(Song currentSong)
 {
     // send to Search, view playlist, view artist
 }
Example #17
0
 /*
  * FUNCTION TO ADD A SONG TO THE LIST
  * @PARAMETERS: - theSong: the song to add
  */
 public void addSongs(Song theSong)
 {
     this.songs.Add(theSong);
 }
        /// <summary>
        /// Acquires the file path of the song via the playlist
        /// </summary>
        /// <returns>The file location of the song</returns>
        private string getNextSong()
        {
            // Acquires the song
            thisSong = activePlaylist.getSongByID(playlistIndex);

            // Get and the album artwork
            string imagePath = thisSong.getImagePath();

            // Sets the album art image
            try
            {
                picBoxAlbumArt.Image = Image.FromFile(imagePath);
            }catch(FileNotFoundException){
                picBoxAlbumArt.Image = MALT_Music.Properties.Resources.logo;
            }

            // Acquires the path
            string songPath = thisSong.getFileLocation();

            return songPath;
        }