Package it.unipd.netmus.client.ui

Examples of it.unipd.netmus.client.ui.ProfileView$Song


*/
public class DynamicPlaylistExample {

    public static void main(String[] args) throws EchoNestException, IOException {
        EchoNestAPI en = new EchoNestAPI();
        Song lastSong = null;
        en.setTraceSends(false);

        DynamicPlaylistParams params = new DynamicPlaylistParams();
        params.setType(PlaylistParams.PlaylistType.GENRE_RADIO);
        params.addGenre("dance pop");
        params.setMinEnergy(.6f);
        params.setMinDanceability(.6f);
        params.includeAudioSummary();
        DynamicPlaylistSession session = en.createDynamicPlaylist(params);


        boolean done = false;
        while (!done) {
            String keys = "nsfd+-";

            System.out.println();
            System.out.print("(n)ext (s)kip (f)av (d)one (+)faster (-)slower ->");

            int cv;
            do {
                cv = System.in.read();
            } while (keys.indexOf(cv) < 0);

            char c = (char) cv;

            // System.out.println("c " + c + " " + cv);

            if (c == 'd') {
                done = true;
            }

            if (c == 'f') {
                session.feedback(DynamicPlaylistSession.FeedbackType.favorite_song, "last");
            }

            if (c == 's') {
                session.feedback(DynamicPlaylistSession.FeedbackType.skip_song, "last");
            }

            if (c == 'n') {
                Playlist playlist = session.next();

                for (Song song : playlist.getSongs()) {
                    System.out.println(song.getTitle());
                    System.out.println(song.getArtistName());
                    System.out.printf("Dance: %f\n", song.getDanceability());
                    System.out.printf("Energy: %f\n", song.getEnergy());
                    System.out.printf("Tempo: %f\n", song.getTempo());
                    lastSong = song;
                }
            }

            if (c == '+') {
                if (lastSong != null) {
                    DynamicPlaylistSteerParams steerParams = new DynamicPlaylistSteerParams();
                    steerParams.addTargetValue(DynamicPlaylistSteerParams.SteeringParameter.tempo, (float) lastSong.getTempo() * 1.2f);
                    System.out.println("steer " + steerParams);
                    session.steer(steerParams);
                }
            }

            if (c == '-') {
                if (lastSong != null) {
                    DynamicPlaylistSteerParams steerParams = new DynamicPlaylistSteerParams();
                    steerParams.addTargetValue(DynamicPlaylistSteerParams.SteeringParameter.tempo, (float) lastSong.getTempo() * .8f);
                    System.out.println("steer " + steerParams);

                    session.steer(steerParams);
                }
            }
View Full Code Here


            public String execute(Shell ci, String[] args) throws Exception {
                SongParams p = new SongParams();
                p.setID(args[1]);
                List<Song> songs = en.getSongs(p);
                if (songs.size() >= 1) {
                    Song song = songs.get(0);
                    System.out.println(song.toString());

                }
                return "";
            }

            public String getHelp() {
                return "gets info for a song ";
            }
        });

        shell.add("hot_songs", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                boolean old_way = true;
                SongParams p = new SongParams();
                p.sortBy(SongParams.SORT_SONG_HOTTTNESSS, false);

                String description = Shell.mash(args, 1);

                if (old_way) {
                    p.addDescription(description);
                } else {
                    if (description.length() > 0) {
                        String[] fields = description.split(",");
                        for (String f : fields) {
                            p.addDescription(f.trim());
                        }
                    }
                }
                List<Song> songs = en.searchSongs(p);
                for (Song song : songs) {
                    System.out.println(song.toString());
                }
                return "";
            }

            public String getHelp() {
                return "show hot songs";
            }
        });

        shell.add("display_count", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                if (args.length == 2) {
                    displayCount = Integer.parseInt(args[1]);
                } else {
                    System.out.println("Display count: " + displayCount);
                }
                return "";
            }

            public String getHelp() {
                return "sets/gets the number of items to display";
            }
        });

        shell.add("get_similar", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    System.out.println("Similarity for " + artist.getName());
                    List<Artist> artists = artist.getSimilar(displayCount);
                    for (Artist sartist : artists) {
                        System.out.printf("  %s\n", sartist.getName());
                    }

                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "finds similar artists";
            }
        });

        shell.add("get_blogs", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    dumpDocs("blogs", artist.getBlogs());
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets blogs for an artist";
            }
        });

        shell.add("get_images", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    dumpDocs("images", artist.getImages());
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets images for an artist";
            }
        });

        shell.add("get_audio", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    dumpDocs("audio", artist.getAudio());
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets audio for an artist";
            }
        });

        shell.add("get_bio", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    dumpDocs("audio", artist.getBiographies());
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets bios for an artist";
            }
        });

        shell.add("get_album_art", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                SongParams p = new SongParams();
                p.setArtist(args[1]);
                p.setTitle(args[2]);
                p.includeTracks();
                p.setLimit(true);
                p.addIDSpace("7digital-US");
                List<Song> songs = en.searchSongs(p);
                for (Song song : songs) {
                    System.out.println(song.toString());
                    String url = song.getString("tracks[0].release_image");
                    System.out.println("release image" + url);
                }
                return "";
            }

            public String getHelp() {
                return "shows cover art for a song";
            }
        });


        shell.add("get_song_foreign_ids", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                SongParams p = new SongParams();
                p.setArtist(args[1]);
                p.setTitle(args[2]);
                p.includeTracks();
                p.setLimit(true);
                p.addIDSpace("rdio-us-streaming");
                List<Song> songs = en.searchSongs(p);
                for (Song song : songs) {
                    System.out.println(song.toString());
                    String fid = song.getString("foreign_ids[0].foreign_id");
                    System.out.println("fid is " + fid);
                }
                return "";
            }

            public String getHelp() {
                return "demonstrate how to extract song foreign ids from a song";
            }
        });

        shell.add("get_urls", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    System.out.println("URLS for " + artist.getName());
                    Map<String, String> urlMap = artist.getUrls();
                    List<String> keys = new ArrayList<String>(urlMap.keySet());
                    Collections.sort(keys);
                    for (String key : keys) {
                        System.out.printf("%20s : %s\n", key, urlMap.get(key));
                    }
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets urls for an artist";
            }
        });

        shell.add("get_video", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    dumpDocs("video", artist.getVideos());
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets videos for an artist";
            }
        });

        shell.add("get_news", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    dumpDocs("news", artist.getNews());
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets news for an artist";
            }
        });

        shell.add("get_reviews", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    dumpDocs("reviews", artist.getReviews());
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets reviews for an artist";
            }
        });

        shell.add("get_artist_location", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    ArtistLocation location = artist.getArtistLocation();
                    System.out.println("Location is " + location.getLocation());
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets location for an artist";
            }
        });

        shell.add("get_terms", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    System.out.println("Terms for " + artist.getName());
                    List<Term> terms = artist.getTerms();
                    for (Term term : terms) {
                        System.out.printf("%.2f %s\n", term.getWeight(), term
                                .getName());
                    }
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets terms for an artist";
            }
        });

        shell.add("get_fam", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    System.out.println("Familiarity for " + artist.getName()
                            + " " + artist.getFamiliarity());
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets familiarity for an artist";
            }
        });

        shell.add("get_hot", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                Artist artist = getArtist(Shell.mash(args, 1));
                if (artist != null) {
                    System.out.println("Hotttnesss for " + artist.getName()
                            + " " + artist.getHotttnesss());
                } else {
                    System.out.println("Can't find artist");
                }
                return "";
            }

            public String getHelp() {
                return "gets hotttnesss for an artist";
            }
        });

        shell.add("trackUpload", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                String arg = null;
                if (args.length >= 2) {
                    arg = Shell.mash(args, 1);
                } else {
                    arg = Utilities.createNewAudioFile("au").getAbsolutePath();
                }
                try {
                    Track track;
                    if (arg.startsWith("http:")) {
                        track = en.uploadTrack(new URL(arg), true);
                    } else {
                        System.out.println("md5 is " + Utilities.md5(arg));
                        track = en.uploadTrack(new File(arg));
                    }
                    track.waitForAnalysis(30000);
                    System.out.println("ID: " + track.getID() + " status "
                            + track.getStatus());

                    currentTrack = track;
                    System.out.println("Tempo is "
                            + track.getAnalysis().getTempo());
                } catch (IOException e) {
                    System.out.println("Trouble uploading");
                }
                return "";
            }

            public String getHelp() {
                return "uploads a track";
            }
        });

        shell.add("trackBeats", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                TrackAnalysis a = currentTrack.getAnalysis();
                List<TimedEvent> beats = a.getBeats();
                for (TimedEvent beat : beats) {
                    System.out.printf("%.6f, %.6f\n", beat.getStart(), beat
                            .getDuration());
                }
                return "";
            }

            public String getHelp() {
                return "uploads a track";
            }
        });

        shell.add("trackReanalyze", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                if (args.length == 2) {
                    Track track = en.newTrackByID(args[1]);
                    Track.AnalysisStatus status = track.reanalyze(true);
                    System.out.println("Analysis status " + status);
                } else {
                    System.out.println("trackReanalyze TRID");
                }
                return "";
            }

            public String getHelp() {
                return "reanalyzes a trak";
            }
        });

        shell.add("stats", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                en.showStats();
                return "";
            }

            public String getHelp() {
                return "shows stats";
            }
        });

        shell.add("acov" + "", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {

                int count = 100;
                String[] buckets = {"audio", "biographies", "blogs",
                    "familiarity", "hotttnesss", "images", "news",
                    "reviews", "urls", "video"};

                if (args.length >= 2) {
                    count = Integer.parseInt(args[1]);
                }

                if (todo.size() == 0) {
                    Artist seed = getArtist("The Beatles");
                    todo.add(seed);
                }

                for (int i = 0; i < count; i++) {
                    Artist next = null;

                    while (todo.size() > 0 && next == null) {
                        next = todo.remove(0);
                        if (!done.contains(next)) {
                            break;
                        }
                    }

                    if (next != null) {
                        done.add(next);

                        next.fetchBuckets(buckets);
                        float score = scoreArtist(next);
                        if (i % 20 == 0) {
                            System.out
                                    .printf(
                                    "%5s %3s %3s %3s %3s %3s %3s %3s %3s %5s %5s %s\n",
                                    "score", "aud", "bio", "blg",
                                    "img", "nws", "rvs", "vid", "url",
                                    "hot", "fam", "");
                        }

                        System.out
                                .printf(
                                "%5.1f %3d %3d %3d %3d %3d %3d %3d %3d %.3f %.3f %s\n",
                                score, next.getAudio().size(), next
                                .getBiographies().size(), next
                                .getBlogs().size(), next
                                .getImages().size(), next
                                .getNews().size(), next
                                .getReviews().size(), next
                                .getVideos().size(), next
                                .getUrls().size(), next
                                .getHotttnesss(), next
                                .getFamiliarity(), next
                                .getName());
                        todo.addAll(next.getSimilar(20));
                        Collections.shuffle(todo);
                    }
                }
                return "";
            }

            public String getHelp() {
                return "shows artist coverage";
            }
        });

        shell.add("mbidtest", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                int count = 100;
                if (args.length >= 2) {
                    count = Integer.parseInt(args[1]);
                }
                for (Artist artist : en.topHotArtists(count)) {
                    String mbid = artist.getForeignID("musicbrainz");
                    if (mbid != null && mbid.length() > 0) {
                        Artist nArtist = en.newArtistByID(mbid);
                        String status = "FAIL";
                        if (artist.equals(nArtist)) {
                            status = "GOOD";
                        }
                        System.out.printf("   %s %s %s %s %s\n", status, mbid,
                                artist.getName(), nArtist
                                .getForeignID("musicbrainz"), nArtist
                                .getName());
                    } else {
                        System.out.printf("MISSING mbid for %s\n", artist
                                .getName());
                    }
                }
                return "";
            }

            public String getHelp() {
                return "test mbids for popular artists";
            }
        });

        shell.add("scov", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                int count = 100;
                boolean showSims = false;
                if (args.length >= 2) {
                    count = Integer.parseInt(args[1]);
                }

                if (args.length >= 3) {
                    showSims = true;
                }

                if (todo.size() == 0) {
                    Artist seed = getArtist("The Beatles");
                    todo.add(seed);
                }

                for (int i = 0; i < count; i++) {
                    Artist next = null;

                    while (todo.size() > 0 && next == null) {
                        next = todo.remove(0);
                        if (!done.contains(next)) {
                            break;
                        }
                    }

                    if (next != null) {
                        done.add(next);
                        System.out.printf("%s %s\n", next.getID(), next
                                .getName());
                        try {
                            List<Artist> sims = next.getSimilar(15);
                            if (showSims) {
                                for (Artist sim : sims) {
                                    System.out
                                            .printf("    %s\n", sim.getName());
                                }
                            }
                            todo.addAll(sims);
                        } catch (EchoNestException e) {
                            System.out.printf("WARNING, no sims for %s %s\n",
                                    next.getID(), next.getName());
                        }
                        Collections.shuffle(todo);
                    }
                }
                return "";
            }

            public String getHelp() {
                return "shows artist similarity coverage";
            }
        });

        shell.add("splaylist", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                PlaylistParams p = new PlaylistParams();
                p.setType(PlaylistType.ARTIST_RADIO);
                p.addArtist(Shell.mash(args, 1));
                p.setResults(10);
                p.setVariety(.5f);
                Playlist playlist = en.createStaticPlaylist(p);
                for (Song song : playlist.getSongs()) {
                    System.out.printf("%40.40s %s\n", song.getArtistName(),
                            song.getTitle());
                }
                return "";
            }

            public String getHelp() {
                return "generates an artist radio playlist";
            }
        });


        shell.add("bplaylist", new ShellCommand() {
            public String execute(Shell ci, String[] args) throws Exception {
                BasicPlaylistParams p = new BasicPlaylistParams();
                p.setType(BasicPlaylistParams.PlaylistType.ARTIST_RADIO);
                p.addArtist(Shell.mash(args, 1));
                p.setResults(10);
                Playlist playlist = en.createBasicPlaylist(p);
                for (Song song : playlist.getSongs()) {
                    System.out.printf("%40.40s %s\n", song.getArtistName(),
                            song.getTitle());
                }
                return "";
            }

            public String getHelp() {
View Full Code Here

            @Override
            public void onSuccess(final String user) {

                client_factory.getProfileView().setUser(user);
                final ProfileView profileView = client_factory.getProfileView();

                // Gestore degli eventi DeviceScannedEvent. Questo metodo viene
                // invocato al termine
                // di ogni inserimento di canzoni (sia da USB che da file
                // system)
                client_factory.getEventBus().addHandler(
                        DeviceScannedEvent.TYPE,
                        new DeviceScannedEventHandler() {

                            // L'evento porta con se la lista delle nuove
                            // canzoni inserite, queste
                            // vanno ad aggiornare la libreria dell'utente
                            // mantenuta nell'activity
                            @Override
                            public void onScanDevice(DeviceScannedEvent event) {

                                List<String> tmp_list = new ArrayList<String>();

                                for (SongDTO tmp : event.getNewSongs()) {
                                    if (!tmp.getTitle().equals("")) {

                                        if (current_user
                                                .getMusicLibrary()
                                                .getSongs()
                                                .put(FieldVerifier.generateSongId(
                                                        tmp.getTitle(),
                                                        tmp.getArtist(),
                                                        tmp.getAlbum()),
                                                        new SongSummaryDTO(tmp
                                                                .getArtist(),
                                                                tmp.getTitle(),
                                                                tmp.getAlbum())) == null) {
                                            tmp_list.add(tmp.getArtist());
                                            tmp_list.add(tmp.getTitle());
                                            tmp_list.add(tmp.getAlbum());
                                        }
                                    }
                                }

                                client_factory.getProfileView().paintCatalogo(
                                        tmp_list);

                                if (event.isLastSongs()) {
                                    client_factory.getProfileView()
                                            .sortCatalogo();

                                    String preferred_artist = calculatePreferredArtist(current_user
                                            .getMusicLibrary().getSongs());

                                    // Aggiornamento delle statistiche calcolate
                                    // nel catalogo mantenuto nel client
                                    current_user.getMusicLibrary()
                                            .setPreferred_artist(
                                                    preferred_artist);

                                    // Aggiornamento delle statistiche calcolate
                                    // nel Datastore
                                    library_service_svc.storeStatistics(
                                            current_user.getUser(),
                                            preferred_artist, "", "",
                                            new AsyncCallback<Void>() {
                                                @Override
                                                public void onFailure(
                                                        Throwable caught) {
                                                    client_factory
                                                            .getProfileView()
                                                            .showError(
                                                                    my_constants
                                                                            .storeStatisticsError());

                                                }

                                                @Override
                                                public void onSuccess(
                                                        Void result) {
                                                }
                                            });

                                    // Aggiornamento della lista degli utenti
                                    // affini
                                    setFriendList();

                                }
                            }

                        });

                profileView.setName(name);
                profileView.setPresenter(ProfileActivity.this);

                // inizializzazione dell'UserCompleteDTO mantenuto nell'activity
                user_service_svc.loadProfile(user,
                        new AsyncCallback<UserCompleteDTO>() {
                            @Override
                            public void onFailure(Throwable caught) {
                                client_factory.getProfileView().showError(
                                        my_constants.loadProfileError());
                            }

                            @Override
                            public void onSuccess(UserCompleteDTO result) {
                                current_user = result;

                                List<String> tmp = new ArrayList<String>();
                                for (SongSummaryDTO dto : result
                                        .getMusicLibrary().getSongs().values()) {
                                    tmp.add(dto.getArtist());
                                    tmp.add(dto.getTitle());
                                    tmp.add(dto.getAlbum());
                                }
                                client_factory.getProfileView().paintCatalogo(
                                        tmp);
                                client_factory.getProfileView().sortCatalogo();

                                setPlaylistList();
                                setFriendList();
                                profileView.setUser(user);
                                profileView.setInfo(getSongInfo());
                                editProfileView(user);

                                container_widget.setWidget(profileView
                                        .asWidget());
                                profileView.setLayout();
                               
                                if (tmp.size() == 0) {
                                    // mostra help
                                    client_factory.getProfileView().showHelp();
                                }
View Full Code Here

TOP

Related Classes of it.unipd.netmus.client.ui.ProfileView$Song

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.