| View previous topic :: View next topic |
| Author |
Message |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Thu Jun 02, 2011 12:24 pm Post subject: |
|
|
| got it compiled. gonna add the pause.
|
|
| Back to top |
|
 |
Evil_Intentions Expert Cheater
Reputation: 65
Joined: 07 Jan 2010 Posts: 214
|
Posted: Thu Jun 02, 2011 12:29 pm Post subject: |
|
|
| How are you doing it, threads or modifying the play method?
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
|
| Back to top |
|
 |
Evil_Intentions Expert Cheater
Reputation: 65
Joined: 07 Jan 2010 Posts: 214
|
Posted: Thu Jun 02, 2011 12:35 pm Post subject: |
|
|
| Slugsnack wrote: | | if it doesn't already supply pause/stop functionality (which makes it pretty shit) i guess second method is better |
It doesn't. It has pause and stop functions, but the play function stops all input to the program. I think the play method works by sleeping until the music pattern is done playing, so maybe simply removing the sleep portion?
EDIT: That pause method won't do anything. The program locks up to play music.
EDIT2: I'm looking at the JFugue source, and I've found this bit of code in teh play method
| Code: | // Wait for the sequence to finish
while (isOn())
{
try {
Thread.sleep(20); // don't hog all of the CPU
} catch (InterruptedException e) {
try {
stop();
} catch (Exception e2) {
// do nothing
}
throw new JFugueException(JFugueException.ERROR_SLEEP);
}
} |
Would this be the culprit?
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Thu Jun 02, 2011 12:48 pm Post subject: |
|
|
i'm done. basically Player.play is a call which blocks till it finishes. easiest to branch it off to another thread. i've just done this as a proof of concept so haven't dealt with thread synchronization and shit but it works and you can have fun cleaning it up.
Rot1SucksCock.java
| Code: | package fractalmuse;
import org.jfugue.Pattern;
import org.jfugue.Player;
public class Rot1SucksCock extends Thread {
private final Player player;
private final Pattern music;
public Rot1SucksCock( Player player, Pattern music ) {
this.player = player;
this.music = music;
}
public void run() {
player.play( music );
player.close();
}
}
|
to make a class which can be threaded you need to either implement runnable or extend thread. and then implement run() which is called when a thread is created. here it is spawning the thread:
| Code: | Thread halfInchWonder = new Rot1SucksCock( player, music );
halfInchWonder.start(); |
and here is the pause function..
| Code: | pauseBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
pauseBtnActionPerformed(evt);
}
private void pauseBtnActionPerformed(ActionEvent evt) {
player.pause();
}
}); |
here is the final jar:
http://www.sendspace.com/file/uab160
i couldn't be bothered to space the pause button properly.. and here is the eclipse project:
http://www.sendspace.com/file/2r8k3a
as a general UI piece of advice. heavy work shouldn't be done in the UI thread which is usually single threaded. to make sure the app is responsive, this sort of work should be dispatched to worker threads so the UI thread can return and quickly continue processing other UI events.
|
|
| Back to top |
|
 |
Evil_Intentions Expert Cheater
Reputation: 65
Joined: 07 Jan 2010 Posts: 214
|
Posted: Thu Jun 02, 2011 1:05 pm Post subject: |
|
|
Thank you so much Slugsnack. I'll start messing with it.
EDIT: I now have a perfectly working stop button. I shall tell my kids about you. haha
|
|
| Back to top |
|
 |
InternetIsSeriousBusiness Grandmaster Cheater Supreme
Reputation: 8
Joined: 12 Jul 2010 Posts: 1268
|
Posted: Thu Jun 02, 2011 6:00 pm Post subject: |
|
|
wat
_________________
FLAME FLAME FLAME!!!@@@ |
|
| Back to top |
|
 |
Nirojan How do I cheat?
Reputation: 108
Joined: 16 Sep 2008 Posts: 0 Location: seshville
|
Posted: Tue Apr 24, 2012 11:28 pm Post subject: |
|
|
virus
_________________
| Quote: | | yo i b 22 tryna make it in dis rap game but da steetz dont got luv for no wun na mean so im out hea tryna holla at da fams on dis innernet shit u no way i sayin |
|
|
| Back to top |
|
 |
InternetIsSeriousBusiness Grandmaster Cheater Supreme
Reputation: 8
Joined: 12 Jul 2010 Posts: 1268
|
Posted: Tue Apr 24, 2012 11:38 pm Post subject: |
|
|
wat
_________________
FLAME FLAME FLAME!!!@@@ |
|
| Back to top |
|
 |
the the the Master Cheater
Reputation: 46
Joined: 15 Jun 2008 Posts: 429
|
Posted: Wed Apr 25, 2012 12:08 am Post subject: |
|
|
| Slugsnack wrote: | i'm done. basically Player.play is a call which blocks till it finishes. easiest to branch it off to another thread. i've just done this as a proof of concept so haven't dealt with thread synchronization and shit but it works and you can have fun cleaning it up.
Rot1SucksCock.java
| Code: | package fractalmuse;
import org.jfugue.Pattern;
import org.jfugue.Player;
public class Rot1SucksCock extends Thread {
private final Player player;
private final Pattern music;
public Rot1SucksCock( Player player, Pattern music ) {
this.player = player;
this.music = music;
}
public void run() {
player.play( music );
player.close();
}
}
|
to make a class which can be threaded you need to either implement runnable or extend thread. and then implement run() which is called when a thread is created. here it is spawning the thread:
| Code: | Thread halfInchWonder = new Rot1SucksCock( player, music );
halfInchWonder.start(); |
and here is the pause function..
| Code: | pauseBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
pauseBtnActionPerformed(evt);
}
private void pauseBtnActionPerformed(ActionEvent evt) {
player.pause();
}
}); |
here is the final jar:
http://www.sendspace.com/file/uab160
i couldn't be bothered to space the pause button properly.. and here is the eclipse project:
http://www.sendspace.com/file/2r8k3a
as a general UI piece of advice. heavy work shouldn't be done in the UI thread which is usually single threaded. to make sure the app is responsive, this sort of work should be dispatched to worker threads so the UI thread can return and quickly continue processing other UI events. | wow good advice
i had 2 reformat 4 time bcuz ur stupid java virus!!!!
|
|
| Back to top |
|
 |
|