— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet320/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   316   317   318   319   320   321   322   323   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

player.start();


342
 
chapter 11
import javax.sound.midi.*;
public class MiniMiniMusicApp {
public static void main(String[] args) {
MiniMiniMusicApp mini = new MiniMiniMusicApp();
mini.play();

// close main
public void play() {
try {
Sequencer player = MidiSystem.getSequencer();
player.open();
Sequence seq = new Sequence(Sequence.PPQ, 4);
Track track = seq.createTrack();
ShortMessage a = new ShortMessage();
a.setMessage(144, 1, 44, 100);
MidiEvent noteOn = new MidiEvent(a, 1); 
track.add(noteOn);
ShortMessage b = new ShortMessage();
b.setMessage(128, 1, 44, 100);
MidiEvent noteOff = new MidiEvent(b, 16); 
track.add(noteOff);
player.setSequence(seq);
player.start();
} catch (Exception ex) {
ex.printStackTrace();
}

// close play

// close class
get a Sequencer and open it 
(so we can use it... a Sequencer 
doesn’t come already open)
Don’t worry about the arguments to the 
Sequence constructor. 
Just copy these 
(think 
of ‘em as Ready-bake arguments
). 
Ask the Sequence for a Track. Remember, the 
Track lives in the Sequence, and the MIDI data 
lives in the Track.
Put some MidiEvents into the Track. This part 
is mostly Ready-bake code. The only thing you’ll 
have to care about are the arguments to the 
setMessage() method, and the arguments to 
the MidiEvent constructor. We’ll look at those 
arguments on the next page.
Start() the Sequencer (like pushing PLAY)
Don’t forget to import the midi package
Your very first sound player app
1
2
3
4
Type it in and run it. You’ll hear the sound of someone playing a 
single note on a piano! (OK, maybe not someone, but something.) 
Give the Sequence to the Sequencer (like 
putting the CD in the CD player)

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   316   317   318   319   320   321   322   323   ...   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