— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet363/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   359   360   361   362   363   364   365   366   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)


// close main
public static MidiEvent makeEvent(int comd, int chan, int one, int two, int tick) {
MidiEvent event = null;
try {
ShortMessage a = new ShortMessage();
a.setMessage(comd, chan, one, two);
event = new MidiEvent(a, tick);

}catch(Exception e) { }
return event;
}

// close class
make (and open) a sequencer
make a sequence 
and a track
make a bunch of events to make the notes keep 
going up (from piano note 5 to piano note 61)
don’t forget the import
call our new makeEvent() method to make the 
message and event, then add the result (the 
MidiEvent returned from makeEvent()) to 
the track. These are NOTE ON (144) and 
NOTE OFF (128) pairs
start it running
There’s no event handling or graphics here, just a sequence of 15 
notes that go up the scale. The point of this code is simply to learn 
how to use our new makeEvent() method. The code for the next 
two versions is much smaller and simpler thanks to this method.
Example: how to use the new static 
makeEvent() method


390
 
chapter 12
import javax.sound.midi.*;
public class MiniMusicPlayer2 implements ControllerEventListener {

public static void main(String[] args) {
MiniMusicPlayer2 mini = new MiniMusicPlayer2();
mini.go();
}
public void go() {
try {
Sequencer sequencer = MidiSystem.getSequencer();
sequencer.open();
int[] eventsIWant = {127};
sequencer.addControllerEventListener(this, eventsIWant);
Sequence seq = new Sequence(Sequence.PPQ, 4);

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   359   360   361   362   363   364   365   366   ...   555




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish