当前位置: 首页>>代码示例>>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;未经允许,请勿转载。