/**
  * Clean all references for the given device.
  *
  * @param sId : Device id
  */
 public synchronized void cleanDevice(String sId) {
   for (Playlist plf : getPlaylists()) {
     if (plf.getDirectory() == null || plf.getDirectory().getDevice().getID().equals(sId)) {
       removeItem(plf);
     }
   }
 }
 /*
  * (non-Javadoc)
  *
  * @see org.jajuk.base.Observer#update(org.jajuk.base.Event)
  */
 public void update(Event event) {
   synchronized (getLock()) {
     EventSubject subject = event.getSubject();
     if (EventSubject.EVENT_FILE_NAME_CHANGED.equals(subject)) {
       Properties properties = event.getDetails();
       File fNew = (File) properties.get(DETAIL_NEW);
       File fileOld = (File) properties.get(DETAIL_OLD);
       // search references in playlists
       Iterator it = hmItems.values().iterator();
       for (int i = 0; it.hasNext(); i++) {
         Playlist plf = (Playlist) it.next();
         if (plf.isReady()) { // check only in mounted
           // playlists, note that we can't
           // change unmounted playlists
           try {
             if (plf.getFiles().contains(fileOld)) {
               plf.replaceFile(fileOld, fNew);
             }
           } catch (Exception e) {
             Log.error(17, e);
           }
         }
       }
     }
   }
 }
 /**
  * Walk through all Playlists and remove the ones for the current device.
  *
  * @param dirsToRefresh list of the directory to refresh, null if all of them
  * @return true if there was any playlist removed
  */
 private boolean cleanPlaylist(List<Directory> dirsToRefresh) {
   boolean bChanges = false;
   final List<Playlist> plfiles = PlaylistManager.getInstance().getPlaylists();
   for (final Playlist plf : plfiles) {
     // check if it is a playlist located inside refreshed directory
     if (dirsToRefresh != null) {
       boolean checkIt = false;
       for (Directory directory : dirsToRefresh) {
         if (plf.hasAncestor(directory)) {
           checkIt = true;
         }
       }
       // This item is not in given directories, just continue
       if (!checkIt) {
         continue;
       }
     }
     if (!ExitService.isExiting()
         && plf.getDirectory().getDevice().equals(this)
         && plf.isReady()
         && !plf.getFIO().exists()) {
       PlaylistManager.getInstance().removeItem(plf);
       Log.debug("Removed: " + plf);
       if (reporter != null) {
         reporter.notifyFileOrPlaylistDropped();
       }
       bChanges = true;
     }
   }
   return bChanges;
 }
  // main method for testing
  // used before integrating with gui
  public static void main(String[] args) {
    Playlist p1 = new Playlist("timer_test");
    String song = "test";

    p1.addSong("1");
    p1.addSong("2");
    p1.addSong("3");
  }
 public Song getCurrentSong() {
   if (songIndexInPlaylist < 0) {
     songIndexInPlaylist = 0;
   }
   if (songIndexInPlaylist >= activePlaylist.songCount()) {
     songIndexInPlaylist = activePlaylist.songCount() - 1;
     return null;
   }
   return activePlaylist.getSongFromIndex(songIndexInPlaylist);
 }
  /**
   * Returns the first playlist with the given name.
   *
   * @param name The name of the Playlist to search
   * @return The playlist if found, null otherwise.
   */
  public Playlist getPlaylistByName(String name) {
    for (Playlist pl : getPlaylists()) {
      // if this is the correct playlist, return it
      if (pl.getName().equals(name)) {
        return pl;
      }
    }

    // none found
    return null;
  }
 /**
  * Clean all references for the given device
  *
  * @param sId : Device id
  */
 public void cleanDevice(String sId) {
   synchronized (PlaylistManager.getInstance().getLock()) {
     Iterator<Playlist> it = hmItems.values().iterator();
     while (it.hasNext()) {
       Playlist plf = it.next();
       if (plf.getDirectory() == null || plf.getDirectory().getDevice().getID().equals(sId)) {
         it.remove();
       }
     }
   }
 }
Example #8
0
 public boolean newPlaylist(Playlist p) {
   // se conseguir guardar a musica manda true, senao manda false
   boolean existe = false;
   ArrayList<Playlist> lista = findAllPlaylists();
   for (Playlist pla : lista) {
     if (pla.getName().equals(p.getName())) {
       existe = false;
     } else {
       existe = true;
     }
   }
   if (existe) em.merge(p);
   log.info("Nova Playlist criada!");
   return existe;
 }
    public void run() {
      list.load(musicHome.getMusicDirectory().getAbsolutePath() + "/" + list.getName());
      // add all songs in Playlist to queue, refresh, and play
      for (int i = 0; i < list.getSize(); i++) {
        list.setPosition(i);
        songQueue.add(new File(list.getCurrentSong()));
      }
      musicHome.refreshQueue();
      musicPlayer.setSong(songQueue.remove(0));
      musicHome.refreshQueue();
      if (!musicPlayer.isPlaying()) {
        musicPlayer.play(-1);
      }

      t.cancel();
    }
Example #10
0
 public void update(Playlist p) {
   Playlist oldP = this.p;
   this.p = p;
   // Any items on the old list that aren't on the new, stop finding
   // sources for them
   for (String streamId : oldP.getStreamIds()) {
     if (!p.getStreamIds().contains(streamId)) control.stopFindingSources(streamId, this);
   }
   updateLock.lock();
   try {
     regenEventList();
   } finally {
     updateLock.unlock();
   }
   if (canEdit || activated) activate();
 }
Example #11
0
 public static PlaylistTableModel create(RobonoboFrame frame, Playlist p, boolean canEdit) {
   List<Track> trax = new ArrayList<Track>();
   for (String sid : p.getStreamIds()) {
     trax.add(frame.ctrl.getTrack(sid));
   }
   EventList<Track> el = GlazedLists.eventList(trax);
   return new PlaylistTableModel(frame, p, canEdit, el, null);
 }
Example #12
0
 /** Must only be called from inside updateLock */
 protected void regenEventList() {
   eventList.clear();
   trackIndices.clear();
   int i = 0;
   for (String sid : p.getStreamIds()) {
     eventList.add(control.getTrack(sid));
     trackIndices.put(sid, i++);
   }
 }
  private void deletePlaylist() {

    playlist = new Playlist();
    playlist.setPlaylistName(playlist_name);
    if (playlistController.deleteDateFromTable(playlist))
      JOptionPane.showMessageDialog(null, "Deleted Success");
    else JOptionPane.showMessageDialog(null, "Faild");
    resetPlaylist();
  }
 /**
  * Sets the url.
  *
  * @param url The sUrl to set.
  */
 public void setUrl(final String url) {
   sUrl = url;
   setProperty(Const.XML_URL, url);
   fio = new File(url);
   /** Reset files */
   for (final org.jajuk.base.File file : FileManager.getInstance().getFiles()) {
     file.reset();
   }
   /** Reset playlists */
   for (final Playlist plf : PlaylistManager.getInstance().getPlaylists()) {
     plf.reset();
   }
   /** Reset directories */
   for (final Directory dir : DirectoryManager.getInstance().getDirectories()) {
     dir.reset();
   }
   // Reset the root dir
   rootDir = null;
 }
Example #15
0
 public void activate() {
   if (!activated) {
     activated = true;
     // Make sure we've got fresh info for all our tracks
     for (String sid : p.getStreamIds()) {
       Track t = control.getTrack(sid);
       if (t instanceof CloudTrack) control.findSources(sid, this);
       trackUpdated(sid, t);
     }
   }
 }
 /**
  * Delete a playlist.
  *
  * @param plf DOCUMENT_ME
  */
 public synchronized void removePlaylistFile(Playlist plf) {
   String sFileToDelete =
       plf.getDirectory().getFio().getAbsoluteFile().toString()
           + java.io.File.separatorChar
           + plf.getName();
   java.io.File fileToDelete = new java.io.File(sFileToDelete);
   if (fileToDelete.exists()) {
     if (!fileToDelete.delete()) {
       Log.warn("Could not delete file: " + fileToDelete.toString());
     }
     // check that file has been really deleted (sometimes, we get no
     // exception)
     if (fileToDelete.exists()) {
       Log.error("131", new JajukException(131));
       Messages.showErrorMessage(131);
       return;
     }
   }
   // remove playlist
   removeItem(plf);
 }
Example #17
0
  public static void exam() {
    Track t1 = new Track("Yesterday", "The Beatles", 2, 25);
    Track t2 = new Track("Imagine", "The Beatles", 3, 45);
    Track t3 = new Track("When I'm Sixty Four", "The Beatles", 4, 10);
    Track t4 = new Track("Elinor Rigby", "The Beatles", 3, 15);
    Track t5 = new Track("Come Together", "The Beatles", 3, 32);
    Track t6 = new Track("A Hard Days Night", "The Beatles", 2, 55);

    //         System.out.println(t1 + "\n" + t2);
    //
    Playlist p1 = new Playlist("Oldies");
    p1.addTrack(t1);
    p1.addTrack(t2);
    p1.addTrack(t3);
    p1.addTrack(t4);
    p1.addTrack(t5);
    p1.addTrack(t6);

    //         System.out.println(t1.getLength());
    //
    p1.orderByArtist();
  }
Example #18
0
 /**
  * If any of these streams are already in this playlist, they will be removed before being added
  * in their new position
  */
 public void addStreams(List<String> streamIds, int position) {
   if (!canEdit) throw new SeekInnerCalmException();
   updateLock.lock();
   try {
     // Rather than buggering about inside our eventlist, we re-order the playlist and then just
     // re-add the whole
     // list again
     // First, scan through our playlist and remove any that are in this
     // list (they're being moved)
     for (Iterator<String> iter = p.getStreamIds().iterator(); iter.hasNext(); ) {
       String pStreamId = iter.next();
       if (streamIds.contains(pStreamId)) iter.remove();
     }
     if (position > p.getStreamIds().size()) position = p.getStreamIds().size();
     // Put the new streams in the right spot
     p.getStreamIds().addAll(position, streamIds);
     // Now regenerate our tracks
     regenEventList();
   } finally {
     updateLock.unlock();
   }
   runPlaylistUpdate();
 }
Example #19
0
 @Override
 public void deleteTracks(List<String> streamIds) {
   if (!canDelete) throw new SeekInnerCalmException();
   updateLock.lock();
   try {
     for (String sid : streamIds) {
       p.getStreamIds().remove(sid);
       control.stopFindingSources(sid, this);
     }
     regenEventList();
   } finally {
     updateLock.unlock();
   }
   runPlaylistUpdate();
 }
 /*
  * (non-Javadoc)
  *
  * @see org.jajuk.base.Observer#update(org.jajuk.base.Event)
  */
 public void update(JajukEvent event) {
   JajukEvents subject = event.getSubject();
   if (JajukEvents.FILE_NAME_CHANGED.equals(subject)) {
     Properties properties = event.getDetails();
     File fNew = (File) properties.get(Const.DETAIL_NEW);
     File fileOld = (File) properties.get(Const.DETAIL_OLD);
     // search references in playlists
     ReadOnlyIterator<Playlist> it = getPlaylistsIterator();
     while (it.hasNext()) {
       Playlist plf = it.next();
       if (plf.isReady()) { // check only in mounted
         // playlists, note that we can't
         // change unmounted playlists
         try {
           if (plf.getFiles().contains(fileOld)) {
             plf.replaceFile(fileOld, fNew);
           }
         } catch (Exception e) {
           Log.error(17, e);
         }
       }
     }
   }
 }
Example #21
0
 protected PlaylistTableModel(
     RobonoboFrame frame, Playlist p, boolean canEdit, EventList<Track> el, SortedList<Track> sl) {
   super(frame, el, sl, null);
   this.p = p;
   this.canEdit = canEdit;
   this.canDelete = canEdit;
   int i = 0;
   for (String sid : p.getStreamIds()) {
     trackIndices.put(sid, i++);
   }
   if (canEdit) {
     control
         .getExecutor()
         .execute(
             new CatchingRunnable() {
               public void doRun() throws Exception {
                 activate();
               }
             });
   }
 }
 /**
  * Change a playlist name.
  *
  * @param plfOld DOCUMENT_ME
  * @param sNewName DOCUMENT_ME
  * @return new playlist
  * @throws JajukException the jajuk exception
  */
 public synchronized Playlist changePlaylistFileName(Playlist plfOld, String sNewName)
     throws JajukException {
   // check given name is different
   if (plfOld.getName().equals(sNewName)) {
     return plfOld;
   }
   // check if this file still exists
   if (!plfOld.getFIO().exists()) {
     throw new JajukException(135);
   }
   java.io.File ioNew =
       new java.io.File(
           plfOld.getFIO().getParentFile().getAbsolutePath() + java.io.File.separator + sNewName);
   // recalculate file ID
   plfOld.getDirectory();
   String sNewId = PlaylistManager.createID(sNewName, plfOld.getDirectory());
   // create a new playlist (with own fio and sAbs)
   Playlist plfNew = new Playlist(sNewId, sNewName, plfOld.getDirectory());
   // Transfer all properties (id and name)
   // We use a shallow copy of properties to avoid any properties share between
   // two items
   plfNew.setProperties(plfOld.getShallowProperties());
   plfNew.setProperty(Const.XML_ID, sNewId); // reset new id and name
   plfNew.setProperty(Const.XML_NAME, sNewName); // reset new id and name
   // check file name and extension
   if (plfNew.getName().lastIndexOf('.') != plfNew.getName().indexOf('.') // just
       // one
       // '.'
       || !(UtilSystem.getExtension(ioNew).equals(Const.EXT_PLAYLIST))) { // check
     // extension
     Messages.showErrorMessage(134);
     throw new JajukException(134);
   }
   // check if future file exists (under windows, file.exists
   // return true even with different case so we test file name is
   // different)
   if (!ioNew.getName().equalsIgnoreCase(plfOld.getName()) && ioNew.exists()) {
     throw new JajukException(134);
   }
   // try to rename file on disk
   try {
     boolean result = plfOld.getFIO().renameTo(ioNew);
     if (!result) {
       throw new IOException();
     }
   } catch (Exception e) {
     throw new JajukException(134, e);
   }
   // OK, remove old file and register this new file
   removeItem(plfOld);
   registerItem(plfNew);
   return plfNew;
 }
 /**
  * Change a playlist name
  *
  * @param plfOld
  * @param sNewName
  * @return new playlist
  */
 public Playlist changePlaylistFileName(Playlist plfOld, String sNewName) throws JajukException {
   synchronized (PlaylistManager.getInstance().getLock()) {
     // check given name is different
     if (plfOld.getName().equals(sNewName)) {
       return plfOld;
     }
     // check if this file still exists
     if (!plfOld.getFio().exists()) {
       throw new JajukException(135);
     }
     java.io.File ioNew =
         new java.io.File(
             plfOld.getFio().getParentFile().getAbsolutePath()
                 + java.io.File.separator
                 + sNewName);
     // recalculate file ID
     plfOld.getDirectory();
     String sNewId = PlaylistManager.createID(sNewName, plfOld.getDirectory());
     // create a new playlist (with own fio and sAbs)
     Playlist plfNew = new Playlist(sNewId, sNewName, plfOld.getDirectory());
     plfNew.setProperties(plfOld.getProperties()); // transfert all
     // properties
     // (inc id and
     // name)
     plfNew.setProperty(XML_ID, sNewId); // reset new id and name
     plfNew.setProperty(XML_NAME, sNewName); // reset new id and name
     // check file name and extension
     if (plfNew.getName().lastIndexOf('.') != plfNew.getName().indexOf('.') // just
         // one
         // '.'
         || !(Util.getExtension(ioNew).equals(EXT_PLAYLIST))) { // check
       // extension
       Messages.showErrorMessage(134);
       throw new JajukException(134);
     }
     // check if future file exists (under windows, file.exists
     // return true even with different case so we test file name is
     // different)
     if (!ioNew.getName().equalsIgnoreCase(plfOld.getName()) && ioNew.exists()) {
       throw new JajukException(134);
     }
     // try to rename file on disk
     try {
       plfOld.getFio().renameTo(ioNew);
     } catch (Exception e) {
       throw new JajukException(134);
     }
     // OK, remove old file and register this new file
     hmItems.remove(plfOld.getID());
     if (!hmItems.containsKey(sNewId)) {
       hmItems.put(sNewId, plfNew);
     }
     // change directory reference
     plfNew.getDirectory().changePlaylistFile(plfOld, plfNew);
     return plfNew;
   }
 }
 private void playPlaylistOpen() {
   Playlist pl = new Playlist();
   pl.setPlaylistName(playlist_name.split(":")[0]);
   playlistController.upCountDisplay(pl.getPlaylistID());
   FrameMain.getInstane().addFramePlaySongInPlaylist(playlistController.getIDByPlaylistName(pl));
 }
Example #25
0
 public void nuke() {
   control.removeTrackListener(this);
   for (String streamId : p.getStreamIds()) {
     control.stopFindingSources(streamId, this);
   }
 }
Example #26
0
  /**
   * Prompt the user for input and interpret the command recieved.
   *
   * @throws MidiUnavailableException, InvalidMidiDataException
   */
  public static void executeUserCommand()
      throws MidiUnavailableException, InvalidMidiDataException {

    while (true) {
      System.out.println();
      System.out.print("Enter User Command. (Type 'quit' to quit) ");
      System.out.println();
      InputStreamReader isr = new java.io.InputStreamReader(System.in);
      BufferedReader br = new BufferedReader(isr);

      try {
        String userInput = br.readLine();
        // the userInput is evaluated to different functions encased in
        // the following if blocks.
        // some functions take in user input and evaluates what the user
        // wants by separating it into different sections
        if (userInput.equals("quit")) {
          Execution.quit(player);
          Execution.writePlaylistsToFile(library);
          break;

        } else if (userInput.startsWith("create playlist") && userInput.endsWith(")")) {
          library = Execution.createPlaylist(userInput, library);
          Execution.writePlaylistsToFile(library);

        } else if (userInput.startsWith("play playlist")) {
          String[] userInputSplited = userInput.split(" ");
          String playlist = userInputSplited[2];
          if (userInputSplited.length == 4 & userInput.matches(".*\\d.*")) {
            // When input length is 4, then play specified song that
            // user inputs
            int songIndex;
            try {
              songIndex = Integer.parseInt(userInputSplited[3]) - 1;
            } catch (NumberFormatException nfe) {
              System.out.println(
                  "Please enter a valid index that is in this playlist. Please try again.");
              continue;
            }
            try {
              player = Execution.playPlaylistSong(library, player, playlist, songIndex);
            } catch (IndexOutOfBoundsException iobe) {
              System.out.println(
                  "Please enter a valid index that is in this playlist. Please try again.");
              continue;
            } catch (NullPointerException e) {
              System.out.println("Playlist does not exist. Please try again.");
              continue;
            }

          } else if (userInputSplited.length == 3 | (!userInput.matches(".*\\d.*"))) {
            // if command does not contain integer, play entire
            // playlist
            Playlist pl;
            pl = library.findPlaylist(playlist);
            // checks if playlist exists
            if (pl == null) {
              System.out.println("Playlist does not exist. Please try again.");
              continue;
            }
            for (int i = 0; i < pl.numberOfSongs(); i++) {
              // plays the playlist songs one by one
              try {
                player = Execution.playPlaylistSong(library, player, pl, i);
              } catch (IOException e) {
                System.out.println("Midi file not available!");
              }
              player.checkIfRunning();
            }
          }

        } else if (userInput.startsWith("delete playlist")) {
          library = Execution.deletePlaylist(library, userInput);

        } else if (userInput.startsWith("find songs by")) {
          library = Execution.findSongByArtist(library, userInput);
        } else if (userInput.startsWith("play song")) {

          String[] userInputSplited = userInput.split(" ");
          int songIndex;
          try {
            songIndex = Integer.parseInt(userInputSplited[2]) - 1;
          } catch (NumberFormatException nfe) {
            // the user input can only be an integer
            System.out.println("Please enter a song index!");
            continue;
          }
          try {
            player = Execution.playSong(library, player, songIndex);
          } catch (IndexOutOfBoundsException iobe) {
            System.out.println("Song does not exist, please try again.");
            continue;
          }
        } else if (userInput.startsWith("delete song")) {
          String[] userInputSplited = userInput.split(" ");
          int songIndex;
          System.out.println(
              "Are you sure you want to permanently remove this song?(yes to confirm, type anything to return to menu)");
          String confirm = br.readLine().trim();
          // additional layer of confirmation, in case of accidental
          // deletion
          if (confirm.equals("yes")) {
            try {
              songIndex = Integer.parseInt(userInputSplited[2]) - 1;
            } catch (NumberFormatException nfe) {
              System.out.println("Please enter a song index!");
              continue;
            }
            try {
              library.delSong(songIndex);
              library = Execution.readPlaylistXml(library);
              library.displayAllLibrarySongs();
              library.displayAllLibraryPlaylists();
            } catch (IndexOutOfBoundsException iobe) {
              System.out.println("Song does not exist, please try again.");
              continue;
            }
          }
        } else if (userInput.startsWith("play random")) {
          // User may enter any of the three commands that begin with
          // play random
          // each is encased in an if block
          List<Integer> indexes;
          if (userInput.equals("play random for all")) {
            int numberOfSongs = library.numberOfSongs();

            indexes = new ArrayList<Integer>();
            for (int i = 0; i < numberOfSongs; i++) {
              indexes.add(i);
            }
            player = Execution.playRandom(library, player, indexes);

          } else if (userInput.startsWith("play random") & userInput.endsWith(")")) {
            // When user wants to play specified songs randomly
            String[] userInputSplited = userInput.split(" ");
            userInputSplited =
                userInputSplited[2].substring(1, userInputSplited[2].length() - 1).split(",");
            ArrayList<String> tempList = new ArrayList<String>(Arrays.asList(userInputSplited));

            indexes = new ArrayList<Integer>(tempList.size());
            for (String i : tempList) {
              if (Integer.valueOf(i) > library.numberOfSongs()) {
                System.out.println(
                    "the song of index "
                        + Integer.valueOf(i)
                        + " does not exist in your music libaray.");
              } else {
                indexes.add(Integer.valueOf(i) - 1);
              }
            }
            player = Execution.playRandom(library, player, indexes);

          } else if (userInput.startsWith("play random playlist")) {
            String[] userInputSplited = userInput.split(" ");
            // The 4th element in list is the playlist that user
            // wants to play randomly
            String playlist = userInputSplited[3];
            Playlist pl = library.findPlaylist(playlist);
            try {
              indexes = new ArrayList<Integer>(pl.numberOfSongs());
            } catch (NullPointerException npe) {
              System.out.println("Playlist " + playlist + " does not exist. Please try again.");
              continue;
            }

            for (int n = 0; n < pl.numberOfSongs(); n++) {
              indexes.add(n);
            }
            player = Execution.playRandom(library, player, pl, indexes);
          }

        } else if (userInput.startsWith("download")) {
          String title = userInput.split("download ")[1];
          library.downloadSong(title);

        } else if (userInput.startsWith("display jcloud songs")) {
          library.displayJcloudSongs();

        } else if (userInput.startsWith("get downloaded songs")) {
          library.downloadPreviousSongs();
          library.displayAllLibrarySongs();
        } else if (userInput.equals("display songs")) {
          library.displayAllLibrarySongs();
        } else if (userInput.equals("display library")) {
          library.displayAllLibrarySongs();
          library.displayAllLibraryPlaylists();
        } else if (userInput.equals("display playlists")) {
          library.displayAllLibraryPlaylists();
          // Shows nothing when no playlist have been created
        } else if (userInput.equals("help")) {
          displayUserManual();
        } else if (userInput.contains("pause")) {
          try {
            player.pause();
          } catch (NullPointerException e) {
            continue;
          }
        } else if (userInput.contains("resume")) {
          try {
            player.resume();
          } catch (NullPointerException e) {
            continue;
          }
        } else {
          System.out.println(
              "Invalid command. Please pay attention to input format and try again!");
        }
      } catch (IOException e) {

        e.printStackTrace();
      }
    }
  }
 // schedule list to be played at time
 ScheduledPlay(Date time, Playlist list, MusicHome mh) {
   t = new Timer();
   isPlaylist = true;
   t.schedule(new scheduledPlaylist(list, mh), time);
   System.out.println("Playlist \"" + list.getName() + "\" scheduled for: " + time);
 }
 public Playlist getPlaylist(int id) {
   for (Playlist playlist : mPlaylists) {
     if (playlist.getId() == id) return playlist;
   }
   return null;
 }
 public Playlist getPlaylist(String title) {
   for (Playlist playlist : mPlaylists) {
     if (playlist.getTitle().equals(title)) return playlist;
   }
   return null;
 }