TonePlayer Pre Release-V.Player v1
Simple tone player with mmapi
TonePlayer Pre Release-V.Player v1
i didnt really satisfied from this work of mine ,
planning to make really efficient V. Player v2 may be
get V.Player
java
jar
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package paket;
import java.io.IOException;
import java.util.Vector;
import javax.microedition.media.MediaException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.ToneControl;
/**
* @author sertac
*/
public class VDotPlayer extends MIDlet implements CommandListener {
Display d;
Form f, fMain;
Command cmdExit, cmdPlay, cmdOk, cmdBack, cmdStop, cmdAddTone, cmdPlayTone,cmdHelp;
TextField tfNote, tfDuration, tfVolume, tfToneSequence;
byte[] sequence;
int note = 0;
int duration = 0;
int volume = 0;
private int size;
StringBuffer initialTone = new StringBuffer("-2,1,67,16,69,16,67,8,65,8,64,48,62,8,60,8,59,16,57,16,59,32,59,32");
StringBuffer sb = null;
public VDotPlayer() {
d = Display.getDisplay(this);
f = new Form("Play Tone");
cmdPlay = new Command("Play", Command.SCREEN, 3);
cmdAddTone = new Command("Add", Command.SCREEN, 1);
cmdBack = new Command("Reset", Command.SCREEN, 4);
cmdStop = new Command("Stop", Command.SCREEN, 5);
cmdExit = new Command("Exit", Command.SCREEN, 6);
cmdPlayTone = new Command("Play Tone", Command.SCREEN, 2);
cmdHelp = new Command("Help", Command.SCREEN, 7);
f.addCommand(cmdBack);
f.addCommand(cmdStop);
f.addCommand(cmdPlay);
f.addCommand(cmdAddTone);
f.addCommand(cmdExit);
f.addCommand(cmdPlayTone);
f.addCommand(cmdHelp);
tfToneSequence = new TextField("Tone Sequence", initialTone.toString(),100, TextField.ANY);
final int maxSize = tfToneSequence.getMaxSize();
tfToneSequence.setMaxSize(maxSize);
tfNote = new TextField("Note 0-127", "", 3, TextField.NUMERIC);
tfDuration = new TextField("Duration Milisecond >0", "2000", 10, TextField.NUMERIC);
tfVolume = new TextField("Volume 0-100", "100", 3, TextField.NUMERIC);
f.append(tfNote);
f.append(tfDuration);
f.append(tfVolume);
f.append(new Spacer(2, 2));
f.append(tfToneSequence);
f.setCommandListener(this);
}
public void startApp() {
d.setCurrent(f);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command arg0, Displayable arg1) {
if (arg0 == cmdPlay) {
try {
note = Integer.parseInt(tfNote.getString());
duration = Integer.parseInt(tfDuration.getString());
volume = Integer.parseInt(tfVolume.getString());
Manager.playTone(note, duration, volume);
} catch (MediaException ex) {
new Alert("Hata",ex.getMessage(),null,AlertType.WARNING);
}
} else if (arg0 == cmdAddTone) {
sb = new StringBuffer();
sb.append(",");
sb.append((byte)note);
sb.append(",");
sb.append((byte)duration);
tfToneSequence.insert(sb.toString(), tfToneSequence.getCaretPosition());
} else if (arg0 == cmdPlayTone) {
try {
Player p = Manager.createPlayer(Manager.TONE_DEVICE_LOCATOR);
p.realize();
ToneControl tc = (ToneControl) p.getControl("ToneControl");
sequence = split(tfToneSequence.getString());
tc.setSequence(sequence);
p.start();
} catch (IOException ex) {
new Alert("Hata",ex.getMessage(),null,AlertType.WARNING);
} catch (MediaException ex) {
new Alert("Hata",ex.getMessage(),null,AlertType.WARNING);
}
} else if (arg0 == cmdBack) {
} else if (arg0 == cmdHelp) {
String helpText=" -2 VERSION, -3 TEMPO, -4 RESOLUTION, -5 BLOCK_START. -6 BLOCK_END. -7 PLAY_BLOCK.e -8 SET_VOLUME. -9 REPEAT. 60 C4. -1 SILENCE.";
Alert a =new Alert("V. Player",helpText,null,null);
a.setTimeout(Alert.FOREVER);
d.setCurrent(a);
} else if (arg0 == cmdStop) {
try {
throw new MediaException();
} catch (MediaException ex) {
}
} else {
destroyApp(true);
notifyDestroyed();
}
}
private byte[] split(String original) {
Vector nodes = new Vector();
String separator = ",";
// Parse nodes into vector
int index = original.indexOf(separator);
while (index >= 0) {
nodes.addElement(original.substring(0, index));
original = original.substring(index + separator.length());
index = original.indexOf(separator);
}
// Get the last node
nodes.addElement(original);
// Create splitted string array
byte[] result = new byte[nodes.size()];
if (nodes.size() > 0) {
for (int loop = 0; loop < nodes.size(); loop++) {
result[loop] = Byte.parseByte((String) nodes.elementAt(loop));
}
}
return result;
}
}
TonePlayer Pre Release-V.Player v1
i didnt really satisfied from this work of mine ,
planning to make really efficient V. Player v2 may be
get V.Player
java
jar
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package paket;
import java.io.IOException;
import java.util.Vector;
import javax.microedition.media.MediaException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.ToneControl;
/**
* @author sertac
*/
public class VDotPlayer extends MIDlet implements CommandListener {
Display d;
Form f, fMain;
Command cmdExit, cmdPlay, cmdOk, cmdBack, cmdStop, cmdAddTone, cmdPlayTone,cmdHelp;
TextField tfNote, tfDuration, tfVolume, tfToneSequence;
byte[] sequence;
int note = 0;
int duration = 0;
int volume = 0;
private int size;
StringBuffer initialTone = new StringBuffer("-2,1,67,16,69,16,67,8,65,8,64,48,62,8,60,8,59,16,57,16,59,32,59,32");
StringBuffer sb = null;
public VDotPlayer() {
d = Display.getDisplay(this);
f = new Form("Play Tone");
cmdPlay = new Command("Play", Command.SCREEN, 3);
cmdAddTone = new Command("Add", Command.SCREEN, 1);
cmdBack = new Command("Reset", Command.SCREEN, 4);
cmdStop = new Command("Stop", Command.SCREEN, 5);
cmdExit = new Command("Exit", Command.SCREEN, 6);
cmdPlayTone = new Command("Play Tone", Command.SCREEN, 2);
cmdHelp = new Command("Help", Command.SCREEN, 7);
f.addCommand(cmdBack);
f.addCommand(cmdStop);
f.addCommand(cmdPlay);
f.addCommand(cmdAddTone);
f.addCommand(cmdExit);
f.addCommand(cmdPlayTone);
f.addCommand(cmdHelp);
tfToneSequence = new TextField("Tone Sequence", initialTone.toString(),100, TextField.ANY);
final int maxSize = tfToneSequence.getMaxSize();
tfToneSequence.setMaxSize(maxSize);
tfNote = new TextField("Note 0-127", "", 3, TextField.NUMERIC);
tfDuration = new TextField("Duration Milisecond >0", "2000", 10, TextField.NUMERIC);
tfVolume = new TextField("Volume 0-100", "100", 3, TextField.NUMERIC);
f.append(tfNote);
f.append(tfDuration);
f.append(tfVolume);
f.append(new Spacer(2, 2));
f.append(tfToneSequence);
f.setCommandListener(this);
}
public void startApp() {
d.setCurrent(f);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command arg0, Displayable arg1) {
if (arg0 == cmdPlay) {
try {
note = Integer.parseInt(tfNote.getString());
duration = Integer.parseInt(tfDuration.getString());
volume = Integer.parseInt(tfVolume.getString());
Manager.playTone(note, duration, volume);
} catch (MediaException ex) {
new Alert("Hata",ex.getMessage(),null,AlertType.WARNING);
}
} else if (arg0 == cmdAddTone) {
sb = new StringBuffer();
sb.append(",");
sb.append((byte)note);
sb.append(",");
sb.append((byte)duration);
tfToneSequence.insert(sb.toString(), tfToneSequence.getCaretPosition());
} else if (arg0 == cmdPlayTone) {
try {
Player p = Manager.createPlayer(Manager.TONE_DEVICE_LOCATOR);
p.realize();
ToneControl tc = (ToneControl) p.getControl("ToneControl");
sequence = split(tfToneSequence.getString());
tc.setSequence(sequence);
p.start();
} catch (IOException ex) {
new Alert("Hata",ex.getMessage(),null,AlertType.WARNING);
} catch (MediaException ex) {
new Alert("Hata",ex.getMessage(),null,AlertType.WARNING);
}
} else if (arg0 == cmdBack) {
} else if (arg0 == cmdHelp) {
String helpText=" -2 VERSION, -3 TEMPO, -4 RESOLUTION, -5 BLOCK_START. -6 BLOCK_END. -7 PLAY_BLOCK.e -8 SET_VOLUME. -9 REPEAT. 60 C4. -1 SILENCE.";
Alert a =new Alert("V. Player",helpText,null,null);
a.setTimeout(Alert.FOREVER);
d.setCurrent(a);
} else if (arg0 == cmdStop) {
try {
throw new MediaException();
} catch (MediaException ex) {
}
} else {
destroyApp(true);
notifyDestroyed();
}
}
private byte[] split(String original) {
Vector nodes = new Vector();
String separator = ",";
// Parse nodes into vector
int index = original.indexOf(separator);
while (index >= 0) {
nodes.addElement(original.substring(0, index));
original = original.substring(index + separator.length());
index = original.indexOf(separator);
}
// Get the last node
nodes.addElement(original);
// Create splitted string array
byte[] result = new byte[nodes.size()];
if (nodes.size() > 0) {
for (int loop = 0; loop < nodes.size(); loop++) {
result[loop] = Byte.parseByte((String) nodes.elementAt(loop));
}
}
return result;
}
}
Comments