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


Java Play类代码示例

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


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

示例1: generate

import jm.util.Play; //导入依赖的package包/类
public void generate(String fileName, int barNumber, long seed) {
    Random generator = new Random(seed);
    Tonality tonality = learner_.getTonalityVector().getValue(generator);

    Harmonic harmonic = new Harmonic(tonality, learner_.getMarkovDegree(), learner_.getEndingsVector());
    ArrayList<ChordDegree> harmonicBase = harmonic.generateHarmonicBase(barNumber, generator, 10000);
    System.out.println(harmonicBase);

    int beatperbar = learner_.getBeatPerBarVector().getValue(generator);
    double barUnit = learner_.getBarUnitVector().getValue(generator);
    Rhythm rhythm = new Rhythm(harmonicBase, learner_.getRhythmMatrices_(), beatperbar * barUnit, generator);
    ArrayList<GeneratedNote> melody = rhythm.generateRhythms();


    MelodicGenerator melodicGenerator = new MelodicGenerator(new Random(seed), tonality, learner_.getMelodicLearner());
    melodicGenerator.fillWithPitches(melody);

    score_ = new Score();
    Part part = new Part();
    CPhrase chords = new CPhrase();
    // Jmusic take int[] and not ArrayList<Integer> for the
    for (GeneratedNote gn : melody) {
        // Only in Java 8
        int[] pitches = gn.getChordPitches().stream().mapToInt(i -> i).toArray();
        for (int i = 0; i < pitches.length; ++i)
            if (pitches[i] > 125)
                pitches[i] = pitches[i] % 12 + 12 * 4;
        chords.addChord(pitches, gn.getRhythm());
    }
    /*
    CPhrase degrees = new CPhrase();
    for (ChordDegree degree : harmonicBase) {
        System.out.println(degree);
        degrees.addChord(harmonic.getChord(degree,12),
                (double) (beatperbar * barUnit) / (double)degree.getBarFractionDen());
    }
    */
    part.addCPhrase(chords);
    score_.add(part);
    Part acc = new Part();
    //acc.addCPhrase(degrees);
    score_.add(acc);
    // Code to play the file
    Play.midi(score_);
    // Code to write the file
    System.out.println("TOTO: " + fileName);
    Write.midi(score_, fileName);
}
 
开发者ID:paveyry,项目名称:LyreLand,代码行数:49,代码来源:Generator.java

示例2: playBackMidi

import jm.util.Play; //导入依赖的package包/类
private void playBackMidi() {
    Play.midi(score, false);
}
 
开发者ID:Impro-Visor,项目名称:Impro-Visor,代码行数:4,代码来源:ShowScore.java

示例3: tiNaTinKano

import jm.util.Play; //导入依赖的package包/类
private static void tiNaTinKano() throws Exception {
    Score score = new Score();
    score.addPart(new Part(Instruments.PIANO));
    Phrase phrase = new Phrase();
    score.getPart(0).addPhrase(phrase);

    int[] pitches = new int[] {C4, C4, C4, F4, GS4, A1, G4, F4, F4, DS4, DS4, A1, CS4, CS4, CS4, F4, GS4, BF4, GS4, GS4, G4, G4};
    double[] lengths = new double[] {SIXTEENTH_NOTE, SIXTEENTH_NOTE, SIXTEENTH_NOTE, EIGHTH_NOTE, EIGHTH_NOTE,
            SIXTEENTH_NOTE,
            EIGHTH_NOTE, SIXTEENTH_NOTE, SIXTEENTH_NOTE, SIXTEENTH_NOTE, EIGHTH_NOTE, 
            SIXTEENTH_NOTE, 
            SIXTEENTH_NOTE, SIXTEENTH_NOTE, SIXTEENTH_NOTE, EIGHTH_NOTE, EIGHTH_NOTE, EIGHTH_NOTE, EIGHTH_NOTE, SIXTEENTH_NOTE, SIXTEENTH_NOTE, SIXTEENTH_NOTE};
    
    // off-beat
    phrase.addRest(new Rest(SIXTEENTH_NOTE));
    
    int idx = 0;
    for (Integer pitch : pitches) {
        double length = SIXTEENTH_NOTE;
        if (lengths.length > idx) {
            length = lengths[idx];
        }
        if (pitch != A1) {
            Note note = new Note(pitch, length);
            phrase.add(note);
        } else {
            phrase.addRest(new Rest(length));
        }
        idx++;
    }
   
    score.getPart(0).getPhrase(0).addRest(new Rest(SIXTEENTH_NOTE));
    score.getPart(0).addPhrase(new Phrase(phrase.getNoteArray()));
    
    Part accompaniment = new Part(Instruments.PIANO);
    //score.addPart(accompaniment);
    Phrase accPhrase = new Phrase();
    accompaniment.addPhrase(accPhrase);
    accPhrase.addRest(new Rest(SIXTEENTH_NOTE));
    accPhrase.addChord(new int[] {C4, F4, GS4}, WHOLE_NOTE - SIXTEENTH_NOTE);
    accPhrase.addChord(new int[] {C4, F4, GS4}, WHOLE_NOTE);
    Play.midi(score);
    Write.midi(score, new FileOutputStream("c:/tmp/tinatin.mid"));
}
 
开发者ID:Glamdring,项目名称:computoser,代码行数:45,代码来源:InstrumentTester.java


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