private void tune(final Receiver recv) { try { if (rebasedTuning != null) { for (int i = 0; i < 16; i++) { MidiUtils.sendTunings(recv, i, 0, "african", rebasedTuning); MidiUtils.sendTuningChange(recv, i, 0); } } } catch (final IOException e) { LOG.log(Level.SEVERE, e.getMessage(), e); } catch (final InvalidMidiDataException e) { LOG.log(Level.SEVERE, e.getMessage(), e); } }
/** * Adds a new event to the track. However, if the event is already contained in the track, it is * not added again. The list of events is kept in time order, meaning that this event inserted at * the appropriate place in the list, not necessarily at the end. * * @param event the event to add * @return <code>true</code> if the event did not already exist in the track and was added, * otherwise <code>false</code> */ public boolean add(MidiEvent event) { if (event == null) { return false; } synchronized (eventsList) { if (!set.contains(event)) { int eventsCount = eventsList.size(); // get the last event MidiEvent lastEvent = null; if (eventsCount > 0) { lastEvent = (MidiEvent) eventsList.get(eventsCount - 1); } // sanity check that we have a correct end-of-track if (lastEvent != eotEvent) { // if there is no eot event, add our immutable instance again if (lastEvent != null) { // set eotEvent's tick to the last tick of the track eotEvent.setTick(lastEvent.getTick()); } else { // if the events list is empty, just set the tick to 0 eotEvent.setTick(0); } // we needn't check for a duplicate of eotEvent in "eventsList", // since then it would appear in the set. eventsList.add(eotEvent); set.add(eotEvent); eventsCount = eventsList.size(); } // first see if we are trying to add // and endoftrack event. if (MidiUtils.isMetaEndOfTrack(event.getMessage())) { // since end of track event is useful // for delays at the end of a track, we want to keep // the tick value requested here if it is greater // than the one on the eot we are maintaining. // Otherwise, we only want a single eot event, so ignore. if (event.getTick() > eotEvent.getTick()) { eotEvent.setTick(event.getTick()); } return true; } // prevent duplicates set.add(event); // insert event such that events is sorted in increasing // tick order int i = eventsCount; for (; i > 0; i--) { if (event.getTick() >= ((MidiEvent) eventsList.get(i - 1)).getTick()) { break; } } if (i == eventsCount) { // we're adding an event after the // tick value of our eot, so push the eot out. // Always add at the end for better performance: // this saves all the checks and arraycopy when inserting // overwrite eot with new event eventsList.set(eventsCount - 1, event); // set new time of eot, if necessary if (eotEvent.getTick() < event.getTick()) { eotEvent.setTick(event.getTick()); } // add eot again at the end eventsList.add(eotEvent); } else { eventsList.add(i, event); } return true; } } return false; }