Integration into other software

For integrating SoundHelix into a third-party Java software, you can use the SoundHelix API for generating and playing songs. For this, you must add SoundHelix.jar and log4j.jar to your classpath (or provide your own version of log4j). Then, use the com.soundhelix.util.SongUtils class provided by SoundHelix to generate a song and get a SongContext instance which you can use for playing the song. Internally, this will generate a song name by using a SongNameEngine instance (which will be skipped if you provide a song name instead of a random seed) and will then generate a harmony by using a HarmonyEngine instance, will then generate an Arrangement by using an ArrangementEngine instance and will then generate a Player instance.

The following simple quick-and-dirty Java code will load a SoundHelix XML file, generate a song and play it. Note that this will not give you any remote-controlling capabilities (i.e., no ConsoleRemoteControl for entering commands).

import java.net.URL;
import org.apache.log4j.PropertyConfigurator;
import com.soundhelix.component.player.Player;
import com.soundhelix.misc.SongContext;
import com.soundhelix.util.SongUtils;

public class SoundHelixTest {
    public static void main(String[] args) {
        try {
            // configure log4j
            PropertyConfigurator.configureAndWatch("log4j.properties", 60 * 1000);

            SongContext songContext = SongUtils.generateSong(new URL("http://www.soundhelix.com/applet/examples/SoundHelix-Piano.xml"),
                                                             System.nanoTime());
            // use this instead to generate a specific song based on the given song name
            // SongContext songContext = SongUtils.generateSong(new URL("http://www.soundhelix.com/applet/examples/SoundHelix-Piano.xml"),
            //                                                  "My song name");
            
            Player player = songContext.getPlayer();
            player.play(songContext);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

URLs can also be used to load files from your local computer or to directly provide XML content as a string.

Of course, you can also create a separate thread which does the playback. For remote-controlling the player during playback, just look at the methods provided by the Player class.

Please have a look at the license for details about integrating SoundHelix into your software.

Add new comment

Error | SoundHelix

Error

Error message

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1142 INSERT command denied to user 'o3587400'@'swh-live-web53.swh.1u1.it' for table 'drupal_accesslog': INSERT INTO {accesslog} (title, path, url, hostname, uid, sid, timer, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7); Array ( [:db_insert_placeholder_0] => Integration into other software [:db_insert_placeholder_1] => node/65 [:db_insert_placeholder_2] => http://www.soundhelix.com/doc/integration-into-other-software [:db_insert_placeholder_3] => 44.221.43.208 [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => 0ce3caE1I-uMXTBIep-8wDH16roY4iNAltj1Wl6SFro [:db_insert_placeholder_6] => 1240 [:db_insert_placeholder_7] => 1710837364 ) in statistics_exit() (line 91 of /mnt/web305/e3/68/52429368/htdocs/soundhelix.com/public_html/modules/statistics/statistics.module).
The website encountered an unexpected error. Please try again later.