當前位置: 首頁>>代碼示例>>Java>>正文


Java InvalidMidiDataException.printStackTrace方法代碼示例

本文整理匯總了Java中javax.sound.midi.InvalidMidiDataException.printStackTrace方法的典型用法代碼示例。如果您正苦於以下問題:Java InvalidMidiDataException.printStackTrace方法的具體用法?Java InvalidMidiDataException.printStackTrace怎麽用?Java InvalidMidiDataException.printStackTrace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.sound.midi.InvalidMidiDataException的用法示例。


在下文中一共展示了InvalidMidiDataException.printStackTrace方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createSequencer

import javax.sound.midi.InvalidMidiDataException; //導入方法依賴的package包/類
private boolean createSequencer(BufferedInputStream in) throws IOException {

        if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.createSequencer()");

        // get the sequencer
        try {
            sequencer = MidiSystem.getSequencer( );
        } catch(MidiUnavailableException me) {
            if (DEBUG || Printer.err)me.printStackTrace();
            return false;
        }
        if (sequencer==null) {
            return false;
        }

        try {
            sequence = MidiSystem.getSequence(in);
            if (sequence == null) {
                return false;
            }
        } catch (InvalidMidiDataException e) {
            if (DEBUG || Printer.err)e.printStackTrace();
            return false;
        }

        if (DEBUG || Printer.debug)Printer.debug("Created Sequencer.");
        return true;
    }
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:29,代碼來源:JavaSoundAudioClip.java

示例2: writeToTrack

import javax.sound.midi.InvalidMidiDataException; //導入方法依賴的package包/類
/**
 * Generates the rhythm and writes it to the given track on the given channel
 *
 * @param track   The track to write to
 * @param channel The channel to write to
 */
@Override
public void writeToTrack(Track track, int channel) {

    int length = SecsInTicks(15, tempo.resolution);
    int bass, snare, hiHat;
    int vel = 64;
    try {
        // Add bass
        int i = 0;
        for (int n = 0; n < length; n += bass) {
            addNote(track, n, QUARTER, 36, vel, channel);
            bass = roundToQuaver(QUARTER * avgWordLen[(i += 3) % avgWordLen.length]);
        }

        //Add snare
        i = 0;
        for (int n = 0; n < length; n += snare) {
            addNote(track, n, QUARTER, 38, vel, channel);
            snare = roundToQuaver(QUAVER * avgWordLen[(i += 3 + 1) % avgWordLen.length]);
        }

        //Add hi-hat
        i = 0;
        for (int n = 0; n < length; n += hiHat % QUAVER != 0 ? SEMIQUAVER : QUAVER) {
            hiHat = roundToSemiQuaver(SEMIQUAVER * avgWordLen[(i += 3 + 2) % avgWordLen.length]);
            addNote(track, n, SEMIQUAVER, 42, vel, channel);
        }
    } catch (InvalidMidiDataException e) {
        e.printStackTrace();
    }
}
 
開發者ID:AudiophileDev,項目名稱:T2M,代碼行數:38,代碼來源:RhythmTrack.java

示例3: writeToTrack

import javax.sound.midi.InvalidMidiDataException; //導入方法依賴的package包/類
/**
 * Creates a track based on the calculated {@link MusicData} and the input {@link MelodyTrack#sentences}.
 *
 * @param track   The track to write to
 * @param channel The channel to write to
 */
@Override
public void writeToTrack(Track track, int channel) {
    int dynamicIndex = 0, n = 0, currentVoice = 0; // Marks position an track
    int pitch;
    int len = QUARTER, prevLen = len; // Length of the notes in 128th per beat
    int playable, previous = baseKey.baseNoteMidi;
    try {
        MidiUtils.ChangeInstrument(ensemble.instruments[currentVoice], track, channel, 0);
        for (int i = 0; i < sentences.length; i++) {
            Sentence s = sentences[i];
            if (s.getSentenceType() == Sentence.SentenceType.Exclamation)       // Increase loudness for exclamation sentences
                dynamic.initDynamic = 127;
            else dynamic.initDynamic = 64;
            for (Word w : s.getWords()) {
                if (w.isFiller()) // Skip filler words
                    continue;
                for (char c : Utils.normalizeText(w.getName()).toCharArray()) {
                    int tone = c >= toneMapping.length ? getClosestTone(c) : c;
                    if (n % (4 * WHOLE) == 0) currentKey = new Harmony(baseKey, 7);
                    else if (n % (2 * WHOLE) == 0) currentKey = new Harmony(baseKey, 5);

                    playable = toneMapping[tone];
                    playable = catchOutliers(playable, previous); // prevents notes jumping around or going too high or low
                    playable = inScale(playable); //ensures note is in scale

                    //handling punctuated notes
                    if (prevLen == SEMIQUAVER + QUAVER || prevLen == QUARTER + QUAVER) len = prevLen / 3;
                    else if (prevLen == SEMIQUAVER) len = SEMIQUAVER;
                    else len = setRhythm(c, currentVoice + 1);
                    prevLen = len;
                    //chord on the first beat of every bar
                    if (n % WHOLE <= QUAVER) { //beginning of every bar
                        if (dynamic.dynamicGradient.length > dynamicIndex && n > QUARTER) dynamicIndex++;
                        MidiUtils.addNote(track, n + 64 * ((playable % 4) + 1), len, playable, dynamic.initDynamic, channel);
                        notes[(n + 64 * ((playable % 4) + 1)) / 64][playable % 12] = true;
                        MidiUtils.addNote(track, n, len, isConsonant(playable, n), dynamic.initDynamic, channel);
                        notes[n / 64][playable % 12] = true;
                    } else {
                        if (dynamic.dynamicGradient.length > dynamicIndex)
                            if (Dynamic.isValidDynamic(dynamic.initDynamic + dynamic.dynamicGradient[dynamicIndex]))
                                dynamic.initDynamic += dynamic.dynamicGradient[dynamicIndex];
                        MidiUtils.addNote(track, n, len, isConsonant(playable, n), dynamic.initDynamic, channel);
                        notes[n / 64][playable % 12] = true;
                    }
                    n += len;
                    previous = playable; //save previous to prevent going of the scale
                    if (i == sentences.length - 1) {
                        i = 0;
                    }
                    if (TicksInSecs(n, this.tempo.resolution) >= 15) {                        //finishing part
                        if (currentVoice >= this.voices) // Sets fixed track length of 15sec
                            return;
                        n = 0;
                        pitch = -12 * ((currentVoice <= 1) ? 0 : (currentVoice - 1));
                        this.currentKey = new Harmony(this.baseKey, pitch);
                        MidiUtils.ChangeInstrument(ensemble.instruments[currentVoice++], track, ++channel, 0);
                        dynamic.initDynamic -= 5;
                    }
                }
            }
        }
    } catch (InvalidMidiDataException e) {
        e.printStackTrace();
    }
}
 
開發者ID:AudiophileDev,項目名稱:T2M,代碼行數:72,代碼來源:MelodyTrack.java

示例4: main

import javax.sound.midi.InvalidMidiDataException; //導入方法依賴的package包/類
public static void main(String[] argv) throws Exception {
    if (!hasSequencer()) {
        return;
    }
    Sequencer sequencer = MidiSystem.getSequencer();
    Sequence sequence = new Sequence(Sequence.PPQ, 240);
    Track track = sequence.createTrack();

    track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+0,45,100),0));
    track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+0,45,0),0 + 240));
    track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+9,45,100),10*20));
    track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+9,45,0),10*20 + 10));

    try {
        sequencer.open();
        sequencer.setSequence(sequence);
        sequencer.setTempoInBPM(100);

        System.out.println("Setting loop end point to 1");
        sequencer.setLoopEndPoint(1);
        System.out.println("  -> effectively: "+sequencer.getLoopEndPoint());
        System.out.println("Setting loop start point to 2 -- should throw IAE");
        sequencer.setLoopStartPoint(2);
        System.out.println("  -> effectively: "+sequencer.getLoopStartPoint());
        System.out.println("No IllegalArgumentException was thrown!");
        failed = true;
    } catch (IllegalArgumentException iae) {
        System.out.println("IAE was thrown correctly.");
    } catch (MidiUnavailableException mue) {
        System.out.println("MidiUnavailableException was thrown: " + mue);
        System.out.println("Cannot execute test.");
    } catch (InvalidMidiDataException imEx) {
        System.out.println("InvalidMidiDataException was thrown.");
        imEx.printStackTrace();
        System.out.println("Cannot execute test.");
    } finally {
        if (sequencer != null && sequencer.isOpen()) {
            sequencer.close();
        }
    }
    if (failed) {
        throw new Exception("Test FAILED!");
    }
    System.out.println("test passed.");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:46,代碼來源:LoopIAE.java


注:本文中的javax.sound.midi.InvalidMidiDataException.printStackTrace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。