import javax.sound.midi.*; import java.io.*; public class Rada6{ static int valjus=90; public static void lisaNoot(Track rada, int alghetk, int korgus, int kestus){ lisaNoot(rada, alghetk, korgus, kestus, 0); } public static void lisaNoot(Track rada, int alghetk, int korgus, int kestus, int kanal){ try{ ShortMessage lahti=new ShortMessage(); lahti.setMessage(ShortMessage.NOTE_ON, kanal, korgus, valjus); rada.add(new MidiEvent(lahti, alghetk)); ShortMessage kinni=new ShortMessage(); kinni.setMessage(ShortMessage.NOTE_OFF, kanal, korgus, valjus); rada.add(new MidiEvent(kinni, alghetk+kestus)); }catch(Exception ex){ex.printStackTrace();} } public static void linnukesteViis(Track rada){ lisaNoot(rada, 0, 67, 4); lisaNoot(rada, 4, 64, 4); lisaNoot(rada, 8, 67, 4); lisaNoot(rada, 12, 64, 4); lisaNoot(rada, 16, 67, 8); lisaNoot(rada, 24, 67, 8); //Lisage ka mõned järgnevad noodid. lisaNoot(rada, 32, 65, 4); lisaNoot(rada, 36, 64, 4); lisaNoot(rada, 40, 65, 4); lisaNoot(rada, 44, 67, 4); lisaNoot(rada, 48, 64, 16); } public static void lisaKolmkola(Track rada, int alghetk, int algkorgus, int kestus, int kanal){ lisaNoot(rada, alghetk, algkorgus, 2, kanal); lisaNoot(rada, alghetk+2, algkorgus+7, 2, kanal); lisaNoot(rada, alghetk+4, algkorgus+4, 2, kanal); lisaNoot(rada, alghetk+6, algkorgus+7, 2, kanal); } public static Track lisaRada(Sequence sekvents, int pill, int kanal){ Track rada=sekvents.createTrack(); try{ ShortMessage algus = new ShortMessage(); algus.setMessage(ShortMessage.PROGRAM_CHANGE, kanal, pill, 0); rada.add(new MidiEvent(algus, 0)); }catch(Exception ex){ex.printStackTrace();} return rada; } public static void main(String argumendid[]) throws Exception{ Sequence sekvents=new Sequence(Sequence.PPQ, 4); Track rada=lisaRada(sekvents, 16, 0); linnukesteViis(rada); Track rada2=lisaRada(sekvents, 22, 1); //lisaNoot(rada2, 0, 60, 32, 1); lisaKolmkola(rada2, 0, 60, 8, 1); lisaKolmkola(rada2, 8, 60, 8, 1); lisaKolmkola(rada2, 16, 60, 8, 1); lisaKolmkola(rada2, 24, 60, 8, 1); lisaKolmkola(rada2, 32, 67, 8, 1); lisaKolmkola(rada2, 40, 67, 8, 1); lisaKolmkola(rada2, 48, 60, 8, 1); lisaKolmkola(rada2, 56, 60, 8, 1); MidiSystem.write(sekvents, 1, new FileOutputStream("piiksud.mid")); } }