What is jMorse?

A java library to generate audible morse code.

jMorse is designed to make it easy to generate morse code in the following contexts:

  • directly within your java classes
  • ant
  • log4j
  • java logging
  • from the command line

[top]

How can I use jMorse in my java code?

Here is a sample java file:

import net.sf.jmorse.AudioMorseWriter;

public class SampleMorse {
	public void foo() {
	  AudioMorseWriter morse = new AudioMorseWriter();	  
	  morse.setWpm(15);
	  morse.setVolume(5);
	  morse.setTone(450);
	  morse.write("cq de jMorse");
	}
}

[top]

How can I use jMorse via ant?

You must define the morse task via the taskdef tag. Here is a sample ant build file:

<?xml version="1.0"?>
<project name="jMorse sample usage of ant task" default="morse:test" basedir=".">
   <taskdef name="morse" classname="net.sf.jmorse.ant.MorseTask" />

   <target name="morse:test">
      <morse message="CQ DE JMORSE" wpm="15" tone="450" volume="5" />
   </target>
</project>

[top]

How can I use jMorse via log4j?

You must add the morse appender to your log4j configuration:

log4j.appender.morse = net.sf.jmorse.log4j.AudioMorseAppender
log4j.appender.morse.wpm = 15
log4j.appender.morse.tone = 450
log4j.appender.morse.volume = 5
log4j.appender.morse.layout = org.apache.log4j.PatternLayout
log4j.appender.morse.layout.conversionPattern=%m
Then, tie the morse appender, with the "SampleMorse" class:
log4j.logger.SampleMorse=INFO, morse
Here is a sample java file to log a message:
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class SampleMorse {
	private static final Log s_log = LogFactory.getLog(SampleMorse.class);

	public void foo() {
		s_log.info("cq de jMorse");
	}
}

[top]

How can I use jMorse via java logging?

Here is a sample java file to add an AudioMorseHandler to a Logger instance:

import java.util.logging.Level;
import java.util.logging.Logger;
import net.sf.jmorse.logging.AudioMorseHandler;

public class SampleMorse {
        public void foo() {
                Logger logger = Logger.getLogger(SampleMorse.class);
                AudioMorseHandler handler = new AudioMorseHandler();
                handler.setWpm(15);
                handler.setVolume(5);
                handler.setTone(450);
                logger.addHandler(handler);

                logger.log(Level.FINER, "cq de jMorse");
        }
}

Warning: The AudioMorseHandler should not be added to the list of global Handlers. jMorse uses java logging internally and this may result in an infinite loop.

[top]

How can I use jMorse via the command line?

Examples don't include jar version info:

%java -jar jmorse.jar -v5 Hello World
%echo Hello World | java -jar jmorse.jar 
%cat hello_world.txt | java -jar jmorse.jar -o=hello_world.wav

Usage:

%java -jar target/jmorse.jar --help
Usage: java -jar jmorse.jar [OPTION] {string} [FILE]
Use string, file, or standard input, to generate morse code on the default 
audio output device.

  -t              tone
  -w              word speed
  -v              volume [0-10]
  -i              text file to use as message text
  -o              output file to store morse code as wave
       --help     display this help and exit
       --version  output version information and exit
       --version  output version information and exit

If no input file or string is specified, then the standard input is read.

[top]