当前位置: 首页>>代码示例>>Java>>正文


Java ProgramChange类代码示例

本文整理汇总了Java中com.leff.midi.event.ProgramChange的典型用法代码示例。如果您正苦于以下问题:Java ProgramChange类的具体用法?Java ProgramChange怎么用?Java ProgramChange使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ProgramChange类属于com.leff.midi.event包,在下文中一共展示了ProgramChange类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readMidiTrackFromArray

import com.leff.midi.event.ProgramChange; //导入依赖的package包/类
/**
 * Reads a MIDI track from an array of notes. The array format must be:
 * <ul>
 * <li>Program ID,
 * <li>Note pitch, velocity, duration,
 * <li>(additional notes)
 * </ul>
 *
 * @param notes The array to read as a MIDI track.
 * @return A MIDI track.
 */
private static MidiTrack readMidiTrackFromArray(int[] notes) {
    final MidiTrack noteTrack = new MidiTrack();
    int tick = 0;

    final int program = notes[0];
    if ((program < 0) || (program > 127)) {
        throw new IllegalArgumentException("MIDI track program must be in the range [0,127]");
    }

    // Set the channel volume to maximum.
    noteTrack.insertEvent(new Controller(
            0, 0, DEFAULT_CHANNEL, ControllerType.VOLUME, DEFAULT_VOLUME));

    // Mute the reverb effect.
    noteTrack.insertEvent(new Controller(
            0, 0, DEFAULT_CHANNEL, ControllerType.EFFECTS_LEVEL, 0));

    // Mute the chorus effect.
    noteTrack.insertEvent(new Controller(
            0, 0, DEFAULT_CHANNEL, ControllerType.CHORUS_LEVEL, 0));

    noteTrack.insertEvent(new ProgramChange(0, 0, program));

    if ((notes.length % 3) != 1) {
        throw new IllegalArgumentException(
                "MIDI note array must contain a single integer followed by triplets");
    }

    for (int i = 1; i < (notes.length - 2); i += 3) {
        final int pitch = notes[i];
        if ((pitch < 21) || (pitch > 108)) {
            throw new IllegalArgumentException("MIDI note pitch must be in the range [21,108]");
        }

        final int velocity = notes[i + 1];
        if ((velocity < 0) || (velocity > 127)) {
            throw new IllegalArgumentException(
                    "MIDI note velocity must be in the range [0,127]");
        }

        final int duration = notes[i + 2];

        noteTrack.insertNote(DEFAULT_CHANNEL, pitch, velocity, tick, duration);

        tick += duration;
    }

    return noteTrack;
}
 
开发者ID:google,项目名称:brailleback,代码行数:61,代码来源:MidiUtils.java

示例2: writeProgramChange

import com.leff.midi.event.ProgramChange; //导入依赖的package包/类
@Override public void writeProgramChange(int track, int channel, long tick, int program) {
	MidiEvent event = new ProgramChange(tick, channel, program);
	tracks.get(track).insertEvent(event);
}
 
开发者ID:Xenoage,项目名称:Zong,代码行数:5,代码来源:AndroidMidiSequenceWriter.java


注:本文中的com.leff.midi.event.ProgramChange类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。