ComposiçËao e Performance Musical Utilizando Agentes Móveis
ComposiçËao e Performance Musical Utilizando Agentes Móveis
ComposiçËao e Performance Musical Utilizando Agentes Móveis
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
CAPÍTULO 4. O SISTEMA ANDANTE 40<br />
1 import java.util.Random;<br />
2<br />
3 // Todo agente móvel musical deve ser subclasse da classe abstrata<br />
4 // ’Mobile<strong>Musical</strong>Agent’.<br />
5 public class RandomMelodyAgent extends Mobile<strong>Musical</strong>Agent {<br />
6<br />
7 boolean play = false;<br />
8 short [] cMaj = {60,62,64,65,67,69,71};<br />
9 Random random;<br />
10 Channel channel;<br />
11<br />
12 // Método chamado no final do tratamento do evento de chegada<br />
13 // do agente a um novo palco.<br />
14 public void init() {<br />
15 random = new Random();<br />
16 channel = stage.channel(1);<br />
17 play();<br />
18 }<br />
19<br />
20 public void play() {<br />
21 play = true;<br />
22 int pitch, intensity, duration;<br />
23<br />
24 while ( play) {<br />
25 pitch = cMaj[ random.nextInt( cMaj.length)];<br />
26 intensity = random.nextInt(128);<br />
27 duration = random.nextInt(1000);<br />
28 channel.noteOn(pitch, intensity);<br />
29 try {<br />
30 Thread.sleep(duration);<br />
31 }<br />
32 catch (InterruptedException ie) {}<br />
33 channel.noteOff(pitch);<br />
34 }<br />
35 }<br />
36<br />
37 public void stop() {<br />
38 play = false;<br />
39 }<br />
40<br />
41 }<br />
Figura 4.5: RandomMelodyAgent: exemplo de um agente Andante