package X3dForAdvancedModeling.AudioSpatialSound;

import org.web3d.x3d.jsail.Core.*;
import org.web3d.x3d.jsail.fields.*;
import org.web3d.x3d.jsail.Geometry3D.*;
import org.web3d.x3d.jsail.Shape.*;
import org.web3d.x3d.jsail.Sound.*;
import org.web3d.x3d.jsail.Time.*;

// Javadoc metadata annotations follow, see below for X3DJSAIL Java source code.
/**
 * <p> List of all X3D4 audio graph nodes to test authoring tools and validation support. Each of the sound nodes shown here receives signal input from its children nodes, and provides signal output to its parent node. </p>
 <p> Related links: Catalog page <a href="../../../AudioSpatialSound/AllAudioGraphNodesTestIndex.html" target="_blank">AllAudioGraphNodesTest</a>,  source <a href="../../../AudioSpatialSound/AllAudioGraphNodesTest.java">AllAudioGraphNodesTest.java</a>, <a href="https://www.web3d.org/x3d/content/examples/X3dResources.html" target="_blank">X3D Resources</a>, <a href="https://www.web3d.org/x3d/content/examples/X3dSceneAuthoringHints.html" target="_blank">X3D Scene Authoring Hints</a>, and <a href="https://www.web3d.org/x3d/content/X3dTooltips.html" target="_blank">X3D Tooltips</a>. </p>
	<table style="color:black; border:0px solid; border-spacing:10px 0px;">
        <caption>Scene Meta Information</caption>
		<tr style="background-color:silver; border-color:silver;">
			<td style="text-align:center; padding:10px 0px;"><i>meta tags</i></td>
			<td style="text-align:left;   padding:10px 0px;">&nbsp; Document Metadata </td>
		</tr>

		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> title </i> </td>
			<td> <a href="../../../AudioSpatialSound/AllAudioGraphNodesTest.x3d">AllAudioGraphNodesTest.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> description </i> </td>
			<td> List of all X3D4 audio graph nodes to test authoring tools and validation support. Each of the sound nodes shown here receives signal input from its children nodes, and provides signal output to its parent node. </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> creator </i> </td>
			<td> Don Brutzman </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> created </i> </td>
			<td> 25 October 2020 </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> modified </i> </td>
			<td> 27 August 2025 </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> info </i> </td>
			<td> Developmental test, no actual audio model is produced </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> Sound </i> </td>
			<td> <a href="../../../AudioSpatialSound/sound/saxophone.ogg">sound/saxophone.ogg</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> Sound </i> </td>
			<td> <a href="../../../AudioSpatialSound/sound/saxophone.mp3">sound/saxophone.mp3</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> Sound </i> </td>
			<td> <a href="../../../AudioSpatialSound/sound/saxophone.wav">sound/saxophone.wav</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> identifier </i> </td>
			<td> <a href="https://www.web3d.org/x3d/content/examples/X3dForAdvancedModeling/AudioSpatialSound/AllAudioGraphNodesTest.x3d" target="_blank">https://www.web3d.org/x3d/content/examples/X3dForAdvancedModeling/AudioSpatialSound/AllAudioGraphNodesTest.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> generator </i> </td>
			<td> X3D-Edit 4.0, <a href="https://www.web3d.org/x3d/tools/X3D-Edit" target="_blank">https://www.web3d.org/x3d/tools/X3D-Edit</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> license </i> </td>
			<td> <a href="../../../AudioSpatialSound/../license.html">../license.html</a> </td>
		</tr>
		<tr style="background-color:silver; border-color:silver;">
			<td style="text-align:center;" colspan="2">  &nbsp; </td>
		</tr>
	</table>

	<p>
		This program uses the
		<a href="https://www.web3d.org/specifications/java/X3DJSAIL.html" target="_blank">X3D Java Scene Access Interface Library (X3DJSAIL)</a>.
		It has been produced using the 
		<a href="https://www.web3d.org/x3d/stylesheets/X3dToJava.xslt" target="_blank">X3dToJava.xslt</a>
		stylesheet
	       (<a href="https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/stylesheets/X3dToJava.xslt" target="_blank">version control</a>)
                which is used to create Java source code from an original <code>.x3d</code> model.
	</p>

	* @author Don Brutzman
 */

public class AllAudioGraphNodesTest
{
	/** Default constructor to create this object. */
	public AllAudioGraphNodesTest ()
	{
	  initialize();
	}

	/** Create and initialize the X3D model for this object. */
	public final void initialize()
	{
            try { // catch-all
  x3dModel = new X3D().setProfile(X3D.PROFILE_IMMERSIVE).setVersion(X3D.VERSION_4_0)
  .setHead(new head()
    .addComponent(new component().setName("Sound").setLevel(3))
    .addMeta(new meta().setName(meta.NAME_TITLE      ).setContent("AllAudioGraphNodesTest.x3d"))
    .addMeta(new meta().setName(meta.NAME_DESCRIPTION).setContent("List of all X3D4 audio graph nodes to test authoring tools and validation support. Each of the sound nodes shown here receives signal input from its children nodes, and provides signal output to its parent node."))
    .addMeta(new meta().setName(meta.NAME_CREATOR    ).setContent("Don Brutzman"))
    .addMeta(new meta().setName(meta.NAME_CREATED    ).setContent("25 October 2020"))
    .addMeta(new meta().setName(meta.NAME_MODIFIED   ).setContent("27 August 2025"))
    .addMeta(new meta().setName(meta.NAME_INFO       ).setContent("Developmental test, no actual audio model is produced"))
    .addMeta(new meta().setName(meta.NAME_SOUND      ).setContent("sound/saxophone.ogg"))
    .addMeta(new meta().setName(meta.NAME_SOUND      ).setContent("sound/saxophone.mp3"))
    .addMeta(new meta().setName(meta.NAME_SOUND      ).setContent("sound/saxophone.wav"))
    .addMeta(new meta().setName(meta.NAME_IDENTIFIER ).setContent("https://www.web3d.org/x3d/content/examples/X3dForAdvancedModeling/AudioSpatialSound/AllAudioGraphNodesTest.x3d"))
    .addMeta(new meta().setName(meta.NAME_GENERATOR  ).setContent("X3D-Edit 4.0, https://www.web3d.org/x3d/tools/X3D-Edit"))
    .addMeta(new meta().setName(meta.NAME_LICENSE    ).setContent("../license.html")))
  .setScene(new Scene()
    .addChild(new WorldInfo().setTitle("AllAudioGraphNodesTest.x3d"))
    .addChild(new Shape()
      .setGeometry(new Box())
      .setAppearance(new Appearance()
        .setAcousticProperties(new AcousticProperties("TestAcousticProperties").setDescription("hello AcousticProperties").setAbsorption(0.11).setDiffuse(0.22).setEnabled(false).setRefraction(0.33).setSpecular(0.44))
        .setMaterial(new Material())))
    .addChild(new Sound("TestSound").setDescription("hello Sound").setDirection(0.0,0.0,1.2).setEnabled(false).setIntensity(0.99).setLocation(0.1,1.6,0.1).setMaxBack(10.1).setMaxFront(10.2).setMinBack(1.3).setMinFront(1.4).setPriority(0.01).setSpatialize(false)
      .addComments(" TODO fix missing canonicalization of gain='1' ")
      .setSource(new AudioClip("TestAudioClip").setDescription("hello AudioClip").setAutoRefresh(100).setAutoRefreshTimeLimit(1000).setEnabled(false).setGain(1.2).setPauseTime(5).setPitch(3.4).setResumeTime(6).setStartTime(7).setStopTime(8).setUrl(new String[] {"sound/saxophone.ogg","https://www.web3d.org/x3d/content/examples/X3dForAdvancedModeling/AudioSpatialSound/sound/saxophone.ogg","sound/saxophone.mp3","https://www.web3d.org/x3d/content/examples/X3dForAdvancedModeling/AudioSpatialSound/sound/saxophone.mp3","sound/saxophone.wav","https://www.web3d.org/x3d/content/examples/X3dForAdvancedModeling/AudioSpatialSound/sound/saxophone.wav"}))
      .addComments(" ROUTE connections do not pass validation if provided within a chain of audio nodes. "))
    .addComments(" Any ROUTE connections must follow DEF nodes being connected. ")
    .addChild(new TimeSensor("TestTimeSensor").setDescription("hello TimeSensor").setCycleInterval(2).setEnabled(false).setLoop(true).setPauseTime(3).setResumeTime(4).setStartTime(5).setStopTime(6))
    .addChild(new ROUTE().setFromNode("TestTimeSensor").setFromField("cycleTime").setToNode("TestAudioClip").setToField("startTime"))
    .addComments(" Each of the following sound nodes receives signal input from its children nodes, and provides signal output to its parent node. ")
    .addChild(new SpatialSound("TestSpatialSound").setDescription("hello SpatialSound").setConeInnerAngle(3.14).setConeOuterAngle(3.15).setConeOuterGain(0.5).setDirection(2.0,3.0,4.0).setDistanceModel("EXPONENTIAL").setDopplerEnabled(true).setEnableHRTF(true).setEnabled(false).setGain(1.1).setIntensity(0.5).setLocation(6.0,7.0,8.0).setMaxDistance(20000).setPriority(0.9).setReferenceDistance(10).setRolloffFactor(11).setSpatialize(false)
      .addChild(new Analyser("TestAnalyser").setDescription("hello Analyser").setChannelCountMode("EXPLICIT").setChannelInterpretation("DISCRETE").setFftSize(2049).setGain(0.99).setMaxDecibels(-31).setMinDecibels(-101).setPauseTime(6).setResumeTime(7).setSmoothingTimeConstant(0.88).setStartTime(8).setStopTime(9)
        .addChild(new AudioDestination("TestAudioDestination").setDescription("hello AudioDestination").setChannelCountMode("EXPLICIT").setChannelInterpretation("DISCRETE").setEnabled(false).setGain(1.1).setMediaDeviceID("ABC345")
          .addChild(new BiquadFilter("TestBiquadFilter").setDescription("hello BiquadFilter").setDetune(0.5).setEnabled(false).setFrequency(1000).setGain(2).setPauseTime(3).setResumeTime(4).setStartTime(5).setStopTime(6).setTailTime(7).setType("ALLPASS")
            .addChild(new ChannelMerger("TestChannelMerger").setDescription("hello ChannelMerger").setChannelCountMode("EXPLICIT").setChannelInterpretation("DISCRETE").setEnabled(false).setGain(123)
              .addChild(new ChannelSelector("TestChannelSelector").setDescription("hello ChannelSelector").setChannelCountMode("CLAMPED_MAX").setChannelInterpretation("DISCRETE").setChannelSelection(1).setEnabled(false).setGain(2)
                .addChild(new ChannelSplitter("TestChannelSplitter").setDescription("hello ChannelSplitter").setChannelCountMode("EXPLICIT").setChannelInterpretation("DISCRETE").setEnabled(false).setGain(789)
                  .addChild(new Convolver("TestConvolver").setDescription("hello Convolver").setBuffer(new double[] {0.0,1.0,2.0,3.0}).setChannelCountMode("CLAMPED_MAX").setChannelInterpretation("DISCRETE").setEnabled(false).setGain(4).setNormalize(true).setPauseTime(5).setResumeTime(6).setStartTime(7).setStopTime(8).setTailTime(9)
                    .addChild(new Delay("TestDelay").setDescription("hello delay").setChannelCountMode("CLAMPED_MAX").setDelayTime(2).setEnabled(false).setGain(4).setMaxDelayTime(3).setPauseTime(5).setResumeTime(6).setStartTime(7).setStopTime(8).setTailTime(9)
                      .addChild(new DynamicsCompressor("TestDynamicsCompressor").setDescription("hello DynamicsCompressor").setAttack(0.00333).setEnabled(false).setGain(2).setKnee(10).setPauseTime(3).setRatio(11).setRelease(12).setResumeTime(4).setStartTime(5).setStopTime(6).setTailTime(7).setThreshold(-100)
                        .addChild(new Gain("TestGain").setDescription("hello gain").setChannelCountMode("EXPLICIT").setChannelInterpretation("DISCRETE").setEnabled(false).setGain(-2).setPauseTime(2).setResumeTime(3).setStartTime(4).setStopTime(5).setTailTime(1)
                          .addChild(new StreamAudioDestination("TestStreamAudioDestination").setDescription("hello StreamAudioDestination").setChannelCountMode("CLAMPED_MAX").setChannelInterpretation("DISCRETE").setEnabled(false).setGain(0).setMediaDeviceID("abc123").setStreamIdentifier(new String[] {"unique ID","part 2"})
                            .addChild(new WaveShaper("TestWaveShaper").setDescription("hello WaveShaper").setChannelCountMode("CLAMPED_MAX").setChannelInterpretation("DISCRETE").setCurve(new double[] {1.0,2.0,3.0,4.0}).setEnabled(false).setGain(5).setPauseTime(6).setResumeTime(7).setStartTime(8).setStopTime(9).setTailTime(10)
                              .addComments(" The following X3DSoundSourceNode nodes have no allowed audio-graph children nodes as inputs ")
                              .addChild(new BufferAudioSource("TestBufferAudioSource").setDescription("hello BufferAudioSource").setAutoRefresh(1).setAutoRefreshTimeLimit(2).setBuffer(new double[] {3.0,4.0,5.0}).setBufferDuration(6).setChannelCountMode("CLAMPED_MAX").setChannelInterpretation("DISCRETE").setDetune(7).setEnabled(false).setGain(8).setLoad(false).setLoop(true).setLoopEnd(12).setLoopStart(12).setNumberOfChannels(12).setPauseTime(13).setPlaybackRate(14).setResumeTime(15).setSampleRate(16).setStartTime(17).setStopTime(18).setUrl(new String[] {"sound/saxophone.mp3","https://www.web3d.org/x3d/content/examples/X3dForAdvancedModeling/AudioSpatialSound/sound/saxophone.mp3"}))
                              .addChild(new ListenerPointSource("TestListenerPointSource").setDescription("hello ListenerPointSource").setDopplerEnabled(true).setEnabled(false).setGain(0.1).setInterauralDistance(2).setOrientation(6.0,7.0,8.0,0.9).setPauseTime(10).setPosition(3.0,4.0,5.0).setResumeTime(11).setStartTime(12).setStopTime(13).setTrackCurrentView(true))
                              .addChild(new MicrophoneSource("TestMicrophoneSource").setDescription("hello MicrophoneSource").setEnabled(false).setGain(0.12).setMediaDeviceID("345XYZ").setPauseTime(6).setResumeTime(7).setStartTime(8).setStopTime(9))
                              .addChild(new OscillatorSource("TestOscillatorSource").setDescription("hello OscillatorSource").setDetune(1).setEnabled(false).setFrequency(234).setGain(5).setPauseTime(6).setResumeTime(7).setStartTime(8).setStopTime(9)
                                .setPeriodicWave(new PeriodicWave("TestPeriodicWave").setDescription("hello PeriodicWave").setOptionsImag(new int[] {0,1,2,3,5}).setOptionsReal(new int[] {5,6,7,8,9}).setType("CUSTOM")))
                              .addChild(new StreamAudioSource("TestStreamAudioSource").setDescription("hello StreamAudioSource").setChannelCountMode("EXPLICIT").setChannelInterpretation("DISCRETE").setEnabled(false).setGain(1.2).setPauseTime(6).setResumeTime(7).setStartTime(8).setStopTime(9).setStreamIdentifier(new String[] {"345 XYZ"}))))))))))))))));
            }
            catch (Exception ex)
            {       
                System.err.println ("*** Further hints on X3DJSAIL errors and exceptions at");
                System.err.println ("*** https://www.web3d.org/specifications/java/X3DJSAIL.html");
                throw (ex);
            }
	}
	// end of initialize() method

	/** The initialized model object, created within initialize() method. */
	private X3D x3dModel;

	/** 
	 * Provide a 
	 * <a href="https://dzone.com/articles/java-copy-shallow-vs-deep-in-which-you-will-swim" target="_blank">shallow copy</a>
	 * of the X3D model.
	 * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Core/X3D.html">X3D</a>
	 * @return AllAudioGraphNodesTest model
	 */
	public X3D getX3dModel()
	{	  
		return x3dModel;
	}
	   
    /** 
     * Default main() method provided for test purposes, uses CommandLine to set global ConfigurationProperties for this object.
     * @param args array of input parameters, provided as arguments
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Core/X3D.html#handleArguments-java.lang.String:A-">X3D.handleArguments(args)</a>
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Core/X3D.html#validationReport--">X3D.validationReport()</a>
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/CommandLine.html">CommandLine</a>
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/CommandLine.html#USAGE">CommandLine.USAGE</a>
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/ConfigurationProperties.html">ConfigurationProperties</a>
     */
    public static void main(String args[])
    {
        System.out.println("Build this X3D model, showing validation diagnostics...");
        X3D thisExampleX3dModel = new AllAudioGraphNodesTest().getX3dModel();
//      System.out.println("X3D model construction complete.");
	
        // next handle command line arguments
        boolean hasArguments = (args != null) && (args.length > 0);
        boolean validate = true; // default
        boolean argumentsLoadNewModel = false;
        String  fileName = new String();

        if (args != null)
        {
                for (String arg : args)
                {
                        if (arg.toLowerCase().startsWith("-v") || arg.toLowerCase().contains("validate"))
                        {
                                validate = true; // making sure
                        }
                        if (arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_X3D) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_CLASSICVRML) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_X3DB) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_VRML97) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_EXI) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_GZIP) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_ZIP) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_HTML) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_XHTML))
                        {
                                argumentsLoadNewModel = true;
                                fileName = arg;
                        }
                }
        }
        if      (argumentsLoadNewModel)
                System.out.println("WARNING: \"X3dForAdvancedModeling.AudioSpatialSound.AllAudioGraphNodesTest\" model invocation is attempting to load file \"" + fileName + "\" instead of simply validating itself... file loading ignored.");
        else if (hasArguments) // if no arguments provided, this method produces usage warning
                thisExampleX3dModel.handleArguments(args);
	
        if (validate)
        {
            //  System.out.println("--- TODO fix duplicated outputs ---"); // omit when duplicated outputs problem is solved/refactored
		String validationResults = thisExampleX3dModel.validationReport();
            //  System.out.println("-----------------------------------"); // omit when duplicated outputs problem is solved/refactored
                System.out.print("X3dForAdvancedModeling.AudioSpatialSound.AllAudioGraphNodesTest self-validation test confirmation: ");
                if (!validationResults.equals("success"))
                    System.out.println();
                System.out.println(validationResults.trim());

                // experimental: test X3DJSAIL output files
                // AudioSpatialSound/AllAudioGraphNodesTest_JavaExport.* file validation is checked when building X3D Example Archives
                String filenameX3D  = "AudioSpatialSound/AllAudioGraphNodesTest_JavaExport.x3d"; 
                String filenameX3DV = "AudioSpatialSound/AllAudioGraphNodesTest_JavaExport.x3dv"; 
                String filenameJSON = "AudioSpatialSound/AllAudioGraphNodesTest_JavaExport.json";
                thisExampleX3dModel.toFileX3D        (filenameX3D);
                thisExampleX3dModel.toFileClassicVRML(filenameX3DV);
// TODO         thisExampleX3dModel.toFileJSON       (filenameJSON);
        }
    }
}
