private void updateTempoLabel() { int mpq = sequenceInfo.getDataCache().getTempoMPQ(sequencer.getThumbTick()); int bpm = (int) Math.round(MidiUtils.convertTempo(mpq) * getCurrentTempoFactor()); if (bpm != lastRenderedBPM) { currentTempoLabel.setText(bpm + " BPM "); lastRenderedBPM = bpm; } }
private int tempoToNoteId(int tempoMPQ, int minBPM, int maxBPM) { int bpm = (int) Math.round(MidiUtils.convertTempo(tempoMPQ)); float tempoFactor = getCurrentTempoFactor(); minBPM = Math.round(minBPM * tempoFactor); maxBPM = Math.round(maxBPM * tempoFactor); bpm = Math.round(bpm * tempoFactor); return (bpm - minBPM) * (Note.MAX.id - Note.MIN.id) / (maxBPM - minBPM) + Note.MIN.id; }
public static SequenceInfo fromAbc(AbcToMidi.Params params) throws InvalidMidiDataException, ParseException { if (params.abcInfo == null) params.abcInfo = new AbcInfo(); SequenceInfo sequenceInfo = new SequenceInfo(params.filesData.get(0).file.getName(), AbcToMidi.convert(params)); sequenceInfo.title = params.abcInfo.getTitle(); sequenceInfo.composer = params.abcInfo.getComposer(); sequenceInfo.primaryTempoMPQ = (int) Math.round(MidiUtils.convertTempo(params.abcInfo.getPrimaryTempoBPM())); return sequenceInfo; }
@Override public long tickToMicros(long tick) { if (divisionType != Sequence.PPQ) return (long) (TimingInfo.ONE_SECOND_MICROS * ((double) tick / (double) (divisionType * tickResolution))); TempoEvent te = getTempoEventForTick(tick); return te.micros + MidiUtils.ticks2microsec(tick - te.tick, te.tempoMPQ, tickResolution); }
@Override public long microsToTick(long micros) { if (divisionType != Sequence.PPQ) return (long) (divisionType * tickResolution * micros / (double) TimingInfo.ONE_SECOND_MICROS); TempoEvent te = getTempoEventForMicros(micros); return te.tick + MidiUtils.microsec2ticks(micros - te.micros, te.tempoMPQ, tickResolution); }
@Override public long microsToTick(long micros) { if (getSequence() == null) return 0; return MidiUtils.microsecond2tick(getSequence(), micros, tempoCache); }
@Override public long tickToMicros(long tick) { if (getSequence() == null) return 0; return MidiUtils.tick2microsecond(getSequence(), tick, tempoCache); }
public long getDragTick() { if (getSequence() == null) return 0; return MidiUtils.microsecond2tick(getSequence(), getDragPosition(), tempoCache); }
public void setDragTick(long tick) { if (getSequence() == null) return; setDragPosition(MidiUtils.tick2microsecond(getSequence(), tick, tempoCache)); }
@Override public long tickToMicrosecond(long tick) { //recompute tempo cache if required if (tempoCache == null) tempoCache = new TempoCache(sequence); //compute position return MidiUtils.tick2microsecond(sequence, tick, tempoCache); }
private ImmutableEndOfTrack() { super(new byte[3]); data[0] = (byte) META; data[1] = MidiUtils.META_END_OF_TRACK_TYPE; data[2] = 0; }
/** * Obtains the duration of this sequence, expressed in microseconds. * @return this sequence's duration in microseconds. */ public long getMicrosecondLength() { return com.sun.media.sound.MidiUtils.tick2microsecond(this, getTickLength(), null); }
public TempoPanel(SequenceInfo sequenceInfo, SequencerWrapper sequencer, SequencerWrapper abcSequencer) { super(new TableLayout(LAYOUT_COLS, LAYOUT_ROWS)); TableLayout tableLayout = (TableLayout) getLayout(); tableLayout.setHGap(TrackPanel.HGAP); setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, ColorTable.PANEL_BORDER.get())); this.sequenceInfo = sequenceInfo; this.sequencer = sequencer; this.abcSequencer = abcSequencer; int minBPM = 50; int maxBPM = 200; for (TempoEvent event : sequenceInfo.getDataCache().getTempoEvents().values()) { int bpm = (int) Math.round(MidiUtils.convertTempo(event.tempoMPQ)); if (bpm < minBPM) minBPM = bpm; if (bpm > maxBPM) maxBPM = bpm; } JPanel gutter = new JPanel(); gutter.setOpaque(true); gutter.setBackground(ColorTable.PANEL_HIGHLIGHT_OTHER_PART.get()); this.tempoGraph = new TempoNoteGraph(sequenceInfo, sequencer, minBPM, maxBPM); setBackground(ColorTable.GRAPH_BACKGROUND_DISABLED.get()); JLabel titleLabel = new JLabel("Tempo"); titleLabel.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0)); titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD)); titleLabel.setForeground(ColorTable.PANEL_TEXT_DISABLED.get()); currentTempoLabel = new JLabel(); currentTempoLabel.setForeground(ColorTable.PANEL_TEXT_DISABLED.get()); updateTempoLabel(); add(gutter, GUTTER_COLUMN + ", 0"); add(titleLabel, TITLE_COLUMN + ", 0"); add(currentTempoLabel, TEMPO_COLUMN + ", 0, R, C"); add(tempoGraph, GRAPH_COLUMN + ", 0"); sequencer.addChangeListener(sequencerListener); abcSequencer.addChangeListener(sequencerListener); }
/** * Rounds the given MPQ tempo so it corresponds to a whole-number of beats per minute. */ public static double roundTempoMPQ(double tempoMPQ) { return MidiUtils.convertTempo(Math.round(MidiUtils.convertTempo(tempoMPQ))); }
public int getTempoBPM() { return (int) Math.round(MidiUtils.convertTempo(tempoMPQ)); }
public int getExportTempoBPM() { return (int) Math.round(MidiUtils.convertTempo((double) tempoMPQ / exportTempoFactor)); }
public int getPrimaryTempoBPM() { return (int) Math.round(MidiUtils.convertTempo(getPrimaryTempoMPQ())); }
public int getPrimaryExportTempoBPM() { return (int) Math.round(MidiUtils.convertTempo((double) primaryTempoMPQ / exportTempoFactor)); }
@Override public long tickToMicros(long tick) { TimingInfoEvent e = getTimingEventForTick(tick); return e.micros + MidiUtils.ticks2microsec(tick - e.tick, e.info.getTempoMPQ(), e.info.getResolutionPPQ()); }
@Override public long microsToTick(long micros) { TimingInfoEvent e = getTimingEventForMicros(micros); return e.tick + MidiUtils.microsec2ticks(micros - e.micros, e.info.getTempoMPQ(), e.info.getResolutionPPQ()); }
public int getTempoBPM(long tick) { return (int) Math.round(MidiUtils.convertTempo(getTempoMPQ(tick))); }
public int getMinTempoBPM() { return (int) Math.round(MidiUtils.convertTempo(getMinTempoMPQ())); }
public int getMaxTempoBPM() { return (int) Math.round(MidiUtils.convertTempo(getMaxTempoMPQ())); }