📄 speakerutils.java
字号:
package org.jnode.driver.sound.speaker;
import javax.naming.NameNotFoundException;
import org.apache.log4j.Logger;
import org.jnode.driver.ApiNotFoundException;
import org.jnode.driver.Device;
import org.jnode.driver.DeviceManager;
import org.jnode.driver.DeviceNotFoundException;
import org.jnode.naming.InitialNaming;
/** A static helper class for easy access to the system speaker.
* @author Matt Paine
**/
public class SpeakerUtils
{
/** My logger */
private static final Logger log = Logger.getLogger(SpeakerUtils.class);
/** What to play as the standard beep (null = a simple beep) **/
public static Note[] stdBeep = null;
/** The length of a standard interval **/
public static final int INTERVAL = 500;
/** A full length note **/
public static final int FULL = INTERVAL;
/** A half length note **/
public static final int HALF = INTERVAL/2;
/** A quarter length note **/
public static final int QUART = INTERVAL/4;
/** A three-quater length note **/
public static final int THREEQUART = (int)(INTERVAL*0.75);
/** Sounds a beep on the system speaker **/
public static void beep()
{
if (stdBeep == null)
{
try
{
DeviceManager dm = (DeviceManager)InitialNaming.lookup(DeviceManager.NAME);
Device dev = dm.getDevice("speaker0");
SpeakerAPI s = (SpeakerAPI)dev.getAPI(SpeakerAPI.class);
s.beep();
}
catch (ApiNotFoundException anfex)
{
log.error("Unable to beep: ", anfex);
}
catch (DeviceNotFoundException dnfex)
{
log.error("Unable to beep: ", dnfex);
}
catch (NameNotFoundException nnfex)
{
log.debug("Unable to beep: ", nnfex);
}
}
else
play (stdBeep);
}
/** Plays a series of notes through the default speaker **/
public static void play(Note[] n)
{
try
{
DeviceManager dm = (DeviceManager)InitialNaming.lookup(DeviceManager.NAME);
Device dev = dm.getDevice("speaker0");
SpeakerAPI s = (SpeakerAPI)dev.getAPI(SpeakerAPI.class);
s.playNote(n);
}
catch (ApiNotFoundException anfex)
{
log.error("Unable to beep: ", anfex);
}
catch (DeviceNotFoundException dnfex)
{
log.error("Unable to beep: ", dnfex);
}
catch (NameNotFoundException nnfex)
{
log.debug("Unable to beep: ", nnfex);
}
}
/** Defines a scale **/
public static final Note[] SCALE = new Note[]
{
new Note (Note.NOTE_C4, HALF),
new Note (Note.NOTE_D4, HALF),
new Note (Note.NOTE_E4, HALF),
new Note (Note.NOTE_F4, HALF),
new Note (Note.NOTE_G4, HALF),
new Note (Note.NOTE_A4, HALF),
new Note (Note.NOTE_B4, HALF),
new Note (Note.NOTE_C5, HALF),
new Note (Note.NOTE_D5, HALF),
new Note (Note.NOTE_E5, HALF),
new Note (Note.NOTE_F5, HALF),
new Note (Note.NOTE_G5, HALF),
new Note (Note.NOTE_A5, HALF),
new Note (Note.NOTE_B5, HALF),
new Note (Note.NOTE_C6, HALF)
};
/** Advance Australia Fair **/
public static final Note[] AAF = new Note[]
{
new Note (Note.NOTE_G4, HALF), // australians
new Note (Note.NOTE_C5, HALF),
new Note (Note.NOTE_G4, HALF),
new Note (Note.NOTE_E4, HALF),
new Note (Note.NOTE_G4, HALF),
new Note (Note.NOTE_C5, THREEQUART),
new Note (Note.NOTE_C5, QUART),
new Note (Note.NOTE_C5, HALF),
new Note (Note.NOTE_E5, HALF), // for
new Note (Note.NOTE_D5, HALF),
new Note (Note.NOTE_C5, HALF),
new Note (Note.NOTE_B4, HALF),
new Note (Note.NOTE_C5, HALF),
new Note (Note.NOTE_D5, FULL+THREEQUART),
new Note (Note.NOTE_G4, HALF), // with
new Note (Note.NOTE_C5, HALF),
new Note (Note.NOTE_G4, HALF),
new Note (Note.NOTE_E4, HALF),
new Note (Note.NOTE_C4, HALF),
new Note (Note.NOTE_G4, THREEQUART),
new Note (Note.NOTE_G4, QUART),
new Note (Note.NOTE_G4, HALF),
new Note (Note.NOTE_E5, HALF), // our home
new Note (Note.NOTE_D5, HALF),
new Note (Note.NOTE_C5, HALF),
new Note (Note.NOTE_B4, HALF),
new Note (Note.NOTE_A4, HALF),
new Note (Note.NOTE_G4, FULL+THREEQUART),
new Note (Note.NOTE_G4, HALF), // our lands
new Note (Note.NOTE_A4, THREEQUART),
new Note (Note.NOTE_B4, QUART),
new Note (Note.NOTE_C5, HALF),
new Note (Note.NOTE_A4, HALF),
new Note (Note.NOTE_G4, THREEQUART),
new Note (Note.NOTE_E4, QUART),
new Note (Note.NOTE_E4, HALF),
new Note (Note.NOTE_G4, HALF), // of beuty
new Note (Note.NOTE_A4, HALF),
new Note (Note.NOTE_C5, HALF),
new Note (Note.NOTE_F5, HALF),
new Note (Note.NOTE_E5, HALF),
new Note (Note.NOTE_D5, FULL+THREEQUART),
new Note (Note.NOTE_G4, HALF), // in history
new Note (Note.NOTE_A4, THREEQUART),
new Note (Note.NOTE_B4, QUART),
new Note (Note.NOTE_C5, HALF),
new Note (Note.NOTE_A4, HALF),
new Note (Note.NOTE_G4, THREEQUART),
new Note (Note.NOTE_C5, QUART),
new Note (Note.NOTE_C5, HALF),
new Note (Note.NOTE_D5, HALF), // advance
new Note (Note.NOTE_E5, THREEQUART),
new Note (Note.NOTE_C5, QUART),
new Note (Note.NOTE_D5, THREEQUART),
new Note (Note.NOTE_B4, QUART),
new Note (Note.NOTE_C5, FULL+THREEQUART),
new Note (Note.NOTE_E5, HALF), // in joyful
new Note (Note.NOTE_F5, HALF),
new Note (Note.NOTE_E5, HALF),
new Note (Note.NOTE_D5, HALF),
new Note (Note.NOTE_C5, HALF),
new Note (Note.NOTE_B4, HALF),
new Note (Note.NOTE_A4, HALF),
new Note (Note.NOTE_G4, HALF),
new Note (Note.NOTE_C5, HALF), // advance
new Note (Note.NOTE_E5, THREEQUART),
new Note (Note.NOTE_C5, QUART),
new Note (Note.NOTE_D5, THREEQUART),
new Note (Note.NOTE_B4, QUART),
new Note (Note.NOTE_C5, FULL+THREEQUART)
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -