— Scott McNealy, Sun Microsystems Chairman, President and ceo


Register a listener for the events 3



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

2
Register a listener for the events
3
Start the sequencer playing
4
Each time the listener’s event 
handler method is called, draw a 
random rectangle on the drawing 
panel, and call repaint.
1
Version One: Code that simplifies mak-
ing and adding MIDI events, since we’ll 
be making a lot of them.
We’ll build it in three iterations:
2
Version Two: Register and listen for 
the events, but without graphics. 
Prints a message at the command-line 
with each beat.
4
Version Three: The real deal. Adds 
graphics to version two.


388
 
chapter 12
ShortMessage a = new ShortMessage();
a.setMessage(144, 1, note, 100);
MidiEvent noteOn = new MidiEvent(a, 1); 
track.add(noteOn);
ShortMessage b = new ShortMessage();
b.setMessage(128, 1, note, 100);
MidiEvent noteOff = new MidiEvent(b, 16); 
track.add(noteOff);
Right now, making and adding messages and 
events to a track is tedious. For each message, 
we have to make the message instance (in this 
case, ShortMessage), call setMessage(), make a 
MidiEvent for the message, and add the event 
to the track. In last chapter’s code, we went 
through each step for every message. That 
means eight lines of code just to make a note 
play and then stop playing! Four lines to add a 
NOTE ON event, and four lines to add a NOTE 
OFF event. 
An easier way to make 
messages / events
1
Make a message instance
ShortMessage first = new ShortMessage();
Things that have to happen for 
each event:
2
Call setMessage() with the instructions

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   357   358   359   360   361   362   363   364   ...   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