public JSONArray buildSpotifyJsonObject(ArrayList<Trip> list) { JSONArray array = new JSONArray(); try { for (Trip trip : list) { JSONArray tracks = new JSONArray(); for (Track track : trip.getTracks()) { tracks.put( new JSONObject() .put("name", track.getName()) .put("artist", track.getArtist()) .put("duration", track.getDuration()) .put("url", track.getUrl())); } array.put( new JSONObject() .put("origin", trip.getOrigin()) .put("destination", trip.getDest()) .put("id", trip.getId()) .put("duration", trip.getDurationMs()) .put("originDate", trip.getOriginDate()) .put("destinationDate", trip.getDestDate()) .put("originTime", trip.getOriginTime()) .put("destinationTime", trip.getDestTime()) .put("playlist", tracks)); } } catch (Exception E) { } System.out.println(array); return array; }
/** Print all MIDI tracks and MIDI events */ public void print() { Enumeration aEnum = trackList.elements(); while (aEnum.hasMoreElements()) { Track track = (Track) aEnum.nextElement(); track.print(); } }
public void buildTrackAndStart() { int[] trackList = null; sequence.deleteTrack(track); track = sequence.createTrack(); for (int i = 0; i < 16; i++) { trackList = new int[16]; int key = instruments[i]; for (int j = 0; j < 16; j++) { JCheckBox jc = (JCheckBox) checkboxList.get(j + (16 * i)); if (jc.isSelected()) { trackList[j] = key; } else { trackList[j] = 0; } } // close inner loop makeTracks(trackList); track.add(makeEvent(176, 1, 127, 0, 16)); } // close outer track.add(makeEvent(192, 9, 1, 0, 15)); try { sequencer.setSequence(sequence); sequencer.setLoopCount(sequencer.LOOP_CONTINUOUSLY); sequencer.start(); sequencer.setTempoInBPM(120); } catch (Exception e) { e.printStackTrace(); } } // close buildTrackAndStart method
@Test public void getFavoritesByUserId() { mockUnauthorizedServer .expect(requestTo("https://api.soundcloud.com/users/3510549?client_id=someApiKey")) .andExpect(method(GET)) .andRespond(withResponse(jsonResource("testdata/userprofile"), responseHeaders)); mockUnauthorizedServer .expect( requestTo("https://api.soundcloud.com/users/3510549/favorites?client_id=someApiKey")) .andExpect(method(GET)) .andRespond(withResponse(jsonResource("testdata/favorites"), responseHeaders)); Page<Track> tracksPage = unauthorizedSoundCloud.usersOperations().userOperations(3510549).getFavorites(); assertEquals(0, tracksPage.getNumber()); assertEquals(56, tracksPage.getTotalElements()); List<Track> tracks = tracksPage.getContent(); assertNotNull(tracks); assertEquals(50, tracks.size()); Track firstTrack = tracks.get(0); assertEquals("Sneaky Sound System - Big (Oliver Remix)", firstTrack.getTitle()); assertEquals( "http://soundcloud.com/weareoliver/sneaky-sound-system-big-oliver", firstTrack.getPermalinkUrl()); assertEquals("22905377", firstTrack.getId()); }
@Test public void getTracks() { mockUnauthorizedServer .expect( requestTo( "https://api.soundcloud.com/resolve?url=http://soundcloud.com/mattslip&client_id=someApiKey")) .andExpect(method(GET)) .andRespond(withResponse(jsonResource("testdata/resolveuser"), responseHeaders)); mockUnauthorizedServer .expect(requestTo("https://api.soundcloud.com/users/3510549?client_id=someApiKey")) .andExpect(method(GET)) .andRespond(withResponse(jsonResource("testdata/userprofile"), responseHeaders)); mockUnauthorizedServer .expect(requestTo("https://api.soundcloud.com/users/3510549/tracks?client_id=someApiKey")) .andExpect(method(GET)) .andRespond(withResponse(jsonResource("testdata/tracks"), responseHeaders)); Page<Track> tracksPage = unauthorizedSoundCloud.usersOperations().userOperations("mattslip").getTracks(); List<Track> tracks = tracksPage.getContent(); assertEquals(0, tracksPage.getNumber()); assertEquals(50, tracksPage.getTotalElements()); assertNotNull(tracks); assertEquals(50, tracks.size()); Track firstTrack = tracks.get(0); assertEquals("Kid Sister vs Daft Punk (Monsieur Adi Mashup)", firstTrack.getTitle()); assertEquals( "http://soundcloud.com/monsieuradi/kid-sister-vs-daft-punk", firstTrack.getPermalinkUrl()); assertEquals("39679670", firstTrack.getId()); }
/** * Change the item. * * @param old DOCUMENT_ME * @param sNewName DOCUMENT_ME * @return new album * @throws JajukException the jajuk exception */ public Album changeAlbumName(Album old, String sNewName) throws JajukException { // check there is actually a change if (old.getName2().equals(sNewName)) { return old; } // check up front as later the state of the track is already changed boolean bQueueUpdateRequired = false; if (QueueModel.getPlayingFile() != null && QueueModel.getPlayingFile().getTrack().getAlbum().equals(old)) { bQueueUpdateRequired = true; } Album newItem = registerAlbum(sNewName, old.getDiscID()); // re apply old properties from old item newItem.cloneProperties(old); // update tracks for (Track track : TrackManager.getInstance().getTracks()) { if (track.getAlbum().equals(old)) { TrackManager.getInstance().changeTrackAlbum(track, sNewName, null); } } // if current track album name is changed, notify it if (bQueueUpdateRequired) { ObservationManager.notify(new JajukEvent(JajukEvents.ALBUM_CHANGED)); } // remove old item removeItem(old); return newItem; }
/** * Get sorted list of albums associated with this item. * * @param item DOCUMENT_ME * @return a list of item, void list if no result */ public synchronized List<Album> getAssociatedAlbums(Item item) { List<Album> out; // [Perf] If item is a track, just return its album if (item instanceof Track) { out = new ArrayList<Album>(1); out.add(((Track) item).getAlbum()); } else { ReadOnlyIterator<Album> albums = getAlbumsIterator(); // Use a set to avoid dups Set<Album> albumSet = new HashSet<Album>(); while (albums.hasNext()) { Album album = albums.next(); for (Track track : album.getTracksCache()) { if (item instanceof Artist && track.getArtist().equals(item)) { albumSet.add(album); } else if (item instanceof Genre && track.getGenre().equals(item)) { albumSet.add(album); } if (item instanceof Year && track.getYear().equals(item)) { albumSet.add(album); } } } out = new ArrayList<Album>(albumSet); Collections.sort(out); } return out; }
static List<Track> tstLoadFi( TrackLoader trackLoader, String filepath, Integer expected_tracks, Genome genome, boolean makeIndex) throws Exception { ResourceLocator locator = new ResourceLocator(filepath); // Try creating an index // UI would ask for confirmation if (makeIndex) { try { TestUtils.createIndex(filepath); } catch (Exception e) { } } List<Track> tracks = trackLoader.load(locator, genome); if (expected_tracks != null) { assertEquals(expected_tracks.intValue(), tracks.size()); if (expected_tracks == 0) { return tracks; } } Track track = tracks.get(0); assertEquals(locator, track.getResourceLocator()); return tracks; }
private void deleteAllShipLoads() { if (_track != null) { for (String loadName : _track.getShipLoadNames()) { _track.deleteShipLoadName(loadName); } } }
private void updateShipLoadNames() { log.debug("Update ship load names"); panelShipLoads.removeAll(); if (_track != null) { // set radio button shipLoadNameAll.setSelected(_track.getShipLoadOption().equals(Track.ALL_LOADS)); shipLoadNameInclude.setSelected(_track.getShipLoadOption().equals(Track.INCLUDE_LOADS)); shipLoadNameExclude.setSelected(_track.getShipLoadOption().equals(Track.EXCLUDE_LOADS)); pShipLoadControls.setVisible(!shipLoadNameAll.isSelected()); if (!shipLoadNameAll.isSelected()) { int x = 0; int y = 0; // vertical position in panel int numberOfLoads = getNumberOfCheckboxesPerLine() / 2 + 1; for (String loadName : _track.getShipLoadNames()) { JLabel load = new JLabel(); load.setText(loadName); addItemTop(panelShipLoads, load, x++, y); // limit the number of loads per line if (x > numberOfLoads) { y++; x = 0; } } revalidate(); } } else { shipLoadNameAll.setSelected(true); } panelShipLoads.repaint(); panelShipLoads.revalidate(); }
/** * muestra los detalles de todos los tracks almacenados en un organizador usando un iterador. * ------------------- 0055 */ public void listAllTrackWithIterator() { Iterator<Track> pistas = tracks.iterator(); while (pistas.hasNext()) { Track mostrarPistas = pistas.next(); System.out.println(mostrarPistas.getDetails()); } }
public boolean sameMainMetaData(Track t) { if (t == null) return false; return (compare(t.getTitle(), mTitle) && compare(t.getAlbumTitle(), mAlbumTitle) && compare(t.getArtistName(), mArtistName)); }
public void buttonActionPerformed(java.awt.event.ActionEvent ae) { if (ae.getSource() == saveButton) { // confirm that factor is between 0 and 1000 try { int factor = Integer.parseInt(factorTextField.getText()); if (factor < 0 || factor > 1000) { JOptionPane.showMessageDialog( this, Bundle.getMessage("FactorMustBeNumber"), Bundle.getMessage("ErrorFactor"), JOptionPane.ERROR_MESSAGE); return; } } catch (NumberFormatException e) { JOptionPane.showMessageDialog( this, Bundle.getMessage("FactorMustBeNumber"), Bundle.getMessage("ErrorFactor"), JOptionPane.ERROR_MESSAGE); return; } _track.setReservationFactor(Integer.parseInt(factorTextField.getText())); if (trackBox.getSelectedItem() != null && !trackBox.getSelectedItem().equals(Location.NONE)) { _track.setAlternateTrack((Track) trackBox.getSelectedItem()); } else { _track.setAlternateTrack(null); } OperationsXml.save(); if (Setup.isCloseWindowOnSaveEnabled()) { dispose(); } } }
private void autoscale() { int stateHash = FrameManager.getStateHash(); // if(lastFrameStateHash == stateHash) return; lastStateHash = stateHash; final Collection<Track> trackList = IGV.getInstance().getAllTracks(); Map<String, List<Track>> autoscaleGroups = new HashMap<String, List<Track>>(); for (Track track : trackList) { if (!track.isVisible()) continue; String asGroup = track.getAttributeValue(AttributeManager.GROUP_AUTOSCALE); if (asGroup != null) { if (!autoscaleGroups.containsKey(asGroup)) { autoscaleGroups.put(asGroup, new ArrayList<Track>()); } autoscaleGroups.get(asGroup).add(track); } else if (track.getAutoScale()) { autoscaleGroup(Arrays.asList(track)); } } if (autoscaleGroups.size() > 0) { for (List<Track> tracks : autoscaleGroups.values()) { autoscaleGroup(tracks); } } }
public void go() { setUpGui(); try { Sequencer sequencer = MidiSystem.getSequencer(); sequencer.open(); // make a sequencer and open sequencer.addControllerEventListener(m1, new int[] {127}); Sequence seq = new Sequence(Sequence.PPQ, 4); Track track = seq.createTrack(); int r = 0; for (int i = 0; i < 300; i += 4) { r = (int) ((Math.random() * 50) + 1); track.add(makeEvent(144, 1, r, 100, i)); track.add(makeEvent(176, 1, 127, 0, i)); track.add(makeEvent(128, 1, r, 100, i + 2)); } // end loop sequencer.setSequence(seq); sequencer.start(); sequencer.setTempoInBPM(120); } catch (Exception ex) { ex.printStackTrace(); } } // close method
/** * List all tracks by the given artist. * * @param artist The artist's name. */ public void listByArtist(String artist) { for (Track track : tracks) { if (track.getArtist().contains(artist)) { System.out.println(track.getDetails()); } } }
protected void updateButtons(boolean enabled) { saveTrackButton.setEnabled(enabled); loadNameAll.setEnabled(enabled); loadNameInclude.setEnabled(enabled); loadNameExclude.setEnabled(enabled); loadAndTypeCheckBox.setEnabled(enabled); boolean en = enabled && (_track.isAddCustomLoadsAnyStagingTrackEnabled() || _track.isAddCustomLoadsAnySpurEnabled() || _track.isAddCustomLoadsEnabled()); shipLoadNameAll.setEnabled(en); shipLoadNameInclude.setEnabled(en); shipLoadNameExclude.setEnabled(en); shipLoadAndTypeCheckBox.setEnabled(en); addShipLoadButton.setEnabled(en); deleteShipLoadButton.setEnabled(en); deleteAllShipLoadsButton.setEnabled(en); comboBoxShipLoads.setEnabled(en); comboBoxShipTypes.setEnabled(en); }
/** * Adds a new Track associated with this ProxySession. * * @param url The URL used as a control reference for the Track * @param serverSsrc the SSRC id given by the server or null if not provided * @return a reference to the newly created Track */ public synchronized Track addTrack(String url, String serverSsrc) { Track track = new Track(url); if (serverSsrc != null) track.setServerSSRC(serverSsrc); trackList.put(url, track); log.debug("ProxySession: " + clientSessionId + " Added track. TrackList: " + trackList); return track; }
/** * añade un método a la clase MusicOrganizer llamado findInTitle que tome un único parámetro de * tipo String y muestre por pantalla la información de los tracks que contienen dicha cadena en * el título de la canción. ------------ 0052 */ public void findInTitle(String informaciónDeTracks) { for (Track datos : tracks) { // --------------------------------------------------------------------- 0052 if (datos.getTitle().contains(informaciónDeTracks)) { System.out.println(datos.getDetails()); } } }
/** Show a list of all the tracks in the collection. */ public void listAllTracks() { System.out.println("Track listing: "); for (Track track : tracks) { System.out.println(track.getDetails()); } System.out.println(); }
/** * que permita eliminar del organizador los tracks que contengan una determinada cadena en el * título de la canción */ public void removeByTitle( String titulo) { // ------------------------------------------------- 0055 Iterator<Track> pistas = tracks.iterator(); while (pistas.hasNext()) { Track mostrarPistas = pistas.next(); if (mostrarPistas.getTitle().contains(titulo)) { pistas.remove(); } } }
/** * permite reproducir los primeros segundos de cada canción en orden aleatorio y cumple los * siguientes requisitos: Cada canción debe reproducirse una única vez y deben reproducirse todas * las canciones. Los contadores de reproducción deben actualizarse correctamente. Debe mostrar * por pantalla los detalles de la canción que está sonando en este momento. -------------------- * 0057 */ public void playSuffle() { // ------------------------------------------------------------------------------ 0057 Collections.shuffle( tracks); // ---solo con esta línea la colección queda desordenada aleatoriament. for (Track track : tracks) { track.incrementaContadorReproduciones(); System.out.println("Canción de. " + track.getDetails()); player.playSample(track.getFilename()); } }
/** * permita eliminar del organizador los tracks que contengan un determinado artista usando un * iterador */ public void removeByArtist( String nombreAr) { // ------------------------------------------------- 0055 Iterator<Track> pistas = tracks.iterator(); while (pistas.hasNext()) { Track mostrarPistas = pistas.next(); if (mostrarPistas.getArtist().contains(nombreAr)) { pistas.remove(); } } }
private void checkForErrors() { if (_track.getLoadOption().equals(Track.INCLUDE_LOADS) && _track.getLoadNames().length == 0 || _track.getShipLoadOption().equals(Track.INCLUDE_LOADS) && _track.getShipLoadNames().length == 0) { JOptionPane.showMessageDialog( this, Bundle.getMessage("ErrorNeedLoads"), Bundle.getMessage("ErrorNoLoads"), JOptionPane.ERROR_MESSAGE); } }
@Override public int compare(Track track1, Track track2) { // Disabled tracks come second if (track1.isEnabled() && !track2.isEnabled()) { return -1; } else if (!track1.isEnabled() && track2.isEnabled()) { return 1; } else { return compareByType(track1, track2); } }
public void makeTracks(int[] list) { for (int i = 0; i < 16; i++) { int key = list[i]; if (key != 0) { track.add(makeEvent(144, 9, key, 100, i)); track.add(makeEvent(128, 9, key, 100, i + 1)); } } }
public void loadDataTrack(String path) { allTracks = new HashMap<Integer, Track>(); List<String> data = loadData(path); for (String str : data) { Track track = new Track(); String[] strArray = str.split("\\|"); int trackId = Integer.parseInt(strArray[0]); int trackAlbum = -1; // -1 means none int trackArtist = -1; List<Integer> trackGenres = new LinkedList<Integer>(); if (!strArray[1].equals("None")) { trackAlbum = Integer.parseInt(strArray[1]); if (allAlbums.containsKey(trackAlbum)) { Album album = allAlbums.get(trackAlbum); List<Integer> tracksInList = album.getTracks(); tracksInList.add(trackId); album.setTracks(tracksInList); allAlbums.put(trackAlbum, album); } } if (!strArray[2].equals("None")) { trackArtist = Integer.parseInt(strArray[2]); if (allArtists.containsKey(trackArtist)) { Artist artist = allArtists.get(trackArtist); List<Integer> tracksInList = artist.getTracks(); tracksInList.add(trackId); artist.setTracks(tracksInList); allArtists.put(trackArtist, artist); } } if (strArray.length > 3) { for (int i = 0; i < strArray.length - 3; i++) { int trackGenre = Integer.parseInt(strArray[i + 3]); trackGenres.add(trackGenre); if (allGenres.containsKey(trackGenre)) { Genre genre = allGenres.get(trackGenre); List<Integer> tracksInList = genre.getTracks(); tracksInList.add(trackId); genre.setTracks(tracksInList); allGenres.put(trackGenre, genre); } } } else { trackGenres.add(-1); } track.setId(trackId); track.setAlbumId(trackAlbum); track.setArtistId(trackArtist); track.setGenreId(trackGenres); allTracks.put(trackId, track); } }
/** * Play a track in the collection. * * @param index The index of the track to be played. */ public void playTrack(int index) { if (indexValid(index) && reproduciendose == false) { Track track = tracks.get(index); track .incrementaContadorReproduciones(); // ----------------------- 0052 para incrementar el nº // de reproducciones reproduciendose = true; // --------------------------------------- 0054 player.startPlaying(track.getFilename()); System.out.println("Now playing: " + track.getArtist() + " - " + track.getTitle()); } else { System.out.println("Error ya hay una reproducción en curso "); } }
private void loadNotes() { int program = 0; HashMap<Integer, Float> lastTimeNote = new HashMap<Integer, Float>(); HashMap<Float, Integer> secondsNotes = new HashMap<Float, Integer>(); this.notas = new ArrayList<MIDINote>(); for (Track track : sequencia.getTracks()) { for (int c = 0; c < track.size(); ++c) { MidiEvent event = track.get(c); MidiMessage msg = event.getMessage(); if (msg instanceof ShortMessage) { ShortMessage shortmsg = (ShortMessage) msg; if (shortmsg.getCommand() == ShortMessage.PROGRAM_CHANGE) { program = shortmsg.getData1(); } else { // }else if(program>=25 && program <= 40){ // else if(program== 30){ if (shortmsg.getCommand() == ShortMessage.NOTE_ON) { MIDINote midiNote = new MIDINote(event, sequencia, tempoProcessor, program); // tocador.start(); int noteChord = midiNote.getChord(); float noteSecond = midiNote.getSecond(); if (!lastTimeNote.containsKey(noteChord)) { lastTimeNote.put(noteChord, 0.0f); } if (noteSecond - lastTimeNote.get(noteChord).floatValue() <= this.interval) { continue; } lastTimeNote.put(noteChord, noteSecond); // System.out.println("Play chord "+noteChord+" in "+noteSecond+" seconds"); notas.add(midiNote); if (!secondsNotes.containsKey(noteSecond)) { secondsNotes.put(noteSecond, 1); } secondsNotes.put(noteSecond, secondsNotes.get(noteSecond).intValue() + 1); } } } } } // System.out.println("tamanho da pista "+notas.size()+" e track "+maxNote); for (float second : secondsNotes.keySet()) { int repeated = secondsNotes.get(second).intValue(); if (repeated > maxNote) { this.maxNote = repeated; } } this.notesLength = secondsNotes.size(); // GameEngine.getInstance().setFramesPerSecond((int)(((tocador.getMicrosecondLength()/1000000)/(notas.size()*1.0))*4000)); // System.out.println("(int)(("+sequencia.getMicrosecondLength()+"/1000000)/"+notas.size()+"="+(int)((sequencia.getMicrosecondLength()/1000000)/notas.size())) }
// Save, Delete, Add public void buttonActionPerformed(java.awt.event.ActionEvent ae) { if (_track == null) { return; } if (ae.getSource() == saveTrackButton) { log.debug("track save button activated"); save(); if (Setup.isCloseWindowOnSaveEnabled()) { dispose(); } } if (ae.getSource() == addLoadButton) { String loadName = (String) comboBoxLoads.getSelectedItem(); if (loadAndTypeCheckBox.isSelected()) { loadName = comboBoxTypes.getSelectedItem() + CarLoad.SPLIT_CHAR + loadName; } _track.addLoadName(loadName); selectNextItemComboBox(comboBoxLoads); } if (ae.getSource() == deleteLoadButton) { String loadName = (String) comboBoxLoads.getSelectedItem(); if (loadAndTypeCheckBox.isSelected()) { loadName = comboBoxTypes.getSelectedItem() + CarLoad.SPLIT_CHAR + loadName; } _track.deleteLoadName(loadName); selectNextItemComboBox(comboBoxLoads); } if (ae.getSource() == deleteAllLoadsButton) { deleteAllLoads(); } if (ae.getSource() == addShipLoadButton) { String loadName = (String) comboBoxShipLoads.getSelectedItem(); if (shipLoadAndTypeCheckBox.isSelected()) { loadName = comboBoxShipTypes.getSelectedItem() + CarLoad.SPLIT_CHAR + loadName; } _track.addShipLoadName(loadName); selectNextItemComboBox(comboBoxShipLoads); } if (ae.getSource() == deleteShipLoadButton) { String loadName = (String) comboBoxShipLoads.getSelectedItem(); if (shipLoadAndTypeCheckBox.isSelected()) { loadName = comboBoxShipTypes.getSelectedItem() + CarLoad.SPLIT_CHAR + loadName; } _track.deleteShipLoadName(loadName); selectNextItemComboBox(comboBoxShipLoads); } if (ae.getSource() == deleteAllShipLoadsButton) { deleteAllShipLoads(); } }