1.1 --- a/make/common/Release.gmk Thu Jan 29 21:46:48 2009 -0800
1.2 +++ b/make/common/Release.gmk Tue Feb 03 22:02:55 2009 -0800
1.3 @@ -912,14 +912,6 @@
1.4 done
1.5 ifeq ($(PLATFORM), windows)
1.6 @#
1.7 - @# Audio soundbank - Bug# 4236400
1.8 - @# Windows only: adding audio files to JDK's jre/lib directory.
1.9 - @#
1.10 - ($(CD) $(LIBDIR) && $(TAR) cf - \
1.11 - `$(FIND) audio -depth -print`) | \
1.12 - ($(CD) $(JDK_IMAGE_DIR)/jre/lib && $(TAR) xf -)
1.13 - @#
1.14 - @#
1.15 @# lib/
1.16 @#
1.17 $(CP) $(LIBDIR)/$(LIB_PREFIX)jvm.$(LIB_SUFFIX) $(JDK_IMAGE_DIR)/lib
2.1 --- a/make/common/internal/BinaryPlugs.gmk Thu Jan 29 21:46:48 2009 -0800
2.2 +++ b/make/common/internal/BinaryPlugs.gmk Tue Feb 03 22:02:55 2009 -0800
2.3 @@ -29,9 +29,7 @@
2.4
2.5 # Names of native shared libraries
2.6
2.7 -PLUG_JSOUND_LIBRARY=$(LIB_PREFIX)jsoundhs.$(LIBRARY_SUFFIX)
2.8 -PLUG_LIBRARY_NAMES = \
2.9 - $(PLUG_JSOUND_LIBRARY)
2.10 +PLUG_LIBRARY_NAMES=
2.11
2.12 # Sub-directory where native shared libraries are located (e.g. jre/bin or...)
2.13
2.14 @@ -74,62 +72,10 @@
2.15 com/sun/jmx/snmp/daemon/SnmpTimerServer.class \
2.16 com/sun/jmx/snmp/daemon/WaitQ.class
2.17
2.18 -PLUG_SOUND_CLASS_NAMES = \
2.19 -com/sun/media/sound/AbstractPlayer.class \
2.20 -com/sun/media/sound/CircularBuffer.class \
2.21 -com/sun/media/sound/HeadspaceInstrument.class \
2.22 -com/sun/media/sound/HeadspaceMixer\$$1.class \
2.23 -com/sun/media/sound/HeadspaceMixer\$$MidiLine.class \
2.24 -com/sun/media/sound/HeadspaceMixer\$$MidiLineInfo.class \
2.25 -com/sun/media/sound/HeadspaceMixer\$$MixerInfo.class \
2.26 -com/sun/media/sound/HeadspaceMixer\$$MixerReverbControl\$$MixerReverbType.class \
2.27 -com/sun/media/sound/HeadspaceMixer\$$MixerReverbControl.class \
2.28 -com/sun/media/sound/HeadspaceMixer.class \
2.29 -com/sun/media/sound/HeadspaceMixerProvider.class \
2.30 -com/sun/media/sound/HeadspaceSample.class \
2.31 -com/sun/media/sound/HeadspaceSoundbank.class \
2.32 -com/sun/media/sound/HsbParser.class \
2.33 -com/sun/media/sound/MixerClip\$$1.class \
2.34 -com/sun/media/sound/MixerClip\$$MixerClipApplyReverbControl.class \
2.35 -com/sun/media/sound/MixerClip\$$MixerClipGainControl.class \
2.36 -com/sun/media/sound/MixerClip\$$MixerClipMuteControl.class \
2.37 -com/sun/media/sound/MixerClip\$$MixerClipPanControl.class \
2.38 -com/sun/media/sound/MixerClip\$$MixerClipSampleRateControl.class \
2.39 -com/sun/media/sound/MixerClip.class \
2.40 -com/sun/media/sound/MixerMidiChannel.class \
2.41 -com/sun/media/sound/MixerSequencer\$$1.class \
2.42 -com/sun/media/sound/MixerSequencer\$$ControllerVectorElement.class \
2.43 -com/sun/media/sound/MixerSequencer\$$MixerSequencerInfo.class \
2.44 -com/sun/media/sound/MixerSequencer\$$RecordingTrack.class \
2.45 -com/sun/media/sound/MixerSequencer.class \
2.46 -com/sun/media/sound/MixerSequencerProvider.class \
2.47 -com/sun/media/sound/MixerSourceLine\$$1.class \
2.48 -com/sun/media/sound/MixerSourceLine\$$MixerSourceLineApplyReverbControl.class \
2.49 -com/sun/media/sound/MixerSourceLine\$$MixerSourceLineGainControl.class \
2.50 -com/sun/media/sound/MixerSourceLine\$$MixerSourceLineMuteControl.class \
2.51 -com/sun/media/sound/MixerSourceLine\$$MixerSourceLinePanControl.class \
2.52 -com/sun/media/sound/MixerSourceLine\$$MixerSourceLineSampleRateControl.class \
2.53 -com/sun/media/sound/MixerSourceLine.class \
2.54 -com/sun/media/sound/MixerSynth\$$1.class \
2.55 -com/sun/media/sound/MixerSynth\$$MixerSynthInfo.class \
2.56 -com/sun/media/sound/MixerSynth\$$SynthReceiver.class \
2.57 -com/sun/media/sound/MixerSynth.class \
2.58 -com/sun/media/sound/MixerSynthProvider.class \
2.59 -com/sun/media/sound/MixerThread.class \
2.60 -com/sun/media/sound/RmfFileReader.class \
2.61 -com/sun/media/sound/SimpleInputDevice\$$1.class \
2.62 -com/sun/media/sound/SimpleInputDevice\$$InputDeviceDataLine.class \
2.63 -com/sun/media/sound/SimpleInputDevice\$$InputDevicePort.class \
2.64 -com/sun/media/sound/SimpleInputDevice\$$InputDevicePortInfo.class \
2.65 -com/sun/media/sound/SimpleInputDevice.class \
2.66 -com/sun/media/sound/SimpleInputDeviceProvider\$$1.class \
2.67 -com/sun/media/sound/SimpleInputDeviceProvider\$$InputDeviceInfo.class \
2.68 -com/sun/media/sound/SimpleInputDeviceProvider.class
2.69 -
2.70 # Class list temp files (used by both import and export of plugs)
2.71
2.72 PLUG_TEMPDIR=$(ABS_TEMPDIR)/plugs
2.73 -PLUG_CLASS_AREAS = jmf sound
2.74 +PLUG_CLASS_AREAS = jmf
2.75 PLUG_CLISTS = $(PLUG_CLASS_AREAS:%=$(PLUG_TEMPDIR)/%.clist)
2.76
2.77 # Create jargs file command
2.78 @@ -147,18 +93,11 @@
2.79 @for i in $(PLUG_JMF_CLASS_NAMES) ; do \
2.80 $(ECHO) "$$i" >> $@; \
2.81 done
2.82 -$(PLUG_TEMPDIR)/sound.clist:
2.83 - @$(prep-target)
2.84 - @for i in $(PLUG_SOUND_CLASS_NAMES) ; do \
2.85 - $(ECHO) "$$i" >> $@ ; \
2.86 - done
2.87 $(PLUG_TEMPDIR)/all.clist: $(PLUG_CLISTS)
2.88 @$(prep-target)
2.89 $(CAT) $(PLUG_CLISTS) > $@
2.90 $(PLUG_TEMPDIR)/jmf.jargs: $(PLUG_TEMPDIR)/jmf.clist
2.91 $(plug-create-jargs)
2.92 -$(PLUG_TEMPDIR)/sound.jargs: $(PLUG_TEMPDIR)/sound.clist
2.93 - $(plug-create-jargs)
2.94 $(PLUG_TEMPDIR)/all.jargs: $(PLUG_TEMPDIR)/all.clist
2.95 $(plug-create-jargs)
2.96
2.97 @@ -193,25 +132,11 @@
2.98
2.99 import-binary-plug-jmf-classes: $(PLUG_IMPORT_JARFILE) $(PLUG_TEMPDIR)/jmf.clist
2.100 $(call import-binary-plug-classes,$(PLUG_TEMPDIR)/jmf.clist)
2.101 -import-binary-plug-sound-classes: $(PLUG_IMPORT_JARFILE) $(PLUG_TEMPDIR)/sound.clist
2.102 - $(call import-binary-plug-classes,$(PLUG_TEMPDIR)/sound.clist)
2.103
2.104 # Import all classes from the jar file
2.105
2.106 import-binary-plug-jar: \
2.107 - import-binary-plug-jmf-classes \
2.108 - import-binary-plug-sound-classes
2.109 -
2.110 -# Import native libraries
2.111 -
2.112 -$(LIB_LOCATION)/$(PLUG_JSOUND_LIBRARY): \
2.113 - $(PLUG_IMPORT_DIR)/$(PLUG_LOCATION_SUBDIR)/$(PLUG_JSOUND_LIBRARY)
2.114 - $(import-binary-plug-file)
2.115 -
2.116 -# Rules only used by lower level makefiles
2.117 -
2.118 -import-binary-plug-jsound-library: \
2.119 - $(LIB_LOCATION)/$(PLUG_JSOUND_LIBRARY)
2.120 + import-binary-plug-jmf-classes
2.121
2.122 # Binary plug start/complete messages
2.123
2.124 @@ -241,9 +166,7 @@
2.125 import-binary-plugs-libs \
2.126 import-binary-plugs \
2.127 import-binary-plug-jar \
2.128 - import-binary-plug-jmf-classes \
2.129 - import-binary-plug-sound-classes \
2.130 - import-binary-plug-jsound-library
2.131 + import-binary-plug-jmf-classes
2.132
2.133 else # !OPENJDK
2.134
2.135 @@ -280,12 +203,6 @@
2.136 @$(java-vm-cleanup)
2.137 export-binary-plugs-jar: $(PLUG_EXPORT_JARFILE)
2.138
2.139 -# Export native libraries
2.140 -
2.141 -$(PLUG_EXPORT_DIR)/$(PLUG_LOCATION_SUBDIR)/$(PLUG_JSOUND_LIBRARY): \
2.142 - $(LIB_LOCATION)/$(PLUG_JSOUND_LIBRARY)
2.143 - $(export-binary-plug-file)
2.144 -
2.145 # Export binary plug start/complete messages
2.146
2.147 export-binary-plugs-started:
3.1 --- a/make/javax/sound/Makefile Thu Jan 29 21:46:48 2009 -0800
3.2 +++ b/make/javax/sound/Makefile Tue Feb 03 22:02:55 2009 -0800
3.3 @@ -54,18 +54,6 @@
3.4 AUTO_FILES_JAVA_DIRS = javax/sound com/sun/media/sound
3.5
3.6 #
3.7 -# Specific to OpenJDK building
3.8 -#
3.9 -ifdef OPENJDK
3.10 -
3.11 -# copy closed .class files
3.12 -build: import-binary-plug-sound-classes
3.13 -
3.14 -include $(BUILDDIR)/common/internal/BinaryPlugs.gmk
3.15 -
3.16 -endif # OPENJDK
3.17 -
3.18 -#
3.19 # Files that just need cp.
3.20 #
3.21 SERVICEDIR = $(CLASSBINDIR)/META-INF/services
3.22 @@ -79,13 +67,11 @@
3.23 $(SERVICEDIR)/javax.sound.sampled.spi.AudioFileReader \
3.24 $(SERVICEDIR)/javax.sound.sampled.spi.FormatConversionProvider \
3.25 $(SERVICEDIR)/javax.sound.sampled.spi.MixerProvider \
3.26 - $(LIBDIR)/audio/soundbank.gm \
3.27 $(LIBDIR)/sound.properties
3.28
3.29 FILES_mkdirs = \
3.30 $(CLASSBINDIR)/META-INF \
3.31 - $(CLASSBINDIR)/META-INF/services \
3.32 - $(LIBDIR)/audio
3.33 + $(CLASSBINDIR)/META-INF/services
3.34
3.35 FILES_copydirs = \
3.36 $(CLASSBINDIR) \
3.37 @@ -96,11 +82,6 @@
3.38
3.39
3.40 #
3.41 -# add "closed" library
3.42 -#
3.43 -SUBDIRS += jsoundhs
3.44 -
3.45 -#
3.46 # system dependent flags
3.47 #
3.48 ifeq ($(PLATFORM), windows)
4.1 --- a/make/javax/sound/jsoundhs/FILES.gmk Thu Jan 29 21:46:48 2009 -0800
4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
4.3 @@ -1,91 +0,0 @@
4.4 -#
4.5 -# Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
4.6 -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4.7 -#
4.8 -# This code is free software; you can redistribute it and/or modify it
4.9 -# under the terms of the GNU General Public License version 2 only, as
4.10 -# published by the Free Software Foundation. Sun designates this
4.11 -# particular file as subject to the "Classpath" exception as provided
4.12 -# by Sun in the LICENSE file that accompanied this code.
4.13 -#
4.14 -# This code is distributed in the hope that it will be useful, but WITHOUT
4.15 -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4.16 -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4.17 -# version 2 for more details (a copy is included in the LICENSE file that
4.18 -# accompanied this code).
4.19 -#
4.20 -# You should have received a copy of the GNU General Public License version
4.21 -# 2 along with this work; if not, write to the Free Software Foundation,
4.22 -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4.23 -#
4.24 -# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
4.25 -# CA 95054 USA or visit www.sun.com if you need additional information or
4.26 -# have any questions.
4.27 -#
4.28 -
4.29 -FILES_c = \
4.30 - Utilities.c \
4.31 - MixerThread.c \
4.32 - HeadspaceMixer.c \
4.33 - MixerClip.c \
4.34 - MixerSourceLine.c \
4.35 - SimpleInputDevice.c \
4.36 - SimpleInputDeviceProvider.c \
4.37 - HeadspaceSoundbank.c \
4.38 - MixerMidiChannel.c \
4.39 - AbstractPlayer.c \
4.40 - MixerSequencer.c \
4.41 - MixerSynth.c
4.42 -
4.43 -FILES_engine = \
4.44 - DriverTools.c \
4.45 - GenAudioCaptureStreams.c \
4.46 - GenAudioStreams.c \
4.47 - GenOutput.c \
4.48 - GenPatch.c \
4.49 - GenReverb.c \
4.50 - GenSample.c \
4.51 - GenSeq.c \
4.52 - GenSetup.c \
4.53 - GenSong.c \
4.54 - GenSynth.c \
4.55 - GenSynthFilters.c \
4.56 - GenSynthInterp2.c \
4.57 - GenSynthResample.c \
4.58 - NewNewLZSS.c \
4.59 - SampleTools.c \
4.60 - SMOD_Volume_Scaler.c \
4.61 - X_API.c \
4.62 - X_Decompress.c \
4.63 - X_IMA.c \
4.64 - GenFiltersReverb.c \
4.65 - GenInterp2Reverb.c \
4.66 - GenSoundFiles.c \
4.67 - SincResample.c
4.68 -
4.69 -FILES_solaris = \
4.70 - HAE_API_SolarisOS.c \
4.71 - HAE_API_SolarisOS_Capture.c
4.72 -
4.73 -FILES_linux = \
4.74 - HAE_API_LinuxOS.c \
4.75 - HAE_API_LinuxOS_Capture.c
4.76 -
4.77 -FILES_windows = \
4.78 - HAE_API_WinOS.c \
4.79 - HAE_API_WinOS_Capture.c \
4.80 - HAE_API_WinOS_Synth.c
4.81 -
4.82 -FILES_export = \
4.83 - com/sun/media/sound/AbstractPlayer.java \
4.84 - com/sun/media/sound/HeadspaceMixer.java \
4.85 - com/sun/media/sound/HeadspaceSoundbank.java \
4.86 - com/sun/media/sound/MixerClip.java \
4.87 - com/sun/media/sound/MixerMidiChannel.java \
4.88 - com/sun/media/sound/MixerSequencer.java \
4.89 - com/sun/media/sound/MixerSourceLine.java \
4.90 - com/sun/media/sound/MixerSynth.java \
4.91 - com/sun/media/sound/MixerThread.java \
4.92 - com/sun/media/sound/SimpleInputDevice.java \
4.93 - com/sun/media/sound/SimpleInputDeviceProvider.java
4.94 -
5.1 --- a/make/javax/sound/jsoundhs/Makefile Thu Jan 29 21:46:48 2009 -0800
5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
5.3 @@ -1,100 +0,0 @@
5.4 -#
5.5 -# Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
5.6 -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5.7 -#
5.8 -# This code is free software; you can redistribute it and/or modify it
5.9 -# under the terms of the GNU General Public License version 2 only, as
5.10 -# published by the Free Software Foundation. Sun designates this
5.11 -# particular file as subject to the "Classpath" exception as provided
5.12 -# by Sun in the LICENSE file that accompanied this code.
5.13 -#
5.14 -# This code is distributed in the hope that it will be useful, but WITHOUT
5.15 -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5.16 -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5.17 -# version 2 for more details (a copy is included in the LICENSE file that
5.18 -# accompanied this code).
5.19 -#
5.20 -# You should have received a copy of the GNU General Public License version
5.21 -# 2 along with this work; if not, write to the Free Software Foundation,
5.22 -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5.23 -#
5.24 -# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
5.25 -# CA 95054 USA or visit www.sun.com if you need additional information or
5.26 -# have any questions.
5.27 -#
5.28 -
5.29 -BUILDDIR = ../../..
5.30 -PACKAGE = javax.sound
5.31 -LIBRARY = jsoundhs
5.32 -PRODUCT = sun
5.33 -CPLUSPLUSLIBRARY = true
5.34 -include $(BUILDDIR)/common/Defs.gmk
5.35 -
5.36 -# this Makefile compiles "closed" JavaSound library
5.37 -
5.38 -ifdef OPENJDK
5.39 -
5.40 -# precompiled lib will be copied by the rules in Library.gmk instead of compiling.
5.41 -USE_BINARY_PLUG_LIBRARY=true
5.42 -
5.43 -build: import-binary-plug-jsound-library
5.44 -
5.45 -include $(BUILDDIR)/common/internal/BinaryPlugs.gmk
5.46 -
5.47 -else # OPENJDK
5.48 -
5.49 -# include defines for sound
5.50 -include ../SoundDefs.gmk
5.51 -
5.52 -#
5.53 -# Add use of mapfile
5.54 -#
5.55 -FILES_m = mapfile-vers
5.56 -include $(BUILDDIR)/common/Mapfile-vers.gmk
5.57 -
5.58 -#
5.59 -# Files
5.60 -#
5.61 -include FILES.gmk
5.62 -
5.63 -FILES_c += $(FILES_engine) $(FILES_$(PLATFORM))
5.64 -
5.65 -#
5.66 -# Extra cc/linker flags.
5.67 -#
5.68 -# flags needed for all platforms
5.69 -CPPFLAGS += \
5.70 - -DJAVA_SOUND -DJAVA_THREAD \
5.71 - -I$(CLOSED_SHARE_SRC)/native/com/sun/media/sound \
5.72 - -I$(CLOSED_SHARE_SRC)/native/com/sun/media/sound/engine
5.73 -
5.74 -# system dependent flags
5.75 -ifeq ($(PLATFORM), windows)
5.76 - CPPFLAGS += -DUSE_DIRECTSOUND=0 \
5.77 - -DUSE_EXTERNAL_SYNTH=TRUE
5.78 - LDLIBS += winmm.lib
5.79 -endif # PLATFORM windows
5.80 -
5.81 -ifeq ($(PLATFORM), linux)
5.82 -endif # PLATFORM linux
5.83 -
5.84 -ifeq ($(PLATFORM), solaris)
5.85 -endif # PLATFORM solaris
5.86 -
5.87 -
5.88 -#
5.89 -# Add to the ambient VPATH.
5.90 -#
5.91 -vpath %.c $(CLOSED_SHARE_SRC)/native/com/sun/media/sound
5.92 -vpath %.c $(CLOSED_SHARE_SRC)/native/com/sun/media/sound/engine
5.93 -vpath %.c $(CLOSED_PLATFORM_SRC)/native/com/sun/media/sound/engine
5.94 -
5.95 -
5.96 -endif # OPENJDK
5.97 -
5.98 -
5.99 -#
5.100 -# Include rules
5.101 -#
5.102 -include $(BUILDDIR)/common/Library.gmk
5.103 -
6.1 --- a/make/javax/sound/jsoundhs/mapfile-vers Thu Jan 29 21:46:48 2009 -0800
6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
6.3 @@ -1,153 +0,0 @@
6.4 -#
6.5 -# Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
6.6 -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6.7 -#
6.8 -# This code is free software; you can redistribute it and/or modify it
6.9 -# under the terms of the GNU General Public License version 2 only, as
6.10 -# published by the Free Software Foundation. Sun designates this
6.11 -# particular file as subject to the "Classpath" exception as provided
6.12 -# by Sun in the LICENSE file that accompanied this code.
6.13 -#
6.14 -# This code is distributed in the hope that it will be useful, but WITHOUT
6.15 -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6.16 -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6.17 -# version 2 for more details (a copy is included in the LICENSE file that
6.18 -# accompanied this code).
6.19 -#
6.20 -# You should have received a copy of the GNU General Public License version
6.21 -# 2 along with this work; if not, write to the Free Software Foundation,
6.22 -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6.23 -#
6.24 -# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
6.25 -# CA 95054 USA or visit www.sun.com if you need additional information or
6.26 -# have any questions.
6.27 -#
6.28 -
6.29 -# Define library interface.
6.30 -
6.31 -SUNWprivate_1.1 {
6.32 - global:
6.33 - Java_com_sun_media_sound_AbstractPlayer_nAddReceiver;
6.34 - Java_com_sun_media_sound_AbstractPlayer_nClose;
6.35 - Java_com_sun_media_sound_AbstractPlayer_nLoadInstrument;
6.36 - Java_com_sun_media_sound_AbstractPlayer_nRemapInstrument;
6.37 - Java_com_sun_media_sound_AbstractPlayer_nRemoveReceiver;
6.38 - Java_com_sun_media_sound_AbstractPlayer_nUnloadInstrument;
6.39 - Java_com_sun_media_sound_HeadspaceMixer_nAllocateVoices;
6.40 - Java_com_sun_media_sound_HeadspaceMixer_nCloseMixer;
6.41 - Java_com_sun_media_sound_HeadspaceMixer_nCreateLinkedStreams;
6.42 - Java_com_sun_media_sound_HeadspaceMixer_nDrain;
6.43 - Java_com_sun_media_sound_HeadspaceMixer_nFlush;
6.44 - Java_com_sun_media_sound_HeadspaceMixer_nGetCpuLoad;
6.45 - Java_com_sun_media_sound_HeadspaceMixer_nGetDefaultBufferSize;
6.46 - Java_com_sun_media_sound_HeadspaceMixer_nGetLevel;
6.47 - Java_com_sun_media_sound_HeadspaceMixer_nGetPosition;
6.48 - Java_com_sun_media_sound_HeadspaceMixer_nGetTotalVoices;
6.49 - Java_com_sun_media_sound_HeadspaceMixer_nOpenMixer;
6.50 - Java_com_sun_media_sound_HeadspaceMixer_nPause;
6.51 - Java_com_sun_media_sound_HeadspaceMixer_nResume;
6.52 - Java_com_sun_media_sound_HeadspaceMixer_nSetInterpolation;
6.53 - Java_com_sun_media_sound_HeadspaceMixer_nSetMixerFormat;
6.54 - Java_com_sun_media_sound_HeadspaceMixer_nSetMixLevel;
6.55 - Java_com_sun_media_sound_HeadspaceMixer_nSetReverb;
6.56 - Java_com_sun_media_sound_HeadspaceMixer_nStartLinkedStreams;
6.57 - Java_com_sun_media_sound_HeadspaceMixer_nStopLinkedStreams;
6.58 - Java_com_sun_media_sound_HeadspaceSoundbank_nCloseResource;
6.59 - Java_com_sun_media_sound_HeadspaceSoundbank_nGetInstruments;
6.60 - Java_com_sun_media_sound_HeadspaceSoundbank_nGetName;
6.61 - Java_com_sun_media_sound_HeadspaceSoundbank_nGetSamples;
6.62 - Java_com_sun_media_sound_HeadspaceSoundbank_nGetVersionMajor;
6.63 - Java_com_sun_media_sound_HeadspaceSoundbank_nGetVersionMinor;
6.64 - Java_com_sun_media_sound_HeadspaceSoundbank_nGetVersionSubMinor;
6.65 - Java_com_sun_media_sound_HeadspaceSoundbank_nOpenResource;
6.66 - Java_com_sun_media_sound_HeadspaceSoundbank_nOpenResourceFromByteArray;
6.67 - Java_com_sun_media_sound_MixerClip_nClose;
6.68 - Java_com_sun_media_sound_MixerClip_nDrain;
6.69 - Java_com_sun_media_sound_MixerClip_nFlush;
6.70 - Java_com_sun_media_sound_MixerClip_nGetPosition;
6.71 - Java_com_sun_media_sound_MixerClip_nOpen;
6.72 - Java_com_sun_media_sound_MixerClip_nSetLinearGain;
6.73 - Java_com_sun_media_sound_MixerClip_nSetPan;
6.74 - Java_com_sun_media_sound_MixerClip_nSetSampleRate;
6.75 - Java_com_sun_media_sound_MixerClip_nSetup;
6.76 - Java_com_sun_media_sound_MixerClip_nStart;
6.77 - Java_com_sun_media_sound_MixerClip_nStop;
6.78 - Java_com_sun_media_sound_MixerMidiChannel_nAllNotesOff;
6.79 - Java_com_sun_media_sound_MixerMidiChannel_nControlChange;
6.80 - Java_com_sun_media_sound_MixerMidiChannel_nGetController;
6.81 - Java_com_sun_media_sound_MixerMidiChannel_nGetPitchBend;
6.82 - Java_com_sun_media_sound_MixerMidiChannel_nGetSolo;
6.83 - Java_com_sun_media_sound_MixerMidiChannel_nNoteOff;
6.84 - Java_com_sun_media_sound_MixerMidiChannel_nNoteOn;
6.85 - Java_com_sun_media_sound_MixerMidiChannel_nProgramChange__JIIIJ;
6.86 - Java_com_sun_media_sound_MixerMidiChannel_nProgramChange__JIIJ;
6.87 - Java_com_sun_media_sound_MixerMidiChannel_nResetAllControllers;
6.88 - Java_com_sun_media_sound_MixerMidiChannel_nSetMute;
6.89 - Java_com_sun_media_sound_MixerMidiChannel_nSetPitchBend;
6.90 - Java_com_sun_media_sound_MixerMidiChannel_nSetSolo;
6.91 - Java_com_sun_media_sound_MixerSequencer_nAddControllerEventCallback;
6.92 - Java_com_sun_media_sound_MixerSequencer_nGetMasterTempo;
6.93 - Java_com_sun_media_sound_MixerSequencer_nGetSequenceMicrosecondLength;
6.94 - Java_com_sun_media_sound_MixerSequencer_nGetSequencerMicrosecondPosition;
6.95 - Java_com_sun_media_sound_MixerSequencer_nGetSequencerTickPosition;
6.96 - Java_com_sun_media_sound_MixerSequencer_nGetSequenceTickLength;
6.97 - Java_com_sun_media_sound_MixerSequencer_nGetTempoInBPM;
6.98 - Java_com_sun_media_sound_MixerSequencer_nGetTempoInMPQ;
6.99 - Java_com_sun_media_sound_MixerSequencer_nGetTrackMute;
6.100 - Java_com_sun_media_sound_MixerSequencer_nGetTrackSolo;
6.101 - Java_com_sun_media_sound_MixerSequencer_nOpenMidiSequencer;
6.102 - Java_com_sun_media_sound_MixerSequencer_nOpenRmfSequencer;
6.103 - Java_com_sun_media_sound_MixerSequencer_nPauseSequencer;
6.104 - Java_com_sun_media_sound_MixerSequencer_nResumeSequencer;
6.105 - Java_com_sun_media_sound_MixerSequencer_nSetMasterTempo;
6.106 - Java_com_sun_media_sound_MixerSequencer_nSetSequencerMicrosecondPosition;
6.107 - Java_com_sun_media_sound_MixerSequencer_nSetSequencerTickPosition;
6.108 - Java_com_sun_media_sound_MixerSequencer_nSetTempoInBPM;
6.109 - Java_com_sun_media_sound_MixerSequencer_nSetTempoInMPQ;
6.110 - Java_com_sun_media_sound_MixerSequencer_nSetTrackMute;
6.111 - Java_com_sun_media_sound_MixerSequencer_nSetTrackSolo;
6.112 - Java_com_sun_media_sound_MixerSequencer_nStartSequencer;
6.113 - Java_com_sun_media_sound_MixerSourceLine_nClose;
6.114 - Java_com_sun_media_sound_MixerSourceLine_nDrain;
6.115 - Java_com_sun_media_sound_MixerSourceLine_nFlush;
6.116 - Java_com_sun_media_sound_MixerSourceLine_nGetLevel;
6.117 - Java_com_sun_media_sound_MixerSourceLine_nGetPosition;
6.118 - Java_com_sun_media_sound_MixerSourceLine_nOpen;
6.119 - Java_com_sun_media_sound_MixerSourceLine_nPause;
6.120 - Java_com_sun_media_sound_MixerSourceLine_nResume;
6.121 - Java_com_sun_media_sound_MixerSourceLine_nSetLinearGain;
6.122 - Java_com_sun_media_sound_MixerSourceLine_nSetPan;
6.123 - Java_com_sun_media_sound_MixerSourceLine_nSetSampleRate;
6.124 - Java_com_sun_media_sound_MixerSourceLine_nStart;
6.125 - Java_com_sun_media_sound_MixerSynth_nCreateSynthesizer;
6.126 - Java_com_sun_media_sound_MixerSynth_nDestroySynthesizer;
6.127 - Java_com_sun_media_sound_MixerSynth_nGetLatency;
6.128 - Java_com_sun_media_sound_MixerSynth_nLoadInstrument;
6.129 - Java_com_sun_media_sound_MixerSynth_nRemapInstrument;
6.130 - Java_com_sun_media_sound_MixerSynth_nStartSynthesizer;
6.131 - Java_com_sun_media_sound_MixerSynth_nUnloadInstrument;
6.132 - Java_com_sun_media_sound_MixerThread_runNative;
6.133 - Java_com_sun_media_sound_SimpleInputDevice_nClose;
6.134 - Java_com_sun_media_sound_SimpleInputDevice_nDrain;
6.135 - Java_com_sun_media_sound_SimpleInputDevice_nFlush;
6.136 - Java_com_sun_media_sound_SimpleInputDevice_nGetBufferSizeInFrames;
6.137 - Java_com_sun_media_sound_SimpleInputDevice_nGetFormats;
6.138 - Java_com_sun_media_sound_SimpleInputDevice_nGetNumPorts;
6.139 - Java_com_sun_media_sound_SimpleInputDevice_nGetPortName;
6.140 - Java_com_sun_media_sound_SimpleInputDevice_nGetPosition;
6.141 - Java_com_sun_media_sound_SimpleInputDevice_nOpen;
6.142 - Java_com_sun_media_sound_SimpleInputDevice_nPause;
6.143 - Java_com_sun_media_sound_SimpleInputDevice_nResume;
6.144 - Java_com_sun_media_sound_SimpleInputDevice_nStart;
6.145 - Java_com_sun_media_sound_SimpleInputDevice_nStop;
6.146 - Java_com_sun_media_sound_SimpleInputDevice_nSupportsChannels;
6.147 - Java_com_sun_media_sound_SimpleInputDevice_nSupportsSampleRate;
6.148 - Java_com_sun_media_sound_SimpleInputDevice_nSupportsSampleSizeInBits;
6.149 - Java_com_sun_media_sound_SimpleInputDeviceProvider_nGetDescription;
6.150 - Java_com_sun_media_sound_SimpleInputDeviceProvider_nGetName;
6.151 - Java_com_sun_media_sound_SimpleInputDeviceProvider_nGetNumDevices;
6.152 - Java_com_sun_media_sound_SimpleInputDeviceProvider_nGetVendor;
6.153 - Java_com_sun_media_sound_SimpleInputDeviceProvider_nGetVersion;
6.154 - local:
6.155 - *;
6.156 -};
7.1 --- a/make/sun/javazic/tzdata/VERSION Thu Jan 29 21:46:48 2009 -0800
7.2 +++ b/make/sun/javazic/tzdata/VERSION Tue Feb 03 22:02:55 2009 -0800
7.3 @@ -21,4 +21,4 @@
7.4 # CA 95054 USA or visit www.sun.com if you need additional information or
7.5 # have any questions.
7.6 #
7.7 -tzdata2008e
7.8 +tzdata2009a
8.1 --- a/make/sun/javazic/tzdata/africa Thu Jan 29 21:46:48 2009 -0800
8.2 +++ b/make/sun/javazic/tzdata/africa Tue Feb 03 22:02:55 2009 -0800
8.3 @@ -458,11 +458,36 @@
8.4 # http://www.worldtimezone.com/dst_news/dst_news_mauritius02.html
8.5 # </a>
8.6
8.7 +# From Riad M. Hossen Ally (2008-08-03):
8.8 +# The Government of Mauritius weblink
8.9 +# <a href="http://www.gov.mu/portal/site/pmosite/menuitem.4ca0efdee47462e7440a600248a521ca/?content_id=3D4728ca68b2a5b110VgnVCM1000000a04a8c0RCRD">
8.10 +# http://www.gov.mu/portal/site/pmosite/menuitem.4ca0efdee47462e7440a600248a521ca/?content_id=3D4728ca68b2a5b110VgnVCM1000000a04a8c0RCRD
8.11 +# </a>
8.12 +# Cabinet Decision of July 18th, 2008 states as follows:
8.13 +#
8.14 +# 4. ...Cabinet has agreed to the introduction into the National Assembly
8.15 +# of the Time Bill which provides for the introduction of summer time in
8.16 +# Mauritius. The summer time period which will be of one hour ahead of
8.17 +# the standard time, will be aligned with that in Europe and the United
8.18 +# States of America. It will start at two o'clock in the morning on the
8.19 +# last Sunday of October and will end at two o'clock in the morning on
8.20 +# the last Sunday of March the following year. The summer time for the
8.21 +# year 2008 - 2009 will, therefore, be effective as from 26 October 2008
8.22 +# and end on 29 March 2009.
8.23 +
8.24 +# From Ed Maste (2008-10-07):
8.25 +# THE TIME BILL (No. XXVII of 2008) Explanatory Memorandum states the
8.26 +# beginning / ending of summer time is 2 o'clock standard time in the
8.27 +# morning of the last Sunday of October / last Sunday of March.
8.28 +# <a href="http://www.gov.mu/portal/goc/assemblysite/file/bill2708.pdf">
8.29 +# http://www.gov.mu/portal/goc/assemblysite/file/bill2708.pdf
8.30 +# </a>
8.31 +
8.32 # Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
8.33 Rule Mauritius 1982 only - Oct 10 0:00 1:00 S
8.34 Rule Mauritius 1983 only - Mar 21 0:00 0 -
8.35 -Rule Mauritius 2008 only - Oct 26 2:00s 1:00 S
8.36 -Rule Mauritius 2009 only - Mar 27 2:00s 0 -
8.37 +Rule Mauritius 2008 max - Oct lastSun 2:00s 1:00 S
8.38 +Rule Mauritius 2009 max - Mar lastSun 2:00s 0 -
8.39 # Zone NAME GMTOFF RULES FORMAT [UNTIL]
8.40 Zone Indian/Mauritius 3:50:00 - LMT 1907 # Port Louis
8.41 4:00 Mauritius MU%sT # Mauritius Time
8.42 @@ -547,7 +572,22 @@
8.43 # From Arthur David Olson (2008-05-09):
8.44 # XXX--guess that it is only Morocco for now; guess only 2008 for now.
8.45
8.46 +# From Steffen Thorsen (2008-08-27):
8.47 +# Morocco will change the clocks back on the midnight between August 31
8.48 +# and September 1. They originally planned to observe DST to near the end
8.49 +# of September:
8.50 +#
8.51 +# One article about it (in French):
8.52 +# <a href="http://www.menara.ma/fr/Actualites/Maroc/Societe/ci.retour_a_l_heure_gmt_a_partir_du_dimanche_31_aout_a_minuit_officiel_.default">
8.53 +# http://www.menara.ma/fr/Actualites/Maroc/Societe/ci.retour_a_l_heure_gmt_a_partir_du_dimanche_31_aout_a_minuit_officiel_.default
8.54 +# </a>
8.55 +#
8.56 +# We have some further details posted here:
8.57 +# <a href="http://www.timeanddate.com/news/time/morocco-ends-dst-early-2008.html">
8.58 +# http://www.timeanddate.com/news/time/morocco-ends-dst-early-2008.html
8.59 +# </a>
8.60 # RULE NAME FROM TO TYPE IN ON AT SAVE LETTER/S
8.61 +
8.62 Rule Morocco 1939 only - Sep 12 0:00 1:00 S
8.63 Rule Morocco 1939 only - Nov 19 0:00 0 -
8.64 Rule Morocco 1940 only - Feb 25 0:00 1:00 S
8.65 @@ -564,7 +604,7 @@
8.66 Rule Morocco 1978 only - Jun 1 0:00 1:00 S
8.67 Rule Morocco 1978 only - Aug 4 0:00 0 -
8.68 Rule Morocco 2008 only - Jun 1 0:00 1:00 S
8.69 -Rule Morocco 2008 only - Sep 28 0:00 0 -
8.70 +Rule Morocco 2008 only - Sep 1 0:00 0 -
8.71 # Zone NAME GMTOFF RULES FORMAT [UNTIL]
8.72 Zone Africa/Casablanca -0:30:20 - LMT 1913 Oct 26
8.73 0:00 Morocco WE%sT 1984 Mar 16
9.1 --- a/make/sun/javazic/tzdata/asia Thu Jan 29 21:46:48 2009 -0800
9.2 +++ b/make/sun/javazic/tzdata/asia Tue Feb 03 22:02:55 2009 -0800
9.3 @@ -1496,7 +1496,7 @@
9.4
9.5 # Nepal
9.6 # Zone NAME GMTOFF RULES FORMAT [UNTIL]
9.7 -Zone Asia/Katmandu 5:41:16 - LMT 1920
9.8 +Zone Asia/Kathmandu 5:41:16 - LMT 1920
9.9 5:30 - IST 1986
9.10 5:45 - NPT # Nepal Time
9.11
9.12 @@ -1563,11 +1563,24 @@
9.13 # From Arthur David Olson (2008-05-19):
9.14 # XXX--midnight transitions is a guess; 2008 only is a guess.
9.15
9.16 +# From Alexander Krivenyshev (2008-08-28):
9.17 +# Pakistan government has decided to keep the watches one-hour advanced
9.18 +# for another 2 months--plan to return to Standard Time on October 31
9.19 +# instead of August 31.
9.20 +#
9.21 +# <a href="http://www.worldtimezone.com/dst_news/dst_news_pakistan02.html">
9.22 +# http://www.worldtimezone.com/dst_news/dst_news_pakistan02.html
9.23 +# </a>
9.24 +# OR
9.25 +# <a href="http://dailymailnews.com/200808/28/news/dmbrn03.html">
9.26 +# http://dailymailnews.com/200808/28/news/dmbrn03.html
9.27 +# </a>
9.28 +
9.29 # Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
9.30 Rule Pakistan 2002 only - Apr Sun>=2 0:01 1:00 S
9.31 Rule Pakistan 2002 only - Oct Sun>=2 0:01 0 -
9.32 Rule Pakistan 2008 only - Jun 1 0:00 1:00 S
9.33 -Rule Pakistan 2008 only - Sep 1 0:00 0 -
9.34 +Rule Pakistan 2008 only - Nov 1 0:00 0 -
9.35 # Zone NAME GMTOFF RULES FORMAT [UNTIL]
9.36 Zone Asia/Karachi 4:28:12 - LMT 1907
9.37 5:30 - IST 1942 Sep
9.38 @@ -1687,6 +1700,23 @@
9.39 # For lack of better information, predict that future changes will be
9.40 # the 2nd Thursday of September at 02:00.
9.41
9.42 +# From Alexander Krivenyshev (2008-08-28):
9.43 +# Here is an article, that Mideast running on different clocks at Ramadan.
9.44 +#
9.45 +# Gaza Strip (as Egypt) ended DST at midnight Thursday (Aug 28, 2008), while
9.46 +# the West Bank will end Daylight Saving Time at midnight Sunday (Aug 31, 2008).
9.47 +#
9.48 +# <a href="http://www.guardian.co.uk/world/feedarticle/7759001">
9.49 +# http://www.guardian.co.uk/world/feedarticle/7759001
9.50 +# </a>
9.51 +# <a href="http://www.abcnews.go.com/International/wireStory?id=5676087">
9.52 +# http://www.abcnews.go.com/International/wireStory?id=5676087
9.53 +# </a>
9.54 +# or
9.55 +# <a href="http://www.worldtimezone.com/dst_news/dst_news_gazastrip01.html">
9.56 +# http://www.worldtimezone.com/dst_news/dst_news_gazastrip01.html
9.57 +# </a>
9.58 +
9.59 # The rules for Egypt are stolen from the `africa' file.
9.60 # Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
9.61 Rule EgyptAsia 1957 only - May 10 0:00 1:00 S
9.62 @@ -1702,7 +1732,8 @@
9.63 Rule Palestine 2005 only - Oct 4 2:00 0 -
9.64 Rule Palestine 2006 max - Apr 1 0:00 1:00 S
9.65 Rule Palestine 2006 only - Sep 22 0:00 0 -
9.66 -Rule Palestine 2007 max - Sep Thu>=8 2:00 0 -
9.67 +Rule Palestine 2007 only - Sep Thu>=8 2:00 0 -
9.68 +Rule Palestine 2008 max - Aug lastThu 2:00 0 -
9.69
9.70 # Zone NAME GMTOFF RULES FORMAT [UNTIL]
9.71 Zone Asia/Gaza 2:17:52 - LMT 1900 Oct
9.72 @@ -1948,8 +1979,20 @@
9.73 # compilers can't handle or having multiple Rules (a la Israel).
9.74 # For now, use "Apr Fri>=1", and go with IATA on a uniform Sep 30 end.
9.75
9.76 +# From Steffen Thorsen (2008-10-07):
9.77 +# Syria has now officially decided to end DST on 2008-11-01 this year,
9.78 +# according to the following article in the Syrian Arab News Agency (SANA).
9.79 +#
9.80 +# The article is in Arabic, and seems to tell that they will go back to
9.81 +# winter time on 2008-11-01 at 00:00 local daylight time (delaying/setting
9.82 +# clocks back 60 minutes).
9.83 +#
9.84 +# <a href="http://sana.sy/ara/2/2008/10/07/195459.htm">
9.85 +# http://sana.sy/ara/2/2008/10/07/195459.htm
9.86 +# </a>
9.87 +
9.88 Rule Syria 2008 max - Apr Fri>=1 0:00 1:00 S
9.89 -Rule Syria 2008 max - Oct 1 0:00 0 -
9.90 +Rule Syria 2008 max - Nov 1 0:00 0 -
9.91
9.92 # Zone NAME GMTOFF RULES FORMAT [UNTIL]
9.93 Zone Asia/Damascus 2:25:12 - LMT 1920 # Dimashq
10.1 --- a/make/sun/javazic/tzdata/backward Thu Jan 29 21:46:48 2009 -0800
10.2 +++ b/make/sun/javazic/tzdata/backward Tue Feb 03 22:02:55 2009 -0800
10.3 @@ -46,6 +46,7 @@
10.4 Link Asia/Ashgabat Asia/Ashkhabad
10.5 Link Asia/Chongqing Asia/Chungking
10.6 Link Asia/Dhaka Asia/Dacca
10.7 +Link Asia/Kathmandu Asia/Katmandu
10.8 Link Asia/Kolkata Asia/Calcutta
10.9 Link Asia/Macau Asia/Macao
10.10 Link Asia/Jerusalem Asia/Tel_Aviv
11.1 --- a/make/sun/javazic/tzdata/europe Thu Jan 29 21:46:48 2009 -0800
11.2 +++ b/make/sun/javazic/tzdata/europe Tue Feb 03 22:02:55 2009 -0800
11.3 @@ -2335,11 +2335,64 @@
11.4 # mean time in preference to apparent time -- Geneva from 1780 ....
11.5 # Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
11.6 # From Whitman (who writes ``Midnight?''):
11.7 -Rule Swiss 1940 only - Nov 2 0:00 1:00 S
11.8 -Rule Swiss 1940 only - Dec 31 0:00 0 -
11.9 +# Rule Swiss 1940 only - Nov 2 0:00 1:00 S
11.10 +# Rule Swiss 1940 only - Dec 31 0:00 0 -
11.11 # From Shanks & Pottenger:
11.12 -Rule Swiss 1941 1942 - May Sun>=1 2:00 1:00 S
11.13 -Rule Swiss 1941 1942 - Oct Sun>=1 0:00 0 -
11.14 +# Rule Swiss 1941 1942 - May Sun>=1 2:00 1:00 S
11.15 +# Rule Swiss 1941 1942 - Oct Sun>=1 0:00 0 -
11.16 +
11.17 +# From Alois Treindl (2008-12-17):
11.18 +# I have researched the DST usage in Switzerland during the 1940ies.
11.19 +#
11.20 +# As I wrote in an earlier message, I suspected the current tzdata values
11.21 +# to be wrong. This is now verified.
11.22 +#
11.23 +# I have found copies of the original ruling by the Swiss Federal
11.24 +# government, in 'Eidgen[o]ssische Gesetzessammlung 1941 and 1942' (Swiss
11.25 +# federal law collection)...
11.26 +#
11.27 +# DST began on Monday 5 May 1941, 1:00 am by shifting the clocks to 2:00 am
11.28 +# DST ended on Monday 6 Oct 1941, 2:00 am by shifting the clocks to 1:00 am.
11.29 +#
11.30 +# DST began on Monday, 4 May 1942 at 01:00 am
11.31 +# DST ended on Monday, 5 Oct 1942 at 02:00 am
11.32 +#
11.33 +# There was no DST in 1940, I have checked the law collection carefully.
11.34 +# It is also indicated by the fact that the 1942 entry in the law
11.35 +# collection points back to 1941 as a reference, but no reference to any
11.36 +# other years are made.
11.37 +#
11.38 +# Newspaper articles I have read in the archives on 6 May 1941 reported
11.39 +# about the introduction of DST (Sommerzeit in German) during the previous
11.40 +# night as an absolute novelty, because this was the first time that such
11.41 +# a thing had happened in Switzerland.
11.42 +#
11.43 +# I have also checked 1916, because one book source (Gabriel, Traite de
11.44 +# l'heure dans le monde) claims that Switzerland had DST in 1916. This is
11.45 +# false, no official document could be found. Probably Gabriel got misled
11.46 +# by references to Germany, which introduced DST in 1916 for the first time.
11.47 +#
11.48 +# The tzdata rules for Switzerland must be changed to:
11.49 +# Rule Swiss 1941 1942 - May Mon>=1 1:00 1:00 S
11.50 +# Rule Swiss 1941 1942 - Oct Mon>=1 2:00 0 -
11.51 +#
11.52 +# The 1940 rules must be deleted.
11.53 +#
11.54 +# One further detail for Switzerland, which is probably out of scope for
11.55 +# most users of tzdata:
11.56 +# The zone file
11.57 +# Zone Europe/Zurich 0:34:08 - LMT 1848 Sep 12
11.58 +# 0:29:44 - BMT 1894 Jun #Bern Mean Time
11.59 +# 1:00 Swiss CE%sT 1981
11.60 +# 1:00 EU CE%sT
11.61 +# describes all of Switzerland correctly, with the exception of
11.62 +# the Cantone Geneve (Geneva, Genf). Between 1848 and 1894 Geneve did not
11.63 +# follow Bern Mean Time but kept its own local mean time.
11.64 +# To represent this, an extra zone would be needed.
11.65 +
11.66 +# Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
11.67 +Rule Swiss 1941 1942 - May Mon>=1 1:00 1:00 S
11.68 +Rule Swiss 1941 1942 - Oct Mon>=1 2:00 0 -
11.69 # Zone NAME GMTOFF RULES FORMAT [UNTIL]
11.70 Zone Europe/Zurich 0:34:08 - LMT 1848 Sep 12
11.71 0:29:44 - BMT 1894 Jun # Bern Mean Time
11.72 @@ -2375,6 +2428,27 @@
11.73 # (on a non-government server though) describing dates between 2002 and 2006:
11.74 # http://www.alomaliye.com/bkk_2002_3769.htm
11.75
11.76 +# From Sue Williams (2008-08-11):
11.77 +# I spotted this news article about a potential change in Turkey.
11.78 +#
11.79 +# <a href="http://www.hurriyet.com.tr/english/domestic/9626174.asp?scr=1">
11.80 +# http://www.hurriyet.com.tr/english/domestic/9626174.asp?scr=1
11.81 +# </a>
11.82 +
11.83 +# From Sue Williams (2008-08-20):
11.84 +# This article says that around the end of March 2011, Turkey wants to
11.85 +# adjust the clocks forward by 1/2 hour and stay that way permanently.
11.86 +# The article indicates that this is a change in timezone offset in addition
11.87 +# to stopping observance of DST.
11.88 +# This proposal has not yet been approved.
11.89 +#
11.90 +# Read more here...
11.91 +#
11.92 +# Turkey to abandon daylight saving time in 2011
11.93 +# <a href="http://www.turkishdailynews.com.tr/article.php?enewsid=112989">
11.94 +# http://www.turkishdailynews.com.tr/article.php?enewsid=112989
11.95 +# </a>
11.96 +
11.97 # Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
11.98 Rule Turkey 1916 only - May 1 0:00 1:00 S
11.99 Rule Turkey 1916 only - Oct 1 0:00 0 -
12.1 --- a/make/sun/javazic/tzdata/northamerica Thu Jan 29 21:46:48 2009 -0800
12.2 +++ b/make/sun/javazic/tzdata/northamerica Tue Feb 03 22:02:55 2009 -0800
12.3 @@ -1764,9 +1764,13 @@
12.4 # The individual that answered the phone confirmed that the clocks did not
12.5 # move at the end of daylight saving on October 29/2006. He also told me that
12.6 # the clocks did not move this past weekend (March 11/2007)....
12.7 -#
12.8 -# America/Resolute should use the "Canada" Rule up to October 29/2006.
12.9 -# After that it should be fixed on Eastern Standard Time until further notice.
12.10 +
12.11 +# From Chris Walton (2008-11-13):
12.12 +# ...the residents of Resolute believe that they are changing "time zones"
12.13 +# twice a year. In winter months, local time is qualified with "Eastern
12.14 +# Time" which is really "Eastern Standard Time (UTC-5)". In summer
12.15 +# months, local time is qualified with "Central Time" which is really
12.16 +# "Central Daylight Time (UTC-5)"...
12.17
12.18 # Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
12.19 Rule NT_YK 1918 only - Apr 14 2:00 1:00 D
12.20 @@ -1794,11 +1798,14 @@
12.21 -6:00 Canada C%sT 2000 Oct 29 2:00
12.22 -5:00 Canada E%sT
12.23 # aka Qausuittuq
12.24 +# Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
12.25 +Rule Resolute 2006 max - Nov Sun>=1 2:00 0 ES
12.26 +Rule Resolute 2007 max - Mar Sun>=8 2:00 0 CD
12.27 Zone America/Resolute 0 - zzz 1947 Aug 31 # Resolute founded
12.28 -6:00 NT_YK C%sT 2000 Oct 29 2:00
12.29 -5:00 - EST 2001 Apr 1 3:00
12.30 -6:00 Canada C%sT 2006 Oct 29 2:00
12.31 - -5:00 - EST
12.32 + -5:00 Resolute %sT
12.33 # aka Kangiqiniq
12.34 Zone America/Rankin_Inlet 0 - zzz 1957 # Rankin Inlet founded
12.35 -6:00 NT_YK C%sT 2000 Oct 29 2:00
12.36 @@ -2302,7 +2309,7 @@
12.37 Rule Cuba 1997 only - Oct 12 0:00s 0 S
12.38 Rule Cuba 1998 1999 - Mar lastSun 0:00s 1:00 D
12.39 Rule Cuba 1998 2003 - Oct lastSun 0:00s 0 S
12.40 -Rule Cuba 2000 2006 - Apr Sun>=1 0:00s 1:00 D
12.41 +Rule Cuba 2000 2004 - Apr Sun>=1 0:00s 1:00 D
12.42 Rule Cuba 2006 max - Oct lastSun 0:00s 0 S
12.43 Rule Cuba 2007 only - Mar Sun>=8 0:00s 1:00 D
12.44 Rule Cuba 2008 max - Mar Sun>=15 0:00s 1:00 D
13.1 --- a/make/sun/javazic/tzdata/southamerica Thu Jan 29 21:46:48 2009 -0800
13.2 +++ b/make/sun/javazic/tzdata/southamerica Tue Feb 03 22:02:55 2009 -0800
13.3 @@ -186,9 +186,58 @@
13.4 # From Paul Eggert (2007-12-22):
13.5 # For dates after mid-2008, the following rules are my guesses and
13.6 # are quite possibly wrong, but are more likely than no DST at all.
13.7 +
13.8 +# From Alexander Krivenyshev (2008-09-05):
13.9 +# As per message from Carlos Alberto Fonseca Arauz (Nicaragua),
13.10 +# Argentina will start DST on Sunday October 19, 2008.
13.11 +#
13.12 +# <a href="http://www.worldtimezone.com/dst_news/dst_news_argentina03.html">
13.13 +# http://www.worldtimezone.com/dst_news/dst_news_argentina03.html
13.14 +# </a>
13.15 +# OR
13.16 +# <a href="http://www.impulsobaires.com.ar/nota.php?id=57832 (in spanish)">
13.17 +# http://www.impulsobaires.com.ar/nota.php?id=57832 (in spanish)
13.18 +# </a>
13.19 +
13.20 +# From Rodrigo Severo (2008-10-06):
13.21 +# Here is some info available at a Gentoo bug related to TZ on Argentina's DST:
13.22 +# ...
13.23 +# ------- Comment #1 from [jmdocile] 2008-10-06 16:28 0000 -------
13.24 +# Hi, there is a problem with timezone-data-2008e and maybe with
13.25 +# timezone-data-2008f
13.26 +# Argentinian law [Number] 25.155 is no longer valid.
13.27 +# <a href="http://www.infoleg.gov.ar/infolegInternet/anexos/60000-64999/60036/norma.htm">
13.28 +# http://www.infoleg.gov.ar/infolegInternet/anexos/60000-64999/60036/norma.htm
13.29 +# </a>
13.30 +# The new one is law [Number] 26.350
13.31 +# <a href="http://www.infoleg.gov.ar/infolegInternet/anexos/135000-139999/136191/norma.htm">
13.32 +# http://www.infoleg.gov.ar/infolegInternet/anexos/135000-139999/136191/norma.htm
13.33 +# </a>
13.34 +# So there is no summer time in Argentina for now.
13.35 +
13.36 +# From Mariano Absatz (2008-10-20):
13.37 +# Decree 1693/2008 applies Law 26.350 for the summer 2008/2009 establishing DST in Argentina
13.38 +# From 2008-10-19 until 2009-03-15
13.39 +# <a href="http://www.boletinoficial.gov.ar/Bora.Portal/CustomControls/PdfContent.aspx?fp=16102008&pi=3&pf=4&s=0&sec=01">
13.40 +# http://www.boletinoficial.gov.ar/Bora.Portal/CustomControls/PdfContent.aspx?fp=16102008&pi=3&pf=4&s=0&sec=01
13.41 +# </a>
13.42 +#
13.43 +# Decree 1705/2008 excepting 12 Provinces from applying DST in the summer 2008/2009:
13.44 +# Catamarca, La Rioja, Mendoza, Salta, San Juan, San Luis, La Pampa, Neuquen, Rio Negro, Chubut, Santa Cruz
13.45 +# and Tierra del Fuego
13.46 +# <a href="http://www.boletinoficial.gov.ar/Bora.Portal/CustomControls/PdfContent.aspx?fp=17102008&pi=1&pf=1&s=0&sec=01">
13.47 +# http://www.boletinoficial.gov.ar/Bora.Portal/CustomControls/PdfContent.aspx?fp=17102008&pi=1&pf=1&s=0&sec=01
13.48 +# </a>
13.49 +#
13.50 +# Press release 235 dated Saturday October 18th, from the Government of the Province of Jujuy saying
13.51 +# it will not apply DST either (even when it was not included in Decree 1705/2008)
13.52 +# <a href="http://www.jujuy.gov.ar/index2/partes_prensa/18_10_08/235-181008.doc">
13.53 +# http://www.jujuy.gov.ar/index2/partes_prensa/18_10_08/235-181008.doc
13.54 +# </a>
13.55 +
13.56 Rule Arg 2007 only - Dec 30 0:00 1:00 S
13.57 Rule Arg 2008 max - Mar Sun>=15 0:00 0 -
13.58 -Rule Arg 2008 max - Oct Sun>=1 0:00 1:00 S
13.59 +Rule Arg 2008 max - Oct Sun>=15 0:00 1:00 S
13.60
13.61 # From Mariano Absatz (2004-05-21):
13.62 # Today it was officially published that the Province of Mendoza is changing
13.63 @@ -336,9 +385,8 @@
13.64 -4:00 Arg AR%sT 2000 Mar 3
13.65 -3:00 Arg AR%sT
13.66 #
13.67 -# Santa Fe (SF), Entre Rios (ER), Corrientes (CN), Misiones (MN), Chaco (CC),
13.68 -# Formosa (FM), Salta (SA), Santiago del Estero (SE), Cordoba (CB),
13.69 -# La Pampa (LP), Neuquen (NQ), Rio Negro (RN)
13.70 +# Cordoba (CB), Santa Fe (SF), Entre Rios (ER), Corrientes (CN), Misiones (MN),
13.71 +# Chaco (CC), Formosa (FM), Santiago del Estero (SE)
13.72 #
13.73 # Shanks & Pottenger also make the following claims, which we haven't verified:
13.74 # - Formosa switched to -3:00 on 1991-01-07.
13.75 @@ -357,6 +405,18 @@
13.76 -4:00 Arg AR%sT 2000 Mar 3
13.77 -3:00 Arg AR%sT
13.78 #
13.79 +# Salta (SA), La Pampa (LP), Neuquen (NQ), Rio Negro (RN)
13.80 +Zone America/Argentina/Salta -4:21:40 - LMT 1894 Oct 31
13.81 + -4:16:48 - CMT 1920 May
13.82 + -4:00 - ART 1930 Dec
13.83 + -4:00 Arg AR%sT 1969 Oct 5
13.84 + -3:00 Arg AR%sT 1991 Mar 3
13.85 + -4:00 - WART 1991 Oct 20
13.86 + -3:00 Arg AR%sT 1999 Oct 3
13.87 + -4:00 Arg AR%sT 2000 Mar 3
13.88 + -3:00 Arg AR%sT 2008 Oct 18
13.89 + -3:00 - ART
13.90 +#
13.91 # Tucuman (TM)
13.92 Zone America/Argentina/Tucuman -4:20:52 - LMT 1894 Oct 31
13.93 -4:16:48 - CMT 1920 May
13.94 @@ -381,7 +441,8 @@
13.95 -4:00 Arg AR%sT 2000 Mar 3
13.96 -3:00 - ART 2004 Jun 1
13.97 -4:00 - WART 2004 Jun 20
13.98 - -3:00 Arg AR%sT
13.99 + -3:00 Arg AR%sT 2008 Oct 18
13.100 + -3:00 - ART
13.101 #
13.102 # San Juan (SJ)
13.103 Zone America/Argentina/San_Juan -4:34:04 - LMT 1894 Oct 31
13.104 @@ -394,7 +455,8 @@
13.105 -4:00 Arg AR%sT 2000 Mar 3
13.106 -3:00 - ART 2004 May 31
13.107 -4:00 - WART 2004 Jul 25
13.108 - -3:00 Arg AR%sT
13.109 + -3:00 Arg AR%sT 2008 Oct 18
13.110 + -3:00 - ART
13.111 #
13.112 # Jujuy (JY)
13.113 Zone America/Argentina/Jujuy -4:21:12 - LMT 1894 Oct 31
13.114 @@ -408,7 +470,8 @@
13.115 -3:00 1:00 ARST 1992
13.116 -3:00 Arg AR%sT 1999 Oct 3
13.117 -4:00 Arg AR%sT 2000 Mar 3
13.118 - -3:00 Arg AR%sT
13.119 + -3:00 Arg AR%sT 2008 Oct 18
13.120 + -3:00 - ART
13.121 #
13.122 # Catamarca (CT), Chubut (CH)
13.123 Zone America/Argentina/Catamarca -4:23:08 - LMT 1894 Oct 31
13.124 @@ -421,7 +484,8 @@
13.125 -4:00 Arg AR%sT 2000 Mar 3
13.126 -3:00 - ART 2004 Jun 1
13.127 -4:00 - WART 2004 Jun 20
13.128 - -3:00 Arg AR%sT
13.129 + -3:00 Arg AR%sT 2008 Oct 18
13.130 + -3:00 - ART
13.131 #
13.132 # Mendoza (MZ)
13.133 Zone America/Argentina/Mendoza -4:35:16 - LMT 1894 Oct 31
13.134 @@ -438,7 +502,8 @@
13.135 -4:00 Arg AR%sT 2000 Mar 3
13.136 -3:00 - ART 2004 May 23
13.137 -4:00 - WART 2004 Sep 26
13.138 - -3:00 Arg AR%sT
13.139 + -3:00 Arg AR%sT 2008 Oct 18
13.140 + -3:00 - ART
13.141 #
13.142 # San Luis (SL)
13.143 Zone America/Argentina/San_Luis -4:25:24 - LMT 1894 Oct 31
13.144 @@ -466,7 +531,8 @@
13.145 -4:00 Arg AR%sT 2000 Mar 3
13.146 -3:00 - ART 2004 Jun 1
13.147 -4:00 - WART 2004 Jun 20
13.148 - -3:00 Arg AR%sT
13.149 + -3:00 Arg AR%sT 2008 Oct 18
13.150 + -3:00 - ART
13.151 #
13.152 # Tierra del Fuego, Antartida e Islas del Atlantico Sur (TF)
13.153 Zone America/Argentina/Ushuaia -4:33:12 - LMT 1894 Oct 31
13.154 @@ -477,7 +543,8 @@
13.155 -4:00 Arg AR%sT 2000 Mar 3
13.156 -3:00 - ART 2004 May 30
13.157 -4:00 - WART 2004 Jun 20
13.158 - -3:00 Arg AR%sT
13.159 + -3:00 Arg AR%sT 2008 Oct 18
13.160 + -3:00 - ART
13.161
13.162 # Aruba
13.163 # Zone NAME GMTOFF RULES FORMAT [UNTIL]
13.164 @@ -613,6 +680,36 @@
13.165 # Decretos sobre o Horario de Verao no Brasil
13.166 # </a>.
13.167
13.168 +# From Steffen Thorsen (2008-08-29):
13.169 +# As announced by the government and many newspapers in Brazil late
13.170 +# yesterday, Brazil will start DST on 2008-10-19 (need to change rule) and
13.171 +# it will end on 2009-02-15 (current rule for Brazil is fine). Based on
13.172 +# past years experience with the elections, there was a good chance that
13.173 +# the start was postponed to November, but it did not happen this year.
13.174 +#
13.175 +# It has not yet been posted to http://pcdsh01.on.br/DecHV.html
13.176 +#
13.177 +# An official page about it:
13.178 +# <a href="http://www.mme.gov.br/site/news/detail.do?newsId=16722">
13.179 +# http://www.mme.gov.br/site/news/detail.do?newsId=16722
13.180 +# </a>
13.181 +# Note that this link does not always work directly, but must be accessed
13.182 +# by going to
13.183 +# <a href="http://www.mme.gov.br/first">
13.184 +# http://www.mme.gov.br/first
13.185 +# </a>
13.186 +#
13.187 +# One example link that works directly:
13.188 +# <a href="http://jornale.com.br/index.php?option=com_content&task=view&id=13530&Itemid=54">
13.189 +# http://jornale.com.br/index.php?option=com_content&task=view&id=13530&Itemid=54
13.190 +# (Portuguese)
13.191 +# </a>
13.192 +#
13.193 +# We have a written a short article about it as well:
13.194 +# <a href="http://www.timeanddate.com/news/time/brazil-dst-2008-2009.html">
13.195 +# http://www.timeanddate.com/news/time/brazil-dst-2008-2009.html
13.196 +# </a>
13.197 +
13.198 # Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
13.199 # Decree <a href="http://pcdsh01.on.br/HV20466.htm">20,466</a> (1931-10-01)
13.200 # Decree <a href="http://pcdsh01.on.br/HV21896.htm">21,896</a> (1932-01-10)
13.201 @@ -746,12 +843,34 @@
13.202 Rule Brazil 2007 only - Feb 25 0:00 0 -
13.203 # Decree <a href="http://pcdsh01.on.br/DecHV6212.gif">6,212</a> (2007-09-26),
13.204 # adopted by the same states as before.
13.205 -Rule Brazil 2007 max - Oct Sun>=8 0:00 1:00 S
13.206 -Rule Brazil 2008 max - Feb Sun>=15 0:00 0 -
13.207 +Rule Brazil 2007 only - Oct Sun>=8 0:00 1:00 S
13.208 +# From Frederico A. C. Neves (2008-09-10):
13.209 +# Acording to this decree
13.210 +# <a href="http://www.planalto.gov.br/ccivil_03/_Ato2007-2010/2008/Decreto/D6558.htm">
13.211 +# http://www.planalto.gov.br/ccivil_03/_Ato2007-2010/2008/Decreto/D6558.htm
13.212 +# </a>
13.213 +# [t]he DST period in Brazil now on will be from the 3rd Oct Sunday to the
13.214 +# 3rd Feb Sunday. There is an exception on the return date when this is
13.215 +# the Carnival Sunday then the return date will be the next Sunday...
13.216 +Rule Brazil 2008 max - Oct Sun>=15 0:00 1:00 S
13.217 +Rule Brazil 2008 2011 - Feb Sun>=15 0:00 0 -
13.218 +Rule Brazil 2012 only - Feb Sun>=22 0:00 0 -
13.219 +Rule Brazil 2013 2014 - Feb Sun>=15 0:00 0 -
13.220 +Rule Brazil 2015 only - Feb Sun>=22 0:00 0 -
13.221 +Rule Brazil 2016 2022 - Feb Sun>=15 0:00 0 -
13.222 +Rule Brazil 2023 only - Feb Sun>=22 0:00 0 -
13.223 +Rule Brazil 2024 2025 - Feb Sun>=15 0:00 0 -
13.224 +Rule Brazil 2026 only - Feb Sun>=22 0:00 0 -
13.225 +Rule Brazil 2027 2033 - Feb Sun>=15 0:00 0 -
13.226 +Rule Brazil 2034 only - Feb Sun>=22 0:00 0 -
13.227 +Rule Brazil 2035 2036 - Feb Sun>=15 0:00 0 -
13.228 +Rule Brazil 2037 only - Feb Sun>=22 0:00 0 -
13.229 +# From Arthur David Olson (2008-09-29):
13.230 +# The next is wrong in some years but is better than nothing.
13.231 +Rule Brazil 2038 max - Feb Sun>=15 0:00 0 -
13.232 +
13.233 # The latest ruleset listed above says that the following states observe DST:
13.234 # DF, ES, GO, MG, MS, MT, PR, RJ, RS, SC, SP.
13.235 -# For dates after mid-2008, the above rules with TO="max" are guesses
13.236 -# and are quite possibly wrong, but are more likely than no DST at all.
13.237
13.238 # Zone NAME GMTOFF RULES FORMAT [UNTIL]
13.239 #
14.1 --- a/make/sun/javazic/tzdata/zone.tab Thu Jan 29 21:46:48 2009 -0800
14.2 +++ b/make/sun/javazic/tzdata/zone.tab Tue Feb 03 22:02:55 2009 -0800
14.3 @@ -64,14 +64,15 @@
14.4 AQ -6640+14001 Antarctica/DumontDUrville Dumont-d'Urville Station, Terre Adelie
14.5 AQ -690022+0393524 Antarctica/Syowa Syowa Station, E Ongul I
14.6 AR -3436-05827 America/Argentina/Buenos_Aires Buenos Aires (BA, CF)
14.7 -AR -3124-06411 America/Argentina/Cordoba most locations (CB, CC, CN, ER, FM, LP, MN, NQ, RN, SA, SE, SF)
14.8 -AR -3319-06621 America/Argentina/San_Luis San Luis (SL)
14.9 +AR -3124-06411 America/Argentina/Cordoba most locations (CB, CC, CN, ER, FM, MN, SE, SF)
14.10 +AR -2447-06525 America/Argentina/Salta (SA, LP, NQ, RN)
14.11 AR -2411-06518 America/Argentina/Jujuy Jujuy (JY)
14.12 AR -2649-06513 America/Argentina/Tucuman Tucuman (TM)
14.13 AR -2828-06547 America/Argentina/Catamarca Catamarca (CT), Chubut (CH)
14.14 AR -2926-06651 America/Argentina/La_Rioja La Rioja (LR)
14.15 AR -3132-06831 America/Argentina/San_Juan San Juan (SJ)
14.16 AR -3253-06849 America/Argentina/Mendoza Mendoza (MZ)
14.17 +AR -3319-06621 America/Argentina/San_Luis San Luis (SL)
14.18 AR -5138-06913 America/Argentina/Rio_Gallegos Santa Cruz (SC)
14.19 AR -5448-06818 America/Argentina/Ushuaia Tierra del Fuego (TF)
14.20 AS -1416-17042 Pacific/Pago_Pago
14.21 @@ -137,7 +138,7 @@
14.22 CA +4823-08915 America/Thunder_Bay Eastern Time - Thunder Bay, Ontario
14.23 CA +6344-06828 America/Iqaluit Eastern Time - east Nunavut - most locations
14.24 CA +6608-06544 America/Pangnirtung Eastern Time - Pangnirtung, Nunavut
14.25 -CA +744144-0944945 America/Resolute Eastern Time - Resolute, Nunavut
14.26 +CA +744144-0944945 America/Resolute Eastern Standard Time - Resolute, Nunavut
14.27 CA +484531-0913718 America/Atikokan Eastern Standard Time - Atikokan, Ontario and Southampton I, Nunavut
14.28 CA +624900-0920459 America/Rankin_Inlet Central Time - central Nunavut
14.29 CA +4953-09709 America/Winnipeg Central Time - Manitoba & west Ontario
14.30 @@ -313,9 +314,9 @@
14.31 NI +1209-08617 America/Managua
14.32 NL +5222+00454 Europe/Amsterdam
14.33 NO +5955+01045 Europe/Oslo
14.34 -NP +2743+08519 Asia/Katmandu
14.35 +NP +2743+08519 Asia/Kathmandu
14.36 NR -0031+16655 Pacific/Nauru
14.37 -NU -1901+16955 Pacific/Niue
14.38 +NU -1901-16955 Pacific/Niue
14.39 NZ -3652+17446 Pacific/Auckland most locations
14.40 NZ -4357-17633 Pacific/Chatham Chatham Islands
14.41 OM +2336+05835 Asia/Muscat
14.42 @@ -406,13 +407,13 @@
14.43 US +364947-0845057 America/Kentucky/Monticello Eastern Time - Kentucky - Wayne County
14.44 US +394606-0860929 America/Indiana/Indianapolis Eastern Time - Indiana - most locations
14.45 US +384038-0873143 America/Indiana/Vincennes Eastern Time - Indiana - Daviess, Dubois, Knox & Martin Counties
14.46 -US +411745-0863730 America/Indiana/Knox Eastern Time - Indiana - Starke County
14.47 US +410305-0863611 America/Indiana/Winamac Eastern Time - Indiana - Pulaski County
14.48 US +382232-0862041 America/Indiana/Marengo Eastern Time - Indiana - Crawford County
14.49 +US +382931-0871643 America/Indiana/Petersburg Eastern Time - Indiana - Pike County
14.50 US +384452-0850402 America/Indiana/Vevay Eastern Time - Indiana - Switzerland County
14.51 US +415100-0873900 America/Chicago Central Time
14.52 US +375711-0864541 America/Indiana/Tell_City Central Time - Indiana - Perry County
14.53 -US +382931-0871643 America/Indiana/Petersburg Central Time - Indiana - Pike County
14.54 +US +411745-0863730 America/Indiana/Knox Central Time - Indiana - Starke County
14.55 US +450628-0873651 America/Menominee Central Time - Michigan - Dickinson, Gogebic, Iron & Menominee Counties
14.56 US +470659-1011757 America/North_Dakota/Center Central Time - North Dakota - Oliver County
14.57 US +465042-1012439 America/North_Dakota/New_Salem Central Time - North Dakota - Morton County (except Mandan area)
15.1 --- a/src/share/classes/com/sun/beans/ObjectHandler.java Thu Jan 29 21:46:48 2009 -0800
15.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
15.3 @@ -1,479 +0,0 @@
15.4 -/*
15.5 - * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
15.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
15.7 - *
15.8 - * This code is free software; you can redistribute it and/or modify it
15.9 - * under the terms of the GNU General Public License version 2 only, as
15.10 - * published by the Free Software Foundation. Sun designates this
15.11 - * particular file as subject to the "Classpath" exception as provided
15.12 - * by Sun in the LICENSE file that accompanied this code.
15.13 - *
15.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
15.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15.17 - * version 2 for more details (a copy is included in the LICENSE file that
15.18 - * accompanied this code).
15.19 - *
15.20 - * You should have received a copy of the GNU General Public License version
15.21 - * 2 along with this work; if not, write to the Free Software Foundation,
15.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
15.23 - *
15.24 - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
15.25 - * CA 95054 USA or visit www.sun.com if you need additional information or
15.26 - * have any questions.
15.27 - */
15.28 -
15.29 -package com.sun.beans;
15.30 -
15.31 -import com.sun.beans.finder.ClassFinder;
15.32 -
15.33 -import java.beans.*;
15.34 -import java.util.*;
15.35 -
15.36 -import org.xml.sax.*;
15.37 -
15.38 -import static java.util.Locale.ENGLISH;
15.39 -
15.40 -/**
15.41 - * <b>WARNING</b>: This class is an implementation detail and only meant
15.42 - * for use within the core platform. You should NOT depend upon it! This
15.43 - * API may change drastically between dot dot release, and it may even be
15.44 - * removed.
15.45 - *
15.46 - * @see java.beans.XMLEncoder
15.47 - * @see java.io.ObjectInputStream
15.48 - *
15.49 - * @since 1.4
15.50 - *
15.51 - * @author Philip Milne
15.52 - */
15.53 -public class ObjectHandler extends HandlerBase {
15.54 -
15.55 - public static Class typeNameToClass(String typeName) {
15.56 - typeName = typeName.intern();
15.57 - if (typeName == "boolean") return Boolean.class;
15.58 - if (typeName == "byte") return Byte.class;
15.59 - if (typeName == "char") return Character.class;
15.60 - if (typeName == "short") return Short.class;
15.61 - if (typeName == "int") return Integer.class;
15.62 - if (typeName == "long") return Long.class;
15.63 - if (typeName == "float") return Float.class;
15.64 - if (typeName == "double") return Double.class;
15.65 - if (typeName == "void") return Void.class;
15.66 - return null;
15.67 - }
15.68 -
15.69 - public static Class typeNameToPrimitiveClass(String typeName) {
15.70 - typeName = typeName.intern();
15.71 - if (typeName == "boolean") return boolean.class;
15.72 - if (typeName == "byte") return byte.class;
15.73 - if (typeName == "char") return char.class;
15.74 - if (typeName == "short") return short.class;
15.75 - if (typeName == "int") return int.class;
15.76 - if (typeName == "long") return long.class;
15.77 - if (typeName == "float") return float.class;
15.78 - if (typeName == "double") return double.class;
15.79 - if (typeName == "void") return void.class;
15.80 - return null;
15.81 - }
15.82 -
15.83 - /**
15.84 - * Returns the <code>Class</code> object associated with
15.85 - * the class or interface with the given string name,
15.86 - * using the default class loader.
15.87 - *
15.88 - * @param name fully qualified name of the desired class
15.89 - * @param cl class loader from which the class must be loaded
15.90 - * @return class object representing the desired class
15.91 - *
15.92 - * @exception ClassNotFoundException if the class cannot be located
15.93 - * by the specified class loader
15.94 - *
15.95 - * @deprecated As of JDK version 7, replaced by
15.96 - * {@link ClassFinder#resolveClass(String)}.
15.97 - */
15.98 - @Deprecated
15.99 - public static Class classForName(String name) throws ClassNotFoundException {
15.100 - return ClassFinder.resolveClass(name);
15.101 - }
15.102 -
15.103 - /**
15.104 - * Returns the <code>Class</code> object associated with
15.105 - * the class or interface with the given string name,
15.106 - * using the given class loader.
15.107 - *
15.108 - * @param name fully qualified name of the desired class
15.109 - * @param cl class loader from which the class must be loaded
15.110 - * @return class object representing the desired class
15.111 - *
15.112 - * @exception ClassNotFoundException if the class cannot be located
15.113 - * by the specified class loader
15.114 - *
15.115 - * @deprecated As of JDK version 7, replaced by
15.116 - * {@link ClassFinder#resolveClass(String,ClassLoader)}.
15.117 - */
15.118 - @Deprecated
15.119 - public static Class classForName(String name, ClassLoader cl)
15.120 - throws ClassNotFoundException {
15.121 - return ClassFinder.resolveClass(name, cl);
15.122 - }
15.123 -
15.124 - private Hashtable environment;
15.125 - private Vector expStack;
15.126 - private StringBuffer chars;
15.127 - private XMLDecoder is;
15.128 - private ClassLoader ldr;
15.129 - private int itemsRead = 0;
15.130 - private boolean isString;
15.131 -
15.132 - public ObjectHandler() {
15.133 - environment = new Hashtable();
15.134 - expStack = new Vector();
15.135 - chars = new StringBuffer();
15.136 - }
15.137 -
15.138 - public ObjectHandler(XMLDecoder is) {
15.139 - this();
15.140 - this.is = is;
15.141 - }
15.142 -
15.143 - /* loader can be null */
15.144 - public ObjectHandler(XMLDecoder is, ClassLoader loader) {
15.145 - this(is);
15.146 - this.ldr = loader;
15.147 - }
15.148 -
15.149 -
15.150 - public void reset() {
15.151 - expStack.clear();
15.152 - chars.setLength(0);
15.153 - MutableExpression e = new MutableExpression();
15.154 - e.setTarget(classForName2("java.lang.Object"));
15.155 - e.setMethodName("null");
15.156 - expStack.add(e);
15.157 - }
15.158 -
15.159 - private Object getValue(Expression exp) {
15.160 - try {
15.161 - return exp.getValue();
15.162 - }
15.163 - catch (Exception e) {
15.164 - if (is != null) {
15.165 - is.getExceptionListener().exceptionThrown(e);
15.166 - }
15.167 - return null;
15.168 - }
15.169 - }
15.170 -
15.171 - private void addArg(Object arg) {
15.172 - lastExp().addArg(arg);
15.173 - }
15.174 -
15.175 - private Object pop(Vector v) {
15.176 - int last = v.size()-1;
15.177 - Object result = v.get(last);
15.178 - v.remove(last);
15.179 - return result;
15.180 - }
15.181 -
15.182 - private Object eval() {
15.183 - return getValue(lastExp());
15.184 - }
15.185 -
15.186 - private MutableExpression lastExp() {
15.187 - return (MutableExpression)expStack.lastElement();
15.188 - }
15.189 -
15.190 - public Object dequeueResult() {
15.191 - Object[] results = lastExp().getArguments();
15.192 - return results[itemsRead++];
15.193 - }
15.194 -
15.195 - private boolean isPrimitive(String name) {
15.196 - return name != "void" && typeNameToClass(name) != null;
15.197 - }
15.198 -
15.199 - private void simulateException(String message) {
15.200 - Exception e = new Exception(message);
15.201 - e.fillInStackTrace();
15.202 - if (is != null) {
15.203 - is.getExceptionListener().exceptionThrown(e);
15.204 - }
15.205 - }
15.206 -
15.207 - private Class classForName2(String name) {
15.208 - try {
15.209 - return ClassFinder.resolveClass(name, this.ldr);
15.210 - }
15.211 - catch (ClassNotFoundException e) {
15.212 - if (is != null) {
15.213 - is.getExceptionListener().exceptionThrown(e);
15.214 - }
15.215 - }
15.216 - return null;
15.217 - }
15.218 -
15.219 - private HashMap getAttributes(AttributeList attrs) {
15.220 - HashMap attributes = new HashMap();
15.221 - if (attrs != null && attrs.getLength() > 0) {
15.222 - for(int i = 0; i < attrs.getLength(); i++) {
15.223 - attributes.put(attrs.getName(i), attrs.getValue(i));
15.224 - }
15.225 - }
15.226 - return attributes;
15.227 - }
15.228 -
15.229 - public void startElement(String name, AttributeList attrs) throws SAXException {
15.230 - name = name.intern(); // Xerces parser does not supply unique tag names.
15.231 - if (this.isString) {
15.232 - parseCharCode(name, getAttributes(attrs));
15.233 - return;
15.234 - }
15.235 - chars.setLength(0);
15.236 -
15.237 - HashMap attributes = getAttributes(attrs);
15.238 - MutableExpression e = new MutableExpression();
15.239 -
15.240 - // Target
15.241 - String className = (String)attributes.get("class");
15.242 - if (className != null) {
15.243 - e.setTarget(classForName2(className));
15.244 - }
15.245 -
15.246 - // Property
15.247 - Object property = attributes.get("property");
15.248 - String index = (String)attributes.get("index");
15.249 - if (index != null) {
15.250 - property = new Integer(index);
15.251 - e.addArg(property);
15.252 - }
15.253 - e.setProperty(property);
15.254 -
15.255 - // Method
15.256 - String methodName = (String)attributes.get("method");
15.257 - if (methodName == null && property == null) {
15.258 - methodName = "new";
15.259 - }
15.260 - e.setMethodName(methodName);
15.261 -
15.262 - // Tags
15.263 - if (name == "string") {
15.264 - e.setTarget(String.class);
15.265 - e.setMethodName("new");
15.266 - this.isString = true;
15.267 - }
15.268 - else if (isPrimitive(name)){
15.269 - Class wrapper = typeNameToClass(name);
15.270 - e.setTarget(wrapper);
15.271 - e.setMethodName("new");
15.272 - parseCharCode(name, attributes);
15.273 - }
15.274 - else if (name == "class") {
15.275 - e.setTarget(Class.class);
15.276 - e.setMethodName("forName");
15.277 - }
15.278 - else if (name == "null") {
15.279 - // Create an arbitrary expression that has a value of null - for
15.280 - // consistency.
15.281 - e.setTarget(Object.class);
15.282 - e.setMethodName("getSuperclass");
15.283 - e.setValue(null);
15.284 - }
15.285 - else if (name == "void") {
15.286 - if (e.getTarget() == null) { // this check is for "void class="foo" method= ..."
15.287 - e.setTarget(eval());
15.288 - }
15.289 - }
15.290 - else if (name == "array") {
15.291 - // The class attribute means sub-type for arrays.
15.292 - String subtypeName = (String)attributes.get("class");
15.293 - Class subtype = (subtypeName == null) ? Object.class : classForName2(subtypeName);
15.294 - String length = (String)attributes.get("length");
15.295 - if (length != null) {
15.296 - e.setTarget(java.lang.reflect.Array.class);
15.297 - e.addArg(subtype);
15.298 - e.addArg(new Integer(length));
15.299 - }
15.300 - else {
15.301 - Class arrayClass = java.lang.reflect.Array.newInstance(subtype, 0).getClass();
15.302 - e.setTarget(arrayClass);
15.303 - }
15.304 - }
15.305 - else if (name == "java") {
15.306 - e.setValue(is); // The outermost scope is the stream itself.
15.307 - }
15.308 - else if (name == "object") {
15.309 - }
15.310 - else {
15.311 - simulateException("Unrecognized opening tag: " + name + " " + attrsToString(attrs));
15.312 - return;
15.313 - }
15.314 -
15.315 - // ids
15.316 - String idName = (String)attributes.get("id");
15.317 - if (idName != null) {
15.318 - environment.put(idName, e);
15.319 - }
15.320 -
15.321 - // idrefs
15.322 - String idrefName = (String)attributes.get("idref");
15.323 - if (idrefName != null) {
15.324 - e.setValue(lookup(idrefName));
15.325 - }
15.326 -
15.327 - // fields
15.328 - String fieldName = (String)attributes.get("field");
15.329 - if (fieldName != null) {
15.330 - e.setValue(getFieldValue(e.getTarget(), fieldName));
15.331 - }
15.332 - expStack.add(e);
15.333 - }
15.334 -
15.335 - private Object getFieldValue(Object target, String fieldName) {
15.336 - try {
15.337 - Class type = target.getClass();
15.338 - if (type == Class.class) {
15.339 - type = (Class)target;
15.340 - }
15.341 - java.lang.reflect.Field f = sun.reflect.misc.FieldUtil.getField(type, fieldName);
15.342 - return f.get(target);
15.343 - }
15.344 - catch (Exception e) {
15.345 - if (is != null) {
15.346 - is.getExceptionListener().exceptionThrown(e);
15.347 - }
15.348 - return null;
15.349 - }
15.350 - }
15.351 -
15.352 - private String attrsToString(AttributeList attrs) {
15.353 - StringBuffer b = new StringBuffer();
15.354 - for (int i = 0; i < attrs.getLength (); i++) {
15.355 - b.append(attrs.getName(i)+"=\""+attrs.getValue(i)+"\" ");
15.356 - }
15.357 - return b.toString();
15.358 - }
15.359 -
15.360 - public void characters(char buf [], int offset, int len) throws SAXException {
15.361 - chars.append(new String(buf, offset, len));
15.362 - }
15.363 -
15.364 - private void parseCharCode(String name, Map map) {
15.365 - if (name == "char") {
15.366 - String value = (String) map.get("code");
15.367 - if (value != null) {
15.368 - int code = Integer.decode(value);
15.369 - for (char ch : Character.toChars(code)) {
15.370 - this.chars.append(ch);
15.371 - }
15.372 - }
15.373 - }
15.374 - }
15.375 -
15.376 - public Object lookup(String s) {
15.377 - Expression e = (Expression)environment.get(s);
15.378 - if (e == null) {
15.379 - simulateException("Unbound variable: " + s);
15.380 - }
15.381 - return getValue(e);
15.382 - }
15.383 -
15.384 - public void register(String id, Object value) {
15.385 - Expression e = new MutableExpression();
15.386 - e.setValue(value);
15.387 - environment.put(id, e);
15.388 - }
15.389 -
15.390 - public void endElement(String name) throws SAXException {
15.391 - name = name.intern(); // Xerces parser does not supply unique tag names.
15.392 - if (name == "string") {
15.393 - this.isString = false;
15.394 - } else if (this.isString) {
15.395 - return;
15.396 - }
15.397 - if (name == "java") {
15.398 - return;
15.399 - }
15.400 - if (isPrimitive(name) || name == "string" || name == "class") {
15.401 - addArg(chars.toString());
15.402 - }
15.403 - if (name == "object" || name == "array" || name == "void" ||
15.404 - isPrimitive(name) || name == "string" || name == "class" ||
15.405 - name == "null") {
15.406 - Expression e = (Expression)pop(expStack);
15.407 - Object value = getValue(e);
15.408 - if (name != "void") {
15.409 - addArg(value);
15.410 - }
15.411 - }
15.412 - else {
15.413 - simulateException("Unrecognized closing tag: " + name);
15.414 - }
15.415 - }
15.416 -}
15.417 -
15.418 -
15.419 -class MutableExpression extends Expression {
15.420 - private Object target;
15.421 - private String methodName;
15.422 -
15.423 - private Object property;
15.424 - private Vector argV = new Vector();
15.425 -
15.426 - private String capitalize(String propertyName) {
15.427 - if (propertyName.length() == 0) {
15.428 - return propertyName;
15.429 - }
15.430 - return propertyName.substring(0, 1).toUpperCase(ENGLISH) + propertyName.substring(1);
15.431 - }
15.432 -
15.433 - public MutableExpression() {
15.434 - super(null, null, null);
15.435 - }
15.436 -
15.437 - public Object[] getArguments() {
15.438 - return argV.toArray();
15.439 - }
15.440 -
15.441 - public String getMethodName() {
15.442 - if (property == null) {
15.443 - return methodName;
15.444 - }
15.445 - int setterArgs = (property instanceof String) ? 1 : 2;
15.446 - String methodName = (argV.size() == setterArgs) ? "set" : "get";
15.447 - if (property instanceof String) {
15.448 - return methodName + capitalize((String)property);
15.449 - }
15.450 - else {
15.451 - return methodName;
15.452 - }
15.453 - }
15.454 -
15.455 - public void addArg(Object arg) {
15.456 - argV.add(arg);
15.457 - }
15.458 -
15.459 - public void setTarget(Object target) {
15.460 - this.target = target;
15.461 - }
15.462 -
15.463 - public Object getTarget() {
15.464 - return target;
15.465 - }
15.466 -
15.467 - public void setMethodName(String methodName) {
15.468 - this.methodName = methodName;
15.469 - }
15.470 -
15.471 - public void setProperty(Object property) {
15.472 - this.property = property;
15.473 - }
15.474 -
15.475 - public void setValue(Object value) {
15.476 - super.setValue(value);
15.477 - }
15.478 -
15.479 - public Object getValue() throws Exception {
15.480 - return super.getValue();
15.481 - }
15.482 -}
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
16.2 +++ b/src/share/classes/com/sun/beans/decoder/AccessorElementHandler.java Tue Feb 03 22:02:55 2009 -0800
16.3 @@ -0,0 +1,105 @@
16.4 +/*
16.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
16.7 + *
16.8 + * This code is free software; you can redistribute it and/or modify it
16.9 + * under the terms of the GNU General Public License version 2 only, as
16.10 + * published by the Free Software Foundation. Sun designates this
16.11 + * particular file as subject to the "Classpath" exception as provided
16.12 + * by Sun in the LICENSE file that accompanied this code.
16.13 + *
16.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
16.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16.17 + * version 2 for more details (a copy is included in the LICENSE file that
16.18 + * accompanied this code).
16.19 + *
16.20 + * You should have received a copy of the GNU General Public License version
16.21 + * 2 along with this work; if not, write to the Free Software Foundation,
16.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
16.23 + *
16.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
16.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
16.26 + * have any questions.
16.27 + */
16.28 +package com.sun.beans.decoder;
16.29 +
16.30 +/**
16.31 + * This is base class that simplifies access to entities (fields or properties).
16.32 + * The {@code name} attribute specifies the name of the accessible entity.
16.33 + * The element defines getter if it contains no argument
16.34 + * or setter if it contains one argument.
16.35 + *
16.36 + * @since 1.7
16.37 + *
16.38 + * @author Sergey A. Malenkov
16.39 + */
16.40 +abstract class AccessorElementHandler extends ElementHandler {
16.41 + private String name;
16.42 + private ValueObject value;
16.43 +
16.44 + /**
16.45 + * Parses attributes of the element.
16.46 + * The following atributes are supported:
16.47 + * <dl>
16.48 + * <dt>name
16.49 + * <dd>the name of the accessible entity
16.50 + * <dt>id
16.51 + * <dd>the identifier of the variable that is intended to store the result
16.52 + * </dl>
16.53 + *
16.54 + * @param name the attribute name
16.55 + * @param value the attribute value
16.56 + */
16.57 + @Override
16.58 + public void addAttribute(String name, String value) {
16.59 + if (name.equals("name")) { // NON-NLS: the attribute name
16.60 + this.name = value;
16.61 + } else {
16.62 + super.addAttribute(name, value);
16.63 + }
16.64 + }
16.65 +
16.66 + /**
16.67 + * Adds the argument that is used to set the value of this element.
16.68 + *
16.69 + * @param argument the value of the element that contained in this one
16.70 + */
16.71 + @Override
16.72 + protected final void addArgument(Object argument) {
16.73 + if (this.value != null) {
16.74 + throw new IllegalStateException("Could not add argument to evaluated element");
16.75 + }
16.76 + setValue(this.name, argument);
16.77 + this.value = ValueObjectImpl.VOID;
16.78 + }
16.79 +
16.80 + /**
16.81 + * Returns the value of this element.
16.82 + *
16.83 + * @return the value of this element
16.84 + */
16.85 + @Override
16.86 + protected final ValueObject getValueObject() {
16.87 + if (this.value == null) {
16.88 + this.value = ValueObjectImpl.create(getValue(this.name));
16.89 + }
16.90 + return this.value;
16.91 + }
16.92 +
16.93 + /**
16.94 + * Returns the value of the entity with specified {@code name}.
16.95 + *
16.96 + * @param name the name of the accessible entity
16.97 + * @return the value of the specified entity
16.98 + */
16.99 + protected abstract Object getValue(String name);
16.100 +
16.101 + /**
16.102 + * Sets the new value for the entity with specified {@code name}.
16.103 + *
16.104 + * @param name the name of the accessible entity
16.105 + * @param value the new value for the specified entity
16.106 + */
16.107 + protected abstract void setValue(String name, Object value);
16.108 +}
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
17.2 +++ b/src/share/classes/com/sun/beans/decoder/ArrayElementHandler.java Tue Feb 03 22:02:55 2009 -0800
17.3 @@ -0,0 +1,133 @@
17.4 +/*
17.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
17.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
17.7 + *
17.8 + * This code is free software; you can redistribute it and/or modify it
17.9 + * under the terms of the GNU General Public License version 2 only, as
17.10 + * published by the Free Software Foundation. Sun designates this
17.11 + * particular file as subject to the "Classpath" exception as provided
17.12 + * by Sun in the LICENSE file that accompanied this code.
17.13 + *
17.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
17.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17.17 + * version 2 for more details (a copy is included in the LICENSE file that
17.18 + * accompanied this code).
17.19 + *
17.20 + * You should have received a copy of the GNU General Public License version
17.21 + * 2 along with this work; if not, write to the Free Software Foundation,
17.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17.23 + *
17.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
17.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
17.26 + * have any questions.
17.27 + */
17.28 +package com.sun.beans.decoder;
17.29 +
17.30 +import java.lang.reflect.Array;
17.31 +
17.32 +/**
17.33 + * This class is intended to handle <array> element,
17.34 + * that is used to array creation.
17.35 + * The {@code length} attribute specifies the length of the array.
17.36 + * The {@code class} attribute specifies the elements type.
17.37 + * The {@link Object} type is used by default.
17.38 + * For example:<pre>
17.39 + * <array length="10"/></pre>
17.40 + * is equivalent to {@code new Component[10]} in Java code.
17.41 + * The {@code set} and {@code get} methods,
17.42 + * as defined in the {@link java.util.List} interface,
17.43 + * can be used as if they could be applied to array instances.
17.44 + * The {@code index} attribute can thus be used with arrays.
17.45 + * For example:<pre>
17.46 + * <array length="3" class="java.lang.String">
17.47 + * <void index="1">
17.48 + * <string>Hello, world</string>
17.49 + * </void>
17.50 + * </array></pre>
17.51 + * is equivalent to the following Java code:<pre>
17.52 + * String[] s = new String[3];
17.53 + * s[1] = "Hello, world";</pre>
17.54 + * It is possible to omit the {@code length} attribute and
17.55 + * specify the values directly, without using {@code void} tags.
17.56 + * The length of the array is equal to the number of values specified.
17.57 + * For example:<pre>
17.58 + * <array id="array" class="int">
17.59 + * <int>123</int>
17.60 + * <int>456</int>
17.61 + * </array></pre>
17.62 + * is equivalent to {@code int[] array = {123, 456}} in Java code.
17.63 + * <p>The following atributes are supported:
17.64 + * <dl>
17.65 + * <dt>length
17.66 + * <dd>the array length
17.67 + * <dt>class
17.68 + * <dd>the type of object for instantiation
17.69 + * <dt>id
17.70 + * <dd>the identifier of the variable that is intended to store the result
17.71 + * </dl>
17.72 + *
17.73 + * @since 1.7
17.74 + *
17.75 + * @author Sergey A. Malenkov
17.76 + */
17.77 +final class ArrayElementHandler extends NewElementHandler {
17.78 + private Integer length;
17.79 +
17.80 + /**
17.81 + * Parses attributes of the element.
17.82 + * The following atributes are supported:
17.83 + * <dl>
17.84 + * <dt>length
17.85 + * <dd>the array length
17.86 + * <dt>class
17.87 + * <dd>the type of object for instantiation
17.88 + * <dt>id
17.89 + * <dd>the identifier of the variable that is intended to store the result
17.90 + * </dl>
17.91 + *
17.92 + * @param name the attribute name
17.93 + * @param value the attribute value
17.94 + */
17.95 + @Override
17.96 + public void addAttribute(String name, String value) {
17.97 + if (name.equals("length")) { // NON-NLS: the attribute name
17.98 + this.length = Integer.valueOf(value);
17.99 + } else {
17.100 + super.addAttribute(name, value);
17.101 + }
17.102 + }
17.103 +
17.104 + /**
17.105 + * Calculates the value of this element
17.106 + * if the lentgh attribute is set.
17.107 + */
17.108 + @Override
17.109 + public void startElement() {
17.110 + if (this.length != null) {
17.111 + getValueObject();
17.112 + }
17.113 + }
17.114 +
17.115 + /**
17.116 + * Creates an instance of the array.
17.117 + *
17.118 + * @param type the base class
17.119 + * @param args the array of arguments
17.120 + * @return the value of this element
17.121 + */
17.122 + @Override
17.123 + protected ValueObject getValueObject(Class<?> type, Object[] args) {
17.124 + if (type == null) {
17.125 + type = Object.class;
17.126 + }
17.127 + if (this.length != null) {
17.128 + return ValueObjectImpl.create(Array.newInstance(type, this.length));
17.129 + }
17.130 + Object array = Array.newInstance(type, args.length);
17.131 + for (int i = 0; i < args.length; i++) {
17.132 + Array.set(array, i, args[i]);
17.133 + }
17.134 + return ValueObjectImpl.create(array);
17.135 + }
17.136 +}
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
18.2 +++ b/src/share/classes/com/sun/beans/decoder/BooleanElementHandler.java Tue Feb 03 22:02:55 2009 -0800
18.3 @@ -0,0 +1,69 @@
18.4 +/*
18.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
18.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
18.7 + *
18.8 + * This code is free software; you can redistribute it and/or modify it
18.9 + * under the terms of the GNU General Public License version 2 only, as
18.10 + * published by the Free Software Foundation. Sun designates this
18.11 + * particular file as subject to the "Classpath" exception as provided
18.12 + * by Sun in the LICENSE file that accompanied this code.
18.13 + *
18.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
18.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18.17 + * version 2 for more details (a copy is included in the LICENSE file that
18.18 + * accompanied this code).
18.19 + *
18.20 + * You should have received a copy of the GNU General Public License version
18.21 + * 2 along with this work; if not, write to the Free Software Foundation,
18.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18.23 + *
18.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
18.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
18.26 + * have any questions.
18.27 + */
18.28 +package com.sun.beans.decoder;
18.29 +
18.30 +/**
18.31 + * This class is intended to handle <boolean> element.
18.32 + * This element specifies {@code boolean} values.
18.33 + * The class {@link Boolean} is used as wrapper for these values.
18.34 + * The result value is created from text of the body of this element.
18.35 + * The body parsing is described in the class {@link StringElementHandler}.
18.36 + * For example:<pre>
18.37 + * <boolean>true</boolean></pre>
18.38 + * is shortcut to<pre>
18.39 + * <method name="valueOf" class="java.lang.Boolean">
18.40 + * <string>true</string>
18.41 + * </method></pre>
18.42 + * which is equivalent to {@code Boolean.valueOf("true")} in Java code.
18.43 + * <p>The following atribute is supported:
18.44 + * <dl>
18.45 + * <dt>id
18.46 + * <dd>the identifier of the variable that is intended to store the result
18.47 + * </dl>
18.48 + *
18.49 + * @since 1.7
18.50 + *
18.51 + * @author Sergey A. Malenkov
18.52 + */
18.53 +final class BooleanElementHandler extends StringElementHandler {
18.54 +
18.55 + /**
18.56 + * Creates {@code boolean} value from
18.57 + * the text of the body of this element.
18.58 + *
18.59 + * @param argument the text of the body
18.60 + * @return evaluated {@code boolean} value
18.61 + */
18.62 + @Override
18.63 + public Object getValue(String argument) {
18.64 + if (Boolean.TRUE.toString().equalsIgnoreCase(argument)) {
18.65 + return Boolean.TRUE;
18.66 + }
18.67 + if (Boolean.FALSE.toString().equalsIgnoreCase(argument)) {
18.68 + return Boolean.FALSE;
18.69 + }
18.70 + throw new IllegalArgumentException("Unsupported boolean argument: " + argument);
18.71 + }
18.72 +}
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
19.2 +++ b/src/share/classes/com/sun/beans/decoder/ByteElementHandler.java Tue Feb 03 22:02:55 2009 -0800
19.3 @@ -0,0 +1,63 @@
19.4 +/*
19.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
19.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
19.7 + *
19.8 + * This code is free software; you can redistribute it and/or modify it
19.9 + * under the terms of the GNU General Public License version 2 only, as
19.10 + * published by the Free Software Foundation. Sun designates this
19.11 + * particular file as subject to the "Classpath" exception as provided
19.12 + * by Sun in the LICENSE file that accompanied this code.
19.13 + *
19.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
19.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19.17 + * version 2 for more details (a copy is included in the LICENSE file that
19.18 + * accompanied this code).
19.19 + *
19.20 + * You should have received a copy of the GNU General Public License version
19.21 + * 2 along with this work; if not, write to the Free Software Foundation,
19.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19.23 + *
19.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
19.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
19.26 + * have any questions.
19.27 + */
19.28 +package com.sun.beans.decoder;
19.29 +
19.30 +/**
19.31 + * This class is intended to handle <byte> element.
19.32 + * This element specifies {@code byte} values.
19.33 + * The class {@link Byte} is used as wrapper for these values.
19.34 + * The result value is created from text of the body of this element.
19.35 + * The body parsing is described in the class {@link StringElementHandler}.
19.36 + * For example:<pre>
19.37 + * <byte>127</byte></pre>
19.38 + * is shortcut to<pre>
19.39 + * <method name="decode" class="java.lang.Byte">
19.40 + * <string>127</string>
19.41 + * </method></pre>
19.42 + * which is equivalent to {@code Byte.decode("127")} in Java code.
19.43 + * <p>The following atribute is supported:
19.44 + * <dl>
19.45 + * <dt>id
19.46 + * <dd>the identifier of the variable that is intended to store the result
19.47 + * </dl>
19.48 + *
19.49 + * @since 1.7
19.50 + *
19.51 + * @author Sergey A. Malenkov
19.52 + */
19.53 +final class ByteElementHandler extends StringElementHandler {
19.54 +
19.55 + /**
19.56 + * Creates {@code byte} value from
19.57 + * the text of the body of this element.
19.58 + *
19.59 + * @param argument the text of the body
19.60 + * @return evaluated {@code byte} value
19.61 + */
19.62 + @Override
19.63 + public Object getValue(String argument) {
19.64 + return Byte.decode(argument);
19.65 + }
19.66 +}
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
20.2 +++ b/src/share/classes/com/sun/beans/decoder/CharElementHandler.java Tue Feb 03 22:02:55 2009 -0800
20.3 @@ -0,0 +1,92 @@
20.4 +/*
20.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
20.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
20.7 + *
20.8 + * This code is free software; you can redistribute it and/or modify it
20.9 + * under the terms of the GNU General Public License version 2 only, as
20.10 + * published by the Free Software Foundation. Sun designates this
20.11 + * particular file as subject to the "Classpath" exception as provided
20.12 + * by Sun in the LICENSE file that accompanied this code.
20.13 + *
20.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
20.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20.17 + * version 2 for more details (a copy is included in the LICENSE file that
20.18 + * accompanied this code).
20.19 + *
20.20 + * You should have received a copy of the GNU General Public License version
20.21 + * 2 along with this work; if not, write to the Free Software Foundation,
20.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20.23 + *
20.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
20.26 + * have any questions.
20.27 + */
20.28 +package com.sun.beans.decoder;
20.29 +
20.30 +/**
20.31 + * This class is intended to handle <char> element.
20.32 + * This element specifies {@code char} values.
20.33 + * The class {@link Character} is used as wrapper for these values.
20.34 + * The result value is created from text of the body of this element.
20.35 + * The body parsing is described in the class {@link StringElementHandler}.
20.36 + * For example:<pre>
20.37 + * <char>X</char></pre>
20.38 + * which is equivalent to {@code Character.valueOf('X')} in Java code.
20.39 + * <p>The following atributes are supported:
20.40 + * <dl>
20.41 + * <dt>code
20.42 + * <dd>this attribute specifies character code
20.43 + * <dt>id
20.44 + * <dd>the identifier of the variable that is intended to store the result
20.45 + * </dl>
20.46 + * The {@code code} attribute can be used for characters
20.47 + * that are illegal in XML document, for example:<pre>
20.48 + * <char code="0"/></pre>
20.49 + *
20.50 + * @since 1.7
20.51 + *
20.52 + * @author Sergey A. Malenkov
20.53 + */
20.54 +final class CharElementHandler extends StringElementHandler {
20.55 +
20.56 + /**
20.57 + * Parses attributes of the element.
20.58 + * The following atributes are supported:
20.59 + * <dl>
20.60 + * <dt>code
20.61 + * <dd>this attribute specifies character code
20.62 + * <dt>id
20.63 + * <dd>the identifier of the variable that is intended to store the result
20.64 + * </dl>
20.65 + *
20.66 + * @param name the attribute name
20.67 + * @param value the attribute value
20.68 + */
20.69 + @Override
20.70 + public void addAttribute(String name, String value) {
20.71 + if (name.equals("code")) { // NON-NLS: the attribute name
20.72 + int code = Integer.decode(value);
20.73 + for (char ch : Character.toChars(code)) {
20.74 + addCharacter(ch);
20.75 + }
20.76 + } else {
20.77 + super.addAttribute(name, value);
20.78 + }
20.79 + }
20.80 +
20.81 + /**
20.82 + * Creates {@code char} value from
20.83 + * the text of the body of this element.
20.84 + *
20.85 + * @param argument the text of the body
20.86 + * @return evaluated {@code char} value
20.87 + */
20.88 + @Override
20.89 + public Object getValue(String argument) {
20.90 + if (argument.length() != 1) {
20.91 + throw new IllegalArgumentException("Wrong characters count");
20.92 + }
20.93 + return Character.valueOf(argument.charAt(0));
20.94 + }
20.95 +}
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
21.2 +++ b/src/share/classes/com/sun/beans/decoder/ClassElementHandler.java Tue Feb 03 22:02:55 2009 -0800
21.3 @@ -0,0 +1,62 @@
21.4 +/*
21.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
21.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
21.7 + *
21.8 + * This code is free software; you can redistribute it and/or modify it
21.9 + * under the terms of the GNU General Public License version 2 only, as
21.10 + * published by the Free Software Foundation. Sun designates this
21.11 + * particular file as subject to the "Classpath" exception as provided
21.12 + * by Sun in the LICENSE file that accompanied this code.
21.13 + *
21.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
21.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21.17 + * version 2 for more details (a copy is included in the LICENSE file that
21.18 + * accompanied this code).
21.19 + *
21.20 + * You should have received a copy of the GNU General Public License version
21.21 + * 2 along with this work; if not, write to the Free Software Foundation,
21.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21.23 + *
21.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
21.26 + * have any questions.
21.27 + */
21.28 +package com.sun.beans.decoder;
21.29 +
21.30 +/**
21.31 + * This class is intended to handle <class> element.
21.32 + * This element specifies {@link Class} values.
21.33 + * The result value is created from text of the body of this element.
21.34 + * The body parsing is described in the class {@link StringElementHandler}.
21.35 + * For example:<pre>
21.36 + * <class>java.lang.Class</class></pre>
21.37 + * is shortcut to<pre>
21.38 + * <method name="forName" class="java.lang.Class">
21.39 + * <string>java.lang.Class</string>
21.40 + * </method></pre>
21.41 + * which is equivalent to {@code Class.forName("java.lang.Class")} in Java code.
21.42 + * <p>The following atribute is supported:
21.43 + * <dl>
21.44 + * <dt>id
21.45 + * <dd>the identifier of the variable that is intended to store the result
21.46 + * </dl>
21.47 + *
21.48 + * @since 1.7
21.49 + *
21.50 + * @author Sergey A. Malenkov
21.51 + */
21.52 +final class ClassElementHandler extends StringElementHandler {
21.53 +
21.54 + /**
21.55 + * Creates class by the name from
21.56 + * the text of the body of this element.
21.57 + *
21.58 + * @param argument the text of the body
21.59 + * @return evaluated {@code Class} value
21.60 + */
21.61 + @Override
21.62 + public Object getValue(String argument) {
21.63 + return getOwner().findClass(argument);
21.64 + }
21.65 +}
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
22.2 +++ b/src/share/classes/com/sun/beans/decoder/DocumentHandler.java Tue Feb 03 22:02:55 2009 -0800
22.3 @@ -0,0 +1,389 @@
22.4 +/*
22.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
22.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
22.7 + *
22.8 + * This code is free software; you can redistribute it and/or modify it
22.9 + * under the terms of the GNU General Public License version 2 only, as
22.10 + * published by the Free Software Foundation. Sun designates this
22.11 + * particular file as subject to the "Classpath" exception as provided
22.12 + * by Sun in the LICENSE file that accompanied this code.
22.13 + *
22.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
22.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22.17 + * version 2 for more details (a copy is included in the LICENSE file that
22.18 + * accompanied this code).
22.19 + *
22.20 + * You should have received a copy of the GNU General Public License version
22.21 + * 2 along with this work; if not, write to the Free Software Foundation,
22.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22.23 + *
22.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
22.26 + * have any questions.
22.27 + */
22.28 +package com.sun.beans.decoder;
22.29 +
22.30 +import com.sun.beans.finder.ClassFinder;
22.31 +
22.32 +import java.beans.ExceptionListener;
22.33 +
22.34 +import java.io.IOException;
22.35 +
22.36 +import java.lang.ref.Reference;
22.37 +import java.lang.ref.WeakReference;
22.38 +
22.39 +import java.util.ArrayList;
22.40 +import java.util.HashMap;
22.41 +import java.util.List;
22.42 +import java.util.Map;
22.43 +
22.44 +import javax.xml.parsers.ParserConfigurationException;
22.45 +import javax.xml.parsers.SAXParserFactory;
22.46 +
22.47 +import org.xml.sax.Attributes;
22.48 +import org.xml.sax.InputSource;
22.49 +import org.xml.sax.SAXException;
22.50 +import org.xml.sax.helpers.DefaultHandler;
22.51 +
22.52 +/**
22.53 + * The main class to parse JavaBeans XML archive.
22.54 + *
22.55 + * @since 1.7
22.56 + *
22.57 + * @author Sergey A. Malenkov
22.58 + *
22.59 + * @see ElementHandler
22.60 + */
22.61 +public final class DocumentHandler extends DefaultHandler {
22.62 + private final Map<String, Class<? extends ElementHandler>> handlers = new HashMap<String, Class<? extends ElementHandler>>();
22.63 +
22.64 + private final Map<String, Object> environment = new HashMap<String, Object>();
22.65 +
22.66 + private final List<Object> objects = new ArrayList<Object>();
22.67 +
22.68 + private Reference<ClassLoader> loader;
22.69 + private ExceptionListener listener;
22.70 + private Object owner;
22.71 +
22.72 + private ElementHandler handler;
22.73 +
22.74 + /**
22.75 + * Creates new instance of document handler.
22.76 + */
22.77 + public DocumentHandler() {
22.78 + setElementHandler("java", JavaElementHandler.class); // NON-NLS: the element name
22.79 + setElementHandler("null", NullElementHandler.class); // NON-NLS: the element name
22.80 + setElementHandler("array", ArrayElementHandler.class); // NON-NLS: the element name
22.81 + setElementHandler("class", ClassElementHandler.class); // NON-NLS: the element name
22.82 + setElementHandler("string", StringElementHandler.class); // NON-NLS: the element name
22.83 + setElementHandler("object", ObjectElementHandler.class); // NON-NLS: the element name
22.84 +
22.85 + setElementHandler("void", VoidElementHandler.class); // NON-NLS: the element name
22.86 + setElementHandler("char", CharElementHandler.class); // NON-NLS: the element name
22.87 + setElementHandler("byte", ByteElementHandler.class); // NON-NLS: the element name
22.88 + setElementHandler("short", ShortElementHandler.class); // NON-NLS: the element name
22.89 + setElementHandler("int", IntElementHandler.class); // NON-NLS: the element name
22.90 + setElementHandler("long", LongElementHandler.class); // NON-NLS: the element name
22.91 + setElementHandler("float", FloatElementHandler.class); // NON-NLS: the element name
22.92 + setElementHandler("double", DoubleElementHandler.class); // NON-NLS: the element name
22.93 + setElementHandler("boolean", BooleanElementHandler.class); // NON-NLS: the element name
22.94 +
22.95 + // some handlers for new elements
22.96 + setElementHandler("new", NewElementHandler.class); // NON-NLS: the element name
22.97 + setElementHandler("var", VarElementHandler.class); // NON-NLS: the element name
22.98 + setElementHandler("true", TrueElementHandler.class); // NON-NLS: the element name
22.99 + setElementHandler("false", FalseElementHandler.class); // NON-NLS: the element name
22.100 + setElementHandler("field", FieldElementHandler.class); // NON-NLS: the element name
22.101 + setElementHandler("method", MethodElementHandler.class); // NON-NLS: the element name
22.102 + setElementHandler("property", PropertyElementHandler.class); // NON-NLS: the element name
22.103 + }
22.104 +
22.105 + /**
22.106 + * Returns the class loader used to instantiate objects.
22.107 + * If the class loader has not been explicitly set
22.108 + * then {@code null} is returned.
22.109 + *
22.110 + * @return the class loader used to instantiate objects
22.111 + */
22.112 + public ClassLoader getClassLoader() {
22.113 + return (this.loader != null)
22.114 + ? this.loader.get()
22.115 + : null;
22.116 + }
22.117 +
22.118 + /**
22.119 + * Sets the class loader used to instantiate objects.
22.120 + * If the class loader is not set
22.121 + * then default class loader will be used.
22.122 + *
22.123 + * @param loader a classloader to use
22.124 + */
22.125 + public void setClassLoader(ClassLoader loader) {
22.126 + this.loader = new WeakReference<ClassLoader>(loader);
22.127 + }
22.128 +
22.129 + /**
22.130 + * Returns the exception listener for parsing.
22.131 + * The exception listener is notified
22.132 + * when handler catches recoverable exceptions.
22.133 + * If the exception listener has not been explicitly set
22.134 + * then default exception listener is returned.
22.135 + *
22.136 + * @return the exception listener for parsing
22.137 + */
22.138 + public ExceptionListener getExceptionListener() {
22.139 + return this.listener;
22.140 + }
22.141 +
22.142 + /**
22.143 + * Sets the exception listener for parsing.
22.144 + * The exception listener is notified
22.145 + * when handler catches recoverable exceptions.
22.146 + *
22.147 + * @param listener the exception listener for parsing
22.148 + */
22.149 + public void setExceptionListener(ExceptionListener listener) {
22.150 + this.listener = listener;
22.151 + }
22.152 +
22.153 + /**
22.154 + * Returns the owner of this document handler.
22.155 + *
22.156 + * @return the owner of this document handler
22.157 + */
22.158 + public Object getOwner() {
22.159 + return this.owner;
22.160 + }
22.161 +
22.162 + /**
22.163 + * Sets the owner of this document handler.
22.164 + *
22.165 + * @param owner the owner of this document handler
22.166 + */
22.167 + public void setOwner(Object owner) {
22.168 + this.owner = owner;
22.169 + }
22.170 +
22.171 + /**
22.172 + * Returns the handler for the element with specified name.
22.173 + *
22.174 + * @param name the name of the element
22.175 + * @return the corresponding element handler
22.176 + */
22.177 + public Class<? extends ElementHandler> getElementHandler(String name) {
22.178 + Class<? extends ElementHandler> type = this.handlers.get(name);
22.179 + if (type == null) {
22.180 + throw new IllegalArgumentException("Unsupported element: " + name);
22.181 + }
22.182 + return type;
22.183 + }
22.184 +
22.185 + /**
22.186 + * Sets the handler for the element with specified name.
22.187 + *
22.188 + * @param name the name of the element
22.189 + * @param handler the corresponding element handler
22.190 + */
22.191 + public void setElementHandler(String name, Class<? extends ElementHandler> handler) {
22.192 + this.handlers.put(name, handler);
22.193 + }
22.194 +
22.195 + /**
22.196 + * Indicates whether the variable with specified identifier is defined.
22.197 + *
22.198 + * @param id the identifier
22.199 + * @return @{code true} if the variable is defined;
22.200 + * @{code false} otherwise
22.201 + */
22.202 + public boolean hasVariable(String id) {
22.203 + return this.environment.containsKey(id);
22.204 + }
22.205 +
22.206 + /**
22.207 + * Returns the value of the variable with specified identifier.
22.208 + *
22.209 + * @param id the identifier
22.210 + * @return the value of the variable
22.211 + */
22.212 + public Object getVariable(String id) {
22.213 + if (!this.environment.containsKey(id)) {
22.214 + throw new IllegalArgumentException("Unbound variable: " + id);
22.215 + }
22.216 + return this.environment.get(id);
22.217 + }
22.218 +
22.219 + /**
22.220 + * Sets new value of the variable with specified identifier.
22.221 + *
22.222 + * @param id the identifier
22.223 + * @param value new value of the variable
22.224 + */
22.225 + public void setVariable(String id, Object value) {
22.226 + this.environment.put(id, value);
22.227 + }
22.228 +
22.229 + /**
22.230 + * Returns the array of readed objects.
22.231 + *
22.232 + * @return the array of readed objects
22.233 + */
22.234 + public Object[] getObjects() {
22.235 + return this.objects.toArray();
22.236 + }
22.237 +
22.238 + /**
22.239 + * Adds the object to the list of readed objects.
22.240 + *
22.241 + * @param object the object that is readed from XML document
22.242 + */
22.243 + void addObject(Object object) {
22.244 + this.objects.add(object);
22.245 + }
22.246 +
22.247 + /**
22.248 + * Prepares this handler to read objects from XML document.
22.249 + */
22.250 + @Override
22.251 + public void startDocument() {
22.252 + this.objects.clear();
22.253 + this.handler = null;
22.254 + }
22.255 +
22.256 + /**
22.257 + * Parses opening tag of XML element
22.258 + * using corresponding element handler.
22.259 + *
22.260 + * @param uri the namespace URI, or the empty string
22.261 + * if the element has no namespace URI or
22.262 + * if namespace processing is not being performed
22.263 + * @param localName the local name (without prefix), or the empty string
22.264 + * if namespace processing is not being performed
22.265 + * @param qName the qualified name (with prefix), or the empty string
22.266 + * if qualified names are not available
22.267 + * @param attributes the attributes attached to the element
22.268 + */
22.269 + @Override
22.270 + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
22.271 + ElementHandler parent = this.handler;
22.272 + try {
22.273 + this.handler = getElementHandler(qName).newInstance();
22.274 + this.handler.setOwner(this);
22.275 + this.handler.setParent(parent);
22.276 + }
22.277 + catch (Exception exception) {
22.278 + throw new SAXException(exception);
22.279 + }
22.280 + for (int i = 0; i < attributes.getLength(); i++)
22.281 + try {
22.282 + String name = attributes.getQName(i);
22.283 + String value = attributes.getValue(i);
22.284 + this.handler.addAttribute(name, value);
22.285 + }
22.286 + catch (RuntimeException exception) {
22.287 + handleException(exception);
22.288 + }
22.289 +
22.290 + this.handler.startElement();
22.291 + }
22.292 +
22.293 + /**
22.294 + * Parses closing tag of XML element
22.295 + * using corresponding element handler.
22.296 + *
22.297 + * @param uri the namespace URI, or the empty string
22.298 + * if the element has no namespace URI or
22.299 + * if namespace processing is not being performed
22.300 + * @param localName the local name (without prefix), or the empty string
22.301 + * if namespace processing is not being performed
22.302 + * @param qName the qualified name (with prefix), or the empty string
22.303 + * if qualified names are not available
22.304 + */
22.305 + @Override
22.306 + public void endElement(String uri, String localName, String qName) {
22.307 + try {
22.308 + this.handler.endElement();
22.309 + }
22.310 + catch (RuntimeException exception) {
22.311 + handleException(exception);
22.312 + }
22.313 + finally {
22.314 + this.handler = this.handler.getParent();
22.315 + }
22.316 + }
22.317 +
22.318 + /**
22.319 + * Parses character data inside XML element.
22.320 + *
22.321 + * @param chars the array of characters
22.322 + * @param start the start position in the character array
22.323 + * @param length the number of characters to use
22.324 + */
22.325 + @Override
22.326 + public void characters(char[] chars, int start, int length) {
22.327 + if (this.handler != null) {
22.328 + try {
22.329 + while (0 < length--) {
22.330 + this.handler.addCharacter(chars[start++]);
22.331 + }
22.332 + }
22.333 + catch (RuntimeException exception) {
22.334 + handleException(exception);
22.335 + }
22.336 + }
22.337 + }
22.338 +
22.339 + /**
22.340 + * Handles an exception using current exception listener.
22.341 + *
22.342 + * @param exception an exception to handle
22.343 + * @see #setExceptionListener
22.344 + */
22.345 + public void handleException(Exception exception) {
22.346 + if (this.listener == null) {
22.347 + throw new IllegalStateException(exception);
22.348 + }
22.349 + this.listener.exceptionThrown(exception);
22.350 + }
22.351 +
22.352 + /**
22.353 + * Starts parsing of the specified input source.
22.354 + *
22.355 + * @param input the input source to parse
22.356 + */
22.357 + public void parse(InputSource input) {
22.358 + try {
22.359 + SAXParserFactory.newInstance().newSAXParser().parse(input, this);
22.360 + }
22.361 + catch (ParserConfigurationException exception) {
22.362 + handleException(exception);
22.363 + }
22.364 + catch (SAXException wrapper) {
22.365 + Exception exception = wrapper.getException();
22.366 + if (exception == null) {
22.367 + exception = wrapper;
22.368 + }
22.369 + handleException(exception);
22.370 + }
22.371 + catch (IOException exception) {
22.372 + handleException(exception);
22.373 + }
22.374 + }
22.375 +
22.376 + /**
22.377 + * Resolves class by name using current class loader.
22.378 + * This method handles exception using current exception listener.
22.379 + *
22.380 + * @param name the name of the class
22.381 + * @return the object that represents the class
22.382 + */
22.383 + public Class<?> findClass(String name) {
22.384 + try {
22.385 + return ClassFinder.resolveClass(name, getClassLoader());
22.386 + }
22.387 + catch (ClassNotFoundException exception) {
22.388 + handleException(exception);
22.389 + return null;
22.390 + }
22.391 + }
22.392 +}
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
23.2 +++ b/src/share/classes/com/sun/beans/decoder/DoubleElementHandler.java Tue Feb 03 22:02:55 2009 -0800
23.3 @@ -0,0 +1,63 @@
23.4 +/*
23.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
23.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
23.7 + *
23.8 + * This code is free software; you can redistribute it and/or modify it
23.9 + * under the terms of the GNU General Public License version 2 only, as
23.10 + * published by the Free Software Foundation. Sun designates this
23.11 + * particular file as subject to the "Classpath" exception as provided
23.12 + * by Sun in the LICENSE file that accompanied this code.
23.13 + *
23.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
23.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23.17 + * version 2 for more details (a copy is included in the LICENSE file that
23.18 + * accompanied this code).
23.19 + *
23.20 + * You should have received a copy of the GNU General Public License version
23.21 + * 2 along with this work; if not, write to the Free Software Foundation,
23.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23.23 + *
23.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
23.26 + * have any questions.
23.27 + */
23.28 +package com.sun.beans.decoder;
23.29 +
23.30 +/**
23.31 + * This class is intended to handle <double> element.
23.32 + * This element specifies {@code double} values.
23.33 + * The class {@link Double} is used as wrapper for these values.
23.34 + * The result value is created from text of the body of this element.
23.35 + * The body parsing is described in the class {@link StringElementHandler}.
23.36 + * For example:<pre>
23.37 + * <double>1.23e45</double></pre>
23.38 + * is shortcut to<pre>
23.39 + * <method name="valueOf" class="java.lang.Double">
23.40 + * <string>1.23e45</string>
23.41 + * </method></pre>
23.42 + * which is equivalent to {@code Double.valueOf("1.23e45")} in Java code.
23.43 + * <p>The following atribute is supported:
23.44 + * <dl>
23.45 + * <dt>id
23.46 + * <dd>the identifier of the variable that is intended to store the result
23.47 + * </dl>
23.48 + *
23.49 + * @since 1.7
23.50 + *
23.51 + * @author Sergey A. Malenkov
23.52 + */
23.53 +final class DoubleElementHandler extends StringElementHandler {
23.54 +
23.55 + /**
23.56 + * Creates {@code double} value from
23.57 + * the text of the body of this element.
23.58 + *
23.59 + * @param argument the text of the body
23.60 + * @return evaluated {@code double} value
23.61 + */
23.62 + @Override
23.63 + public Object getValue(String argument) {
23.64 + return Double.valueOf(argument);
23.65 + }
23.66 +}
24.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
24.2 +++ b/src/share/classes/com/sun/beans/decoder/ElementHandler.java Tue Feb 03 22:02:55 2009 -0800
24.3 @@ -0,0 +1,224 @@
24.4 +/*
24.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
24.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
24.7 + *
24.8 + * This code is free software; you can redistribute it and/or modify it
24.9 + * under the terms of the GNU General Public License version 2 only, as
24.10 + * published by the Free Software Foundation. Sun designates this
24.11 + * particular file as subject to the "Classpath" exception as provided
24.12 + * by Sun in the LICENSE file that accompanied this code.
24.13 + *
24.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
24.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24.17 + * version 2 for more details (a copy is included in the LICENSE file that
24.18 + * accompanied this code).
24.19 + *
24.20 + * You should have received a copy of the GNU General Public License version
24.21 + * 2 along with this work; if not, write to the Free Software Foundation,
24.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24.23 + *
24.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
24.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
24.26 + * have any questions.
24.27 + */
24.28 +package com.sun.beans.decoder;
24.29 +
24.30 +/**
24.31 + * The base class for element handlers.
24.32 + *
24.33 + * @since 1.7
24.34 + *
24.35 + * @author Sergey A. Malenkov
24.36 + *
24.37 + * @see DocumentHandler
24.38 + */
24.39 +public abstract class ElementHandler {
24.40 + private DocumentHandler owner;
24.41 + private ElementHandler parent;
24.42 +
24.43 + private String id;
24.44 +
24.45 + /**
24.46 + * Returns the document handler that creates this element handler.
24.47 + *
24.48 + * @return the owner document handler
24.49 + */
24.50 + public final DocumentHandler getOwner() {
24.51 + return this.owner;
24.52 + }
24.53 +
24.54 + /**
24.55 + * Sets the document handler that creates this element handler.
24.56 + * The owner document handler should be set after instantiation.
24.57 + * Such approach is used to simplify the extensibility.
24.58 + *
24.59 + * @param owner the owner document handler
24.60 + * @see DocumentHandler#startElement
24.61 + */
24.62 + final void setOwner(DocumentHandler owner) {
24.63 + if (owner == null) {
24.64 + throw new IllegalArgumentException("Every element should have owner");
24.65 + }
24.66 + this.owner = owner;
24.67 + }
24.68 +
24.69 + /**
24.70 + * Returns the element handler that contains this one.
24.71 + *
24.72 + * @return the parent element handler
24.73 + */
24.74 + public final ElementHandler getParent() {
24.75 + return this.parent;
24.76 + }
24.77 +
24.78 + /**
24.79 + * Sets the element handler that contains this one.
24.80 + * The parent element handler should be set after instantiation.
24.81 + * Such approach is used to simplify the extensibility.
24.82 + *
24.83 + * @param parent the parent element handler
24.84 + * @see DocumentHandler#startElement
24.85 + */
24.86 + final void setParent(ElementHandler parent) {
24.87 + this.parent = parent;
24.88 + }
24.89 +
24.90 + /**
24.91 + * Returns the value of the variable with specified identifier.
24.92 + *
24.93 + * @param id the identifier
24.94 + * @return the value of the variable
24.95 + */
24.96 + protected final Object getVariable(String id) {
24.97 + if (id.equals(this.id)) {
24.98 + ValueObject value = getValueObject();
24.99 + if (value.isVoid()) {
24.100 + throw new IllegalStateException("The element does not return value");
24.101 + }
24.102 + return value.getValue();
24.103 + }
24.104 + return (this.parent != null)
24.105 + ? this.parent.getVariable(id)
24.106 + : this.owner.getVariable(id);
24.107 + }
24.108 +
24.109 + /**
24.110 + * Returns the value of the parent element.
24.111 + *
24.112 + * @return the value of the parent element
24.113 + */
24.114 + protected Object getContextBean() {
24.115 + if (this.parent != null) {
24.116 + ValueObject value = this.parent.getValueObject();
24.117 + if (!value.isVoid()) {
24.118 + return value.getValue();
24.119 + }
24.120 + throw new IllegalStateException("The outer element does not return value");
24.121 + } else {
24.122 + Object value = this.owner.getOwner();
24.123 + if (value != null) {
24.124 + return value;
24.125 + }
24.126 + throw new IllegalStateException("The topmost element does not have context");
24.127 + }
24.128 + }
24.129 +
24.130 + /**
24.131 + * Parses attributes of the element.
24.132 + * By default, the following atribute is supported:
24.133 + * <dl>
24.134 + * <dt>id
24.135 + * <dd>the identifier of the variable that is intended to store the result
24.136 + * </dl>
24.137 + *
24.138 + * @param name the attribute name
24.139 + * @param value the attribute value
24.140 + */
24.141 + public void addAttribute(String name, String value) {
24.142 + if (name.equals("id")) { // NON-NLS: the attribute name
24.143 + this.id = value;
24.144 + } else {
24.145 + throw new IllegalArgumentException("Unsupported attribute: " + name);
24.146 + }
24.147 + }
24.148 +
24.149 + /**
24.150 + * This method is called before parsing of the element's body.
24.151 + * All attributes are parsed at this point.
24.152 + * By default, do nothing.
24.153 + */
24.154 + public void startElement() {
24.155 + }
24.156 +
24.157 + /**
24.158 + * This method is called after parsing of the element's body.
24.159 + * By default, it calculates the value of this element.
24.160 + * The following tasks are executing for any non-void value:
24.161 + * <ol>
24.162 + * <li>If the {@code id} attribute is set
24.163 + * the value of the variable with the specified identifier
24.164 + * is set to the value of this element.</li>
24.165 + * <li>This element is used as an argument of parent element if it is possible.</li>
24.166 + * </ol>
24.167 + *
24.168 + * @see #isArgument
24.169 + */
24.170 + public void endElement() {
24.171 + // do nothing if no value returned
24.172 + ValueObject value = getValueObject();
24.173 + if (!value.isVoid()) {
24.174 + if (this.id != null) {
24.175 + this.owner.setVariable(this.id, value.getValue());
24.176 + }
24.177 + if (isArgument()) {
24.178 + if (this.parent != null) {
24.179 + this.parent.addArgument(value.getValue());
24.180 + } else {
24.181 + this.owner.addObject(value.getValue());
24.182 + }
24.183 + }
24.184 + }
24.185 + }
24.186 +
24.187 + /**
24.188 + * Adds the character that contained in this element.
24.189 + * By default, only whitespaces are acceptable.
24.190 + *
24.191 + * @param ch the character
24.192 + */
24.193 + public void addCharacter(char ch) {
24.194 + if ((ch != ' ') && (ch != '\n') && (ch != '\t') && (ch != '\r')) {
24.195 + throw new IllegalStateException("Illegal character with code " + (int) ch);
24.196 + }
24.197 + }
24.198 +
24.199 + /**
24.200 + * Adds the argument that is used to calculate the value of this element.
24.201 + * By default, no arguments are acceptable.
24.202 + *
24.203 + * @param argument the value of the element that contained in this one
24.204 + */
24.205 + protected void addArgument(Object argument) {
24.206 + throw new IllegalStateException("Could not add argument to simple element");
24.207 + }
24.208 +
24.209 + /**
24.210 + * Tests whether the value of this element can be used
24.211 + * as an argument of the element that contained in this one.
24.212 + *
24.213 + * @return {@code true} if the value of this element can be used
24.214 + * as an argument of the element that contained in this one,
24.215 + * {@code false} otherwise
24.216 + */
24.217 + protected boolean isArgument() {
24.218 + return this.id == null;
24.219 + }
24.220 +
24.221 + /**
24.222 + * Returns the value of this element.
24.223 + *
24.224 + * @return the value of this element
24.225 + */
24.226 + protected abstract ValueObject getValueObject();
24.227 +}
25.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
25.2 +++ b/src/share/classes/com/sun/beans/decoder/FalseElementHandler.java Tue Feb 03 22:02:55 2009 -0800
25.3 @@ -0,0 +1,56 @@
25.4 +/*
25.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
25.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
25.7 + *
25.8 + * This code is free software; you can redistribute it and/or modify it
25.9 + * under the terms of the GNU General Public License version 2 only, as
25.10 + * published by the Free Software Foundation. Sun designates this
25.11 + * particular file as subject to the "Classpath" exception as provided
25.12 + * by Sun in the LICENSE file that accompanied this code.
25.13 + *
25.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
25.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25.17 + * version 2 for more details (a copy is included in the LICENSE file that
25.18 + * accompanied this code).
25.19 + *
25.20 + * You should have received a copy of the GNU General Public License version
25.21 + * 2 along with this work; if not, write to the Free Software Foundation,
25.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25.23 + *
25.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
25.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
25.26 + * have any questions.
25.27 + */
25.28 +package com.sun.beans.decoder;
25.29 +
25.30 +/**
25.31 + * This class is intended to handle <false> element.
25.32 + * This element specifies {@code false} value.
25.33 + * It should not contain body or inner elements.
25.34 + * For example:<pre>
25.35 + * <false/></pre>
25.36 + * is equivalent to {@code false} in Java code.
25.37 + * <p>The following atribute is supported:
25.38 + * <dl>
25.39 + * <dt>id
25.40 + * <dd>the identifier of the variable that is intended to store the result
25.41 + * </dl>
25.42 + *
25.43 + * @since 1.7
25.44 + *
25.45 + * @author Sergey A. Malenkov
25.46 + */
25.47 +final class FalseElementHandler extends NullElementHandler {
25.48 +
25.49 + /**
25.50 + * Returns {@code Boolean.FALSE}
25.51 + * as a value of <false> element.
25.52 + *
25.53 + * @return {@code Boolean.FALSE} by default
25.54 + */
25.55 + @Override
25.56 + public Object getValue() {
25.57 + return Boolean.FALSE;
25.58 + }
25.59 +}
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
26.2 +++ b/src/share/classes/com/sun/beans/decoder/FieldElementHandler.java Tue Feb 03 22:02:55 2009 -0800
26.3 @@ -0,0 +1,189 @@
26.4 +/*
26.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
26.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
26.7 + *
26.8 + * This code is free software; you can redistribute it and/or modify it
26.9 + * under the terms of the GNU General Public License version 2 only, as
26.10 + * published by the Free Software Foundation. Sun designates this
26.11 + * particular file as subject to the "Classpath" exception as provided
26.12 + * by Sun in the LICENSE file that accompanied this code.
26.13 + *
26.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
26.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
26.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26.17 + * version 2 for more details (a copy is included in the LICENSE file that
26.18 + * accompanied this code).
26.19 + *
26.20 + * You should have received a copy of the GNU General Public License version
26.21 + * 2 along with this work; if not, write to the Free Software Foundation,
26.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26.23 + *
26.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
26.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
26.26 + * have any questions.
26.27 + */
26.28 +package com.sun.beans.decoder;
26.29 +
26.30 +import com.sun.beans.finder.FieldFinder;
26.31 +
26.32 +import java.lang.reflect.Field;
26.33 +
26.34 +/**
26.35 + * This class is intended to handle <field> element.
26.36 + * This element simplifies access to the fields.
26.37 + * If the {@code class} attribute is specified
26.38 + * this element accesses static field of specified class.
26.39 + * This element defines getter if it contains no argument.
26.40 + * It returns the value of the field in this case.
26.41 + * For example:<pre>
26.42 + * <field name="TYPE" class="java.lang.Long"/></pre>
26.43 + * is equivalent to {@code Long.TYPE} in Java code.
26.44 + * This element defines setter if it contains one argument.
26.45 + * It does not return the value of the field in this case.
26.46 + * For example:<pre>
26.47 + * <field name="id"><int>0</int></field></pre>
26.48 + * is equivalent to {@code id = 0} in Java code.
26.49 + * <p>The following atributes are supported:
26.50 + * <dl>
26.51 + * <dt>name
26.52 + * <dd>the field name
26.53 + * <dt>class
26.54 + * <dd>the type is used for static fields only
26.55 + * <dt>id
26.56 + * <dd>the identifier of the variable that is intended to store the result
26.57 + * </dl>
26.58 + *
26.59 + * @since 1.7
26.60 + *
26.61 + * @author Sergey A. Malenkov
26.62 + */
26.63 +final class FieldElementHandler extends AccessorElementHandler {
26.64 + private Class<?> type;
26.65 +
26.66 + /**
26.67 + * Parses attributes of the element.
26.68 + * The following atributes are supported:
26.69 + * <dl>
26.70 + * <dt>name
26.71 + * <dd>the field name
26.72 + * <dt>class
26.73 + * <dd>the type is used for static fields only
26.74 + * <dt>id
26.75 + * <dd>the identifier of the variable that is intended to store the result
26.76 + * </dl>
26.77 + *
26.78 + * @param name the attribute name
26.79 + * @param value the attribute value
26.80 + */
26.81 + @Override
26.82 + public void addAttribute(String name, String value) {
26.83 + if (name.equals("class")) { // NON-NLS: the attribute name
26.84 + this.type = getOwner().findClass(value);
26.85 + } else {
26.86 + super.addAttribute(name, value);
26.87 + }
26.88 + }
26.89 +
26.90 + /**
26.91 + * Tests whether the value of this element can be used
26.92 + * as an argument of the element that contained in this one.
26.93 + *
26.94 + * @return {@code true} if the value of this element should be used
26.95 + * as an argument of the element that contained in this one,
26.96 + * {@code false} otherwise
26.97 + */
26.98 + @Override
26.99 + protected boolean isArgument() {
26.100 + return super.isArgument() && (this.type != null); // only static accessor can be used an argument
26.101 + }
26.102 +
26.103 + /**
26.104 + * Returns the context of the field.
26.105 + * The context of the static field is the class object.
26.106 + * The context of the non-static field is the value of the parent element.
26.107 + *
26.108 + * @return the context of the field
26.109 + */
26.110 + @Override
26.111 + protected Object getContextBean() {
26.112 + return (this.type != null)
26.113 + ? this.type
26.114 + : super.getContextBean();
26.115 + }
26.116 +
26.117 + /**
26.118 + * Returns the value of the field with specified {@code name}.
26.119 + *
26.120 + * @param name the name of the field
26.121 + * @return the value of the specified field
26.122 + */
26.123 + @Override
26.124 + protected Object getValue(String name) {
26.125 + try {
26.126 + return getFieldValue(getContextBean(), name);
26.127 + }
26.128 + catch (Exception exception) {
26.129 + getOwner().handleException(exception);
26.130 + }
26.131 + return null;
26.132 + }
26.133 +
26.134 + /**
26.135 + * Sets the new value for the field with specified {@code name}.
26.136 + *
26.137 + * @param name the name of the field
26.138 + * @param value the new value for the specified field
26.139 + */
26.140 + @Override
26.141 + protected void setValue(String name, Object value) {
26.142 + try {
26.143 + setFieldValue(getContextBean(), name, value);
26.144 + }
26.145 + catch (Exception exception) {
26.146 + getOwner().handleException(exception);
26.147 + }
26.148 + }
26.149 +
26.150 + /**
26.151 + * Performs the search of the field with specified {@code name}
26.152 + * in specified context and returns its value.
26.153 + *
26.154 + * @param bean the context bean that contains field
26.155 + * @param name the name of the field
26.156 + * @return the value of the field
26.157 + * @throws IllegalAccessException if the field is not accesible
26.158 + * @throws NoSuchFieldException if the field is not found
26.159 + */
26.160 + static Object getFieldValue(Object bean, String name) throws IllegalAccessException, NoSuchFieldException {
26.161 + return findField(bean, name).get(bean);
26.162 + }
26.163 +
26.164 + /**
26.165 + * Performs the search of the field with specified {@code name}
26.166 + * in specified context and updates its value.
26.167 + *
26.168 + * @param bean the context bean that contains field
26.169 + * @param name the name of the field
26.170 + * @param value the new value for the field
26.171 + * @throws IllegalAccessException if the field is not accesible
26.172 + * @throws NoSuchFieldException if the field is not found
26.173 + */
26.174 + private static void setFieldValue(Object bean, String name, Object value) throws IllegalAccessException, NoSuchFieldException {
26.175 + findField(bean, name).set(bean, value);
26.176 + }
26.177 +
26.178 + /**
26.179 + * Performs the search of the field
26.180 + * with specified {@code name} in specified context.
26.181 + *
26.182 + * @param bean the context bean that contains field
26.183 + * @param name the name of the field
26.184 + * @return field object that represents found field
26.185 + * @throws NoSuchFieldException if the field is not found
26.186 + */
26.187 + private static Field findField(Object bean, String name) throws NoSuchFieldException {
26.188 + return (bean instanceof Class<?>)
26.189 + ? FieldFinder.findStaticField((Class<?>) bean, name)
26.190 + : FieldFinder.findField(bean.getClass(), name);
26.191 + }
26.192 +}
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
27.2 +++ b/src/share/classes/com/sun/beans/decoder/FloatElementHandler.java Tue Feb 03 22:02:55 2009 -0800
27.3 @@ -0,0 +1,63 @@
27.4 +/*
27.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
27.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
27.7 + *
27.8 + * This code is free software; you can redistribute it and/or modify it
27.9 + * under the terms of the GNU General Public License version 2 only, as
27.10 + * published by the Free Software Foundation. Sun designates this
27.11 + * particular file as subject to the "Classpath" exception as provided
27.12 + * by Sun in the LICENSE file that accompanied this code.
27.13 + *
27.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
27.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27.17 + * version 2 for more details (a copy is included in the LICENSE file that
27.18 + * accompanied this code).
27.19 + *
27.20 + * You should have received a copy of the GNU General Public License version
27.21 + * 2 along with this work; if not, write to the Free Software Foundation,
27.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27.23 + *
27.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
27.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
27.26 + * have any questions.
27.27 + */
27.28 +package com.sun.beans.decoder;
27.29 +
27.30 +/**
27.31 + * This class is intended to handle <float> element.
27.32 + * This element specifies {@code float} values.
27.33 + * The class {@link Float} is used as wrapper for these values.
27.34 + * The result value is created from text of the body of this element.
27.35 + * The body parsing is described in the class {@link StringElementHandler}.
27.36 + * For example:<pre>
27.37 + * <float>-1.23</float></pre>
27.38 + * is shortcut to<pre>
27.39 + * <method name="valueOf" class="java.lang.Float">
27.40 + * <string>-1.23</string>
27.41 + * </method></pre>
27.42 + * which is equivalent to {@code Float.valueOf("-1.23")} in Java code.
27.43 + * <p>The following atribute is supported:
27.44 + * <dl>
27.45 + * <dt>id
27.46 + * <dd>the identifier of the variable that is intended to store the result
27.47 + * </dl>
27.48 + *
27.49 + * @since 1.7
27.50 + *
27.51 + * @author Sergey A. Malenkov
27.52 + */
27.53 +final class FloatElementHandler extends StringElementHandler {
27.54 +
27.55 + /**
27.56 + * Creates {@code float} value from
27.57 + * the text of the body of this element.
27.58 + *
27.59 + * @param argument the text of the body
27.60 + * @return evaluated {@code float} value
27.61 + */
27.62 + @Override
27.63 + public Object getValue(String argument) {
27.64 + return Float.valueOf(argument);
27.65 + }
27.66 +}
28.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
28.2 +++ b/src/share/classes/com/sun/beans/decoder/IntElementHandler.java Tue Feb 03 22:02:55 2009 -0800
28.3 @@ -0,0 +1,63 @@
28.4 +/*
28.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
28.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
28.7 + *
28.8 + * This code is free software; you can redistribute it and/or modify it
28.9 + * under the terms of the GNU General Public License version 2 only, as
28.10 + * published by the Free Software Foundation. Sun designates this
28.11 + * particular file as subject to the "Classpath" exception as provided
28.12 + * by Sun in the LICENSE file that accompanied this code.
28.13 + *
28.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
28.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
28.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28.17 + * version 2 for more details (a copy is included in the LICENSE file that
28.18 + * accompanied this code).
28.19 + *
28.20 + * You should have received a copy of the GNU General Public License version
28.21 + * 2 along with this work; if not, write to the Free Software Foundation,
28.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
28.23 + *
28.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
28.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
28.26 + * have any questions.
28.27 + */
28.28 +package com.sun.beans.decoder;
28.29 +
28.30 +/**
28.31 + * This class is intended to handle <int> element.
28.32 + * This element specifies {@code int} values.
28.33 + * The class {@link Integer} is used as wrapper for these values.
28.34 + * The result value is created from text of the body of this element.
28.35 + * The body parsing is described in the class {@link StringElementHandler}.
28.36 + * For example:<pre>
28.37 + * <int>-1</int></pre>
28.38 + * is shortcut to<pre>
28.39 + * <method name="decode" class="java.lang.Integer">
28.40 + * <string>-1</string>
28.41 + * </method></pre>
28.42 + * which is equivalent to {@code Integer.decode("-1")} in Java code.
28.43 + * <p>The following atribute is supported:
28.44 + * <dl>
28.45 + * <dt>id
28.46 + * <dd>the identifier of the variable that is intended to store the result
28.47 + * </dl>
28.48 + *
28.49 + * @since 1.7
28.50 + *
28.51 + * @author Sergey A. Malenkov
28.52 + */
28.53 +final class IntElementHandler extends StringElementHandler {
28.54 +
28.55 + /**
28.56 + * Creates {@code int} value from
28.57 + * the text of the body of this element.
28.58 + *
28.59 + * @param argument the text of the body
28.60 + * @return evaluated {@code int} value
28.61 + */
28.62 + @Override
28.63 + public Object getValue(String argument) {
28.64 + return Integer.decode(argument);
28.65 + }
28.66 +}
29.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
29.2 +++ b/src/share/classes/com/sun/beans/decoder/JavaElementHandler.java Tue Feb 03 22:02:55 2009 -0800
29.3 @@ -0,0 +1,151 @@
29.4 +/*
29.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
29.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
29.7 + *
29.8 + * This code is free software; you can redistribute it and/or modify it
29.9 + * under the terms of the GNU General Public License version 2 only, as
29.10 + * published by the Free Software Foundation. Sun designates this
29.11 + * particular file as subject to the "Classpath" exception as provided
29.12 + * by Sun in the LICENSE file that accompanied this code.
29.13 + *
29.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
29.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
29.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
29.17 + * version 2 for more details (a copy is included in the LICENSE file that
29.18 + * accompanied this code).
29.19 + *
29.20 + * You should have received a copy of the GNU General Public License version
29.21 + * 2 along with this work; if not, write to the Free Software Foundation,
29.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
29.23 + *
29.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
29.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
29.26 + * have any questions.
29.27 + */
29.28 +package com.sun.beans.decoder;
29.29 +
29.30 +import java.beans.XMLDecoder;
29.31 +
29.32 +/**
29.33 + * This class is intended to handle <java> element.
29.34 + * Each element that appears in the body of this element
29.35 + * is evaluated in the context of the decoder itself.
29.36 + * Typically this outer context is used to retrieve the owner of the decoder,
29.37 + * which can be set before reading the archive.
29.38 + * <p>The following atributes are supported:
29.39 + * <dl>
29.40 + * <dt>version
29.41 + * <dd>the Java version (not supported)
29.42 + * <dt>class
29.43 + * <dd>the type of preferable parser (not supported)
29.44 + * <dt>id
29.45 + * <dd>the identifier of the variable that is intended to store the result
29.46 + * </dl>
29.47 + *
29.48 + * @see DocumentHandler#getOwner
29.49 + * @see DocumentHandler#setOwner
29.50 + * @since 1.7
29.51 + *
29.52 + * @author Sergey A. Malenkov
29.53 + */
29.54 +final class JavaElementHandler extends ElementHandler {
29.55 + private Class<?> type;
29.56 + private ValueObject value;
29.57 +
29.58 + /**
29.59 + * Parses attributes of the element.
29.60 + * The following atributes are supported:
29.61 + * <dl>
29.62 + * <dt>version
29.63 + * <dd>the Java version (not supported)
29.64 + * <dt>class
29.65 + * <dd>the type of preferable parser (not supported)
29.66 + * <dt>id
29.67 + * <dd>the identifier of the variable that is intended to store the result
29.68 + * </dl>
29.69 + *
29.70 + * @param name the attribute name
29.71 + * @param value the attribute value
29.72 + */
29.73 + @Override
29.74 + public void addAttribute(String name, String value) {
29.75 + if (name.equals("version")) { // NON-NLS: the attribute name
29.76 + // unsupported attribute
29.77 + } else if (name.equals("class")) { // NON-NLS: the attribute name
29.78 + // check class for owner
29.79 + this.type = getOwner().findClass(value);
29.80 + } else {
29.81 + super.addAttribute(name, value);
29.82 + }
29.83 + }
29.84 +
29.85 + /**
29.86 + * Adds the argument to the list of readed objects.
29.87 + *
29.88 + * @param argument the value of the element that contained in this one
29.89 + */
29.90 + @Override
29.91 + protected void addArgument(Object argument) {
29.92 + getOwner().addObject(argument);
29.93 + }
29.94 +
29.95 + /**
29.96 + * Tests whether the value of this element can be used
29.97 + * as an argument of the element that contained in this one.
29.98 + *
29.99 + * @return {@code true} if the value of this element should be used
29.100 + * as an argument of the element that contained in this one,
29.101 + * {@code false} otherwise
29.102 + */
29.103 + @Override
29.104 + protected boolean isArgument() {
29.105 + return false; // do not use owner as object
29.106 + }
29.107 +
29.108 + /**
29.109 + * Returns the value of this element.
29.110 + *
29.111 + * @return the value of this element
29.112 + */
29.113 + @Override
29.114 + protected ValueObject getValueObject() {
29.115 + if (this.value == null) {
29.116 + this.value = ValueObjectImpl.create(getValue());
29.117 + }
29.118 + return this.value;
29.119 + }
29.120 +
29.121 + /**
29.122 + * Returns the owner of the owner document handler
29.123 + * as a value of <java> element.
29.124 + *
29.125 + * @return the owner of the owner document handler
29.126 + */
29.127 + private Object getValue() {
29.128 + Object owner = getOwner().getOwner();
29.129 + if ((this.type == null) || isValid(owner)) {
29.130 + return owner;
29.131 + }
29.132 + if (owner instanceof XMLDecoder) {
29.133 + XMLDecoder decoder = (XMLDecoder) owner;
29.134 + owner = decoder.getOwner();
29.135 + if (isValid(owner)) {
29.136 + return owner;
29.137 + }
29.138 + }
29.139 + throw new IllegalStateException("Unexpected owner class: " + owner.getClass().getName());
29.140 + }
29.141 +
29.142 + /**
29.143 + * Validates the owner of the <java> element.
29.144 + * The owner is valid if it is {@code null} or an instance
29.145 + * of the class specified by the {@code class} attribute.
29.146 + *
29.147 + * @param owner the owner of the <java> element
29.148 + * @return {@code true} if the {@code owner} is valid;
29.149 + * {@code false} otherwise
29.150 + */
29.151 + private boolean isValid(Object owner) {
29.152 + return (owner == null) || this.type.isInstance(owner);
29.153 + }
29.154 +}
30.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
30.2 +++ b/src/share/classes/com/sun/beans/decoder/LongElementHandler.java Tue Feb 03 22:02:55 2009 -0800
30.3 @@ -0,0 +1,63 @@
30.4 +/*
30.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
30.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
30.7 + *
30.8 + * This code is free software; you can redistribute it and/or modify it
30.9 + * under the terms of the GNU General Public License version 2 only, as
30.10 + * published by the Free Software Foundation. Sun designates this
30.11 + * particular file as subject to the "Classpath" exception as provided
30.12 + * by Sun in the LICENSE file that accompanied this code.
30.13 + *
30.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
30.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
30.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
30.17 + * version 2 for more details (a copy is included in the LICENSE file that
30.18 + * accompanied this code).
30.19 + *
30.20 + * You should have received a copy of the GNU General Public License version
30.21 + * 2 along with this work; if not, write to the Free Software Foundation,
30.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
30.23 + *
30.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
30.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
30.26 + * have any questions.
30.27 + */
30.28 +package com.sun.beans.decoder;
30.29 +
30.30 +/**
30.31 + * This class is intended to handle <long> element.
30.32 + * This element specifies {@code long} values.
30.33 + * The class {@link Long} is used as wrapper for these values.
30.34 + * The result value is created from text of the body of this element.
30.35 + * The body parsing is described in the class {@link StringElementHandler}.
30.36 + * For example:<pre>
30.37 + * <long>0xFFFF</long></pre>
30.38 + * is shortcut to<pre>
30.39 + * <method name="decode" class="java.lang.Long">
30.40 + * <string>0xFFFF</string>
30.41 + * </method></pre>
30.42 + * which is equivalent to {@code Long.decode("0xFFFF")} in Java code.
30.43 + * <p>The following atribute is supported:
30.44 + * <dl>
30.45 + * <dt>id
30.46 + * <dd>the identifier of the variable that is intended to store the result
30.47 + * </dl>
30.48 + *
30.49 + * @since 1.7
30.50 + *
30.51 + * @author Sergey A. Malenkov
30.52 + */
30.53 +final class LongElementHandler extends StringElementHandler {
30.54 +
30.55 + /**
30.56 + * Creates {@code long} value from
30.57 + * the text of the body of this element.
30.58 + *
30.59 + * @param argument the text of the body
30.60 + * @return evaluated {@code long} value
30.61 + */
30.62 + @Override
30.63 + public Object getValue(String argument) {
30.64 + return Long.decode(argument);
30.65 + }
30.66 +}
31.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
31.2 +++ b/src/share/classes/com/sun/beans/decoder/MethodElementHandler.java Tue Feb 03 22:02:55 2009 -0800
31.3 @@ -0,0 +1,109 @@
31.4 +/*
31.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
31.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
31.7 + *
31.8 + * This code is free software; you can redistribute it and/or modify it
31.9 + * under the terms of the GNU General Public License version 2 only, as
31.10 + * published by the Free Software Foundation. Sun designates this
31.11 + * particular file as subject to the "Classpath" exception as provided
31.12 + * by Sun in the LICENSE file that accompanied this code.
31.13 + *
31.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
31.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
31.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
31.17 + * version 2 for more details (a copy is included in the LICENSE file that
31.18 + * accompanied this code).
31.19 + *
31.20 + * You should have received a copy of the GNU General Public License version
31.21 + * 2 along with this work; if not, write to the Free Software Foundation,
31.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
31.23 + *
31.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
31.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
31.26 + * have any questions.
31.27 + */
31.28 +package com.sun.beans.decoder;
31.29 +
31.30 +import com.sun.beans.finder.MethodFinder;
31.31 +
31.32 +import java.lang.reflect.Method;
31.33 +
31.34 +/**
31.35 + * This class is intended to handle <method> element.
31.36 + * It describes invocation of the method.
31.37 + * The {@code name} attribute denotes
31.38 + * the name of the method to invoke.
31.39 + * If the {@code class} attribute is specified
31.40 + * this element invokes static method of specified class.
31.41 + * The inner elements specifies the arguments of the method.
31.42 + * For example:<pre>
31.43 + * <method name="valueOf" class="java.lang.Long">
31.44 + * <string>10</string>
31.45 + * </method></pre>
31.46 + * is equivalent to {@code Long.valueOf("10")} in Java code.
31.47 + * <p>The following atributes are supported:
31.48 + * <dl>
31.49 + * <dt>name
31.50 + * <dd>the method name
31.51 + * <dt>class
31.52 + * <dd>the type of object for instantiation
31.53 + * <dt>id
31.54 + * <dd>the identifier of the variable that is intended to store the result
31.55 + * </dl>
31.56 + *
31.57 + * @since 1.7
31.58 + *
31.59 + * @author Sergey A. Malenkov
31.60 + */
31.61 +final class MethodElementHandler extends NewElementHandler {
31.62 + private String name;
31.63 +
31.64 + /**
31.65 + * Parses attributes of the element.
31.66 + * The following atributes are supported:
31.67 + * <dl>
31.68 + * <dt>name
31.69 + * <dd>the method name
31.70 + * <dt>class
31.71 + * <dd>the type of object for instantiation
31.72 + * <dt>id
31.73 + * <dd>the identifier of the variable that is intended to store the result
31.74 + * </dl>
31.75 + *
31.76 + * @param name the attribute name
31.77 + * @param value the attribute value
31.78 + */
31.79 + @Override
31.80 + public void addAttribute(String name, String value) {
31.81 + if (name.equals("name")) { // NON-NLS: the attribute name
31.82 + this.name = value;
31.83 + } else {
31.84 + super.addAttribute(name, value);
31.85 + }
31.86 + }
31.87 +
31.88 + /**
31.89 + * Returns the result of method execution.
31.90 + *
31.91 + * @param type the base class
31.92 + * @param args the array of arguments
31.93 + * @return the value of this element
31.94 + * @throws Exception if calculation is failed
31.95 + */
31.96 + @Override
31.97 + protected ValueObject getValueObject(Class<?> type, Object[] args) throws Exception {
31.98 + Object bean = getContextBean();
31.99 + Class<?>[] types = getArgumentTypes(args);
31.100 + Method method = (type != null)
31.101 + ? MethodFinder.findStaticMethod(type, this.name, types)
31.102 + : MethodFinder.findMethod(bean.getClass(), this.name, types);
31.103 +
31.104 + if (method.isVarArgs()) {
31.105 + args = getArguments(args, method.getParameterTypes());
31.106 + }
31.107 + Object value = method.invoke(bean, args);
31.108 + return method.getReturnType().equals(void.class)
31.109 + ? ValueObjectImpl.VOID
31.110 + : ValueObjectImpl.create(value);
31.111 + }
31.112 +}
32.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
32.2 +++ b/src/share/classes/com/sun/beans/decoder/NewElementHandler.java Tue Feb 03 22:02:55 2009 -0800
32.3 @@ -0,0 +1,205 @@
32.4 +/*
32.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
32.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
32.7 + *
32.8 + * This code is free software; you can redistribute it and/or modify it
32.9 + * under the terms of the GNU General Public License version 2 only, as
32.10 + * published by the Free Software Foundation. Sun designates this
32.11 + * particular file as subject to the "Classpath" exception as provided
32.12 + * by Sun in the LICENSE file that accompanied this code.
32.13 + *
32.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
32.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
32.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
32.17 + * version 2 for more details (a copy is included in the LICENSE file that
32.18 + * accompanied this code).
32.19 + *
32.20 + * You should have received a copy of the GNU General Public License version
32.21 + * 2 along with this work; if not, write to the Free Software Foundation,
32.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
32.23 + *
32.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
32.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
32.26 + * have any questions.
32.27 + */
32.28 +package com.sun.beans.decoder;
32.29 +
32.30 +import com.sun.beans.finder.ConstructorFinder;
32.31 +
32.32 +import java.lang.reflect.Array;
32.33 +import java.lang.reflect.Constructor;
32.34 +
32.35 +import java.util.ArrayList;
32.36 +import java.util.List;
32.37 +
32.38 +/**
32.39 + * This class is intended to handle <new> element.
32.40 + * It describes instantiation of the object.
32.41 + * The {@code class} attribute denotes
32.42 + * the name of the class to instantiate.
32.43 + * The inner elements specifies the arguments of the constructor.
32.44 + * For example:<pre>
32.45 + * <new class="java.lang.Long">
32.46 + * <string>10</string>
32.47 + * </new></pre>
32.48 + * is equivalent to {@code new Long("10")} in Java code.
32.49 + * <p>The following atributes are supported:
32.50 + * <dl>
32.51 + * <dt>class
32.52 + * <dd>the type of object for instantiation
32.53 + * <dt>id
32.54 + * <dd>the identifier of the variable that is intended to store the result
32.55 + * </dl>
32.56 + *
32.57 + * @since 1.7
32.58 + *
32.59 + * @author Sergey A. Malenkov
32.60 + */
32.61 +class NewElementHandler extends ElementHandler {
32.62 + private List<Object> arguments = new ArrayList<Object>();
32.63 + private ValueObject value = ValueObjectImpl.VOID;
32.64 +
32.65 + private Class<?> type;
32.66 +
32.67 + /**
32.68 + * Parses attributes of the element.
32.69 + * The following atributes are supported:
32.70 + * <dl>
32.71 + * <dt>class
32.72 + * <dd>the type of object for instantiation
32.73 + * <dt>id
32.74 + * <dd>the identifier of the variable that is intended to store the result
32.75 + * </dl>
32.76 + *
32.77 + * @param name the attribute name
32.78 + * @param value the attribute value
32.79 + */
32.80 + @Override
32.81 + public void addAttribute(String name, String value) {
32.82 + if (name.equals("class")) { // NON-NLS: the attribute name
32.83 + this.type = getOwner().findClass(value);
32.84 + } else {
32.85 + super.addAttribute(name, value);
32.86 + }
32.87 + }
32.88 +
32.89 + /**
32.90 + * Adds the argument to the list of arguments
32.91 + * that is used to calculate the value of this element.
32.92 + *
32.93 + * @param argument the value of the element that contained in this one
32.94 + */
32.95 + @Override
32.96 + protected final void addArgument(Object argument) {
32.97 + if (this.arguments == null) {
32.98 + throw new IllegalStateException("Could not add argument to evaluated element");
32.99 + }
32.100 + this.arguments.add(argument);
32.101 + }
32.102 +
32.103 + /**
32.104 + * Returns the context of the method.
32.105 + * The context of the static method is the class object.
32.106 + * The context of the non-static method is the value of the parent element.
32.107 + *
32.108 + * @return the context of the method
32.109 + */
32.110 + @Override
32.111 + protected final Object getContextBean() {
32.112 + return (this.type != null)
32.113 + ? this.type
32.114 + : super.getContextBean();
32.115 + }
32.116 +
32.117 + /**
32.118 + * Returns the value of this element.
32.119 + *
32.120 + * @return the value of this element
32.121 + */
32.122 + @Override
32.123 + protected final ValueObject getValueObject() {
32.124 + if (this.arguments != null) {
32.125 + try {
32.126 + this.value = getValueObject(this.type, this.arguments.toArray());
32.127 + }
32.128 + catch (Exception exception) {
32.129 + getOwner().handleException(exception);
32.130 + }
32.131 + finally {
32.132 + this.arguments = null;
32.133 + }
32.134 + }
32.135 + return this.value;
32.136 + }
32.137 +
32.138 + /**
32.139 + * Calculates the value of this element
32.140 + * using the base class and the array of arguments.
32.141 + * By default, it creates an instance of the base class.
32.142 + * This method should be overridden in those handlers
32.143 + * that extend behavior of this element.
32.144 + *
32.145 + * @param type the base class
32.146 + * @param args the array of arguments
32.147 + * @return the value of this element
32.148 + * @throws Exception if calculation is failed
32.149 + */
32.150 + ValueObject getValueObject(Class<?> type, Object[] args) throws Exception {
32.151 + if (type == null) {
32.152 + throw new IllegalArgumentException("Class name is not set");
32.153 + }
32.154 + Class<?>[] types = getArgumentTypes(args);
32.155 + Constructor<?> constructor = ConstructorFinder.findConstructor(type, types);
32.156 + if (constructor.isVarArgs()) {
32.157 + args = getArguments(args, constructor.getParameterTypes());
32.158 + }
32.159 + return ValueObjectImpl.create(constructor.newInstance(args));
32.160 + }
32.161 +
32.162 + /**
32.163 + * Converts the array of arguments to the array of corresponding classes.
32.164 + * If argument is {@code null} the class is {@code null} too.
32.165 + *
32.166 + * @param arguments the array of arguments
32.167 + * @return the array of corresponding classes
32.168 + */
32.169 + static Class<?>[] getArgumentTypes(Object[] arguments) {
32.170 + Class<?>[] types = new Class<?>[arguments.length];
32.171 + for (int i = 0; i < arguments.length; i++) {
32.172 + if (arguments[i] != null) {
32.173 + types[i] = arguments[i].getClass();
32.174 + }
32.175 + }
32.176 + return types;
32.177 + }
32.178 +
32.179 + /**
32.180 + * Resolves variable arguments.
32.181 + *
32.182 + * @param arguments the array of arguments
32.183 + * @param types the array of parameter types
32.184 + * @return the resolved array of arguments
32.185 + */
32.186 + static Object[] getArguments(Object[] arguments, Class<?>[] types) {
32.187 + int index = types.length - 1;
32.188 + if (types.length == arguments.length) {
32.189 + Object argument = arguments[index];
32.190 + if (argument == null) {
32.191 + return arguments;
32.192 + }
32.193 + Class<?> type = types[index];
32.194 + if (type.isAssignableFrom(argument.getClass())) {
32.195 + return arguments;
32.196 + }
32.197 + }
32.198 + int length = arguments.length - index;
32.199 + Class<?> type = types[index].getComponentType();
32.200 + Object array = Array.newInstance(type, length);
32.201 + System.arraycopy(arguments, index, array, 0, length);
32.202 +
32.203 + Object[] args = new Object[types.length];
32.204 + System.arraycopy(arguments, 0, args, 0, index);
32.205 + args[index] = array;
32.206 + return args;
32.207 + }
32.208 +}
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
33.2 +++ b/src/share/classes/com/sun/beans/decoder/NullElementHandler.java Tue Feb 03 22:02:55 2009 -0800
33.3 @@ -0,0 +1,76 @@
33.4 +/*
33.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
33.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33.7 + *
33.8 + * This code is free software; you can redistribute it and/or modify it
33.9 + * under the terms of the GNU General Public License version 2 only, as
33.10 + * published by the Free Software Foundation. Sun designates this
33.11 + * particular file as subject to the "Classpath" exception as provided
33.12 + * by Sun in the LICENSE file that accompanied this code.
33.13 + *
33.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
33.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
33.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
33.17 + * version 2 for more details (a copy is included in the LICENSE file that
33.18 + * accompanied this code).
33.19 + *
33.20 + * You should have received a copy of the GNU General Public License version
33.21 + * 2 along with this work; if not, write to the Free Software Foundation,
33.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
33.23 + *
33.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
33.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
33.26 + * have any questions.
33.27 + */
33.28 +package com.sun.beans.decoder;
33.29 +
33.30 +/**
33.31 + * This class is intended to handle <null> element.
33.32 + * This element specifies {@code null} value.
33.33 + * It should not contain body or inner elements.
33.34 + * For example:<pre>
33.35 + * <null/></pre>
33.36 + * is equivalent to {@code null} in Java code.
33.37 + * <p>The following atribute is supported:
33.38 + * <dl>
33.39 + * <dt>id
33.40 + * <dd>the identifier of the variable that is intended to store the result
33.41 + * </dl>
33.42 + *
33.43 + * @since 1.7
33.44 + *
33.45 + * @author Sergey A. Malenkov
33.46 + */
33.47 +class NullElementHandler extends ElementHandler implements ValueObject {
33.48 +
33.49 + /**
33.50 + * Returns the value of this element.
33.51 + *
33.52 + * @return the value of this element
33.53 + */
33.54 + @Override
33.55 + protected final ValueObject getValueObject() {
33.56 + return this;
33.57 + }
33.58 +
33.59 + /**
33.60 + * Returns {@code null}
33.61 + * as a value of <null> element.
33.62 + * This method should be overridden in those handlers
33.63 + * that extend behavior of this element.
33.64 + *
33.65 + * @return {@code null} by default
33.66 + */
33.67 + public Object getValue() {
33.68 + return null;
33.69 + }
33.70 +
33.71 + /**
33.72 + * Returns {@code void} state of this value object.
33.73 + *
33.74 + * @return {@code false} always
33.75 + */
33.76 + public final boolean isVoid() {
33.77 + return false;
33.78 + }
33.79 +}
34.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
34.2 +++ b/src/share/classes/com/sun/beans/decoder/ObjectElementHandler.java Tue Feb 03 22:02:55 2009 -0800
34.3 @@ -0,0 +1,168 @@
34.4 +/*
34.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
34.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
34.7 + *
34.8 + * This code is free software; you can redistribute it and/or modify it
34.9 + * under the terms of the GNU General Public License version 2 only, as
34.10 + * published by the Free Software Foundation. Sun designates this
34.11 + * particular file as subject to the "Classpath" exception as provided
34.12 + * by Sun in the LICENSE file that accompanied this code.
34.13 + *
34.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
34.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
34.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
34.17 + * version 2 for more details (a copy is included in the LICENSE file that
34.18 + * accompanied this code).
34.19 + *
34.20 + * You should have received a copy of the GNU General Public License version
34.21 + * 2 along with this work; if not, write to the Free Software Foundation,
34.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
34.23 + *
34.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
34.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
34.26 + * have any questions.
34.27 + */
34.28 +package com.sun.beans.decoder;
34.29 +
34.30 +import java.beans.Expression;
34.31 +
34.32 +import static java.util.Locale.ENGLISH;
34.33 +
34.34 +/**
34.35 + * This class is intended to handle <object> element.
34.36 + * This element looks like <void> element,
34.37 + * but its value is always used as an argument for element
34.38 + * that contains this one.
34.39 + * <p>The following atributes are supported:
34.40 + * <dl>
34.41 + * <dt>class
34.42 + * <dd>the type is used for static methods and fields
34.43 + * <dt>method
34.44 + * <dd>the method name
34.45 + * <dt>property
34.46 + * <dd>the property name
34.47 + * <dt>index
34.48 + * <dd>the property index
34.49 + * <dt>field
34.50 + * <dd>the field name
34.51 + * <dt>idref
34.52 + * <dd>the identifier to refer to the variable
34.53 + * <dt>id
34.54 + * <dd>the identifier of the variable that is intended to store the result
34.55 + * </dl>
34.56 + *
34.57 + * @since 1.7
34.58 + *
34.59 + * @author Sergey A. Malenkov
34.60 + */
34.61 +class ObjectElementHandler extends NewElementHandler {
34.62 + private String idref;
34.63 + private String field;
34.64 + private Integer index;
34.65 + private String property;
34.66 + private String method;
34.67 +
34.68 + /**
34.69 + * Parses attributes of the element.
34.70 + * The following atributes are supported:
34.71 + * <dl>
34.72 + * <dt>class
34.73 + * <dd>the type is used for static methods and fields
34.74 + * <dt>method
34.75 + * <dd>the method name
34.76 + * <dt>property
34.77 + * <dd>the property name
34.78 + * <dt>index
34.79 + * <dd>the property index
34.80 + * <dt>field
34.81 + * <dd>the field name
34.82 + * <dt>idref
34.83 + * <dd>the identifier to refer to the variable
34.84 + * <dt>id
34.85 + * <dd>the identifier of the variable that is intended to store the result
34.86 + * </dl>
34.87 + *
34.88 + * @param name the attribute name
34.89 + * @param value the attribute value
34.90 + */
34.91 + @Override
34.92 + public final void addAttribute(String name, String value) {
34.93 + if (name.equals("idref")) { // NON-NLS: the attribute name
34.94 + this.idref = value;
34.95 + } else if (name.equals("field")) { // NON-NLS: the attribute name
34.96 + this.field = value;
34.97 + } else if (name.equals("index")) { // NON-NLS: the attribute name
34.98 + this.index = Integer.valueOf(value);
34.99 + addArgument(this.index); // hack for compatibility
34.100 + } else if (name.equals("property")) { // NON-NLS: the attribute name
34.101 + this.property = value;
34.102 + } else if (name.equals("method")) { // NON-NLS: the attribute name
34.103 + this.method = value;
34.104 + } else {
34.105 + super.addAttribute(name, value);
34.106 + }
34.107 + }
34.108 +
34.109 + /**
34.110 + * Calculates the value of this element
34.111 + * if the field attribute or the idref attribute is set.
34.112 + */
34.113 + @Override
34.114 + public final void startElement() {
34.115 + if ((this.field != null) || (this.idref != null)) {
34.116 + getValueObject();
34.117 + }
34.118 + }
34.119 +
34.120 + /**
34.121 + * Tests whether the value of this element can be used
34.122 + * as an argument of the element that contained in this one.
34.123 + *
34.124 + * @return {@code true} if the value of this element can be used
34.125 + * as an argument of the element that contained in this one,
34.126 + * {@code false} otherwise
34.127 + */
34.128 + @Override
34.129 + protected boolean isArgument() {
34.130 + return true; // hack for compatibility
34.131 + }
34.132 +
34.133 + /**
34.134 + * Creates the value of this element.
34.135 + *
34.136 + * @param type the base class
34.137 + * @param args the array of arguments
34.138 + * @return the value of this element
34.139 + * @throws Exception if calculation is failed
34.140 + */
34.141 + @Override
34.142 + protected final ValueObject getValueObject(Class<?> type, Object[] args) throws Exception {
34.143 + if (this.field != null) {
34.144 + return ValueObjectImpl.create(FieldElementHandler.getFieldValue(getContextBean(), this.field));
34.145 + }
34.146 + if (this.idref != null) {
34.147 + return ValueObjectImpl.create(getVariable(this.idref));
34.148 + }
34.149 + Object bean = getContextBean();
34.150 + String name;
34.151 + if (this.index != null) {
34.152 + name = (args.length == 2)
34.153 + ? PropertyElementHandler.SETTER
34.154 + : PropertyElementHandler.GETTER;
34.155 + } else if (this.property != null) {
34.156 + name = (args.length == 1)
34.157 + ? PropertyElementHandler.SETTER
34.158 + : PropertyElementHandler.GETTER;
34.159 +
34.160 + if (0 < this.property.length()) {
34.161 + name += this.property.substring(0, 1).toUpperCase(ENGLISH) + this.property.substring(1);
34.162 + }
34.163 + } else {
34.164 + name = (this.method != null) && (0 < this.method.length())
34.165 + ? this.method
34.166 + : "new"; // NON-NLS: the constructor marker
34.167 + }
34.168 + Expression expression = new Expression(bean, name, args);
34.169 + return ValueObjectImpl.create(expression.getValue());
34.170 + }
34.171 +}
35.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
35.2 +++ b/src/share/classes/com/sun/beans/decoder/PropertyElementHandler.java Tue Feb 03 22:02:55 2009 -0800
35.3 @@ -0,0 +1,287 @@
35.4 +/*
35.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
35.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
35.7 + *
35.8 + * This code is free software; you can redistribute it and/or modify it
35.9 + * under the terms of the GNU General Public License version 2 only, as
35.10 + * published by the Free Software Foundation. Sun designates this
35.11 + * particular file as subject to the "Classpath" exception as provided
35.12 + * by Sun in the LICENSE file that accompanied this code.
35.13 + *
35.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
35.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
35.17 + * version 2 for more details (a copy is included in the LICENSE file that
35.18 + * accompanied this code).
35.19 + *
35.20 + * You should have received a copy of the GNU General Public License version
35.21 + * 2 along with this work; if not, write to the Free Software Foundation,
35.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
35.23 + *
35.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
35.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
35.26 + * have any questions.
35.27 + */
35.28 +package com.sun.beans.decoder;
35.29 +
35.30 +import com.sun.beans.finder.MethodFinder;
35.31 +
35.32 +import java.beans.IndexedPropertyDescriptor;
35.33 +import java.beans.IntrospectionException;
35.34 +import java.beans.Introspector;
35.35 +import java.beans.PropertyDescriptor;
35.36 +
35.37 +import java.lang.reflect.Array;
35.38 +import java.lang.reflect.InvocationTargetException;
35.39 +import java.lang.reflect.Method;
35.40 +
35.41 +/**
35.42 + * This class is intended to handle <property> element.
35.43 + * This element simplifies access to the properties.
35.44 + * If the {@code index} attribute is specified
35.45 + * this element uses additional {@code int} parameter.
35.46 + * If the {@code name} attribute is not specified
35.47 + * this element uses method "get" as getter
35.48 + * and method "set" as setter.
35.49 + * This element defines getter if it contains no argument.
35.50 + * It returns the value of the property in this case.
35.51 + * For example:<pre>
35.52 + * <property name="object" index="10"/></pre>
35.53 + * is shortcut to<pre>
35.54 + * <method name="getObject">
35.55 + * <int>10</int>
35.56 + * </method></pre>
35.57 + * which is equivalent to {@code getObject(10)} in Java code.
35.58 + * This element defines setter if it contains one argument.
35.59 + * It does not return the value of the property in this case.
35.60 + * For example:<pre>
35.61 + * <property><int>0</int></property></pre>
35.62 + * is shortcut to<pre>
35.63 + * <method name="set">
35.64 + * <int>0</int>
35.65 + * </method></pre>
35.66 + * which is equivalent to {@code set(0)} in Java code.
35.67 + * <p>The following atributes are supported:
35.68 + * <dl>
35.69 + * <dt>name
35.70 + * <dd>the property name
35.71 + * <dt>index
35.72 + * <dd>the property index
35.73 + * <dt>id
35.74 + * <dd>the identifier of the variable that is intended to store the result
35.75 + * </dl>
35.76 + *
35.77 + * @since 1.7
35.78 + *
35.79 + * @author Sergey A. Malenkov
35.80 + */
35.81 +final class PropertyElementHandler extends AccessorElementHandler {
35.82 + static final String GETTER = "get"; // NON-NLS: the getter prefix
35.83 + static final String SETTER = "set"; // NON-NLS: the setter prefix
35.84 +
35.85 + private Integer index;
35.86 +
35.87 + /**
35.88 + * Parses attributes of the element.
35.89 + * The following atributes are supported:
35.90 + * <dl>
35.91 + * <dt>name
35.92 + * <dd>the property name
35.93 + * <dt>index
35.94 + * <dd>the property index
35.95 + * <dt>id
35.96 + * <dd>the identifier of the variable that is intended to store the result
35.97 + * </dl>
35.98 + *
35.99 + * @param name the attribute name
35.100 + * @param value the attribute value
35.101 + */
35.102 + @Override
35.103 + public void addAttribute(String name, String value) {
35.104 + if (name.equals("index")) { // NON-NLS: the attribute name
35.105 + this.index = Integer.valueOf(value);
35.106 + } else {
35.107 + super.addAttribute(name, value);
35.108 + }
35.109 + }
35.110 +
35.111 + /**
35.112 + * Tests whether the value of this element can be used
35.113 + * as an argument of the element that contained in this one.
35.114 + *
35.115 + * @return {@code true} if the value of this element should be used
35.116 + * as an argument of the element that contained in this one,
35.117 + * {@code false} otherwise
35.118 + */
35.119 + @Override
35.120 + protected boolean isArgument() {
35.121 + return false; // non-static accessor cannot be used an argument
35.122 + }
35.123 +
35.124 + /**
35.125 + * Returns the value of the property with specified {@code name}.
35.126 + *
35.127 + * @param name the name of the property
35.128 + * @return the value of the specified property
35.129 + */
35.130 + @Override
35.131 + protected Object getValue(String name) {
35.132 + try {
35.133 + return getPropertyValue(getContextBean(), name, this.index);
35.134 + }
35.135 + catch (Exception exception) {
35.136 + getOwner().handleException(exception);
35.137 + }
35.138 + return null;
35.139 + }
35.140 +
35.141 + /**
35.142 + * Sets the new value for the property with specified {@code name}.
35.143 + *
35.144 + * @param name the name of the property
35.145 + * @param value the new value for the specified property
35.146 + */
35.147 + @Override
35.148 + protected void setValue(String name, Object value) {
35.149 + try {
35.150 + setPropertyValue(getContextBean(), name, this.index, value);
35.151 + }
35.152 + catch (Exception exception) {
35.153 + getOwner().handleException(exception);
35.154 + }
35.155 + }
35.156 +
35.157 + /**
35.158 + * Performs the search of the getter for the property
35.159 + * with specified {@code name} in specified class
35.160 + * and returns value of the property.
35.161 + *
35.162 + * @param bean the context bean that contains property
35.163 + * @param name the name of the property
35.164 + * @param index the index of the indexed property
35.165 + * @return the value of the property
35.166 + * @throws IllegalAccessException if the property is not accesible
35.167 + * @throws IntrospectionException if the bean introspection is failed
35.168 + * @throws InvocationTargetException if the getter cannot be invoked
35.169 + * @throws NoSuchMethodException if the getter is not found
35.170 + */
35.171 + private static Object getPropertyValue(Object bean, String name, Integer index) throws IllegalAccessException, IntrospectionException, InvocationTargetException, NoSuchMethodException {
35.172 + Class<?> type = bean.getClass();
35.173 + if (index == null) {
35.174 + return findGetter(type, name).invoke(bean);
35.175 + } else if (type.isArray() && (name == null)) {
35.176 + return Array.get(bean, index);
35.177 + } else {
35.178 + return findGetter(type, name, int.class).invoke(bean, index);
35.179 + }
35.180 + }
35.181 +
35.182 + /**
35.183 + * Performs the search of the setter for the property
35.184 + * with specified {@code name} in specified class
35.185 + * and updates value of the property.
35.186 + *
35.187 + * @param bean the context bean that contains property
35.188 + * @param name the name of the property
35.189 + * @param index the index of the indexed property
35.190 + * @param value the new value for the property
35.191 + * @throws IllegalAccessException if the property is not accesible
35.192 + * @throws IntrospectionException if the bean introspection is failed
35.193 + * @throws InvocationTargetException if the setter cannot be invoked
35.194 + * @throws NoSuchMethodException if the setter is not found
35.195 + */
35.196 + private static void setPropertyValue(Object bean, String name, Integer index, Object value) throws IllegalAccessException, IntrospectionException, InvocationTargetException, NoSuchMethodException {
35.197 + Class<?> type = bean.getClass();
35.198 + Class<?> param = (value != null)
35.199 + ? value.getClass()
35.200 + : null;
35.201 +
35.202 + if (index == null) {
35.203 + findSetter(type, name, param).invoke(bean, value);
35.204 + } else if (type.isArray() && (name == null)) {
35.205 + Array.set(bean, index, value);
35.206 + } else {
35.207 + findSetter(type, name, int.class, param).invoke(bean, index, value);
35.208 + }
35.209 + }
35.210 +
35.211 + /**
35.212 + * Performs the search of the getter for the property
35.213 + * with specified {@code name} in specified class.
35.214 + *
35.215 + * @param type the class that contains method
35.216 + * @param name the name of the property
35.217 + * @param args the method arguments
35.218 + * @return method object that represents found getter
35.219 + * @throws IntrospectionException if the bean introspection is failed
35.220 + * @throws NoSuchMethodException if method is not found
35.221 + */
35.222 + private static Method findGetter(Class<?> type, String name, Class<?>...args) throws IntrospectionException, NoSuchMethodException {
35.223 + if (name == null) {
35.224 + return MethodFinder.findInstanceMethod(type, GETTER, args);
35.225 + }
35.226 + PropertyDescriptor pd = getProperty(type, name);
35.227 + if (args.length == 0) {
35.228 + Method method = pd.getReadMethod();
35.229 + if (method != null) {
35.230 + return method;
35.231 + }
35.232 + } else if (pd instanceof IndexedPropertyDescriptor) {
35.233 + IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
35.234 + Method method = ipd.getIndexedReadMethod();
35.235 + if (method != null) {
35.236 + return method;
35.237 + }
35.238 + }
35.239 + throw new IntrospectionException("Could not find getter for the " + name + " property");
35.240 + }
35.241 +
35.242 + /**
35.243 + * Performs the search of the setter for the property
35.244 + * with specified {@code name} in specified class.
35.245 + *
35.246 + * @param type the class that contains method
35.247 + * @param name the name of the property
35.248 + * @param args the method arguments
35.249 + * @return method object that represents found setter
35.250 + * @throws IntrospectionException if the bean introspection is failed
35.251 + * @throws NoSuchMethodException if method is not found
35.252 + */
35.253 + private static Method findSetter(Class<?> type, String name, Class<?>...args) throws IntrospectionException, NoSuchMethodException {
35.254 + if (name == null) {
35.255 + return MethodFinder.findInstanceMethod(type, SETTER, args);
35.256 + }
35.257 + PropertyDescriptor pd = getProperty(type, name);
35.258 + if (args.length == 1) {
35.259 + Method method = pd.getWriteMethod();
35.260 + if (method != null) {
35.261 + return method;
35.262 + }
35.263 + } else if (pd instanceof IndexedPropertyDescriptor) {
35.264 + IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
35.265 + Method method = ipd.getIndexedWriteMethod();
35.266 + if (method != null) {
35.267 + return method;
35.268 + }
35.269 + }
35.270 + throw new IntrospectionException("Could not find setter for the " + name + " property");
35.271 + }
35.272 +
35.273 + /**
35.274 + * Performs the search of the descriptor for the property
35.275 + * with specified {@code name} in specified class.
35.276 + *
35.277 + * @param type the class to introspect
35.278 + * @param name the property name
35.279 + * @return descriptor for the named property
35.280 + * @throws IntrospectionException if property descriptor is not found
35.281 + */
35.282 + private static PropertyDescriptor getProperty(Class<?> type, String name) throws IntrospectionException {
35.283 + for (PropertyDescriptor pd : Introspector.getBeanInfo(type).getPropertyDescriptors()) {
35.284 + if (name.equals(pd.getName())) {
35.285 + return pd;
35.286 + }
35.287 + }
35.288 + throw new IntrospectionException("Could not find the " + name + " property descriptor");
35.289 + }
35.290 +}
36.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
36.2 +++ b/src/share/classes/com/sun/beans/decoder/ShortElementHandler.java Tue Feb 03 22:02:55 2009 -0800
36.3 @@ -0,0 +1,63 @@
36.4 +/*
36.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
36.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
36.7 + *
36.8 + * This code is free software; you can redistribute it and/or modify it
36.9 + * under the terms of the GNU General Public License version 2 only, as
36.10 + * published by the Free Software Foundation. Sun designates this
36.11 + * particular file as subject to the "Classpath" exception as provided
36.12 + * by Sun in the LICENSE file that accompanied this code.
36.13 + *
36.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
36.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
36.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
36.17 + * version 2 for more details (a copy is included in the LICENSE file that
36.18 + * accompanied this code).
36.19 + *
36.20 + * You should have received a copy of the GNU General Public License version
36.21 + * 2 along with this work; if not, write to the Free Software Foundation,
36.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
36.23 + *
36.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
36.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
36.26 + * have any questions.
36.27 + */
36.28 +package com.sun.beans.decoder;
36.29 +
36.30 +/**
36.31 + * This class is intended to handle <short> element.
36.32 + * This element specifies {@code short} values.
36.33 + * The class {@link Short} is used as wrapper for these values.
36.34 + * The result value is created from text of the body of this element.
36.35 + * The body parsing is described in the class {@link StringElementHandler}.
36.36 + * For example:<pre>
36.37 + * <short>200</short></pre>
36.38 + * is shortcut to<pre>
36.39 + * <method name="decode" class="java.lang.Short">
36.40 + * <string>200</string>
36.41 + * </method></pre>
36.42 + * which is equivalent to {@code Short.decode("200")} in Java code.
36.43 + * <p>The following atribute is supported:
36.44 + * <dl>
36.45 + * <dt>id
36.46 + * <dd>the identifier of the variable that is intended to store the result
36.47 + * </dl>
36.48 + *
36.49 + * @since 1.7
36.50 + *
36.51 + * @author Sergey A. Malenkov
36.52 + */
36.53 +final class ShortElementHandler extends StringElementHandler {
36.54 +
36.55 + /**
36.56 + * Creates {@code short} value from
36.57 + * the text of the body of this element.
36.58 + *
36.59 + * @param argument the text of the body
36.60 + * @return evaluated {@code short} value
36.61 + */
36.62 + @Override
36.63 + public Object getValue(String argument) {
36.64 + return Short.decode(argument);
36.65 + }
36.66 +}
37.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
37.2 +++ b/src/share/classes/com/sun/beans/decoder/StringElementHandler.java Tue Feb 03 22:02:55 2009 -0800
37.3 @@ -0,0 +1,116 @@
37.4 +/*
37.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
37.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
37.7 + *
37.8 + * This code is free software; you can redistribute it and/or modify it
37.9 + * under the terms of the GNU General Public License version 2 only, as
37.10 + * published by the Free Software Foundation. Sun designates this
37.11 + * particular file as subject to the "Classpath" exception as provided
37.12 + * by Sun in the LICENSE file that accompanied this code.
37.13 + *
37.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
37.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
37.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
37.17 + * version 2 for more details (a copy is included in the LICENSE file that
37.18 + * accompanied this code).
37.19 + *
37.20 + * You should have received a copy of the GNU General Public License version
37.21 + * 2 along with this work; if not, write to the Free Software Foundation,
37.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
37.23 + *
37.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
37.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
37.26 + * have any questions.
37.27 + */
37.28 +package com.sun.beans.decoder;
37.29 +
37.30 +/**
37.31 + * This class is intended to handle <string> element.
37.32 + * This element specifies {@link String} values.
37.33 + * The result value is created from text of the body of this element.
37.34 + * For example:<pre>
37.35 + * <string>description</string></pre>
37.36 + * is equivalent to {@code "description"} in Java code.
37.37 + * The value of inner element is calculated
37.38 + * before adding to the string using {@link String#valueOf(Object)}.
37.39 + * Note that all characters are used including whitespaces (' ', '\t', '\n', '\r').
37.40 + * So the value of the element<pre>
37.41 + * <string><true></string></pre>
37.42 + * is not equal to the value of the element<pre>
37.43 + * <string>
37.44 + * <true>
37.45 + * </string></pre>
37.46 + * <p>The following atribute is supported:
37.47 + * <dl>
37.48 + * <dt>id
37.49 + * <dd>the identifier of the variable that is intended to store the result
37.50 + * </dl>
37.51 + *
37.52 + * @since 1.7
37.53 + *
37.54 + * @author Sergey A. Malenkov
37.55 + */
37.56 +public class StringElementHandler extends ElementHandler {
37.57 + private StringBuilder sb = new StringBuilder();
37.58 + private ValueObject value = ValueObjectImpl.NULL;
37.59 +
37.60 + /**
37.61 + * Adds the character that contained in this element.
37.62 + *
37.63 + * @param ch the character
37.64 + */
37.65 + @Override
37.66 + public final void addCharacter(char ch) {
37.67 + if (this.sb == null) {
37.68 + throw new IllegalStateException("Could not add chararcter to evaluated string element");
37.69 + }
37.70 + this.sb.append(ch);
37.71 + }
37.72 +
37.73 + /**
37.74 + * Adds the string value of the argument to the string value of this element.
37.75 + *
37.76 + * @param argument the value of the element that contained in this one
37.77 + */
37.78 + @Override
37.79 + protected final void addArgument(Object argument) {
37.80 + if (this.sb == null) {
37.81 + throw new IllegalStateException("Could not add argument to evaluated string element");
37.82 + }
37.83 + this.sb.append(argument);
37.84 + }
37.85 +
37.86 + /**
37.87 + * Returns the value of this element.
37.88 + *
37.89 + * @return the value of this element
37.90 + */
37.91 + @Override
37.92 + protected final ValueObject getValueObject() {
37.93 + if (this.sb != null) {
37.94 + try {
37.95 + this.value = ValueObjectImpl.create(getValue(this.sb.toString()));
37.96 + }
37.97 + catch (RuntimeException exception) {
37.98 + getOwner().handleException(exception);
37.99 + }
37.100 + finally {
37.101 + this.sb = null;
37.102 + }
37.103 + }
37.104 + return this.value;
37.105 + }
37.106 +
37.107 + /**
37.108 + * Returns the text of the body of this element.
37.109 + * This method evaluates value from text of the body,
37.110 + * and should be overridden in those handlers
37.111 + * that extend behavior of this element.
37.112 + *
37.113 + * @param argument the text of the body
37.114 + * @return evaluated value
37.115 + */
37.116 + protected Object getValue(String argument) {
37.117 + return argument;
37.118 + }
37.119 +}
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
38.2 +++ b/src/share/classes/com/sun/beans/decoder/TrueElementHandler.java Tue Feb 03 22:02:55 2009 -0800
38.3 @@ -0,0 +1,56 @@
38.4 +/*
38.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
38.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
38.7 + *
38.8 + * This code is free software; you can redistribute it and/or modify it
38.9 + * under the terms of the GNU General Public License version 2 only, as
38.10 + * published by the Free Software Foundation. Sun designates this
38.11 + * particular file as subject to the "Classpath" exception as provided
38.12 + * by Sun in the LICENSE file that accompanied this code.
38.13 + *
38.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
38.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
38.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
38.17 + * version 2 for more details (a copy is included in the LICENSE file that
38.18 + * accompanied this code).
38.19 + *
38.20 + * You should have received a copy of the GNU General Public License version
38.21 + * 2 along with this work; if not, write to the Free Software Foundation,
38.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
38.23 + *
38.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
38.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
38.26 + * have any questions.
38.27 + */
38.28 +package com.sun.beans.decoder;
38.29 +
38.30 +/**
38.31 + * This class is intended to handle <true> element.
38.32 + * This element specifies {@code true} value.
38.33 + * It should not contain body or inner elements.
38.34 + * For example:<pre>
38.35 + * <true/></pre>
38.36 + * is equivalent to {@code true} in Java code.
38.37 + * <p>The following atribute is supported:
38.38 + * <dl>
38.39 + * <dt>id
38.40 + * <dd>the identifier of the variable that is intended to store the result
38.41 + * </dl>
38.42 + *
38.43 + * @since 1.7
38.44 + *
38.45 + * @author Sergey A. Malenkov
38.46 + */
38.47 +final class TrueElementHandler extends NullElementHandler {
38.48 +
38.49 + /**
38.50 + * Returns {@code Boolean.TRUE}
38.51 + * as a value of <true> element.
38.52 + *
38.53 + * @return {@code Boolean.TRUE} by default
38.54 + */
38.55 + @Override
38.56 + public Object getValue() {
38.57 + return Boolean.TRUE;
38.58 + }
38.59 +}
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
39.2 +++ b/src/share/classes/com/sun/beans/decoder/ValueObject.java Tue Feb 03 22:02:55 2009 -0800
39.3 @@ -0,0 +1,50 @@
39.4 +/*
39.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
39.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
39.7 + *
39.8 + * This code is free software; you can redistribute it and/or modify it
39.9 + * under the terms of the GNU General Public License version 2 only, as
39.10 + * published by the Free Software Foundation. Sun designates this
39.11 + * particular file as subject to the "Classpath" exception as provided
39.12 + * by Sun in the LICENSE file that accompanied this code.
39.13 + *
39.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
39.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
39.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
39.17 + * version 2 for more details (a copy is included in the LICENSE file that
39.18 + * accompanied this code).
39.19 + *
39.20 + * You should have received a copy of the GNU General Public License version
39.21 + * 2 along with this work; if not, write to the Free Software Foundation,
39.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
39.23 + *
39.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
39.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
39.26 + * have any questions.
39.27 + */
39.28 +package com.sun.beans.decoder;
39.29 +
39.30 +/**
39.31 + * This interface represents the result of method execution.
39.32 + *
39.33 + * @since 1.7
39.34 + *
39.35 + * @author Sergey A. Malenkov
39.36 + */
39.37 +public interface ValueObject {
39.38 +
39.39 + /**
39.40 + * Returns the result of method execution.
39.41 + *
39.42 + * @return the result of method execution
39.43 + */
39.44 + Object getValue();
39.45 +
39.46 + /**
39.47 + * Returns {@code void} state of this value object.
39.48 + *
39.49 + * @return {@code true} if value can be ignored,
39.50 + * {@code false} otherwise
39.51 + */
39.52 + boolean isVoid();
39.53 +}
40.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
40.2 +++ b/src/share/classes/com/sun/beans/decoder/ValueObjectImpl.java Tue Feb 03 22:02:55 2009 -0800
40.3 @@ -0,0 +1,88 @@
40.4 +/*
40.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
40.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
40.7 + *
40.8 + * This code is free software; you can redistribute it and/or modify it
40.9 + * under the terms of the GNU General Public License version 2 only, as
40.10 + * published by the Free Software Foundation. Sun designates this
40.11 + * particular file as subject to the "Classpath" exception as provided
40.12 + * by Sun in the LICENSE file that accompanied this code.
40.13 + *
40.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
40.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
40.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
40.17 + * version 2 for more details (a copy is included in the LICENSE file that
40.18 + * accompanied this code).
40.19 + *
40.20 + * You should have received a copy of the GNU General Public License version
40.21 + * 2 along with this work; if not, write to the Free Software Foundation,
40.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
40.23 + *
40.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
40.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
40.26 + * have any questions.
40.27 + */
40.28 +package com.sun.beans.decoder;
40.29 +
40.30 +/**
40.31 + * This utility class provides {@code static} method
40.32 + * to create the object that contains the result of method execution.
40.33 + *
40.34 + * @since 1.7
40.35 + *
40.36 + * @author Sergey A. Malenkov
40.37 + */
40.38 +final class ValueObjectImpl implements ValueObject {
40.39 + static final ValueObject NULL = new ValueObjectImpl(null);
40.40 + static final ValueObject VOID = new ValueObjectImpl();
40.41 +
40.42 + /**
40.43 + * Returns the object that describes returning value.
40.44 + *
40.45 + * @param value the result of method execution
40.46 + * @return the object that describes value
40.47 + */
40.48 + static ValueObject create(Object value) {
40.49 + return (value != null)
40.50 + ? new ValueObjectImpl(value)
40.51 + : NULL;
40.52 + }
40.53 +
40.54 + private Object value;
40.55 + private boolean isVoid;
40.56 +
40.57 + /**
40.58 + * Creates the object that describes returning void value.
40.59 + */
40.60 + private ValueObjectImpl() {
40.61 + this.isVoid = true;
40.62 + }
40.63 +
40.64 + /**
40.65 + * Creates the object that describes returning non-void value.
40.66 + *
40.67 + * @param value the result of method execution
40.68 + */
40.69 + private ValueObjectImpl(Object value) {
40.70 + this.value = value;
40.71 + }
40.72 +
40.73 + /**
40.74 + * Returns the result of method execution.
40.75 + *
40.76 + * @return the result of method execution
40.77 + */
40.78 + public Object getValue() {
40.79 + return this.value;
40.80 + }
40.81 +
40.82 + /**
40.83 + * Returns {@code void} state of this value object.
40.84 + *
40.85 + * @return {@code true} if value should be ignored,
40.86 + * {@code false} otherwise
40.87 + */
40.88 + public boolean isVoid() {
40.89 + return this.isVoid;
40.90 + }
40.91 +}
41.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
41.2 +++ b/src/share/classes/com/sun/beans/decoder/VarElementHandler.java Tue Feb 03 22:02:55 2009 -0800
41.3 @@ -0,0 +1,82 @@
41.4 +/*
41.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
41.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41.7 + *
41.8 + * This code is free software; you can redistribute it and/or modify it
41.9 + * under the terms of the GNU General Public License version 2 only, as
41.10 + * published by the Free Software Foundation. Sun designates this
41.11 + * particular file as subject to the "Classpath" exception as provided
41.12 + * by Sun in the LICENSE file that accompanied this code.
41.13 + *
41.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
41.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
41.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
41.17 + * version 2 for more details (a copy is included in the LICENSE file that
41.18 + * accompanied this code).
41.19 + *
41.20 + * You should have received a copy of the GNU General Public License version
41.21 + * 2 along with this work; if not, write to the Free Software Foundation,
41.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
41.23 + *
41.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
41.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
41.26 + * have any questions.
41.27 + */
41.28 +package com.sun.beans.decoder;
41.29 +
41.30 +/**
41.31 + * This class is intended to handle <var> element.
41.32 + * This element retrieves the value of specified variable.
41.33 + * For example:<pre>
41.34 + * <var id="id1" idref="id2"/></pre>
41.35 + * is equivalent to {@code id1 = id2} in Java code.
41.36 + * <p>The following atributes are supported:
41.37 + * <dl>
41.38 + * <dt>idref
41.39 + * <dd>the identifier to refer to the variable
41.40 + * <dt>id
41.41 + * <dd>the identifier of the variable that is intended to store the result
41.42 + * </dl>
41.43 + *
41.44 + * @since 1.7
41.45 + *
41.46 + * @author Sergey A. Malenkov
41.47 + */
41.48 +final class VarElementHandler extends ElementHandler {
41.49 + private ValueObject value;
41.50 +
41.51 + /**
41.52 + * Parses attributes of the element.
41.53 + * The following atributes are supported:
41.54 + * <dl>
41.55 + * <dt>idref
41.56 + * <dd>the identifier to refer to the variable
41.57 + * <dt>id
41.58 + * <dd>the identifier of the variable that is intended to store the result
41.59 + * </dl>
41.60 + *
41.61 + * @param name the attribute name
41.62 + * @param value the attribute value
41.63 + */
41.64 + @Override
41.65 + public void addAttribute(String name, String value) {
41.66 + if (name.equals("idref")) { // NON-NLS: the attribute name
41.67 + this.value = ValueObjectImpl.create(getVariable(value));
41.68 + } else {
41.69 + super.addAttribute(name, value);
41.70 + }
41.71 + }
41.72 +
41.73 + /**
41.74 + * Returns the value of this element.
41.75 + *
41.76 + * @return the value of this element
41.77 + */
41.78 + @Override
41.79 + protected ValueObject getValueObject() {
41.80 + if (this.value == null) {
41.81 + throw new IllegalArgumentException("Variable name is not set");
41.82 + }
41.83 + return this.value;
41.84 + }
41.85 +}
42.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
42.2 +++ b/src/share/classes/com/sun/beans/decoder/VoidElementHandler.java Tue Feb 03 22:02:55 2009 -0800
42.3 @@ -0,0 +1,68 @@
42.4 +/*
42.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
42.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
42.7 + *
42.8 + * This code is free software; you can redistribute it and/or modify it
42.9 + * under the terms of the GNU General Public License version 2 only, as
42.10 + * published by the Free Software Foundation. Sun designates this
42.11 + * particular file as subject to the "Classpath" exception as provided
42.12 + * by Sun in the LICENSE file that accompanied this code.
42.13 + *
42.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
42.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
42.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
42.17 + * version 2 for more details (a copy is included in the LICENSE file that
42.18 + * accompanied this code).
42.19 + *
42.20 + * You should have received a copy of the GNU General Public License version
42.21 + * 2 along with this work; if not, write to the Free Software Foundation,
42.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
42.23 + *
42.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
42.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
42.26 + * have any questions.
42.27 + */
42.28 +package com.sun.beans.decoder;
42.29 +
42.30 +/**
42.31 + * This class is intended to handle <void> element.
42.32 + * This element looks like <object> element,
42.33 + * but its value is not used as an argument for element
42.34 + * that contains this one.
42.35 + * <p>The following atributes are supported:
42.36 + * <dl>
42.37 + * <dt>class
42.38 + * <dd>the type is used for static methods and fields
42.39 + * <dt>method
42.40 + * <dd>the method name
42.41 + * <dt>property
42.42 + * <dd>the property name
42.43 + * <dt>index
42.44 + * <dd>the property index
42.45 + * <dt>field
42.46 + * <dd>the field name
42.47 + * <dt>idref
42.48 + * <dd>the identifier to refer to the variable
42.49 + * <dt>id
42.50 + * <dd>the identifier of the variable that is intended to store the result
42.51 + * </dl>
42.52 + *
42.53 + * @since 1.7
42.54 + *
42.55 + * @author Sergey A. Malenkov
42.56 + */
42.57 +final class VoidElementHandler extends ObjectElementHandler {
42.58 +
42.59 + /**
42.60 + * Tests whether the value of this element can be used
42.61 + * as an argument of the element that contained in this one.
42.62 + *
42.63 + * @return {@code true} if the value of this element should be used
42.64 + * as an argument of the element that contained in this one,
42.65 + * {@code false} otherwise
42.66 + */
42.67 + @Override
42.68 + protected boolean isArgument() {
42.69 + return false; // hack for compatibility
42.70 + }
42.71 +}
43.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
43.2 +++ b/src/share/classes/com/sun/beans/finder/AbstractFinder.java Tue Feb 03 22:02:55 2009 -0800
43.3 @@ -0,0 +1,213 @@
43.4 +/*
43.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
43.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
43.7 + *
43.8 + * This code is free software; you can redistribute it and/or modify it
43.9 + * under the terms of the GNU General Public License version 2 only, as
43.10 + * published by the Free Software Foundation. Sun designates this
43.11 + * particular file as subject to the "Classpath" exception as provided
43.12 + * by Sun in the LICENSE file that accompanied this code.
43.13 + *
43.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
43.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
43.17 + * version 2 for more details (a copy is included in the LICENSE file that
43.18 + * accompanied this code).
43.19 + *
43.20 + * You should have received a copy of the GNU General Public License version
43.21 + * 2 along with this work; if not, write to the Free Software Foundation,
43.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
43.23 + *
43.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
43.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
43.26 + * have any questions.
43.27 + */
43.28 +package com.sun.beans.finder;
43.29 +
43.30 +import java.util.HashMap;
43.31 +import java.util.Map;
43.32 +
43.33 +/**
43.34 + * This abstract class provides functionality
43.35 + * to find a public method or constructor
43.36 + * with specified parameter types.
43.37 + * It supports a variable number of parameters.
43.38 + *
43.39 + * @since 1.7
43.40 + *
43.41 + * @author Sergey A. Malenkov
43.42 + */
43.43 +abstract class AbstractFinder<T> {
43.44 + private final Class<?>[] args;
43.45 +
43.46 + /**
43.47 + * Creates finder for array of classes of arguments.
43.48 + * If a particular element of array equals {@code null},
43.49 + * than the appropriate pair of classes
43.50 + * does not take into consideration.
43.51 + *
43.52 + * @param args array of classes of arguments
43.53 + */
43.54 + protected AbstractFinder(Class<?>[] args) {
43.55 + this.args = args;
43.56 + }
43.57 +
43.58 + /**
43.59 + * Returns an array of {@code Class} objects
43.60 + * that represent the formal parameter types of the method
43.61 + * Returns an empty array if the method takes no parameters.
43.62 + *
43.63 + * @param method the object that represents method
43.64 + * @return the parameter types of the method
43.65 + */
43.66 + protected abstract Class<?>[] getParameters(T method);
43.67 +
43.68 + /**
43.69 + * Returns {@code true} if and only if the method
43.70 + * was declared to take a variable number of arguments.
43.71 + *
43.72 + * @param method the object that represents method
43.73 + * @return {@code true} if the method was declared
43.74 + * to take a variable number of arguments;
43.75 + * {@code false} otherwise
43.76 + */
43.77 + protected abstract boolean isVarArgs(T method);
43.78 +
43.79 + /**
43.80 + * Checks validness of the method.
43.81 + * At least the valid method should be public.
43.82 + *
43.83 + * @param method the object that represents method
43.84 + * @return {@code true} if the method is valid,
43.85 + * {@code false} otherwise
43.86 + */
43.87 + protected abstract boolean isValid(T method);
43.88 +
43.89 + /**
43.90 + * Performs a search in the {@code methods} array.
43.91 + * The one method is selected from the array of the valid methods.
43.92 + * The list of parameters of the selected method shows
43.93 + * the best correlation with the list of arguments
43.94 + * specified at class initialization.
43.95 + * If more than one method is both accessible and applicable
43.96 + * to a method invocation, it is necessary to choose one
43.97 + * to provide the descriptor for the run-time method dispatch.
43.98 + * The most specific method should be chosen.
43.99 + *
43.100 + * @param methods the array of methods to search within
43.101 + * @return the object that represents found method
43.102 + * @throws NoSuchMethodException if no method was found or several
43.103 + * methods meet the search criteria
43.104 + * @see #isAssignable
43.105 + */
43.106 + final T find(T[] methods) throws NoSuchMethodException {
43.107 + Map<T, Class<?>[]> map = new HashMap<T, Class<?>[]>();
43.108 +
43.109 + T oldMethod = null;
43.110 + Class<?>[] oldParams = null;
43.111 + boolean ambiguous = false;
43.112 +
43.113 + for (T newMethod : methods) {
43.114 + if (isValid(newMethod)) {
43.115 + Class<?>[] newParams = getParameters(newMethod);
43.116 + if (newParams.length == this.args.length) {
43.117 + PrimitiveWrapperMap.replacePrimitivesWithWrappers(newParams);
43.118 + if (isAssignable(newParams, this.args)) {
43.119 + if (oldMethod == null) {
43.120 + oldMethod = newMethod;
43.121 + oldParams = newParams;
43.122 + } else {
43.123 + boolean useNew = isAssignable(oldParams, newParams);
43.124 + boolean useOld = isAssignable(newParams, oldParams);
43.125 +
43.126 + if (useOld == useNew) {
43.127 + ambiguous = true;
43.128 + } else if (useNew) {
43.129 + oldMethod = newMethod;
43.130 + oldParams = newParams;
43.131 + ambiguous = false;
43.132 + }
43.133 + }
43.134 + }
43.135 + }
43.136 + if (isVarArgs(newMethod)) {
43.137 + int length = newParams.length - 1;
43.138 + if (length <= this.args.length) {
43.139 + Class<?>[] array = new Class<?>[this.args.length];
43.140 + System.arraycopy(newParams, 0, array, 0, length);
43.141 + if (length < this.args.length) {
43.142 + Class<?> type = newParams[length].getComponentType();
43.143 + if (type.isPrimitive()) {
43.144 + type = PrimitiveWrapperMap.getType(type.getName());
43.145 + }
43.146 + for (int i = length; i < this.args.length; i++) {
43.147 + array[i] = type;
43.148 + }
43.149 + }
43.150 + map.put(newMethod, array);
43.151 + }
43.152 + }
43.153 + }
43.154 + }
43.155 + for (T newMethod : methods) {
43.156 + Class<?>[] newParams = map.get(newMethod);
43.157 + if (newParams != null) {
43.158 + if (isAssignable(newParams, this.args)) {
43.159 + if (oldMethod == null) {
43.160 + oldMethod = newMethod;
43.161 + oldParams = newParams;
43.162 + } else {
43.163 + boolean useNew = isAssignable(oldParams, newParams);
43.164 + boolean useOld = isAssignable(newParams, oldParams);
43.165 +
43.166 + if (useOld == useNew) {
43.167 + if (oldParams == map.get(oldMethod)) {
43.168 + ambiguous = true;
43.169 + }
43.170 + } else if (useNew) {
43.171 + oldMethod = newMethod;
43.172 + oldParams = newParams;
43.173 + ambiguous = false;
43.174 + }
43.175 + }
43.176 + }
43.177 + }
43.178 + }
43.179 +
43.180 + if (ambiguous) {
43.181 + throw new NoSuchMethodException("Ambiguous methods are found");
43.182 + }
43.183 + if (oldMethod == null) {
43.184 + throw new NoSuchMethodException("Method is not found");
43.185 + }
43.186 + return oldMethod;
43.187 + }
43.188 +
43.189 + /**
43.190 + * Determines if every class in {@code min} array is either the same as,
43.191 + * or is a superclass of, the corresponding class in {@code max} array.
43.192 + * The length of every array must equal the number of arguments.
43.193 + * This comparison is performed in the {@link #find} method
43.194 + * before the first call of the isAssignable method.
43.195 + * If an argument equals {@code null}
43.196 + * the appropriate pair of classes does not take into consideration.
43.197 + *
43.198 + * @param min the array of classes to be checked
43.199 + * @param max the array of classes that is used to check
43.200 + * @return {@code true} if all classes in {@code min} array
43.201 + * are assignable from corresponding classes in {@code max} array,
43.202 + * {@code false} otherwise
43.203 + *
43.204 + * @see Class#isAssignableFrom
43.205 + */
43.206 + private boolean isAssignable(Class<?>[] min, Class<?>[] max) {
43.207 + for (int i = 0; i < this.args.length; i++) {
43.208 + if (null != this.args[i]) {
43.209 + if (!min[i].isAssignableFrom(max[i])) {
43.210 + return false;
43.211 + }
43.212 + }
43.213 + }
43.214 + return true;
43.215 + }
43.216 +}
44.1 --- a/src/share/classes/com/sun/beans/finder/ClassFinder.java Thu Jan 29 21:46:48 2009 -0800
44.2 +++ b/src/share/classes/com/sun/beans/finder/ClassFinder.java Tue Feb 03 22:02:55 2009 -0800
44.3 @@ -1,5 +1,5 @@
44.4 /*
44.5 - * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
44.6 + * Copyright 2006-2008 Sun Microsystems, Inc. All Rights Reserved.
44.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44.8 *
44.9 * This code is free software; you can redistribute it and/or modify it
44.10 @@ -25,7 +25,7 @@
44.11 package com.sun.beans.finder;
44.12
44.13 /**
44.14 - * This is utility class that provides <code>static</code> methods
44.15 + * This is utility class that provides {@code static} methods
44.16 * to find a class with the specified name using the specified class loader.
44.17 *
44.18 * @since 1.7
44.19 @@ -33,137 +33,138 @@
44.20 * @author Sergey A. Malenkov
44.21 */
44.22 public final class ClassFinder {
44.23 +
44.24 /**
44.25 - * Returns the <code>Class</code> object associated
44.26 + * Returns the {@code Class} object associated
44.27 * with the class or interface with the given string name,
44.28 * using the default class loader.
44.29 * <p>
44.30 - * The <code>name</code> can denote an array class
44.31 + * The {@code name} can denote an array class
44.32 * (see {@link Class#getName} for details).
44.33 *
44.34 * @param name fully qualified name of the desired class
44.35 * @return class object representing the desired class
44.36 *
44.37 - * @exception ClassNotFoundException if the class cannot be located
44.38 - * by the specified class loader
44.39 + * @throws ClassNotFoundException if the class cannot be located
44.40 + * by the specified class loader
44.41 *
44.42 * @see Class#forName(String)
44.43 * @see Class#forName(String,boolean,ClassLoader)
44.44 * @see ClassLoader#getSystemClassLoader()
44.45 * @see Thread#getContextClassLoader()
44.46 */
44.47 - public static Class findClass( String name ) throws ClassNotFoundException {
44.48 + public static Class<?> findClass(String name) throws ClassNotFoundException {
44.49 try {
44.50 ClassLoader loader = Thread.currentThread().getContextClassLoader();
44.51 - if ( loader == null ) {
44.52 + if (loader == null) {
44.53 // can be null in IE (see 6204697)
44.54 loader = ClassLoader.getSystemClassLoader();
44.55 }
44.56 - if ( loader != null ) {
44.57 - return Class.forName( name, false, loader );
44.58 + if (loader != null) {
44.59 + return Class.forName(name, false, loader);
44.60 }
44.61
44.62 - } catch ( ClassNotFoundException exception ) {
44.63 + } catch (ClassNotFoundException exception) {
44.64 // use current class loader instead
44.65 - } catch ( SecurityException exception ) {
44.66 + } catch (SecurityException exception) {
44.67 // use current class loader instead
44.68 }
44.69 - return Class.forName( name );
44.70 + return Class.forName(name);
44.71 }
44.72
44.73 /**
44.74 - * Returns the <code>Class</code> object associated with
44.75 + * Returns the {@code Class} object associated with
44.76 * the class or interface with the given string name,
44.77 * using the given class loader.
44.78 * <p>
44.79 - * The <code>name</code> can denote an array class
44.80 + * The {@code name} can denote an array class
44.81 * (see {@link Class#getName} for details).
44.82 * <p>
44.83 - * If the parameter <code>loader</code> is null,
44.84 + * If the parameter {@code loader} is null,
44.85 * the class is loaded through the default class loader.
44.86 *
44.87 * @param name fully qualified name of the desired class
44.88 * @param loader class loader from which the class must be loaded
44.89 * @return class object representing the desired class
44.90 *
44.91 - * @exception ClassNotFoundException if the class cannot be located
44.92 - * by the specified class loader
44.93 + * @throws ClassNotFoundException if the class cannot be located
44.94 + * by the specified class loader
44.95 *
44.96 * @see #findClass(String,ClassLoader)
44.97 * @see Class#forName(String,boolean,ClassLoader)
44.98 */
44.99 - public static Class findClass( String name, ClassLoader loader ) throws ClassNotFoundException {
44.100 - if ( loader != null ) {
44.101 + public static Class<?> findClass(String name, ClassLoader loader) throws ClassNotFoundException {
44.102 + if (loader != null) {
44.103 try {
44.104 - return Class.forName( name, false, loader );
44.105 - } catch ( ClassNotFoundException exception ) {
44.106 + return Class.forName(name, false, loader);
44.107 + } catch (ClassNotFoundException exception) {
44.108 // use default class loader instead
44.109 - } catch ( SecurityException exception ) {
44.110 + } catch (SecurityException exception) {
44.111 // use default class loader instead
44.112 }
44.113 }
44.114 - return findClass( name );
44.115 + return findClass(name);
44.116 }
44.117
44.118 /**
44.119 - * Returns the <code>Class</code> object associated
44.120 + * Returns the {@code Class} object associated
44.121 * with the class or interface with the given string name,
44.122 * using the default class loader.
44.123 * <p>
44.124 - * The <code>name</code> can denote an array class
44.125 + * The {@code name} can denote an array class
44.126 * (see {@link Class#getName} for details).
44.127 * <p>
44.128 * This method can be used to obtain
44.129 - * any of the <code>Class</code> objects
44.130 - * representing <code>void</code> or primitive Java types:
44.131 - * <code>char</code>, <code>byte</code>, <code>short</code>,
44.132 - * <code>int</code>, <code>long</code>, <code>float</code>,
44.133 - * <code>double</code> and <code>boolean</code>.
44.134 + * any of the {@code Class} objects
44.135 + * representing {@code void} or primitive Java types:
44.136 + * {@code char}, {@code byte}, {@code short},
44.137 + * {@code int}, {@code long}, {@code float},
44.138 + * {@code double} and {@code boolean}.
44.139 *
44.140 * @param name fully qualified name of the desired class
44.141 * @return class object representing the desired class
44.142 *
44.143 - * @exception ClassNotFoundException if the class cannot be located
44.144 - * by the specified class loader
44.145 + * @throws ClassNotFoundException if the class cannot be located
44.146 + * by the specified class loader
44.147 *
44.148 * @see #resolveClass(String,ClassLoader)
44.149 */
44.150 - public static Class resolveClass( String name ) throws ClassNotFoundException {
44.151 - return resolveClass( name, null );
44.152 + public static Class<?> resolveClass(String name) throws ClassNotFoundException {
44.153 + return resolveClass(name, null);
44.154 }
44.155
44.156 /**
44.157 - * Returns the <code>Class</code> object associated with
44.158 + * Returns the {@code Class} object associated with
44.159 * the class or interface with the given string name,
44.160 * using the given class loader.
44.161 * <p>
44.162 - * The <code>name</code> can denote an array class
44.163 + * The {@code name} can denote an array class
44.164 * (see {@link Class#getName} for details).
44.165 * <p>
44.166 - * If the parameter <code>loader</code> is null,
44.167 + * If the parameter {@code loader} is null,
44.168 * the class is loaded through the default class loader.
44.169 * <p>
44.170 * This method can be used to obtain
44.171 - * any of the <code>Class</code> objects
44.172 - * representing <code>void</code> or primitive Java types:
44.173 - * <code>char</code>, <code>byte</code>, <code>short</code>,
44.174 - * <code>int</code>, <code>long</code>, <code>float</code>,
44.175 - * <code>double</code> and <code>boolean</code>.
44.176 + * any of the {@code Class} objects
44.177 + * representing {@code void} or primitive Java types:
44.178 + * {@code char}, {@code byte}, {@code short},
44.179 + * {@code int}, {@code long}, {@code float},
44.180 + * {@code double} and {@code boolean}.
44.181 *
44.182 * @param name fully qualified name of the desired class
44.183 * @param loader class loader from which the class must be loaded
44.184 * @return class object representing the desired class
44.185 *
44.186 - * @exception ClassNotFoundException if the class cannot be located
44.187 - * by the specified class loader
44.188 + * @throws ClassNotFoundException if the class cannot be located
44.189 + * by the specified class loader
44.190 *
44.191 * @see #findClass(String,ClassLoader)
44.192 * @see PrimitiveTypeMap#getType(String)
44.193 */
44.194 - public static Class resolveClass( String name, ClassLoader loader ) throws ClassNotFoundException {
44.195 - Class type = PrimitiveTypeMap.getType( name );
44.196 - return ( type == null )
44.197 - ? findClass( name, loader )
44.198 + public static Class<?> resolveClass(String name, ClassLoader loader) throws ClassNotFoundException {
44.199 + Class<?> type = PrimitiveTypeMap.getType(name);
44.200 + return (type == null)
44.201 + ? findClass(name, loader)
44.202 : type;
44.203 }
44.204
45.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
45.2 +++ b/src/share/classes/com/sun/beans/finder/ConstructorFinder.java Tue Feb 03 22:02:55 2009 -0800
45.3 @@ -0,0 +1,127 @@
45.4 +/*
45.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
45.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45.7 + *
45.8 + * This code is free software; you can redistribute it and/or modify it
45.9 + * under the terms of the GNU General Public License version 2 only, as
45.10 + * published by the Free Software Foundation. Sun designates this
45.11 + * particular file as subject to the "Classpath" exception as provided
45.12 + * by Sun in the LICENSE file that accompanied this code.
45.13 + *
45.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
45.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
45.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
45.17 + * version 2 for more details (a copy is included in the LICENSE file that
45.18 + * accompanied this code).
45.19 + *
45.20 + * You should have received a copy of the GNU General Public License version
45.21 + * 2 along with this work; if not, write to the Free Software Foundation,
45.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
45.23 + *
45.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
45.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
45.26 + * have any questions.
45.27 + */
45.28 +package com.sun.beans.finder;
45.29 +
45.30 +import com.sun.beans.WeakCache;
45.31 +
45.32 +import java.lang.reflect.Constructor;
45.33 +import java.lang.reflect.Modifier;
45.34 +
45.35 +/**
45.36 + * This utility class provides {@code static} methods
45.37 + * to find a public constructor with specified parameter types
45.38 + * in specified class.
45.39 + *
45.40 + * @since 1.7
45.41 + *
45.42 + * @author Sergey A. Malenkov
45.43 + */
45.44 +public final class ConstructorFinder extends AbstractFinder<Constructor<?>> {
45.45 + private static final WeakCache<Signature, Constructor<?>> CACHE = new WeakCache<Signature, Constructor<?>>();
45.46 +
45.47 + /**
45.48 + * Finds public constructor
45.49 + * that is declared in public class.
45.50 + *
45.51 + * @param type the class that can have constructor
45.52 + * @param args parameter types that is used to find constructor
45.53 + * @return object that represents found constructor
45.54 + * @throws NoSuchMethodException if constructor could not be found
45.55 + * or some constructors are found
45.56 + */
45.57 + public static Constructor<?> findConstructor(Class<?> type, Class<?>...args) throws NoSuchMethodException {
45.58 + if (type.isPrimitive()) {
45.59 + throw new NoSuchMethodException("Primitive wrapper does not contain constructors");
45.60 + }
45.61 + if (type.isInterface()) {
45.62 + throw new NoSuchMethodException("Interface does not contain constructors");
45.63 + }
45.64 + if (Modifier.isAbstract(type.getModifiers())) {
45.65 + throw new NoSuchMethodException("Abstract class cannot be instantiated");
45.66 + }
45.67 + if (!Modifier.isPublic(type.getModifiers())) {
45.68 + throw new NoSuchMethodException("Class is not accessible");
45.69 + }
45.70 + PrimitiveWrapperMap.replacePrimitivesWithWrappers(args);
45.71 + Signature signature = new Signature(type, args);
45.72 +
45.73 + Constructor<?> constructor = CACHE.get(signature);
45.74 + if (constructor != null) {
45.75 + return constructor;
45.76 + }
45.77 + constructor = new ConstructorFinder(args).find(type.getConstructors());
45.78 + CACHE.put(signature, constructor);
45.79 + return constructor;
45.80 + }
45.81 +
45.82 + /**
45.83 + * Creates constructor finder with specified array of parameter types.
45.84 + *
45.85 + * @param args the array of parameter types
45.86 + */
45.87 + private ConstructorFinder(Class<?>[] args) {
45.88 + super(args);
45.89 + }
45.90 +
45.91 + /**
45.92 + * Returns an array of {@code Class} objects
45.93 + * that represent the formal parameter types of the constructor
45.94 + * Returns an empty array if the constructor takes no parameters.
45.95 + *
45.96 + * @param constructor the object that represents constructor
45.97 + * @return the parameter types of the constructor
45.98 + */
45.99 + @Override
45.100 + protected Class<?>[] getParameters(Constructor<?> constructor) {
45.101 + return constructor.getParameterTypes();
45.102 + }
45.103 +
45.104 + /**
45.105 + * Returns {@code true} if and only if the constructor
45.106 + * was declared to take a variable number of arguments.
45.107 + *
45.108 + * @param constructor the object that represents constructor
45.109 + * @return {@code true} if the constructor was declared
45.110 + * to take a variable number of arguments;
45.111 + * {@code false} otherwise
45.112 + */
45.113 + @Override
45.114 + protected boolean isVarArgs(Constructor<?> constructor) {
45.115 + return constructor.isVarArgs();
45.116 + }
45.117 +
45.118 + /**
45.119 + * Checks validness of the constructor.
45.120 + * The valid constructor should be public.
45.121 + *
45.122 + * @param constructor the object that represents constructor
45.123 + * @return {@code true} if the constructor is valid,
45.124 + * {@code false} otherwise
45.125 + */
45.126 + @Override
45.127 + protected boolean isValid(Constructor<?> constructor) {
45.128 + return Modifier.isPublic(constructor.getModifiers());
45.129 + }
45.130 +}
46.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
46.2 +++ b/src/share/classes/com/sun/beans/finder/FieldFinder.java Tue Feb 03 22:02:55 2009 -0800
46.3 @@ -0,0 +1,106 @@
46.4 +/*
46.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
46.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
46.7 + *
46.8 + * This code is free software; you can redistribute it and/or modify it
46.9 + * under the terms of the GNU General Public License version 2 only, as
46.10 + * published by the Free Software Foundation. Sun designates this
46.11 + * particular file as subject to the "Classpath" exception as provided
46.12 + * by Sun in the LICENSE file that accompanied this code.
46.13 + *
46.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
46.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
46.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
46.17 + * version 2 for more details (a copy is included in the LICENSE file that
46.18 + * accompanied this code).
46.19 + *
46.20 + * You should have received a copy of the GNU General Public License version
46.21 + * 2 along with this work; if not, write to the Free Software Foundation,
46.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
46.23 + *
46.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
46.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
46.26 + * have any questions.
46.27 + */
46.28 +package com.sun.beans.finder;
46.29 +
46.30 +import java.lang.reflect.Field;
46.31 +import java.lang.reflect.Modifier;
46.32 +
46.33 +/**
46.34 + * This utility class provides {@code static} methods
46.35 + * to find a public field with specified name
46.36 + * in specified class.
46.37 + *
46.38 + * @since 1.7
46.39 + *
46.40 + * @author Sergey A. Malenkov
46.41 + */
46.42 +public final class FieldFinder {
46.43 +
46.44 + /**
46.45 + * Finds public field (static or non-static)
46.46 + * that is declared in public class.
46.47 + *
46.48 + * @param type the class that can have field
46.49 + * @param name the name of field to find
46.50 + * @return object that represents found field
46.51 + * @throws NoSuchFieldException if field is not found
46.52 + * @see Class#getField
46.53 + */
46.54 + public static Field findField(Class<?> type, String name) throws NoSuchFieldException {
46.55 + if (name == null) {
46.56 + throw new IllegalArgumentException("Field name is not set");
46.57 + }
46.58 + Field field = type.getField(name);
46.59 + if (!Modifier.isPublic(field.getModifiers())) {
46.60 + throw new NoSuchFieldException("Field '" + name + "' is not public");
46.61 + }
46.62 + if (!Modifier.isPublic(field.getDeclaringClass().getModifiers())) {
46.63 + throw new NoSuchFieldException("Field '" + name + "' is not accessible");
46.64 + }
46.65 + return field;
46.66 + }
46.67 +
46.68 + /**
46.69 + * Finds public non-static field
46.70 + * that is declared in public class.
46.71 + *
46.72 + * @param type the class that can have field
46.73 + * @param name the name of field to find
46.74 + * @return object that represents found field
46.75 + * @throws NoSuchFieldException if field is not found
46.76 + * @see Class#getField
46.77 + */
46.78 + public static Field findInstanceField(Class<?> type, String name) throws NoSuchFieldException {
46.79 + Field field = findField(type, name);
46.80 + if (Modifier.isStatic(field.getModifiers())) {
46.81 + throw new NoSuchFieldException("Field '" + name + "' is static");
46.82 + }
46.83 + return field;
46.84 + }
46.85 +
46.86 + /**
46.87 + * Finds public static field
46.88 + * that is declared in public class.
46.89 + *
46.90 + * @param type the class that can have field
46.91 + * @param name the name of field to find
46.92 + * @return object that represents found field
46.93 + * @throws NoSuchFieldException if field is not found
46.94 + * @see Class#getField
46.95 + */
46.96 + public static Field findStaticField(Class<?> type, String name) throws NoSuchFieldException {
46.97 + Field field = findField(type, name);
46.98 + if (!Modifier.isStatic(field.getModifiers())) {
46.99 + throw new NoSuchFieldException("Field '" + name + "' is not static");
46.100 + }
46.101 + return field;
46.102 + }
46.103 +
46.104 + /**
46.105 + * Disable instantiation.
46.106 + */
46.107 + private FieldFinder() {
46.108 + }
46.109 +}
47.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
47.2 +++ b/src/share/classes/com/sun/beans/finder/MethodFinder.java Tue Feb 03 22:02:55 2009 -0800
47.3 @@ -0,0 +1,231 @@
47.4 +/*
47.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
47.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
47.7 + *
47.8 + * This code is free software; you can redistribute it and/or modify it
47.9 + * under the terms of the GNU General Public License version 2 only, as
47.10 + * published by the Free Software Foundation. Sun designates this
47.11 + * particular file as subject to the "Classpath" exception as provided
47.12 + * by Sun in the LICENSE file that accompanied this code.
47.13 + *
47.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
47.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
47.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
47.17 + * version 2 for more details (a copy is included in the LICENSE file that
47.18 + * accompanied this code).
47.19 + *
47.20 + * You should have received a copy of the GNU General Public License version
47.21 + * 2 along with this work; if not, write to the Free Software Foundation,
47.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
47.23 + *
47.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
47.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
47.26 + * have any questions.
47.27 + */
47.28 +package com.sun.beans.finder;
47.29 +
47.30 +import com.sun.beans.TypeResolver;
47.31 +import com.sun.beans.WeakCache;
47.32 +
47.33 +import java.lang.reflect.Method;
47.34 +import java.lang.reflect.Modifier;
47.35 +import java.lang.reflect.ParameterizedType;
47.36 +import java.lang.reflect.Type;
47.37 +import java.util.Arrays;
47.38 +
47.39 +/**
47.40 + * This utility class provides {@code static} methods
47.41 + * to find a public method with specified name and parameter types
47.42 + * in specified class.
47.43 + *
47.44 + * @since 1.7
47.45 + *
47.46 + * @author Sergey A. Malenkov
47.47 + */
47.48 +public final class MethodFinder extends AbstractFinder<Method> {
47.49 + private static final WeakCache<Signature, Method> CACHE = new WeakCache<Signature, Method>();
47.50 +
47.51 + /**
47.52 + * Finds public method (static or non-static)
47.53 + * that is accessible from public class.
47.54 + *
47.55 + * @param type the class that can have method
47.56 + * @param name the name of method to find
47.57 + * @param args parameter types that is used to find method
47.58 + * @return object that represents found method
47.59 + * @throws NoSuchMethodException if method could not be found
47.60 + * or some methods are found
47.61 + */
47.62 + public static Method findMethod(Class<?> type, String name, Class<?>...args) throws NoSuchMethodException {
47.63 + if (name == null) {
47.64 + throw new IllegalArgumentException("Method name is not set");
47.65 + }
47.66 + PrimitiveWrapperMap.replacePrimitivesWithWrappers(args);
47.67 + Signature signature = new Signature(type, name, args);
47.68 +
47.69 + Method method = CACHE.get(signature);
47.70 + if (method != null) {
47.71 + return method;
47.72 + }
47.73 + method = findAccessibleMethod(new MethodFinder(name, args).find(type.getMethods()));
47.74 + CACHE.put(signature, method);
47.75 + return method;
47.76 + }
47.77 +
47.78 + /**
47.79 + * Finds public non-static method
47.80 + * that is accessible from public class.
47.81 + *
47.82 + * @param type the class that can have method
47.83 + * @param name the name of method to find
47.84 + * @param args parameter types that is used to find method
47.85 + * @return object that represents found method
47.86 + * @throws NoSuchMethodException if method could not be found
47.87 + * or some methods are found
47.88 + */
47.89 + public static Method findInstanceMethod(Class<?> type, String name, Class<?>... args) throws NoSuchMethodException {
47.90 + Method method = findMethod(type, name, args);
47.91 + if (Modifier.isStatic(method.getModifiers())) {
47.92 + throw new NoSuchMethodException("Method '" + name + "' is static");
47.93 + }
47.94 + return method;
47.95 + }
47.96 +
47.97 + /**
47.98 + * Finds public static method
47.99 + * that is accessible from public class.
47.100 + *
47.101 + * @param type the class that can have method
47.102 + * @param name the name of method to find
47.103 + * @param args parameter types that is used to find method
47.104 + * @return object that represents found method
47.105 + * @throws NoSuchMethodException if method could not be found
47.106 + * or some methods are found
47.107 + */
47.108 + public static Method findStaticMethod(Class<?> type, String name, Class<?>...args) throws NoSuchMethodException {
47.109 + Method method = findMethod(type, name, args);
47.110 + if (!Modifier.isStatic(method.getModifiers())) {
47.111 + throw new NoSuchMethodException("Method '" + name + "' is not static");
47.112 + }
47.113 + return method;
47.114 + }
47.115 +
47.116 + /**
47.117 + * Finds method that is accessible from public class or interface through class hierarchy.
47.118 + *
47.119 + * @param method object that represents found method
47.120 + * @return object that represents accessible method
47.121 + * @throws NoSuchMethodException if method is not accessible or is not found
47.122 + * in specified superclass or interface
47.123 + */
47.124 + private static Method findAccessibleMethod(Method method) throws NoSuchMethodException {
47.125 + Class<?> type = method.getDeclaringClass();
47.126 + if (Modifier.isPublic(type.getModifiers())) {
47.127 + return method;
47.128 + }
47.129 + if (Modifier.isStatic(method.getModifiers())) {
47.130 + throw new NoSuchMethodException("Method '" + method.getName() + "' is not accessible");
47.131 + }
47.132 + for (Type generic : type.getGenericInterfaces()) {
47.133 + try {
47.134 + return findAccessibleMethod(method, generic);
47.135 + }
47.136 + catch (NoSuchMethodException exception) {
47.137 + // try to find in superclass or another interface
47.138 + }
47.139 + }
47.140 + return findAccessibleMethod(method, type.getGenericSuperclass());
47.141 + }
47.142 +
47.143 + /**
47.144 + * Finds method that accessible from specified class.
47.145 + *
47.146 + * @param method object that represents found method
47.147 + * @param generic generic type that is used to find accessible method
47.148 + * @return object that represents accessible method
47.149 + * @throws NoSuchMethodException if method is not accessible or is not found
47.150 + * in specified superclass or interface
47.151 + */
47.152 + private static Method findAccessibleMethod(Method method, Type generic) throws NoSuchMethodException {
47.153 + String name = method.getName();
47.154 + Class<?>[] params = method.getParameterTypes();
47.155 + if (generic instanceof Class) {
47.156 + Class<?> type = (Class<?>) generic;
47.157 + return findAccessibleMethod(type.getMethod(name, params));
47.158 + }
47.159 + if (generic instanceof ParameterizedType) {
47.160 + ParameterizedType pt = (ParameterizedType) generic;
47.161 + Class<?> type = (Class<?>) pt.getRawType();
47.162 + for (Method m : type.getMethods()) {
47.163 + if (m.getName().equals(name)) {
47.164 + Class<?>[] pts = m.getParameterTypes();
47.165 + if (pts.length == params.length) {
47.166 + if (Arrays.equals(params, pts)) {
47.167 + return findAccessibleMethod(m);
47.168 + }
47.169 + Type[] gpts = m.getGenericParameterTypes();
47.170 + if (Arrays.equals(params, TypeResolver.erase(TypeResolver.resolve(pt, gpts)))) {
47.171 + return findAccessibleMethod(m);
47.172 + }
47.173 + }
47.174 + }
47.175 + }
47.176 + }
47.177 + throw new NoSuchMethodException("Method '" + name + "' is not accessible");
47.178 + }
47.179 +
47.180 +
47.181 + private final String name;
47.182 +
47.183 + /**
47.184 + * Creates method finder with specified array of parameter types.
47.185 + *
47.186 + * @param name the name of method to find
47.187 + * @param args the array of parameter types
47.188 + */
47.189 + private MethodFinder(String name, Class<?>[] args) {
47.190 + super(args);
47.191 + this.name = name;
47.192 + }
47.193 +
47.194 + /**
47.195 + * Returns an array of {@code Class} objects
47.196 + * that represent the formal parameter types of the method
47.197 + * Returns an empty array if the method takes no parameters.
47.198 + *
47.199 + * @param method the object that represents method
47.200 + * @return the parameter types of the method
47.201 + */
47.202 + @Override
47.203 + protected Class<?>[] getParameters(Method method) {
47.204 + return method.getParameterTypes();
47.205 + }
47.206 +
47.207 + /**
47.208 + * Returns {@code true} if and only if the method
47.209 + * was declared to take a variable number of arguments.
47.210 + *
47.211 + * @param method the object that represents method
47.212 + * @return {@code true} if the method was declared
47.213 + * to take a variable number of arguments;
47.214 + * {@code false} otherwise
47.215 + */
47.216 + @Override
47.217 + protected boolean isVarArgs(Method method) {
47.218 + return method.isVarArgs();
47.219 + }
47.220 +
47.221 + /**
47.222 + * Checks validness of the method.
47.223 + * The valid method should be public and
47.224 + * should have the specified name.
47.225 + *
47.226 + * @param method the object that represents method
47.227 + * @return {@code true} if the method is valid,
47.228 + * {@code false} otherwise
47.229 + */
47.230 + @Override
47.231 + protected boolean isValid(Method method) {
47.232 + return Modifier.isPublic(method.getModifiers()) && method.getName().equals(this.name);
47.233 + }
47.234 +}
48.1 --- a/src/share/classes/com/sun/beans/finder/PrimitiveTypeMap.java Thu Jan 29 21:46:48 2009 -0800
48.2 +++ b/src/share/classes/com/sun/beans/finder/PrimitiveTypeMap.java Tue Feb 03 22:02:55 2009 -0800
48.3 @@ -1,5 +1,5 @@
48.4 /*
48.5 - * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
48.6 + * Copyright 2006-2008 Sun Microsystems, Inc. All Rights Reserved.
48.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
48.8 *
48.9 * This code is free software; you can redistribute it and/or modify it
48.10 @@ -36,29 +36,30 @@
48.11 * @author Sergey A. Malenkov
48.12 */
48.13 final class PrimitiveTypeMap {
48.14 +
48.15 /**
48.16 * Returns primitive type class by its name.
48.17 *
48.18 * @param name the name of primitive type
48.19 * @return found primitive type class,
48.20 - * or <code>null</code> if not found
48.21 + * or {@code null} if not found
48.22 */
48.23 - static Class getType( String name ) {
48.24 - return map.get( name );
48.25 + static Class<?> getType(String name) {
48.26 + return map.get(name);
48.27 }
48.28
48.29 - private static final Map<String, Class> map = new HashMap<String, Class>( 9 );
48.30 + private static final Map<String, Class<?>> map = new HashMap<String, Class<?>>(9);
48.31
48.32 static {
48.33 - map.put( boolean.class.getName(), boolean.class );
48.34 - map.put( char.class.getName(), char.class );
48.35 - map.put( byte.class.getName(), byte.class );
48.36 - map.put( short.class.getName(), short.class );
48.37 - map.put( int.class.getName(), int.class );
48.38 - map.put( long.class.getName(), long.class );
48.39 - map.put( float.class.getName(), float.class );
48.40 - map.put( double.class.getName(), double.class );
48.41 - map.put( void.class.getName(), void.class );
48.42 + map.put(boolean.class.getName(), boolean.class);
48.43 + map.put(char.class.getName(), char.class);
48.44 + map.put(byte.class.getName(), byte.class);
48.45 + map.put(short.class.getName(), short.class);
48.46 + map.put(int.class.getName(), int.class);
48.47 + map.put(long.class.getName(), long.class);
48.48 + map.put(float.class.getName(), float.class);
48.49 + map.put(double.class.getName(), double.class);
48.50 + map.put(void.class.getName(), void.class);
48.51 }
48.52
48.53 /**
49.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
49.2 +++ b/src/share/classes/com/sun/beans/finder/PrimitiveWrapperMap.java Tue Feb 03 22:02:55 2009 -0800
49.3 @@ -0,0 +1,86 @@
49.4 +/*
49.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
49.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
49.7 + *
49.8 + * This code is free software; you can redistribute it and/or modify it
49.9 + * under the terms of the GNU General Public License version 2 only, as
49.10 + * published by the Free Software Foundation. Sun designates this
49.11 + * particular file as subject to the "Classpath" exception as provided
49.12 + * by Sun in the LICENSE file that accompanied this code.
49.13 + *
49.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
49.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
49.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
49.17 + * version 2 for more details (a copy is included in the LICENSE file that
49.18 + * accompanied this code).
49.19 + *
49.20 + * You should have received a copy of the GNU General Public License version
49.21 + * 2 along with this work; if not, write to the Free Software Foundation,
49.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
49.23 + *
49.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
49.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
49.26 + * have any questions.
49.27 + */
49.28 +package com.sun.beans.finder;
49.29 +
49.30 +import java.util.HashMap;
49.31 +import java.util.Map;
49.32 +
49.33 +/**
49.34 + * This utility class associates
49.35 + * name of primitive type with appropriate wrapper.
49.36 + *
49.37 + * @since 1.7
49.38 + *
49.39 + * @author Sergey A. Malenkov
49.40 + */
49.41 +public final class PrimitiveWrapperMap {
49.42 +
49.43 + /**
49.44 + * Replaces all primitive types in specified array with wrappers.
49.45 + *
49.46 + * @param types array of classes where all primitive types
49.47 + * will be replaced by appropriate wrappers
49.48 + */
49.49 + static void replacePrimitivesWithWrappers(Class<?>[] types) {
49.50 + for (int i = 0; i < types.length; i++) {
49.51 + if (types[i] != null) {
49.52 + if (types[i].isPrimitive()) {
49.53 + types[i] = getType(types[i].getName());
49.54 + }
49.55 + }
49.56 + }
49.57 + }
49.58 +
49.59 + /**
49.60 + * Returns wrapper for primitive type by its name.
49.61 + *
49.62 + * @param name the name of primitive type
49.63 + * @return found wrapper for primitive type,
49.64 + * or {@code null} if not found
49.65 + */
49.66 + public static Class<?> getType(String name) {
49.67 + return map.get(name);
49.68 + }
49.69 +
49.70 + private static final Map<String, Class<?>> map = new HashMap<String, Class<?>>(9);
49.71 +
49.72 + static {
49.73 + map.put(Boolean.TYPE.getName(), Boolean.class);
49.74 + map.put(Character.TYPE.getName(), Character.class);
49.75 + map.put(Byte.TYPE.getName(), Byte.class);
49.76 + map.put(Short.TYPE.getName(), Short.class);
49.77 + map.put(Integer.TYPE.getName(), Integer.class);
49.78 + map.put(Long.TYPE.getName(), Long.class);
49.79 + map.put(Float.TYPE.getName(), Float.class);
49.80 + map.put(Double.TYPE.getName(), Double.class);
49.81 + map.put(Void.TYPE.getName(), Void.class);
49.82 + }
49.83 +
49.84 + /**
49.85 + * Disable instantiation.
49.86 + */
49.87 + private PrimitiveWrapperMap() {
49.88 + }
49.89 +}
50.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
50.2 +++ b/src/share/classes/com/sun/beans/finder/Signature.java Tue Feb 03 22:02:55 2009 -0800
50.3 @@ -0,0 +1,169 @@
50.4 +/*
50.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
50.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
50.7 + *
50.8 + * This code is free software; you can redistribute it and/or modify it
50.9 + * under the terms of the GNU General Public License version 2 only, as
50.10 + * published by the Free Software Foundation. Sun designates this
50.11 + * particular file as subject to the "Classpath" exception as provided
50.12 + * by Sun in the LICENSE file that accompanied this code.
50.13 + *
50.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
50.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
50.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
50.17 + * version 2 for more details (a copy is included in the LICENSE file that
50.18 + * accompanied this code).
50.19 + *
50.20 + * You should have received a copy of the GNU General Public License version
50.21 + * 2 along with this work; if not, write to the Free Software Foundation,
50.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
50.23 + *
50.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
50.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
50.26 + * have any questions.
50.27 + */
50.28 +package com.sun.beans.finder;
50.29 +
50.30 +/**
50.31 + * This class is designed to be a key of a cache
50.32 + * of constructors or methods.
50.33 + *
50.34 + * @since 1.7
50.35 + *
50.36 + * @author Sergey A. Malenkov
50.37 + */
50.38 +final class Signature {
50.39 + private final Class<?> type;
50.40 + private final String name;
50.41 + private final Class<?>[] args;
50.42 +
50.43 + private volatile int code;
50.44 +
50.45 + /**
50.46 + * Constructs signature for constructor.
50.47 + *
50.48 + * @param type the class that contains constructor
50.49 + * @param args the types of constructor's parameters
50.50 + */
50.51 + Signature(Class<?> type, Class<?>[] args) {
50.52 + this(type, null, args);
50.53 + }
50.54 +
50.55 + /**
50.56 + * Constructs signature for method.
50.57 + *
50.58 + * @param type the class that contains method
50.59 + * @param name the name of the method
50.60 + * @param args the types of method's parameters
50.61 + */
50.62 + Signature(Class<?> type, String name, Class<?>[] args) {
50.63 + this.type = type;
50.64 + this.name = name;
50.65 + this.args = args;
50.66 + }
50.67 +
50.68 + /**
50.69 + * Indicates whether some other object is "equal to" this one.
50.70 + *
50.71 + * @param object the reference object with which to compare
50.72 + * @return {@code true} if this object is the same as the
50.73 + * {@code object} argument, {@code false} otherwise
50.74 + * @see #hashCode()
50.75 + */
50.76 + @Override
50.77 + public boolean equals(Object object) {
50.78 + if (this == object) {
50.79 + return true;
50.80 + }
50.81 + if (object instanceof Signature) {
50.82 + Signature signature = (Signature) object;
50.83 + return isEqual(signature.type, this.type)
50.84 + && isEqual(signature.name, this.name)
50.85 + && isEqual(signature.args, this.args);
50.86 + }
50.87 + return false;
50.88 + }
50.89 +
50.90 + /**
50.91 + * Indicates whether some object is "equal to" another one.
50.92 + * This method supports {@code null} values.
50.93 + *
50.94 + * @param obj1 the first reference object that will compared
50.95 + * @param obj2 the second reference object that will compared
50.96 + * @return {@code true} if first object is the same as the second object,
50.97 + * {@code false} otherwise
50.98 + */
50.99 + private static boolean isEqual(Object obj1, Object obj2) {
50.100 + return (obj1 == null)
50.101 + ? obj2 == null
50.102 + : obj1.equals(obj2);
50.103 + }
50.104 +
50.105 + /**
50.106 + * Indicates whether some array is "equal to" another one.
50.107 + * This method supports {@code null} values.
50.108 + *
50.109 + * @param args1 the first reference array that will compared
50.110 + * @param args2 the second reference array that will compared
50.111 + * @return {@code true} if first array is the same as the second array,
50.112 + * {@code false} otherwise
50.113 + */
50.114 + private static boolean isEqual(Class<?>[] args1, Class<?>[] args2) {
50.115 + if ((args1 == null) || (args2 == null)) {
50.116 + return args1 == args2;
50.117 + }
50.118 + if (args1.length != args2.length) {
50.119 + return false;
50.120 + }
50.121 + for (int i = 0; i < args1.length; i++) {
50.122 + if (!isEqual(args1[i], args2[i])) {
50.123 + return false;
50.124 + }
50.125 + }
50.126 + return true;
50.127 + }
50.128 +
50.129 + /**
50.130 + * Returns a hash code value for the object.
50.131 + * This method is supported for the benefit of hashtables
50.132 + * such as {@link java.util.HashMap} or {@link java.util.HashSet}.
50.133 + * Hash code computed using algorithm
50.134 + * suggested in Effective Java, Item 8.
50.135 + *
50.136 + * @return a hash code value for this object
50.137 + * @see #equals(Object)
50.138 + */
50.139 + @Override
50.140 + public int hashCode() {
50.141 + if (this.code == 0) {
50.142 + int code = 17;
50.143 + code = addHashCode(code, this.type);
50.144 + code = addHashCode(code, this.name);
50.145 +
50.146 + if (this.args != null) {
50.147 + for (Class<?> arg : this.args) {
50.148 + code = addHashCode(code, arg);
50.149 + }
50.150 + }
50.151 + this.code = code;
50.152 + }
50.153 + return this.code;
50.154 + }
50.155 +
50.156 + /**
50.157 + * Adds hash code value if specified object.
50.158 + * This is a part of the algorithm
50.159 + * suggested in Effective Java, Item 8.
50.160 + *
50.161 + * @param code current hash code value
50.162 + * @param object object that updates hash code value
50.163 + * @return updated hash code value
50.164 + * @see #hashCode()
50.165 + */
50.166 + private static int addHashCode(int code, Object object) {
50.167 + code *= 37;
50.168 + return (object != null)
50.169 + ? code + object.hashCode()
50.170 + : code;
50.171 + }
50.172 +}
51.1 --- a/src/share/classes/com/sun/java/swing/plaf/gtk/GTKColorChooserPanel.java Thu Jan 29 21:46:48 2009 -0800
51.2 +++ b/src/share/classes/com/sun/java/swing/plaf/gtk/GTKColorChooserPanel.java Tue Feb 03 22:02:55 2009 -0800
51.3 @@ -799,9 +799,9 @@
51.4 Graphics g = triangleImage.getGraphics();
51.5 g.setColor(new Color(0, 0, 0, 0));
51.6 g.fillRect(0, 0, a, a);
51.7 - g.translate((int)(a / 2), 0);
51.8 + g.translate(a / 2, 0);
51.9 paintTriangle(g, triangleSize, getColor());
51.10 - g.translate((int)(-a / 2), 0);
51.11 + g.translate(-a / 2, 0);
51.12 g.dispose();
51.13
51.14 g = wheelImage.getGraphics();
51.15 @@ -897,7 +897,7 @@
51.16 return false;
51.17 }
51.18 // Rotate to origin and and verify x is valid.
51.19 - int triangleSize = (int)innerR * 3 / 2;
51.20 + int triangleSize = innerR * 3 / 2;
51.21 double x1 = Math.cos(angle) * x - Math.sin(angle) * y;
51.22 double y1 = Math.sin(angle) * x + Math.cos(angle) * y;
51.23 if (x1 < -(innerR / 2)) {
51.24 @@ -960,7 +960,7 @@
51.25 */
51.26 private void setSaturationAndBrightness(float s, float b) {
51.27 int innerR = getTriangleCircumscribedRadius();
51.28 - int triangleSize = (int)innerR * 3 / 2;
51.29 + int triangleSize = innerR * 3 / 2;
51.30 double x = b * triangleSize;
51.31 double maxY = x * Math.tan(Math.toRadians(30.0));
51.32 double y = 2 * maxY * s - maxY;
51.33 @@ -1156,7 +1156,7 @@
51.34 * @param x X location to get color for
51.35 * @param y Y location to get color for
51.36 * @param rad Radius from center of color wheel
51.37 - * @param integer with red, green and blue components
51.38 + * @return integer with red, green and blue components
51.39 */
51.40 private int colorWheelLocationToRGB(int x, int y, double rad) {
51.41 double angle = Math.acos((double)x / rad);
51.42 @@ -1165,12 +1165,12 @@
51.43 if (angle < PI_3) {
51.44 if (y < 0) {
51.45 // FFFF00 - FF0000
51.46 - rgb = 0xFF0000 | (int)Math.min(255,
51.47 + rgb = 0xFF0000 | Math.min(255,
51.48 (int)(255 * angle / PI_3)) << 8;
51.49 }
51.50 else {
51.51 // FF0000 - FF00FF
51.52 - rgb = 0xFF0000 | (int)Math.min(255,
51.53 + rgb = 0xFF0000 | Math.min(255,
51.54 (int)(255 * angle / PI_3));
51.55 }
51.56 }
51.57 @@ -1178,12 +1178,12 @@
51.58 angle -= PI_3;
51.59 if (y < 0) {
51.60 // 00FF00 - FFFF00
51.61 - rgb = 0x00FF00 | (int)Math.max(0, 255 -
51.62 + rgb = 0x00FF00 | Math.max(0, 255 -
51.63 (int)(255 * angle / PI_3)) << 16;
51.64 }
51.65 else {
51.66 // FF00FF - 0000FF
51.67 - rgb = 0x0000FF | (int)Math.max(0, 255 -
51.68 + rgb = 0x0000FF | Math.max(0, 255 -
51.69 (int)(255 * angle / PI_3)) << 16;
51.70 }
51.71 }
51.72 @@ -1191,12 +1191,12 @@
51.73 angle -= 2 * PI_3;
51.74 if (y < 0) {
51.75 // 00FFFF - 00FF00
51.76 - rgb = 0x00FF00 | (int)Math.min(255,
51.77 + rgb = 0x00FF00 | Math.min(255,
51.78 (int)(255 * angle / PI_3));
51.79 }
51.80 else {
51.81 // 0000FF - 00FFFF
51.82 - rgb = 0x0000FF | (int)Math.min(255,
51.83 + rgb = 0x0000FF | Math.min(255,
51.84 (int)(255 * angle / PI_3)) << 8;
51.85 }
51.86 }
52.1 --- a/src/share/classes/com/sun/java/swing/plaf/gtk/GTKEngine.java Thu Jan 29 21:46:48 2009 -0800
52.2 +++ b/src/share/classes/com/sun/java/swing/plaf/gtk/GTKEngine.java Tue Feb 03 22:02:55 2009 -0800
52.3 @@ -112,7 +112,7 @@
52.4 }
52.5
52.6
52.7 - private static HashMap regionToWidgetTypeMap;
52.8 + private static HashMap<Region, Object> regionToWidgetTypeMap;
52.9 private ImageCache cache = new ImageCache(CACHE_SIZE);
52.10 private int x0, y0, w0, h0;
52.11 private Graphics graphics;
52.12 @@ -178,7 +178,7 @@
52.13 Toolkit.getDefaultToolkit();
52.14
52.15 // Initialize regionToWidgetTypeMap
52.16 - regionToWidgetTypeMap = new HashMap(50);
52.17 + regionToWidgetTypeMap = new HashMap<Region, Object>(50);
52.18 regionToWidgetTypeMap.put(Region.ARROW_BUTTON, new WidgetType[] {
52.19 WidgetType.SPINNER_ARROW_BUTTON,
52.20 WidgetType.COMBO_BOX_ARROW_BUTTON,
53.1 --- a/src/share/classes/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java Thu Jan 29 21:46:48 2009 -0800
53.2 +++ b/src/share/classes/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java Tue Feb 03 22:02:55 2009 -0800
53.3 @@ -148,7 +148,7 @@
53.4 directoryList : fileList;
53.5 Object[] files = list.getSelectedValues();
53.6 int len = files.length;
53.7 - Vector result = new Vector(len + 1);
53.8 + Vector<String> result = new Vector<String>(len + 1);
53.9
53.10 // we return all selected file names
53.11 for (int i = 0; i < len; i++) {
53.12 @@ -263,13 +263,13 @@
53.13 ListSelectionModel sm = directoryList.getSelectionModel();
53.14 if (sm instanceof DefaultListSelectionModel) {
53.15 ((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
53.16 - ((DefaultListSelectionModel)sm).setAnchorSelectionIndex(0);
53.17 + sm.setAnchorSelectionIndex(0);
53.18 }
53.19 fileList.clearSelection();
53.20 sm = fileList.getSelectionModel();
53.21 if (sm instanceof DefaultListSelectionModel) {
53.22 ((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
53.23 - ((DefaultListSelectionModel)sm).setAnchorSelectionIndex(0);
53.24 + sm.setAnchorSelectionIndex(0);
53.25 }
53.26
53.27 File currentDirectory = getFileChooser().getCurrentDirectory();
53.28 @@ -425,16 +425,16 @@
53.29 setDirectorySelected(true);
53.30 setDirectory(((File)objects[0]));
53.31 } else {
53.32 - ArrayList fList = new ArrayList(objects.length);
53.33 - for (int i = 0; i < objects.length; i++) {
53.34 - File f = (File)objects[i];
53.35 + ArrayList<File> fList = new ArrayList<File>(objects.length);
53.36 + for (Object object : objects) {
53.37 + File f = (File) object;
53.38 if ((chooser.isFileSelectionEnabled() && f.isFile())
53.39 || (chooser.isDirectorySelectionEnabled() && f.isDirectory())) {
53.40 fList.add(f);
53.41 }
53.42 }
53.43 if (fList.size() > 0) {
53.44 - files = (File[])fList.toArray(new File[fList.size()]);
53.45 + files = fList.toArray(new File[fList.size()]);
53.46 }
53.47 setDirectorySelected(false);
53.48 }
53.49 @@ -671,9 +671,9 @@
53.50
53.51 pathFieldLabel.setLabelFor(fileNameTextField);
53.52
53.53 - Set forwardTraversalKeys = fileNameTextField.getFocusTraversalKeys(
53.54 + Set<AWTKeyStroke> forwardTraversalKeys = fileNameTextField.getFocusTraversalKeys(
53.55 KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
53.56 - forwardTraversalKeys = new HashSet(forwardTraversalKeys);
53.57 + forwardTraversalKeys = new HashSet<AWTKeyStroke>(forwardTraversalKeys);
53.58 forwardTraversalKeys.remove(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
53.59 fileNameTextField.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forwardTraversalKeys);
53.60
53.61 @@ -895,10 +895,9 @@
53.62
53.63 private class GTKDirectoryModel extends BasicDirectoryModel {
53.64 FileSystemView fsv;
53.65 - private Comparator fileComparator = new Comparator() {
53.66 - public int compare(Object o, Object o1) {
53.67 - return fsv.getSystemDisplayName((File) o).compareTo
53.68 - (fsv.getSystemDisplayName((File) o1));
53.69 + private Comparator<File> fileComparator = new Comparator<File>() {
53.70 + public int compare(File o, File o1) {
53.71 + return fsv.getSystemDisplayName(o).compareTo(fsv.getSystemDisplayName(o1));
53.72 }
53.73 };
53.74
53.75 @@ -1074,7 +1073,7 @@
53.76 * Data model for a type-face selection combo-box.
53.77 */
53.78 protected class DirectoryComboBoxModel extends AbstractListModel implements ComboBoxModel {
53.79 - Vector directories = new Vector();
53.80 + Vector<File> directories = new Vector<File>();
53.81 File selectedDirectory = null;
53.82 JFileChooser chooser = getFileChooser();
53.83 FileSystemView fsv = chooser.getFileSystemView();
53.84 @@ -1216,7 +1215,7 @@
53.85 ListSelectionModel sm = fileList.getSelectionModel();
53.86 if (sm instanceof DefaultListSelectionModel) {
53.87 ((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
53.88 - ((DefaultListSelectionModel)sm).setAnchorSelectionIndex(0);
53.89 + sm.setAnchorSelectionIndex(0);
53.90 }
53.91 rescanCurrentDirectory(getFileChooser());
53.92 return;
53.93 @@ -1352,8 +1351,8 @@
53.94 FileFilter currentFilter = getFileChooser().getFileFilter();
53.95 boolean found = false;
53.96 if (currentFilter != null) {
53.97 - for (int i = 0; i < filters.length; i++) {
53.98 - if (filters[i] == currentFilter) {
53.99 + for (FileFilter filter : filters) {
53.100 + if (filter == currentFilter) {
53.101 found = true;
53.102 }
53.103 }
54.1 --- a/src/share/classes/com/sun/java/swing/plaf/gtk/GTKLookAndFeel.java Thu Jan 29 21:46:48 2009 -0800
54.2 +++ b/src/share/classes/com/sun/java/swing/plaf/gtk/GTKLookAndFeel.java Tue Feb 03 22:02:55 2009 -0800
54.3 @@ -1470,7 +1470,7 @@
54.4 aaTextInfo = SwingUtilities2.AATextInfo.getAATextInfo(gtkAAFontSettingsCond);
54.5 }
54.6
54.7 - static ReferenceQueue queue = new ReferenceQueue();
54.8 + static ReferenceQueue<GTKLookAndFeel> queue = new ReferenceQueue<GTKLookAndFeel>();
54.9
54.10 private static void flushUnreferenced() {
54.11 WeakPCL pcl;
54.12 @@ -1480,12 +1480,12 @@
54.13 }
54.14 }
54.15
54.16 - static class WeakPCL extends WeakReference implements
54.17 + static class WeakPCL extends WeakReference<GTKLookAndFeel> implements
54.18 PropertyChangeListener {
54.19 private Toolkit kit;
54.20 private String key;
54.21
54.22 - WeakPCL(Object target, Toolkit kit, String key) {
54.23 + WeakPCL(GTKLookAndFeel target, Toolkit kit, String key) {
54.24 super(target, queue);
54.25 this.kit = kit;
54.26 this.key = key;
54.27 @@ -1494,7 +1494,7 @@
54.28 public String getKey() { return key; }
54.29
54.30 public void propertyChange(final PropertyChangeEvent pce) {
54.31 - final GTKLookAndFeel lnf = (GTKLookAndFeel)get();
54.32 + final GTKLookAndFeel lnf = get();
54.33
54.34 if (lnf == null || UIManager.getLookAndFeel() != lnf) {
54.35 // The property was GC'ed, we're no longer interested in
55.1 --- a/src/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java Thu Jan 29 21:46:48 2009 -0800
55.2 +++ b/src/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java Tue Feb 03 22:02:55 2009 -0800
55.3 @@ -299,7 +299,7 @@
55.4 // Paint the default indicator
55.5 GTKStyle style = (GTKStyle)context.getStyle();
55.6 if (defaultCapable && !toolButton) {
55.7 - Insets defaultInsets = (Insets)style.getClassSpecificInsetsValue(
55.8 + Insets defaultInsets = style.getClassSpecificInsetsValue(
55.9 context, "default-border",
55.10 GTKStyle.BUTTON_DEFAULT_BORDER_INSETS);
55.11
56.1 --- a/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java Thu Jan 29 21:46:48 2009 -0800
56.2 +++ b/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java Tue Feb 03 22:02:55 2009 -0800
56.3 @@ -124,7 +124,7 @@
56.4 }
56.5
56.6 // Initialize constants
56.7 - variables = new HashMap();
56.8 + variables = new HashMap<String, Integer>();
56.9 NodeList nodes = xmlDoc.getElementsByTagName("constant");
56.10 int n = nodes.getLength();
56.11 for (int i = 0; i < n; i++) {
56.12 @@ -144,14 +144,14 @@
56.13 }
56.14
56.15 // Cache frame geometries
56.16 - frameGeometries = new HashMap();
56.17 + frameGeometries = new HashMap<String, Map<String, Object>>();
56.18 nodes = xmlDoc.getElementsByTagName("frame_geometry");
56.19 n = nodes.getLength();
56.20 for (int i = 0; i < n; i++) {
56.21 Node node = nodes.item(i);
56.22 String name = getStringAttr(node, "name");
56.23 if (name != null) {
56.24 - HashMap<String, Object> gm = new HashMap();
56.25 + HashMap<String, Object> gm = new HashMap<String, Object>();
56.26 frameGeometries.put(name, gm);
56.27
56.28 String parentGM = getStringAttr(node, "parent");
56.29 @@ -458,7 +458,7 @@
56.30
56.31
56.32
56.33 - private static class Privileged implements PrivilegedAction {
56.34 + private static class Privileged implements PrivilegedAction<Object> {
56.35 private static int GET_THEME_DIR = 0;
56.36 private static int GET_USER_THEME = 1;
56.37 private static int GET_IMAGE = 2;
56.38 @@ -598,7 +598,7 @@
56.39 g2.setComposite(oldComp);
56.40 }
56.41
56.42 - private HashMap<String, Image> images = new HashMap();
56.43 + private HashMap<String, Image> images = new HashMap<String, Image>();
56.44
56.45 protected Image getImage(String key, Color c) {
56.46 Image image = images.get(key+"-"+c.getRGB());
56.47 @@ -1530,8 +1530,8 @@
56.48 DocumentBuilderFactory.newInstance().newDocumentBuilder();
56.49 }
56.50 InputStream inputStream =
56.51 - (InputStream)AccessController.doPrivileged(new PrivilegedAction() {
56.52 - public Object run() {
56.53 + AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
56.54 + public InputStream run() {
56.55 try {
56.56 return new BufferedInputStream(xmlFile.openStream());
56.57 } catch (IOException ex) {
56.58 @@ -1551,7 +1551,7 @@
56.59 protected Node[] getNodesByName(Node parent, String name) {
56.60 NodeList nodes = parent.getChildNodes(); // ElementNode
56.61 int n = nodes.getLength();
56.62 - ArrayList<Node> list = new ArrayList();
56.63 + ArrayList<Node> list = new ArrayList<Node>();
56.64 for (int i=0; i < n; i++) {
56.65 Node node = nodes.item(i);
56.66 if (name.equals(node.getNodeName())) {
56.67 @@ -1603,7 +1603,7 @@
56.68 String aValue = attrs[a * 2 + 1];
56.69 Node attr = nodeAttrs.getNamedItem(aName);
56.70 if (attr == null ||
56.71 - aValue != null && !aValue.equals((String)attr.getNodeValue())) {
56.72 + aValue != null && !aValue.equals(attr.getNodeValue())) {
56.73 matches = false;
56.74 break;
56.75 }
56.76 @@ -1642,7 +1642,7 @@
56.77
56.78 protected String getStringAttr(NamedNodeMap attrs, String name) {
56.79 Node item = attrs.getNamedItem(name);
56.80 - return (item != null) ? (String)item.getNodeValue() : null;
56.81 + return (item != null) ? item.getNodeValue() : null;
56.82 }
56.83
56.84 protected boolean getBooleanAttr(Node node, String name, boolean fallback) {
57.1 --- a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java Thu Jan 29 21:46:48 2009 -0800
57.2 +++ b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java Tue Feb 03 22:02:55 2009 -0800
57.3 @@ -70,7 +70,6 @@
57.4 private JTextField filenameTextField;
57.5 private FilePane filePane;
57.6 private WindowsPlacesBar placesBar;
57.7 - private boolean useShellFolder;
57.8
57.9 private JButton approveButton;
57.10 private JButton cancelButton;
57.11 @@ -210,10 +209,6 @@
57.12 public ListSelectionListener createListSelectionListener() {
57.13 return WindowsFileChooserUI.this.createListSelectionListener(getFileChooser());
57.14 }
57.15 -
57.16 - public boolean usesShellFolder() {
57.17 - return useShellFolder;
57.18 - }
57.19 }
57.20
57.21 public void installComponents(JFileChooser fc) {
57.22 @@ -625,15 +620,8 @@
57.23 // Decide whether to use the ShellFolder class to populate shortcut
57.24 // panel and combobox.
57.25 JFileChooser fc = getFileChooser();
57.26 - Boolean prop =
57.27 - (Boolean)fc.getClientProperty("FileChooser.useShellFolder");
57.28 - if (prop != null) {
57.29 - useShellFolder = prop.booleanValue();
57.30 - } else {
57.31 - useShellFolder = fc.getFileSystemView().equals(FileSystemView.getFileSystemView());
57.32 - }
57.33 if (OS_VERSION.compareTo(OSInfo.WINDOWS_ME) >= 0) {
57.34 - if (useShellFolder) {
57.35 + if (FilePane.usesShellFolder(fc)) {
57.36 if (placesBar == null && !UIManager.getBoolean("FileChooser.noPlacesBar")) {
57.37 placesBar = new WindowsPlacesBar(fc, XPStyle.getXP() != null);
57.38 fc.add(placesBar, BorderLayout.BEFORE_LINE_BEGINS);
57.39 @@ -1149,6 +1137,8 @@
57.40 return;
57.41 }
57.42
57.43 + boolean useShellFolder = FilePane.usesShellFolder(chooser);
57.44 +
57.45 directories.clear();
57.46
57.47 File[] baseFolders;
58.1 --- a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java Thu Jan 29 21:46:48 2009 -0800
58.2 +++ b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java Tue Feb 03 22:02:55 2009 -0800
58.3 @@ -1554,10 +1554,10 @@
58.4 "Tree.selectionBackground", SelectionBackgroundColor,
58.5 "Tree.expandedIcon", treeExpandedIcon,
58.6 "Tree.collapsedIcon", treeCollapsedIcon,
58.7 - "Tree.openIcon", new ActiveWindowsIcon("win.icon.shellIconBPP", "shell32Icon 5",
58.8 - (Icon)table.get("Tree.openIcon")),
58.9 - "Tree.closedIcon", new ActiveWindowsIcon("win.icon.shellIconBPP", "shell32Icon 4",
58.10 - (Icon)table.get("Tree.closedIcon")),
58.11 + "Tree.openIcon", new ActiveWindowsIcon("win.icon.shellIconBPP",
58.12 + "shell32Icon 5", "icons/TreeOpen.gif"),
58.13 + "Tree.closedIcon", new ActiveWindowsIcon("win.icon.shellIconBPP",
58.14 + "shell32Icon 4", "icons/TreeClosed.gif"),
58.15 "Tree.focusInputMap",
58.16 new UIDefaults.LazyInputMap(new Object[] {
58.17 "ADD", "expand",
58.18 @@ -2205,21 +2205,21 @@
58.19 */
58.20 private class ActiveWindowsIcon implements UIDefaults.ActiveValue {
58.21 private Icon icon;
58.22 - private Icon fallback;
58.23 private String nativeImageName;
58.24 + private String fallbackName;
58.25 private DesktopProperty desktopProperty;
58.26
58.27 ActiveWindowsIcon(String desktopPropertyName,
58.28 - String nativeImageName, Icon fallback) {
58.29 + String nativeImageName, String fallbackName) {
58.30 this.nativeImageName = nativeImageName;
58.31 - this.fallback = fallback;
58.32 + this.fallbackName = fallbackName;
58.33
58.34 if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS &&
58.35 OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_XP) < 0) {
58.36 // This desktop property is needed to trigger reloading the icon.
58.37 // It is kept in member variable to avoid GC.
58.38 this.desktopProperty = new TriggerDesktopProperty(desktopPropertyName) {
58.39 - protected void updateUI() {
58.40 + @Override protected void updateUI() {
58.41 icon = null;
58.42 super.updateUI();
58.43 }
58.44 @@ -2227,6 +2227,7 @@
58.45 }
58.46 }
58.47
58.48 + @Override
58.49 public Object createValue(UIDefaults table) {
58.50 if (icon == null) {
58.51 Image image = (Image)ShellFolder.get(nativeImageName);
58.52 @@ -2234,8 +2235,11 @@
58.53 icon = new ImageIconUIResource(image);
58.54 }
58.55 }
58.56 - if (icon == null && fallback != null) {
58.57 - icon = fallback;
58.58 + if (icon == null && fallbackName != null) {
58.59 + UIDefaults.LazyValue fallback = (UIDefaults.LazyValue)
58.60 + SwingUtilities2.makeIcon(WindowsLookAndFeel.class,
58.61 + BasicLookAndFeel.class, fallbackName);
58.62 + icon = (Icon) fallback.createValue(table);
58.63 }
58.64 return icon;
58.65 }
59.1 --- a/src/share/classes/com/sun/media/sound/AbstractMidiDevice.java Thu Jan 29 21:46:48 2009 -0800
59.2 +++ b/src/share/classes/com/sun/media/sound/AbstractMidiDevice.java Tue Feb 03 22:02:55 2009 -0800
59.3 @@ -75,13 +75,6 @@
59.4 /**
59.5 * This is the device handle returned from native code
59.6 */
59.7 - /*
59.8 - * $$rratta Solaris 64 bit holds pointer must be long
59.9 - *
59.10 - * $$mp 2003-08-07:
59.11 - * 'id' is a really bad name. The variable should
59.12 - * be called nativePointer or something similar.
59.13 - */
59.14 protected long id = 0;
59.15
59.16
59.17 @@ -586,7 +579,6 @@
59.18
59.19 private ArrayList<Transmitter> transmitters = new ArrayList<Transmitter>();
59.20 private MidiOutDevice.MidiOutReceiver midiOutReceiver;
59.21 - private MixerSynth.SynthReceiver mixerSynthReceiver;
59.22
59.23 // how many transmitters must be present for optimized
59.24 // handling
59.25 @@ -621,22 +613,14 @@
59.26 if (midiOutReceiver == oldR) {
59.27 midiOutReceiver = null;
59.28 }
59.29 - if (mixerSynthReceiver == oldR) {
59.30 - mixerSynthReceiver = null;
59.31 - }
59.32 if (newR != null) {
59.33 if ((newR instanceof MidiOutDevice.MidiOutReceiver)
59.34 && (midiOutReceiver == null)) {
59.35 midiOutReceiver = ((MidiOutDevice.MidiOutReceiver) newR);
59.36 }
59.37 - if ((newR instanceof MixerSynth.SynthReceiver)
59.38 - && (mixerSynthReceiver == null)) {
59.39 - mixerSynthReceiver = ((MixerSynth.SynthReceiver) newR);
59.40 - }
59.41 }
59.42 optimizedReceiverCount =
59.43 - ((midiOutReceiver!=null)?1:0)
59.44 - + ((mixerSynthReceiver!=null)?1:0);
59.45 + ((midiOutReceiver!=null)?1:0);
59.46 }
59.47 // more potential for optimization here
59.48 }
59.49 @@ -670,10 +654,6 @@
59.50 if (TRACE_TRANSMITTER) Printer.println("Sending packed message to MidiOutReceiver");
59.51 midiOutReceiver.sendPackedMidiMessage(packedMessage, timeStamp);
59.52 }
59.53 - if (mixerSynthReceiver != null) {
59.54 - if (TRACE_TRANSMITTER) Printer.println("Sending packed message to MixerSynthReceiver");
59.55 - mixerSynthReceiver.sendPackedMidiMessage(packedMessage, timeStamp);
59.56 - }
59.57 } else {
59.58 if (TRACE_TRANSMITTER) Printer.println("Sending packed message to "+size+" transmitter's receivers");
59.59 for (int i = 0; i < size; i++) {
59.60 @@ -682,9 +662,6 @@
59.61 if (optimizedReceiverCount > 0) {
59.62 if (receiver instanceof MidiOutDevice.MidiOutReceiver) {
59.63 ((MidiOutDevice.MidiOutReceiver) receiver).sendPackedMidiMessage(packedMessage, timeStamp);
59.64 - }
59.65 - else if (receiver instanceof MixerSynth.SynthReceiver) {
59.66 - ((MixerSynth.SynthReceiver) receiver).sendPackedMidiMessage(packedMessage, timeStamp);
59.67 } else {
59.68 receiver.send(new FastShortMessage(packedMessage), timeStamp);
59.69 }
59.70 @@ -739,10 +716,6 @@
59.71 if (TRACE_TRANSMITTER) Printer.println("Sending MIDI message to MidiOutReceiver");
59.72 midiOutReceiver.send(message, timeStamp);
59.73 }
59.74 - if (mixerSynthReceiver != null) {
59.75 - if (TRACE_TRANSMITTER) Printer.println("Sending MIDI message to MixerSynthReceiver");
59.76 - mixerSynthReceiver.send(message, timeStamp);
59.77 - }
59.78 } else {
59.79 if (TRACE_TRANSMITTER) Printer.println("Sending MIDI message to "+size+" transmitter's receivers");
59.80 for (int i = 0; i < size; i++) {
60.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
60.2 +++ b/src/share/classes/com/sun/media/sound/AudioFileSoundbankReader.java Tue Feb 03 22:02:55 2009 -0800
60.3 @@ -0,0 +1,131 @@
60.4 +/*
60.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
60.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
60.7 + *
60.8 + * This code is free software; you can redistribute it and/or modify it
60.9 + * under the terms of the GNU General Public License version 2 only, as
60.10 + * published by the Free Software Foundation. Sun designates this
60.11 + * particular file as subject to the "Classpath" exception as provided
60.12 + * by Sun in the LICENSE file that accompanied this code.
60.13 + *
60.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
60.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
60.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
60.17 + * version 2 for more details (a copy is included in the LICENSE file that
60.18 + * accompanied this code).
60.19 + *
60.20 + * You should have received a copy of the GNU General Public License version
60.21 + * 2 along with this work; if not, write to the Free Software Foundation,
60.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
60.23 + *
60.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
60.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
60.26 + * have any questions.
60.27 + */
60.28 +package com.sun.media.sound;
60.29 +
60.30 +import java.io.ByteArrayOutputStream;
60.31 +import java.io.DataInputStream;
60.32 +import java.io.File;
60.33 +import java.io.IOException;
60.34 +import java.io.InputStream;
60.35 +import java.net.URL;
60.36 +
60.37 +import javax.sound.midi.InvalidMidiDataException;
60.38 +import javax.sound.midi.Soundbank;
60.39 +import javax.sound.midi.spi.SoundbankReader;
60.40 +import javax.sound.sampled.AudioInputStream;
60.41 +import javax.sound.sampled.AudioSystem;
60.42 +import javax.sound.sampled.UnsupportedAudioFileException;
60.43 +
60.44 +/**
60.45 + * Soundbank reader that uses audio files as soundbanks.
60.46 + *
60.47 + * @author Karl Helgason
60.48 + */
60.49 +public class AudioFileSoundbankReader extends SoundbankReader {
60.50 +
60.51 + public Soundbank getSoundbank(URL url)
60.52 + throws InvalidMidiDataException, IOException {
60.53 + try {
60.54 + AudioInputStream ais = AudioSystem.getAudioInputStream(url);
60.55 + Soundbank sbk = getSoundbank(ais);
60.56 + ais.close();
60.57 + return sbk;
60.58 + } catch (UnsupportedAudioFileException e) {
60.59 + return null;
60.60 + } catch (IOException e) {
60.61 + return null;
60.62 + }
60.63 + }
60.64 +
60.65 + public Soundbank getSoundbank(InputStream stream)
60.66 + throws InvalidMidiDataException, IOException {
60.67 + stream.mark(512);
60.68 + try {
60.69 + AudioInputStream ais = AudioSystem.getAudioInputStream(stream);
60.70 + Soundbank sbk = getSoundbank(ais);
60.71 + if (sbk != null)
60.72 + return sbk;
60.73 + } catch (UnsupportedAudioFileException e) {
60.74 + } catch (IOException e) {
60.75 + }
60.76 + stream.reset();
60.77 + return null;
60.78 + }
60.79 +
60.80 + public Soundbank getSoundbank(AudioInputStream ais)
60.81 + throws InvalidMidiDataException, IOException {
60.82 + try {
60.83 + byte[] buffer;
60.84 + if (ais.getFrameLength() == -1) {
60.85 + ByteArrayOutputStream baos = new ByteArrayOutputStream();
60.86 + byte[] buff = new byte[1024
60.87 + - (1024 % ais.getFormat().getFrameSize())];
60.88 + int ret;
60.89 + while ((ret = ais.read(buff)) != -1) {
60.90 + baos.write(buff, 0, ret);
60.91 + }
60.92 + ais.close();
60.93 + buffer = baos.toByteArray();
60.94 + } else {
60.95 + buffer = new byte[(int) (ais.getFrameLength()
60.96 + * ais.getFormat().getFrameSize())];
60.97 + new DataInputStream(ais).readFully(buffer);
60.98 + }
60.99 + ModelByteBufferWavetable osc = new ModelByteBufferWavetable(
60.100 + new ModelByteBuffer(buffer), ais.getFormat(), -4800);
60.101 + ModelPerformer performer = new ModelPerformer();
60.102 + performer.getOscillators().add(osc);
60.103 +
60.104 + SimpleSoundbank sbk = new SimpleSoundbank();
60.105 + SimpleInstrument ins = new SimpleInstrument();
60.106 + ins.add(performer);
60.107 + sbk.addInstrument(ins);
60.108 + return sbk;
60.109 + } catch (Exception e) {
60.110 + return null;
60.111 + }
60.112 + }
60.113 +
60.114 + public Soundbank getSoundbank(File file)
60.115 + throws InvalidMidiDataException, IOException {
60.116 + try {
60.117 + AudioInputStream ais = AudioSystem.getAudioInputStream(file);
60.118 + ais.close();
60.119 + ModelByteBufferWavetable osc = new ModelByteBufferWavetable(
60.120 + new ModelByteBuffer(file, 0, file.length()), -4800);
60.121 + ModelPerformer performer = new ModelPerformer();
60.122 + performer.getOscillators().add(osc);
60.123 + SimpleSoundbank sbk = new SimpleSoundbank();
60.124 + SimpleInstrument ins = new SimpleInstrument();
60.125 + ins.add(performer);
60.126 + sbk.addInstrument(ins);
60.127 + return sbk;
60.128 + } catch (UnsupportedAudioFileException e1) {
60.129 + return null;
60.130 + } catch (IOException e) {
60.131 + return null;
60.132 + }
60.133 + }
60.134 +}
61.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
61.2 +++ b/src/share/classes/com/sun/media/sound/AudioFloatConverter.java Tue Feb 03 22:02:55 2009 -0800
61.3 @@ -0,0 +1,1058 @@
61.4 +/*
61.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
61.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
61.7 + *
61.8 + * This code is free software; you can redistribute it and/or modify it
61.9 + * under the terms of the GNU General Public License version 2 only, as
61.10 + * published by the Free Software Foundation. Sun designates this
61.11 + * particular file as subject to the "Classpath" exception as provided
61.12 + * by Sun in the LICENSE file that accompanied this code.
61.13 + *
61.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
61.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
61.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
61.17 + * version 2 for more details (a copy is included in the LICENSE file that
61.18 + * accompanied this code).
61.19 + *
61.20 + * You should have received a copy of the GNU General Public License version
61.21 + * 2 along with this work; if not, write to the Free Software Foundation,
61.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
61.23 + *
61.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
61.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
61.26 + * have any questions.
61.27 + */
61.28 +package com.sun.media.sound;
61.29 +
61.30 +import java.nio.ByteBuffer;
61.31 +import java.nio.ByteOrder;
61.32 +import java.nio.DoubleBuffer;
61.33 +import java.nio.FloatBuffer;
61.34 +
61.35 +import javax.sound.sampled.AudioFormat;
61.36 +import javax.sound.sampled.AudioFormat.Encoding;
61.37 +
61.38 +/**
61.39 + * This class is used to convert between 8,16,24,32,32+ bit signed/unsigned
61.40 + * big/litle endian fixed/floating point byte buffers and float buffers.
61.41 + *
61.42 + * @author Karl Helgason
61.43 + */
61.44 +public abstract class AudioFloatConverter {
61.45 +
61.46 + public static final Encoding PCM_FLOAT = new Encoding("PCM_FLOAT");
61.47 +
61.48 + /***************************************************************************
61.49 + *
61.50 + * LSB Filter, used filter least significant byte in samples arrays.
61.51 + *
61.52 + * Is used filter out data in lsb byte when SampleSizeInBits is not
61.53 + * dividable by 8.
61.54 + *
61.55 + **************************************************************************/
61.56 +
61.57 + private static class AudioFloatLSBFilter extends AudioFloatConverter {
61.58 +
61.59 + private AudioFloatConverter converter;
61.60 +
61.61 + final private int offset;
61.62 +
61.63 + final private int stepsize;
61.64 +
61.65 + final private byte mask;
61.66 +
61.67 + private byte[] mask_buffer;
61.68 +
61.69 + public AudioFloatLSBFilter(AudioFloatConverter converter,
61.70 + AudioFormat format) {
61.71 + int bits = format.getSampleSizeInBits();
61.72 + boolean bigEndian = format.isBigEndian();
61.73 + this.converter = converter;
61.74 + stepsize = (bits + 7) / 8;
61.75 + offset = bigEndian ? (stepsize - 1) : 0;
61.76 + int lsb_bits = bits % 8;
61.77 + if (lsb_bits == 0)
61.78 + mask = (byte) 0x00;
61.79 + else if (lsb_bits == 1)
61.80 + mask = (byte) 0x80;
61.81 + else if (lsb_bits == 2)
61.82 + mask = (byte) 0xC0;
61.83 + else if (lsb_bits == 3)
61.84 + mask = (byte) 0xE0;
61.85 + else if (lsb_bits == 4)
61.86 + mask = (byte) 0xF0;
61.87 + else if (lsb_bits == 5)
61.88 + mask = (byte) 0xF8;
61.89 + else if (lsb_bits == 6)
61.90 + mask = (byte) 0xFC;
61.91 + else if (lsb_bits == 7)
61.92 + mask = (byte) 0xFE;
61.93 + else
61.94 + mask = (byte) 0xFF;
61.95 + }
61.96 +
61.97 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.98 + byte[] out_buff, int out_offset) {
61.99 + byte[] ret = converter.toByteArray(in_buff, in_offset, in_len,
61.100 + out_buff, out_offset);
61.101 +
61.102 + int out_offset_end = in_len * stepsize;
61.103 + for (int i = out_offset + offset; i < out_offset_end; i += stepsize) {
61.104 + out_buff[i] = (byte) (out_buff[i] & mask);
61.105 + }
61.106 +
61.107 + return ret;
61.108 + }
61.109 +
61.110 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.111 + float[] out_buff, int out_offset, int out_len) {
61.112 + if (mask_buffer == null || mask_buffer.length < in_buff.length)
61.113 + mask_buffer = new byte[in_buff.length];
61.114 + System.arraycopy(in_buff, 0, mask_buffer, 0, in_buff.length);
61.115 + int in_offset_end = out_len * stepsize;
61.116 + for (int i = in_offset + offset; i < in_offset_end; i += stepsize) {
61.117 + mask_buffer[i] = (byte) (mask_buffer[i] & mask);
61.118 + }
61.119 + float[] ret = converter.toFloatArray(mask_buffer, in_offset,
61.120 + out_buff, out_offset, out_len);
61.121 + return ret;
61.122 + }
61.123 +
61.124 + }
61.125 +
61.126 + /***************************************************************************
61.127 + *
61.128 + * 64 bit float, little/big-endian
61.129 + *
61.130 + **************************************************************************/
61.131 +
61.132 + // PCM 64 bit float, little-endian
61.133 + private static class AudioFloatConversion64L extends AudioFloatConverter {
61.134 + ByteBuffer bytebuffer = null;
61.135 +
61.136 + DoubleBuffer floatbuffer = null;
61.137 +
61.138 + double[] double_buff = null;
61.139 +
61.140 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.141 + float[] out_buff, int out_offset, int out_len) {
61.142 + int in_len = out_len * 8;
61.143 + if (bytebuffer == null || bytebuffer.capacity() < in_len) {
61.144 + bytebuffer = ByteBuffer.allocate(in_len).order(
61.145 + ByteOrder.LITTLE_ENDIAN);
61.146 + floatbuffer = bytebuffer.asDoubleBuffer();
61.147 + }
61.148 + bytebuffer.position(0);
61.149 + floatbuffer.position(0);
61.150 + bytebuffer.put(in_buff, in_offset, in_len);
61.151 + if (double_buff == null
61.152 + || double_buff.length < out_len + out_offset)
61.153 + double_buff = new double[out_len + out_offset];
61.154 + floatbuffer.get(double_buff, out_offset, out_len);
61.155 + int out_offset_end = out_offset + out_len;
61.156 + for (int i = out_offset; i < out_offset_end; i++) {
61.157 + out_buff[i] = (float) double_buff[i];
61.158 + }
61.159 + return out_buff;
61.160 + }
61.161 +
61.162 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.163 + byte[] out_buff, int out_offset) {
61.164 + int out_len = in_len * 8;
61.165 + if (bytebuffer == null || bytebuffer.capacity() < out_len) {
61.166 + bytebuffer = ByteBuffer.allocate(out_len).order(
61.167 + ByteOrder.LITTLE_ENDIAN);
61.168 + floatbuffer = bytebuffer.asDoubleBuffer();
61.169 + }
61.170 + floatbuffer.position(0);
61.171 + bytebuffer.position(0);
61.172 + if (double_buff == null || double_buff.length < in_offset + in_len)
61.173 + double_buff = new double[in_offset + in_len];
61.174 + int in_offset_end = in_offset + in_len;
61.175 + for (int i = in_offset; i < in_offset_end; i++) {
61.176 + double_buff[i] = in_buff[i];
61.177 + }
61.178 + floatbuffer.put(double_buff, in_offset, in_len);
61.179 + bytebuffer.get(out_buff, out_offset, out_len);
61.180 + return out_buff;
61.181 + }
61.182 + }
61.183 +
61.184 + // PCM 64 bit float, big-endian
61.185 + private static class AudioFloatConversion64B extends AudioFloatConverter {
61.186 + ByteBuffer bytebuffer = null;
61.187 +
61.188 + DoubleBuffer floatbuffer = null;
61.189 +
61.190 + double[] double_buff = null;
61.191 +
61.192 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.193 + float[] out_buff, int out_offset, int out_len) {
61.194 + int in_len = out_len * 8;
61.195 + if (bytebuffer == null || bytebuffer.capacity() < in_len) {
61.196 + bytebuffer = ByteBuffer.allocate(in_len).order(
61.197 + ByteOrder.BIG_ENDIAN);
61.198 + floatbuffer = bytebuffer.asDoubleBuffer();
61.199 + }
61.200 + bytebuffer.position(0);
61.201 + floatbuffer.position(0);
61.202 + bytebuffer.put(in_buff, in_offset, in_len);
61.203 + if (double_buff == null
61.204 + || double_buff.length < out_len + out_offset)
61.205 + double_buff = new double[out_len + out_offset];
61.206 + floatbuffer.get(double_buff, out_offset, out_len);
61.207 + int out_offset_end = out_offset + out_len;
61.208 + for (int i = out_offset; i < out_offset_end; i++) {
61.209 + out_buff[i] = (float) double_buff[i];
61.210 + }
61.211 + return out_buff;
61.212 + }
61.213 +
61.214 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.215 + byte[] out_buff, int out_offset) {
61.216 + int out_len = in_len * 8;
61.217 + if (bytebuffer == null || bytebuffer.capacity() < out_len) {
61.218 + bytebuffer = ByteBuffer.allocate(out_len).order(
61.219 + ByteOrder.BIG_ENDIAN);
61.220 + floatbuffer = bytebuffer.asDoubleBuffer();
61.221 + }
61.222 + floatbuffer.position(0);
61.223 + bytebuffer.position(0);
61.224 + if (double_buff == null || double_buff.length < in_offset + in_len)
61.225 + double_buff = new double[in_offset + in_len];
61.226 + int in_offset_end = in_offset + in_len;
61.227 + for (int i = in_offset; i < in_offset_end; i++) {
61.228 + double_buff[i] = in_buff[i];
61.229 + }
61.230 + floatbuffer.put(double_buff, in_offset, in_len);
61.231 + bytebuffer.get(out_buff, out_offset, out_len);
61.232 + return out_buff;
61.233 + }
61.234 + }
61.235 +
61.236 + /***************************************************************************
61.237 + *
61.238 + * 32 bit float, little/big-endian
61.239 + *
61.240 + **************************************************************************/
61.241 +
61.242 + // PCM 32 bit float, little-endian
61.243 + private static class AudioFloatConversion32L extends AudioFloatConverter {
61.244 + ByteBuffer bytebuffer = null;
61.245 +
61.246 + FloatBuffer floatbuffer = null;
61.247 +
61.248 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.249 + float[] out_buff, int out_offset, int out_len) {
61.250 + int in_len = out_len * 4;
61.251 + if (bytebuffer == null || bytebuffer.capacity() < in_len) {
61.252 + bytebuffer = ByteBuffer.allocate(in_len).order(
61.253 + ByteOrder.LITTLE_ENDIAN);
61.254 + floatbuffer = bytebuffer.asFloatBuffer();
61.255 + }
61.256 + bytebuffer.position(0);
61.257 + floatbuffer.position(0);
61.258 + bytebuffer.put(in_buff, in_offset, in_len);
61.259 + floatbuffer.get(out_buff, out_offset, out_len);
61.260 + return out_buff;
61.261 + }
61.262 +
61.263 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.264 + byte[] out_buff, int out_offset) {
61.265 + int out_len = in_len * 4;
61.266 + if (bytebuffer == null || bytebuffer.capacity() < out_len) {
61.267 + bytebuffer = ByteBuffer.allocate(out_len).order(
61.268 + ByteOrder.LITTLE_ENDIAN);
61.269 + floatbuffer = bytebuffer.asFloatBuffer();
61.270 + }
61.271 + floatbuffer.position(0);
61.272 + bytebuffer.position(0);
61.273 + floatbuffer.put(in_buff, in_offset, in_len);
61.274 + bytebuffer.get(out_buff, out_offset, out_len);
61.275 + return out_buff;
61.276 + }
61.277 + }
61.278 +
61.279 + // PCM 32 bit float, big-endian
61.280 + private static class AudioFloatConversion32B extends AudioFloatConverter {
61.281 + ByteBuffer bytebuffer = null;
61.282 +
61.283 + FloatBuffer floatbuffer = null;
61.284 +
61.285 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.286 + float[] out_buff, int out_offset, int out_len) {
61.287 + int in_len = out_len * 4;
61.288 + if (bytebuffer == null || bytebuffer.capacity() < in_len) {
61.289 + bytebuffer = ByteBuffer.allocate(in_len).order(
61.290 + ByteOrder.BIG_ENDIAN);
61.291 + floatbuffer = bytebuffer.asFloatBuffer();
61.292 + }
61.293 + bytebuffer.position(0);
61.294 + floatbuffer.position(0);
61.295 + bytebuffer.put(in_buff, in_offset, in_len);
61.296 + floatbuffer.get(out_buff, out_offset, out_len);
61.297 + return out_buff;
61.298 + }
61.299 +
61.300 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.301 + byte[] out_buff, int out_offset) {
61.302 + int out_len = in_len * 4;
61.303 + if (bytebuffer == null || bytebuffer.capacity() < out_len) {
61.304 + bytebuffer = ByteBuffer.allocate(out_len).order(
61.305 + ByteOrder.BIG_ENDIAN);
61.306 + floatbuffer = bytebuffer.asFloatBuffer();
61.307 + }
61.308 + floatbuffer.position(0);
61.309 + bytebuffer.position(0);
61.310 + floatbuffer.put(in_buff, in_offset, in_len);
61.311 + bytebuffer.get(out_buff, out_offset, out_len);
61.312 + return out_buff;
61.313 + }
61.314 + }
61.315 +
61.316 + /***************************************************************************
61.317 + *
61.318 + * 8 bit signed/unsigned
61.319 + *
61.320 + **************************************************************************/
61.321 +
61.322 + // PCM 8 bit, signed
61.323 + private static class AudioFloatConversion8S extends AudioFloatConverter {
61.324 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.325 + float[] out_buff, int out_offset, int out_len) {
61.326 + int ix = in_offset;
61.327 + int ox = out_offset;
61.328 + for (int i = 0; i < out_len; i++)
61.329 + out_buff[ox++] = in_buff[ix++] * (1.0f / 127.0f);
61.330 + return out_buff;
61.331 + }
61.332 +
61.333 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.334 + byte[] out_buff, int out_offset) {
61.335 + int ix = in_offset;
61.336 + int ox = out_offset;
61.337 + for (int i = 0; i < in_len; i++)
61.338 + out_buff[ox++] = (byte) (in_buff[ix++] * 127.0f);
61.339 + return out_buff;
61.340 + }
61.341 + }
61.342 +
61.343 + // PCM 8 bit, unsigned
61.344 + private static class AudioFloatConversion8U extends AudioFloatConverter {
61.345 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.346 + float[] out_buff, int out_offset, int out_len) {
61.347 + int ix = in_offset;
61.348 + int ox = out_offset;
61.349 + for (int i = 0; i < out_len; i++)
61.350 + out_buff[ox++] = ((in_buff[ix++] & 0xFF) - 127)
61.351 + * (1.0f / 127.0f);
61.352 + return out_buff;
61.353 + }
61.354 +
61.355 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.356 + byte[] out_buff, int out_offset) {
61.357 + int ix = in_offset;
61.358 + int ox = out_offset;
61.359 + for (int i = 0; i < in_len; i++)
61.360 + out_buff[ox++] = (byte) (127 + in_buff[ix++] * 127.0f);
61.361 + return out_buff;
61.362 + }
61.363 + }
61.364 +
61.365 + /***************************************************************************
61.366 + *
61.367 + * 16 bit signed/unsigned, little/big-endian
61.368 + *
61.369 + **************************************************************************/
61.370 +
61.371 + // PCM 16 bit, signed, little-endian
61.372 + private static class AudioFloatConversion16SL extends AudioFloatConverter {
61.373 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.374 + float[] out_buff, int out_offset, int out_len) {
61.375 + int ix = in_offset;
61.376 + int len = out_offset + out_len;
61.377 + for (int ox = out_offset; ox < len; ox++) {
61.378 + out_buff[ox] = ((short) ((in_buff[ix++] & 0xFF) |
61.379 + (in_buff[ix++] << 8))) * (1.0f / 32767.0f);
61.380 + }
61.381 +
61.382 + return out_buff;
61.383 + }
61.384 +
61.385 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.386 + byte[] out_buff, int out_offset) {
61.387 + int ox = out_offset;
61.388 + int len = in_offset + in_len;
61.389 + for (int ix = in_offset; ix < len; ix++) {
61.390 + int x = (int) (in_buff[ix] * 32767.0);
61.391 + out_buff[ox++] = (byte) x;
61.392 + out_buff[ox++] = (byte) (x >>> 8);
61.393 + }
61.394 + return out_buff;
61.395 + }
61.396 + }
61.397 +
61.398 + // PCM 16 bit, signed, big-endian
61.399 + private static class AudioFloatConversion16SB extends AudioFloatConverter {
61.400 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.401 + float[] out_buff, int out_offset, int out_len) {
61.402 + int ix = in_offset;
61.403 + int ox = out_offset;
61.404 + for (int i = 0; i < out_len; i++) {
61.405 + out_buff[ox++] = ((short) ((in_buff[ix++] << 8) |
61.406 + (in_buff[ix++] & 0xFF))) * (1.0f / 32767.0f);
61.407 + }
61.408 + return out_buff;
61.409 + }
61.410 +
61.411 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.412 + byte[] out_buff, int out_offset) {
61.413 + int ix = in_offset;
61.414 + int ox = out_offset;
61.415 + for (int i = 0; i < in_len; i++) {
61.416 + int x = (int) (in_buff[ix++] * 32767.0);
61.417 + out_buff[ox++] = (byte) (x >>> 8);
61.418 + out_buff[ox++] = (byte) x;
61.419 + }
61.420 + return out_buff;
61.421 + }
61.422 + }
61.423 +
61.424 + // PCM 16 bit, unsigned, little-endian
61.425 + private static class AudioFloatConversion16UL extends AudioFloatConverter {
61.426 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.427 + float[] out_buff, int out_offset, int out_len) {
61.428 + int ix = in_offset;
61.429 + int ox = out_offset;
61.430 + for (int i = 0; i < out_len; i++) {
61.431 + int x = (in_buff[ix++] & 0xFF) | ((in_buff[ix++] & 0xFF) << 8);
61.432 + out_buff[ox++] = (x - 32767) * (1.0f / 32767.0f);
61.433 + }
61.434 + return out_buff;
61.435 + }
61.436 +
61.437 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.438 + byte[] out_buff, int out_offset) {
61.439 + int ix = in_offset;
61.440 + int ox = out_offset;
61.441 + for (int i = 0; i < in_len; i++) {
61.442 + int x = 32767 + (int) (in_buff[ix++] * 32767.0);
61.443 + out_buff[ox++] = (byte) x;
61.444 + out_buff[ox++] = (byte) (x >>> 8);
61.445 + }
61.446 + return out_buff;
61.447 + }
61.448 + }
61.449 +
61.450 + // PCM 16 bit, unsigned, big-endian
61.451 + private static class AudioFloatConversion16UB extends AudioFloatConverter {
61.452 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.453 + float[] out_buff, int out_offset, int out_len) {
61.454 + int ix = in_offset;
61.455 + int ox = out_offset;
61.456 + for (int i = 0; i < out_len; i++) {
61.457 + int x = ((in_buff[ix++] & 0xFF) << 8) | (in_buff[ix++] & 0xFF);
61.458 + out_buff[ox++] = (x - 32767) * (1.0f / 32767.0f);
61.459 + }
61.460 + return out_buff;
61.461 + }
61.462 +
61.463 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.464 + byte[] out_buff, int out_offset) {
61.465 + int ix = in_offset;
61.466 + int ox = out_offset;
61.467 + for (int i = 0; i < in_len; i++) {
61.468 + int x = 32767 + (int) (in_buff[ix++] * 32767.0);
61.469 + out_buff[ox++] = (byte) (x >>> 8);
61.470 + out_buff[ox++] = (byte) x;
61.471 + }
61.472 + return out_buff;
61.473 + }
61.474 + }
61.475 +
61.476 + /***************************************************************************
61.477 + *
61.478 + * 24 bit signed/unsigned, little/big-endian
61.479 + *
61.480 + **************************************************************************/
61.481 +
61.482 + // PCM 24 bit, signed, little-endian
61.483 + private static class AudioFloatConversion24SL extends AudioFloatConverter {
61.484 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.485 + float[] out_buff, int out_offset, int out_len) {
61.486 + int ix = in_offset;
61.487 + int ox = out_offset;
61.488 + for (int i = 0; i < out_len; i++) {
61.489 + int x = (in_buff[ix++] & 0xFF) | ((in_buff[ix++] & 0xFF) << 8)
61.490 + | ((in_buff[ix++] & 0xFF) << 16);
61.491 + if (x > 0x7FFFFF)
61.492 + x -= 0x1000000;
61.493 + out_buff[ox++] = x * (1.0f / (float)0x7FFFFF);
61.494 + }
61.495 + return out_buff;
61.496 + }
61.497 +
61.498 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.499 + byte[] out_buff, int out_offset) {
61.500 + int ix = in_offset;
61.501 + int ox = out_offset;
61.502 + for (int i = 0; i < in_len; i++) {
61.503 + int x = (int) (in_buff[ix++] * (float)0x7FFFFF);
61.504 + if (x < 0)
61.505 + x += 0x1000000;
61.506 + out_buff[ox++] = (byte) x;
61.507 + out_buff[ox++] = (byte) (x >>> 8);
61.508 + out_buff[ox++] = (byte) (x >>> 16);
61.509 + }
61.510 + return out_buff;
61.511 + }
61.512 + }
61.513 +
61.514 + // PCM 24 bit, signed, big-endian
61.515 + private static class AudioFloatConversion24SB extends AudioFloatConverter {
61.516 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.517 + float[] out_buff, int out_offset, int out_len) {
61.518 + int ix = in_offset;
61.519 + int ox = out_offset;
61.520 + for (int i = 0; i < out_len; i++) {
61.521 + int x = ((in_buff[ix++] & 0xFF) << 16)
61.522 + | ((in_buff[ix++] & 0xFF) << 8) | (in_buff[ix++] & 0xFF);
61.523 + if (x > 0x7FFFFF)
61.524 + x -= 0x1000000;
61.525 + out_buff[ox++] = x * (1.0f / (float)0x7FFFFF);
61.526 + }
61.527 + return out_buff;
61.528 + }
61.529 +
61.530 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.531 + byte[] out_buff, int out_offset) {
61.532 + int ix = in_offset;
61.533 + int ox = out_offset;
61.534 + for (int i = 0; i < in_len; i++) {
61.535 + int x = (int) (in_buff[ix++] * (float)0x7FFFFF);
61.536 + if (x < 0)
61.537 + x += 0x1000000;
61.538 + out_buff[ox++] = (byte) (x >>> 16);
61.539 + out_buff[ox++] = (byte) (x >>> 8);
61.540 + out_buff[ox++] = (byte) x;
61.541 + }
61.542 + return out_buff;
61.543 + }
61.544 + }
61.545 +
61.546 + // PCM 24 bit, unsigned, little-endian
61.547 + private static class AudioFloatConversion24UL extends AudioFloatConverter {
61.548 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.549 + float[] out_buff, int out_offset, int out_len) {
61.550 + int ix = in_offset;
61.551 + int ox = out_offset;
61.552 + for (int i = 0; i < out_len; i++) {
61.553 + int x = (in_buff[ix++] & 0xFF) | ((in_buff[ix++] & 0xFF) << 8)
61.554 + | ((in_buff[ix++] & 0xFF) << 16);
61.555 + x -= 0x7FFFFF;
61.556 + out_buff[ox++] = x * (1.0f / (float)0x7FFFFF);
61.557 + }
61.558 + return out_buff;
61.559 + }
61.560 +
61.561 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.562 + byte[] out_buff, int out_offset) {
61.563 + int ix = in_offset;
61.564 + int ox = out_offset;
61.565 + for (int i = 0; i < in_len; i++) {
61.566 + int x = (int) (in_buff[ix++] * (float)0x7FFFFF);
61.567 + x += 0x7FFFFF;
61.568 + out_buff[ox++] = (byte) x;
61.569 + out_buff[ox++] = (byte) (x >>> 8);
61.570 + out_buff[ox++] = (byte) (x >>> 16);
61.571 + }
61.572 + return out_buff;
61.573 + }
61.574 + }
61.575 +
61.576 + // PCM 24 bit, unsigned, big-endian
61.577 + private static class AudioFloatConversion24UB extends AudioFloatConverter {
61.578 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.579 + float[] out_buff, int out_offset, int out_len) {
61.580 + int ix = in_offset;
61.581 + int ox = out_offset;
61.582 + for (int i = 0; i < out_len; i++) {
61.583 + int x = ((in_buff[ix++] & 0xFF) << 16)
61.584 + | ((in_buff[ix++] & 0xFF) << 8) | (in_buff[ix++] & 0xFF);
61.585 + x -= 0x7FFFFF;
61.586 + out_buff[ox++] = x * (1.0f / (float)0x7FFFFF);
61.587 + }
61.588 + return out_buff;
61.589 + }
61.590 +
61.591 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.592 + byte[] out_buff, int out_offset) {
61.593 + int ix = in_offset;
61.594 + int ox = out_offset;
61.595 + for (int i = 0; i < in_len; i++) {
61.596 + int x = (int) (in_buff[ix++] * (float)0x7FFFFF);
61.597 + x += 0x7FFFFF;
61.598 + out_buff[ox++] = (byte) (x >>> 16);
61.599 + out_buff[ox++] = (byte) (x >>> 8);
61.600 + out_buff[ox++] = (byte) x;
61.601 + }
61.602 + return out_buff;
61.603 + }
61.604 + }
61.605 +
61.606 + /***************************************************************************
61.607 + *
61.608 + * 32 bit signed/unsigned, little/big-endian
61.609 + *
61.610 + **************************************************************************/
61.611 +
61.612 + // PCM 32 bit, signed, little-endian
61.613 + private static class AudioFloatConversion32SL extends AudioFloatConverter {
61.614 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.615 + float[] out_buff, int out_offset, int out_len) {
61.616 + int ix = in_offset;
61.617 + int ox = out_offset;
61.618 + for (int i = 0; i < out_len; i++) {
61.619 + int x = (in_buff[ix++] & 0xFF) | ((in_buff[ix++] & 0xFF) << 8) |
61.620 + ((in_buff[ix++] & 0xFF) << 16) |
61.621 + ((in_buff[ix++] & 0xFF) << 24);
61.622 + out_buff[ox++] = x * (1.0f / (float)0x7FFFFFFF);
61.623 + }
61.624 + return out_buff;
61.625 + }
61.626 +
61.627 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.628 + byte[] out_buff, int out_offset) {
61.629 + int ix = in_offset;
61.630 + int ox = out_offset;
61.631 + for (int i = 0; i < in_len; i++) {
61.632 + int x = (int) (in_buff[ix++] * (float)0x7FFFFFFF);
61.633 + out_buff[ox++] = (byte) x;
61.634 + out_buff[ox++] = (byte) (x >>> 8);
61.635 + out_buff[ox++] = (byte) (x >>> 16);
61.636 + out_buff[ox++] = (byte) (x >>> 24);
61.637 + }
61.638 + return out_buff;
61.639 + }
61.640 + }
61.641 +
61.642 + // PCM 32 bit, signed, big-endian
61.643 + private static class AudioFloatConversion32SB extends AudioFloatConverter {
61.644 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.645 + float[] out_buff, int out_offset, int out_len) {
61.646 + int ix = in_offset;
61.647 + int ox = out_offset;
61.648 + for (int i = 0; i < out_len; i++) {
61.649 + int x = ((in_buff[ix++] & 0xFF) << 24) |
61.650 + ((in_buff[ix++] & 0xFF) << 16) |
61.651 + ((in_buff[ix++] & 0xFF) << 8) | (in_buff[ix++] & 0xFF);
61.652 + out_buff[ox++] = x * (1.0f / (float)0x7FFFFFFF);
61.653 + }
61.654 + return out_buff;
61.655 + }
61.656 +
61.657 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.658 + byte[] out_buff, int out_offset) {
61.659 + int ix = in_offset;
61.660 + int ox = out_offset;
61.661 + for (int i = 0; i < in_len; i++) {
61.662 + int x = (int) (in_buff[ix++] * (float)0x7FFFFFFF);
61.663 + out_buff[ox++] = (byte) (x >>> 24);
61.664 + out_buff[ox++] = (byte) (x >>> 16);
61.665 + out_buff[ox++] = (byte) (x >>> 8);
61.666 + out_buff[ox++] = (byte) x;
61.667 + }
61.668 + return out_buff;
61.669 + }
61.670 + }
61.671 +
61.672 + // PCM 32 bit, unsigned, little-endian
61.673 + private static class AudioFloatConversion32UL extends AudioFloatConverter {
61.674 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.675 + float[] out_buff, int out_offset, int out_len) {
61.676 + int ix = in_offset;
61.677 + int ox = out_offset;
61.678 + for (int i = 0; i < out_len; i++) {
61.679 + int x = (in_buff[ix++] & 0xFF) | ((in_buff[ix++] & 0xFF) << 8) |
61.680 + ((in_buff[ix++] & 0xFF) << 16) |
61.681 + ((in_buff[ix++] & 0xFF) << 24);
61.682 + x -= 0x7FFFFFFF;
61.683 + out_buff[ox++] = x * (1.0f / (float)0x7FFFFFFF);
61.684 + }
61.685 + return out_buff;
61.686 + }
61.687 +
61.688 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.689 + byte[] out_buff, int out_offset) {
61.690 + int ix = in_offset;
61.691 + int ox = out_offset;
61.692 + for (int i = 0; i < in_len; i++) {
61.693 + int x = (int) (in_buff[ix++] * (float)0x7FFFFFFF);
61.694 + x += 0x7FFFFFFF;
61.695 + out_buff[ox++] = (byte) x;
61.696 + out_buff[ox++] = (byte) (x >>> 8);
61.697 + out_buff[ox++] = (byte) (x >>> 16);
61.698 + out_buff[ox++] = (byte) (x >>> 24);
61.699 + }
61.700 + return out_buff;
61.701 + }
61.702 + }
61.703 +
61.704 + // PCM 32 bit, unsigned, big-endian
61.705 + private static class AudioFloatConversion32UB extends AudioFloatConverter {
61.706 +
61.707 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.708 + float[] out_buff, int out_offset, int out_len) {
61.709 + int ix = in_offset;
61.710 + int ox = out_offset;
61.711 + for (int i = 0; i < out_len; i++) {
61.712 + int x = ((in_buff[ix++] & 0xFF) << 24) |
61.713 + ((in_buff[ix++] & 0xFF) << 16) |
61.714 + ((in_buff[ix++] & 0xFF) << 8) | (in_buff[ix++] & 0xFF);
61.715 + x -= 0x7FFFFFFF;
61.716 + out_buff[ox++] = x * (1.0f / (float)0x7FFFFFFF);
61.717 + }
61.718 + return out_buff;
61.719 + }
61.720 +
61.721 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.722 + byte[] out_buff, int out_offset) {
61.723 + int ix = in_offset;
61.724 + int ox = out_offset;
61.725 + for (int i = 0; i < in_len; i++) {
61.726 + int x = (int) (in_buff[ix++] * (float)0x7FFFFFFF);
61.727 + x += 0x7FFFFFFF;
61.728 + out_buff[ox++] = (byte) (x >>> 24);
61.729 + out_buff[ox++] = (byte) (x >>> 16);
61.730 + out_buff[ox++] = (byte) (x >>> 8);
61.731 + out_buff[ox++] = (byte) x;
61.732 + }
61.733 + return out_buff;
61.734 + }
61.735 + }
61.736 +
61.737 + /***************************************************************************
61.738 + *
61.739 + * 32+ bit signed/unsigned, little/big-endian
61.740 + *
61.741 + **************************************************************************/
61.742 +
61.743 + // PCM 32+ bit, signed, little-endian
61.744 + private static class AudioFloatConversion32xSL extends AudioFloatConverter {
61.745 +
61.746 + final int xbytes;
61.747 +
61.748 + public AudioFloatConversion32xSL(int xbytes) {
61.749 + this.xbytes = xbytes;
61.750 + }
61.751 +
61.752 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.753 + float[] out_buff, int out_offset, int out_len) {
61.754 + int ix = in_offset;
61.755 + int ox = out_offset;
61.756 + for (int i = 0; i < out_len; i++) {
61.757 + ix += xbytes;
61.758 + int x = (in_buff[ix++] & 0xFF) | ((in_buff[ix++] & 0xFF) << 8)
61.759 + | ((in_buff[ix++] & 0xFF) << 16)
61.760 + | ((in_buff[ix++] & 0xFF) << 24);
61.761 + out_buff[ox++] = x * (1.0f / (float)0x7FFFFFFF);
61.762 + }
61.763 + return out_buff;
61.764 + }
61.765 +
61.766 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.767 + byte[] out_buff, int out_offset) {
61.768 + int ix = in_offset;
61.769 + int ox = out_offset;
61.770 + for (int i = 0; i < in_len; i++) {
61.771 + int x = (int) (in_buff[ix++] * (float)0x7FFFFFFF);
61.772 + for (int j = 0; j < xbytes; j++) {
61.773 + out_buff[ox++] = 0;
61.774 + }
61.775 + out_buff[ox++] = (byte) x;
61.776 + out_buff[ox++] = (byte) (x >>> 8);
61.777 + out_buff[ox++] = (byte) (x >>> 16);
61.778 + out_buff[ox++] = (byte) (x >>> 24);
61.779 + }
61.780 + return out_buff;
61.781 + }
61.782 + }
61.783 +
61.784 + // PCM 32+ bit, signed, big-endian
61.785 + private static class AudioFloatConversion32xSB extends AudioFloatConverter {
61.786 +
61.787 + final int xbytes;
61.788 +
61.789 + public AudioFloatConversion32xSB(int xbytes) {
61.790 + this.xbytes = xbytes;
61.791 + }
61.792 +
61.793 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.794 + float[] out_buff, int out_offset, int out_len) {
61.795 + int ix = in_offset;
61.796 + int ox = out_offset;
61.797 + for (int i = 0; i < out_len; i++) {
61.798 + int x = ((in_buff[ix++] & 0xFF) << 24)
61.799 + | ((in_buff[ix++] & 0xFF) << 16)
61.800 + | ((in_buff[ix++] & 0xFF) << 8)
61.801 + | (in_buff[ix++] & 0xFF);
61.802 + ix += xbytes;
61.803 + out_buff[ox++] = x * (1.0f / (float)0x7FFFFFFF);
61.804 + }
61.805 + return out_buff;
61.806 + }
61.807 +
61.808 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.809 + byte[] out_buff, int out_offset) {
61.810 + int ix = in_offset;
61.811 + int ox = out_offset;
61.812 + for (int i = 0; i < in_len; i++) {
61.813 + int x = (int) (in_buff[ix++] * (float)0x7FFFFFFF);
61.814 + out_buff[ox++] = (byte) (x >>> 24);
61.815 + out_buff[ox++] = (byte) (x >>> 16);
61.816 + out_buff[ox++] = (byte) (x >>> 8);
61.817 + out_buff[ox++] = (byte) x;
61.818 + for (int j = 0; j < xbytes; j++) {
61.819 + out_buff[ox++] = 0;
61.820 + }
61.821 + }
61.822 + return out_buff;
61.823 + }
61.824 + }
61.825 +
61.826 + // PCM 32+ bit, unsigned, little-endian
61.827 + private static class AudioFloatConversion32xUL extends AudioFloatConverter {
61.828 +
61.829 + final int xbytes;
61.830 +
61.831 + public AudioFloatConversion32xUL(int xbytes) {
61.832 + this.xbytes = xbytes;
61.833 + }
61.834 +
61.835 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.836 + float[] out_buff, int out_offset, int out_len) {
61.837 + int ix = in_offset;
61.838 + int ox = out_offset;
61.839 + for (int i = 0; i < out_len; i++) {
61.840 + ix += xbytes;
61.841 + int x = (in_buff[ix++] & 0xFF) | ((in_buff[ix++] & 0xFF) << 8)
61.842 + | ((in_buff[ix++] & 0xFF) << 16)
61.843 + | ((in_buff[ix++] & 0xFF) << 24);
61.844 + x -= 0x7FFFFFFF;
61.845 + out_buff[ox++] = x * (1.0f / (float)0x7FFFFFFF);
61.846 + }
61.847 + return out_buff;
61.848 + }
61.849 +
61.850 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.851 + byte[] out_buff, int out_offset) {
61.852 + int ix = in_offset;
61.853 + int ox = out_offset;
61.854 + for (int i = 0; i < in_len; i++) {
61.855 + int x = (int) (in_buff[ix++] * (float)0x7FFFFFFF);
61.856 + x += 0x7FFFFFFF;
61.857 + for (int j = 0; j < xbytes; j++) {
61.858 + out_buff[ox++] = 0;
61.859 + }
61.860 + out_buff[ox++] = (byte) x;
61.861 + out_buff[ox++] = (byte) (x >>> 8);
61.862 + out_buff[ox++] = (byte) (x >>> 16);
61.863 + out_buff[ox++] = (byte) (x >>> 24);
61.864 + }
61.865 + return out_buff;
61.866 + }
61.867 + }
61.868 +
61.869 + // PCM 32+ bit, unsigned, big-endian
61.870 + private static class AudioFloatConversion32xUB extends AudioFloatConverter {
61.871 +
61.872 + final int xbytes;
61.873 +
61.874 + public AudioFloatConversion32xUB(int xbytes) {
61.875 + this.xbytes = xbytes;
61.876 + }
61.877 +
61.878 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.879 + float[] out_buff, int out_offset, int out_len) {
61.880 + int ix = in_offset;
61.881 + int ox = out_offset;
61.882 + for (int i = 0; i < out_len; i++) {
61.883 + int x = ((in_buff[ix++] & 0xFF) << 24) |
61.884 + ((in_buff[ix++] & 0xFF) << 16) |
61.885 + ((in_buff[ix++] & 0xFF) << 8) | (in_buff[ix++] & 0xFF);
61.886 + ix += xbytes;
61.887 + x -= 2147483647;
61.888 + out_buff[ox++] = x * (1.0f / 2147483647.0f);
61.889 + }
61.890 + return out_buff;
61.891 + }
61.892 +
61.893 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.894 + byte[] out_buff, int out_offset) {
61.895 + int ix = in_offset;
61.896 + int ox = out_offset;
61.897 + for (int i = 0; i < in_len; i++) {
61.898 + int x = (int) (in_buff[ix++] * 2147483647.0);
61.899 + x += 2147483647;
61.900 + out_buff[ox++] = (byte) (x >>> 24);
61.901 + out_buff[ox++] = (byte) (x >>> 16);
61.902 + out_buff[ox++] = (byte) (x >>> 8);
61.903 + out_buff[ox++] = (byte) x;
61.904 + for (int j = 0; j < xbytes; j++) {
61.905 + out_buff[ox++] = 0;
61.906 + }
61.907 + }
61.908 + return out_buff;
61.909 + }
61.910 + }
61.911 +
61.912 + public static AudioFloatConverter getConverter(AudioFormat format) {
61.913 + AudioFloatConverter conv = null;
61.914 + if (format.getFrameSize() == 0)
61.915 + return null;
61.916 + if (format.getFrameSize() !=
61.917 + ((format.getSampleSizeInBits() + 7) / 8) * format.getChannels()) {
61.918 + return null;
61.919 + }
61.920 + if (format.getEncoding().equals(Encoding.PCM_SIGNED)) {
61.921 + if (format.isBigEndian()) {
61.922 + if (format.getSampleSizeInBits() <= 8) {
61.923 + conv = new AudioFloatConversion8S();
61.924 + } else if (format.getSampleSizeInBits() > 8 &&
61.925 + format.getSampleSizeInBits() <= 16) {
61.926 + conv = new AudioFloatConversion16SB();
61.927 + } else if (format.getSampleSizeInBits() > 16 &&
61.928 + format.getSampleSizeInBits() <= 24) {
61.929 + conv = new AudioFloatConversion24SB();
61.930 + } else if (format.getSampleSizeInBits() > 24 &&
61.931 + format.getSampleSizeInBits() <= 32) {
61.932 + conv = new AudioFloatConversion32SB();
61.933 + } else if (format.getSampleSizeInBits() > 32) {
61.934 + conv = new AudioFloatConversion32xSB(((format
61.935 + .getSampleSizeInBits() + 7) / 8) - 4);
61.936 + }
61.937 + } else {
61.938 + if (format.getSampleSizeInBits() <= 8) {
61.939 + conv = new AudioFloatConversion8S();
61.940 + } else if (format.getSampleSizeInBits() > 8 &&
61.941 + format.getSampleSizeInBits() <= 16) {
61.942 + conv = new AudioFloatConversion16SL();
61.943 + } else if (format.getSampleSizeInBits() > 16 &&
61.944 + format.getSampleSizeInBits() <= 24) {
61.945 + conv = new AudioFloatConversion24SL();
61.946 + } else if (format.getSampleSizeInBits() > 24 &&
61.947 + format.getSampleSizeInBits() <= 32) {
61.948 + conv = new AudioFloatConversion32SL();
61.949 + } else if (format.getSampleSizeInBits() > 32) {
61.950 + conv = new AudioFloatConversion32xSL(((format
61.951 + .getSampleSizeInBits() + 7) / 8) - 4);
61.952 + }
61.953 + }
61.954 + } else if (format.getEncoding().equals(Encoding.PCM_UNSIGNED)) {
61.955 + if (format.isBigEndian()) {
61.956 + if (format.getSampleSizeInBits() <= 8) {
61.957 + conv = new AudioFloatConversion8U();
61.958 + } else if (format.getSampleSizeInBits() > 8 &&
61.959 + format.getSampleSizeInBits() <= 16) {
61.960 + conv = new AudioFloatConversion16UB();
61.961 + } else if (format.getSampleSizeInBits() > 16 &&
61.962 + format.getSampleSizeInBits() <= 24) {
61.963 + conv = new AudioFloatConversion24UB();
61.964 + } else if (format.getSampleSizeInBits() > 24 &&
61.965 + format.getSampleSizeInBits() <= 32) {
61.966 + conv = new AudioFloatConversion32UB();
61.967 + } else if (format.getSampleSizeInBits() > 32) {
61.968 + conv = new AudioFloatConversion32xUB(((
61.969 + format.getSampleSizeInBits() + 7) / 8) - 4);
61.970 + }
61.971 + } else {
61.972 + if (format.getSampleSizeInBits() <= 8) {
61.973 + conv = new AudioFloatConversion8U();
61.974 + } else if (format.getSampleSizeInBits() > 8 &&
61.975 + format.getSampleSizeInBits() <= 16) {
61.976 + conv = new AudioFloatConversion16UL();
61.977 + } else if (format.getSampleSizeInBits() > 16 &&
61.978 + format.getSampleSizeInBits() <= 24) {
61.979 + conv = new AudioFloatConversion24UL();
61.980 + } else if (format.getSampleSizeInBits() > 24 &&
61.981 + format.getSampleSizeInBits() <= 32) {
61.982 + conv = new AudioFloatConversion32UL();
61.983 + } else if (format.getSampleSizeInBits() > 32) {
61.984 + conv = new AudioFloatConversion32xUL(((
61.985 + format.getSampleSizeInBits() + 7) / 8) - 4);
61.986 + }
61.987 + }
61.988 + } else if (format.getEncoding().equals(PCM_FLOAT)) {
61.989 + if (format.getSampleSizeInBits() == 32) {
61.990 + if (format.isBigEndian())
61.991 + conv = new AudioFloatConversion32B();
61.992 + else
61.993 + conv = new AudioFloatConversion32L();
61.994 + } else if (format.getSampleSizeInBits() == 64) {
61.995 + if (format.isBigEndian())
61.996 + conv = new AudioFloatConversion64B();
61.997 + else
61.998 + conv = new AudioFloatConversion64L();
61.999 + }
61.1000 +
61.1001 + }
61.1002 +
61.1003 + if ((format.getEncoding().equals(Encoding.PCM_SIGNED) ||
61.1004 + format.getEncoding().equals(Encoding.PCM_UNSIGNED)) &&
61.1005 + (format.getSampleSizeInBits() % 8 != 0)) {
61.1006 + conv = new AudioFloatLSBFilter(conv, format);
61.1007 + }
61.1008 +
61.1009 + if (conv != null)
61.1010 + conv.format = format;
61.1011 + return conv;
61.1012 + }
61.1013 +
61.1014 + private AudioFormat format;
61.1015 +
61.1016 + public AudioFormat getFormat() {
61.1017 + return format;
61.1018 + }
61.1019 +
61.1020 + public abstract float[] toFloatArray(byte[] in_buff, int in_offset,
61.1021 + float[] out_buff, int out_offset, int out_len);
61.1022 +
61.1023 + public float[] toFloatArray(byte[] in_buff, float[] out_buff,
61.1024 + int out_offset, int out_len) {
61.1025 + return toFloatArray(in_buff, 0, out_buff, out_offset, out_len);
61.1026 + }
61.1027 +
61.1028 + public float[] toFloatArray(byte[] in_buff, int in_offset,
61.1029 + float[] out_buff, int out_len) {
61.1030 + return toFloatArray(in_buff, in_offset, out_buff, 0, out_len);
61.1031 + }
61.1032 +
61.1033 + public float[] toFloatArray(byte[] in_buff, float[] out_buff, int out_len) {
61.1034 + return toFloatArray(in_buff, 0, out_buff, 0, out_len);
61.1035 + }
61.1036 +
61.1037 + public float[] toFloatArray(byte[] in_buff, float[] out_buff) {
61.1038 + return toFloatArray(in_buff, 0, out_buff, 0, out_buff.length);
61.1039 + }
61.1040 +
61.1041 + public abstract byte[] toByteArray(float[] in_buff, int in_offset,
61.1042 + int in_len, byte[] out_buff, int out_offset);
61.1043 +
61.1044 + public byte[] toByteArray(float[] in_buff, int in_len, byte[] out_buff,
61.1045 + int out_offset) {
61.1046 + return toByteArray(in_buff, 0, in_len, out_buff, out_offset);
61.1047 + }
61.1048 +
61.1049 + public byte[] toByteArray(float[] in_buff, int in_offset, int in_len,
61.1050 + byte[] out_buff) {
61.1051 + return toByteArray(in_buff, in_offset, in_len, out_buff, 0);
61.1052 + }
61.1053 +
61.1054 + public byte[] toByteArray(float[] in_buff, int in_len, byte[] out_buff) {
61.1055 + return toByteArray(in_buff, 0, in_len, out_buff, 0);
61.1056 + }
61.1057 +
61.1058 + public byte[] toByteArray(float[] in_buff, byte[] out_buff) {
61.1059 + return toByteArray(in_buff, 0, in_buff.length, out_buff, 0);
61.1060 + }
61.1061 +}
62.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
62.2 +++ b/src/share/classes/com/sun/media/sound/AudioFloatFormatConverter.java Tue Feb 03 22:02:55 2009 -0800
62.3 @@ -0,0 +1,617 @@
62.4 +/*
62.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
62.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
62.7 + *
62.8 + * This code is free software; you can redistribute it and/or modify it
62.9 + * under the terms of the GNU General Public License version 2 only, as
62.10 + * published by the Free Software Foundation. Sun designates this
62.11 + * particular file as subject to the "Classpath" exception as provided
62.12 + * by Sun in the LICENSE file that accompanied this code.
62.13 + *
62.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
62.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
62.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
62.17 + * version 2 for more details (a copy is included in the LICENSE file that
62.18 + * accompanied this code).
62.19 + *
62.20 + * You should have received a copy of the GNU General Public License version
62.21 + * 2 along with this work; if not, write to the Free Software Foundation,
62.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
62.23 + *
62.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
62.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
62.26 + * have any questions.
62.27 + */
62.28 +package com.sun.media.sound;
62.29 +
62.30 +import java.io.IOException;
62.31 +import java.io.InputStream;
62.32 +import java.util.ArrayList;
62.33 +import java.util.Arrays;
62.34 +
62.35 +import javax.sound.sampled.AudioFormat;
62.36 +import javax.sound.sampled.AudioInputStream;
62.37 +import javax.sound.sampled.AudioSystem;
62.38 +import javax.sound.sampled.AudioFormat.Encoding;
62.39 +import javax.sound.sampled.spi.FormatConversionProvider;
62.40 +
62.41 +/**
62.42 + * This class is used to convert between 8,16,24,32 bit signed/unsigned
62.43 + * big/litle endian fixed/floating stereo/mono/multi-channel audio streams and
62.44 + * perform sample-rate conversion if needed.
62.45 + *
62.46 + * @author Karl Helgason
62.47 + */
62.48 +public class AudioFloatFormatConverter extends FormatConversionProvider {
62.49 +
62.50 + private static class AudioFloatFormatConverterInputStream extends
62.51 + InputStream {
62.52 + private AudioFloatConverter converter;
62.53 +
62.54 + private AudioFloatInputStream stream;
62.55 +
62.56 + private float[] readfloatbuffer;
62.57 +
62.58 + private int fsize = 0;
62.59 +
62.60 + public AudioFloatFormatConverterInputStream(AudioFormat targetFormat,
62.61 + AudioFloatInputStream stream) {
62.62 + this.stream = stream;
62.63 + converter = AudioFloatConverter.getConverter(targetFormat);
62.64 + fsize = ((targetFormat.getSampleSizeInBits() + 7) / 8);
62.65 + }
62.66 +
62.67 + public int read() throws IOException {
62.68 + byte[] b = new byte[1];
62.69 + int ret = read(b);
62.70 + if (ret < 0)
62.71 + return ret;
62.72 + return b[0] & 0xFF;
62.73 + }
62.74 +
62.75 + public int read(byte[] b, int off, int len) throws IOException {
62.76 +
62.77 + int flen = len / fsize;
62.78 + if (readfloatbuffer == null || readfloatbuffer.length < flen)
62.79 + readfloatbuffer = new float[flen];
62.80 + int ret = stream.read(readfloatbuffer, 0, flen);
62.81 + if (ret < 0)
62.82 + return ret;
62.83 + converter.toByteArray(readfloatbuffer, 0, ret, b, off);
62.84 + return ret * fsize;
62.85 + }
62.86 +
62.87 + public int available() throws IOException {
62.88 + int ret = stream.available();
62.89 + if (ret < 0)
62.90 + return ret;
62.91 + return ret * fsize;
62.92 + }
62.93 +
62.94 + public void close() throws IOException {
62.95 + stream.close();
62.96 + }
62.97 +
62.98 + public synchronized void mark(int readlimit) {
62.99 + stream.mark(readlimit * fsize);
62.100 + }
62.101 +
62.102 + public boolean markSupported() {
62.103 + return stream.markSupported();
62.104 + }
62.105 +
62.106 + public synchronized void reset() throws IOException {
62.107 + stream.reset();
62.108 + }
62.109 +
62.110 + public long skip(long n) throws IOException {
62.111 + long ret = stream.skip(n / fsize);
62.112 + if (ret < 0)
62.113 + return ret;
62.114 + return ret * fsize;
62.115 + }
62.116 +
62.117 + }
62.118 +
62.119 + private static class AudioFloatInputStreamChannelMixer extends
62.120 + AudioFloatInputStream {
62.121 +
62.122 + private int targetChannels;
62.123 +
62.124 + private int sourceChannels;
62.125 +
62.126 + private AudioFloatInputStream ais;
62.127 +
62.128 + private AudioFormat targetFormat;
62.129 +
62.130 + private float[] conversion_buffer;
62.131 +
62.132 + public AudioFloatInputStreamChannelMixer(AudioFloatInputStream ais,
62.133 + int targetChannels) {
62.134 + this.sourceChannels = ais.getFormat().getChannels();
62.135 + this.targetChannels = targetChannels;
62.136 + this.ais = ais;
62.137 + AudioFormat format = ais.getFormat();
62.138 + targetFormat = new AudioFormat(format.getEncoding(), format
62.139 + .getSampleRate(), format.getSampleSizeInBits(),
62.140 + targetChannels, (format.getFrameSize() / sourceChannels)
62.141 + * targetChannels, format.getFrameRate(), format
62.142 + .isBigEndian());
62.143 + }
62.144 +
62.145 + public int available() throws IOException {
62.146 + return (ais.available() / sourceChannels) * targetChannels;
62.147 + }
62.148 +
62.149 + public void close() throws IOException {
62.150 + ais.close();
62.151 + }
62.152 +
62.153 + public AudioFormat getFormat() {
62.154 + return targetFormat;
62.155 + }
62.156 +
62.157 + public long getFrameLength() {
62.158 + return ais.getFrameLength();
62.159 + }
62.160 +
62.161 + public void mark(int readlimit) {
62.162 + ais.mark((readlimit / targetChannels) * sourceChannels);
62.163 + }
62.164 +
62.165 + public boolean markSupported() {
62.166 + return ais.markSupported();
62.167 + }
62.168 +
62.169 + public int read(float[] b, int off, int len) throws IOException {
62.170 + int len2 = (len / targetChannels) * sourceChannels;
62.171 + if (conversion_buffer == null || conversion_buffer.length < len2)
62.172 + conversion_buffer = new float[len2];
62.173 + int ret = ais.read(conversion_buffer, 0, len2);
62.174 + if (ret < 0)
62.175 + return ret;
62.176 + if (sourceChannels == 1) {
62.177 + int cs = targetChannels;
62.178 + for (int c = 0; c < targetChannels; c++) {
62.179 + for (int i = 0, ix = off + c; i < len2; i++, ix += cs) {
62.180 + b[ix] = conversion_buffer[i];
62.181 + ;
62.182 + }
62.183 + }
62.184 + } else if (targetChannels == 1) {
62.185 + int cs = sourceChannels;
62.186 + for (int i = 0, ix = off; i < len2; i += cs, ix++) {
62.187 + b[ix] = conversion_buffer[i];
62.188 + }
62.189 + for (int c = 1; c < sourceChannels; c++) {
62.190 + for (int i = c, ix = off; i < len2; i += cs, ix++) {
62.191 + b[ix] += conversion_buffer[i];
62.192 + ;
62.193 + }
62.194 + }
62.195 + float vol = 1f / ((float) sourceChannels);
62.196 + for (int i = 0, ix = off; i < len2; i += cs, ix++) {
62.197 + b[ix] *= vol;
62.198 + }
62.199 + } else {
62.200 + int minChannels = Math.min(sourceChannels, targetChannels);
62.201 + int off_len = off + len;
62.202 + int ct = targetChannels;
62.203 + int cs = sourceChannels;
62.204 + for (int c = 0; c < minChannels; c++) {
62.205 + for (int i = off + c, ix = c; i < off_len; i += ct, ix += cs) {
62.206 + b[i] = conversion_buffer[ix];
62.207 + }
62.208 + }
62.209 + for (int c = minChannels; c < targetChannels; c++) {
62.210 + for (int i = off + c; i < off_len; i += ct) {
62.211 + b[i] = 0;
62.212 + }
62.213 + }
62.214 + }
62.215 + return (ret / sourceChannels) * targetChannels;
62.216 + }
62.217 +
62.218 + public void reset() throws IOException {
62.219 + ais.reset();
62.220 + }
62.221 +
62.222 + public long skip(long len) throws IOException {
62.223 + long ret = ais.skip((len / targetChannels) * sourceChannels);
62.224 + if (ret < 0)
62.225 + return ret;
62.226 + return (ret / sourceChannels) * targetChannels;
62.227 + }
62.228 +
62.229 + }
62.230 +
62.231 + private static class AudioFloatInputStreamResampler extends
62.232 + AudioFloatInputStream {
62.233 +
62.234 + private AudioFloatInputStream ais;
62.235 +
62.236 + private AudioFormat targetFormat;
62.237 +
62.238 + private float[] skipbuffer;
62.239 +
62.240 + private SoftAbstractResampler resampler;
62.241 +
62.242 + private float[] pitch = new float[1];
62.243 +
62.244 + private float[] ibuffer2;
62.245 +
62.246 + private float[][] ibuffer;
62.247 +
62.248 + private float ibuffer_index = 0;
62.249 +
62.250 + private int ibuffer_len = 0;
62.251 +
62.252 + private int nrofchannels = 0;
62.253 +
62.254 + private float[][] cbuffer;
62.255 +
62.256 + private int buffer_len = 512;
62.257 +
62.258 + private int pad;
62.259 +
62.260 + private int pad2;
62.261 +
62.262 + private float[] ix = new float[1];
62.263 +
62.264 + private int[] ox = new int[1];
62.265 +
62.266 + private float[][] mark_ibuffer = null;
62.267 +
62.268 + private float mark_ibuffer_index = 0;
62.269 +
62.270 + private int mark_ibuffer_len = 0;
62.271 +
62.272 + public AudioFloatInputStreamResampler(AudioFloatInputStream ais,
62.273 + AudioFormat format) {
62.274 + this.ais = ais;
62.275 + AudioFormat sourceFormat = ais.getFormat();
62.276 + targetFormat = new AudioFormat(sourceFormat.getEncoding(), format
62.277 + .getSampleRate(), sourceFormat.getSampleSizeInBits(),
62.278 + sourceFormat.getChannels(), sourceFormat.getFrameSize(),
62.279 + format.getSampleRate(), sourceFormat.isBigEndian());
62.280 + nrofchannels = targetFormat.getChannels();
62.281 + Object interpolation = format.getProperty("interpolation");
62.282 + if (interpolation != null && (interpolation instanceof String)) {
62.283 + String resamplerType = (String) interpolation;
62.284 + if (resamplerType.equalsIgnoreCase("point"))
62.285 + this.resampler = new SoftPointResampler();
62.286 + if (resamplerType.equalsIgnoreCase("linear"))
62.287 + this.resampler = new SoftLinearResampler2();
62.288 + if (resamplerType.equalsIgnoreCase("linear1"))
62.289 + this.resampler = new SoftLinearResampler();
62.290 + if (resamplerType.equalsIgnoreCase("linear2"))
62.291 + this.resampler = new SoftLinearResampler2();
62.292 + if (resamplerType.equalsIgnoreCase("cubic"))
62.293 + this.resampler = new SoftCubicResampler();
62.294 + if (resamplerType.equalsIgnoreCase("lanczos"))
62.295 + this.resampler = new SoftLanczosResampler();
62.296 + if (resamplerType.equalsIgnoreCase("sinc"))
62.297 + this.resampler = new SoftSincResampler();
62.298 + }
62.299 + if (resampler == null)
62.300 + resampler = new SoftLinearResampler2(); // new
62.301 + // SoftLinearResampler2();
62.302 + pitch[0] = sourceFormat.getSampleRate() / format.getSampleRate();
62.303 + pad = resampler.getPadding();
62.304 + pad2 = pad * 2;
62.305 + ibuffer = new float[nrofchannels][buffer_len + pad2];
62.306 + ibuffer2 = new float[nrofchannels * buffer_len];
62.307 + ibuffer_index = buffer_len + pad;
62.308 + ibuffer_len = buffer_len;
62.309 + }
62.310 +
62.311 + public int available() throws IOException {
62.312 + return 0;
62.313 + }
62.314 +
62.315 + public void close() throws IOException {
62.316 + ais.close();
62.317 + }
62.318 +
62.319 + public AudioFormat getFormat() {
62.320 + return targetFormat;
62.321 + }
62.322 +
62.323 + public long getFrameLength() {
62.324 + return AudioSystem.NOT_SPECIFIED; // ais.getFrameLength();
62.325 + }
62.326 +
62.327 + public void mark(int readlimit) {
62.328 + ais.mark((int) (readlimit * pitch[0]));
62.329 + mark_ibuffer_index = ibuffer_index;
62.330 + mark_ibuffer_len = ibuffer_len;
62.331 + if (mark_ibuffer == null) {
62.332 + mark_ibuffer = new float[ibuffer.length][ibuffer[0].length];
62.333 + }
62.334 + for (int c = 0; c < ibuffer.length; c++) {
62.335 + float[] from = ibuffer[c];
62.336 + float[] to = mark_ibuffer[c];
62.337 + for (int i = 0; i < to.length; i++) {
62.338 + to[i] = from[i];
62.339 + }
62.340 + }
62.341 + }
62.342 +
62.343 + public boolean markSupported() {
62.344 + return ais.markSupported();
62.345 + }
62.346 +
62.347 + private void readNextBuffer() throws IOException {
62.348 +
62.349 + if (ibuffer_len == -1)
62.350 + return;
62.351 +
62.352 + for (int c = 0; c < nrofchannels; c++) {
62.353 + float[] buff = ibuffer[c];
62.354 + int buffer_len_pad = ibuffer_len + pad2;
62.355 + for (int i = ibuffer_len, ix = 0; i < buffer_len_pad; i++, ix++) {
62.356 + buff[ix] = buff[i];
62.357 + }
62.358 + }
62.359 +
62.360 + ibuffer_index -= (ibuffer_len);
62.361 +
62.362 + ibuffer_len = ais.read(ibuffer2);
62.363 + if (ibuffer_len >= 0) {
62.364 + while (ibuffer_len < ibuffer2.length) {
62.365 + int ret = ais.read(ibuffer2, ibuffer_len, ibuffer2.length
62.366 + - ibuffer_len);
62.367 + if (ret == -1)
62.368 + break;
62.369 + ibuffer_len += ret;
62.370 + }
62.371 + Arrays.fill(ibuffer2, ibuffer_len, ibuffer2.length, 0);
62.372 + ibuffer_len /= nrofchannels;
62.373 + } else {
62.374 + Arrays.fill(ibuffer2, 0, ibuffer2.length, 0);
62.375 + }
62.376 +
62.377 + int ibuffer2_len = ibuffer2.length;
62.378 + for (int c = 0; c < nrofchannels; c++) {
62.379 + float[] buff = ibuffer[c];
62.380 + for (int i = c, ix = pad2; i < ibuffer2_len; i += nrofchannels, ix++) {
62.381 + buff[ix] = ibuffer2[i];
62.382 + }
62.383 + }
62.384 +
62.385 + }
62.386 +
62.387 + public int read(float[] b, int off, int len) throws IOException {
62.388 +
62.389 + if (cbuffer == null || cbuffer[0].length < len / nrofchannels) {
62.390 + cbuffer = new float[nrofchannels][len / nrofchannels];
62.391 + }
62.392 + if (ibuffer_len == -1)
62.393 + return -1;
62.394 + if (len < 0)
62.395 + return 0;
62.396 + int remain = len / nrofchannels;
62.397 + int destPos = 0;
62.398 + int in_end = ibuffer_len;
62.399 + while (remain > 0) {
62.400 + if (ibuffer_len >= 0) {
62.401 + if (ibuffer_index >= (ibuffer_len + pad))
62.402 + readNextBuffer();
62.403 + in_end = ibuffer_len + pad;
62.404 + }
62.405 +
62.406 + if (ibuffer_len < 0) {
62.407 + in_end = pad2;
62.408 + if (ibuffer_index >= in_end)
62.409 + break;
62.410 + }
62.411 +
62.412 + if (ibuffer_index < 0)
62.413 + break;
62.414 + int preDestPos = destPos;
62.415 + for (int c = 0; c < nrofchannels; c++) {
62.416 + ix[0] = ibuffer_index;
62.417 + ox[0] = destPos;
62.418 + float[] buff = ibuffer[c];
62.419 + resampler.interpolate(buff, ix, in_end, pitch, 0,
62.420 + cbuffer[c], ox, len / nrofchannels);
62.421 + }
62.422 + ibuffer_index = ix[0];
62.423 + destPos = ox[0];
62.424 + remain -= destPos - preDestPos;
62.425 + }
62.426 + for (int c = 0; c < nrofchannels; c++) {
62.427 + int ix = 0;
62.428 + float[] buff = cbuffer[c];
62.429 + for (int i = c; i < b.length; i += nrofchannels) {
62.430 + b[i] = buff[ix++];
62.431 + }
62.432 + }
62.433 + return len - remain * nrofchannels;
62.434 + }
62.435 +
62.436 + public void reset() throws IOException {
62.437 + ais.reset();
62.438 + if (mark_ibuffer == null)
62.439 + return;
62.440 + ibuffer_index = mark_ibuffer_index;
62.441 + ibuffer_len = mark_ibuffer_len;
62.442 + for (int c = 0; c < ibuffer.length; c++) {
62.443 + float[] from = mark_ibuffer[c];
62.444 + float[] to = ibuffer[c];
62.445 + for (int i = 0; i < to.length; i++) {
62.446 + to[i] = from[i];
62.447 + }
62.448 + }
62.449 +
62.450 + }
62.451 +
62.452 + public long skip(long len) throws IOException {
62.453 + if (len > 0)
62.454 + return 0;
62.455 + if (skipbuffer == null)
62.456 + skipbuffer = new float[1024 * targetFormat.getFrameSize()];
62.457 + float[] l_skipbuffer = skipbuffer;
62.458 + long remain = len;
62.459 + while (remain > 0) {
62.460 + int ret = read(l_skipbuffer, 0, (int) Math.min(remain,
62.461 + skipbuffer.length));
62.462 + if (ret < 0) {
62.463 + if (remain == len)
62.464 + return ret;
62.465 + break;
62.466 + }
62.467 + remain -= ret;
62.468 + }
62.469 + return len - remain;
62.470 +
62.471 + }
62.472 +
62.473 + }
62.474 +
62.475 + private Encoding[] formats = { Encoding.PCM_SIGNED, Encoding.PCM_UNSIGNED,
62.476 + AudioFloatConverter.PCM_FLOAT };
62.477 +
62.478 + public AudioInputStream getAudioInputStream(Encoding targetEncoding,
62.479 + AudioInputStream sourceStream) {
62.480 + if (sourceStream.getFormat().getEncoding().equals(targetEncoding))
62.481 + return sourceStream;
62.482 + AudioFormat format = sourceStream.getFormat();
62.483 + int channels = format.getChannels();
62.484 + Encoding encoding = targetEncoding;
62.485 + float samplerate = format.getSampleRate();
62.486 + int bits = format.getSampleSizeInBits();
62.487 + boolean bigendian = format.isBigEndian();
62.488 + if (targetEncoding.equals(AudioFloatConverter.PCM_FLOAT))
62.489 + bits = 32;
62.490 + AudioFormat targetFormat = new AudioFormat(encoding, samplerate, bits,
62.491 + channels, channels * bits / 8, samplerate, bigendian);
62.492 + return getAudioInputStream(targetFormat, sourceStream);
62.493 + }
62.494 +
62.495 + public AudioInputStream getAudioInputStream(AudioFormat targetFormat,
62.496 + AudioInputStream sourceStream) {
62.497 + if (!isConversionSupported(targetFormat, sourceStream.getFormat()))
62.498 + throw new IllegalArgumentException("Unsupported conversion: "
62.499 + + sourceStream.getFormat().toString() + " to "
62.500 + + targetFormat.toString());
62.501 + return getAudioInputStream(targetFormat, AudioFloatInputStream
62.502 + .getInputStream(sourceStream));
62.503 + }
62.504 +
62.505 + public AudioInputStream getAudioInputStream(AudioFormat targetFormat,
62.506 + AudioFloatInputStream sourceStream) {
62.507 +
62.508 + if (!isConversionSupported(targetFormat, sourceStream.getFormat()))
62.509 + throw new IllegalArgumentException("Unsupported conversion: "
62.510 + + sourceStream.getFormat().toString() + " to "
62.511 + + targetFormat.toString());
62.512 + if (targetFormat.getChannels() != sourceStream.getFormat()
62.513 + .getChannels())
62.514 + sourceStream = new AudioFloatInputStreamChannelMixer(sourceStream,
62.515 + targetFormat.getChannels());
62.516 + if (Math.abs(targetFormat.getSampleRate()
62.517 + - sourceStream.getFormat().getSampleRate()) > 0.000001)
62.518 + sourceStream = new AudioFloatInputStreamResampler(sourceStream,
62.519 + targetFormat);
62.520 + return new AudioInputStream(new AudioFloatFormatConverterInputStream(
62.521 + targetFormat, sourceStream), targetFormat, sourceStream
62.522 + .getFrameLength());
62.523 + }
62.524 +
62.525 + public Encoding[] getSourceEncodings() {
62.526 + return new Encoding[] { Encoding.PCM_SIGNED, Encoding.PCM_UNSIGNED,
62.527 + AudioFloatConverter.PCM_FLOAT };
62.528 + }
62.529 +
62.530 + public Encoding[] getTargetEncodings() {
62.531 + return new Encoding[] { Encoding.PCM_SIGNED, Encoding.PCM_UNSIGNED,
62.532 + AudioFloatConverter.PCM_FLOAT };
62.533 + }
62.534 +
62.535 + public Encoding[] getTargetEncodings(AudioFormat sourceFormat) {
62.536 + if (AudioFloatConverter.getConverter(sourceFormat) == null)
62.537 + return new Encoding[0];
62.538 + return new Encoding[] { Encoding.PCM_SIGNED, Encoding.PCM_UNSIGNED,
62.539 + AudioFloatConverter.PCM_FLOAT };
62.540 + }
62.541 +
62.542 + public AudioFormat[] getTargetFormats(Encoding targetEncoding,
62.543 + AudioFormat sourceFormat) {
62.544 + if (AudioFloatConverter.getConverter(sourceFormat) == null)
62.545 + return new AudioFormat[0];
62.546 + int channels = sourceFormat.getChannels();
62.547 +
62.548 + ArrayList<AudioFormat> formats = new ArrayList<AudioFormat>();
62.549 +
62.550 + if (targetEncoding.equals(Encoding.PCM_SIGNED))
62.551 + formats.add(new AudioFormat(Encoding.PCM_SIGNED,
62.552 + AudioSystem.NOT_SPECIFIED, 8, channels, channels,
62.553 + AudioSystem.NOT_SPECIFIED, false));
62.554 + if (targetEncoding.equals(Encoding.PCM_UNSIGNED))
62.555 + formats.add(new AudioFormat(Encoding.PCM_UNSIGNED,
62.556 + AudioSystem.NOT_SPECIFIED, 8, channels, channels,
62.557 + AudioSystem.NOT_SPECIFIED, false));
62.558 +
62.559 + for (int bits = 16; bits < 32; bits += 8) {
62.560 + if (targetEncoding.equals(Encoding.PCM_SIGNED)) {
62.561 + formats.add(new AudioFormat(Encoding.PCM_SIGNED,
62.562 + AudioSystem.NOT_SPECIFIED, bits, channels, channels
62.563 + * bits / 8, AudioSystem.NOT_SPECIFIED, false));
62.564 + formats.add(new AudioFormat(Encoding.PCM_SIGNED,
62.565 + AudioSystem.NOT_SPECIFIED, bits, channels, channels
62.566 + * bits / 8, AudioSystem.NOT_SPECIFIED, true));
62.567 + }
62.568 + if (targetEncoding.equals(Encoding.PCM_UNSIGNED)) {
62.569 + formats.add(new AudioFormat(Encoding.PCM_UNSIGNED,
62.570 + AudioSystem.NOT_SPECIFIED, bits, channels, channels
62.571 + * bits / 8, AudioSystem.NOT_SPECIFIED, true));
62.572 + formats.add(new AudioFormat(Encoding.PCM_UNSIGNED,
62.573 + AudioSystem.NOT_SPECIFIED, bits, channels, channels
62.574 + * bits / 8, AudioSystem.NOT_SPECIFIED, false));
62.575 + }
62.576 + }
62.577 +
62.578 + if (targetEncoding.equals(AudioFloatConverter.PCM_FLOAT)) {
62.579 + formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT,
62.580 + AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4,
62.581 + AudioSystem.NOT_SPECIFIED, false));
62.582 + formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT,
62.583 + AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4,
62.584 + AudioSystem.NOT_SPECIFIED, true));
62.585 + formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT,
62.586 + AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8,
62.587 + AudioSystem.NOT_SPECIFIED, false));
62.588 + formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT,
62.589 + AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8,
62.590 + AudioSystem.NOT_SPECIFIED, true));
62.591 + }
62.592 +
62.593 + return formats.toArray(new AudioFormat[formats.size()]);
62.594 + }
62.595 +
62.596 + public boolean isConversionSupported(AudioFormat targetFormat,
62.597 + AudioFormat sourceFormat) {
62.598 + if (AudioFloatConverter.getConverter(sourceFormat) == null)
62.599 + return false;
62.600 + if (AudioFloatConverter.getConverter(targetFormat) == null)
62.601 + return false;
62.602 + if (sourceFormat.getChannels() <= 0)
62.603 + return false;
62.604 + if (targetFormat.getChannels() <= 0)
62.605 + return false;
62.606 + return true;
62.607 + }
62.608 +
62.609 + public boolean isConversionSupported(Encoding targetEncoding,
62.610 + AudioFormat sourceFormat) {
62.611 + if (AudioFloatConverter.getConverter(sourceFormat) == null)
62.612 + return false;
62.613 + for (int i = 0; i < formats.length; i++) {
62.614 + if (targetEncoding.equals(formats[i]))
62.615 + return true;
62.616 + }
62.617 + return false;
62.618 + }
62.619 +
62.620 +}
63.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
63.2 +++ b/src/share/classes/com/sun/media/sound/AudioFloatInputStream.java Tue Feb 03 22:02:55 2009 -0800
63.3 @@ -0,0 +1,281 @@
63.4 +/*
63.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
63.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
63.7 + *
63.8 + * This code is free software; you can redistribute it and/or modify it
63.9 + * under the terms of the GNU General Public License version 2 only, as
63.10 + * published by the Free Software Foundation. Sun designates this
63.11 + * particular file as subject to the "Classpath" exception as provided
63.12 + * by Sun in the LICENSE file that accompanied this code.
63.13 + *
63.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
63.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
63.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
63.17 + * version 2 for more details (a copy is included in the LICENSE file that
63.18 + * accompanied this code).
63.19 + *
63.20 + * You should have received a copy of the GNU General Public License version
63.21 + * 2 along with this work; if not, write to the Free Software Foundation,
63.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
63.23 + *
63.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
63.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
63.26 + * have any questions.
63.27 + */
63.28 +package com.sun.media.sound;
63.29 +
63.30 +import java.io.ByteArrayInputStream;
63.31 +import java.io.File;
63.32 +import java.io.IOException;
63.33 +import java.io.InputStream;
63.34 +import java.net.URL;
63.35 +
63.36 +import javax.sound.sampled.AudioFormat;
63.37 +import javax.sound.sampled.AudioInputStream;
63.38 +import javax.sound.sampled.AudioSystem;
63.39 +import javax.sound.sampled.UnsupportedAudioFileException;
63.40 +
63.41 +/**
63.42 + * This class is used to create AudioFloatInputStream from AudioInputStream and
63.43 + * byte buffers.
63.44 + *
63.45 + * @author Karl Helgason
63.46 + */
63.47 +public abstract class AudioFloatInputStream {
63.48 +
63.49 + private static class BytaArrayAudioFloatInputStream
63.50 + extends AudioFloatInputStream {
63.51 +
63.52 + private int pos = 0;
63.53 + private int markpos = 0;
63.54 + private AudioFloatConverter converter;
63.55 + private AudioFormat format;
63.56 + private byte[] buffer;
63.57 + private int buffer_offset;
63.58 + private int buffer_len;
63.59 + private int framesize_pc;
63.60 +
63.61 + public BytaArrayAudioFloatInputStream(AudioFloatConverter converter,
63.62 + byte[] buffer, int offset, int len) {
63.63 + this.converter = converter;
63.64 + this.format = converter.getFormat();
63.65 + this.buffer = buffer;
63.66 + this.buffer_offset = offset;
63.67 + framesize_pc = format.getFrameSize() / format.getChannels();
63.68 + this.buffer_len = len / framesize_pc;
63.69 +
63.70 + }
63.71 +
63.72 + public AudioFormat getFormat() {
63.73 + return format;
63.74 + }
63.75 +
63.76 + public long getFrameLength() {
63.77 + return buffer_len;// / format.getFrameSize();
63.78 + }
63.79 +
63.80 + public int read(float[] b, int off, int len) throws IOException {
63.81 + if (b == null)
63.82 + throw new NullPointerException();
63.83 + if (off < 0 || len < 0 || len > b.length - off)
63.84 + throw new IndexOutOfBoundsException();
63.85 + if (pos >= buffer_len)
63.86 + return -1;
63.87 + if (len == 0)
63.88 + return 0;
63.89 + if (pos + len > buffer_len)
63.90 + len = buffer_len - pos;
63.91 + converter.toFloatArray(buffer, buffer_offset + pos * framesize_pc,
63.92 + b, off, len);
63.93 + pos += len;
63.94 + return len;
63.95 + }
63.96 +
63.97 + public long skip(long len) throws IOException {
63.98 + if (pos >= buffer_len)
63.99 + return -1;
63.100 + if (len <= 0)
63.101 + return 0;
63.102 + if (pos + len > buffer_len)
63.103 + len = buffer_len - pos;
63.104 + pos += len;
63.105 + return len;
63.106 + }
63.107 +
63.108 + public int available() throws IOException {
63.109 + return buffer_len - pos;
63.110 + }
63.111 +
63.112 + public void close() throws IOException {
63.113 + }
63.114 +
63.115 + public void mark(int readlimit) {
63.116 + markpos = pos;
63.117 + }
63.118 +
63.119 + public boolean markSupported() {
63.120 + return true;
63.121 + }
63.122 +
63.123 + public void reset() throws IOException {
63.124 + pos = markpos;
63.125 + }
63.126 + }
63.127 +
63.128 + private static class DirectAudioFloatInputStream
63.129 + extends AudioFloatInputStream {
63.130 +
63.131 + private AudioInputStream stream;
63.132 + private AudioFloatConverter converter;
63.133 + private int framesize_pc; // framesize / channels
63.134 + private byte[] buffer;
63.135 +
63.136 + public DirectAudioFloatInputStream(AudioInputStream stream) {
63.137 + converter = AudioFloatConverter.getConverter(stream.getFormat());
63.138 + if (converter == null) {
63.139 + AudioFormat format = stream.getFormat();
63.140 + AudioFormat newformat;
63.141 +
63.142 + AudioFormat[] formats = AudioSystem.getTargetFormats(
63.143 + AudioFormat.Encoding.PCM_SIGNED, format);
63.144 + if (formats.length != 0) {
63.145 + newformat = formats[0];
63.146 + } else {
63.147 + float samplerate = format.getSampleRate();
63.148 + int samplesizeinbits = format.getSampleSizeInBits();
63.149 + int framesize = format.getFrameSize();
63.150 + float framerate = format.getFrameRate();
63.151 + samplesizeinbits = 16;
63.152 + framesize = format.getChannels() * (samplesizeinbits / 8);
63.153 + framerate = samplerate;
63.154 +
63.155 + newformat = new AudioFormat(
63.156 + AudioFormat.Encoding.PCM_SIGNED, samplerate,
63.157 + samplesizeinbits, format.getChannels(), framesize,
63.158 + framerate, false);
63.159 + }
63.160 +
63.161 + stream = AudioSystem.getAudioInputStream(newformat, stream);
63.162 + converter = AudioFloatConverter.getConverter(stream.getFormat());
63.163 + }
63.164 + framesize_pc = stream.getFormat().getFrameSize()
63.165 + / stream.getFormat().getChannels();
63.166 + this.stream = stream;
63.167 + }
63.168 +
63.169 + public AudioFormat getFormat() {
63.170 + return stream.getFormat();
63.171 + }
63.172 +
63.173 + public long getFrameLength() {
63.174 + return stream.getFrameLength();
63.175 + }
63.176 +
63.177 + public int read(float[] b, int off, int len) throws IOException {
63.178 + int b_len = len * framesize_pc;
63.179 + if (buffer == null || buffer.length < b_len)
63.180 + buffer = new byte[b_len];
63.181 + int ret = stream.read(buffer, 0, b_len);
63.182 + if (ret == -1)
63.183 + return -1;
63.184 + converter.toFloatArray(buffer, b, off, ret / framesize_pc);
63.185 + return ret / framesize_pc;
63.186 + }
63.187 +
63.188 + public long skip(long len) throws IOException {
63.189 + long b_len = len * framesize_pc;
63.190 + long ret = stream.skip(b_len);
63.191 + if (ret == -1)
63.192 + return -1;
63.193 + return ret / framesize_pc;
63.194 + }
63.195 +
63.196 + public int available() throws IOException {
63.197 + return stream.available() / framesize_pc;
63.198 + }
63.199 +
63.200 + public void close() throws IOException {
63.201 + stream.close();
63.202 + }
63.203 +
63.204 + public void mark(int readlimit) {
63.205 + stream.mark(readlimit * framesize_pc);
63.206 + }
63.207 +
63.208 + public boolean markSupported() {
63.209 + return stream.markSupported();
63.210 + }
63.211 +
63.212 + public void reset() throws IOException {
63.213 + stream.reset();
63.214 + }
63.215 + }
63.216 +
63.217 + public static AudioFloatInputStream getInputStream(URL url)
63.218 + throws UnsupportedAudioFileException, IOException {
63.219 + return new DirectAudioFloatInputStream(AudioSystem
63.220 + .getAudioInputStream(url));
63.221 + }
63.222 +
63.223 + public static AudioFloatInputStream getInputStream(File file)
63.224 + throws UnsupportedAudioFileException, IOException {
63.225 + return new DirectAudioFloatInputStream(AudioSystem
63.226 + .getAudioInputStream(file));
63.227 + }
63.228 +
63.229 + public static AudioFloatInputStream getInputStream(InputStream stream)
63.230 + throws UnsupportedAudioFileException, IOException {
63.231 + return new DirectAudioFloatInputStream(AudioSystem
63.232 + .getAudioInputStream(stream));
63.233 + }
63.234 +
63.235 + public static AudioFloatInputStream getInputStream(
63.236 + AudioInputStream stream) {
63.237 + return new DirectAudioFloatInputStream(stream);
63.238 + }
63.239 +
63.240 + public static AudioFloatInputStream getInputStream(AudioFormat format,
63.241 + byte[] buffer, int offset, int len) {
63.242 + AudioFloatConverter converter = AudioFloatConverter
63.243 + .getConverter(format);
63.244 + if (converter != null)
63.245 + return new BytaArrayAudioFloatInputStream(converter, buffer,
63.246 + offset, len);
63.247 +
63.248 + InputStream stream = new ByteArrayInputStream(buffer, offset, len);
63.249 + long aLen = format.getFrameSize() == AudioSystem.NOT_SPECIFIED
63.250 + ? AudioSystem.NOT_SPECIFIED : len / format.getFrameSize();
63.251 + AudioInputStream astream = new AudioInputStream(stream, format, aLen);
63.252 + return getInputStream(astream);
63.253 + }
63.254 +
63.255 + public abstract AudioFormat getFormat();
63.256 +
63.257 + public abstract long getFrameLength();
63.258 +
63.259 + public abstract int read(float[] b, int off, int len) throws IOException;
63.260 +
63.261 + public int read(float[] b) throws IOException {
63.262 + return read(b, 0, b.length);
63.263 + }
63.264 +
63.265 + public float read() throws IOException {
63.266 + float[] b = new float[1];
63.267 + int ret = read(b, 0, 1);
63.268 + if (ret == -1 || ret == 0)
63.269 + return 0;
63.270 + return b[0];
63.271 + }
63.272 +
63.273 + public abstract long skip(long len) throws IOException;
63.274 +
63.275 + public abstract int available() throws IOException;
63.276 +
63.277 + public abstract void close() throws IOException;
63.278 +
63.279 + public abstract void mark(int readlimit);
63.280 +
63.281 + public abstract boolean markSupported();
63.282 +
63.283 + public abstract void reset() throws IOException;
63.284 +}
64.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
64.2 +++ b/src/share/classes/com/sun/media/sound/AudioSynthesizer.java Tue Feb 03 22:02:55 2009 -0800
64.3 @@ -0,0 +1,128 @@
64.4 +/*
64.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
64.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
64.7 + *
64.8 + * This code is free software; you can redistribute it and/or modify it
64.9 + * under the terms of the GNU General Public License version 2 only, as
64.10 + * published by the Free Software Foundation. Sun designates this
64.11 + * particular file as subject to the "Classpath" exception as provided
64.12 + * by Sun in the LICENSE file that accompanied this code.
64.13 + *
64.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
64.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
64.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
64.17 + * version 2 for more details (a copy is included in the LICENSE file that
64.18 + * accompanied this code).
64.19 + *
64.20 + * You should have received a copy of the GNU General Public License version
64.21 + * 2 along with this work; if not, write to the Free Software Foundation,
64.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
64.23 + *
64.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
64.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
64.26 + * have any questions.
64.27 + */
64.28 +package com.sun.media.sound;
64.29 +
64.30 +import java.util.Map;
64.31 +import javax.sound.midi.MidiUnavailableException;
64.32 +import javax.sound.midi.Synthesizer;
64.33 +import javax.sound.sampled.AudioFormat;
64.34 +import javax.sound.sampled.AudioInputStream;
64.35 +import javax.sound.sampled.SourceDataLine;
64.36 +
64.37 +/**
64.38 + * <code>AudioSynthesizer</code> is a <code>Synthesizer</code>
64.39 + * which renders it's output audio into <code>SourceDataLine</code>
64.40 + * or <code>AudioInputStream</code>.
64.41 + *
64.42 + * @see MidiSystem#getSynthesizer
64.43 + * @see Synthesizer
64.44 + *
64.45 + * @author Karl Helgason
64.46 + */
64.47 +public interface AudioSynthesizer extends Synthesizer {
64.48 +
64.49 + /**
64.50 + * Obtains the current format (encoding, sample rate, number of channels,
64.51 + * etc.) of the synthesizer audio data.
64.52 + *
64.53 + * <p>If the synthesizer is not open and has never been opened, it returns
64.54 + * the default format.
64.55 + *
64.56 + * @return current audio data format
64.57 + * @see AudioFormat
64.58 + */
64.59 + public AudioFormat getFormat();
64.60 +
64.61 + /**
64.62 + * Gets information about the possible properties for the synthesizer.
64.63 + *
64.64 + * @param info a proposed list of tag/value pairs that will be sent on open.
64.65 + * @return an array of <code>AudioSynthesizerPropertyInfo</code> objects
64.66 + * describing possible properties. This array may be an empty array if
64.67 + * no properties are required.
64.68 + */
64.69 + public AudioSynthesizerPropertyInfo[] getPropertyInfo(
64.70 + Map<String, Object> info);
64.71 +
64.72 + /**
64.73 + * Opens the synthesizer and starts rendering audio into
64.74 + * <code>SourceDataLine</code>.
64.75 + *
64.76 + * <p>An application opening a synthesizer explicitly with this call
64.77 + * has to close the synthesizer by calling {@link #close}. This is
64.78 + * necessary to release system resources and allow applications to
64.79 + * exit cleanly.
64.80 + *
64.81 + * <p>Note that some synthesizers, once closed, cannot be reopened.
64.82 + * Attempts to reopen such a synthesizer will always result in
64.83 + * a <code>MidiUnavailableException</code>.
64.84 + *
64.85 + * @param line which <code>AudioSynthesizer</code> writes output audio into.
64.86 + * If <code>line</code> is null, then line from system default mixer is used.
64.87 + * @param info a <code>Map<String,Object></code> object containing
64.88 + * properties for additional configuration supported by synthesizer.
64.89 + * If <code>info</code> is null then default settings are used.
64.90 + *
64.91 + * @throws MidiUnavailableException thrown if the synthesizer cannot be
64.92 + * opened due to resource restrictions.
64.93 + * @throws SecurityException thrown if the synthesizer cannot be
64.94 + * opened due to security restrictions.
64.95 + *
64.96 + * @see #close
64.97 + * @see #isOpen
64.98 + */
64.99 + public void open(SourceDataLine line, Map<String, Object> info)
64.100 + throws MidiUnavailableException;
64.101 +
64.102 + /**
64.103 + * Opens the synthesizer and renders audio into returned
64.104 + * <code>AudioInputStream</code>.
64.105 + *
64.106 + * <p>An application opening a synthesizer explicitly with this call
64.107 + * has to close the synthesizer by calling {@link #close}. This is
64.108 + * necessary to release system resources and allow applications to
64.109 + * exit cleanly.
64.110 + *
64.111 + * <p>Note that some synthesizers, once closed, cannot be reopened.
64.112 + * Attempts to reopen such a synthesizer will always result in
64.113 + * a <code>MidiUnavailableException<code>.
64.114 + *
64.115 + * @param targetFormat specifies the <code>AudioFormat</code>
64.116 + * used in returned <code>AudioInputStream</code>.
64.117 + * @param info a <code>Map<String,Object></code> object containing
64.118 + * properties for additional configuration supported by synthesizer.
64.119 + * If <code>info</code> is null then default settings are used.
64.120 + *
64.121 + * @throws MidiUnavailableException thrown if the synthesizer cannot be
64.122 + * opened due to resource restrictions.
64.123 + * @throws SecurityException thrown if the synthesizer cannot be
64.124 + * opened due to security restrictions.
64.125 + *
64.126 + * @see #close
64.127 + * @see #isOpen
64.128 + */
64.129 + public AudioInputStream openStream(AudioFormat targetFormat,
64.130 + Map<String, Object> info) throws MidiUnavailableException;
64.131 +}
65.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
65.2 +++ b/src/share/classes/com/sun/media/sound/AudioSynthesizerPropertyInfo.java Tue Feb 03 22:02:55 2009 -0800
65.3 @@ -0,0 +1,76 @@
65.4 +/*
65.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
65.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
65.7 + *
65.8 + * This code is free software; you can redistribute it and/or modify it
65.9 + * under the terms of the GNU General Public License version 2 only, as
65.10 + * published by the Free Software Foundation. Sun designates this
65.11 + * particular file as subject to the "Classpath" exception as provided
65.12 + * by Sun in the LICENSE file that accompanied this code.
65.13 + *
65.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
65.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
65.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
65.17 + * version 2 for more details (a copy is included in the LICENSE file that
65.18 + * accompanied this code).
65.19 + *
65.20 + * You should have received a copy of the GNU General Public License version
65.21 + * 2 along with this work; if not, write to the Free Software Foundation,
65.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
65.23 + *
65.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
65.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
65.26 + * have any questions.
65.27 + */
65.28 +package com.sun.media.sound;
65.29 +
65.30 +/**
65.31 + * Information about property used in opening <code>AudioSynthesizer</code>.
65.32 + *
65.33 + * @author Karl Helgason
65.34 + */
65.35 +public class AudioSynthesizerPropertyInfo {
65.36 +
65.37 + /**
65.38 + * Constructs a <code>AudioSynthesizerPropertyInfo</code> object with a given
65.39 + * name and value. The <code>description</code> and <code>choices</code>
65.40 + * are intialized by <code>null</code> values.
65.41 + *
65.42 + * @param name the name of the property
65.43 + * @param value the current value or class used for values.
65.44 + *
65.45 + */
65.46 + public AudioSynthesizerPropertyInfo(String name, Object value) {
65.47 + this.name = name;
65.48 + this.value = value;
65.49 + if (value instanceof Class)
65.50 + valueClass = (Class)value;
65.51 + else if (value != null)
65.52 + valueClass = value.getClass();
65.53 + }
65.54 + /**
65.55 + * The name of the property.
65.56 + */
65.57 + public String name;
65.58 + /**
65.59 + * A brief description of the property, which may be null.
65.60 + */
65.61 + public String description = null;
65.62 + /**
65.63 + * The <code>value</code> field specifies the current value of
65.64 + * the property.
65.65 + */
65.66 + public Object value = null;
65.67 + /**
65.68 + * The <code>valueClass</code> field specifies class
65.69 + * used in <code>value</code> field.
65.70 + */
65.71 + public Class valueClass = null;
65.72 + /**
65.73 + * An array of possible values if the value for the field
65.74 + * <code>AudioSynthesizerPropertyInfo.value</code> may be selected
65.75 + * from a particular set of values; otherwise null.
65.76 + */
65.77 + public Object[] choices = null;
65.78 +
65.79 +}
66.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
66.2 +++ b/src/share/classes/com/sun/media/sound/DLSInfo.java Tue Feb 03 22:02:55 2009 -0800
66.3 @@ -0,0 +1,109 @@
66.4 +/*
66.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
66.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
66.7 + *
66.8 + * This code is free software; you can redistribute it and/or modify it
66.9 + * under the terms of the GNU General Public License version 2 only, as
66.10 + * published by the Free Software Foundation. Sun designates this
66.11 + * particular file as subject to the "Classpath" exception as provided
66.12 + * by Sun in the LICENSE file that accompanied this code.
66.13 + *
66.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
66.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
66.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
66.17 + * version 2 for more details (a copy is included in the LICENSE file that
66.18 + * accompanied this code).
66.19 + *
66.20 + * You should have received a copy of the GNU General Public License version
66.21 + * 2 along with this work; if not, write to the Free Software Foundation,
66.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
66.23 + *
66.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
66.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
66.26 + * have any questions.
66.27 + */
66.28 +package com.sun.media.sound;
66.29 +
66.30 +/**
66.31 + * This class is used to store information to describe soundbanks, instruments
66.32 + * and samples. It is stored inside a "INFO" List Chunk inside DLS files.
66.33 + *
66.34 + * @author Karl Helgason
66.35 + */
66.36 +public class DLSInfo {
66.37 +
66.38 + /**
66.39 + * (INAM) Title or subject.
66.40 + */
66.41 + public String name = "untitled";
66.42 + /**
66.43 + * (ICRD) Date of creation, the format is: YYYY-MM-DD.
66.44 + * For example 2007-01-01 for 1. january of year 2007.
66.45 + */
66.46 + public String creationDate = null;
66.47 + /**
66.48 + * (IENG) Name of engineer who created the object.
66.49 + */
66.50 + public String engineers = null;
66.51 + /**
66.52 + * (IPRD) Name of the product which the object is intended for.
66.53 + */
66.54 + public String product = null;
66.55 + /**
66.56 + * (ICOP) Copyright information.
66.57 + */
66.58 + public String copyright = null;
66.59 + /**
66.60 + * (ICMT) General comments. Doesn't contain newline characters.
66.61 + */
66.62 + public String comments = null;
66.63 + /**
66.64 + * (ISFT) Name of software package used to create the file.
66.65 + */
66.66 + public String tools = null;
66.67 + /**
66.68 + * (IARL) Where content is archived.
66.69 + */
66.70 + public String archival_location = null;
66.71 + /**
66.72 + * (IART) Artists of original content.
66.73 + */
66.74 + public String artist = null;
66.75 + /**
66.76 + * (ICMS) Names of persons or orginizations who commissioned the file.
66.77 + */
66.78 + public String commissioned = null;
66.79 + /**
66.80 + * (IGNR) Genre of the work.
66.81 + * Example: jazz, classical, rock, etc.
66.82 + */
66.83 + public String genre = null;
66.84 + /**
66.85 + * (IKEY) List of keyword that describe the content.
66.86 + * Examples: FX, bird, piano, etc.
66.87 + */
66.88 + public String keywords = null;
66.89 + /**
66.90 + * (IMED) Describes original medium of the data.
66.91 + * For example: record, CD, etc.
66.92 + */
66.93 + public String medium = null;
66.94 + /**
66.95 + * (ISBJ) Description of the content.
66.96 + */
66.97 + public String subject = null;
66.98 + /**
66.99 + * (ISRC) Name of person or orginization who supplied
66.100 + * orginal material for the file.
66.101 + */
66.102 + public String source = null;
66.103 + /**
66.104 + * (ISRF) Source media for sample data is from.
66.105 + * For example: CD, TV, etc.
66.106 + */
66.107 + public String source_form = null;
66.108 + /**
66.109 + * (ITCH) Technician who sample the file/object.
66.110 + */
66.111 + public String technician = null;
66.112 +}
67.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
67.2 +++ b/src/share/classes/com/sun/media/sound/DLSInstrument.java Tue Feb 03 22:02:55 2009 -0800
67.3 @@ -0,0 +1,448 @@
67.4 +/*
67.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
67.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
67.7 + *
67.8 + * This code is free software; you can redistribute it and/or modify it
67.9 + * under the terms of the GNU General Public License version 2 only, as
67.10 + * published by the Free Software Foundation. Sun designates this
67.11 + * particular file as subject to the "Classpath" exception as provided
67.12 + * by Sun in the LICENSE file that accompanied this code.
67.13 + *
67.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
67.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
67.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
67.17 + * version 2 for more details (a copy is included in the LICENSE file that
67.18 + * accompanied this code).
67.19 + *
67.20 + * You should have received a copy of the GNU General Public License version
67.21 + * 2 along with this work; if not, write to the Free Software Foundation,
67.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
67.23 + *
67.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
67.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
67.26 + * have any questions.
67.27 + */
67.28 +package com.sun.media.sound;
67.29 +
67.30 +import java.util.ArrayList;
67.31 +import java.util.HashMap;
67.32 +import java.util.List;
67.33 +import java.util.Map;
67.34 +
67.35 +import javax.sound.midi.Patch;
67.36 +
67.37 +/**
67.38 + * This class is used to store information to describe instrument.
67.39 + * It contains list of regions and modulators.
67.40 + * It is stored inside a "ins " List Chunk inside DLS files.
67.41 + * In the DLS documentation a modulator is called articulator.
67.42 + *
67.43 + * @author Karl Helgason
67.44 + */
67.45 +public class DLSInstrument extends ModelInstrument {
67.46 +
67.47 + protected int preset = 0;
67.48 + protected int bank = 0;
67.49 + protected boolean druminstrument = false;
67.50 + protected byte[] guid = null;
67.51 + protected DLSInfo info = new DLSInfo();
67.52 + protected List<DLSRegion> regions = new ArrayList<DLSRegion>();
67.53 + protected List<DLSModulator> modulators = new ArrayList<DLSModulator>();
67.54 +
67.55 + public DLSInstrument() {
67.56 + super(null, null, null, null);
67.57 + }
67.58 +
67.59 + public DLSInstrument(DLSSoundbank soundbank) {
67.60 + super(soundbank, null, null, null);
67.61 + }
67.62 +
67.63 + public DLSInfo getInfo() {
67.64 + return info;
67.65 + }
67.66 +
67.67 + public String getName() {
67.68 + return info.name;
67.69 + }
67.70 +
67.71 + public void setName(String name) {
67.72 + info.name = name;
67.73 + }
67.74 +
67.75 + public ModelPatch getPatch() {
67.76 + return new ModelPatch(bank, preset, druminstrument);
67.77 + }
67.78 +
67.79 + public void setPatch(Patch patch) {
67.80 + if (patch instanceof ModelPatch && ((ModelPatch)patch).isPercussion()) {
67.81 + druminstrument = true;
67.82 + bank = patch.getBank();
67.83 + preset = patch.getProgram();
67.84 + } else {
67.85 + druminstrument = false;
67.86 + bank = patch.getBank();
67.87 + preset = patch.getProgram();
67.88 + }
67.89 + }
67.90 +
67.91 + public Object getData() {
67.92 + return null;
67.93 + }
67.94 +
67.95 + public List<DLSRegion> getRegions() {
67.96 + return regions;
67.97 + }
67.98 +
67.99 + public List<DLSModulator> getModulators() {
67.100 + return modulators;
67.101 + }
67.102 +
67.103 + public String toString() {
67.104 + if (druminstrument)
67.105 + return "Drumkit: " + info.name
67.106 + + " bank #" + bank + " preset #" + preset;
67.107 + else
67.108 + return "Instrument: " + info.name
67.109 + + " bank #" + bank + " preset #" + preset;
67.110 + }
67.111 +
67.112 + private ModelIdentifier convertToModelDest(int dest) {
67.113 + if (dest == DLSModulator.CONN_DST_NONE)
67.114 + return null;
67.115 + if (dest == DLSModulator.CONN_DST_GAIN)
67.116 + return ModelDestination.DESTINATION_GAIN;
67.117 + if (dest == DLSModulator.CONN_DST_PITCH)
67.118 + return ModelDestination.DESTINATION_PITCH;
67.119 + if (dest == DLSModulator.CONN_DST_PAN)
67.120 + return ModelDestination.DESTINATION_PAN;
67.121 +
67.122 + if (dest == DLSModulator.CONN_DST_LFO_FREQUENCY)
67.123 + return ModelDestination.DESTINATION_LFO1_FREQ;
67.124 + if (dest == DLSModulator.CONN_DST_LFO_STARTDELAY)
67.125 + return ModelDestination.DESTINATION_LFO1_DELAY;
67.126 +
67.127 + if (dest == DLSModulator.CONN_DST_EG1_ATTACKTIME)
67.128 + return ModelDestination.DESTINATION_EG1_ATTACK;
67.129 + if (dest == DLSModulator.CONN_DST_EG1_DECAYTIME)
67.130 + return ModelDestination.DESTINATION_EG1_DECAY;
67.131 + if (dest == DLSModulator.CONN_DST_EG1_RELEASETIME)
67.132 + return ModelDestination.DESTINATION_EG1_RELEASE;
67.133 + if (dest == DLSModulator.CONN_DST_EG1_SUSTAINLEVEL)
67.134 + return ModelDestination.DESTINATION_EG1_SUSTAIN;
67.135 +
67.136 + if (dest == DLSModulator.CONN_DST_EG2_ATTACKTIME)
67.137 + return ModelDestination.DESTINATION_EG2_ATTACK;
67.138 + if (dest == DLSModulator.CONN_DST_EG2_DECAYTIME)
67.139 + return ModelDestination.DESTINATION_EG2_DECAY;
67.140 + if (dest == DLSModulator.CONN_DST_EG2_RELEASETIME)
67.141 + return ModelDestination.DESTINATION_EG2_RELEASE;
67.142 + if (dest == DLSModulator.CONN_DST_EG2_SUSTAINLEVEL)
67.143 + return ModelDestination.DESTINATION_EG2_SUSTAIN;
67.144 +
67.145 + // DLS2 Destinations
67.146 + if (dest == DLSModulator.CONN_DST_KEYNUMBER)
67.147 + return ModelDestination.DESTINATION_KEYNUMBER;
67.148 +
67.149 + if (dest == DLSModulator.CONN_DST_CHORUS)
67.150 + return ModelDestination.DESTINATION_CHORUS;
67.151 + if (dest == DLSModulator.CONN_DST_REVERB)
67.152 + return ModelDestination.DESTINATION_REVERB;
67.153 +
67.154 + if (dest == DLSModulator.CONN_DST_VIB_FREQUENCY)
67.155 + return ModelDestination.DESTINATION_LFO2_FREQ;
67.156 + if (dest == DLSModulator.CONN_DST_VIB_STARTDELAY)
67.157 + return ModelDestination.DESTINATION_LFO2_DELAY;
67.158 +
67.159 + if (dest == DLSModulator.CONN_DST_EG1_DELAYTIME)
67.160 + return ModelDestination.DESTINATION_EG1_DELAY;
67.161 + if (dest == DLSModulator.CONN_DST_EG1_HOLDTIME)
67.162 + return ModelDestination.DESTINATION_EG1_HOLD;
67.163 + if (dest == DLSModulator.CONN_DST_EG1_SHUTDOWNTIME)
67.164 + return ModelDestination.DESTINATION_EG1_SHUTDOWN;
67.165 +
67.166 + if (dest == DLSModulator.CONN_DST_EG2_DELAYTIME)
67.167 + return ModelDestination.DESTINATION_EG2_DELAY;
67.168 + if (dest == DLSModulator.CONN_DST_EG2_HOLDTIME)
67.169 + return ModelDestination.DESTINATION_EG2_HOLD;
67.170 +
67.171 + if (dest == DLSModulator.CONN_DST_FILTER_CUTOFF)
67.172 + return ModelDestination.DESTINATION_FILTER_FREQ;
67.173 + if (dest == DLSModulator.CONN_DST_FILTER_Q)
67.174 + return ModelDestination.DESTINATION_FILTER_Q;
67.175 +
67.176 + return null;
67.177 + }
67.178 +
67.179 + private ModelIdentifier convertToModelSrc(int src) {
67.180 + if (src == DLSModulator.CONN_SRC_NONE)
67.181 + return null;
67.182 +
67.183 + if (src == DLSModulator.CONN_SRC_LFO)
67.184 + return ModelSource.SOURCE_LFO1;
67.185 + if (src == DLSModulator.CONN_SRC_KEYONVELOCITY)
67.186 + return ModelSource.SOURCE_NOTEON_VELOCITY;
67.187 + if (src == DLSModulator.CONN_SRC_KEYNUMBER)
67.188 + return ModelSource.SOURCE_NOTEON_KEYNUMBER;
67.189 + if (src == DLSModulator.CONN_SRC_EG1)
67.190 + return ModelSource.SOURCE_EG1;
67.191 + if (src == DLSModulator.CONN_SRC_EG2)
67.192 + return ModelSource.SOURCE_EG2;
67.193 + if (src == DLSModulator.CONN_SRC_PITCHWHEEL)
67.194 + return ModelSource.SOURCE_MIDI_PITCH;
67.195 + if (src == DLSModulator.CONN_SRC_CC1)
67.196 + return new ModelIdentifier("midi_cc", "1", 0);
67.197 + if (src == DLSModulator.CONN_SRC_CC7)
67.198 + return new ModelIdentifier("midi_cc", "7", 0);
67.199 + if (src == DLSModulator.CONN_SRC_CC10)
67.200 + return new ModelIdentifier("midi_cc", "10", 0);
67.201 + if (src == DLSModulator.CONN_SRC_CC11)
67.202 + return new ModelIdentifier("midi_cc", "11", 0);
67.203 + if (src == DLSModulator.CONN_SRC_RPN0)
67.204 + return new ModelIdentifier("midi_rpn", "0", 0);
67.205 + if (src == DLSModulator.CONN_SRC_RPN1)
67.206 + return new ModelIdentifier("midi_rpn", "1", 0);
67.207 +
67.208 + if (src == DLSModulator.CONN_SRC_POLYPRESSURE)
67.209 + return ModelSource.SOURCE_MIDI_POLY_PRESSURE;
67.210 + if (src == DLSModulator.CONN_SRC_CHANNELPRESSURE)
67.211 + return ModelSource.SOURCE_MIDI_CHANNEL_PRESSURE;
67.212 + if (src == DLSModulator.CONN_SRC_VIBRATO)
67.213 + return ModelSource.SOURCE_LFO2;
67.214 + if (src == DLSModulator.CONN_SRC_MONOPRESSURE)
67.215 + return ModelSource.SOURCE_MIDI_CHANNEL_PRESSURE;
67.216 +
67.217 + if (src == DLSModulator.CONN_SRC_CC91)
67.218 + return new ModelIdentifier("midi_cc", "91", 0);
67.219 + if (src == DLSModulator.CONN_SRC_CC93)
67.220 + return new ModelIdentifier("midi_cc", "93", 0);
67.221 +
67.222 + return null;
67.223 + }
67.224 +
67.225 + private ModelConnectionBlock convertToModel(DLSModulator mod) {
67.226 + ModelIdentifier source = convertToModelSrc(mod.getSource());
67.227 + ModelIdentifier control = convertToModelSrc(mod.getControl());
67.228 + ModelIdentifier destination_id =
67.229 + convertToModelDest(mod.getDestination());
67.230 +
67.231 + int scale = mod.getScale();
67.232 + double f_scale;
67.233 + if (scale == Integer.MIN_VALUE)
67.234 + f_scale = Double.NEGATIVE_INFINITY;
67.235 + else
67.236 + f_scale = scale / 65536.0;
67.237 +
67.238 + if (destination_id != null) {
67.239 + ModelSource src = null;
67.240 + ModelSource ctrl = null;
67.241 + ModelConnectionBlock block = new ModelConnectionBlock();
67.242 + if (control != null) {
67.243 + ModelSource s = new ModelSource();
67.244 + if (control == ModelSource.SOURCE_MIDI_PITCH) {
67.245 + ((ModelStandardTransform)s.getTransform()).setPolarity(
67.246 + ModelStandardTransform.POLARITY_BIPOLAR);
67.247 + } else if (control == ModelSource.SOURCE_LFO1
67.248 + || control == ModelSource.SOURCE_LFO2) {
67.249 + ((ModelStandardTransform)s.getTransform()).setPolarity(
67.250 + ModelStandardTransform.POLARITY_BIPOLAR);
67.251 + }
67.252 + s.setIdentifier(control);
67.253 + block.addSource(s);
67.254 + ctrl = s;
67.255 + }
67.256 + if (source != null) {
67.257 + ModelSource s = new ModelSource();
67.258 + if (source == ModelSource.SOURCE_MIDI_PITCH) {
67.259 + ((ModelStandardTransform)s.getTransform()).setPolarity(
67.260 + ModelStandardTransform.POLARITY_BIPOLAR);
67.261 + } else if (source == ModelSource.SOURCE_LFO1
67.262 + || source == ModelSource.SOURCE_LFO2) {
67.263 + ((ModelStandardTransform)s.getTransform()).setPolarity(
67.264 + ModelStandardTransform.POLARITY_BIPOLAR);
67.265 + }
67.266 + s.setIdentifier(source);
67.267 + block.addSource(s);
67.268 + src = s;
67.269 + }
67.270 + ModelDestination destination = new ModelDestination();
67.271 + destination.setIdentifier(destination_id);
67.272 + block.setDestination(destination);
67.273 +
67.274 + if (mod.getVersion() == 1) {
67.275 + //if (mod.getTransform() == DLSModulator.CONN_TRN_CONCAVE) {
67.276 + // ((ModelStandardTransform)destination.getTransform())
67.277 + // .setTransform(
67.278 + // ModelStandardTransform.TRANSFORM_CONCAVE);
67.279 + //}
67.280 + if (mod.getTransform() == DLSModulator.CONN_TRN_CONCAVE) {
67.281 + if (src != null) {
67.282 + ((ModelStandardTransform)src.getTransform())
67.283 + .setTransform(
67.284 + ModelStandardTransform.TRANSFORM_CONCAVE);
67.285 + ((ModelStandardTransform)src.getTransform())
67.286 + .setDirection(
67.287 + ModelStandardTransform.DIRECTION_MAX2MIN);
67.288 + }
67.289 + if (ctrl != null) {
67.290 + ((ModelStandardTransform)ctrl.getTransform())
67.291 + .setTransform(
67.292 + ModelStandardTransform.TRANSFORM_CONCAVE);
67.293 + ((ModelStandardTransform)ctrl.getTransform())
67.294 + .setDirection(
67.295 + ModelStandardTransform.DIRECTION_MAX2MIN);
67.296 + }
67.297 + }
67.298 +
67.299 + } else if (mod.getVersion() == 2) {
67.300 + int transform = mod.getTransform();
67.301 + int src_transform_invert = (transform >> 15) & 1;
67.302 + int src_transform_bipolar = (transform >> 14) & 1;
67.303 + int src_transform = (transform >> 10) & 8;
67.304 + int ctr_transform_invert = (transform >> 9) & 1;
67.305 + int ctr_transform_bipolar = (transform >> 8) & 1;
67.306 + int ctr_transform = (transform >> 4) & 8;
67.307 +
67.308 +
67.309 + if (src != null) {
67.310 + int trans = ModelStandardTransform.TRANSFORM_LINEAR;
67.311 + if (src_transform == DLSModulator.CONN_TRN_SWITCH)
67.312 + trans = ModelStandardTransform.TRANSFORM_SWITCH;
67.313 + if (src_transform == DLSModulator.CONN_TRN_CONCAVE)
67.314 + trans = ModelStandardTransform.TRANSFORM_CONCAVE;
67.315 + if (src_transform == DLSModulator.CONN_TRN_CONVEX)
67.316 + trans = ModelStandardTransform.TRANSFORM_CONVEX;
67.317 + ((ModelStandardTransform)src.getTransform())
67.318 + .setTransform(trans);
67.319 + ((ModelStandardTransform)src.getTransform())
67.320 + .setPolarity(src_transform_bipolar == 1);
67.321 + ((ModelStandardTransform)src.getTransform())
67.322 + .setDirection(src_transform_invert == 1);
67.323 +
67.324 + }
67.325 +
67.326 + if (ctrl != null) {
67.327 + int trans = ModelStandardTransform.TRANSFORM_LINEAR;
67.328 + if (ctr_transform == DLSModulator.CONN_TRN_SWITCH)
67.329 + trans = ModelStandardTransform.TRANSFORM_SWITCH;
67.330 + if (ctr_transform == DLSModulator.CONN_TRN_CONCAVE)
67.331 + trans = ModelStandardTransform.TRANSFORM_CONCAVE;
67.332 + if (ctr_transform == DLSModulator.CONN_TRN_CONVEX)
67.333 + trans = ModelStandardTransform.TRANSFORM_CONVEX;
67.334 + ((ModelStandardTransform)ctrl.getTransform())
67.335 + .setTransform(trans);
67.336 + ((ModelStandardTransform)ctrl.getTransform())
67.337 + .setPolarity(ctr_transform_bipolar == 1);
67.338 + ((ModelStandardTransform)ctrl.getTransform())
67.339 + .setDirection(ctr_transform_invert == 1);
67.340 + }
67.341 +
67.342 + /* No output transforms are defined the DLS Level 2
67.343 + int out_transform = transform % 8;
67.344 + int trans = ModelStandardTransform.TRANSFORM_LINEAR;
67.345 + if (out_transform == DLSModulator.CONN_TRN_SWITCH)
67.346 + trans = ModelStandardTransform.TRANSFORM_SWITCH;
67.347 + if (out_transform == DLSModulator.CONN_TRN_CONCAVE)
67.348 + trans = ModelStandardTransform.TRANSFORM_CONCAVE;
67.349 + if (out_transform == DLSModulator.CONN_TRN_CONVEX)
67.350 + trans = ModelStandardTransform.TRANSFORM_CONVEX;
67.351 + if (ctrl != null) {
67.352 + ((ModelStandardTransform)destination.getTransform())
67.353 + .setTransform(trans);
67.354 + }
67.355 + */
67.356 +
67.357 + }
67.358 +
67.359 + block.setScale(f_scale);
67.360 +
67.361 + return block;
67.362 + }
67.363 +
67.364 + return null;
67.365 + }
67.366 +
67.367 + public ModelPerformer[] getPerformers() {
67.368 + List<ModelPerformer> performers = new ArrayList<ModelPerformer>();
67.369 +
67.370 + Map<String, DLSModulator> modmap = new HashMap<String, DLSModulator>();
67.371 + for (DLSModulator mod: getModulators()) {
67.372 + modmap.put(mod.getSource() + "x" + mod.getControl() + "=" +
67.373 + mod.getDestination(), mod);
67.374 + }
67.375 +
67.376 + Map<String, DLSModulator> insmodmap =
67.377 + new HashMap<String, DLSModulator>();
67.378 +
67.379 + for (DLSRegion zone: regions) {
67.380 + ModelPerformer performer = new ModelPerformer();
67.381 + performer.setName(zone.getSample().getName());
67.382 + performer.setSelfNonExclusive((zone.getFusoptions() &
67.383 + DLSRegion.OPTION_SELFNONEXCLUSIVE) != 0);
67.384 + performer.setExclusiveClass(zone.getExclusiveClass());
67.385 + performer.setKeyFrom(zone.getKeyfrom());
67.386 + performer.setKeyTo(zone.getKeyto());
67.387 + performer.setVelFrom(zone.getVelfrom());
67.388 + performer.setVelTo(zone.getVelto());
67.389 +
67.390 + insmodmap.clear();
67.391 + insmodmap.putAll(modmap);
67.392 + for (DLSModulator mod: zone.getModulators()) {
67.393 + insmodmap.put(mod.getSource() + "x" + mod.getControl() + "=" +
67.394 + mod.getDestination(), mod);
67.395 + }
67.396 +
67.397 + List<ModelConnectionBlock> blocks = performer.getConnectionBlocks();
67.398 + for (DLSModulator mod: insmodmap.values()) {
67.399 + ModelConnectionBlock p = convertToModel(mod);
67.400 + if (p != null)
67.401 + blocks.add(p);
67.402 + }
67.403 +
67.404 +
67.405 + DLSSample sample = zone.getSample();
67.406 + DLSSampleOptions sampleopt = zone.getSampleoptions();
67.407 + if (sampleopt == null)
67.408 + sampleopt = sample.getSampleoptions();
67.409 +
67.410 + ModelByteBuffer buff = sample.getDataBuffer();
67.411 +
67.412 + float pitchcorrection = (-sampleopt.unitynote * 100) +
67.413 + sampleopt.finetune;
67.414 +
67.415 + ModelByteBufferWavetable osc = new ModelByteBufferWavetable(buff,
67.416 + sample.getFormat(), pitchcorrection);
67.417 + osc.setAttenuation(osc.getAttenuation() / 65536f);
67.418 + if (sampleopt.getLoops().size() != 0) {
67.419 + DLSSampleLoop loop = sampleopt.getLoops().get(0);
67.420 + osc.setLoopStart((int)loop.getStart());
67.421 + osc.setLoopLength((int)loop.getLength());
67.422 + if (loop.getType() == DLSSampleLoop.LOOP_TYPE_FORWARD)
67.423 + osc.setLoopType(ModelWavetable.LOOP_TYPE_FORWARD);
67.424 + if (loop.getType() == DLSSampleLoop.LOOP_TYPE_RELEASE)
67.425 + osc.setLoopType(ModelWavetable.LOOP_TYPE_RELEASE);
67.426 + else
67.427 + osc.setLoopType(ModelWavetable.LOOP_TYPE_FORWARD);
67.428 + }
67.429 +
67.430 + performer.getConnectionBlocks().add(
67.431 + new ModelConnectionBlock(SoftFilter.FILTERTYPE_LP12,
67.432 + new ModelDestination(
67.433 + new ModelIdentifier("filter", "type", 1))));
67.434 +
67.435 + performer.getOscillators().add(osc);
67.436 +
67.437 + performers.add(performer);
67.438 +
67.439 + }
67.440 +
67.441 + return performers.toArray(new ModelPerformer[performers.size()]);
67.442 + }
67.443 +
67.444 + public byte[] getGuid() {
67.445 + return guid;
67.446 + }
67.447 +
67.448 + public void setGuid(byte[] guid) {
67.449 + this.guid = guid;
67.450 + }
67.451 +}
68.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
68.2 +++ b/src/share/classes/com/sun/media/sound/DLSModulator.java Tue Feb 03 22:02:55 2009 -0800
68.3 @@ -0,0 +1,351 @@
68.4 +/*
68.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
68.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
68.7 + *
68.8 + * This code is free software; you can redistribute it and/or modify it
68.9 + * under the terms of the GNU General Public License version 2 only, as
68.10 + * published by the Free Software Foundation. Sun designates this
68.11 + * particular file as subject to the "Classpath" exception as provided
68.12 + * by Sun in the LICENSE file that accompanied this code.
68.13 + *
68.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
68.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
68.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
68.17 + * version 2 for more details (a copy is included in the LICENSE file that
68.18 + * accompanied this code).
68.19 + *
68.20 + * You should have received a copy of the GNU General Public License version
68.21 + * 2 along with this work; if not, write to the Free Software Foundation,
68.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
68.23 + *
68.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
68.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
68.26 + * have any questions.
68.27 + */
68.28 +package com.sun.media.sound;
68.29 +
68.30 +/**
68.31 + * This class is used to store modulator/artiuclation data.
68.32 + * A modulator connects one synthesizer source to
68.33 + * a destination. For example a note on velocity
68.34 + * can be mapped to the gain of the synthesized voice.
68.35 + * It is stored as a "art1" or "art2" chunk inside DLS files.
68.36 + *
68.37 + * @author Karl Helgason
68.38 + */
68.39 +public class DLSModulator {
68.40 +
68.41 + // DLS1 Destinations
68.42 + public static final int CONN_DST_NONE = 0x000; // 0
68.43 + public static final int CONN_DST_GAIN = 0x001; // cB
68.44 + public static final int CONN_DST_PITCH = 0x003; // cent
68.45 + public static final int CONN_DST_PAN = 0x004; // 0.1%
68.46 + public static final int CONN_DST_LFO_FREQUENCY = 0x104; // cent (default 5 Hz)
68.47 + public static final int CONN_DST_LFO_STARTDELAY = 0x105; // timecent
68.48 + public static final int CONN_DST_EG1_ATTACKTIME = 0x206; // timecent
68.49 + public static final int CONN_DST_EG1_DECAYTIME = 0x207; // timecent
68.50 + public static final int CONN_DST_EG1_RELEASETIME = 0x209; // timecent
68.51 + public static final int CONN_DST_EG1_SUSTAINLEVEL = 0x20A; // 0.1%
68.52 + public static final int CONN_DST_EG2_ATTACKTIME = 0x30A; // timecent
68.53 + public static final int CONN_DST_EG2_DECAYTIME = 0x30B; // timecent
68.54 + public static final int CONN_DST_EG2_RELEASETIME = 0x30D; // timecent
68.55 + public static final int CONN_DST_EG2_SUSTAINLEVEL = 0x30E; // 0.1%
68.56 + // DLS2 Destinations
68.57 + public static final int CONN_DST_KEYNUMBER = 0x005;
68.58 + public static final int CONN_DST_LEFT = 0x010; // 0.1%
68.59 + public static final int CONN_DST_RIGHT = 0x011; // 0.1%
68.60 + public static final int CONN_DST_CENTER = 0x012; // 0.1%
68.61 + public static final int CONN_DST_LEFTREAR = 0x013; // 0.1%
68.62 + public static final int CONN_DST_RIGHTREAR = 0x014; // 0.1%
68.63 + public static final int CONN_DST_LFE_CHANNEL = 0x015; // 0.1%
68.64 + public static final int CONN_DST_CHORUS = 0x080; // 0.1%
68.65 + public static final int CONN_DST_REVERB = 0x081; // 0.1%
68.66 + public static final int CONN_DST_VIB_FREQUENCY = 0x114; // cent
68.67 + public static final int CONN_DST_VIB_STARTDELAY = 0x115; // dB
68.68 + public static final int CONN_DST_EG1_DELAYTIME = 0x20B; // timecent
68.69 + public static final int CONN_DST_EG1_HOLDTIME = 0x20C; // timecent
68.70 + public static final int CONN_DST_EG1_SHUTDOWNTIME = 0x20D; // timecent
68.71 + public static final int CONN_DST_EG2_DELAYTIME = 0x30F; // timecent
68.72 + public static final int CONN_DST_EG2_HOLDTIME = 0x310; // timecent
68.73 + public static final int CONN_DST_FILTER_CUTOFF = 0x500; // cent
68.74 + public static final int CONN_DST_FILTER_Q = 0x501; // dB
68.75 +
68.76 + // DLS1 Sources
68.77 + public static final int CONN_SRC_NONE = 0x000; // 1
68.78 + public static final int CONN_SRC_LFO = 0x001; // linear (sine wave)
68.79 + public static final int CONN_SRC_KEYONVELOCITY = 0x002; // ??db or velocity??
68.80 + public static final int CONN_SRC_KEYNUMBER = 0x003; // ??cent or keynumber??
68.81 + public static final int CONN_SRC_EG1 = 0x004; // linear direct from eg
68.82 + public static final int CONN_SRC_EG2 = 0x005; // linear direct from eg
68.83 + public static final int CONN_SRC_PITCHWHEEL = 0x006; // linear -1..1
68.84 + public static final int CONN_SRC_CC1 = 0x081; // linear 0..1
68.85 + public static final int CONN_SRC_CC7 = 0x087; // linear 0..1
68.86 + public static final int CONN_SRC_CC10 = 0x08A; // linear 0..1
68.87 + public static final int CONN_SRC_CC11 = 0x08B; // linear 0..1
68.88 + public static final int CONN_SRC_RPN0 = 0x100; // ?? // Pitch Bend Range
68.89 + public static final int CONN_SRC_RPN1 = 0x101; // ?? // Fine Tune
68.90 + public static final int CONN_SRC_RPN2 = 0x102; // ?? // Course Tune
68.91 + // DLS2 Sources
68.92 + public static final int CONN_SRC_POLYPRESSURE = 0x007; // linear 0..1
68.93 + public static final int CONN_SRC_CHANNELPRESSURE = 0x008; // linear 0..1
68.94 + public static final int CONN_SRC_VIBRATO = 0x009; // linear 0..1
68.95 + public static final int CONN_SRC_MONOPRESSURE = 0x00A; // linear 0..1
68.96 + public static final int CONN_SRC_CC91 = 0x0DB; // linear 0..1
68.97 + public static final int CONN_SRC_CC93 = 0x0DD; // linear 0..1
68.98 + // DLS1 Transforms
68.99 + public static final int CONN_TRN_NONE = 0x000;
68.100 + public static final int CONN_TRN_CONCAVE = 0x001;
68.101 + // DLS2 Transforms
68.102 + public static final int CONN_TRN_CONVEX = 0x002;
68.103 + public static final int CONN_TRN_SWITCH = 0x003;
68.104 + public static final int DST_FORMAT_CB = 1;
68.105 + public static final int DST_FORMAT_CENT = 1;
68.106 + public static final int DST_FORMAT_TIMECENT = 2;
68.107 + public static final int DST_FORMAT_PERCENT = 3;
68.108 + protected int source;
68.109 + protected int control;
68.110 + protected int destination;
68.111 + protected int transform;
68.112 + protected int scale;
68.113 + protected int version = 1;
68.114 +
68.115 + public int getControl() {
68.116 + return control;
68.117 + }
68.118 +
68.119 + public void setControl(int control) {
68.120 + this.control = control;
68.121 + }
68.122 +
68.123 + public static int getDestinationFormat(int destination) {
68.124 +
68.125 + if (destination == CONN_DST_GAIN)
68.126 + return DST_FORMAT_CB;
68.127 + if (destination == CONN_DST_PITCH)
68.128 + return DST_FORMAT_CENT;
68.129 + if (destination == CONN_DST_PAN)
68.130 + return DST_FORMAT_PERCENT;
68.131 +
68.132 + if (destination == CONN_DST_LFO_FREQUENCY)
68.133 + return DST_FORMAT_CENT;
68.134 + if (destination == CONN_DST_LFO_STARTDELAY)
68.135 + return DST_FORMAT_TIMECENT;
68.136 +
68.137 + if (destination == CONN_DST_EG1_ATTACKTIME)
68.138 + return DST_FORMAT_TIMECENT;
68.139 + if (destination == CONN_DST_EG1_DECAYTIME)
68.140 + return DST_FORMAT_TIMECENT;
68.141 + if (destination == CONN_DST_EG1_RELEASETIME)
68.142 + return DST_FORMAT_TIMECENT;
68.143 + if (destination == CONN_DST_EG1_SUSTAINLEVEL)
68.144 + return DST_FORMAT_PERCENT;
68.145 +
68.146 + if (destination == CONN_DST_EG2_ATTACKTIME)
68.147 + return DST_FORMAT_TIMECENT;
68.148 + if (destination == CONN_DST_EG2_DECAYTIME)
68.149 + return DST_FORMAT_TIMECENT;
68.150 + if (destination == CONN_DST_EG2_RELEASETIME)
68.151 + return DST_FORMAT_TIMECENT;
68.152 + if (destination == CONN_DST_EG2_SUSTAINLEVEL)
68.153 + return DST_FORMAT_PERCENT;
68.154 +
68.155 + if (destination == CONN_DST_KEYNUMBER)
68.156 + return DST_FORMAT_CENT; // NOT SURE WITHOUT DLS 2 SPEC
68.157 + if (destination == CONN_DST_LEFT)
68.158 + return DST_FORMAT_CB;
68.159 + if (destination == CONN_DST_RIGHT)
68.160 + return DST_FORMAT_CB;
68.161 + if (destination == CONN_DST_CENTER)
68.162 + return DST_FORMAT_CB;
68.163 + if (destination == CONN_DST_LEFTREAR)
68.164 + return DST_FORMAT_CB;
68.165 + if (destination == CONN_DST_RIGHTREAR)
68.166 + return DST_FORMAT_CB;
68.167 + if (destination == CONN_DST_LFE_CHANNEL)
68.168 + return DST_FORMAT_CB;
68.169 + if (destination == CONN_DST_CHORUS)
68.170 + return DST_FORMAT_PERCENT;
68.171 + if (destination == CONN_DST_REVERB)
68.172 + return DST_FORMAT_PERCENT;
68.173 +
68.174 + if (destination == CONN_DST_VIB_FREQUENCY)
68.175 + return DST_FORMAT_CENT;
68.176 + if (destination == CONN_DST_VIB_STARTDELAY)
68.177 + return DST_FORMAT_TIMECENT;
68.178 +
68.179 + if (destination == CONN_DST_EG1_DELAYTIME)
68.180 + return DST_FORMAT_TIMECENT;
68.181 + if (destination == CONN_DST_EG1_HOLDTIME)
68.182 + return DST_FORMAT_TIMECENT;
68.183 + if (destination == CONN_DST_EG1_SHUTDOWNTIME)
68.184 + return DST_FORMAT_TIMECENT;
68.185 +
68.186 + if (destination == CONN_DST_EG2_DELAYTIME)
68.187 + return DST_FORMAT_TIMECENT;
68.188 + if (destination == CONN_DST_EG2_HOLDTIME)
68.189 + return DST_FORMAT_TIMECENT;
68.190 +
68.191 + if (destination == CONN_DST_FILTER_CUTOFF)
68.192 + return DST_FORMAT_CENT;
68.193 + if (destination == CONN_DST_FILTER_Q)
68.194 + return DST_FORMAT_CB;
68.195 +
68.196 + return -1;
68.197 + }
68.198 +
68.199 + public static String getDestinationName(int destination) {
68.200 +
68.201 + if (destination == CONN_DST_GAIN)
68.202 + return "gain";
68.203 + if (destination == CONN_DST_PITCH)
68.204 + return "pitch";
68.205 + if (destination == CONN_DST_PAN)
68.206 + return "pan";
68.207 +
68.208 + if (destination == CONN_DST_LFO_FREQUENCY)
68.209 + return "lfo1.freq";
68.210 + if (destination == CONN_DST_LFO_STARTDELAY)
68.211 + return "lfo1.delay";
68.212 +
68.213 + if (destination == CONN_DST_EG1_ATTACKTIME)
68.214 + return "eg1.attack";
68.215 + if (destination == CONN_DST_EG1_DECAYTIME)
68.216 + return "eg1.decay";
68.217 + if (destination == CONN_DST_EG1_RELEASETIME)
68.218 + return "eg1.release";
68.219 + if (destination == CONN_DST_EG1_SUSTAINLEVEL)
68.220 + return "eg1.sustain";
68.221 +
68.222 + if (destination == CONN_DST_EG2_ATTACKTIME)
68.223 + return "eg2.attack";
68.224 + if (destination == CONN_DST_EG2_DECAYTIME)
68.225 + return "eg2.decay";
68.226 + if (destination == CONN_DST_EG2_RELEASETIME)
68.227 + return "eg2.release";
68.228 + if (destination == CONN_DST_EG2_SUSTAINLEVEL)
68.229 + return "eg2.sustain";
68.230 +
68.231 + if (destination == CONN_DST_KEYNUMBER)
68.232 + return "keynumber";
68.233 + if (destination == CONN_DST_LEFT)
68.234 + return "left";
68.235 + if (destination == CONN_DST_RIGHT)
68.236 + return "right";
68.237 + if (destination == CONN_DST_CENTER)
68.238 + return "center";
68.239 + if (destination == CONN_DST_LEFTREAR)
68.240 + return "leftrear";
68.241 + if (destination == CONN_DST_RIGHTREAR)
68.242 + return "rightrear";
68.243 + if (destination == CONN_DST_LFE_CHANNEL)
68.244 + return "lfe_channel";
68.245 + if (destination == CONN_DST_CHORUS)
68.246 + return "chorus";
68.247 + if (destination == CONN_DST_REVERB)
68.248 + return "reverb";
68.249 +
68.250 + if (destination == CONN_DST_VIB_FREQUENCY)
68.251 + return "vib.freq";
68.252 + if (destination == CONN_DST_VIB_STARTDELAY)
68.253 + return "vib.delay";
68.254 +
68.255 + if (destination == CONN_DST_EG1_DELAYTIME)
68.256 + return "eg1.delay";
68.257 + if (destination == CONN_DST_EG1_HOLDTIME)
68.258 + return "eg1.hold";
68.259 + if (destination == CONN_DST_EG1_SHUTDOWNTIME)
68.260 + return "eg1.shutdown";
68.261 +
68.262 + if (destination == CONN_DST_EG2_DELAYTIME)
68.263 + return "eg2.delay";
68.264 + if (destination == CONN_DST_EG2_HOLDTIME)
68.265 + return "eg.2hold";
68.266 +
68.267 + if (destination == CONN_DST_FILTER_CUTOFF)
68.268 + return "filter.cutoff"; // NOT SURE WITHOUT DLS 2 SPEC
68.269 + if (destination == CONN_DST_FILTER_Q)
68.270 + return "filter.q"; // NOT SURE WITHOUT DLS 2 SPEC
68.271 +
68.272 + return null;
68.273 + }
68.274 +
68.275 + public static String getSourceName(int source) {
68.276 +
68.277 + if (source == CONN_SRC_NONE)
68.278 + return "none";
68.279 + if (source == CONN_SRC_LFO)
68.280 + return "lfo";
68.281 + if (source == CONN_SRC_KEYONVELOCITY)
68.282 + return "keyonvelocity";
68.283 + if (source == CONN_SRC_KEYNUMBER)
68.284 + return "keynumber";
68.285 + if (source == CONN_SRC_EG1)
68.286 + return "eg1";
68.287 + if (source == CONN_SRC_EG2)
68.288 + return "eg2";
68.289 + if (source == CONN_SRC_PITCHWHEEL)
68.290 + return "pitchweel";
68.291 + if (source == CONN_SRC_CC1)
68.292 + return "cc1";
68.293 + if (source == CONN_SRC_CC7)
68.294 + return "cc7";
68.295 + if (source == CONN_SRC_CC10)
68.296 + return "c10";
68.297 + if (source == CONN_SRC_CC11)
68.298 + return "cc11";
68.299 +
68.300 + if (source == CONN_SRC_POLYPRESSURE)
68.301 + return "polypressure";
68.302 + if (source == CONN_SRC_CHANNELPRESSURE)
68.303 + return "channelpressure";
68.304 + if (source == CONN_SRC_VIBRATO)
68.305 + return "vibrato";
68.306 + if (source == CONN_SRC_MONOPRESSURE)
68.307 + return "monopressure";
68.308 + if (source == CONN_SRC_CC91)
68.309 + return "cc91";
68.310 + if (source == CONN_SRC_CC93)
68.311 + return "cc93";
68.312 + return null;
68.313 + }
68.314 +
68.315 + public int getDestination() {
68.316 + return destination;
68.317 + }
68.318 +
68.319 + public void setDestination(int destination) {
68.320 + this.destination = destination;
68.321 + }
68.322 +
68.323 + public int getScale() {
68.324 + return scale;
68.325 + }
68.326 +
68.327 + public void setScale(int scale) {
68.328 + this.scale = scale;
68.329 + }
68.330 +
68.331 + public int getSource() {
68.332 + return source;
68.333 + }
68.334 +
68.335 + public void setSource(int source) {
68.336 + this.source = source;
68.337 + }
68.338 +
68.339 + public int getVersion() {
68.340 + return version;
68.341 + }
68.342 +
68.343 + public void setVersion(int version) {
68.344 + this.version = version;
68.345 + }
68.346 +
68.347 + public int getTransform() {
68.348 + return transform;
68.349 + }
68.350 +
68.351 + public void setTransform(int transform) {
68.352 + this.transform = transform;
68.353 + }
68.354 +}
69.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
69.2 +++ b/src/share/classes/com/sun/media/sound/DLSRegion.java Tue Feb 03 22:02:55 2009 -0800
69.3 @@ -0,0 +1,150 @@
69.4 +/*
69.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
69.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
69.7 + *
69.8 + * This code is free software; you can redistribute it and/or modify it
69.9 + * under the terms of the GNU General Public License version 2 only, as
69.10 + * published by the Free Software Foundation. Sun designates this
69.11 + * particular file as subject to the "Classpath" exception as provided
69.12 + * by Sun in the LICENSE file that accompanied this code.
69.13 + *
69.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
69.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
69.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
69.17 + * version 2 for more details (a copy is included in the LICENSE file that
69.18 + * accompanied this code).
69.19 + *
69.20 + * You should have received a copy of the GNU General Public License version
69.21 + * 2 along with this work; if not, write to the Free Software Foundation,
69.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
69.23 + *
69.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
69.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
69.26 + * have any questions.
69.27 + */
69.28 +package com.sun.media.sound;
69.29 +
69.30 +import java.util.ArrayList;
69.31 +import java.util.List;
69.32 +
69.33 +/**
69.34 + * This class is used to store region parts for instrument.
69.35 + * A region has a velocity and key range which it response to.
69.36 + * And it has a list of modulators/articulators which
69.37 + * is used how to synthesize a single voice.
69.38 + * It is stored inside a "rgn " List Chunk inside DLS files.
69.39 + *
69.40 + * @author Karl Helgason
69.41 + */
69.42 +public class DLSRegion {
69.43 +
69.44 + public final static int OPTION_SELFNONEXCLUSIVE = 0x0001;
69.45 + protected List<DLSModulator> modulators = new ArrayList<DLSModulator>();
69.46 + protected int keyfrom;
69.47 + protected int keyto;
69.48 + protected int velfrom;
69.49 + protected int velto;
69.50 + protected int options;
69.51 + protected int exclusiveClass;
69.52 + protected int fusoptions;
69.53 + protected int phasegroup;
69.54 + protected long channel;
69.55 + protected DLSSample sample = null;
69.56 + protected DLSSampleOptions sampleoptions;
69.57 +
69.58 + public List<DLSModulator> getModulators() {
69.59 + return modulators;
69.60 + }
69.61 +
69.62 + public long getChannel() {
69.63 + return channel;
69.64 + }
69.65 +
69.66 + public void setChannel(long channel) {
69.67 + this.channel = channel;
69.68 + }
69.69 +
69.70 + public int getExclusiveClass() {
69.71 + return exclusiveClass;
69.72 + }
69.73 +
69.74 + public void setExclusiveClass(int exclusiveClass) {
69.75 + this.exclusiveClass = exclusiveClass;
69.76 + }
69.77 +
69.78 + public int getFusoptions() {
69.79 + return fusoptions;
69.80 + }
69.81 +
69.82 + public void setFusoptions(int fusoptions) {
69.83 + this.fusoptions = fusoptions;
69.84 + }
69.85 +
69.86 + public int getKeyfrom() {
69.87 + return keyfrom;
69.88 + }
69.89 +
69.90 + public void setKeyfrom(int keyfrom) {
69.91 + this.keyfrom = keyfrom;
69.92 + }
69.93 +
69.94 + public int getKeyto() {
69.95 + return keyto;
69.96 + }
69.97 +
69.98 + public void setKeyto(int keyto) {
69.99 + this.keyto = keyto;
69.100 + }
69.101 +
69.102 + public int getOptions() {
69.103 + return options;
69.104 + }
69.105 +
69.106 + public void setOptions(int options) {
69.107 + this.options = options;
69.108 + }
69.109 +
69.110 + public int getPhasegroup() {
69.111 + return phasegroup;
69.112 + }
69.113 +
69.114 + public void setPhasegroup(int phasegroup) {
69.115 + this.phasegroup = phasegroup;
69.116 + }
69.117 +
69.118 + public DLSSample getSample() {
69.119 + return sample;
69.120 + }
69.121 +
69.122 + public void setSample(DLSSample sample) {
69.123 + this.sample = sample;
69.124 + }
69.125 +
69.126 + public int getVelfrom() {
69.127 + return velfrom;
69.128 + }
69.129 +
69.130 + public void setVelfrom(int velfrom) {
69.131 + this.velfrom = velfrom;
69.132 + }
69.133 +
69.134 + public int getVelto() {
69.135 + return velto;
69.136 + }
69.137 +
69.138 + public void setVelto(int velto) {
69.139 + this.velto = velto;
69.140 + }
69.141 +
69.142 + public void setModulators(List<DLSModulator> modulators) {
69.143 + this.modulators = modulators;
69.144 + }
69.145 +
69.146 + public DLSSampleOptions getSampleoptions() {
69.147 + return sampleoptions;
69.148 + }
69.149 +
69.150 + public void setSampleoptions(DLSSampleOptions sampleOptions) {
69.151 + this.sampleoptions = sampleOptions;
69.152 + }
69.153 +}
70.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
70.2 +++ b/src/share/classes/com/sun/media/sound/DLSSample.java Tue Feb 03 22:02:55 2009 -0800
70.3 @@ -0,0 +1,122 @@
70.4 +/*
70.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
70.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
70.7 + *
70.8 + * This code is free software; you can redistribute it and/or modify it
70.9 + * under the terms of the GNU General Public License version 2 only, as
70.10 + * published by the Free Software Foundation. Sun designates this
70.11 + * particular file as subject to the "Classpath" exception as provided
70.12 + * by Sun in the LICENSE file that accompanied this code.
70.13 + *
70.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
70.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
70.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
70.17 + * version 2 for more details (a copy is included in the LICENSE file that
70.18 + * accompanied this code).
70.19 + *
70.20 + * You should have received a copy of the GNU General Public License version
70.21 + * 2 along with this work; if not, write to the Free Software Foundation,
70.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
70.23 + *
70.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
70.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
70.26 + * have any questions.
70.27 + */
70.28 +package com.sun.media.sound;
70.29 +
70.30 +import java.io.InputStream;
70.31 +import javax.sound.midi.Soundbank;
70.32 +import javax.sound.midi.SoundbankResource;
70.33 +import javax.sound.sampled.AudioFormat;
70.34 +import javax.sound.sampled.AudioInputStream;
70.35 +
70.36 +/**
70.37 + * This class is used to store the sample data itself.
70.38 + * A sample is encoded as PCM audio stream
70.39 + * and in DLS Level 1 files it is always a mono 8/16 bit stream.
70.40 + * They are stored just like RIFF WAVE files are stored.
70.41 + * It is stored inside a "wave" List Chunk inside DLS files.
70.42 + *
70.43 + * @author Karl Helgason
70.44 + */
70.45 +public class DLSSample extends SoundbankResource {
70.46 +
70.47 + protected byte[] guid = null;
70.48 + protected DLSInfo info = new DLSInfo();
70.49 + protected DLSSampleOptions sampleoptions;
70.50 + protected ModelByteBuffer data;
70.51 + protected AudioFormat format;
70.52 +
70.53 + public DLSSample(Soundbank soundBank) {
70.54 + super(soundBank, null, AudioInputStream.class);
70.55 + }
70.56 +
70.57 + public DLSSample() {
70.58 + super(null, null, AudioInputStream.class);
70.59 + }
70.60 +
70.61 + public DLSInfo getInfo() {
70.62 + return info;
70.63 + }
70.64 +
70.65 + public Object getData() {
70.66 + AudioFormat format = getFormat();
70.67 +
70.68 + InputStream is = data.getInputStream();
70.69 + if (is == null)
70.70 + return null;
70.71 + return new AudioInputStream(is, format, data.capacity());
70.72 + }
70.73 +
70.74 + public ModelByteBuffer getDataBuffer() {
70.75 + return data;
70.76 + }
70.77 +
70.78 + public AudioFormat getFormat() {
70.79 + return format;
70.80 + }
70.81 +
70.82 + public void setFormat(AudioFormat format) {
70.83 + this.format = format;
70.84 + }
70.85 +
70.86 + public void setData(ModelByteBuffer data) {
70.87 + this.data = data;
70.88 + }
70.89 +
70.90 + public void setData(byte[] data) {
70.91 + this.data = new ModelByteBuffer(data);
70.92 + }
70.93 +
70.94 + public void setData(byte[] data, int offset, int length) {
70.95 + this.data = new ModelByteBuffer(data, offset, length);
70.96 + }
70.97 +
70.98 + public String getName() {
70.99 + return info.name;
70.100 + }
70.101 +
70.102 + public void setName(String name) {
70.103 + info.name = name;
70.104 + }
70.105 +
70.106 + public DLSSampleOptions getSampleoptions() {
70.107 + return sampleoptions;
70.108 + }
70.109 +
70.110 + public void setSampleoptions(DLSSampleOptions sampleOptions) {
70.111 + this.sampleoptions = sampleOptions;
70.112 + }
70.113 +
70.114 + public String toString() {
70.115 + return "Sample: " + info.name;
70.116 + }
70.117 +
70.118 + public byte[] getGuid() {
70.119 + return guid;
70.120 + }
70.121 +
70.122 + public void setGuid(byte[] guid) {
70.123 + this.guid = guid;
70.124 + }
70.125 +}
71.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
71.2 +++ b/src/share/classes/com/sun/media/sound/DLSSampleLoop.java Tue Feb 03 22:02:55 2009 -0800
71.3 @@ -0,0 +1,63 @@
71.4 +/*
71.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
71.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
71.7 + *
71.8 + * This code is free software; you can redistribute it and/or modify it
71.9 + * under the terms of the GNU General Public License version 2 only, as
71.10 + * published by the Free Software Foundation. Sun designates this
71.11 + * particular file as subject to the "Classpath" exception as provided
71.12 + * by Sun in the LICENSE file that accompanied this code.
71.13 + *
71.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
71.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
71.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
71.17 + * version 2 for more details (a copy is included in the LICENSE file that
71.18 + * accompanied this code).
71.19 + *
71.20 + * You should have received a copy of the GNU General Public License version
71.21 + * 2 along with this work; if not, write to the Free Software Foundation,
71.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
71.23 + *
71.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
71.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
71.26 + * have any questions.
71.27 + */
71.28 +package com.sun.media.sound;
71.29 +
71.30 +/**
71.31 + * This class is used to store loop points inside DLSSampleOptions class.
71.32 + *
71.33 + * @author Karl Helgason
71.34 + */
71.35 +public class DLSSampleLoop {
71.36 +
71.37 + public final static int LOOP_TYPE_FORWARD = 0;
71.38 + public final static int LOOP_TYPE_RELEASE = 1;
71.39 + protected long type;
71.40 + protected long start;
71.41 + protected long length;
71.42 +
71.43 + public long getLength() {
71.44 + return length;
71.45 + }
71.46 +
71.47 + public void setLength(long length) {
71.48 + this.length = length;
71.49 + }
71.50 +
71.51 + public long getStart() {
71.52 + return start;
71.53 + }
71.54 +
71.55 + public void setStart(long start) {
71.56 + this.start = start;
71.57 + }
71.58 +
71.59 + public long getType() {
71.60 + return type;
71.61 + }
71.62 +
71.63 + public void setType(long type) {
71.64 + this.type = type;
71.65 + }
71.66 +}
72.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
72.2 +++ b/src/share/classes/com/sun/media/sound/DLSSampleOptions.java Tue Feb 03 22:02:55 2009 -0800
72.3 @@ -0,0 +1,80 @@
72.4 +/*
72.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
72.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
72.7 + *
72.8 + * This code is free software; you can redistribute it and/or modify it
72.9 + * under the terms of the GNU General Public License version 2 only, as
72.10 + * published by the Free Software Foundation. Sun designates this
72.11 + * particular file as subject to the "Classpath" exception as provided
72.12 + * by Sun in the LICENSE file that accompanied this code.
72.13 + *
72.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
72.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
72.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
72.17 + * version 2 for more details (a copy is included in the LICENSE file that
72.18 + * accompanied this code).
72.19 + *
72.20 + * You should have received a copy of the GNU General Public License version
72.21 + * 2 along with this work; if not, write to the Free Software Foundation,
72.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
72.23 + *
72.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
72.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
72.26 + * have any questions.
72.27 + */
72.28 +package com.sun.media.sound;
72.29 +
72.30 +import java.util.ArrayList;
72.31 +import java.util.List;
72.32 +
72.33 +/**
72.34 + * This class stores options how to playback sampled data like pitch/tuning,
72.35 + * attenuation and loops.
72.36 + * It is stored as a "wsmp" chunk inside DLS files.
72.37 + *
72.38 + * @author Karl Helgason
72.39 + */
72.40 +public class DLSSampleOptions {
72.41 +
72.42 + protected int unitynote;
72.43 + protected short finetune;
72.44 + protected int attenuation;
72.45 + protected long options;
72.46 + protected List<DLSSampleLoop> loops = new ArrayList<DLSSampleLoop>();
72.47 +
72.48 + public int getAttenuation() {
72.49 + return attenuation;
72.50 + }
72.51 +
72.52 + public void setAttenuation(int attenuation) {
72.53 + this.attenuation = attenuation;
72.54 + }
72.55 +
72.56 + public short getFinetune() {
72.57 + return finetune;
72.58 + }
72.59 +
72.60 + public void setFinetune(short finetune) {
72.61 + this.finetune = finetune;
72.62 + }
72.63 +
72.64 + public List<DLSSampleLoop> getLoops() {
72.65 + return loops;
72.66 + }
72.67 +
72.68 + public long getOptions() {
72.69 + return options;
72.70 + }
72.71 +
72.72 + public void setOptions(long options) {
72.73 + this.options = options;
72.74 + }
72.75 +
72.76 + public int getUnitynote() {
72.77 + return unitynote;
72.78 + }
72.79 +
72.80 + public void setUnitynote(int unitynote) {
72.81 + this.unitynote = unitynote;
72.82 + }
72.83 +}
73.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
73.2 +++ b/src/share/classes/com/sun/media/sound/DLSSoundbank.java Tue Feb 03 22:02:55 2009 -0800
73.3 @@ -0,0 +1,1287 @@
73.4 +/*
73.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
73.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
73.7 + *
73.8 + * This code is free software; you can redistribute it and/or modify it
73.9 + * under the terms of the GNU General Public License version 2 only, as
73.10 + * published by the Free Software Foundation. Sun designates this
73.11 + * particular file as subject to the "Classpath" exception as provided
73.12 + * by Sun in the LICENSE file that accompanied this code.
73.13 + *
73.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
73.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
73.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
73.17 + * version 2 for more details (a copy is included in the LICENSE file that
73.18 + * accompanied this code).
73.19 + *
73.20 + * You should have received a copy of the GNU General Public License version
73.21 + * 2 along with this work; if not, write to the Free Software Foundation,
73.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
73.23 + *
73.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
73.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
73.26 + * have any questions.
73.27 + */
73.28 +package com.sun.media.sound;
73.29 +
73.30 +import java.io.File;
73.31 +import java.io.FileInputStream;
73.32 +import java.io.IOException;
73.33 +import java.io.InputStream;
73.34 +import java.io.OutputStream;
73.35 +import java.net.URL;
73.36 +import java.util.ArrayList;
73.37 +import java.util.Arrays;
73.38 +import java.util.HashMap;
73.39 +import java.util.List;
73.40 +import java.util.Map;
73.41 +import java.util.Stack;
73.42 +
73.43 +import javax.sound.midi.Instrument;
73.44 +import javax.sound.midi.Patch;
73.45 +import javax.sound.midi.Soundbank;
73.46 +import javax.sound.midi.SoundbankResource;
73.47 +import javax.sound.sampled.AudioFormat;
73.48 +import javax.sound.sampled.AudioInputStream;
73.49 +import javax.sound.sampled.AudioSystem;
73.50 +import javax.sound.sampled.AudioFormat.Encoding;
73.51 +
73.52 +/**
73.53 + * A DLS Level 1 and Level 2 soundbank reader (from files/url/streams).
73.54 + *
73.55 + * @author Karl Helgason
73.56 + */
73.57 +public class DLSSoundbank implements Soundbank {
73.58 +
73.59 + static private class DLSID {
73.60 + long i1;
73.61 + int s1;
73.62 + int s2;
73.63 + int x1;
73.64 + int x2;
73.65 + int x3;
73.66 + int x4;
73.67 + int x5;
73.68 + int x6;
73.69 + int x7;
73.70 + int x8;
73.71 +
73.72 + private DLSID() {
73.73 + }
73.74 +
73.75 + public DLSID(long i1, int s1, int s2, int x1, int x2, int x3, int x4,
73.76 + int x5, int x6, int x7, int x8) {
73.77 + this.i1 = i1;
73.78 + this.s1 = s1;
73.79 + this.s2 = s2;
73.80 + this.x1 = x1;
73.81 + this.x2 = x2;
73.82 + this.x3 = x3;
73.83 + this.x4 = x4;
73.84 + this.x5 = x5;
73.85 + this.x6 = x6;
73.86 + this.x7 = x7;
73.87 + this.x8 = x8;
73.88 + }
73.89 +
73.90 + public static DLSID read(RIFFReader riff) throws IOException {
73.91 + DLSID d = new DLSID();
73.92 + d.i1 = riff.readUnsignedInt();
73.93 + d.s1 = riff.readUnsignedShort();
73.94 + d.s2 = riff.readUnsignedShort();
73.95 + d.x1 = riff.readUnsignedByte();
73.96 + d.x2 = riff.readUnsignedByte();
73.97 + d.x3 = riff.readUnsignedByte();
73.98 + d.x4 = riff.readUnsignedByte();
73.99 + d.x5 = riff.readUnsignedByte();
73.100 + d.x6 = riff.readUnsignedByte();
73.101 + d.x7 = riff.readUnsignedByte();
73.102 + d.x8 = riff.readUnsignedByte();
73.103 + return d;
73.104 + }
73.105 +
73.106 + public int hashCode() {
73.107 + return (int)i1;
73.108 + }
73.109 +
73.110 + public boolean equals(Object obj) {
73.111 + if (!(obj instanceof DLSID)) {
73.112 + return false;
73.113 + }
73.114 + DLSID t = (DLSID) obj;
73.115 + return i1 == t.i1 && s1 == t.s1 && s2 == t.s2
73.116 + && x1 == t.x1 && x2 == t.x2 && x3 == t.x3 && x4 == t.x4
73.117 + && x5 == t.x5 && x6 == t.x6 && x7 == t.x7 && x8 == t.x8;
73.118 + }
73.119 + }
73.120 +
73.121 + /** X = X & Y */
73.122 + private static final int DLS_CDL_AND = 0x0001;
73.123 + /** X = X | Y */
73.124 + private static final int DLS_CDL_OR = 0x0002;
73.125 + /** X = X ^ Y */
73.126 + private static final int DLS_CDL_XOR = 0x0003;
73.127 + /** X = X + Y */
73.128 + private static final int DLS_CDL_ADD = 0x0004;
73.129 + /** X = X - Y */
73.130 + private static final int DLS_CDL_SUBTRACT = 0x0005;
73.131 + /** X = X * Y */
73.132 + private static final int DLS_CDL_MULTIPLY = 0x0006;
73.133 + /** X = X / Y */
73.134 + private static final int DLS_CDL_DIVIDE = 0x0007;
73.135 + /** X = X && Y */
73.136 + private static final int DLS_CDL_LOGICAL_AND = 0x0008;
73.137 + /** X = X || Y */
73.138 + private static final int DLS_CDL_LOGICAL_OR = 0x0009;
73.139 + /** X = (X < Y) */
73.140 + private static final int DLS_CDL_LT = 0x000A;
73.141 + /** X = (X <= Y) */
73.142 + private static final int DLS_CDL_LE = 0x000B;
73.143 + /** X = (X > Y) */
73.144 + private static final int DLS_CDL_GT = 0x000C;
73.145 + /** X = (X >= Y) */
73.146 + private static final int DLS_CDL_GE = 0x000D;
73.147 + /** X = (X == Y) */
73.148 + private static final int DLS_CDL_EQ = 0x000E;
73.149 + /** X = !X */
73.150 + private static final int DLS_CDL_NOT = 0x000F;
73.151 + /** 32-bit constant */
73.152 + private static final int DLS_CDL_CONST = 0x0010;
73.153 + /** 32-bit value returned from query */
73.154 + private static final int DLS_CDL_QUERY = 0x0011;
73.155 + /** 32-bit value returned from query */
73.156 + private static final int DLS_CDL_QUERYSUPPORTED = 0x0012;
73.157 +
73.158 + private static final DLSID DLSID_GMInHardware = new DLSID(0x178f2f24,
73.159 + 0xc364, 0x11d1, 0xa7, 0x60, 0x00, 0x00, 0xf8, 0x75, 0xac, 0x12);
73.160 + private static final DLSID DLSID_GSInHardware = new DLSID(0x178f2f25,
73.161 + 0xc364, 0x11d1, 0xa7, 0x60, 0x00, 0x00, 0xf8, 0x75, 0xac, 0x12);
73.162 + private static final DLSID DLSID_XGInHardware = new DLSID(0x178f2f26,
73.163 + 0xc364, 0x11d1, 0xa7, 0x60, 0x00, 0x00, 0xf8, 0x75, 0xac, 0x12);
73.164 + private static final DLSID DLSID_SupportsDLS1 = new DLSID(0x178f2f27,
73.165 + 0xc364, 0x11d1, 0xa7, 0x60, 0x00, 0x00, 0xf8, 0x75, 0xac, 0x12);
73.166 + private static final DLSID DLSID_SupportsDLS2 = new DLSID(0xf14599e5,
73.167 + 0x4689, 0x11d2, 0xaf, 0xa6, 0x0, 0xaa, 0x0, 0x24, 0xd8, 0xb6);
73.168 + private static final DLSID DLSID_SampleMemorySize = new DLSID(0x178f2f28,
73.169 + 0xc364, 0x11d1, 0xa7, 0x60, 0x00, 0x00, 0xf8, 0x75, 0xac, 0x12);
73.170 + private static final DLSID DLSID_ManufacturersID = new DLSID(0xb03e1181,
73.171 + 0x8095, 0x11d2, 0xa1, 0xef, 0x0, 0x60, 0x8, 0x33, 0xdb, 0xd8);
73.172 + private static final DLSID DLSID_ProductID = new DLSID(0xb03e1182,
73.173 + 0x8095, 0x11d2, 0xa1, 0xef, 0x0, 0x60, 0x8, 0x33, 0xdb, 0xd8);
73.174 + private static final DLSID DLSID_SamplePlaybackRate = new DLSID(0x2a91f713,
73.175 + 0xa4bf, 0x11d2, 0xbb, 0xdf, 0x0, 0x60, 0x8, 0x33, 0xdb, 0xd8);
73.176 +
73.177 + private long major = -1;
73.178 + private long minor = -1;
73.179 +
73.180 + private DLSInfo info = new DLSInfo();
73.181 +
73.182 + private List<DLSInstrument> instruments = new ArrayList<DLSInstrument>();
73.183 + private List<DLSSample> samples = new ArrayList<DLSSample>();
73.184 +
73.185 + private boolean largeFormat = false;
73.186 + private File sampleFile;
73.187 +
73.188 + public DLSSoundbank() {
73.189 + }
73.190 +
73.191 + public DLSSoundbank(URL url) throws IOException {
73.192 + InputStream is = url.openStream();
73.193 + try {
73.194 + readSoundbank(is);
73.195 + } finally {
73.196 + is.close();
73.197 + }
73.198 + }
73.199 +
73.200 + public DLSSoundbank(File file) throws IOException {
73.201 + largeFormat = true;
73.202 + sampleFile = file;
73.203 + InputStream is = new FileInputStream(file);
73.204 + try {
73.205 + readSoundbank(is);
73.206 + } finally {
73.207 + is.close();
73.208 + }
73.209 + }
73.210 +
73.211 + public DLSSoundbank(InputStream inputstream) throws IOException {
73.212 + readSoundbank(inputstream);
73.213 + }
73.214 +
73.215 + private void readSoundbank(InputStream inputstream) throws IOException {
73.216 + RIFFReader riff = new RIFFReader(inputstream);
73.217 + if (!riff.getFormat().equals("RIFF")) {
73.218 + throw new RIFFInvalidFormatException(
73.219 + "Input stream is not a valid RIFF stream!");
73.220 + }
73.221 + if (!riff.getType().equals("DLS ")) {
73.222 + throw new RIFFInvalidFormatException(
73.223 + "Input stream is not a valid DLS soundbank!");
73.224 + }
73.225 + while (riff.hasNextChunk()) {
73.226 + RIFFReader chunk = riff.nextChunk();
73.227 + if (chunk.getFormat().equals("LIST")) {
73.228 + if (chunk.getType().equals("INFO"))
73.229 + readInfoChunk(chunk);
73.230 + if (chunk.getType().equals("lins"))
73.231 + readLinsChunk(chunk);
73.232 + if (chunk.getType().equals("wvpl"))
73.233 + readWvplChunk(chunk);
73.234 + } else {
73.235 + if (chunk.getFormat().equals("cdl ")) {
73.236 + if (!readCdlChunk(chunk)) {
73.237 + throw new RIFFInvalidFormatException(
73.238 + "DLS file isn't supported!");
73.239 + }
73.240 + }
73.241 + if (chunk.getFormat().equals("colh")) {
73.242 + // skipped because we will load the entire bank into memory
73.243 + // long instrumentcount = chunk.readUnsignedInt();
73.244 + // System.out.println("instrumentcount = "+ instrumentcount);
73.245 + }
73.246 + if (chunk.getFormat().equals("ptbl")) {
73.247 + // Pool Table Chunk
73.248 + // skipped because we will load the entire bank into memory
73.249 + }
73.250 + if (chunk.getFormat().equals("vers")) {
73.251 + major = chunk.readUnsignedInt();
73.252 + minor = chunk.readUnsignedInt();
73.253 + }
73.254 + }
73.255 + }
73.256 +
73.257 + for (Map.Entry<DLSRegion, Long> entry : temp_rgnassign.entrySet()) {
73.258 + entry.getKey().sample = samples.get((int)entry.getValue().longValue());
73.259 + }
73.260 +
73.261 + temp_rgnassign = null;
73.262 + }
73.263 +
73.264 + private boolean cdlIsQuerySupported(DLSID uuid) {
73.265 + return uuid.equals(DLSID_GMInHardware)
73.266 + || uuid.equals(DLSID_GSInHardware)
73.267 + || uuid.equals(DLSID_XGInHardware)
73.268 + || uuid.equals(DLSID_SupportsDLS1)
73.269 + || uuid.equals(DLSID_SupportsDLS2)
73.270 + || uuid.equals(DLSID_SampleMemorySize)
73.271 + || uuid.equals(DLSID_ManufacturersID)
73.272 + || uuid.equals(DLSID_ProductID)
73.273 + || uuid.equals(DLSID_SamplePlaybackRate);
73.274 + }
73.275 +
73.276 + private long cdlQuery(DLSID uuid) {
73.277 + if (uuid.equals(DLSID_GMInHardware))
73.278 + return 1;
73.279 + if (uuid.equals(DLSID_GSInHardware))
73.280 + return 0;
73.281 + if (uuid.equals(DLSID_XGInHardware))
73.282 + return 0;
73.283 + if (uuid.equals(DLSID_SupportsDLS1))
73.284 + return 1;
73.285 + if (uuid.equals(DLSID_SupportsDLS2))
73.286 + return 1;
73.287 + if (uuid.equals(DLSID_SampleMemorySize))
73.288 + return Runtime.getRuntime().totalMemory();
73.289 + if (uuid.equals(DLSID_ManufacturersID))
73.290 + return 0;
73.291 + if (uuid.equals(DLSID_ProductID))
73.292 + return 0;
73.293 + if (uuid.equals(DLSID_SamplePlaybackRate))
73.294 + return 44100;
73.295 + return 0;
73.296 + }
73.297 +
73.298 +
73.299 + // Reading cdl-ck Chunk
73.300 + // "cdl " chunk can only appear inside : DLS,lart,lar2,rgn,rgn2
73.301 + private boolean readCdlChunk(RIFFReader riff) throws IOException {
73.302 +
73.303 + DLSID uuid;
73.304 + long x;
73.305 + long y;
73.306 + Stack<Long> stack = new Stack<Long>();
73.307 +
73.308 + while (riff.available() != 0) {
73.309 + int opcode = riff.readUnsignedShort();
73.310 + switch (opcode) {
73.311 + case DLS_CDL_AND:
73.312 + x = stack.pop();
73.313 + y = stack.pop();
73.314 + stack.push(Long.valueOf(((x != 0) && (y != 0)) ? 1 : 0));
73.315 + break;
73.316 + case DLS_CDL_OR:
73.317 + x = stack.pop();
73.318 + y = stack.pop();
73.319 + stack.push(Long.valueOf(((x != 0) || (y != 0)) ? 1 : 0));
73.320 + break;
73.321 + case DLS_CDL_XOR:
73.322 + x = stack.pop();
73.323 + y = stack.pop();
73.324 + stack.push(Long.valueOf(((x != 0) ^ (y != 0)) ? 1 : 0));
73.325 + break;
73.326 + case DLS_CDL_ADD:
73.327 + x = stack.pop();
73.328 + y = stack.pop();
73.329 + stack.push(Long.valueOf(x + y));
73.330 + break;
73.331 + case DLS_CDL_SUBTRACT:
73.332 + x = stack.pop();
73.333 + y = stack.pop();
73.334 + stack.push(Long.valueOf(x - y));
73.335 + break;
73.336 + case DLS_CDL_MULTIPLY:
73.337 + x = stack.pop();
73.338 + y = stack.pop();
73.339 + stack.push(Long.valueOf(x * y));
73.340 + break;
73.341 + case DLS_CDL_DIVIDE:
73.342 + x = stack.pop();
73.343 + y = stack.pop();
73.344 + stack.push(Long.valueOf(x / y));
73.345 + break;
73.346 + case DLS_CDL_LOGICAL_AND:
73.347 + x = stack.pop();
73.348 + y = stack.pop();
73.349 + stack.push(Long.valueOf(((x != 0) && (y != 0)) ? 1 : 0));
73.350 + break;
73.351 + case DLS_CDL_LOGICAL_OR:
73.352 + x = stack.pop();
73.353 + y = stack.pop();
73.354 + stack.push(Long.valueOf(((x != 0) || (y != 0)) ? 1 : 0));
73.355 + break;
73.356 + case DLS_CDL_LT:
73.357 + x = stack.pop();
73.358 + y = stack.pop();
73.359 + stack.push(Long.valueOf((x < y) ? 1 : 0));
73.360 + break;
73.361 + case DLS_CDL_LE:
73.362 + x = stack.pop();
73.363 + y = stack.pop();
73.364 + stack.push(Long.valueOf((x <= y) ? 1 : 0));
73.365 + break;
73.366 + case DLS_CDL_GT:
73.367 + x = stack.pop();
73.368 + y = stack.pop();
73.369 + stack.push(Long.valueOf((x > y) ? 1 : 0));
73.370 + break;
73.371 + case DLS_CDL_GE:
73.372 + x = stack.pop();
73.373 + y = stack.pop();
73.374 + stack.push(Long.valueOf((x >= y) ? 1 : 0));
73.375 + break;
73.376 + case DLS_CDL_EQ:
73.377 + x = stack.pop();
73.378 + y = stack.pop();
73.379 + stack.push(Long.valueOf((x == y) ? 1 : 0));
73.380 + break;
73.381 + case DLS_CDL_NOT:
73.382 + x = stack.pop();
73.383 + y = stack.pop();
73.384 + stack.push(Long.valueOf((x == 0) ? 1 : 0));
73.385 + break;
73.386 + case DLS_CDL_CONST:
73.387 + stack.push(Long.valueOf(riff.readUnsignedInt()));
73.388 + break;
73.389 + case DLS_CDL_QUERY:
73.390 + uuid = DLSID.read(riff);
73.391 + stack.push(cdlQuery(uuid));
73.392 + break;
73.393 + case DLS_CDL_QUERYSUPPORTED:
73.394 + uuid = DLSID.read(riff);
73.395 + stack.push(Long.valueOf(cdlIsQuerySupported(uuid) ? 1 : 0));
73.396 + break;
73.397 + default:
73.398 + break;
73.399 + }
73.400 + }
73.401 + if (stack.isEmpty())
73.402 + return false;
73.403 +
73.404 + return stack.pop() == 1;
73.405 + }
73.406 +
73.407 + private void readInfoChunk(RIFFReader riff) throws IOException {
73.408 + info.name = null;
73.409 + while (riff.hasNextChunk()) {
73.410 + RIFFReader chunk = riff.nextChunk();
73.411 + String format = chunk.getFormat();
73.412 + if (format.equals("INAM"))
73.413 + info.name = chunk.readString(chunk.available());
73.414 + else if (format.equals("ICRD"))
73.415 + info.creationDate = chunk.readString(chunk.available());
73.416 + else if (format.equals("IENG"))
73.417 + info.engineers = chunk.readString(chunk.available());
73.418 + else if (format.equals("IPRD"))
73.419 + info.product = chunk.readString(chunk.available());
73.420 + else if (format.equals("ICOP"))
73.421 + info.copyright = chunk.readString(chunk.available());
73.422 + else if (format.equals("ICMT"))
73.423 + info.comments = chunk.readString(chunk.available());
73.424 + else if (format.equals("ISFT"))
73.425 + info.tools = chunk.readString(chunk.available());
73.426 + else if (format.equals("IARL"))
73.427 + info.archival_location = chunk.readString(chunk.available());
73.428 + else if (format.equals("IART"))
73.429 + info.artist = chunk.readString(chunk.available());
73.430 + else if (format.equals("ICMS"))
73.431 + info.commissioned = chunk.readString(chunk.available());
73.432 + else if (format.equals("IGNR"))
73.433 + info.genre = chunk.readString(chunk.available());
73.434 + else if (format.equals("IKEY"))
73.435 + info.keywords = chunk.readString(chunk.available());
73.436 + else if (format.equals("IMED"))
73.437 + info.medium = chunk.readString(chunk.available());
73.438 + else if (format.equals("ISBJ"))
73.439 + info.subject = chunk.readString(chunk.available());
73.440 + else if (format.equals("ISRC"))
73.441 + info.source = chunk.readString(chunk.available());
73.442 + else if (format.equals("ISRF"))
73.443 + info.source_form = chunk.readString(chunk.available());
73.444 + else if (format.equals("ITCH"))
73.445 + info.technician = chunk.readString(chunk.available());
73.446 + }
73.447 + }
73.448 +
73.449 + private void readLinsChunk(RIFFReader riff) throws IOException {
73.450 + while (riff.hasNextChunk()) {
73.451 + RIFFReader chunk = riff.nextChunk();
73.452 + if (chunk.getFormat().equals("LIST")) {
73.453 + if (chunk.getType().equals("ins "))
73.454 + readInsChunk(chunk);
73.455 + }
73.456 + }
73.457 + }
73.458 +
73.459 + private void readInsChunk(RIFFReader riff) throws IOException {
73.460 + DLSInstrument instrument = new DLSInstrument(this);
73.461 +
73.462 + while (riff.hasNextChunk()) {
73.463 + RIFFReader chunk = riff.nextChunk();
73.464 + String format = chunk.getFormat();
73.465 + if (format.equals("LIST")) {
73.466 + if (chunk.getType().equals("INFO")) {
73.467 + readInsInfoChunk(instrument, chunk);
73.468 + }
73.469 + if (chunk.getType().equals("lrgn")) {
73.470 + while (chunk.hasNextChunk()) {
73.471 + RIFFReader subchunk = chunk.nextChunk();
73.472 + if (subchunk.getFormat().equals("LIST")) {
73.473 + if (subchunk.getType().equals("rgn ")) {
73.474 + DLSRegion split = new DLSRegion();
73.475 + if (readRgnChunk(split, subchunk))
73.476 + instrument.getRegions().add(split);
73.477 + }
73.478 + if (subchunk.getType().equals("rgn2")) {
73.479 + // support for DLS level 2 regions
73.480 + DLSRegion split = new DLSRegion();
73.481 + if (readRgnChunk(split, subchunk))
73.482 + instrument.getRegions().add(split);
73.483 + }
73.484 + }
73.485 + }
73.486 + }
73.487 + if (chunk.getType().equals("lart")) {
73.488 + List<DLSModulator> modlist = new ArrayList<DLSModulator>();
73.489 + while (chunk.hasNextChunk()) {
73.490 + RIFFReader subchunk = chunk.nextChunk();
73.491 + if (chunk.getFormat().equals("cdl ")) {
73.492 + if (!readCdlChunk(chunk)) {
73.493 + modlist.clear();
73.494 + break;
73.495 + }
73.496 + }
73.497 + if (subchunk.getFormat().equals("art1"))
73.498 + readArt1Chunk(modlist, subchunk);
73.499 + }
73.500 + instrument.getModulators().addAll(modlist);
73.501 + }
73.502 + if (chunk.getType().equals("lar2")) {
73.503 + // support for DLS level 2 ART
73.504 + List<DLSModulator> modlist = new ArrayList<DLSModulator>();
73.505 + while (chunk.hasNextChunk()) {
73.506 + RIFFReader subchunk = chunk.nextChunk();
73.507 + if (chunk.getFormat().equals("cdl ")) {
73.508 + if (!readCdlChunk(chunk)) {
73.509 + modlist.clear();
73.510 + break;
73.511 + }
73.512 + }
73.513 + if (subchunk.getFormat().equals("art2"))
73.514 + readArt2Chunk(modlist, subchunk);
73.515 + }
73.516 + instrument.getModulators().addAll(modlist);
73.517 + }
73.518 + } else {
73.519 + if (format.equals("dlid")) {
73.520 + instrument.guid = new byte[16];
73.521 + chunk.readFully(instrument.guid);
73.522 + }
73.523 + if (format.equals("insh")) {
73.524 + chunk.readUnsignedInt(); // Read Region Count - ignored
73.525 +
73.526 + int bank = chunk.read(); // LSB
73.527 + bank += (chunk.read() & 127) << 7; // MSB
73.528 + chunk.read(); // Read Reserved byte
73.529 + int drumins = chunk.read(); // Drum Instrument
73.530 +
73.531 + int id = chunk.read() & 127; // Read only first 7 bits
73.532 + chunk.read(); // Read Reserved byte
73.533 + chunk.read(); // Read Reserved byte
73.534 + chunk.read(); // Read Reserved byte
73.535 +
73.536 + instrument.bank = bank;
73.537 + instrument.preset = (int) id;
73.538 + instrument.druminstrument = (drumins & 128) > 0;
73.539 + //System.out.println("bank="+bank+" drumkit="+drumkit
73.540 + // +" id="+id);
73.541 + }
73.542 +
73.543 + }
73.544 + }
73.545 + instruments.add(instrument);
73.546 + }
73.547 +
73.548 + private void readArt1Chunk(List<DLSModulator> modulators, RIFFReader riff)
73.549 + throws IOException {
73.550 + long size = riff.readUnsignedInt();
73.551 + long count = riff.readUnsignedInt();
73.552 +
73.553 + if (size - 8 != 0)
73.554 + riff.skipBytes(size - 8);
73.555 +
73.556 + for (int i = 0; i < count; i++) {
73.557 + DLSModulator modulator = new DLSModulator();
73.558 + modulator.version = 1;
73.559 + modulator.source = riff.readUnsignedShort();
73.560 + modulator.control = riff.readUnsignedShort();
73.561 + modulator.destination = riff.readUnsignedShort();
73.562 + modulator.transform = riff.readUnsignedShort();
73.563 + modulator.scale = riff.readInt();
73.564 + modulators.add(modulator);
73.565 + }
73.566 + }
73.567 +
73.568 + private void readArt2Chunk(List<DLSModulator> modulators, RIFFReader riff)
73.569 + throws IOException {
73.570 + long size = riff.readUnsignedInt();
73.571 + long count = riff.readUnsignedInt();
73.572 +
73.573 + if (size - 8 != 0)
73.574 + riff.skipBytes(size - 8);
73.575 +
73.576 + for (int i = 0; i < count; i++) {
73.577 + DLSModulator modulator = new DLSModulator();
73.578 + modulator.version = 2;
73.579 + modulator.source = riff.readUnsignedShort();
73.580 + modulator.control = riff.readUnsignedShort();
73.581 + modulator.destination = riff.readUnsignedShort();
73.582 + modulator.transform = riff.readUnsignedShort();
73.583 + modulator.scale = riff.readInt();
73.584 + modulators.add(modulator);
73.585 + }
73.586 + }
73.587 +
73.588 + private Map<DLSRegion, Long> temp_rgnassign = new HashMap<DLSRegion, Long>();
73.589 +
73.590 + private boolean readRgnChunk(DLSRegion split, RIFFReader riff)
73.591 + throws IOException {
73.592 + while (riff.hasNextChunk()) {
73.593 + RIFFReader chunk = riff.nextChunk();
73.594 + String format = chunk.getFormat();
73.595 + if (format.equals("LIST")) {
73.596 + if (chunk.getType().equals("lart")) {
73.597 + List<DLSModulator> modlist = new ArrayList<DLSModulator>();
73.598 + while (chunk.hasNextChunk()) {
73.599 + RIFFReader subchunk = chunk.nextChunk();
73.600 + if (chunk.getFormat().equals("cdl ")) {
73.601 + if (!readCdlChunk(chunk)) {
73.602 + modlist.clear();
73.603 + break;
73.604 + }
73.605 + }
73.606 + if (subchunk.getFormat().equals("art1"))
73.607 + readArt1Chunk(modlist, subchunk);
73.608 + }
73.609 + split.getModulators().addAll(modlist);
73.610 + }
73.611 + if (chunk.getType().equals("lar2")) {
73.612 + // support for DLS level 2 ART
73.613 + List<DLSModulator> modlist = new ArrayList<DLSModulator>();
73.614 + while (chunk.hasNextChunk()) {
73.615 + RIFFReader subchunk = chunk.nextChunk();
73.616 + if (chunk.getFormat().equals("cdl ")) {
73.617 + if (!readCdlChunk(chunk)) {
73.618 + modlist.clear();
73.619 + break;
73.620 + }
73.621 + }
73.622 + if (subchunk.getFormat().equals("art2"))
73.623 + readArt2Chunk(modlist, subchunk);
73.624 + }
73.625 + split.getModulators().addAll(modlist);
73.626 + }
73.627 + } else {
73.628 +
73.629 + if (format.equals("cdl ")) {
73.630 + if (!readCdlChunk(chunk))
73.631 + return false;
73.632 + }
73.633 + if (format.equals("rgnh")) {
73.634 + split.keyfrom = chunk.readUnsignedShort();
73.635 + split.keyto = chunk.readUnsignedShort();
73.636 + split.velfrom = chunk.readUnsignedShort();
73.637 + split.velto = chunk.readUnsignedShort();
73.638 + split.options = chunk.readUnsignedShort();
73.639 + split.exclusiveClass = chunk.readUnsignedShort();
73.640 + }
73.641 + if (format.equals("wlnk")) {
73.642 + split.fusoptions = chunk.readUnsignedShort();
73.643 + split.phasegroup = chunk.readUnsignedShort();
73.644 + split.channel = chunk.readUnsignedInt();
73.645 + long sampleid = chunk.readUnsignedInt();
73.646 + temp_rgnassign.put(split, sampleid);
73.647 + }
73.648 + if (format.equals("wsmp")) {
73.649 + split.sampleoptions = new DLSSampleOptions();
73.650 + readWsmpChunk(split.sampleoptions, chunk);
73.651 + }
73.652 + }
73.653 + }
73.654 + return true;
73.655 + }
73.656 +
73.657 + private void readWsmpChunk(DLSSampleOptions sampleOptions, RIFFReader riff)
73.658 + throws IOException {
73.659 + long size = riff.readUnsignedInt();
73.660 + sampleOptions.unitynote = riff.readUnsignedShort();
73.661 + sampleOptions.finetune = riff.readShort();
73.662 + sampleOptions.attenuation = riff.readInt();
73.663 + sampleOptions.options = riff.readUnsignedInt();
73.664 + long loops = riff.readInt();
73.665 +
73.666 + if (size > 20)
73.667 + riff.skipBytes(size - 20);
73.668 +
73.669 + for (int i = 0; i < loops; i++) {
73.670 + DLSSampleLoop loop = new DLSSampleLoop();
73.671 + long size2 = riff.readUnsignedInt();
73.672 + loop.type = riff.readUnsignedInt();
73.673 + loop.start = riff.readUnsignedInt();
73.674 + loop.length = riff.readUnsignedInt();
73.675 + sampleOptions.loops.add(loop);
73.676 + if (size2 > 16)
73.677 + riff.skipBytes(size2 - 16);
73.678 + }
73.679 + }
73.680 +
73.681 + private void readInsInfoChunk(DLSInstrument dlsinstrument, RIFFReader riff)
73.682 + throws IOException {
73.683 + dlsinstrument.info.name = null;
73.684 + while (riff.hasNextChunk()) {
73.685 + RIFFReader chunk = riff.nextChunk();
73.686 + String format = chunk.getFormat();
73.687 + if (format.equals("INAM")) {
73.688 + dlsinstrument.info.name = chunk.readString(chunk.available());
73.689 + } else if (format.equals("ICRD")) {
73.690 + dlsinstrument.info.creationDate =
73.691 + chunk.readString(chunk.available());
73.692 + } else if (format.equals("IENG")) {
73.693 + dlsinstrument.info.engineers =
73.694 + chunk.readString(chunk.available());
73.695 + } else if (format.equals("IPRD")) {
73.696 + dlsinstrument.info.product = chunk.readString(chunk.available());
73.697 + } else if (format.equals("ICOP")) {
73.698 + dlsinstrument.info.copyright =
73.699 + chunk.readString(chunk.available());
73.700 + } else if (format.equals("ICMT")) {
73.701 + dlsinstrument.info.comments =
73.702 + chunk.readString(chunk.available());
73.703 + } else if (format.equals("ISFT")) {
73.704 + dlsinstrument.info.tools = chunk.readString(chunk.available());
73.705 + } else if (format.equals("IARL")) {
73.706 + dlsinstrument.info.archival_location =
73.707 + chunk.readString(chunk.available());
73.708 + } else if (format.equals("IART")) {
73.709 + dlsinstrument.info.artist = chunk.readString(chunk.available());
73.710 + } else if (format.equals("ICMS")) {
73.711 + dlsinstrument.info.commissioned =
73.712 + chunk.readString(chunk.available());
73.713 + } else if (format.equals("IGNR")) {
73.714 + dlsinstrument.info.genre = chunk.readString(chunk.available());
73.715 + } else if (format.equals("IKEY")) {
73.716 + dlsinstrument.info.keywords =
73.717 + chunk.readString(chunk.available());
73.718 + } else if (format.equals("IMED")) {
73.719 + dlsinstrument.info.medium = chunk.readString(chunk.available());
73.720 + } else if (format.equals("ISBJ")) {
73.721 + dlsinstrument.info.subject = chunk.readString(chunk.available());
73.722 + } else if (format.equals("ISRC")) {
73.723 + dlsinstrument.info.source = chunk.readString(chunk.available());
73.724 + } else if (format.equals("ISRF")) {
73.725 + dlsinstrument.info.source_form =
73.726 + chunk.readString(chunk.available());
73.727 + } else if (format.equals("ITCH")) {
73.728 + dlsinstrument.info.technician =
73.729 + chunk.readString(chunk.available());
73.730 + }
73.731 + }
73.732 + }
73.733 +
73.734 + private void readWvplChunk(RIFFReader riff) throws IOException {
73.735 + while (riff.hasNextChunk()) {
73.736 + RIFFReader chunk = riff.nextChunk();
73.737 + if (chunk.getFormat().equals("LIST")) {
73.738 + if (chunk.getType().equals("wave"))
73.739 + readWaveChunk(chunk);
73.740 + }
73.741 + }
73.742 + }
73.743 +
73.744 + private void readWaveChunk(RIFFReader riff) throws IOException {
73.745 + DLSSample sample = new DLSSample(this);
73.746 +
73.747 + while (riff.hasNextChunk()) {
73.748 + RIFFReader chunk = riff.nextChunk();
73.749 + String format = chunk.getFormat();
73.750 + if (format.equals("LIST")) {
73.751 + if (chunk.getType().equals("INFO")) {
73.752 + readWaveInfoChunk(sample, chunk);
73.753 + }
73.754 + } else {
73.755 + if (format.equals("dlid")) {
73.756 + sample.guid = new byte[16];
73.757 + chunk.readFully(sample.guid);
73.758 + }
73.759 +
73.760 + if (format.equals("fmt ")) {
73.761 + int sampleformat = chunk.readUnsignedShort();
73.762 + if (sampleformat != 1 && sampleformat != 3) {
73.763 + throw new RIFFInvalidDataException(
73.764 + "Only PCM samples are supported!");
73.765 + }
73.766 + int channels = chunk.readUnsignedShort();
73.767 + long samplerate = chunk.readUnsignedInt();
73.768 + // bytes per sec
73.769 + /* long framerate = */ chunk.readUnsignedInt();
73.770 + // block align, framesize
73.771 + int framesize = chunk.readUnsignedShort();
73.772 + int bits = chunk.readUnsignedShort();
73.773 + AudioFormat audioformat = null;
73.774 + if (sampleformat == 1) {
73.775 + if (bits == 8) {
73.776 + audioformat = new AudioFormat(
73.777 + Encoding.PCM_UNSIGNED, samplerate, bits,
73.778 + channels, framesize, samplerate, false);
73.779 + } else {
73.780 + audioformat = new AudioFormat(
73.781 + Encoding.PCM_SIGNED, samplerate, bits,
73.782 + channels, framesize, samplerate, false);
73.783 + }
73.784 + }
73.785 + if (sampleformat == 3) {
73.786 + audioformat = new AudioFormat(
73.787 + AudioFloatConverter.PCM_FLOAT, samplerate, bits,
73.788 + channels, framesize, samplerate, false);
73.789 + }
73.790 +
73.791 + sample.format = audioformat;
73.792 + }
73.793 +
73.794 + if (format.equals("data")) {
73.795 + if (largeFormat) {
73.796 + sample.setData(new ModelByteBuffer(sampleFile,
73.797 + chunk.getFilePointer(), chunk.available()));
73.798 + } else {
73.799 + byte[] buffer = new byte[chunk.available()];
73.800 + // chunk.read(buffer);
73.801 + sample.setData(buffer);
73.802 +
73.803 + int read = 0;
73.804 + int avail = chunk.available();
73.805 + while (read != avail) {
73.806 + if (avail - read > 65536) {
73.807 + chunk.readFully(buffer, read, 65536);
73.808 + read += 65536;
73.809 + } else {
73.810 + chunk.readFully(buffer, read, avail - read);
73.811 + read = avail;
73.812 + }
73.813 + }
73.814 + }
73.815 + }
73.816 +
73.817 + if (format.equals("wsmp")) {
73.818 + sample.sampleoptions = new DLSSampleOptions();
73.819 + readWsmpChunk(sample.sampleoptions, chunk);
73.820 + }
73.821 + }
73.822 + }
73.823 +
73.824 + samples.add(sample);
73.825 +
73.826 + }
73.827 +
73.828 + private void readWaveInfoChunk(DLSSample dlssample, RIFFReader riff)
73.829 + throws IOException {
73.830 + dlssample.info.name = null;
73.831 + while (riff.hasNextChunk()) {
73.832 + RIFFReader chunk = riff.nextChunk();
73.833 + String format = chunk.getFormat();
73.834 + if (format.equals("INAM")) {
73.835 + dlssample.info.name = chunk.readString(chunk.available());
73.836 + } else if (format.equals("ICRD")) {
73.837 + dlssample.info.creationDate =
73.838 + chunk.readString(chunk.available());
73.839 + } else if (format.equals("IENG")) {
73.840 + dlssample.info.engineers = chunk.readString(chunk.available());
73.841 + } else if (format.equals("IPRD")) {
73.842 + dlssample.info.product = chunk.readString(chunk.available());
73.843 + } else if (format.equals("ICOP")) {
73.844 + dlssample.info.copyright = chunk.readString(chunk.available());
73.845 + } else if (format.equals("ICMT")) {
73.846 + dlssample.info.comments = chunk.readString(chunk.available());
73.847 + } else if (format.equals("ISFT")) {
73.848 + dlssample.info.tools = chunk.readString(chunk.available());
73.849 + } else if (format.equals("IARL")) {
73.850 + dlssample.info.archival_location =
73.851 + chunk.readString(chunk.available());
73.852 + } else if (format.equals("IART")) {
73.853 + dlssample.info.artist = chunk.readString(chunk.available());
73.854 + } else if (format.equals("ICMS")) {
73.855 + dlssample.info.commissioned =
73.856 + chunk.readString(chunk.available());
73.857 + } else if (format.equals("IGNR")) {
73.858 + dlssample.info.genre = chunk.readString(chunk.available());
73.859 + } else if (format.equals("IKEY")) {
73.860 + dlssample.info.keywords = chunk.readString(chunk.available());
73.861 + } else if (format.equals("IMED")) {
73.862 + dlssample.info.medium = chunk.readString(chunk.available());
73.863 + } else if (format.equals("ISBJ")) {
73.864 + dlssample.info.subject = chunk.readString(chunk.available());
73.865 + } else if (format.equals("ISRC")) {
73.866 + dlssample.info.source = chunk.readString(chunk.available());
73.867 + } else if (format.equals("ISRF")) {
73.868 + dlssample.info.source_form = chunk.readString(chunk.available());
73.869 + } else if (format.equals("ITCH")) {
73.870 + dlssample.info.technician = chunk.readString(chunk.available());
73.871 + }
73.872 + }
73.873 + }
73.874 +
73.875 + public void save(String name) throws IOException {
73.876 + writeSoundbank(new RIFFWriter(name, "DLS "));
73.877 + }
73.878 +
73.879 + public void save(File file) throws IOException {
73.880 + writeSoundbank(new RIFFWriter(file, "DLS "));
73.881 + }
73.882 +
73.883 + public void save(OutputStream out) throws IOException {
73.884 + writeSoundbank(new RIFFWriter(out, "DLS "));
73.885 + }
73.886 +
73.887 + private void writeSoundbank(RIFFWriter writer) throws IOException {
73.888 + RIFFWriter colh_chunk = writer.writeChunk("colh");
73.889 + colh_chunk.writeUnsignedInt(instruments.size());
73.890 +
73.891 + if (major != -1 && minor != -1) {
73.892 + RIFFWriter vers_chunk = writer.writeChunk("vers");
73.893 + vers_chunk.writeUnsignedInt(major);
73.894 + vers_chunk.writeUnsignedInt(minor);
73.895 + }
73.896 +
73.897 + writeInstruments(writer.writeList("lins"));
73.898 +
73.899 + RIFFWriter ptbl = writer.writeChunk("ptbl");
73.900 + ptbl.writeUnsignedInt(8);
73.901 + ptbl.writeUnsignedInt(samples.size());
73.902 + long ptbl_offset = writer.getFilePointer();
73.903 + for (int i = 0; i < samples.size(); i++)
73.904 + ptbl.writeUnsignedInt(0);
73.905 +
73.906 + RIFFWriter wvpl = writer.writeList("wvpl");
73.907 + long off = wvpl.getFilePointer();
73.908 + List<Long> offsettable = new ArrayList<Long>();
73.909 + for (DLSSample sample : samples) {
73.910 + offsettable.add(Long.valueOf(wvpl.getFilePointer() - off));
73.911 + writeSample(wvpl.writeList("wave"), sample);
73.912 + }
73.913 +
73.914 + // small cheat, we are going to rewrite data back in wvpl
73.915 + long bak = writer.getFilePointer();
73.916 + writer.seek(ptbl_offset);
73.917 + writer.setWriteOverride(true);
73.918 + for (Long offset : offsettable)
73.919 + writer.writeUnsignedInt(offset.longValue());
73.920 + writer.setWriteOverride(false);
73.921 + writer.seek(bak);
73.922 +
73.923 + writeInfo(writer.writeList("INFO"), info);
73.924 +
73.925 + writer.close();
73.926 + }
73.927 +
73.928 + private void writeSample(RIFFWriter writer, DLSSample sample)
73.929 + throws IOException {
73.930 +
73.931 + AudioFormat audioformat = sample.getFormat();
73.932 +
73.933 + Encoding encoding = audioformat.getEncoding();
73.934 + float sampleRate = audioformat.getSampleRate();
73.935 + int sampleSizeInBits = audioformat.getSampleSizeInBits();
73.936 + int channels = audioformat.getChannels();
73.937 + int frameSize = audioformat.getFrameSize();
73.938 + float frameRate = audioformat.getFrameRate();
73.939 + boolean bigEndian = audioformat.isBigEndian();
73.940 +
73.941 + boolean convert_needed = false;
73.942 +
73.943 + if (audioformat.getSampleSizeInBits() == 8) {
73.944 + if (!encoding.equals(Encoding.PCM_UNSIGNED)) {
73.945 + encoding = Encoding.PCM_UNSIGNED;
73.946 + convert_needed = true;
73.947 + }
73.948 + } else {
73.949 + if (!encoding.equals(Encoding.PCM_SIGNED)) {
73.950 + encoding = Encoding.PCM_SIGNED;
73.951 + convert_needed = true;
73.952 + }
73.953 + if (bigEndian) {
73.954 + bigEndian = false;
73.955 + convert_needed = true;
73.956 + }
73.957 + }
73.958 +
73.959 + if (convert_needed) {
73.960 + audioformat = new AudioFormat(encoding, sampleRate,
73.961 + sampleSizeInBits, channels, frameSize, frameRate, bigEndian);
73.962 + }
73.963 +
73.964 + // fmt
73.965 + RIFFWriter fmt_chunk = writer.writeChunk("fmt ");
73.966 + int sampleformat = 0;
73.967 + if (audioformat.getEncoding().equals(Encoding.PCM_UNSIGNED))
73.968 + sampleformat = 1;
73.969 + else if (audioformat.getEncoding().equals(Encoding.PCM_SIGNED))
73.970 + sampleformat = 1;
73.971 + else if (audioformat.getEncoding().equals(AudioFloatConverter.PCM_FLOAT))
73.972 + sampleformat = 3;
73.973 +
73.974 + fmt_chunk.writeUnsignedShort(sampleformat);
73.975 + fmt_chunk.writeUnsignedShort(audioformat.getChannels());
73.976 + fmt_chunk.writeUnsignedInt((long) audioformat.getSampleRate());
73.977 + long srate = ((long)audioformat.getFrameRate())*audioformat.getFrameSize();
73.978 + fmt_chunk.writeUnsignedInt(srate);
73.979 + fmt_chunk.writeUnsignedShort(audioformat.getFrameSize());
73.980 + fmt_chunk.writeUnsignedShort(audioformat.getSampleSizeInBits());
73.981 + fmt_chunk.write(0);
73.982 + fmt_chunk.write(0);
73.983 +
73.984 + writeSampleOptions(writer.writeChunk("wsmp"), sample.sampleoptions);
73.985 +
73.986 + if (convert_needed) {
73.987 + RIFFWriter data_chunk = writer.writeChunk("data");
73.988 + AudioInputStream stream = AudioSystem.getAudioInputStream(
73.989 + audioformat, (AudioInputStream)sample.getData());
73.990 + byte[] buff = new byte[1024];
73.991 + int ret;
73.992 + while ((ret = stream.read(buff)) != -1) {
73.993 + data_chunk.write(buff, 0, ret);
73.994 + }
73.995 + } else {
73.996 + RIFFWriter data_chunk = writer.writeChunk("data");
73.997 + ModelByteBuffer databuff = sample.getDataBuffer();
73.998 + databuff.writeTo(data_chunk);
73.999 + /*
73.1000 + data_chunk.write(databuff.array(),
73.1001 + databuff.arrayOffset(),
73.1002 + databuff.capacity());
73.1003 + */
73.1004 + }
73.1005 +
73.1006 + writeInfo(writer.writeList("INFO"), sample.info);
73.1007 + }
73.1008 +
73.1009 + private void writeInstruments(RIFFWriter writer) throws IOException {
73.1010 + for (DLSInstrument instrument : instruments) {
73.1011 + writeInstrument(writer.writeList("ins "), instrument);
73.1012 + }
73.1013 + }
73.1014 +
73.1015 + private void writeInstrument(RIFFWriter writer, DLSInstrument instrument)
73.1016 + throws IOException {
73.1017 +
73.1018 + int art1_count = 0;
73.1019 + int art2_count = 0;
73.1020 + for (DLSModulator modulator : instrument.getModulators()) {
73.1021 + if (modulator.version == 1)
73.1022 + art1_count++;
73.1023 + if (modulator.version == 2)
73.1024 + art2_count++;
73.1025 + }
73.1026 + for (DLSRegion region : instrument.regions) {
73.1027 + for (DLSModulator modulator : region.getModulators()) {
73.1028 + if (modulator.version == 1)
73.1029 + art1_count++;
73.1030 + if (modulator.version == 2)
73.1031 + art2_count++;
73.1032 + }
73.1033 + }
73.1034 +
73.1035 + int version = 1;
73.1036 + if (art2_count > 0)
73.1037 + version = 2;
73.1038 +
73.1039 + RIFFWriter insh_chunk = writer.writeChunk("insh");
73.1040 + insh_chunk.writeUnsignedInt(instrument.getRegions().size());
73.1041 + insh_chunk.writeUnsignedInt(instrument.bank +
73.1042 + (instrument.druminstrument ? 2147483648L : 0));
73.1043 + insh_chunk.writeUnsignedInt(instrument.preset);
73.1044 +
73.1045 + RIFFWriter lrgn = writer.writeList("lrgn");
73.1046 + for (DLSRegion region: instrument.regions)
73.1047 + writeRegion(lrgn, region, version);
73.1048 +
73.1049 + writeArticulators(writer, instrument.getModulators());
73.1050 +
73.1051 + writeInfo(writer.writeList("INFO"), instrument.info);
73.1052 +
73.1053 + }
73.1054 +
73.1055 + private void writeArticulators(RIFFWriter writer,
73.1056 + List<DLSModulator> modulators) throws IOException {
73.1057 + int art1_count = 0;
73.1058 + int art2_count = 0;
73.1059 + for (DLSModulator modulator : modulators) {
73.1060 + if (modulator.version == 1)
73.1061 + art1_count++;
73.1062 + if (modulator.version == 2)
73.1063 + art2_count++;
73.1064 + }
73.1065 + if (art1_count > 0) {
73.1066 + RIFFWriter lar1 = writer.writeList("lart");
73.1067 + RIFFWriter art1 = lar1.writeChunk("art1");
73.1068 + art1.writeUnsignedInt(8);
73.1069 + art1.writeUnsignedInt(art1_count);
73.1070 + for (DLSModulator modulator : modulators) {
73.1071 + if (modulator.version == 1) {
73.1072 + art1.writeUnsignedShort(modulator.source);
73.1073 + art1.writeUnsignedShort(modulator.control);
73.1074 + art1.writeUnsignedShort(modulator.destination);
73.1075 + art1.writeUnsignedShort(modulator.transform);
73.1076 + art1.writeInt(modulator.scale);
73.1077 + }
73.1078 + }
73.1079 + }
73.1080 + if (art2_count > 0) {
73.1081 + RIFFWriter lar2 = writer.writeList("lar2");
73.1082 + RIFFWriter art2 = lar2.writeChunk("art2");
73.1083 + art2.writeUnsignedInt(8);
73.1084 + art2.writeUnsignedInt(art2_count);
73.1085 + for (DLSModulator modulator : modulators) {
73.1086 + if (modulator.version == 2) {
73.1087 + art2.writeUnsignedShort(modulator.source);
73.1088 + art2.writeUnsignedShort(modulator.control);
73.1089 + art2.writeUnsignedShort(modulator.destination);
73.1090 + art2.writeUnsignedShort(modulator.transform);
73.1091 + art2.writeInt(modulator.scale);
73.1092 + }
73.1093 + }
73.1094 + }
73.1095 + }
73.1096 +
73.1097 + private void writeRegion(RIFFWriter writer, DLSRegion region, int version)
73.1098 + throws IOException {
73.1099 + RIFFWriter rgns = null;
73.1100 + if (version == 1)
73.1101 + rgns = writer.writeList("rgn ");
73.1102 + if (version == 2)
73.1103 + rgns = writer.writeList("rgn2");
73.1104 + if (rgns == null)
73.1105 + return;
73.1106 +
73.1107 + RIFFWriter rgnh = rgns.writeChunk("rgnh");
73.1108 + rgnh.writeUnsignedShort(region.keyfrom);
73.1109 + rgnh.writeUnsignedShort(region.keyto);
73.1110 + rgnh.writeUnsignedShort(region.velfrom);
73.1111 + rgnh.writeUnsignedShort(region.velto);
73.1112 + rgnh.writeUnsignedShort(region.options);
73.1113 + rgnh.writeUnsignedShort(region.exclusiveClass);
73.1114 +
73.1115 + if (region.sampleoptions != null)
73.1116 + writeSampleOptions(rgns.writeChunk("wsmp"), region.sampleoptions);
73.1117 +
73.1118 + if (region.sample != null) {
73.1119 + if (samples.indexOf(region.sample) != -1) {
73.1120 + RIFFWriter wlnk = rgns.writeChunk("wlnk");
73.1121 + wlnk.writeUnsignedShort(region.fusoptions);
73.1122 + wlnk.writeUnsignedShort(region.phasegroup);
73.1123 + wlnk.writeUnsignedInt(region.channel);
73.1124 + wlnk.writeUnsignedInt(samples.indexOf(region.sample));
73.1125 + }
73.1126 + }
73.1127 + writeArticulators(rgns, region.getModulators());
73.1128 + rgns.close();
73.1129 + }
73.1130 +
73.1131 + private void writeSampleOptions(RIFFWriter wsmp,
73.1132 + DLSSampleOptions sampleoptions) throws IOException {
73.1133 + wsmp.writeUnsignedInt(20);
73.1134 + wsmp.writeUnsignedShort(sampleoptions.unitynote);
73.1135 + wsmp.writeShort(sampleoptions.finetune);
73.1136 + wsmp.writeInt(sampleoptions.attenuation);
73.1137 + wsmp.writeUnsignedInt(sampleoptions.options);
73.1138 + wsmp.writeInt(sampleoptions.loops.size());
73.1139 +
73.1140 + for (DLSSampleLoop loop : sampleoptions.loops) {
73.1141 + wsmp.writeUnsignedInt(16);
73.1142 + wsmp.writeUnsignedInt(loop.type);
73.1143 + wsmp.writeUnsignedInt(loop.start);
73.1144 + wsmp.writeUnsignedInt(loop.length);
73.1145 + }
73.1146 + }
73.1147 +
73.1148 + private void writeInfoStringChunk(RIFFWriter writer,
73.1149 + String name, String value) throws IOException {
73.1150 + if (value == null)
73.1151 + return;
73.1152 + RIFFWriter chunk = writer.writeChunk(name);
73.1153 + chunk.writeString(value);
73.1154 + int len = value.getBytes("ascii").length;
73.1155 + chunk.write(0);
73.1156 + len++;
73.1157 + if (len % 2 != 0)
73.1158 + chunk.write(0);
73.1159 + }
73.1160 +
73.1161 + private void writeInfo(RIFFWriter writer, DLSInfo info) throws IOException {
73.1162 + writeInfoStringChunk(writer, "INAM", info.name);
73.1163 + writeInfoStringChunk(writer, "ICRD", info.creationDate);
73.1164 + writeInfoStringChunk(writer, "IENG", info.engineers);
73.1165 + writeInfoStringChunk(writer, "IPRD", info.product);
73.1166 + writeInfoStringChunk(writer, "ICOP", info.copyright);
73.1167 + writeInfoStringChunk(writer, "ICMT", info.comments);
73.1168 + writeInfoStringChunk(writer, "ISFT", info.tools);
73.1169 + writeInfoStringChunk(writer, "IARL", info.archival_location);
73.1170 + writeInfoStringChunk(writer, "IART", info.artist);
73.1171 + writeInfoStringChunk(writer, "ICMS", info.commissioned);
73.1172 + writeInfoStringChunk(writer, "IGNR", info.genre);
73.1173 + writeInfoStringChunk(writer, "IKEY", info.keywords);
73.1174 + writeInfoStringChunk(writer, "IMED", info.medium);
73.1175 + writeInfoStringChunk(writer, "ISBJ", info.subject);
73.1176 + writeInfoStringChunk(writer, "ISRC", info.source);
73.1177 + writeInfoStringChunk(writer, "ISRF", info.source_form);
73.1178 + writeInfoStringChunk(writer, "ITCH", info.technician);
73.1179 + }
73.1180 +
73.1181 + public DLSInfo getInfo() {
73.1182 + return info;
73.1183 + }
73.1184 +
73.1185 + public String getName() {
73.1186 + return info.name;
73.1187 + }
73.1188 +
73.1189 + public String getVersion() {
73.1190 + return major + "." + minor;
73.1191 + }
73.1192 +
73.1193 + public String getVendor() {
73.1194 + return info.engineers;
73.1195 + }
73.1196 +
73.1197 + public String getDescription() {
73.1198 + return info.comments;
73.1199 + }
73.1200 +
73.1201 + public void setName(String s) {
73.1202 + info.name = s;
73.1203 + }
73.1204 +
73.1205 + public void setVendor(String s) {
73.1206 + info.engineers = s;
73.1207 + }
73.1208 +
73.1209 + public void setDescription(String s) {
73.1210 + info.comments = s;
73.1211 + }
73.1212 +
73.1213 + public SoundbankResource[] getResources() {
73.1214 + SoundbankResource[] resources = new SoundbankResource[samples.size()];
73.1215 + int j = 0;
73.1216 + for (int i = 0; i < samples.size(); i++)
73.1217 + resources[j++] = samples.get(i);
73.1218 + return resources;
73.1219 + }
73.1220 +
73.1221 + public DLSInstrument[] getInstruments() {
73.1222 + DLSInstrument[] inslist_array =
73.1223 + instruments.toArray(new DLSInstrument[instruments.size()]);
73.1224 + Arrays.sort(inslist_array, new ModelInstrumentComparator());
73.1225 + return inslist_array;
73.1226 + }
73.1227 +
73.1228 + public DLSSample[] getSamples() {
73.1229 + return samples.toArray(new DLSSample[samples.size()]);
73.1230 + }
73.1231 +
73.1232 + public Instrument getInstrument(Patch patch) {
73.1233 + int program = patch.getProgram();
73.1234 + int bank = patch.getBank();
73.1235 + boolean percussion = false;
73.1236 + if (patch instanceof ModelPatch)
73.1237 + percussion = ((ModelPatch) patch).isPercussion();
73.1238 + for (Instrument instrument : instruments) {
73.1239 + Patch patch2 = instrument.getPatch();
73.1240 + int program2 = patch2.getProgram();
73.1241 + int bank2 = patch2.getBank();
73.1242 + if (program == program2 && bank == bank2) {
73.1243 + boolean percussion2 = false;
73.1244 + if (patch2 instanceof ModelPatch)
73.1245 + percussion2 = ((ModelPatch) patch2).isPercussion();
73.1246 + if (percussion == percussion2)
73.1247 + return instrument;
73.1248 + }
73.1249 + }
73.1250 + return null;
73.1251 + }
73.1252 +
73.1253 + public void addResource(SoundbankResource resource) {
73.1254 + if (resource instanceof DLSInstrument)
73.1255 + instruments.add((DLSInstrument) resource);
73.1256 + if (resource instanceof DLSSample)
73.1257 + samples.add((DLSSample) resource);
73.1258 + }
73.1259 +
73.1260 + public void removeResource(SoundbankResource resource) {
73.1261 + if (resource instanceof DLSInstrument)
73.1262 + instruments.remove((DLSInstrument) resource);
73.1263 + if (resource instanceof DLSSample)
73.1264 + samples.remove((DLSSample) resource);
73.1265 + }
73.1266 +
73.1267 + public void addInstrument(DLSInstrument resource) {
73.1268 + instruments.add(resource);
73.1269 + }
73.1270 +
73.1271 + public void removeInstrument(DLSInstrument resource) {
73.1272 + instruments.remove(resource);
73.1273 + }
73.1274 +
73.1275 + public long getMajor() {
73.1276 + return major;
73.1277 + }
73.1278 +
73.1279 + public void setMajor(long major) {
73.1280 + this.major = major;
73.1281 + }
73.1282 +
73.1283 + public long getMinor() {
73.1284 + return minor;
73.1285 + }
73.1286 +
73.1287 + public void setMinor(long minor) {
73.1288 + this.minor = minor;
73.1289 + }
73.1290 +}
74.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
74.2 +++ b/src/share/classes/com/sun/media/sound/DLSSoundbankReader.java Tue Feb 03 22:02:55 2009 -0800
74.3 @@ -0,0 +1,74 @@
74.4 +/*
74.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
74.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
74.7 + *
74.8 + * This code is free software; you can redistribute it and/or modify it
74.9 + * under the terms of the GNU General Public License version 2 only, as
74.10 + * published by the Free Software Foundation. Sun designates this
74.11 + * particular file as subject to the "Classpath" exception as provided
74.12 + * by Sun in the LICENSE file that accompanied this code.
74.13 + *
74.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
74.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
74.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
74.17 + * version 2 for more details (a copy is included in the LICENSE file that
74.18 + * accompanied this code).
74.19 + *
74.20 + * You should have received a copy of the GNU General Public License version
74.21 + * 2 along with this work; if not, write to the Free Software Foundation,
74.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
74.23 + *
74.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
74.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
74.26 + * have any questions.
74.27 + */
74.28 +
74.29 +package com.sun.media.sound;
74.30 +
74.31 +import java.io.File;
74.32 +import java.io.IOException;
74.33 +import java.io.InputStream;
74.34 +import java.net.URL;
74.35 +import javax.sound.midi.InvalidMidiDataException;
74.36 +import javax.sound.midi.Soundbank;
74.37 +import javax.sound.midi.spi.SoundbankReader;
74.38 +
74.39 +/**
74.40 + * This class is used to connect the DLSSoundBank class
74.41 + * to the SoundbankReader SPI interface.
74.42 + *
74.43 + * @author Karl Helgason
74.44 + */
74.45 +public class DLSSoundbankReader extends SoundbankReader {
74.46 +
74.47 + public Soundbank getSoundbank(URL url)
74.48 + throws InvalidMidiDataException, IOException {
74.49 + try {
74.50 + return new DLSSoundbank(url);
74.51 + } catch (RIFFInvalidFormatException e) {
74.52 + return null;
74.53 + } catch(IOException ioe) {
74.54 + return null;
74.55 + }
74.56 + }
74.57 +
74.58 + public Soundbank getSoundbank(InputStream stream)
74.59 + throws InvalidMidiDataException, IOException {
74.60 + try {
74.61 + stream.mark(512);
74.62 + return new DLSSoundbank(stream);
74.63 + } catch (RIFFInvalidFormatException e) {
74.64 + stream.reset();
74.65 + return null;
74.66 + }
74.67 + }
74.68 +
74.69 + public Soundbank getSoundbank(File file)
74.70 + throws InvalidMidiDataException, IOException {
74.71 + try {
74.72 + return new DLSSoundbank(file);
74.73 + } catch (RIFFInvalidFormatException e) {
74.74 + return null;
74.75 + }
74.76 + }
74.77 +}
75.1 --- a/src/share/classes/com/sun/media/sound/DirectAudioDevice.java Thu Jan 29 21:46:48 2009 -0800
75.2 +++ b/src/share/classes/com/sun/media/sound/DirectAudioDevice.java Tue Feb 03 22:02:55 2009 -0800
75.3 @@ -394,7 +394,12 @@
75.4 private float leftGain, rightGain;
75.5 protected volatile boolean noService = false; // do not run the nService method
75.6
75.7 + // Guards all native calls.
75.8 protected Object lockNative = new Object();
75.9 + // Guards the lastOpened static variable in implOpen and implClose.
75.10 + protected static Object lockLast = new Object();
75.11 + // Keeps track of last opened line, see implOpen "trick".
75.12 + protected static DirectDL lastOpened;
75.13
75.14 // CONSTRUCTOR
75.15 protected DirectDL(DataLine.Info info,
75.16 @@ -496,20 +501,50 @@
75.17 // align buffer to full frames
75.18 bufferSize = ((int) bufferSize / format.getFrameSize()) * format.getFrameSize();
75.19
75.20 - id = nOpen(mixerIndex, deviceID, isSource,
75.21 - encoding,
75.22 - hardwareFormat.getSampleRate(),
75.23 - hardwareFormat.getSampleSizeInBits(),
75.24 - hardwareFormat.getFrameSize(),
75.25 - hardwareFormat.getChannels(),
75.26 - hardwareFormat.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED),
75.27 - hardwareFormat.isBigEndian(),
75.28 - bufferSize);
75.29 + synchronized(lockLast) {
75.30 + id = nOpen(mixerIndex, deviceID, isSource,
75.31 + encoding,
75.32 + hardwareFormat.getSampleRate(),
75.33 + hardwareFormat.getSampleSizeInBits(),
75.34 + hardwareFormat.getFrameSize(),
75.35 + hardwareFormat.getChannels(),
75.36 + hardwareFormat.getEncoding().equals(
75.37 + AudioFormat.Encoding.PCM_SIGNED),
75.38 + hardwareFormat.isBigEndian(),
75.39 + bufferSize);
75.40
75.41 - if (id == 0) {
75.42 - // TODO: nicer error messages...
75.43 - throw new LineUnavailableException("line with format "+format+" not supported.");
75.44 + if (id == 0) {
75.45 + // Bah... Dirty trick. The most likely cause is an application
75.46 + // already having a line open for this particular hardware
75.47 + // format and forgetting about it. If so, silently close that
75.48 + // implementation and try again. Unfortuantely we can only
75.49 + // open one line per hardware format currently.
75.50 + if (lastOpened != null
75.51 + && hardwareFormat.matches(lastOpened.hardwareFormat)) {
75.52 + lastOpened.implClose();
75.53 + lastOpened = null;
75.54 +
75.55 + id = nOpen(mixerIndex, deviceID, isSource,
75.56 + encoding,
75.57 + hardwareFormat.getSampleRate(),
75.58 + hardwareFormat.getSampleSizeInBits(),
75.59 + hardwareFormat.getFrameSize(),
75.60 + hardwareFormat.getChannels(),
75.61 + hardwareFormat.getEncoding().equals(
75.62 + AudioFormat.Encoding.PCM_SIGNED),
75.63 + hardwareFormat.isBigEndian(),
75.64 + bufferSize);
75.65 + }
75.66 +
75.67 + if (id == 0) {
75.68 + // TODO: nicer error messages...
75.69 + throw new LineUnavailableException(
75.70 + "line with format "+format+" not supported.");
75.71 + }
75.72 + }
75.73 + lastOpened = this;
75.74 }
75.75 +
75.76 this.bufferSize = nGetBufferSize(id, isSource);
75.77 if (this.bufferSize < 1) {
75.78 // this is an error!
75.79 @@ -580,12 +615,12 @@
75.80 }
75.81 synchronized (lockNative) {
75.82 nStop(id, isSource);
75.83 +
75.84 + // need to set doIO to false before notifying the
75.85 + // read/write thread, that's why isStartedRunning()
75.86 + // cannot be used
75.87 + doIO = false;
75.88 }
75.89 -
75.90 - // need to set doIO to false before notifying the
75.91 - // read/write thread, that's why isStartedRunning()
75.92 - // cannot be used
75.93 - doIO = false;
75.94 // wake up any waiting threads
75.95 synchronized(lock) {
75.96 lock.notifyAll();
75.97 @@ -614,8 +649,12 @@
75.98 doIO = false;
75.99 long oldID = id;
75.100 id = 0;
75.101 - synchronized (lockNative) {
75.102 - nClose(oldID, isSource);
75.103 + synchronized (lockLast) {
75.104 + synchronized (lockNative) {
75.105 + nClose(oldID, isSource);
75.106 + if (lastOpened == this)
75.107 + lastOpened = null;
75.108 + }
75.109 }
75.110 bytePosition = 0;
75.111 softwareConversionSize = 0;
75.112 @@ -630,7 +669,8 @@
75.113 }
75.114 int a = 0;
75.115 synchronized (lockNative) {
75.116 - a = nAvailable(id, isSource);
75.117 + if (doIO)
75.118 + a = nAvailable(id, isSource);
75.119 }
75.120 return a;
75.121 }
75.122 @@ -644,9 +684,9 @@
75.123 int counter = 0;
75.124 long startPos = getLongFramePosition();
75.125 boolean posChanged = false;
75.126 - while (!drained && doIO) {
75.127 + while (!drained) {
75.128 synchronized (lockNative) {
75.129 - if ((id == 0) || !nIsStillDraining(id, isSource))
75.130 + if ((id == 0) || (!doIO) || !nIsStillDraining(id, isSource))
75.131 break;
75.132 }
75.133 // check every now and then for a new position
75.134 @@ -686,7 +726,7 @@
75.135 lock.notifyAll();
75.136 }
75.137 synchronized (lockNative) {
75.138 - if (id != 0) {
75.139 + if (id != 0 && doIO) {
75.140 // then flush native buffers
75.141 nFlush(id, isSource);
75.142 }
75.143 @@ -697,9 +737,10 @@
75.144
75.145 // replacement for getFramePosition (see AbstractDataLine)
75.146 public long getLongFramePosition() {
75.147 - long pos;
75.148 + long pos = 0;
75.149 synchronized (lockNative) {
75.150 - pos = nGetBytePosition(id, isSource, bytePosition);
75.151 + if (doIO)
75.152 + pos = nGetBytePosition(id, isSource, bytePosition);
75.153 }
75.154 // hack because ALSA sometimes reports wrong framepos
75.155 if (pos < 0) {
75.156 @@ -745,11 +786,12 @@
75.157 }
75.158 int written = 0;
75.159 while (!flushing) {
75.160 - int thisWritten;
75.161 + int thisWritten = 0;
75.162 synchronized (lockNative) {
75.163 - thisWritten = nWrite(id, b, off, len,
75.164 - softwareConversionSize,
75.165 - leftGain, rightGain);
75.166 + if (doIO)
75.167 + thisWritten = nWrite(id, b, off, len,
75.168 + softwareConversionSize,
75.169 + leftGain, rightGain);
75.170 if (thisWritten < 0) {
75.171 // error in native layer
75.172 break;
75.173 @@ -972,9 +1014,10 @@
75.174 }
75.175 int read = 0;
75.176 while (doIO && !flushing) {
75.177 - int thisRead;
75.178 + int thisRead = 0;
75.179 synchronized (lockNative) {
75.180 - thisRead = nRead(id, b, off, len, softwareConversionSize);
75.181 + if (doIO)
75.182 + thisRead = nRead(id, b, off, len, softwareConversionSize);
75.183 if (thisRead < 0) {
75.184 // error in native layer
75.185 break;
75.186 @@ -1209,7 +1252,8 @@
75.187 // set new native position (if necessary)
75.188 // this must come after the flush!
75.189 synchronized (lockNative) {
75.190 - nSetBytePosition(id, isSource, frames * frameSize);
75.191 + if (doIO)
75.192 + nSetBytePosition(id, isSource, frames * frameSize);
75.193 }
75.194
75.195 if (Printer.debug) Printer.debug(" DirectClip.setFramePosition: "
76.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
76.2 +++ b/src/share/classes/com/sun/media/sound/EmergencySoundbank.java Tue Feb 03 22:02:55 2009 -0800
76.3 @@ -0,0 +1,2695 @@
76.4 +/*
76.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
76.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
76.7 + *
76.8 + * This code is free software; you can redistribute it and/or modify it
76.9 + * under the terms of the GNU General Public License version 2 only, as
76.10 + * published by the Free Software Foundation. Sun designates this
76.11 + * particular file as subject to the "Classpath" exception as provided
76.12 + * by Sun in the LICENSE file that accompanied this code.
76.13 + *
76.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
76.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
76.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
76.17 + * version 2 for more details (a copy is included in the LICENSE file that
76.18 + * accompanied this code).
76.19 + *
76.20 + * You should have received a copy of the GNU General Public License version
76.21 + * 2 along with this work; if not, write to the Free Software Foundation,
76.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
76.23 + *
76.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
76.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
76.26 + * have any questions.
76.27 + */
76.28 +package com.sun.media.sound;
76.29 +
76.30 +import java.util.Random;
76.31 +
76.32 +import javax.sound.midi.Patch;
76.33 +import javax.sound.sampled.AudioFormat;
76.34 +
76.35 +/**
76.36 + * Emergency Soundbank generator.
76.37 + * Used when no other default soundbank can be found.
76.38 + *
76.39 + * @author Karl Helgason
76.40 + */
76.41 +public class EmergencySoundbank {
76.42 +
76.43 + private final static String[] general_midi_instruments = {
76.44 + "Acoustic Grand Piano",
76.45 + "Bright Acoustic Piano",
76.46 + "Electric Grand Piano",
76.47 + "Honky-tonk Piano",
76.48 + "Electric Piano 1",
76.49 + "Electric Piano 2",
76.50 + "Harpsichord",
76.51 + "Clavi",
76.52 + "Celesta",
76.53 + "Glockenspiel",
76.54 + "Music Box",
76.55 + "Vibraphone",
76.56 + "Marimba",
76.57 + "Xylophone",
76.58 + "Tubular Bells",
76.59 + "Dulcimer",
76.60 + "Drawbar Organ",
76.61 + "Percussive Organ",
76.62 + "Rock Organ",
76.63 + "Church Organ",
76.64 + "Reed Organ",
76.65 + "Accordion",
76.66 + "Harmonica",
76.67 + "Tango Accordion",
76.68 + "Acoustic Guitar (nylon)",
76.69 + "Acoustic Guitar (steel)",
76.70 + "Electric Guitar (jazz)",
76.71 + "Electric Guitar (clean)",
76.72 + "Electric Guitar (muted)",
76.73 + "Overdriven Guitar",
76.74 + "Distortion Guitar",
76.75 + "Guitar harmonics",
76.76 + "Acoustic Bass",
76.77 + "Electric Bass (finger)",
76.78 + "Electric Bass (pick)",
76.79 + "Fretless Bass",
76.80 + "Slap Bass 1",
76.81 + "Slap Bass 2",
76.82 + "Synth Bass 1",
76.83 + "Synth Bass 2",
76.84 + "Violin",
76.85 + "Viola",
76.86 + "Cello",
76.87 + "Contrabass",
76.88 + "Tremolo Strings",
76.89 + "Pizzicato Strings",
76.90 + "Orchestral Harp",
76.91 + "Timpani",
76.92 + "String Ensemble 1",
76.93 + "String Ensemble 2",
76.94 + "SynthStrings 1",
76.95 + "SynthStrings 2",
76.96 + "Choir Aahs",
76.97 + "Voice Oohs",
76.98 + "Synth Voice",
76.99 + "Orchestra Hit",
76.100 + "Trumpet",
76.101 + "Trombone",
76.102 + "Tuba",
76.103 + "Muted Trumpet",
76.104 + "French Horn",
76.105 + "Brass Section",
76.106 + "SynthBrass 1",
76.107 + "SynthBrass 2",
76.108 + "Soprano Sax",
76.109 + "Alto Sax",
76.110 + "Tenor Sax",
76.111 + "Baritone Sax",
76.112 + "Oboe",
76.113 + "English Horn",
76.114 + "Bassoon",
76.115 + "Clarinet",
76.116 + "Piccolo",
76.117 + "Flute",
76.118 + "Recorder",
76.119 + "Pan Flute",
76.120 + "Blown Bottle",
76.121 + "Shakuhachi",
76.122 + "Whistle",
76.123 + "Ocarina",
76.124 + "Lead 1 (square)",
76.125 + "Lead 2 (sawtooth)",
76.126 + "Lead 3 (calliope)",
76.127 + "Lead 4 (chiff)",
76.128 + "Lead 5 (charang)",
76.129 + "Lead 6 (voice)",
76.130 + "Lead 7 (fifths)",
76.131 + "Lead 8 (bass + lead)",
76.132 + "Pad 1 (new age)",
76.133 + "Pad 2 (warm)",
76.134 + "Pad 3 (polysynth)",
76.135 + "Pad 4 (choir)",
76.136 + "Pad 5 (bowed)",
76.137 + "Pad 6 (metallic)",
76.138 + "Pad 7 (halo)",
76.139 + "Pad 8 (sweep)",
76.140 + "FX 1 (rain)",
76.141 + "FX 2 (soundtrack)",
76.142 + "FX 3 (crystal)",
76.143 + "FX 4 (atmosphere)",
76.144 + "FX 5 (brightness)",
76.145 + "FX 6 (goblins)",
76.146 + "FX 7 (echoes)",
76.147 + "FX 8 (sci-fi)",
76.148 + "Sitar",
76.149 + "Banjo",
76.150 + "Shamisen",
76.151 + "Koto",
76.152 + "Kalimba",
76.153 + "Bag pipe",
76.154 + "Fiddle",
76.155 + "Shanai",
76.156 + "Tinkle Bell",
76.157 + "Agogo",
76.158 + "Steel Drums",
76.159 + "Woodblock",
76.160 + "Taiko Drum",
76.161 + "Melodic Tom",
76.162 + "Synth Drum",
76.163 + "Reverse Cymbal",
76.164 + "Guitar Fret Noise",
76.165 + "Breath Noise",
76.166 + "Seashore",
76.167 + "Bird Tweet",
76.168 + "Telephone Ring",
76.169 + "Helicopter",
76.170 + "Applause",
76.171 + "Gunshot"
76.172 + };
76.173 +
76.174 + public static SF2Soundbank createSoundbank() throws Exception {
76.175 + SF2Soundbank sf2 = new SF2Soundbank();
76.176 + sf2.setName("Emergency GM sound set");
76.177 + sf2.setVendor("Generated");
76.178 + sf2.setDescription("Emergency generated soundbank");
76.179 +
76.180 + /*
76.181 + * percussion instruments
76.182 + */
76.183 +
76.184 + SF2Layer bass_drum = new_bass_drum(sf2);
76.185 + SF2Layer snare_drum = new_snare_drum(sf2);
76.186 + SF2Layer tom = new_tom(sf2);
76.187 + SF2Layer open_hihat = new_open_hihat(sf2);
76.188 + SF2Layer closed_hihat = new_closed_hihat(sf2);
76.189 + SF2Layer crash_cymbal = new_crash_cymbal(sf2);
76.190 + SF2Layer side_stick = new_side_stick(sf2);
76.191 +
76.192 + SF2Layer[] drums = new SF2Layer[128];
76.193 + drums[35] = bass_drum;
76.194 + drums[36] = bass_drum;
76.195 + drums[38] = snare_drum;
76.196 + drums[40] = snare_drum;
76.197 + drums[41] = tom;
76.198 + drums[43] = tom;
76.199 + drums[45] = tom;
76.200 + drums[47] = tom;
76.201 + drums[48] = tom;
76.202 + drums[50] = tom;
76.203 + drums[42] = closed_hihat;
76.204 + drums[44] = closed_hihat;
76.205 + drums[46] = open_hihat;
76.206 + drums[49] = crash_cymbal;
76.207 + drums[51] = crash_cymbal;
76.208 + drums[52] = crash_cymbal;
76.209 + drums[55] = crash_cymbal;
76.210 + drums[57] = crash_cymbal;
76.211 + drums[59] = crash_cymbal;
76.212 +
76.213 + // Use side_stick for missing drums:
76.214 + drums[37] = side_stick;
76.215 + drums[39] = side_stick;
76.216 + drums[53] = side_stick;
76.217 + drums[54] = side_stick;
76.218 + drums[56] = side_stick;
76.219 + drums[58] = side_stick;
76.220 + drums[69] = side_stick;
76.221 + drums[70] = side_stick;
76.222 + drums[75] = side_stick;
76.223 + drums[60] = side_stick;
76.224 + drums[61] = side_stick;
76.225 + drums[62] = side_stick;
76.226 + drums[63] = side_stick;
76.227 + drums[64] = side_stick;
76.228 + drums[65] = side_stick;
76.229 + drums[66] = side_stick;
76.230 + drums[67] = side_stick;
76.231 + drums[68] = side_stick;
76.232 + drums[71] = side_stick;
76.233 + drums[72] = side_stick;
76.234 + drums[73] = side_stick;
76.235 + drums[74] = side_stick;
76.236 + drums[76] = side_stick;
76.237 + drums[77] = side_stick;
76.238 + drums[78] = side_stick;
76.239 + drums[79] = side_stick;
76.240 + drums[80] = side_stick;
76.241 + drums[81] = side_stick;
76.242 +
76.243 +
76.244 + SF2Instrument drum_instrument = new SF2Instrument(sf2);
76.245 + drum_instrument.setName("Standard Kit");
76.246 + drum_instrument.setPatch(new ModelPatch(0, 0, true));
76.247 + sf2.addInstrument(drum_instrument);
76.248 + for (int i = 0; i < drums.length; i++) {
76.249 + if (drums[i] != null) {
76.250 + SF2InstrumentRegion region = new SF2InstrumentRegion();
76.251 + region.setLayer(drums[i]);
76.252 + region.putBytes(SF2InstrumentRegion.GENERATOR_KEYRANGE,
76.253 + new byte[]{(byte) i, (byte) i});
76.254 + drum_instrument.getRegions().add(region);
76.255 + }
76.256 + }
76.257 +
76.258 +
76.259 + /*
76.260 + * melodic instruments
76.261 + */
76.262 +
76.263 + SF2Layer gpiano = new_gpiano(sf2);
76.264 + SF2Layer gpiano2 = new_gpiano2(sf2);
76.265 + SF2Layer gpiano_hammer = new_piano_hammer(sf2);
76.266 + SF2Layer piano1 = new_piano1(sf2);
76.267 + SF2Layer epiano1 = new_epiano1(sf2);
76.268 + SF2Layer epiano2 = new_epiano2(sf2);
76.269 +
76.270 + SF2Layer guitar = new_guitar1(sf2);
76.271 + SF2Layer guitar_pick = new_guitar_pick(sf2);
76.272 + SF2Layer guitar_dist = new_guitar_dist(sf2);
76.273 + SF2Layer bass1 = new_bass1(sf2);
76.274 + SF2Layer bass2 = new_bass2(sf2);
76.275 + SF2Layer synthbass = new_synthbass(sf2);
76.276 + SF2Layer string2 = new_string2(sf2);
76.277 + SF2Layer orchhit = new_orchhit(sf2);
76.278 + SF2Layer choir = new_choir(sf2);
76.279 + SF2Layer solostring = new_solostring(sf2);
76.280 + SF2Layer organ = new_organ(sf2);
76.281 + SF2Layer ch_organ = new_ch_organ(sf2);
76.282 + SF2Layer bell = new_bell(sf2);
76.283 + SF2Layer flute = new_flute(sf2);
76.284 +
76.285 + SF2Layer timpani = new_timpani(sf2);
76.286 + SF2Layer melodic_toms = new_melodic_toms(sf2);
76.287 + SF2Layer trumpet = new_trumpet(sf2);
76.288 + SF2Layer trombone = new_trombone(sf2);
76.289 + SF2Layer brass_section = new_brass_section(sf2);
76.290 + SF2Layer horn = new_horn(sf2);
76.291 + SF2Layer sax = new_sax(sf2);
76.292 + SF2Layer oboe = new_oboe(sf2);
76.293 + SF2Layer bassoon = new_bassoon(sf2);
76.294 + SF2Layer clarinet = new_clarinet(sf2);
76.295 + SF2Layer reverse_cymbal = new_reverse_cymbal(sf2);
76.296 +
76.297 + SF2Layer defaultsound = piano1;
76.298 +
76.299 + newInstrument(sf2, "Piano", new Patch(0, 0), gpiano, gpiano_hammer);
76.300 + newInstrument(sf2, "Piano", new Patch(0, 1), gpiano2, gpiano_hammer);
76.301 + newInstrument(sf2, "Piano", new Patch(0, 2), piano1);
76.302 + {
76.303 + SF2Instrument ins = newInstrument(sf2, "Honky-tonk Piano",
76.304 + new Patch(0, 3), piano1, piano1);
76.305 + SF2InstrumentRegion region = ins.getRegions().get(0);
76.306 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 80);
76.307 + region.putInteger(SF2Region.GENERATOR_FINETUNE, 30);
76.308 + region = ins.getRegions().get(1);
76.309 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 30);
76.310 + }
76.311 + newInstrument(sf2, "Rhodes", new Patch(0, 4), epiano2);
76.312 + newInstrument(sf2, "Rhodes", new Patch(0, 5), epiano2);
76.313 + newInstrument(sf2, "Clavinet", new Patch(0, 6), epiano1);
76.314 + newInstrument(sf2, "Clavinet", new Patch(0, 7), epiano1);
76.315 + newInstrument(sf2, "Rhodes", new Patch(0, 8), epiano2);
76.316 + newInstrument(sf2, "Bell", new Patch(0, 9), bell);
76.317 + newInstrument(sf2, "Bell", new Patch(0, 10), bell);
76.318 + newInstrument(sf2, "Vibraphone", new Patch(0, 11), bell);
76.319 + newInstrument(sf2, "Marimba", new Patch(0, 12), bell);
76.320 + newInstrument(sf2, "Marimba", new Patch(0, 13), bell);
76.321 + newInstrument(sf2, "Bell", new Patch(0, 14), bell);
76.322 + newInstrument(sf2, "Rock Organ", new Patch(0, 15), organ);
76.323 + newInstrument(sf2, "Rock Organ", new Patch(0, 16), organ);
76.324 + newInstrument(sf2, "Perc Organ", new Patch(0, 17), organ);
76.325 + newInstrument(sf2, "Rock Organ", new Patch(0, 18), organ);
76.326 + newInstrument(sf2, "Church Organ", new Patch(0, 19), ch_organ);
76.327 + newInstrument(sf2, "Accordion", new Patch(0, 20), organ);
76.328 + newInstrument(sf2, "Accordion", new Patch(0, 21), organ);
76.329 + newInstrument(sf2, "Accordion", new Patch(0, 22), organ);
76.330 + newInstrument(sf2, "Accordion", new Patch(0, 23), organ);
76.331 + newInstrument(sf2, "Guitar", new Patch(0, 24), guitar, guitar_pick);
76.332 + newInstrument(sf2, "Guitar", new Patch(0, 25), guitar, guitar_pick);
76.333 + newInstrument(sf2, "Guitar", new Patch(0, 26), guitar, guitar_pick);
76.334 + newInstrument(sf2, "Guitar", new Patch(0, 27), guitar, guitar_pick);
76.335 + newInstrument(sf2, "Guitar", new Patch(0, 28), guitar, guitar_pick);
76.336 + newInstrument(sf2, "Distorted Guitar", new Patch(0, 29), guitar_dist);
76.337 + newInstrument(sf2, "Distorted Guitar", new Patch(0, 30), guitar_dist);
76.338 + newInstrument(sf2, "Guitar", new Patch(0, 31), guitar, guitar_pick);
76.339 + newInstrument(sf2, "Finger Bass", new Patch(0, 32), bass1);
76.340 + newInstrument(sf2, "Finger Bass", new Patch(0, 33), bass1);
76.341 + newInstrument(sf2, "Finger Bass", new Patch(0, 34), bass1);
76.342 + newInstrument(sf2, "Frettless Bass", new Patch(0, 35), bass2);
76.343 + newInstrument(sf2, "Frettless Bass", new Patch(0, 36), bass2);
76.344 + newInstrument(sf2, "Frettless Bass", new Patch(0, 37), bass2);
76.345 + newInstrument(sf2, "Synth Bass1", new Patch(0, 38), synthbass);
76.346 + newInstrument(sf2, "Synth Bass2", new Patch(0, 39), synthbass);
76.347 + newInstrument(sf2, "Solo String", new Patch(0, 40), string2, solostring);
76.348 + newInstrument(sf2, "Solo String", new Patch(0, 41), string2, solostring);
76.349 + newInstrument(sf2, "Solo String", new Patch(0, 42), string2, solostring);
76.350 + newInstrument(sf2, "Solo String", new Patch(0, 43), string2, solostring);
76.351 + newInstrument(sf2, "Solo String", new Patch(0, 44), string2, solostring);
76.352 + newInstrument(sf2, "Def", new Patch(0, 45), defaultsound);
76.353 + newInstrument(sf2, "Harp", new Patch(0, 46), bell);
76.354 + newInstrument(sf2, "Timpani", new Patch(0, 47), timpani);
76.355 + newInstrument(sf2, "Strings", new Patch(0, 48), string2);
76.356 + SF2Instrument slow_strings =
76.357 + newInstrument(sf2, "Slow Strings", new Patch(0, 49), string2);
76.358 + SF2InstrumentRegion region = slow_strings.getRegions().get(0);
76.359 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, 2500);
76.360 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 2000);
76.361 + newInstrument(sf2, "Synth Strings", new Patch(0, 50), string2);
76.362 + newInstrument(sf2, "Synth Strings", new Patch(0, 51), string2);
76.363 +
76.364 +
76.365 + newInstrument(sf2, "Choir", new Patch(0, 52), choir);
76.366 + newInstrument(sf2, "Choir", new Patch(0, 53), choir);
76.367 + newInstrument(sf2, "Choir", new Patch(0, 54), choir);
76.368 + {
76.369 + SF2Instrument ins = newInstrument(sf2, "Orch Hit",
76.370 + new Patch(0, 55), orchhit, orchhit, timpani);
76.371 + region = ins.getRegions().get(0);
76.372 + region.putInteger(SF2Region.GENERATOR_COARSETUNE, -12);
76.373 + region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -100);
76.374 + }
76.375 + newInstrument(sf2, "Trumpet", new Patch(0, 56), trumpet);
76.376 + newInstrument(sf2, "Trombone", new Patch(0, 57), trombone);
76.377 + newInstrument(sf2, "Trombone", new Patch(0, 58), trombone);
76.378 + newInstrument(sf2, "Trumpet", new Patch(0, 59), trumpet);
76.379 + newInstrument(sf2, "Horn", new Patch(0, 60), horn);
76.380 + newInstrument(sf2, "Brass Section", new Patch(0, 61), brass_section);
76.381 + newInstrument(sf2, "Brass Section", new Patch(0, 62), brass_section);
76.382 + newInstrument(sf2, "Brass Section", new Patch(0, 63), brass_section);
76.383 + newInstrument(sf2, "Sax", new Patch(0, 64), sax);
76.384 + newInstrument(sf2, "Sax", new Patch(0, 65), sax);
76.385 + newInstrument(sf2, "Sax", new Patch(0, 66), sax);
76.386 + newInstrument(sf2, "Sax", new Patch(0, 67), sax);
76.387 + newInstrument(sf2, "Oboe", new Patch(0, 68), oboe);
76.388 + newInstrument(sf2, "Horn", new Patch(0, 69), horn);
76.389 + newInstrument(sf2, "Bassoon", new Patch(0, 70), bassoon);
76.390 + newInstrument(sf2, "Clarinet", new Patch(0, 71), clarinet);
76.391 + newInstrument(sf2, "Flute", new Patch(0, 72), flute);
76.392 + newInstrument(sf2, "Flute", new Patch(0, 73), flute);
76.393 + newInstrument(sf2, "Flute", new Patch(0, 74), flute);
76.394 + newInstrument(sf2, "Flute", new Patch(0, 75), flute);
76.395 + newInstrument(sf2, "Flute", new Patch(0, 76), flute);
76.396 + newInstrument(sf2, "Flute", new Patch(0, 77), flute);
76.397 + newInstrument(sf2, "Flute", new Patch(0, 78), flute);
76.398 + newInstrument(sf2, "Flute", new Patch(0, 79), flute);
76.399 + newInstrument(sf2, "Organ", new Patch(0, 80), organ);
76.400 + newInstrument(sf2, "Organ", new Patch(0, 81), organ);
76.401 + newInstrument(sf2, "Flute", new Patch(0, 82), flute);
76.402 + newInstrument(sf2, "Organ", new Patch(0, 83), organ);
76.403 + newInstrument(sf2, "Organ", new Patch(0, 84), organ);
76.404 + newInstrument(sf2, "Choir", new Patch(0, 85), choir);
76.405 + newInstrument(sf2, "Organ", new Patch(0, 86), organ);
76.406 + newInstrument(sf2, "Organ", new Patch(0, 87), organ);
76.407 + newInstrument(sf2, "Synth Strings", new Patch(0, 88), string2);
76.408 + newInstrument(sf2, "Organ", new Patch(0, 89), organ);
76.409 + newInstrument(sf2, "Def", new Patch(0, 90), defaultsound);
76.410 + newInstrument(sf2, "Choir", new Patch(0, 91), choir);
76.411 + newInstrument(sf2, "Organ", new Patch(0, 92), organ);
76.412 + newInstrument(sf2, "Organ", new Patch(0, 93), organ);
76.413 + newInstrument(sf2, "Organ", new Patch(0, 94), organ);
76.414 + newInstrument(sf2, "Organ", new Patch(0, 95), organ);
76.415 + newInstrument(sf2, "Organ", new Patch(0, 96), organ);
76.416 + newInstrument(sf2, "Organ", new Patch(0, 97), organ);
76.417 + newInstrument(sf2, "Bell", new Patch(0, 98), bell);
76.418 + newInstrument(sf2, "Organ", new Patch(0, 99), organ);
76.419 + newInstrument(sf2, "Organ", new Patch(0, 100), organ);
76.420 + newInstrument(sf2, "Organ", new Patch(0, 101), organ);
76.421 + newInstrument(sf2, "Def", new Patch(0, 102), defaultsound);
76.422 + newInstrument(sf2, "Synth Strings", new Patch(0, 103), string2);
76.423 + newInstrument(sf2, "Def", new Patch(0, 104), defaultsound);
76.424 + newInstrument(sf2, "Def", new Patch(0, 105), defaultsound);
76.425 + newInstrument(sf2, "Def", new Patch(0, 106), defaultsound);
76.426 + newInstrument(sf2, "Def", new Patch(0, 107), defaultsound);
76.427 + newInstrument(sf2, "Marimba", new Patch(0, 108), bell);
76.428 + newInstrument(sf2, "Sax", new Patch(0, 109), sax);
76.429 + newInstrument(sf2, "Solo String", new Patch(0, 110), string2, solostring);
76.430 + newInstrument(sf2, "Oboe", new Patch(0, 111), oboe);
76.431 + newInstrument(sf2, "Bell", new Patch(0, 112), bell);
76.432 + newInstrument(sf2, "Melodic Toms", new Patch(0, 113), melodic_toms);
76.433 + newInstrument(sf2, "Marimba", new Patch(0, 114), bell);
76.434 + newInstrument(sf2, "Melodic Toms", new Patch(0, 115), melodic_toms);
76.435 + newInstrument(sf2, "Melodic Toms", new Patch(0, 116), melodic_toms);
76.436 + newInstrument(sf2, "Melodic Toms", new Patch(0, 117), melodic_toms);
76.437 + newInstrument(sf2, "Reverse Cymbal", new Patch(0, 118), reverse_cymbal);
76.438 + newInstrument(sf2, "Reverse Cymbal", new Patch(0, 119), reverse_cymbal);
76.439 + newInstrument(sf2, "Guitar", new Patch(0, 120), guitar);
76.440 + newInstrument(sf2, "Def", new Patch(0, 121), defaultsound);
76.441 + {
76.442 + SF2Instrument ins = newInstrument(sf2, "Seashore/Reverse Cymbal",
76.443 + new Patch(0, 122), reverse_cymbal);
76.444 + region = ins.getRegions().get(0);
76.445 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
76.446 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 18500);
76.447 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 4500);
76.448 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, -4500);
76.449 + }
76.450 + {
76.451 + SF2Instrument ins = newInstrument(sf2, "Bird/Flute",
76.452 + new Patch(0, 123), flute);
76.453 + region = ins.getRegions().get(0);
76.454 + region.putInteger(SF2Region.GENERATOR_COARSETUNE, 24);
76.455 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, -3000);
76.456 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
76.457 + }
76.458 + newInstrument(sf2, "Def", new Patch(0, 124), side_stick);
76.459 + {
76.460 + SF2Instrument ins = newInstrument(sf2, "Seashore/Reverse Cymbal",
76.461 + new Patch(0, 125), reverse_cymbal);
76.462 + region = ins.getRegions().get(0);
76.463 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
76.464 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 18500);
76.465 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 4500);
76.466 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, -4500);
76.467 + }
76.468 + newInstrument(sf2, "Applause/crash_cymbal",
76.469 + new Patch(0, 126), crash_cymbal);
76.470 + newInstrument(sf2, "Gunshot/side_stick", new Patch(0, 127), side_stick);
76.471 +
76.472 + for (SF2Instrument instrument : sf2.getInstruments()) {
76.473 + Patch patch = instrument.getPatch();
76.474 + if (patch instanceof ModelPatch) {
76.475 + if (((ModelPatch) patch).isPercussion())
76.476 + continue;
76.477 + }
76.478 + instrument.setName(general_midi_instruments[patch.getProgram()]);
76.479 + }
76.480 +
76.481 + return sf2;
76.482 +
76.483 + }
76.484 +
76.485 + public static SF2Layer new_bell(SF2Soundbank sf2) {
76.486 + Random random = new Random(102030201);
76.487 + int x = 8;
76.488 + int fftsize = 4096 * x;
76.489 + double[] data = new double[fftsize * 2];
76.490 + double base = x * 25;
76.491 + double start_w = 0.01;
76.492 + double end_w = 0.05;
76.493 + double start_a = 0.2;
76.494 + double end_a = 0.00001;
76.495 + double a = start_a;
76.496 + double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
76.497 + for (int i = 0; i < 40; i++) {
76.498 + double detune = 1 + (random.nextDouble() * 2 - 1) * 0.01;
76.499 + double w = start_w + (end_w - start_w) * (i / 40.0);
76.500 + complexGaussianDist(data, base * (i + 1) * detune, w, a);
76.501 + a *= a_step;
76.502 + }
76.503 + SF2Sample sample = newSimpleFFTSample(sf2, "EPiano", data, base);
76.504 + SF2Layer layer = newLayer(sf2, "EPiano", sample);
76.505 + SF2Region region = layer.getRegions().get(0);
76.506 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.507 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -12000);
76.508 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
76.509 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
76.510 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
76.511 + region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, 1200);
76.512 + region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
76.513 + region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -9000);
76.514 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 16000);
76.515 + return layer;
76.516 + }
76.517 +
76.518 + public static SF2Layer new_guitar1(SF2Soundbank sf2) {
76.519 +
76.520 + int x = 8;
76.521 + int fftsize = 4096 * x;
76.522 + double[] data = new double[fftsize * 2];
76.523 + double base = x * 25;
76.524 + double start_w = 0.01;
76.525 + double end_w = 0.01;
76.526 + double start_a = 2;
76.527 + double end_a = 0.01;
76.528 + double a = start_a;
76.529 + double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
76.530 +
76.531 + double[] aa = new double[40];
76.532 + for (int i = 0; i < 40; i++) {
76.533 + aa[i] = a;
76.534 + a *= a_step;
76.535 + }
76.536 +
76.537 + aa[0] = 2;
76.538 + aa[1] = 0.5;
76.539 + aa[2] = 0.45;
76.540 + aa[3] = 0.2;
76.541 + aa[4] = 1;
76.542 + aa[5] = 0.5;
76.543 + aa[6] = 2;
76.544 + aa[7] = 1;
76.545 + aa[8] = 0.5;
76.546 + aa[9] = 1;
76.547 + aa[9] = 0.5;
76.548 + aa[10] = 0.2;
76.549 + aa[11] = 1;
76.550 + aa[12] = 0.7;
76.551 + aa[13] = 0.5;
76.552 + aa[14] = 1;
76.553 +
76.554 + for (int i = 0; i < 40; i++) {
76.555 + double w = start_w + (end_w - start_w) * (i / 40.0);
76.556 + complexGaussianDist(data, base * (i + 1), w, aa[i]);
76.557 + }
76.558 +
76.559 + SF2Sample sample = newSimpleFFTSample(sf2, "Guitar", data, base);
76.560 + SF2Layer layer = newLayer(sf2, "Guitar", sample);
76.561 + SF2Region region = layer.getRegions().get(0);
76.562 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.563 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -12000);
76.564 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
76.565 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 2400);
76.566 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
76.567 +
76.568 + region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -100);
76.569 + region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
76.570 + region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -6000);
76.571 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 16000);
76.572 + region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -20);
76.573 + return layer;
76.574 + }
76.575 +
76.576 + public static SF2Layer new_guitar_dist(SF2Soundbank sf2) {
76.577 +
76.578 + int x = 8;
76.579 + int fftsize = 4096 * x;
76.580 + double[] data = new double[fftsize * 2];
76.581 + double base = x * 25;
76.582 + double start_w = 0.01;
76.583 + double end_w = 0.01;
76.584 + double start_a = 2;
76.585 + double end_a = 0.01;
76.586 + double a = start_a;
76.587 + double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
76.588 +
76.589 + double[] aa = new double[40];
76.590 + for (int i = 0; i < 40; i++) {
76.591 + aa[i] = a;
76.592 + a *= a_step;
76.593 + }
76.594 +
76.595 + aa[0] = 5;
76.596 + aa[1] = 2;
76.597 + aa[2] = 0.45;
76.598 + aa[3] = 0.2;
76.599 + aa[4] = 1;
76.600 + aa[5] = 0.5;
76.601 + aa[6] = 2;
76.602 + aa[7] = 1;
76.603 + aa[8] = 0.5;
76.604 + aa[9] = 1;
76.605 + aa[9] = 0.5;
76.606 + aa[10] = 0.2;
76.607 + aa[11] = 1;
76.608 + aa[12] = 0.7;
76.609 + aa[13] = 0.5;
76.610 + aa[14] = 1;
76.611 +
76.612 + for (int i = 0; i < 40; i++) {
76.613 + double w = start_w + (end_w - start_w) * (i / 40.0);
76.614 + complexGaussianDist(data, base * (i + 1), w, aa[i]);
76.615 + }
76.616 +
76.617 +
76.618 + SF2Sample sample = newSimpleFFTSample_dist(sf2, "Distorted Guitar",
76.619 + data, base, 10000.0);
76.620 +
76.621 +
76.622 + SF2Layer layer = newLayer(sf2, "Distorted Guitar", sample);
76.623 + SF2Region region = layer.getRegions().get(0);
76.624 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.625 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -12000);
76.626 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
76.627 + //region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 2400);
76.628 + //region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 200);
76.629 +
76.630 + //region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -100);
76.631 + //region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
76.632 + //region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -1000);
76.633 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 8000);
76.634 + //region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -20);
76.635 + return layer;
76.636 + }
76.637 +
76.638 + public static SF2Layer new_guitar_pick(SF2Soundbank sf2) {
76.639 +
76.640 + double datab[];
76.641 +
76.642 + // Make treble part
76.643 + {
76.644 + int m = 2;
76.645 + int fftlen = 4096 * m;
76.646 + double[] data = new double[2 * fftlen];
76.647 + Random random = new Random(3049912);
76.648 + for (int i = 0; i < data.length; i += 2)
76.649 + data[i] = (2.0 * (random.nextDouble() - 0.5));
76.650 + fft(data);
76.651 + // Remove all negative frequency
76.652 + for (int i = fftlen / 2; i < data.length; i++)
76.653 + data[i] = 0;
76.654 + for (int i = 0; i < 2048 * m; i++) {
76.655 + data[i] *= Math.exp(-Math.abs((i - 23) / ((double) m)) * 1.2)
76.656 + + Math.exp(-Math.abs((i - 40) / ((double) m)) * 0.9);
76.657 + }
76.658 + randomPhase(data, new Random(3049912));
76.659 + ifft(data);
76.660 + normalize(data, 0.8);
76.661 + data = realPart(data);
76.662 + double gain = 1.0;
76.663 + for (int i = 0; i < data.length; i++) {
76.664 + data[i] *= gain;
76.665 + gain *= 0.9994;
76.666 + }
76.667 + datab = data;
76.668 +
76.669 + fadeUp(data, 80);
76.670 + }
76.671 +
76.672 + SF2Sample sample = newSimpleDrumSample(sf2, "Guitar Noise", datab);
76.673 +
76.674 + SF2Layer layer = new SF2Layer(sf2);
76.675 + layer.setName("Guitar Noise");
76.676 +
76.677 + SF2GlobalRegion global = new SF2GlobalRegion();
76.678 + layer.setGlobalZone(global);
76.679 + sf2.addResource(layer);
76.680 +
76.681 + SF2LayerRegion region = new SF2LayerRegion();
76.682 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 12000);
76.683 + //region.putInteger(SF2Region.GENERATOR_SCALETUNING, 0);
76.684 +// region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -100);
76.685 +/*
76.686 + region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, 0);
76.687 + region.putInteger(SF2Region.GENERATOR_SUSTAINMODENV, 1000);
76.688 + region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
76.689 + region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -11000);
76.690 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 12000);
76.691 + */
76.692 +
76.693 + region.setSample(sample);
76.694 + layer.getRegions().add(region);
76.695 +
76.696 + return layer;
76.697 + }
76.698 +
76.699 + public static SF2Layer new_gpiano(SF2Soundbank sf2) {
76.700 + //Random random = new Random(302030201);
76.701 + int x = 8;
76.702 + int fftsize = 4096 * x;
76.703 + double[] data = new double[fftsize * 2];
76.704 + double base = x * 25;
76.705 + double start_a = 0.2;
76.706 + double end_a = 0.001;
76.707 + double a = start_a;
76.708 + double a_step = Math.pow(end_a / start_a, 1.0 / 15.0);
76.709 +
76.710 + double[] aa = new double[30];
76.711 + for (int i = 0; i < 30; i++) {
76.712 + aa[i] = a;
76.713 + a *= a_step;
76.714 + }
76.715 +
76.716 + aa[0] *= 2;
76.717 + //aa[2] *= 0.1;
76.718 + aa[4] *= 2;
76.719 +
76.720 +
76.721 + aa[12] *= 0.9;
76.722 + aa[13] *= 0.7;
76.723 + for (int i = 14; i < 30; i++) {
76.724 + aa[i] *= 0.5;
76.725 + }
76.726 +
76.727 +
76.728 + for (int i = 0; i < 30; i++) {
76.729 + //double detune = 1 + (random.nextDouble()*2 - 1)*0.0001;
76.730 + double w = 0.2;
76.731 + double ai = aa[i];
76.732 + if (i > 10) {
76.733 + w = 5;
76.734 + ai *= 10;
76.735 + }
76.736 + int adjust = 0;
76.737 + if (i > 5) {
76.738 + adjust = (i - 5) * 7;
76.739 + }
76.740 + complexGaussianDist(data, base * (i + 1) + adjust, w, ai);
76.741 + }
76.742 +
76.743 + SF2Sample sample = newSimpleFFTSample(sf2, "Grand Piano", data, base, 200);
76.744 + SF2Layer layer = newLayer(sf2, "Grand Piano", sample);
76.745 + SF2Region region = layer.getRegions().get(0);
76.746 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.747 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -7000);
76.748 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
76.749 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
76.750 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
76.751 + region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -6000);
76.752 + region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
76.753 + region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -5500);
76.754 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 18000);
76.755 + return layer;
76.756 + }
76.757 +
76.758 + public static SF2Layer new_gpiano2(SF2Soundbank sf2) {
76.759 + //Random random = new Random(302030201);
76.760 + int x = 8;
76.761 + int fftsize = 4096 * x;
76.762 + double[] data = new double[fftsize * 2];
76.763 + double base = x * 25;
76.764 + double start_a = 0.2;
76.765 + double end_a = 0.001;
76.766 + double a = start_a;
76.767 + double a_step = Math.pow(end_a / start_a, 1.0 / 20.0);
76.768 +
76.769 + double[] aa = new double[30];
76.770 + for (int i = 0; i < 30; i++) {
76.771 + aa[i] = a;
76.772 + a *= a_step;
76.773 + }
76.774 +
76.775 + aa[0] *= 1;
76.776 + //aa[2] *= 0.1;
76.777 + aa[4] *= 2;
76.778 +
76.779 +
76.780 + aa[12] *= 0.9;
76.781 + aa[13] *= 0.7;
76.782 + for (int i = 14; i < 30; i++) {
76.783 + aa[i] *= 0.5;
76.784 + }
76.785 +
76.786 +
76.787 + for (int i = 0; i < 30; i++) {
76.788 + //double detune = 1 + (random.nextDouble()*2 - 1)*0.0001;
76.789 + double w = 0.2;
76.790 + double ai = aa[i];
76.791 + if (i > 10) {
76.792 + w = 5;
76.793 + ai *= 10;
76.794 + }
76.795 + int adjust = 0;
76.796 + if (i > 5) {
76.797 + adjust = (i - 5) * 7;
76.798 + }
76.799 + complexGaussianDist(data, base * (i + 1) + adjust, w, ai);
76.800 + }
76.801 +
76.802 + SF2Sample sample = newSimpleFFTSample(sf2, "Grand Piano", data, base, 200);
76.803 + SF2Layer layer = newLayer(sf2, "Grand Piano", sample);
76.804 + SF2Region region = layer.getRegions().get(0);
76.805 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.806 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -7000);
76.807 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
76.808 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
76.809 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
76.810 + region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -6000);
76.811 + region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
76.812 + region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -5500);
76.813 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 18000);
76.814 + return layer;
76.815 + }
76.816 +
76.817 + public static SF2Layer new_piano_hammer(SF2Soundbank sf2) {
76.818 +
76.819 + double datab[];
76.820 +
76.821 + // Make treble part
76.822 + {
76.823 + int m = 2;
76.824 + int fftlen = 4096 * m;
76.825 + double[] data = new double[2 * fftlen];
76.826 + Random random = new Random(3049912);
76.827 + for (int i = 0; i < data.length; i += 2)
76.828 + data[i] = (2.0 * (random.nextDouble() - 0.5));
76.829 + fft(data);
76.830 + // Remove all negative frequency
76.831 + for (int i = fftlen / 2; i < data.length; i++)
76.832 + data[i] = 0;
76.833 + for (int i = 0; i < 2048 * m; i++)
76.834 + data[i] *= Math.exp(-Math.abs((i - 37) / ((double) m)) * 0.05);
76.835 + randomPhase(data, new Random(3049912));
76.836 + ifft(data);
76.837 + normalize(data, 0.6);
76.838 + data = realPart(data);
76.839 + double gain = 1.0;
76.840 + for (int i = 0; i < data.length; i++) {
76.841 + data[i] *= gain;
76.842 + gain *= 0.9997;
76.843 + }
76.844 + datab = data;
76.845 +
76.846 + fadeUp(data, 80);
76.847 + }
76.848 +
76.849 + SF2Sample sample = newSimpleDrumSample(sf2, "Piano Hammer", datab);
76.850 +
76.851 + SF2Layer layer = new SF2Layer(sf2);
76.852 + layer.setName("Piano Hammer");
76.853 +
76.854 + SF2GlobalRegion global = new SF2GlobalRegion();
76.855 + layer.setGlobalZone(global);
76.856 + sf2.addResource(layer);
76.857 +
76.858 + SF2LayerRegion region = new SF2LayerRegion();
76.859 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 12000);
76.860 + //region.putInteger(SF2Region.GENERATOR_SCALETUNING, 0);
76.861 +/*
76.862 + region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, 0);
76.863 + region.putInteger(SF2Region.GENERATOR_SUSTAINMODENV, 1000);
76.864 + region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
76.865 + region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -11000);
76.866 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 12000);
76.867 + */
76.868 +
76.869 + region.setSample(sample);
76.870 + layer.getRegions().add(region);
76.871 +
76.872 + return layer;
76.873 + }
76.874 +
76.875 + public static SF2Layer new_piano1(SF2Soundbank sf2) {
76.876 + //Random random = new Random(302030201);
76.877 + int x = 8;
76.878 + int fftsize = 4096 * x;
76.879 + double[] data = new double[fftsize * 2];
76.880 + double base = x * 25;
76.881 + double start_a = 0.2;
76.882 + double end_a = 0.0001;
76.883 + double a = start_a;
76.884 + double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
76.885 +
76.886 + double[] aa = new double[30];
76.887 + for (int i = 0; i < 30; i++) {
76.888 + aa[i] = a;
76.889 + a *= a_step;
76.890 + }
76.891 +
76.892 + aa[0] *= 5;
76.893 + aa[2] *= 0.1;
76.894 + aa[7] *= 5;
76.895 +
76.896 +
76.897 + for (int i = 0; i < 30; i++) {
76.898 + //double detune = 1 + (random.nextDouble()*2 - 1)*0.0001;
76.899 + double w = 0.2;
76.900 + double ai = aa[i];
76.901 + if (i > 12) {
76.902 + w = 5;
76.903 + ai *= 10;
76.904 + }
76.905 + int adjust = 0;
76.906 + if (i > 5) {
76.907 + adjust = (i - 5) * 7;
76.908 + }
76.909 + complexGaussianDist(data, base * (i + 1) + adjust, w, ai);
76.910 + }
76.911 +
76.912 + complexGaussianDist(data, base * (15.5), 1, 0.1);
76.913 + complexGaussianDist(data, base * (17.5), 1, 0.01);
76.914 +
76.915 + SF2Sample sample = newSimpleFFTSample(sf2, "EPiano", data, base, 200);
76.916 + SF2Layer layer = newLayer(sf2, "EPiano", sample);
76.917 + SF2Region region = layer.getRegions().get(0);
76.918 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.919 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -12000);
76.920 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
76.921 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
76.922 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
76.923 + region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -1200);
76.924 + region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
76.925 + region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -5500);
76.926 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 16000);
76.927 + return layer;
76.928 + }
76.929 +
76.930 + public static SF2Layer new_epiano1(SF2Soundbank sf2) {
76.931 + Random random = new Random(302030201);
76.932 + int x = 8;
76.933 + int fftsize = 4096 * x;
76.934 + double[] data = new double[fftsize * 2];
76.935 + double base = x * 25;
76.936 + double start_w = 0.05;
76.937 + double end_w = 0.05;
76.938 + double start_a = 0.2;
76.939 + double end_a = 0.0001;
76.940 + double a = start_a;
76.941 + double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
76.942 + for (int i = 0; i < 40; i++) {
76.943 + double detune = 1 + (random.nextDouble() * 2 - 1) * 0.0001;
76.944 + double w = start_w + (end_w - start_w) * (i / 40.0);
76.945 + complexGaussianDist(data, base * (i + 1) * detune, w, a);
76.946 + a *= a_step;
76.947 + }
76.948 +
76.949 +
76.950 +
76.951 + SF2Sample sample = newSimpleFFTSample(sf2, "EPiano", data, base);
76.952 + SF2Layer layer = newLayer(sf2, "EPiano", sample);
76.953 + SF2Region region = layer.getRegions().get(0);
76.954 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.955 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -12000);
76.956 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
76.957 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
76.958 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
76.959 + region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, 1200);
76.960 + region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
76.961 + region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -9000);
76.962 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 16000);
76.963 + return layer;
76.964 + }
76.965 +
76.966 + public static SF2Layer new_epiano2(SF2Soundbank sf2) {
76.967 + Random random = new Random(302030201);
76.968 + int x = 8;
76.969 + int fftsize = 4096 * x;
76.970 + double[] data = new double[fftsize * 2];
76.971 + double base = x * 25;
76.972 + double start_w = 0.01;
76.973 + double end_w = 0.05;
76.974 + double start_a = 0.2;
76.975 + double end_a = 0.00001;
76.976 + double a = start_a;
76.977 + double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
76.978 + for (int i = 0; i < 40; i++) {
76.979 + double detune = 1 + (random.nextDouble() * 2 - 1) * 0.0001;
76.980 + double w = start_w + (end_w - start_w) * (i / 40.0);
76.981 + complexGaussianDist(data, base * (i + 1) * detune, w, a);
76.982 + a *= a_step;
76.983 + }
76.984 +
76.985 + SF2Sample sample = newSimpleFFTSample(sf2, "EPiano", data, base);
76.986 + SF2Layer layer = newLayer(sf2, "EPiano", sample);
76.987 + SF2Region region = layer.getRegions().get(0);
76.988 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.989 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -12000);
76.990 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
76.991 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 8000);
76.992 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
76.993 + region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, 2400);
76.994 + region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
76.995 + region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -9000);
76.996 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 16000);
76.997 + region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -100);
76.998 + return layer;
76.999 + }
76.1000 +
76.1001 + public static SF2Layer new_bass1(SF2Soundbank sf2) {
76.1002 + int x = 8;
76.1003 + int fftsize = 4096 * x;
76.1004 + double[] data = new double[fftsize * 2];
76.1005 + double base = x * 25;
76.1006 + double start_w = 0.05;
76.1007 + double end_w = 0.05;
76.1008 + double start_a = 0.2;
76.1009 + double end_a = 0.02;
76.1010 + double a = start_a;
76.1011 + double a_step = Math.pow(end_a / start_a, 1.0 / 25.0);
76.1012 +
76.1013 + double[] aa = new double[25];
76.1014 + for (int i = 0; i < 25; i++) {
76.1015 + aa[i] = a;
76.1016 + a *= a_step;
76.1017 + }
76.1018 +
76.1019 + aa[0] *= 8;
76.1020 + aa[1] *= 4;
76.1021 + aa[3] *= 8;
76.1022 + aa[5] *= 8;
76.1023 +
76.1024 + for (int i = 0; i < 25; i++) {
76.1025 + double w = start_w + (end_w - start_w) * (i / 40.0);
76.1026 + complexGaussianDist(data, base * (i + 1), w, aa[i]);
76.1027 + }
76.1028 +
76.1029 +
76.1030 + SF2Sample sample = newSimpleFFTSample(sf2, "Bass", data, base);
76.1031 + SF2Layer layer = newLayer(sf2, "Bass", sample);
76.1032 + SF2Region region = layer.getRegions().get(0);
76.1033 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.1034 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -12000);
76.1035 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
76.1036 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
76.1037 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
76.1038 + region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -3000);
76.1039 + region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
76.1040 + region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -5000);
76.1041 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 11000);
76.1042 + region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -100);
76.1043 + return layer;
76.1044 + }
76.1045 +
76.1046 + public static SF2Layer new_synthbass(SF2Soundbank sf2) {
76.1047 + int x = 8;
76.1048 + int fftsize = 4096 * x;
76.1049 + double[] data = new double[fftsize * 2];
76.1050 + double base = x * 25;
76.1051 + double start_w = 0.05;
76.1052 + double end_w = 0.05;
76.1053 + double start_a = 0.2;
76.1054 + double end_a = 0.02;
76.1055 + double a = start_a;
76.1056 + double a_step = Math.pow(end_a / start_a, 1.0 / 25.0);
76.1057 +
76.1058 + double[] aa = new double[25];
76.1059 + for (int i = 0; i < 25; i++) {
76.1060 + aa[i] = a;
76.1061 + a *= a_step;
76.1062 + }
76.1063 +
76.1064 + aa[0] *= 16;
76.1065 + aa[1] *= 4;
76.1066 + aa[3] *= 16;
76.1067 + aa[5] *= 8;
76.1068 +
76.1069 + for (int i = 0; i < 25; i++) {
76.1070 + double w = start_w + (end_w - start_w) * (i / 40.0);
76.1071 + complexGaussianDist(data, base * (i + 1), w, aa[i]);
76.1072 + }
76.1073 +
76.1074 +
76.1075 + SF2Sample sample = newSimpleFFTSample(sf2, "Bass", data, base);
76.1076 + SF2Layer layer = newLayer(sf2, "Bass", sample);
76.1077 + SF2Region region = layer.getRegions().get(0);
76.1078 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.1079 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -12000);
76.1080 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
76.1081 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
76.1082 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
76.1083 + region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -3000);
76.1084 + region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
76.1085 + region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -3000);
76.1086 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERQ, 100);
76.1087 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 8000);
76.1088 + region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -100);
76.1089 + return layer;
76.1090 + }
76.1091 +
76.1092 + public static SF2Layer new_bass2(SF2Soundbank sf2) {
76.1093 + int x = 8;
76.1094 + int fftsize = 4096 * x;
76.1095 + double[] data = new double[fftsize * 2];
76.1096 + double base = x * 25;
76.1097 + double start_w = 0.05;
76.1098 + double end_w = 0.05;
76.1099 + double start_a = 0.2;
76.1100 + double end_a = 0.002;
76.1101 + double a = start_a;
76.1102 + double a_step = Math.pow(end_a / start_a, 1.0 / 25.0);
76.1103 +
76.1104 + double[] aa = new double[25];
76.1105 + for (int i = 0; i < 25; i++) {
76.1106 + aa[i] = a;
76.1107 + a *= a_step;
76.1108 + }
76.1109 +
76.1110 + aa[0] *= 8;
76.1111 + aa[1] *= 4;
76.1112 + aa[3] *= 8;
76.1113 + aa[5] *= 8;
76.1114 +
76.1115 + for (int i = 0; i < 25; i++) {
76.1116 + double w = start_w + (end_w - start_w) * (i / 40.0);
76.1117 + complexGaussianDist(data, base * (i + 1), w, aa[i]);
76.1118 + }
76.1119 +
76.1120 +
76.1121 + SF2Sample sample = newSimpleFFTSample(sf2, "Bass2", data, base);
76.1122 + SF2Layer layer = newLayer(sf2, "Bass2", sample);
76.1123 + SF2Region region = layer.getRegions().get(0);
76.1124 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.1125 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -8000);
76.1126 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
76.1127 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
76.1128 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
76.1129 + region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -6000);
76.1130 + region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
76.1131 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 5000);
76.1132 + region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -100);
76.1133 + return layer;
76.1134 + }
76.1135 +
76.1136 + public static SF2Layer new_solostring(SF2Soundbank sf2) {
76.1137 + int x = 8;
76.1138 + int fftsize = 4096 * x;
76.1139 + double[] data = new double[fftsize * 2];
76.1140 + double base = x * 25;
76.1141 + double start_w = 2;
76.1142 + double end_w = 2;
76.1143 + double start_a = 0.2;
76.1144 + double end_a = 0.01;
76.1145 +
76.1146 + double[] aa = new double[18];
76.1147 + double a = start_a;
76.1148 + double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
76.1149 + for (int i = 0; i < aa.length; i++) {
76.1150 + a *= a_step;
76.1151 + aa[i] = a;
76.1152 + }
76.1153 +
76.1154 + aa[0] *= 5;
76.1155 + aa[1] *= 5;
76.1156 + aa[2] *= 5;
76.1157 + aa[3] *= 4;
76.1158 + aa[4] *= 4;
76.1159 + aa[5] *= 3;
76.1160 + aa[6] *= 3;
76.1161 + aa[7] *= 2;
76.1162 +
76.1163 + for (int i = 0; i < aa.length; i++) {
76.1164 + double w = start_w + (end_w - start_w) * (i / 40.0);
76.1165 + complexGaussianDist(data, base * (i + 1), w, a);
76.1166 + }
76.1167 + SF2Sample sample = newSimpleFFTSample(sf2, "Strings", data, base);
76.1168 + SF2Layer layer = newLayer(sf2, "Strings", sample);
76.1169 + SF2Region region = layer.getRegions().get(0);
76.1170 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.1171 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -5000);
76.1172 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 1000);
76.1173 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
76.1174 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
76.1175 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 9500);
76.1176 + region.putInteger(SF2Region.GENERATOR_FREQVIBLFO, -1000);
76.1177 + region.putInteger(SF2Region.GENERATOR_VIBLFOTOPITCH, 15);
76.1178 + return layer;
76.1179 +
76.1180 + }
76.1181 +
76.1182 + public static SF2Layer new_orchhit(SF2Soundbank sf2) {
76.1183 + int x = 8;
76.1184 + int fftsize = 4096 * x;
76.1185 + double[] data = new double[fftsize * 2];
76.1186 + double base = x * 25;
76.1187 + double start_w = 2;
76.1188 + double end_w = 80;
76.1189 + double start_a = 0.2;
76.1190 + double end_a = 0.001;
76.1191 + double a = start_a;
76.1192 + double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
76.1193 + for (int i = 0; i < 40; i++) {
76.1194 + double w = start_w + (end_w - start_w) * (i / 40.0);
76.1195 + complexGaussianDist(data, base * (i + 1), w, a);
76.1196 + a *= a_step;
76.1197 + }
76.1198 + complexGaussianDist(data, base * 4, 300, 1);
76.1199 +
76.1200 +
76.1201 + SF2Sample sample = newSimpleFFTSample(sf2, "Och Strings", data, base);
76.1202 + SF2Layer layer = newLayer(sf2, "Och Strings", sample);
76.1203 + SF2Region region = layer.getRegions().get(0);
76.1204 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.1205 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -5000);
76.1206 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 200);
76.1207 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 200);
76.1208 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
76.1209 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 9500);
76.1210 + return layer;
76.1211 +
76.1212 + }
76.1213 +
76.1214 + public static SF2Layer new_string2(SF2Soundbank sf2) {
76.1215 + int x = 8;
76.1216 + int fftsize = 4096 * x;
76.1217 + double[] data = new double[fftsize * 2];
76.1218 + double base = x * 25;
76.1219 + double start_w = 2;
76.1220 + double end_w = 80;
76.1221 + double start_a = 0.2;
76.1222 + double end_a = 0.001;
76.1223 + double a = start_a;
76.1224 + double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
76.1225 + for (int i = 0; i < 40; i++) {
76.1226 + double w = start_w + (end_w - start_w) * (i / 40.0);
76.1227 + complexGaussianDist(data, base * (i + 1), w, a);
76.1228 + a *= a_step;
76.1229 + }
76.1230 + SF2Sample sample = newSimpleFFTSample(sf2, "Strings", data, base);
76.1231 + SF2Layer layer = newLayer(sf2, "Strings", sample);
76.1232 + SF2Region region = layer.getRegions().get(0);
76.1233 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.1234 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -5000);
76.1235 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 1000);
76.1236 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
76.1237 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
76.1238 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 9500);
76.1239 + return layer;
76.1240 +
76.1241 + }
76.1242 +
76.1243 + public static SF2Layer new_choir(SF2Soundbank sf2) {
76.1244 + int x = 8;
76.1245 + int fftsize = 4096 * x;
76.1246 + double[] data = new double[fftsize * 2];
76.1247 + double base = x * 25;
76.1248 + double start_w = 2;
76.1249 + double end_w = 80;
76.1250 + double start_a = 0.2;
76.1251 + double end_a = 0.001;
76.1252 + double a = start_a;
76.1253 + double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
76.1254 + double[] aa = new double[40];
76.1255 + for (int i = 0; i < aa.length; i++) {
76.1256 + a *= a_step;
76.1257 + aa[i] = a;
76.1258 + }
76.1259 +
76.1260 + aa[5] *= 0.1;
76.1261 + aa[6] *= 0.01;
76.1262 + aa[7] *= 0.1;
76.1263 + aa[8] *= 0.1;
76.1264 +
76.1265 + for (int i = 0; i < aa.length; i++) {
76.1266 + double w = start_w + (end_w - start_w) * (i / 40.0);
76.1267 + complexGaussianDist(data, base * (i + 1), w, aa[i]);
76.1268 + }
76.1269 + SF2Sample sample = newSimpleFFTSample(sf2, "Strings", data, base);
76.1270 + SF2Layer layer = newLayer(sf2, "Strings", sample);
76.1271 + SF2Region region = layer.getRegions().get(0);
76.1272 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.1273 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -5000);
76.1274 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 1000);
76.1275 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
76.1276 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
76.1277 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 9500);
76.1278 + return layer;
76.1279 +
76.1280 + }
76.1281 +
76.1282 + public static SF2Layer new_organ(SF2Soundbank sf2) {
76.1283 + Random random = new Random(102030201);
76.1284 + int x = 1;
76.1285 + int fftsize = 4096 * x;
76.1286 + double[] data = new double[fftsize * 2];
76.1287 + double base = x * 15;
76.1288 + double start_w = 0.01;
76.1289 + double end_w = 0.01;
76.1290 + double start_a = 0.2;
76.1291 + double end_a = 0.001;
76.1292 + double a = start_a;
76.1293 + double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
76.1294 +
76.1295 + for (int i = 0; i < 12; i++) {
76.1296 + double w = start_w + (end_w - start_w) * (i / 40.0);
76.1297 + complexGaussianDist(data, base * (i + 1), w,
76.1298 + a * (0.5 + 3 * (random.nextDouble())));
76.1299 + a *= a_step;
76.1300 + }
76.1301 + SF2Sample sample = newSimpleFFTSample(sf2, "Organ", data, base);
76.1302 + SF2Layer layer = newLayer(sf2, "Organ", sample);
76.1303 + SF2Region region = layer.getRegions().get(0);
76.1304 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.1305 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -6000);
76.1306 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, -1000);
76.1307 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
76.1308 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
76.1309 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 9500);
76.1310 + return layer;
76.1311 +
76.1312 + }
76.1313 +
76.1314 + public static SF2Layer new_ch_organ(SF2Soundbank sf2) {
76.1315 + int x = 1;
76.1316 + int fftsize = 4096 * x;
76.1317 + double[] data = new double[fftsize * 2];
76.1318 + double base = x * 15;
76.1319 + double start_w = 0.01;
76.1320 + double end_w = 0.01;
76.1321 + double start_a = 0.2;
76.1322 + double end_a = 0.001;
76.1323 + double a = start_a;
76.1324 + double a_step = Math.pow(end_a / start_a, 1.0 / 60.0);
76.1325 +
76.1326 + double[] aa = new double[60];
76.1327 + for (int i = 0; i < aa.length; i++) {
76.1328 + a *= a_step;
76.1329 + aa[i] = a;
76.1330 + }
76.1331 +
76.1332 + aa[0] *= 5;
76.1333 + aa[1] *= 2;
76.1334 + aa[2] = 0;
76.1335 + aa[4] = 0;
76.1336 + aa[5] = 0;
76.1337 + aa[7] *= 7;
76.1338 + aa[9] = 0;
76.1339 + aa[10] = 0;
76.1340 + aa[12] = 0;
76.1341 + aa[15] *= 7;
76.1342 + aa[18] = 0;
76.1343 + aa[20] = 0;
76.1344 + aa[24] = 0;
76.1345 + aa[27] *= 5;
76.1346 + aa[29] = 0;
76.1347 + aa[30] = 0;
76.1348 + aa[33] = 0;
76.1349 + aa[36] *= 4;
76.1350 + aa[37] = 0;
76.1351 + aa[39] = 0;
76.1352 + aa[42] = 0;
76.1353 + aa[43] = 0;
76.1354 + aa[47] = 0;
76.1355 + aa[50] *= 4;
76.1356 + aa[52] = 0;
76.1357 + aa[55] = 0;
76.1358 + aa[57] = 0;
76.1359 +
76.1360 +
76.1361 + aa[10] *= 0.1;
76.1362 + aa[11] *= 0.1;
76.1363 + aa[12] *= 0.1;
76.1364 + aa[13] *= 0.1;
76.1365 +
76.1366 + aa[17] *= 0.1;
76.1367 + aa[18] *= 0.1;
76.1368 + aa[19] *= 0.1;
76.1369 + aa[20] *= 0.1;
76.1370 +
76.1371 + for (int i = 0; i < 60; i++) {
76.1372 + double w = start_w + (end_w - start_w) * (i / 40.0);
76.1373 + complexGaussianDist(data, base * (i + 1), w, aa[i]);
76.1374 + a *= a_step;
76.1375 + }
76.1376 + SF2Sample sample = newSimpleFFTSample(sf2, "Organ", data, base);
76.1377 + SF2Layer layer = newLayer(sf2, "Organ", sample);
76.1378 + SF2Region region = layer.getRegions().get(0);
76.1379 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.1380 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -10000);
76.1381 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, -1000);
76.1382 + return layer;
76.1383 +
76.1384 + }
76.1385 +
76.1386 + public static SF2Layer new_flute(SF2Soundbank sf2) {
76.1387 + int x = 8;
76.1388 + int fftsize = 4096 * x;
76.1389 + double[] data = new double[fftsize * 2];
76.1390 + double base = x * 15;
76.1391 +
76.1392 + complexGaussianDist(data, base * 1, 0.001, 0.5);
76.1393 + complexGaussianDist(data, base * 2, 0.001, 0.5);
76.1394 + complexGaussianDist(data, base * 3, 0.001, 0.5);
76.1395 + complexGaussianDist(data, base * 4, 0.01, 0.5);
76.1396 +
76.1397 + complexGaussianDist(data, base * 4, 100, 120);
76.1398 + complexGaussianDist(data, base * 6, 100, 40);
76.1399 + complexGaussianDist(data, base * 8, 100, 80);
76.1400 +
76.1401 + complexGaussianDist(data, base * 5, 0.001, 0.05);
76.1402 + complexGaussianDist(data, base * 6, 0.001, 0.06);
76.1403 + complexGaussianDist(data, base * 7, 0.001, 0.04);
76.1404 + complexGaussianDist(data, base * 8, 0.005, 0.06);
76.1405 + complexGaussianDist(data, base * 9, 0.005, 0.06);
76.1406 + complexGaussianDist(data, base * 10, 0.01, 0.1);
76.1407 + complexGaussianDist(data, base * 11, 0.08, 0.7);
76.1408 + complexGaussianDist(data, base * 12, 0.08, 0.6);
76.1409 + complexGaussianDist(data, base * 13, 0.08, 0.6);
76.1410 + complexGaussianDist(data, base * 14, 0.08, 0.6);
76.1411 + complexGaussianDist(data, base * 15, 0.08, 0.5);
76.1412 + complexGaussianDist(data, base * 16, 0.08, 0.5);
76.1413 + complexGaussianDist(data, base * 17, 0.08, 0.2);
76.1414 +
76.1415 +
76.1416 + complexGaussianDist(data, base * 1, 10, 8);
76.1417 + complexGaussianDist(data, base * 2, 10, 8);
76.1418 + complexGaussianDist(data, base * 3, 10, 8);
76.1419 + complexGaussianDist(data, base * 4, 10, 8);
76.1420 + complexGaussianDist(data, base * 5, 10, 8);
76.1421 + complexGaussianDist(data, base * 6, 20, 9);
76.1422 + complexGaussianDist(data, base * 7, 20, 9);
76.1423 + complexGaussianDist(data, base * 8, 20, 9);
76.1424 + complexGaussianDist(data, base * 9, 20, 8);
76.1425 + complexGaussianDist(data, base * 10, 30, 8);
76.1426 + complexGaussianDist(data, base * 11, 30, 9);
76.1427 + complexGaussianDist(data, base * 12, 30, 9);
76.1428 + complexGaussianDist(data, base * 13, 30, 8);
76.1429 + complexGaussianDist(data, base * 14, 30, 8);
76.1430 + complexGaussianDist(data, base * 15, 30, 7);
76.1431 + complexGaussianDist(data, base * 16, 30, 7);
76.1432 + complexGaussianDist(data, base * 17, 30, 6);
76.1433 +
76.1434 + SF2Sample sample = newSimpleFFTSample(sf2, "Flute", data, base);
76.1435 + SF2Layer layer = newLayer(sf2, "Flute", sample);
76.1436 + SF2Region region = layer.getRegions().get(0);
76.1437 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.1438 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -6000);
76.1439 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, -1000);
76.1440 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
76.1441 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
76.1442 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 9500);
76.1443 + return layer;
76.1444 +
76.1445 + }
76.1446 +
76.1447 + public static SF2Layer new_horn(SF2Soundbank sf2) {
76.1448 + int x = 8;
76.1449 + int fftsize = 4096 * x;
76.1450 + double[] data = new double[fftsize * 2];
76.1451 + double base = x * 15;
76.1452 +
76.1453 + double start_a = 0.5;
76.1454 + double end_a = 0.00000000001;
76.1455 + double a = start_a;
76.1456 + double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
76.1457 + for (int i = 0; i < 40; i++) {
76.1458 + if (i == 0)
76.1459 + complexGaussianDist(data, base * (i + 1), 0.1, a * 0.2);
76.1460 + else
76.1461 + complexGaussianDist(data, base * (i + 1), 0.1, a);
76.1462 + a *= a_step;
76.1463 + }
76.1464 +
76.1465 + complexGaussianDist(data, base * 2, 100, 1);
76.1466 +
76.1467 +
76.1468 + SF2Sample sample = newSimpleFFTSample(sf2, "Horn", data, base);
76.1469 + SF2Layer layer = newLayer(sf2, "Horn", sample);
76.1470 + SF2Region region = layer.getRegions().get(0);
76.1471 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.1472 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -6000);
76.1473 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, -1000);
76.1474 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
76.1475 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
76.1476 +
76.1477 + region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -500);
76.1478 + region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
76.1479 + region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, 5000);
76.1480 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 4500);
76.1481 + return layer;
76.1482 +
76.1483 + }
76.1484 +
76.1485 + public static SF2Layer new_trumpet(SF2Soundbank sf2) {
76.1486 + int x = 8;
76.1487 + int fftsize = 4096 * x;
76.1488 + double[] data = new double[fftsize * 2];
76.1489 + double base = x * 15;
76.1490 +
76.1491 + double start_a = 0.5;
76.1492 + double end_a = 0.00001;
76.1493 + double a = start_a;
76.1494 + double a_step = Math.pow(end_a / start_a, 1.0 / 80.0);
76.1495 + double[] aa = new double[80];
76.1496 + for (int i = 0; i < 80; i++) {
76.1497 + aa[i] = a;
76.1498 + a *= a_step;
76.1499 + }
76.1500 +
76.1501 + aa[0] *= 0.05;
76.1502 + aa[1] *= 0.2;
76.1503 + aa[2] *= 0.5;
76.1504 + aa[3] *= 0.85;
76.1505 +
76.1506 + for (int i = 0; i < 80; i++) {
76.1507 + complexGaussianDist(data, base * (i + 1), 0.1, aa[i]);
76.1508 + }
76.1509 +
76.1510 + complexGaussianDist(data, base * 5, 300, 3);
76.1511 +
76.1512 +
76.1513 + SF2Sample sample = newSimpleFFTSample(sf2, "Trumpet", data, base);
76.1514 + SF2Layer layer = newLayer(sf2, "Trumpet", sample);
76.1515 + SF2Region region = layer.getRegions().get(0);
76.1516 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.1517 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -10000);
76.1518 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
76.1519 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
76.1520 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
76.1521 +
76.1522 + region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -4000);
76.1523 + region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, -2500);
76.1524 + region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, 5000);
76.1525 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 4500);
76.1526 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERQ, 10);
76.1527 + return layer;
76.1528 +
76.1529 + }
76.1530 +
76.1531 + public static SF2Layer new_brass_section(SF2Soundbank sf2) {
76.1532 + int x = 8;
76.1533 + int fftsize = 4096 * x;
76.1534 + double[] data = new double[fftsize * 2];
76.1535 + double base = x * 15;
76.1536 +
76.1537 + double start_a = 0.5;
76.1538 + double end_a = 0.005;
76.1539 + double a = start_a;
76.1540 + double a_step = Math.pow(end_a / start_a, 1.0 / 30.0);
76.1541 + double[] aa = new double[30];
76.1542 + for (int i = 0; i < 30; i++) {
76.1543 + aa[i] = a;
76.1544 + a *= a_step;
76.1545 + }
76.1546 +
76.1547 + aa[0] *= 0.8;
76.1548 + aa[1] *= 0.9;
76.1549 +
76.1550 + double w = 5;
76.1551 + for (int i = 0; i < 30; i++) {
76.1552 + complexGaussianDist(data, base * (i + 1), 0.1 * w, aa[i] * w);
76.1553 + w += 6; //*= w_step;
76.1554 + }
76.1555 +
76.1556 + complexGaussianDist(data, base * 6, 300, 2);
76.1557 +
76.1558 +
76.1559 + SF2Sample sample = newSimpleFFTSample(sf2, "Brass Section", data, base);
76.1560 + SF2Layer layer = newLayer(sf2, "Brass Section", sample);
76.1561 + SF2Region region = layer.getRegions().get(0);
76.1562 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.1563 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -9200);
76.1564 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, -1000);
76.1565 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
76.1566 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
76.1567 +
76.1568 + region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -3000);
76.1569 + region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
76.1570 + region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, 5000);
76.1571 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 4500);
76.1572 + return layer;
76.1573 +
76.1574 + }
76.1575 +
76.1576 + public static SF2Layer new_trombone(SF2Soundbank sf2) {
76.1577 + int x = 8;
76.1578 + int fftsize = 4096 * x;
76.1579 + double[] data = new double[fftsize * 2];
76.1580 + double base = x * 15;
76.1581 +
76.1582 + double start_a = 0.5;
76.1583 + double end_a = 0.001;
76.1584 + double a = start_a;
76.1585 + double a_step = Math.pow(end_a / start_a, 1.0 / 80.0);
76.1586 + double[] aa = new double[80];
76.1587 + for (int i = 0; i < 80; i++) {
76.1588 + aa[i] = a;
76.1589 + a *= a_step;
76.1590 + }
76.1591 +
76.1592 + aa[0] *= 0.3;
76.1593 + aa[1] *= 0.7;
76.1594 +
76.1595 + for (int i = 0; i < 80; i++) {
76.1596 + complexGaussianDist(data, base * (i + 1), 0.1, aa[i]);
76.1597 + }
76.1598 +
76.1599 + complexGaussianDist(data, base * 6, 300, 2);
76.1600 +
76.1601 +
76.1602 + SF2Sample sample = newSimpleFFTSample(sf2, "Trombone", data, base);
76.1603 + SF2Layer layer = newLayer(sf2, "Trombone", sample);
76.1604 + SF2Region region = layer.getRegions().get(0);
76.1605 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.1606 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -8000);
76.1607 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, -1000);
76.1608 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
76.1609 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
76.1610 +
76.1611 + region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -2000);
76.1612 + region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
76.1613 + region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, 5000);
76.1614 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 4500);
76.1615 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERQ, 10);
76.1616 + return layer;
76.1617 +
76.1618 + }
76.1619 +
76.1620 + public static SF2Layer new_sax(SF2Soundbank sf2) {
76.1621 + int x = 8;
76.1622 + int fftsize = 4096 * x;
76.1623 + double[] data = new double[fftsize * 2];
76.1624 + double base = x * 15;
76.1625 +
76.1626 + double start_a = 0.5;
76.1627 + double end_a = 0.01;
76.1628 + double a = start_a;
76.1629 + double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
76.1630 + for (int i = 0; i < 40; i++) {
76.1631 + if (i == 0 || i == 2)
76.1632 + complexGaussianDist(data, base * (i + 1), 0.1, a * 4);
76.1633 + else
76.1634 + complexGaussianDist(data, base * (i + 1), 0.1, a);
76.1635 + a *= a_step;
76.1636 + }
76.1637 +
76.1638 + complexGaussianDist(data, base * 4, 200, 1);
76.1639 +
76.1640 + SF2Sample sample = newSimpleFFTSample(sf2, "Sax", data, base);
76.1641 + SF2Layer layer = newLayer(sf2, "Sax", sample);
76.1642 + SF2Region region = layer.getRegions().get(0);
76.1643 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.1644 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -6000);
76.1645 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, -1000);
76.1646 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
76.1647 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
76.1648 +
76.1649 + region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, -3000);
76.1650 + region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
76.1651 + region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, 5000);
76.1652 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 4500);
76.1653 + return layer;
76.1654 +
76.1655 + }
76.1656 +
76.1657 + public static SF2Layer new_oboe(SF2Soundbank sf2) {
76.1658 + int x = 8;
76.1659 + int fftsize = 4096 * x;
76.1660 + double[] data = new double[fftsize * 2];
76.1661 + double base = x * 15;
76.1662 +
76.1663 + complexGaussianDist(data, base * 5, 100, 80);
76.1664 +
76.1665 +
76.1666 + complexGaussianDist(data, base * 1, 0.01, 0.53);
76.1667 + complexGaussianDist(data, base * 2, 0.01, 0.51);
76.1668 + complexGaussianDist(data, base * 3, 0.01, 0.48);
76.1669 + complexGaussianDist(data, base * 4, 0.01, 0.49);
76.1670 + complexGaussianDist(data, base * 5, 0.01, 5);
76.1671 + complexGaussianDist(data, base * 6, 0.01, 0.51);
76.1672 + complexGaussianDist(data, base * 7, 0.01, 0.50);
76.1673 + complexGaussianDist(data, base * 8, 0.01, 0.59);
76.1674 + complexGaussianDist(data, base * 9, 0.01, 0.61);
76.1675 + complexGaussianDist(data, base * 10, 0.01, 0.52);
76.1676 + complexGaussianDist(data, base * 11, 0.01, 0.49);
76.1677 + complexGaussianDist(data, base * 12, 0.01, 0.51);
76.1678 + complexGaussianDist(data, base * 13, 0.01, 0.48);
76.1679 + complexGaussianDist(data, base * 14, 0.01, 0.51);
76.1680 + complexGaussianDist(data, base * 15, 0.01, 0.46);
76.1681 + complexGaussianDist(data, base * 16, 0.01, 0.35);
76.1682 + complexGaussianDist(data, base * 17, 0.01, 0.20);
76.1683 + complexGaussianDist(data, base * 18, 0.01, 0.10);
76.1684 + complexGaussianDist(data, base * 19, 0.01, 0.5);
76.1685 + complexGaussianDist(data, base * 20, 0.01, 0.1);
76.1686 +
76.1687 +
76.1688 + SF2Sample sample = newSimpleFFTSample(sf2, "Oboe", data, base);
76.1689 + SF2Layer layer = newLayer(sf2, "Oboe", sample);
76.1690 + SF2Region region = layer.getRegions().get(0);
76.1691 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.1692 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -6000);
76.1693 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, -1000);
76.1694 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
76.1695 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
76.1696 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 9500);
76.1697 + return layer;
76.1698 +
76.1699 + }
76.1700 +
76.1701 + public static SF2Layer new_bassoon(SF2Soundbank sf2) {
76.1702 + int x = 8;
76.1703 + int fftsize = 4096 * x;
76.1704 + double[] data = new double[fftsize * 2];
76.1705 + double base = x * 15;
76.1706 +
76.1707 + complexGaussianDist(data, base * 2, 100, 40);
76.1708 + complexGaussianDist(data, base * 4, 100, 20);
76.1709 +
76.1710 + complexGaussianDist(data, base * 1, 0.01, 0.53);
76.1711 + complexGaussianDist(data, base * 2, 0.01, 5);
76.1712 + complexGaussianDist(data, base * 3, 0.01, 0.51);
76.1713 + complexGaussianDist(data, base * 4, 0.01, 0.48);
76.1714 + complexGaussianDist(data, base * 5, 0.01, 1.49);
76.1715 + complexGaussianDist(data, base * 6, 0.01, 0.51);
76.1716 + complexGaussianDist(data, base * 7, 0.01, 0.50);
76.1717 + complexGaussianDist(data, base * 8, 0.01, 0.59);
76.1718 + complexGaussianDist(data, base * 9, 0.01, 0.61);
76.1719 + complexGaussianDist(data, base * 10, 0.01, 0.52);
76.1720 + complexGaussianDist(data, base * 11, 0.01, 0.49);
76.1721 + complexGaussianDist(data, base * 12, 0.01, 0.51);
76.1722 + complexGaussianDist(data, base * 13, 0.01, 0.48);
76.1723 + complexGaussianDist(data, base * 14, 0.01, 0.51);
76.1724 + complexGaussianDist(data, base * 15, 0.01, 0.46);
76.1725 + complexGaussianDist(data, base * 16, 0.01, 0.35);
76.1726 + complexGaussianDist(data, base * 17, 0.01, 0.20);
76.1727 + complexGaussianDist(data, base * 18, 0.01, 0.10);
76.1728 + complexGaussianDist(data, base * 19, 0.01, 0.5);
76.1729 + complexGaussianDist(data, base * 20, 0.01, 0.1);
76.1730 +
76.1731 +
76.1732 + SF2Sample sample = newSimpleFFTSample(sf2, "Flute", data, base);
76.1733 + SF2Layer layer = newLayer(sf2, "Flute", sample);
76.1734 + SF2Region region = layer.getRegions().get(0);
76.1735 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.1736 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -6000);
76.1737 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, -1000);
76.1738 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
76.1739 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
76.1740 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 9500);
76.1741 + return layer;
76.1742 +
76.1743 + }
76.1744 +
76.1745 + public static SF2Layer new_clarinet(SF2Soundbank sf2) {
76.1746 + int x = 8;
76.1747 + int fftsize = 4096 * x;
76.1748 + double[] data = new double[fftsize * 2];
76.1749 + double base = x * 15;
76.1750 +
76.1751 + complexGaussianDist(data, base * 1, 0.001, 0.5);
76.1752 + complexGaussianDist(data, base * 2, 0.001, 0.02);
76.1753 + complexGaussianDist(data, base * 3, 0.001, 0.2);
76.1754 + complexGaussianDist(data, base * 4, 0.01, 0.1);
76.1755 +
76.1756 + complexGaussianDist(data, base * 4, 100, 60);
76.1757 + complexGaussianDist(data, base * 6, 100, 20);
76.1758 + complexGaussianDist(data, base * 8, 100, 20);
76.1759 +
76.1760 + complexGaussianDist(data, base * 5, 0.001, 0.1);
76.1761 + complexGaussianDist(data, base * 6, 0.001, 0.09);
76.1762 + complexGaussianDist(data, base * 7, 0.001, 0.02);
76.1763 + complexGaussianDist(data, base * 8, 0.005, 0.16);
76.1764 + complexGaussianDist(data, base * 9, 0.005, 0.96);
76.1765 + complexGaussianDist(data, base * 10, 0.01, 0.9);
76.1766 + complexGaussianDist(data, base * 11, 0.08, 1.2);
76.1767 + complexGaussianDist(data, base * 12, 0.08, 1.8);
76.1768 + complexGaussianDist(data, base * 13, 0.08, 1.6);
76.1769 + complexGaussianDist(data, base * 14, 0.08, 1.2);
76.1770 + complexGaussianDist(data, base * 15, 0.08, 0.9);
76.1771 + complexGaussianDist(data, base * 16, 0.08, 0.5);
76.1772 + complexGaussianDist(data, base * 17, 0.08, 0.2);
76.1773 +
76.1774 +
76.1775 + complexGaussianDist(data, base * 1, 10, 8);
76.1776 + complexGaussianDist(data, base * 2, 10, 8);
76.1777 + complexGaussianDist(data, base * 3, 10, 8);
76.1778 + complexGaussianDist(data, base * 4, 10, 8);
76.1779 + complexGaussianDist(data, base * 5, 10, 8);
76.1780 + complexGaussianDist(data, base * 6, 20, 9);
76.1781 + complexGaussianDist(data, base * 7, 20, 9);
76.1782 + complexGaussianDist(data, base * 8, 20, 9);
76.1783 + complexGaussianDist(data, base * 9, 20, 8);
76.1784 + complexGaussianDist(data, base * 10, 30, 8);
76.1785 + complexGaussianDist(data, base * 11, 30, 9);
76.1786 + complexGaussianDist(data, base * 12, 30, 9);
76.1787 + complexGaussianDist(data, base * 13, 30, 8);
76.1788 + complexGaussianDist(data, base * 14, 30, 8);
76.1789 + complexGaussianDist(data, base * 15, 30, 7);
76.1790 + complexGaussianDist(data, base * 16, 30, 7);
76.1791 + complexGaussianDist(data, base * 17, 30, 6);
76.1792 +
76.1793 + SF2Sample sample = newSimpleFFTSample(sf2, "Clarinet", data, base);
76.1794 + SF2Layer layer = newLayer(sf2, "Clarinet", sample);
76.1795 + SF2Region region = layer.getRegions().get(0);
76.1796 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.1797 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -6000);
76.1798 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, -1000);
76.1799 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
76.1800 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, -100);
76.1801 + region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 9500);
76.1802 + return layer;
76.1803 +
76.1804 + }
76.1805 +
76.1806 + public static SF2Layer new_timpani(SF2Soundbank sf2) {
76.1807 +
76.1808 + double datab[];
76.1809 + double datah[];
76.1810 +
76.1811 + // Make Bass Part
76.1812 + {
76.1813 + int fftlen = 4096 * 8;
76.1814 + double[] data = new double[2 * fftlen];
76.1815 + double base = 48;
76.1816 + complexGaussianDist(data, base * 2, 0.2, 1);
76.1817 + complexGaussianDist(data, base * 3, 0.2, 0.7);
76.1818 + complexGaussianDist(data, base * 5, 10, 1);
76.1819 + complexGaussianDist(data, base * 6, 9, 1);
76.1820 + complexGaussianDist(data, base * 8, 15, 1);
76.1821 + complexGaussianDist(data, base * 9, 18, 0.8);
76.1822 + complexGaussianDist(data, base * 11, 21, 0.5);
76.1823 + complexGaussianDist(data, base * 13, 28, 0.3);
76.1824 + complexGaussianDist(data, base * 14, 22, 0.1);
76.1825 + randomPhase(data, new Random(3049912));
76.1826 + ifft(data);
76.1827 + normalize(data, 0.5);
76.1828 + data = realPart(data);
76.1829 +
76.1830 + double d_len = data.length;
76.1831 + for (int i = 0; i < data.length; i++) {
76.1832 + double g = (1.0 - (i / d_len));
76.1833 + data[i] *= g * g;
76.1834 + }
76.1835 + fadeUp(data, 40);
76.1836 + datab = data;
76.1837 + }
76.1838 +
76.1839 + // Make treble part
76.1840 + {
76.1841 + int fftlen = 4096 * 4;
76.1842 + double[] data = new double[2 * fftlen];
76.1843 + Random random = new Random(3049912);
76.1844 + for (int i = 0; i < data.length; i += 2) {
76.1845 + data[i] = (2.0 * (random.nextDouble() - 0.5)) * 0.1;
76.1846 + }
76.1847 + fft(data);
76.1848 + // Remove all negative frequency
76.1849 + for (int i = fftlen / 2; i < data.length; i++)
76.1850 + data[i] = 0;
76.1851 + for (int i = 1024 * 4; i < 2048 * 4; i++)
76.1852 + data[i] = 1.0 - (i - 4096) / 4096.0;
76.1853 + for (int i = 0; i < 300; i++) {
76.1854 + double g = (1.0 - (i / 300.0));
76.1855 + data[i] *= 1.0 + 20 * g * g;
76.1856 + }
76.1857 + for (int i = 0; i < 24; i++)
76.1858 + data[i] = 0;
76.1859 + randomPhase(data, new Random(3049912));
76.1860 + ifft(data);
76.1861 + normalize(data, 0.9);
76.1862 + data = realPart(data);
76.1863 + double gain = 1.0;
76.1864 + for (int i = 0; i < data.length; i++) {
76.1865 + data[i] *= gain;
76.1866 + gain *= 0.9998;
76.1867 + }
76.1868 + datah = data;
76.1869 + }
76.1870 +
76.1871 + for (int i = 0; i < datah.length; i++)
76.1872 + datab[i] += datah[i] * 0.02;
76.1873 +
76.1874 + normalize(datab, 0.9);
76.1875 +
76.1876 + SF2Sample sample = newSimpleDrumSample(sf2, "Timpani", datab);
76.1877 +
76.1878 + SF2Layer layer = new SF2Layer(sf2);
76.1879 + layer.setName("Timpani");
76.1880 +
76.1881 + SF2GlobalRegion global = new SF2GlobalRegion();
76.1882 + layer.setGlobalZone(global);
76.1883 + sf2.addResource(layer);
76.1884 +
76.1885 + SF2LayerRegion region = new SF2LayerRegion();
76.1886 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 12000);
76.1887 + region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -100);
76.1888 + region.setSample(sample);
76.1889 + layer.getRegions().add(region);
76.1890 +
76.1891 + return layer;
76.1892 + }
76.1893 +
76.1894 + public static SF2Layer new_melodic_toms(SF2Soundbank sf2) {
76.1895 +
76.1896 + double datab[];
76.1897 + double datah[];
76.1898 +
76.1899 + // Make Bass Part
76.1900 + {
76.1901 + int fftlen = 4096 * 4;
76.1902 + double[] data = new double[2 * fftlen];
76.1903 + complexGaussianDist(data, 30, 0.5, 1);
76.1904 + randomPhase(data, new Random(3049912));
76.1905 + ifft(data);
76.1906 + normalize(data, 0.8);
76.1907 + data = realPart(data);
76.1908 +
76.1909 + double d_len = data.length;
76.1910 + for (int i = 0; i < data.length; i++)
76.1911 + data[i] *= (1.0 - (i / d_len));
76.1912 + datab = data;
76.1913 + }
76.1914 +
76.1915 + // Make treble part
76.1916 + {
76.1917 + int fftlen = 4096 * 4;
76.1918 + double[] data = new double[2 * fftlen];
76.1919 + Random random = new Random(3049912);
76.1920 + for (int i = 0; i < data.length; i += 2)
76.1921 + data[i] = (2.0 * (random.nextDouble() - 0.5)) * 0.1;
76.1922 + fft(data);
76.1923 + // Remove all negative frequency
76.1924 + for (int i = fftlen / 2; i < data.length; i++)
76.1925 + data[i] = 0;
76.1926 + for (int i = 1024 * 4; i < 2048 * 4; i++)
76.1927 + data[i] = 1.0 - (i - 4096) / 4096.0;
76.1928 + for (int i = 0; i < 200; i++) {
76.1929 + double g = (1.0 - (i / 200.0));
76.1930 + data[i] *= 1.0 + 20 * g * g;
76.1931 + }
76.1932 + for (int i = 0; i < 30; i++)
76.1933 + data[i] = 0;
76.1934 + randomPhase(data, new Random(3049912));
76.1935 + ifft(data);
76.1936 + normalize(data, 0.9);
76.1937 + data = realPart(data);
76.1938 + double gain = 1.0;
76.1939 + for (int i = 0; i < data.length; i++) {
76.1940 + data[i] *= gain;
76.1941 + gain *= 0.9996;
76.1942 + }
76.1943 + datah = data;
76.1944 + }
76.1945 +
76.1946 + for (int i = 0; i < datah.length; i++)
76.1947 + datab[i] += datah[i] * 0.5;
76.1948 + for (int i = 0; i < 5; i++)
76.1949 + datab[i] *= i / 5.0;
76.1950 +
76.1951 + normalize(datab, 0.99);
76.1952 +
76.1953 + SF2Sample sample = newSimpleDrumSample(sf2, "Melodic Toms", datab);
76.1954 + sample.setOriginalPitch(63);
76.1955 +
76.1956 + SF2Layer layer = new SF2Layer(sf2);
76.1957 + layer.setName("Melodic Toms");
76.1958 +
76.1959 + SF2GlobalRegion global = new SF2GlobalRegion();
76.1960 + layer.setGlobalZone(global);
76.1961 + sf2.addResource(layer);
76.1962 +
76.1963 + SF2LayerRegion region = new SF2LayerRegion();
76.1964 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 12000);
76.1965 + //region.putInteger(SF2Region.GENERATOR_SCALETUNING, 0);
76.1966 + region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -100);
76.1967 + region.setSample(sample);
76.1968 + layer.getRegions().add(region);
76.1969 +
76.1970 + return layer;
76.1971 + }
76.1972 +
76.1973 + public static SF2Layer new_reverse_cymbal(SF2Soundbank sf2) {
76.1974 + double datah[];
76.1975 + {
76.1976 + int fftlen = 4096 * 4;
76.1977 + double[] data = new double[2 * fftlen];
76.1978 + Random random = new Random(3049912);
76.1979 + for (int i = 0; i < data.length; i += 2)
76.1980 + data[i] = (2.0 * (random.nextDouble() - 0.5));
76.1981 + for (int i = fftlen / 2; i < data.length; i++)
76.1982 + data[i] = 0;
76.1983 + for (int i = 0; i < 100; i++)
76.1984 + data[i] = 0;
76.1985 +
76.1986 + for (int i = 0; i < 512 * 2; i++) {
76.1987 + double gain = (i / (512.0 * 2.0));
76.1988 + data[i] = 1 - gain;
76.1989 + }
76.1990 + datah = data;
76.1991 + }
76.1992 +
76.1993 + SF2Sample sample = newSimpleFFTSample(sf2, "Reverse Cymbal",
76.1994 + datah, 100, 20);
76.1995 +
76.1996 + SF2Layer layer = new SF2Layer(sf2);
76.1997 + layer.setName("Reverse Cymbal");
76.1998 +
76.1999 + SF2GlobalRegion global = new SF2GlobalRegion();
76.2000 + layer.setGlobalZone(global);
76.2001 + sf2.addResource(layer);
76.2002 +
76.2003 + SF2LayerRegion region = new SF2LayerRegion();
76.2004 + region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -200);
76.2005 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, -12000);
76.2006 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.2007 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, -1000);
76.2008 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
76.2009 + region.setSample(sample);
76.2010 + layer.getRegions().add(region);
76.2011 +
76.2012 + return layer;
76.2013 + }
76.2014 +
76.2015 + public static SF2Layer new_snare_drum(SF2Soundbank sf2) {
76.2016 +
76.2017 + double datab[];
76.2018 + double datah[];
76.2019 +
76.2020 + // Make Bass Part
76.2021 + {
76.2022 + int fftlen = 4096 * 4;
76.2023 + double[] data = new double[2 * fftlen];
76.2024 + complexGaussianDist(data, 24, 0.5, 1);
76.2025 + randomPhase(data, new Random(3049912));
76.2026 + ifft(data);
76.2027 + normalize(data, 0.5);
76.2028 + data = realPart(data);
76.2029 +
76.2030 + double d_len = data.length;
76.2031 + for (int i = 0; i < data.length; i++)
76.2032 + data[i] *= (1.0 - (i / d_len));
76.2033 + datab = data;
76.2034 + }
76.2035 +
76.2036 + // Make treble part
76.2037 + {
76.2038 + int fftlen = 4096 * 4;
76.2039 + double[] data = new double[2 * fftlen];
76.2040 + Random random = new Random(3049912);
76.2041 + for (int i = 0; i < data.length; i += 2)
76.2042 + data[i] = (2.0 * (random.nextDouble() - 0.5)) * 0.1;
76.2043 + fft(data);
76.2044 + // Remove all negative frequency
76.2045 + for (int i = fftlen / 2; i < data.length; i++)
76.2046 + data[i] = 0;
76.2047 + for (int i = 1024 * 4; i < 2048 * 4; i++)
76.2048 + data[i] = 1.0 - (i - 4096) / 4096.0;
76.2049 + for (int i = 0; i < 300; i++) {
76.2050 + double g = (1.0 - (i / 300.0));
76.2051 + data[i] *= 1.0 + 20 * g * g;
76.2052 + }
76.2053 + for (int i = 0; i < 24; i++)
76.2054 + data[i] = 0;
76.2055 + randomPhase(data, new Random(3049912));
76.2056 + ifft(data);
76.2057 + normalize(data, 0.9);
76.2058 + data = realPart(data);
76.2059 + double gain = 1.0;
76.2060 + for (int i = 0; i < data.length; i++) {
76.2061 + data[i] *= gain;
76.2062 + gain *= 0.9998;
76.2063 + }
76.2064 + datah = data;
76.2065 + }
76.2066 +
76.2067 + for (int i = 0; i < datah.length; i++)
76.2068 + datab[i] += datah[i];
76.2069 + for (int i = 0; i < 5; i++)
76.2070 + datab[i] *= i / 5.0;
76.2071 +
76.2072 + SF2Sample sample = newSimpleDrumSample(sf2, "Snare Drum", datab);
76.2073 +
76.2074 + SF2Layer layer = new SF2Layer(sf2);
76.2075 + layer.setName("Snare Drum");
76.2076 +
76.2077 + SF2GlobalRegion global = new SF2GlobalRegion();
76.2078 + layer.setGlobalZone(global);
76.2079 + sf2.addResource(layer);
76.2080 +
76.2081 + SF2LayerRegion region = new SF2LayerRegion();
76.2082 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 12000);
76.2083 + region.putInteger(SF2Region.GENERATOR_SCALETUNING, 0);
76.2084 + region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -100);
76.2085 + region.setSample(sample);
76.2086 + layer.getRegions().add(region);
76.2087 +
76.2088 + return layer;
76.2089 + }
76.2090 +
76.2091 + public static SF2Layer new_bass_drum(SF2Soundbank sf2) {
76.2092 +
76.2093 + double datab[];
76.2094 + double datah[];
76.2095 +
76.2096 + // Make Bass Part
76.2097 + {
76.2098 + int fftlen = 4096 * 4;
76.2099 + double[] data = new double[2 * fftlen];
76.2100 + complexGaussianDist(data, 1.8 * 5 + 1, 2, 1);
76.2101 + complexGaussianDist(data, 1.8 * 9 + 1, 2, 1);
76.2102 + randomPhase(data, new Random(3049912));
76.2103 + ifft(data);
76.2104 + normalize(data, 0.9);
76.2105 + data = realPart(data);
76.2106 + double d_len = data.length;
76.2107 + for (int i = 0; i < data.length; i++)
76.2108 + data[i] *= (1.0 - (i / d_len));
76.2109 + datab = data;
76.2110 + }
76.2111 +
76.2112 + // Make treble part
76.2113 + {
76.2114 + int fftlen = 4096;
76.2115 + double[] data = new double[2 * fftlen];
76.2116 + Random random = new Random(3049912);
76.2117 + for (int i = 0; i < data.length; i += 2)
76.2118 + data[i] = (2.0 * (random.nextDouble() - 0.5)) * 0.1;
76.2119 + fft(data);
76.2120 + // Remove all negative frequency
76.2121 + for (int i = fftlen / 2; i < data.length; i++)
76.2122 + data[i] = 0;
76.2123 + for (int i = 1024; i < 2048; i++)
76.2124 + data[i] = 1.0 - (i - 1024) / 1024.0;
76.2125 + for (int i = 0; i < 512; i++)
76.2126 + data[i] = 10 * i / 512.0;
76.2127 + for (int i = 0; i < 10; i++)
76.2128 + data[i] = 0;
76.2129 + randomPhase(data, new Random(3049912));
76.2130 + ifft(data);
76.2131 + normalize(data, 0.9);
76.2132 + data = realPart(data);
76.2133 + double gain = 1.0;
76.2134 + for (int i = 0; i < data.length; i++) {
76.2135 + data[i] *= gain;
76.2136 + gain *= 0.999;
76.2137 + }
76.2138 + datah = data;
76.2139 + }
76.2140 +
76.2141 + for (int i = 0; i < datah.length; i++)
76.2142 + datab[i] += datah[i] * 0.5;
76.2143 + for (int i = 0; i < 5; i++)
76.2144 + datab[i] *= i / 5.0;
76.2145 +
76.2146 + SF2Sample sample = newSimpleDrumSample(sf2, "Bass Drum", datab);
76.2147 +
76.2148 + SF2Layer layer = new SF2Layer(sf2);
76.2149 + layer.setName("Bass Drum");
76.2150 +
76.2151 + SF2GlobalRegion global = new SF2GlobalRegion();
76.2152 + layer.setGlobalZone(global);
76.2153 + sf2.addResource(layer);
76.2154 +
76.2155 + SF2LayerRegion region = new SF2LayerRegion();
76.2156 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 12000);
76.2157 + region.putInteger(SF2Region.GENERATOR_SCALETUNING, 0);
76.2158 + region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -100);
76.2159 + region.setSample(sample);
76.2160 + layer.getRegions().add(region);
76.2161 +
76.2162 + return layer;
76.2163 + }
76.2164 +
76.2165 + public static SF2Layer new_tom(SF2Soundbank sf2) {
76.2166 +
76.2167 + double datab[];
76.2168 + double datah[];
76.2169 +
76.2170 + // Make Bass Part
76.2171 + {
76.2172 + int fftlen = 4096 * 4;
76.2173 + double[] data = new double[2 * fftlen];
76.2174 + complexGaussianDist(data, 30, 0.5, 1);
76.2175 + randomPhase(data, new Random(3049912));
76.2176 + ifft(data);
76.2177 + normalize(data, 0.8);
76.2178 + data = realPart(data);
76.2179 +
76.2180 + double d_len = data.length;
76.2181 + for (int i = 0; i < data.length; i++)
76.2182 + data[i] *= (1.0 - (i / d_len));
76.2183 + datab = data;
76.2184 + }
76.2185 +
76.2186 + // Make treble part
76.2187 + {
76.2188 + int fftlen = 4096 * 4;
76.2189 + double[] data = new double[2 * fftlen];
76.2190 + Random random = new Random(3049912);
76.2191 + for (int i = 0; i < data.length; i += 2)
76.2192 + data[i] = (2.0 * (random.nextDouble() - 0.5)) * 0.1;
76.2193 + fft(data);
76.2194 + // Remove all negative frequency
76.2195 + for (int i = fftlen / 2; i < data.length; i++)
76.2196 + data[i] = 0;
76.2197 + for (int i = 1024 * 4; i < 2048 * 4; i++)
76.2198 + data[i] = 1.0 - (i - 4096) / 4096.0;
76.2199 + for (int i = 0; i < 200; i++) {
76.2200 + double g = (1.0 - (i / 200.0));
76.2201 + data[i] *= 1.0 + 20 * g * g;
76.2202 + }
76.2203 + for (int i = 0; i < 30; i++)
76.2204 + data[i] = 0;
76.2205 + randomPhase(data, new Random(3049912));
76.2206 + ifft(data);
76.2207 + normalize(data, 0.9);
76.2208 + data = realPart(data);
76.2209 + double gain = 1.0;
76.2210 + for (int i = 0; i < data.length; i++) {
76.2211 + data[i] *= gain;
76.2212 + gain *= 0.9996;
76.2213 + }
76.2214 + datah = data;
76.2215 + }
76.2216 +
76.2217 + for (int i = 0; i < datah.length; i++)
76.2218 + datab[i] += datah[i] * 0.5;
76.2219 + for (int i = 0; i < 5; i++)
76.2220 + datab[i] *= i / 5.0;
76.2221 +
76.2222 + normalize(datab, 0.99);
76.2223 +
76.2224 + SF2Sample sample = newSimpleDrumSample(sf2, "Tom", datab);
76.2225 + sample.setOriginalPitch(50);
76.2226 +
76.2227 + SF2Layer layer = new SF2Layer(sf2);
76.2228 + layer.setName("Tom");
76.2229 +
76.2230 + SF2GlobalRegion global = new SF2GlobalRegion();
76.2231 + layer.setGlobalZone(global);
76.2232 + sf2.addResource(layer);
76.2233 +
76.2234 + SF2LayerRegion region = new SF2LayerRegion();
76.2235 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 12000);
76.2236 + //region.putInteger(SF2Region.GENERATOR_SCALETUNING, 0);
76.2237 + region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -100);
76.2238 + region.setSample(sample);
76.2239 + layer.getRegions().add(region);
76.2240 +
76.2241 + return layer;
76.2242 + }
76.2243 +
76.2244 + public static SF2Layer new_closed_hihat(SF2Soundbank sf2) {
76.2245 + double datah[];
76.2246 +
76.2247 + // Make treble part
76.2248 + {
76.2249 + int fftlen = 4096 * 4;
76.2250 + double[] data = new double[2 * fftlen];
76.2251 + Random random = new Random(3049912);
76.2252 + for (int i = 0; i < data.length; i += 2)
76.2253 + data[i] = (2.0 * (random.nextDouble() - 0.5)) * 0.1;
76.2254 + fft(data);
76.2255 + // Remove all negative frequency
76.2256 + for (int i = fftlen / 2; i < data.length; i++)
76.2257 + data[i] = 0;
76.2258 + for (int i = 1024 * 4; i < 2048 * 4; i++)
76.2259 + data[i] = 1.0 - (i - 4096) / 4096.0;
76.2260 + for (int i = 0; i < 2048; i++)
76.2261 + data[i] = 0.2 + 0.8 * (i / 2048.0);
76.2262 + randomPhase(data, new Random(3049912));
76.2263 + ifft(data);
76.2264 + normalize(data, 0.9);
76.2265 + data = realPart(data);
76.2266 + double gain = 1.0;
76.2267 + for (int i = 0; i < data.length; i++) {
76.2268 + data[i] *= gain;
76.2269 + gain *= 0.9996;
76.2270 + }
76.2271 + datah = data;
76.2272 + }
76.2273 +
76.2274 + for (int i = 0; i < 5; i++)
76.2275 + datah[i] *= i / 5.0;
76.2276 + SF2Sample sample = newSimpleDrumSample(sf2, "Closed Hi-Hat", datah);
76.2277 +
76.2278 + SF2Layer layer = new SF2Layer(sf2);
76.2279 + layer.setName("Closed Hi-Hat");
76.2280 +
76.2281 + SF2GlobalRegion global = new SF2GlobalRegion();
76.2282 + layer.setGlobalZone(global);
76.2283 + sf2.addResource(layer);
76.2284 +
76.2285 + SF2LayerRegion region = new SF2LayerRegion();
76.2286 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 12000);
76.2287 + region.putInteger(SF2Region.GENERATOR_SCALETUNING, 0);
76.2288 + region.putInteger(SF2Region.GENERATOR_EXCLUSIVECLASS, 1);
76.2289 + region.setSample(sample);
76.2290 + layer.getRegions().add(region);
76.2291 +
76.2292 + return layer;
76.2293 + }
76.2294 +
76.2295 + public static SF2Layer new_open_hihat(SF2Soundbank sf2) {
76.2296 + double datah[];
76.2297 + {
76.2298 + int fftlen = 4096 * 4;
76.2299 + double[] data = new double[2 * fftlen];
76.2300 + Random random = new Random(3049912);
76.2301 + for (int i = 0; i < data.length; i += 2)
76.2302 + data[i] = (2.0 * (random.nextDouble() - 0.5));
76.2303 + for (int i = fftlen / 2; i < data.length; i++)
76.2304 + data[i] = 0;
76.2305 + for (int i = 0; i < 200; i++)
76.2306 + data[i] = 0;
76.2307 + for (int i = 0; i < 2048 * 4; i++) {
76.2308 + double gain = (i / (2048.0 * 4.0));
76.2309 + data[i] = gain;
76.2310 + }
76.2311 + datah = data;
76.2312 + }
76.2313 +
76.2314 + SF2Sample sample = newSimpleFFTSample(sf2, "Open Hi-Hat", datah, 1000, 5);
76.2315 +
76.2316 + SF2Layer layer = new SF2Layer(sf2);
76.2317 + layer.setName("Open Hi-Hat");
76.2318 +
76.2319 + SF2GlobalRegion global = new SF2GlobalRegion();
76.2320 + layer.setGlobalZone(global);
76.2321 + sf2.addResource(layer);
76.2322 +
76.2323 + SF2LayerRegion region = new SF2LayerRegion();
76.2324 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 1500);
76.2325 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.2326 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 1500);
76.2327 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
76.2328 + region.putInteger(SF2Region.GENERATOR_SCALETUNING, 0);
76.2329 + region.putInteger(SF2Region.GENERATOR_EXCLUSIVECLASS, 1);
76.2330 + region.setSample(sample);
76.2331 + layer.getRegions().add(region);
76.2332 +
76.2333 + return layer;
76.2334 + }
76.2335 +
76.2336 + public static SF2Layer new_crash_cymbal(SF2Soundbank sf2) {
76.2337 + double datah[];
76.2338 + {
76.2339 + int fftlen = 4096 * 4;
76.2340 + double[] data = new double[2 * fftlen];
76.2341 + Random random = new Random(3049912);
76.2342 + for (int i = 0; i < data.length; i += 2)
76.2343 + data[i] = (2.0 * (random.nextDouble() - 0.5));
76.2344 + for (int i = fftlen / 2; i < data.length; i++)
76.2345 + data[i] = 0;
76.2346 + for (int i = 0; i < 100; i++)
76.2347 + data[i] = 0;
76.2348 + for (int i = 0; i < 512 * 2; i++) {
76.2349 + double gain = (i / (512.0 * 2.0));
76.2350 + data[i] = gain;
76.2351 + }
76.2352 + datah = data;
76.2353 + }
76.2354 +
76.2355 + SF2Sample sample = newSimpleFFTSample(sf2, "Crash Cymbal", datah, 1000, 5);
76.2356 +
76.2357 + SF2Layer layer = new SF2Layer(sf2);
76.2358 + layer.setName("Crash Cymbal");
76.2359 +
76.2360 + SF2GlobalRegion global = new SF2GlobalRegion();
76.2361 + layer.setGlobalZone(global);
76.2362 + sf2.addResource(layer);
76.2363 +
76.2364 + SF2LayerRegion region = new SF2LayerRegion();
76.2365 + region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 1800);
76.2366 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
76.2367 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 1800);
76.2368 + region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
76.2369 + region.putInteger(SF2Region.GENERATOR_SCALETUNING, 0);
76.2370 + region.setSample(sample);
76.2371 + layer.getRegions().add(region);
76.2372 +
76.2373 + return layer;
76.2374 + }
76.2375 +
76.2376 + public static SF2Layer new_side_stick(SF2Soundbank sf2) {
76.2377 + double datab[];
76.2378 +
76.2379 + // Make treble part
76.2380 + {
76.2381 + int fftlen = 4096 * 4;
76.2382 + double[] data = new double[2 * fftlen];
76.2383 + Random random = new Random(3049912);
76.2384 + for (int i = 0; i < data.length; i += 2)
76.2385 + data[i] = (2.0 * (random.nextDouble() - 0.5)) * 0.1;
76.2386 + fft(data);
76.2387 + // Remove all negative frequency
76.2388 + for (int i = fftlen / 2; i < data.length; i++)
76.2389 + data[i] = 0;
76.2390 + for (int i = 1024 * 4; i < 2048 * 4; i++)
76.2391 + data[i] = 1.0 - (i - 4096) / 4096.0;
76.2392 + for (int i = 0; i < 200; i++) {
76.2393 + double g = (1.0 - (i / 200.0));
76.2394 + data[i] *= 1.0 + 20 * g * g;
76.2395 + }
76.2396 + for (int i = 0; i < 30; i++)
76.2397 + data[i] = 0;
76.2398 + randomPhase(data, new Random(3049912));
76.2399 + ifft(data);
76.2400 + normalize(data, 0.9);
76.2401 + data = realPart(data);
76.2402 + double gain = 1.0;
76.2403 + for (int i = 0; i < data.length; i++) {
76.2404 + data[i] *= gain;
76.2405 + gain *= 0.9996;
76.2406 + }
76.2407 + datab = data;
76.2408 + }
76.2409 +
76.2410 + for (int i = 0; i < 10; i++)
76.2411 + datab[i] *= i / 10.0;
76.2412 +
76.2413 + SF2Sample sample = newSimpleDrumSample(sf2, "Side Stick", datab);
76.2414 +
76.2415 + SF2Layer layer = new SF2Layer(sf2);
76.2416 + layer.setName("Side Stick");
76.2417 +
76.2418 + SF2GlobalRegion global = new SF2GlobalRegion();
76.2419 + layer.setGlobalZone(global);
76.2420 + sf2.addResource(layer);
76.2421 +
76.2422 + SF2LayerRegion region = new SF2LayerRegion();
76.2423 + region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 12000);
76.2424 + region.putInteger(SF2Region.GENERATOR_SCALETUNING, 0);
76.2425 + region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -50);
76.2426 + region.setSample(sample);
76.2427 + layer.getRegions().add(region);
76.2428 +
76.2429 + return layer;
76.2430 +
76.2431 + }
76.2432 +
76.2433 + public static SF2Sample newSimpleFFTSample(SF2Soundbank sf2, String name,
76.2434 + double[] data, double base) {
76.2435 + return newSimpleFFTSample(sf2, name, data, base, 10);
76.2436 + }
76.2437 +
76.2438 + public static SF2Sample newSimpleFFTSample(SF2Soundbank sf2, String name,
76.2439 + double[] data, double base, int fadeuptime) {
76.2440 +
76.2441 + int fftsize = data.length / 2;
76.2442 + AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
76.2443 + double basefreq = (base / fftsize) * format.getSampleRate() * 0.5;
76.2444 +
76.2445 + randomPhase(data);
76.2446 + ifft(data);
76.2447 + data = realPart(data);
76.2448 + normalize(data, 0.9);
76.2449 + float[] fdata = toFloat(data);
76.2450 + fdata = loopExtend(fdata, fdata.length + 512);
76.2451 + fadeUp(fdata, fadeuptime);
76.2452 + byte[] bdata = toBytes(fdata, format);
76.2453 +
76.2454 + /*
76.2455 + * Create SoundFont2 sample.
76.2456 + */
76.2457 + SF2Sample sample = new SF2Sample(sf2);
76.2458 + sample.setName(name);
76.2459 + sample.setData(bdata);
76.2460 + sample.setStartLoop(256);
76.2461 + sample.setEndLoop(fftsize + 256);
76.2462 + sample.setSampleRate((long) format.getSampleRate());
76.2463 + double orgnote = (69 + 12)
76.2464 + + (12 * Math.log(basefreq / 440.0) / Math.log(2));
76.2465 + sample.setOriginalPitch((int) orgnote);
76.2466 + sample.setPitchCorrection((byte) (-(orgnote - (int) orgnote) * 100.0));
76.2467 + sf2.addResource(sample);
76.2468 +
76.2469 + return sample;
76.2470 + }
76.2471 +
76.2472 + public static SF2Sample newSimpleFFTSample_dist(SF2Soundbank sf2,
76.2473 + String name, double[] data, double base, double preamp) {
76.2474 +
76.2475 + int fftsize = data.length / 2;
76.2476 + AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
76.2477 + double basefreq = (base / fftsize) * format.getSampleRate() * 0.5;
76.2478 +
76.2479 + randomPhase(data);
76.2480 + ifft(data);
76.2481 + data = realPart(data);
76.2482 +
76.2483 + for (int i = 0; i < data.length; i++) {
76.2484 + data[i] = (1 - Math.exp(-Math.abs(data[i] * preamp)))
76.2485 + * Math.signum(data[i]);
76.2486 + }
76.2487 +
76.2488 + normalize(data, 0.9);
76.2489 + float[] fdata = toFloat(data);
76.2490 + fdata = loopExtend(fdata, fdata.length + 512);
76.2491 + fadeUp(fdata, 80);
76.2492 + byte[] bdata = toBytes(fdata, format);
76.2493 +
76.2494 + /*
76.2495 + * Create SoundFont2 sample.
76.2496 + */
76.2497 + SF2Sample sample = new SF2Sample(sf2);
76.2498 + sample.setName(name);
76.2499 + sample.setData(bdata);
76.2500 + sample.setStartLoop(256);
76.2501 + sample.setEndLoop(fftsize + 256);
76.2502 + sample.setSampleRate((long) format.getSampleRate());
76.2503 + double orgnote = (69 + 12)
76.2504 + + (12 * Math.log(basefreq / 440.0) / Math.log(2));
76.2505 + sample.setOriginalPitch((int) orgnote);
76.2506 + sample.setPitchCorrection((byte) (-(orgnote - (int) orgnote) * 100.0));
76.2507 + sf2.addResource(sample);
76.2508 +
76.2509 + return sample;
76.2510 + }
76.2511 +
76.2512 + public static SF2Sample newSimpleDrumSample(SF2Soundbank sf2, String name,
76.2513 + double[] data) {
76.2514 +
76.2515 + int fftsize = data.length;
76.2516 + AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
76.2517 +
76.2518 + byte[] bdata = toBytes(toFloat(realPart(data)), format);
76.2519 +
76.2520 + /*
76.2521 + * Create SoundFont2 sample.
76.2522 + */
76.2523 + SF2Sample sample = new SF2Sample(sf2);
76.2524 + sample.setName(name);
76.2525 + sample.setData(bdata);
76.2526 + sample.setStartLoop(256);
76.2527 + sample.setEndLoop(fftsize + 256);
76.2528 + sample.setSampleRate((long) format.getSampleRate());
76.2529 + sample.setOriginalPitch(60);
76.2530 + sf2.addResource(sample);
76.2531 +
76.2532 + return sample;
76.2533 + }
76.2534 +
76.2535 + public static SF2Layer newLayer(SF2Soundbank sf2, String name, SF2Sample sample) {
76.2536 + SF2LayerRegion region = new SF2LayerRegion();
76.2537 + region.setSample(sample);
76.2538 +
76.2539 + SF2Layer layer = new SF2Layer(sf2);
76.2540 + layer.setName(name);
76.2541 + layer.getRegions().add(region);
76.2542 + sf2.addResource(layer);
76.2543 +
76.2544 + return layer;
76.2545 + }
76.2546 +
76.2547 + public static SF2Instrument newInstrument(SF2Soundbank sf2, String name,
76.2548 + Patch patch, SF2Layer... layers) {
76.2549 +
76.2550 + /*
76.2551 + * Create SoundFont2 instrument.
76.2552 + */
76.2553 + SF2Instrument ins = new SF2Instrument(sf2);
76.2554 + ins.setPatch(patch);
76.2555 + ins.setName(name);
76.2556 + sf2.addInstrument(ins);
76.2557 +
76.2558 + /*
76.2559 + * Create region for instrument.
76.2560 + */
76.2561 + for (int i = 0; i < layers.length; i++) {
76.2562 + SF2InstrumentRegion insregion = new SF2InstrumentRegion();
76.2563 + insregion.setLayer(layers[i]);
76.2564 + ins.getRegions().add(insregion);
76.2565 + }
76.2566 +
76.2567 + return ins;
76.2568 + }
76.2569 +
76.2570 + static public void ifft(double[] data) {
76.2571 + new FFT(data.length / 2, 1).transform(data);
76.2572 + }
76.2573 +
76.2574 + static public void fft(double[] data) {
76.2575 + new FFT(data.length / 2, -1).transform(data);
76.2576 + }
76.2577 +
76.2578 + public static void complexGaussianDist(double[] cdata, double m,
76.2579 + double s, double v) {
76.2580 + for (int x = 0; x < cdata.length / 4; x++) {
76.2581 + cdata[x * 2] += v * (1.0 / (s * Math.sqrt(2 * Math.PI))
76.2582 + * Math.exp((-1.0 / 2.0) * Math.pow((x - m) / s, 2.0)));
76.2583 + }
76.2584 + }
76.2585 +
76.2586 + static public void randomPhase(double[] data) {
76.2587 + for (int i = 0; i < data.length; i += 2) {
76.2588 + double phase = Math.random() * 2 * Math.PI;
76.2589 + double d = data[i];
76.2590 + data[i] = Math.sin(phase) * d;
76.2591 + data[i + 1] = Math.cos(phase) * d;
76.2592 + }
76.2593 + }
76.2594 +
76.2595 + static public void randomPhase(double[] data, Random random) {
76.2596 + for (int i = 0; i < data.length; i += 2) {
76.2597 + double phase = random.nextDouble() * 2 * Math.PI;
76.2598 + double d = data[i];
76.2599 + data[i] = Math.sin(phase) * d;
76.2600 + data[i + 1] = Math.cos(phase) * d;
76.2601 + }
76.2602 + }
76.2603 +
76.2604 + static public void normalize(double[] data, double target) {
76.2605 + double maxvalue = 0;
76.2606 + for (int i = 0; i < data.length; i++) {
76.2607 + if (data[i] > maxvalue)
76.2608 + maxvalue = data[i];
76.2609 + if (-data[i] > maxvalue)
76.2610 + maxvalue = -data[i];
76.2611 + }
76.2612 + if (maxvalue == 0)
76.2613 + return;
76.2614 + double gain = target / maxvalue;
76.2615 + for (int i = 0; i < data.length; i++)
76.2616 + data[i] *= gain;
76.2617 + }
76.2618 +
76.2619 + static public void normalize(float[] data, double target) {
76.2620 + double maxvalue = 0.5;
76.2621 + for (int i = 0; i < data.length; i++) {
76.2622 + if (data[i * 2] > maxvalue)
76.2623 + maxvalue = data[i * 2];
76.2624 + if (-data[i * 2] > maxvalue)
76.2625 + maxvalue = -data[i * 2];
76.2626 + }
76.2627 + double gain = target / maxvalue;
76.2628 + for (int i = 0; i < data.length; i++)
76.2629 + data[i * 2] *= gain;
76.2630 + }
76.2631 +
76.2632 + static public double[] realPart(double[] in) {
76.2633 + double[] out = new double[in.length / 2];
76.2634 + for (int i = 0; i < out.length; i++) {
76.2635 + out[i] = in[i * 2];
76.2636 + }
76.2637 + return out;
76.2638 + }
76.2639 +
76.2640 + static public double[] imgPart(double[] in) {
76.2641 + double[] out = new double[in.length / 2];
76.2642 + for (int i = 0; i < out.length; i++) {
76.2643 + out[i] = in[i * 2];
76.2644 + }
76.2645 + return out;
76.2646 + }
76.2647 +
76.2648 + static public float[] toFloat(double[] in) {
76.2649 + float[] out = new float[in.length];
76.2650 + for (int i = 0; i < out.length; i++) {
76.2651 + out[i] = (float) in[i];
76.2652 + }
76.2653 + return out;
76.2654 + }
76.2655 +
76.2656 + static public byte[] toBytes(float[] in, AudioFormat format) {
76.2657 + byte[] out = new byte[in.length * format.getFrameSize()];
76.2658 + return AudioFloatConverter.getConverter(format).toByteArray(in, out);
76.2659 + }
76.2660 +
76.2661 + static public void fadeUp(double[] data, int samples) {
76.2662 + double dsamples = samples;
76.2663 + for (int i = 0; i < samples; i++)
76.2664 + data[i] *= i / dsamples;
76.2665 + }
76.2666 +
76.2667 + static public void fadeUp(float[] data, int samples) {
76.2668 + double dsamples = samples;
76.2669 + for (int i = 0; i < samples; i++)
76.2670 + data[i] *= i / dsamples;
76.2671 + }
76.2672 +
76.2673 + static public double[] loopExtend(double[] data, int newsize) {
76.2674 + double[] outdata = new double[newsize];
76.2675 + int p_len = data.length;
76.2676 + int p_ps = 0;
76.2677 + for (int i = 0; i < outdata.length; i++) {
76.2678 + outdata[i] = data[p_ps];
76.2679 + p_ps++;
76.2680 + if (p_ps == p_len)
76.2681 + p_ps = 0;
76.2682 + }
76.2683 + return outdata;
76.2684 + }
76.2685 +
76.2686 + static public float[] loopExtend(float[] data, int newsize) {
76.2687 + float[] outdata = new float[newsize];
76.2688 + int p_len = data.length;
76.2689 + int p_ps = 0;
76.2690 + for (int i = 0; i < outdata.length; i++) {
76.2691 + outdata[i] = data[p_ps];
76.2692 + p_ps++;
76.2693 + if (p_ps == p_len)
76.2694 + p_ps = 0;
76.2695 + }
76.2696 + return outdata;
76.2697 + }
76.2698 +}
77.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
77.2 +++ b/src/share/classes/com/sun/media/sound/FFT.java Tue Feb 03 22:02:55 2009 -0800
77.3 @@ -0,0 +1,748 @@
77.4 +/*
77.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
77.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
77.7 + *
77.8 + * This code is free software; you can redistribute it and/or modify it
77.9 + * under the terms of the GNU General Public License version 2 only, as
77.10 + * published by the Free Software Foundation. Sun designates this
77.11 + * particular file as subject to the "Classpath" exception as provided
77.12 + * by Sun in the LICENSE file that accompanied this code.
77.13 + *
77.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
77.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
77.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
77.17 + * version 2 for more details (a copy is included in the LICENSE file that
77.18 + * accompanied this code).
77.19 + *
77.20 + * You should have received a copy of the GNU General Public License version
77.21 + * 2 along with this work; if not, write to the Free Software Foundation,
77.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
77.23 + *
77.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
77.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
77.26 + * have any questions.
77.27 + */
77.28 +package com.sun.media.sound;
77.29 +
77.30 +/**
77.31 + * Fast Fourier Transformer.
77.32 + *
77.33 + * @author Karl Helgason
77.34 + */
77.35 +public final class FFT {
77.36 +
77.37 + private double[] w;
77.38 + private int fftFrameSize;
77.39 + private int sign;
77.40 + private int[] bitm_array;
77.41 + private int fftFrameSize2;
77.42 +
77.43 + // Sign = -1 is FFT, 1 is IFFT (inverse FFT)
77.44 + // Data = Interlaced double array to be transformed.
77.45 + // The order is: real (sin), complex (cos)
77.46 + // Framesize must be power of 2
77.47 + public FFT(int fftFrameSize, int sign) {
77.48 + w = computeTwiddleFactors(fftFrameSize, sign);
77.49 +
77.50 + this.fftFrameSize = fftFrameSize;
77.51 + this.sign = sign;
77.52 + fftFrameSize2 = fftFrameSize << 1;
77.53 +
77.54 + // Pre-process Bit-Reversal
77.55 + bitm_array = new int[fftFrameSize2];
77.56 + for (int i = 2; i < fftFrameSize2; i += 2) {
77.57 + int j;
77.58 + int bitm;
77.59 + for (bitm = 2, j = 0; bitm < fftFrameSize2; bitm <<= 1) {
77.60 + if ((i & bitm) != 0)
77.61 + j++;
77.62 + j <<= 1;
77.63 + }
77.64 + bitm_array[i] = j;
77.65 + }
77.66 +
77.67 + }
77.68 +
77.69 + public void transform(double[] data) {
77.70 + bitreversal(data);
77.71 + calc(fftFrameSize, data, sign, w);
77.72 + }
77.73 +
77.74 + private final static double[] computeTwiddleFactors(int fftFrameSize,
77.75 + int sign) {
77.76 +
77.77 + int imax = (int) (Math.log(fftFrameSize) / Math.log(2.));
77.78 +
77.79 + double[] warray = new double[(fftFrameSize - 1) * 4];
77.80 + int w_index = 0;
77.81 +
77.82 + for (int i = 0, nstep = 2; i < imax; i++) {
77.83 + int jmax = nstep;
77.84 + nstep <<= 1;
77.85 +
77.86 + double wr = 1.0;
77.87 + double wi = 0.0;
77.88 +
77.89 + double arg = Math.PI / (jmax >> 1);
77.90 + double wfr = Math.cos(arg);
77.91 + double wfi = sign * Math.sin(arg);
77.92 +
77.93 + for (int j = 0; j < jmax; j += 2) {
77.94 + warray[w_index++] = wr;
77.95 + warray[w_index++] = wi;
77.96 +
77.97 + double tempr = wr;
77.98 + wr = tempr * wfr - wi * wfi;
77.99 + wi = tempr * wfi + wi * wfr;
77.100 + }
77.101 + }
77.102 +
77.103 + // PRECOMPUTATION of wwr1, wwi1 for factor 4 Decomposition (3 * complex
77.104 + // operators and 8 +/- complex operators)
77.105 + {
77.106 + w_index = 0;
77.107 + int w_index2 = warray.length >> 1;
77.108 + for (int i = 0, nstep = 2; i < (imax - 1); i++) {
77.109 + int jmax = nstep;
77.110 + nstep *= 2;
77.111 +
77.112 + int ii = w_index + jmax;
77.113 + for (int j = 0; j < jmax; j += 2) {
77.114 + double wr = warray[w_index++];
77.115 + double wi = warray[w_index++];
77.116 + double wr1 = warray[ii++];
77.117 + double wi1 = warray[ii++];
77.118 + warray[w_index2++] = wr * wr1 - wi * wi1;
77.119 + warray[w_index2++] = wr * wi1 + wi * wr1;
77.120 + }
77.121 + }
77.122 +
77.123 + }
77.124 +
77.125 + return warray;
77.126 + }
77.127 +
77.128 + private final static void calc(int fftFrameSize, double[] data, int sign,
77.129 + double[] w) {
77.130 +
77.131 + final int fftFrameSize2 = fftFrameSize << 1;
77.132 +
77.133 + int nstep = 2;
77.134 +
77.135 + if (nstep >= fftFrameSize2)
77.136 + return;
77.137 + int i = nstep - 2;
77.138 + if (sign == -1)
77.139 + calcF4F(fftFrameSize, data, i, nstep, w);
77.140 + else
77.141 + calcF4I(fftFrameSize, data, i, nstep, w);
77.142 +
77.143 + }
77.144 +
77.145 + private final static void calcF2E(int fftFrameSize, double[] data, int i,
77.146 + int nstep, double[] w) {
77.147 + int jmax = nstep;
77.148 + for (int n = 0; n < jmax; n += 2) {
77.149 + double wr = w[i++];
77.150 + double wi = w[i++];
77.151 + int m = n + jmax;
77.152 + double datam_r = data[m];
77.153 + double datam_i = data[m + 1];
77.154 + double datan_r = data[n];
77.155 + double datan_i = data[n + 1];
77.156 + double tempr = datam_r * wr - datam_i * wi;
77.157 + double tempi = datam_r * wi + datam_i * wr;
77.158 + data[m] = datan_r - tempr;
77.159 + data[m + 1] = datan_i - tempi;
77.160 + data[n] = datan_r + tempr;
77.161 + data[n + 1] = datan_i + tempi;
77.162 + }
77.163 + return;
77.164 +
77.165 + }
77.166 +
77.167 + // Perform Factor-4 Decomposition with 3 * complex operators and 8 +/-
77.168 + // complex operators
77.169 + private final static void calcF4F(int fftFrameSize, double[] data, int i,
77.170 + int nstep, double[] w) {
77.171 + final int fftFrameSize2 = fftFrameSize << 1; // 2*fftFrameSize;
77.172 + // Factor-4 Decomposition
77.173 +
77.174 + int w_len = w.length >> 1;
77.175 + while (nstep < fftFrameSize2) {
77.176 +
77.177 + if (nstep << 2 == fftFrameSize2) {
77.178 + // Goto Factor-4 Final Decomposition
77.179 + // calcF4E(data, i, nstep, -1, w);
77.180 + calcF4FE(fftFrameSize, data, i, nstep, w);
77.181 + return;
77.182 + }
77.183 + int jmax = nstep;
77.184 + int nnstep = nstep << 1;
77.185 + if (nnstep == fftFrameSize2) {
77.186 + // Factor-4 Decomposition not possible
77.187 + calcF2E(fftFrameSize, data, i, nstep, w);
77.188 + return;
77.189 + }
77.190 + nstep <<= 2;
77.191 + int ii = i + jmax;
77.192 + int iii = i + w_len;
77.193 +
77.194 + {
77.195 + i += 2;
77.196 + ii += 2;
77.197 + iii += 2;
77.198 +
77.199 + for (int n = 0; n < fftFrameSize2; n += nstep) {
77.200 + int m = n + jmax;
77.201 +
77.202 + double datam1_r = data[m];
77.203 + double datam1_i = data[m + 1];
77.204 + double datan1_r = data[n];
77.205 + double datan1_i = data[n + 1];
77.206 +
77.207 + n += nnstep;
77.208 + m += nnstep;
77.209 + double datam2_r = data[m];
77.210 + double datam2_i = data[m + 1];
77.211 + double datan2_r = data[n];
77.212 + double datan2_i = data[n + 1];
77.213 +
77.214 + double tempr = datam1_r;
77.215 + double tempi = datam1_i;
77.216 +
77.217 + datam1_r = datan1_r - tempr;
77.218 + datam1_i = datan1_i - tempi;
77.219 + datan1_r = datan1_r + tempr;
77.220 + datan1_i = datan1_i + tempi;
77.221 +
77.222 + double n2w1r = datan2_r;
77.223 + double n2w1i = datan2_i;
77.224 + double m2ww1r = datam2_r;
77.225 + double m2ww1i = datam2_i;
77.226 +
77.227 + tempr = m2ww1r - n2w1r;
77.228 + tempi = m2ww1i - n2w1i;
77.229 +
77.230 + datam2_r = datam1_r + tempi;
77.231 + datam2_i = datam1_i - tempr;
77.232 + datam1_r = datam1_r - tempi;
77.233 + datam1_i = datam1_i + tempr;
77.234 +
77.235 + tempr = n2w1r + m2ww1r;
77.236 + tempi = n2w1i + m2ww1i;
77.237 +
77.238 + datan2_r = datan1_r - tempr;
77.239 + datan2_i = datan1_i - tempi;
77.240 + datan1_r = datan1_r + tempr;
77.241 + datan1_i = datan1_i + tempi;
77.242 +
77.243 + data[m] = datam2_r;
77.244 + data[m + 1] = datam2_i;
77.245 + data[n] = datan2_r;
77.246 + data[n + 1] = datan2_i;
77.247 +
77.248 + n -= nnstep;
77.249 + m -= nnstep;
77.250 + data[m] = datam1_r;
77.251 + data[m + 1] = datam1_i;
77.252 + data[n] = datan1_r;
77.253 + data[n + 1] = datan1_i;
77.254 +
77.255 + }
77.256 + }
77.257 +
77.258 + for (int j = 2; j < jmax; j += 2) {
77.259 + double wr = w[i++];
77.260 + double wi = w[i++];
77.261 + double wr1 = w[ii++];
77.262 + double wi1 = w[ii++];
77.263 + double wwr1 = w[iii++];
77.264 + double wwi1 = w[iii++];
77.265 + // double wwr1 = wr * wr1 - wi * wi1; // these numbers can be
77.266 + // precomputed!!!
77.267 + // double wwi1 = wr * wi1 + wi * wr1;
77.268 +
77.269 + for (int n = j; n < fftFrameSize2; n += nstep) {
77.270 + int m = n + jmax;
77.271 +
77.272 + double datam1_r = data[m];
77.273 + double datam1_i = data[m + 1];
77.274 + double datan1_r = data[n];
77.275 + double datan1_i = data[n + 1];
77.276 +
77.277 + n += nnstep;
77.278 + m += nnstep;
77.279 + double datam2_r = data[m];
77.280 + double datam2_i = data[m + 1];
77.281 + double datan2_r = data[n];
77.282 + double datan2_i = data[n + 1];
77.283 +
77.284 + double tempr = datam1_r * wr - datam1_i * wi;
77.285 + double tempi = datam1_r * wi + datam1_i * wr;
77.286 +
77.287 + datam1_r = datan1_r - tempr;
77.288 + datam1_i = datan1_i - tempi;
77.289 + datan1_r = datan1_r + tempr;
77.290 + datan1_i = datan1_i + tempi;
77.291 +
77.292 + double n2w1r = datan2_r * wr1 - datan2_i * wi1;
77.293 + double n2w1i = datan2_r * wi1 + datan2_i * wr1;
77.294 + double m2ww1r = datam2_r * wwr1 - datam2_i * wwi1;
77.295 + double m2ww1i = datam2_r * wwi1 + datam2_i * wwr1;
77.296 +
77.297 + tempr = m2ww1r - n2w1r;
77.298 + tempi = m2ww1i - n2w1i;
77.299 +
77.300 + datam2_r = datam1_r + tempi;
77.301 + datam2_i = datam1_i - tempr;
77.302 + datam1_r = datam1_r - tempi;
77.303 + datam1_i = datam1_i + tempr;
77.304 +
77.305 + tempr = n2w1r + m2ww1r;
77.306 + tempi = n2w1i + m2ww1i;
77.307 +
77.308 + datan2_r = datan1_r - tempr;
77.309 + datan2_i = datan1_i - tempi;
77.310 + datan1_r = datan1_r + tempr;
77.311 + datan1_i = datan1_i + tempi;
77.312 +
77.313 + data[m] = datam2_r;
77.314 + data[m + 1] = datam2_i;
77.315 + data[n] = datan2_r;
77.316 + data[n + 1] = datan2_i;
77.317 +
77.318 + n -= nnstep;
77.319 + m -= nnstep;
77.320 + data[m] = datam1_r;
77.321 + data[m + 1] = datam1_i;
77.322 + data[n] = datan1_r;
77.323 + data[n + 1] = datan1_i;
77.324 + }
77.325 + }
77.326 +
77.327 + i += jmax << 1;
77.328 +
77.329 + }
77.330 +
77.331 + calcF2E(fftFrameSize, data, i, nstep, w);
77.332 +
77.333 + }
77.334 +
77.335 + // Perform Factor-4 Decomposition with 3 * complex operators and 8 +/-
77.336 + // complex operators
77.337 + private final static void calcF4I(int fftFrameSize, double[] data, int i,
77.338 + int nstep, double[] w) {
77.339 + final int fftFrameSize2 = fftFrameSize << 1; // 2*fftFrameSize;
77.340 + // Factor-4 Decomposition
77.341 +
77.342 + int w_len = w.length >> 1;
77.343 + while (nstep < fftFrameSize2) {
77.344 +
77.345 + if (nstep << 2 == fftFrameSize2) {
77.346 + // Goto Factor-4 Final Decomposition
77.347 + // calcF4E(data, i, nstep, 1, w);
77.348 + calcF4IE(fftFrameSize, data, i, nstep, w);
77.349 + return;
77.350 + }
77.351 + int jmax = nstep;
77.352 + int nnstep = nstep << 1;
77.353 + if (nnstep == fftFrameSize2) {
77.354 + // Factor-4 Decomposition not possible
77.355 + calcF2E(fftFrameSize, data, i, nstep, w);
77.356 + return;
77.357 + }
77.358 + nstep <<= 2;
77.359 + int ii = i + jmax;
77.360 + int iii = i + w_len;
77.361 + {
77.362 + i += 2;
77.363 + ii += 2;
77.364 + iii += 2;
77.365 +
77.366 + for (int n = 0; n < fftFrameSize2; n += nstep) {
77.367 + int m = n + jmax;
77.368 +
77.369 + double datam1_r = data[m];
77.370 + double datam1_i = data[m + 1];
77.371 + double datan1_r = data[n];
77.372 + double datan1_i = data[n + 1];
77.373 +
77.374 + n += nnstep;
77.375 + m += nnstep;
77.376 + double datam2_r = data[m];
77.377 + double datam2_i = data[m + 1];
77.378 + double datan2_r = data[n];
77.379 + double datan2_i = data[n + 1];
77.380 +
77.381 + double tempr = datam1_r;
77.382 + double tempi = datam1_i;
77.383 +
77.384 + datam1_r = datan1_r - tempr;
77.385 + datam1_i = datan1_i - tempi;
77.386 + datan1_r = datan1_r + tempr;
77.387 + datan1_i = datan1_i + tempi;
77.388 +
77.389 + double n2w1r = datan2_r;
77.390 + double n2w1i = datan2_i;
77.391 + double m2ww1r = datam2_r;
77.392 + double m2ww1i = datam2_i;
77.393 +
77.394 + tempr = n2w1r - m2ww1r;
77.395 + tempi = n2w1i - m2ww1i;
77.396 +
77.397 + datam2_r = datam1_r + tempi;
77.398 + datam2_i = datam1_i - tempr;
77.399 + datam1_r = datam1_r - tempi;
77.400 + datam1_i = datam1_i + tempr;
77.401 +
77.402 + tempr = n2w1r + m2ww1r;
77.403 + tempi = n2w1i + m2ww1i;
77.404 +
77.405 + datan2_r = datan1_r - tempr;
77.406 + datan2_i = datan1_i - tempi;
77.407 + datan1_r = datan1_r + tempr;
77.408 + datan1_i = datan1_i + tempi;
77.409 +
77.410 + data[m] = datam2_r;
77.411 + data[m + 1] = datam2_i;
77.412 + data[n] = datan2_r;
77.413 + data[n + 1] = datan2_i;
77.414 +
77.415 + n -= nnstep;
77.416 + m -= nnstep;
77.417 + data[m] = datam1_r;
77.418 + data[m + 1] = datam1_i;
77.419 + data[n] = datan1_r;
77.420 + data[n + 1] = datan1_i;
77.421 +
77.422 + }
77.423 +
77.424 + }
77.425 + for (int j = 2; j < jmax; j += 2) {
77.426 + double wr = w[i++];
77.427 + double wi = w[i++];
77.428 + double wr1 = w[ii++];
77.429 + double wi1 = w[ii++];
77.430 + double wwr1 = w[iii++];
77.431 + double wwi1 = w[iii++];
77.432 + // double wwr1 = wr * wr1 - wi * wi1; // these numbers can be
77.433 + // precomputed!!!
77.434 + // double wwi1 = wr * wi1 + wi * wr1;
77.435 +
77.436 + for (int n = j; n < fftFrameSize2; n += nstep) {
77.437 + int m = n + jmax;
77.438 +
77.439 + double datam1_r = data[m];
77.440 + double datam1_i = data[m + 1];
77.441 + double datan1_r = data[n];
77.442 + double datan1_i = data[n + 1];
77.443 +
77.444 + n += nnstep;
77.445 + m += nnstep;
77.446 + double datam2_r = data[m];
77.447 + double datam2_i = data[m + 1];
77.448 + double datan2_r = data[n];
77.449 + double datan2_i = data[n + 1];
77.450 +
77.451 + double tempr = datam1_r * wr - datam1_i * wi;
77.452 + double tempi = datam1_r * wi + datam1_i * wr;
77.453 +
77.454 + datam1_r = datan1_r - tempr;
77.455 + datam1_i = datan1_i - tempi;
77.456 + datan1_r = datan1_r + tempr;
77.457 + datan1_i = datan1_i + tempi;
77.458 +
77.459 + double n2w1r = datan2_r * wr1 - datan2_i * wi1;
77.460 + double n2w1i = datan2_r * wi1 + datan2_i * wr1;
77.461 + double m2ww1r = datam2_r * wwr1 - datam2_i * wwi1;
77.462 + double m2ww1i = datam2_r * wwi1 + datam2_i * wwr1;
77.463 +
77.464 + tempr = n2w1r - m2ww1r;
77.465 + tempi = n2w1i - m2ww1i;
77.466 +
77.467 + datam2_r = datam1_r + tempi;
77.468 + datam2_i = datam1_i - tempr;
77.469 + datam1_r = datam1_r - tempi;
77.470 + datam1_i = datam1_i + tempr;
77.471 +
77.472 + tempr = n2w1r + m2ww1r;
77.473 + tempi = n2w1i + m2ww1i;
77.474 +
77.475 + datan2_r = datan1_r - tempr;
77.476 + datan2_i = datan1_i - tempi;
77.477 + datan1_r = datan1_r + tempr;
77.478 + datan1_i = datan1_i + tempi;
77.479 +
77.480 + data[m] = datam2_r;
77.481 + data[m + 1] = datam2_i;
77.482 + data[n] = datan2_r;
77.483 + data[n + 1] = datan2_i;
77.484 +
77.485 + n -= nnstep;
77.486 + m -= nnstep;
77.487 + data[m] = datam1_r;
77.488 + data[m + 1] = datam1_i;
77.489 + data[n] = datan1_r;
77.490 + data[n + 1] = datan1_i;
77.491 +
77.492 + }
77.493 + }
77.494 +
77.495 + i += jmax << 1;
77.496 +
77.497 + }
77.498 +
77.499 + calcF2E(fftFrameSize, data, i, nstep, w);
77.500 +
77.501 + }
77.502 +
77.503 + // Perform Factor-4 Decomposition with 3 * complex operators and 8 +/-
77.504 + // complex operators
77.505 + private final static void calcF4FE(int fftFrameSize, double[] data, int i,
77.506 + int nstep, double[] w) {
77.507 + final int fftFrameSize2 = fftFrameSize << 1; // 2*fftFrameSize;
77.508 + // Factor-4 Decomposition
77.509 +
77.510 + int w_len = w.length >> 1;
77.511 + while (nstep < fftFrameSize2) {
77.512 +
77.513 + int jmax = nstep;
77.514 + int nnstep = nstep << 1;
77.515 + if (nnstep == fftFrameSize2) {
77.516 + // Factor-4 Decomposition not possible
77.517 + calcF2E(fftFrameSize, data, i, nstep, w);
77.518 + return;
77.519 + }
77.520 + nstep <<= 2;
77.521 + int ii = i + jmax;
77.522 + int iii = i + w_len;
77.523 + for (int n = 0; n < jmax; n += 2) {
77.524 + double wr = w[i++];
77.525 + double wi = w[i++];
77.526 + double wr1 = w[ii++];
77.527 + double wi1 = w[ii++];
77.528 + double wwr1 = w[iii++];
77.529 + double wwi1 = w[iii++];
77.530 + // double wwr1 = wr * wr1 - wi * wi1; // these numbers can be
77.531 + // precomputed!!!
77.532 + // double wwi1 = wr * wi1 + wi * wr1;
77.533 +
77.534 + int m = n + jmax;
77.535 +
77.536 + double datam1_r = data[m];
77.537 + double datam1_i = data[m + 1];
77.538 + double datan1_r = data[n];
77.539 + double datan1_i = data[n + 1];
77.540 +
77.541 + n += nnstep;
77.542 + m += nnstep;
77.543 + double datam2_r = data[m];
77.544 + double datam2_i = data[m + 1];
77.545 + double datan2_r = data[n];
77.546 + double datan2_i = data[n + 1];
77.547 +
77.548 + double tempr = datam1_r * wr - datam1_i * wi;
77.549 + double tempi = datam1_r * wi + datam1_i * wr;
77.550 +
77.551 + datam1_r = datan1_r - tempr;
77.552 + datam1_i = datan1_i - tempi;
77.553 + datan1_r = datan1_r + tempr;
77.554 + datan1_i = datan1_i + tempi;
77.555 +
77.556 + double n2w1r = datan2_r * wr1 - datan2_i * wi1;
77.557 + double n2w1i = datan2_r * wi1 + datan2_i * wr1;
77.558 + double m2ww1r = datam2_r * wwr1 - datam2_i * wwi1;
77.559 + double m2ww1i = datam2_r * wwi1 + datam2_i * wwr1;
77.560 +
77.561 + tempr = m2ww1r - n2w1r;
77.562 + tempi = m2ww1i - n2w1i;
77.563 +
77.564 + datam2_r = datam1_r + tempi;
77.565 + datam2_i = datam1_i - tempr;
77.566 + datam1_r = datam1_r - tempi;
77.567 + datam1_i = datam1_i + tempr;
77.568 +
77.569 + tempr = n2w1r + m2ww1r;
77.570 + tempi = n2w1i + m2ww1i;
77.571 +
77.572 + datan2_r = datan1_r - tempr;
77.573 + datan2_i = datan1_i - tempi;
77.574 + datan1_r = datan1_r + tempr;
77.575 + datan1_i = datan1_i + tempi;
77.576 +
77.577 + data[m] = datam2_r;
77.578 + data[m + 1] = datam2_i;
77.579 + data[n] = datan2_r;
77.580 + data[n + 1] = datan2_i;
77.581 +
77.582 + n -= nnstep;
77.583 + m -= nnstep;
77.584 + data[m] = datam1_r;
77.585 + data[m + 1] = datam1_i;
77.586 + data[n] = datan1_r;
77.587 + data[n + 1] = datan1_i;
77.588 +
77.589 + }
77.590 +
77.591 + i += jmax << 1;
77.592 +
77.593 + }
77.594 +
77.595 + }
77.596 +
77.597 + // Perform Factor-4 Decomposition with 3 * complex operators and 8 +/-
77.598 + // complex operators
77.599 + private final static void calcF4IE(int fftFrameSize, double[] data, int i,
77.600 + int nstep, double[] w) {
77.601 + final int fftFrameSize2 = fftFrameSize << 1; // 2*fftFrameSize;
77.602 + // Factor-4 Decomposition
77.603 +
77.604 + int w_len = w.length >> 1;
77.605 + while (nstep < fftFrameSize2) {
77.606 +
77.607 + int jmax = nstep;
77.608 + int nnstep = nstep << 1;
77.609 + if (nnstep == fftFrameSize2) {
77.610 + // Factor-4 Decomposition not possible
77.611 + calcF2E(fftFrameSize, data, i, nstep, w);
77.612 + return;
77.613 + }
77.614 + nstep <<= 2;
77.615 + int ii = i + jmax;
77.616 + int iii = i + w_len;
77.617 + for (int n = 0; n < jmax; n += 2) {
77.618 + double wr = w[i++];
77.619 + double wi = w[i++];
77.620 + double wr1 = w[ii++];
77.621 + double wi1 = w[ii++];
77.622 + double wwr1 = w[iii++];
77.623 + double wwi1 = w[iii++];
77.624 + // double wwr1 = wr * wr1 - wi * wi1; // these numbers can be
77.625 + // precomputed!!!
77.626 + // double wwi1 = wr * wi1 + wi * wr1;
77.627 +
77.628 + int m = n + jmax;
77.629 +
77.630 + double datam1_r = data[m];
77.631 + double datam1_i = data[m + 1];
77.632 + double datan1_r = data[n];
77.633 + double datan1_i = data[n + 1];
77.634 +
77.635 + n += nnstep;
77.636 + m += nnstep;
77.637 + double datam2_r = data[m];
77.638 + double datam2_i = data[m + 1];
77.639 + double datan2_r = data[n];
77.640 + double datan2_i = data[n + 1];
77.641 +
77.642 + double tempr = datam1_r * wr - datam1_i * wi;
77.643 + double tempi = datam1_r * wi + datam1_i * wr;
77.644 +
77.645 + datam1_r = datan1_r - tempr;
77.646 + datam1_i = datan1_i - tempi;
77.647 + datan1_r = datan1_r + tempr;
77.648 + datan1_i = datan1_i + tempi;
77.649 +
77.650 + double n2w1r = datan2_r * wr1 - datan2_i * wi1;
77.651 + double n2w1i = datan2_r * wi1 + datan2_i * wr1;
77.652 + double m2ww1r = datam2_r * wwr1 - datam2_i * wwi1;
77.653 + double m2ww1i = datam2_r * wwi1 + datam2_i * wwr1;
77.654 +
77.655 + tempr = n2w1r - m2ww1r;
77.656 + tempi = n2w1i - m2ww1i;
77.657 +
77.658 + datam2_r = datam1_r + tempi;
77.659 + datam2_i = datam1_i - tempr;
77.660 + datam1_r = datam1_r - tempi;
77.661 + datam1_i = datam1_i + tempr;
77.662 +
77.663 + tempr = n2w1r + m2ww1r;
77.664 + tempi = n2w1i + m2ww1i;
77.665 +
77.666 + datan2_r = datan1_r - tempr;
77.667 + datan2_i = datan1_i - tempi;
77.668 + datan1_r = datan1_r + tempr;
77.669 + datan1_i = datan1_i + tempi;
77.670 +
77.671 + data[m] = datam2_r;
77.672 + data[m + 1] = datam2_i;
77.673 + data[n] = datan2_r;
77.674 + data[n + 1] = datan2_i;
77.675 +
77.676 + n -= nnstep;
77.677 + m -= nnstep;
77.678 + data[m] = datam1_r;
77.679 + data[m + 1] = datam1_i;
77.680 + data[n] = datan1_r;
77.681 + data[n + 1] = datan1_i;
77.682 +
77.683 + }
77.684 +
77.685 + i += jmax << 1;
77.686 +
77.687 + }
77.688 +
77.689 + }
77.690 +
77.691 + private final void bitreversal(double[] data) {
77.692 + if (fftFrameSize < 4)
77.693 + return;
77.694 +
77.695 + int inverse = fftFrameSize2 - 2;
77.696 + for (int i = 0; i < fftFrameSize; i += 4) {
77.697 + int j = bitm_array[i];
77.698 +
77.699 + // Performing Bit-Reversal, even v.s. even, O(2N)
77.700 + if (i < j) {
77.701 +
77.702 + int n = i;
77.703 + int m = j;
77.704 +
77.705 + // COMPLEX: SWAP(data[n], data[m])
77.706 + // Real Part
77.707 + double tempr = data[n];
77.708 + data[n] = data[m];
77.709 + data[m] = tempr;
77.710 + // Imagery Part
77.711 + n++;
77.712 + m++;
77.713 + double tempi = data[n];
77.714 + data[n] = data[m];
77.715 + data[m] = tempi;
77.716 +
77.717 + n = inverse - i;
77.718 + m = inverse - j;
77.719 +
77.720 + // COMPLEX: SWAP(data[n], data[m])
77.721 + // Real Part
77.722 + tempr = data[n];
77.723 + data[n] = data[m];
77.724 + data[m] = tempr;
77.725 + // Imagery Part
77.726 + n++;
77.727 + m++;
77.728 + tempi = data[n];
77.729 + data[n] = data[m];
77.730 + data[m] = tempi;
77.731 + }
77.732 +
77.733 + // Performing Bit-Reversal, odd v.s. even, O(N)
77.734 +
77.735 + int m = j + fftFrameSize; // bitm_array[i+2];
77.736 + // COMPLEX: SWAP(data[n], data[m])
77.737 + // Real Part
77.738 + int n = i + 2;
77.739 + double tempr = data[n];
77.740 + data[n] = data[m];
77.741 + data[m] = tempr;
77.742 + // Imagery Part
77.743 + n++;
77.744 + m++;
77.745 + double tempi = data[n];
77.746 + data[n] = data[m];
77.747 + data[m] = tempi;
77.748 + }
77.749 +
77.750 + }
77.751 +}
78.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
78.2 +++ b/src/share/classes/com/sun/media/sound/InvalidDataException.java Tue Feb 03 22:02:55 2009 -0800
78.3 @@ -0,0 +1,45 @@
78.4 +/*
78.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
78.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
78.7 + *
78.8 + * This code is free software; you can redistribute it and/or modify it
78.9 + * under the terms of the GNU General Public License version 2 only, as
78.10 + * published by the Free Software Foundation. Sun designates this
78.11 + * particular file as subject to the "Classpath" exception as provided
78.12 + * by Sun in the LICENSE file that accompanied this code.
78.13 + *
78.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
78.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
78.17 + * version 2 for more details (a copy is included in the LICENSE file that
78.18 + * accompanied this code).
78.19 + *
78.20 + * You should have received a copy of the GNU General Public License version
78.21 + * 2 along with this work; if not, write to the Free Software Foundation,
78.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
78.23 + *
78.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
78.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
78.26 + * have any questions.
78.27 + */
78.28 +package com.sun.media.sound;
78.29 +
78.30 +import java.io.IOException;
78.31 +
78.32 +/**
78.33 + * This exception is used when a file contains illegal or unexpected data.
78.34 + *
78.35 + * @author Karl Helgason
78.36 + */
78.37 +public class InvalidDataException extends IOException {
78.38 +
78.39 + private static final long serialVersionUID = 1L;
78.40 +
78.41 + public InvalidDataException() {
78.42 + super("Invalid Data!");
78.43 + }
78.44 +
78.45 + public InvalidDataException(String s) {
78.46 + super(s);
78.47 + }
78.48 +}
79.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
79.2 +++ b/src/share/classes/com/sun/media/sound/InvalidFormatException.java Tue Feb 03 22:02:55 2009 -0800
79.3 @@ -0,0 +1,44 @@
79.4 +/*
79.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
79.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
79.7 + *
79.8 + * This code is free software; you can redistribute it and/or modify it
79.9 + * under the terms of the GNU General Public License version 2 only, as
79.10 + * published by the Free Software Foundation. Sun designates this
79.11 + * particular file as subject to the "Classpath" exception as provided
79.12 + * by Sun in the LICENSE file that accompanied this code.
79.13 + *
79.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
79.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
79.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
79.17 + * version 2 for more details (a copy is included in the LICENSE file that
79.18 + * accompanied this code).
79.19 + *
79.20 + * You should have received a copy of the GNU General Public License version
79.21 + * 2 along with this work; if not, write to the Free Software Foundation,
79.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
79.23 + *
79.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
79.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
79.26 + * have any questions.
79.27 + */
79.28 +package com.sun.media.sound;
79.29 +
79.30 +/**
79.31 + * This exception is used when a reader is used to read file of a format
79.32 + * it doesn't unterstand or support.
79.33 + *
79.34 + * @author Karl Helgason
79.35 + */
79.36 +public class InvalidFormatException extends InvalidDataException {
79.37 +
79.38 + private static final long serialVersionUID = 1L;
79.39 +
79.40 + public InvalidFormatException() {
79.41 + super("Invalid format!");
79.42 + }
79.43 +
79.44 + public InvalidFormatException(String s) {
79.45 + super(s);
79.46 + }
79.47 +}
80.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
80.2 +++ b/src/share/classes/com/sun/media/sound/JARSoundbankReader.java Tue Feb 03 22:02:55 2009 -0800
80.3 @@ -0,0 +1,120 @@
80.4 +/*
80.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
80.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
80.7 + *
80.8 + * This code is free software; you can redistribute it and/or modify it
80.9 + * under the terms of the GNU General Public License version 2 only, as
80.10 + * published by the Free Software Foundation. Sun designates this
80.11 + * particular file as subject to the "Classpath" exception as provided
80.12 + * by Sun in the LICENSE file that accompanied this code.
80.13 + *
80.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
80.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
80.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
80.17 + * version 2 for more details (a copy is included in the LICENSE file that
80.18 + * accompanied this code).
80.19 + *
80.20 + * You should have received a copy of the GNU General Public License version
80.21 + * 2 along with this work; if not, write to the Free Software Foundation,
80.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
80.23 + *
80.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
80.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
80.26 + * have any questions.
80.27 + */
80.28 +package com.sun.media.sound;
80.29 +
80.30 +import java.io.BufferedReader;
80.31 +import java.io.File;
80.32 +import java.io.IOException;
80.33 +import java.io.InputStream;
80.34 +import java.io.InputStreamReader;
80.35 +import java.net.URL;
80.36 +import java.net.URLClassLoader;
80.37 +import java.util.ArrayList;
80.38 +import javax.sound.midi.InvalidMidiDataException;
80.39 +import javax.sound.midi.Soundbank;
80.40 +import javax.sound.midi.spi.SoundbankReader;
80.41 +
80.42 +/**
80.43 + * JarSoundbankReader is used to read sounbank object from jar files.
80.44 + *
80.45 + * @author Karl Helgason
80.46 + */
80.47 +public class JARSoundbankReader extends SoundbankReader {
80.48 +
80.49 + public boolean isZIP(URL url) {
80.50 + boolean ok = false;
80.51 + try {
80.52 + InputStream stream = url.openStream();
80.53 + try {
80.54 + byte[] buff = new byte[4];
80.55 + ok = stream.read(buff) == 4;
80.56 + if (ok) {
80.57 + ok = (buff[0] == 0x50
80.58 + && buff[1] == 0x4b
80.59 + && buff[2] == 0x03
80.60 + && buff[3] == 0x04);
80.61 + }
80.62 + } finally {
80.63 + stream.close();
80.64 + }
80.65 + } catch (IOException e) {
80.66 + }
80.67 + return ok;
80.68 + }
80.69 +
80.70 + public Soundbank getSoundbank(URL url)
80.71 + throws InvalidMidiDataException, IOException {
80.72 + if (!isZIP(url))
80.73 + return null;
80.74 + ArrayList<Soundbank> soundbanks = new ArrayList<Soundbank>();
80.75 + URLClassLoader ucl = URLClassLoader.newInstance(new URL[]{url});
80.76 + InputStream stream = ucl.getResourceAsStream(
80.77 + "META-INF/services/javax.sound.midi.Soundbank");
80.78 + if (stream == null)
80.79 + return null;
80.80 + try
80.81 + {
80.82 + BufferedReader r = new BufferedReader(new InputStreamReader(stream));
80.83 + String line = r.readLine();
80.84 + while (line != null) {
80.85 + if (!line.startsWith("#")) {
80.86 + try {
80.87 + Class c = Class.forName(line.trim(), true, ucl);
80.88 + Object o = c.newInstance();
80.89 + if (o instanceof Soundbank) {
80.90 + soundbanks.add((Soundbank) o);
80.91 + }
80.92 + } catch (ClassNotFoundException e) {
80.93 + } catch (InstantiationException e) {
80.94 + } catch (IllegalAccessException e) {
80.95 + }
80.96 + }
80.97 + line = r.readLine();
80.98 + }
80.99 + }
80.100 + finally
80.101 + {
80.102 + stream.close();
80.103 + }
80.104 + if (soundbanks.size() == 0)
80.105 + return null;
80.106 + if (soundbanks.size() == 1)
80.107 + return soundbanks.get(0);
80.108 + SimpleSoundbank sbk = new SimpleSoundbank();
80.109 + for (Soundbank soundbank : soundbanks)
80.110 + sbk.addAllInstruments(soundbank);
80.111 + return sbk;
80.112 + }
80.113 +
80.114 + public Soundbank getSoundbank(InputStream stream)
80.115 + throws InvalidMidiDataException, IOException {
80.116 + return null;
80.117 + }
80.118 +
80.119 + public Soundbank getSoundbank(File file)
80.120 + throws InvalidMidiDataException, IOException {
80.121 + return getSoundbank(file.toURI().toURL());
80.122 + }
80.123 +}
81.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
81.2 +++ b/src/share/classes/com/sun/media/sound/ModelAbstractChannelMixer.java Tue Feb 03 22:02:55 2009 -0800
81.3 @@ -0,0 +1,126 @@
81.4 +/*
81.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
81.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
81.7 + *
81.8 + * This code is free software; you can redistribute it and/or modify it
81.9 + * under the terms of the GNU General Public License version 2 only, as
81.10 + * published by the Free Software Foundation. Sun designates this
81.11 + * particular file as subject to the "Classpath" exception as provided
81.12 + * by Sun in the LICENSE file that accompanied this code.
81.13 + *
81.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
81.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
81.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
81.17 + * version 2 for more details (a copy is included in the LICENSE file that
81.18 + * accompanied this code).
81.19 + *
81.20 + * You should have received a copy of the GNU General Public License version
81.21 + * 2 along with this work; if not, write to the Free Software Foundation,
81.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
81.23 + *
81.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
81.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
81.26 + * have any questions.
81.27 + */
81.28 +package com.sun.media.sound;
81.29 +
81.30 +/**
81.31 + * ModelAbstractChannelMixer is ready for use class to implement
81.32 + * ModelChannelMixer interface.
81.33 + *
81.34 + * @author Karl Helgason
81.35 + */
81.36 +public abstract class ModelAbstractChannelMixer implements ModelChannelMixer {
81.37 +
81.38 + public abstract boolean process(float[][] buffer, int offset, int len);
81.39 +
81.40 + public abstract void stop();
81.41 +
81.42 + public void allNotesOff() {
81.43 + }
81.44 +
81.45 + public void allSoundOff() {
81.46 + }
81.47 +
81.48 + public void controlChange(int controller, int value) {
81.49 + }
81.50 +
81.51 + public int getChannelPressure() {
81.52 + return 0;
81.53 + }
81.54 +
81.55 + public int getController(int controller) {
81.56 + return 0;
81.57 + }
81.58 +
81.59 + public boolean getMono() {
81.60 + return false;
81.61 + }
81.62 +
81.63 + public boolean getMute() {
81.64 + return false;
81.65 + }
81.66 +
81.67 + public boolean getOmni() {
81.68 + return false;
81.69 + }
81.70 +
81.71 + public int getPitchBend() {
81.72 + return 0;
81.73 + }
81.74 +
81.75 + public int getPolyPressure(int noteNumber) {
81.76 + return 0;
81.77 + }
81.78 +
81.79 + public int getProgram() {
81.80 + return 0;
81.81 + }
81.82 +
81.83 + public boolean getSolo() {
81.84 + return false;
81.85 + }
81.86 +
81.87 + public boolean localControl(boolean on) {
81.88 + return false;
81.89 + }
81.90 +
81.91 + public void noteOff(int noteNumber) {
81.92 + }
81.93 +
81.94 + public void noteOff(int noteNumber, int velocity) {
81.95 + }
81.96 +
81.97 + public void noteOn(int noteNumber, int velocity) {
81.98 + }
81.99 +
81.100 + public void programChange(int program) {
81.101 + }
81.102 +
81.103 + public void programChange(int bank, int program) {
81.104 + }
81.105 +
81.106 + public void resetAllControllers() {
81.107 + }
81.108 +
81.109 + public void setChannelPressure(int pressure) {
81.110 + }
81.111 +
81.112 + public void setMono(boolean on) {
81.113 + }
81.114 +
81.115 + public void setMute(boolean mute) {
81.116 + }
81.117 +
81.118 + public void setOmni(boolean on) {
81.119 + }
81.120 +
81.121 + public void setPitchBend(int bend) {
81.122 + }
81.123 +
81.124 + public void setPolyPressure(int noteNumber, int pressure) {
81.125 + }
81.126 +
81.127 + public void setSolo(boolean soloState) {
81.128 + }
81.129 +}
82.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
82.2 +++ b/src/share/classes/com/sun/media/sound/ModelAbstractOscillator.java Tue Feb 03 22:02:55 2009 -0800
82.3 @@ -0,0 +1,200 @@
82.4 +/*
82.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
82.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
82.7 + *
82.8 + * This code is free software; you can redistribute it and/or modify it
82.9 + * under the terms of the GNU General Public License version 2 only, as
82.10 + * published by the Free Software Foundation. Sun designates this
82.11 + * particular file as subject to the "Classpath" exception as provided
82.12 + * by Sun in the LICENSE file that accompanied this code.
82.13 + *
82.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
82.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
82.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
82.17 + * version 2 for more details (a copy is included in the LICENSE file that
82.18 + * accompanied this code).
82.19 + *
82.20 + * You should have received a copy of the GNU General Public License version
82.21 + * 2 along with this work; if not, write to the Free Software Foundation,
82.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
82.23 + *
82.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
82.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
82.26 + * have any questions.
82.27 + */
82.28 +package com.sun.media.sound;
82.29 +
82.30 +import java.io.IOException;
82.31 +import javax.sound.midi.Instrument;
82.32 +import javax.sound.midi.MidiChannel;
82.33 +import javax.sound.midi.Patch;
82.34 +import javax.sound.midi.Soundbank;
82.35 +import javax.sound.midi.SoundbankResource;
82.36 +import javax.sound.midi.VoiceStatus;
82.37 +
82.38 +/**
82.39 + * A abstract class used to simplify creating custom ModelOscillator.
82.40 + *
82.41 + * @author Karl Helgason
82.42 + */
82.43 +public abstract class ModelAbstractOscillator
82.44 + implements ModelOscillator, ModelOscillatorStream, Soundbank {
82.45 +
82.46 + protected float pitch = 6000;
82.47 + protected float samplerate;
82.48 + protected MidiChannel channel;
82.49 + protected VoiceStatus voice;
82.50 + protected int noteNumber;
82.51 + protected int velocity;
82.52 + protected boolean on = false;
82.53 +
82.54 + public void init() {
82.55 + }
82.56 +
82.57 + public void close() throws IOException {
82.58 + }
82.59 +
82.60 + public void noteOff(int velocity) {
82.61 + on = false;
82.62 + }
82.63 +
82.64 + public void noteOn(MidiChannel channel, VoiceStatus voice, int noteNumber,
82.65 + int velocity) {
82.66 + this.channel = channel;
82.67 + this.voice = voice;
82.68 + this.noteNumber = noteNumber;
82.69 + this.velocity = velocity;
82.70 + on = true;
82.71 + }
82.72 +
82.73 + public int read(float[][] buffer, int offset, int len) throws IOException {
82.74 + return -1;
82.75 + }
82.76 +
82.77 + public MidiChannel getChannel() {
82.78 + return channel;
82.79 + }
82.80 +
82.81 + public VoiceStatus getVoice() {
82.82 + return voice;
82.83 + }
82.84 +
82.85 + public int getNoteNumber() {
82.86 + return noteNumber;
82.87 + }
82.88 +
82.89 + public int getVelocity() {
82.90 + return velocity;
82.91 + }
82.92 +
82.93 + public boolean isOn() {
82.94 + return on;
82.95 + }
82.96 +
82.97 + public void setPitch(float pitch) {
82.98 + this.pitch = pitch;
82.99 + }
82.100 +
82.101 + public float getPitch() {
82.102 + return pitch;
82.103 + }
82.104 +
82.105 + public void setSampleRate(float samplerate) {
82.106 + this.samplerate = samplerate;
82.107 + }
82.108 +
82.109 + public float getSampleRate() {
82.110 + return samplerate;
82.111 + }
82.112 +
82.113 + public float getAttenuation() {
82.114 + return 0;
82.115 + }
82.116 +
82.117 + public int getChannels() {
82.118 + return 1;
82.119 + }
82.120 +
82.121 + public String getName() {
82.122 + return getClass().getName();
82.123 + }
82.124 +
82.125 + public Patch getPatch() {
82.126 + return new Patch(0, 0);
82.127 + }
82.128 +
82.129 + public ModelOscillatorStream open(float samplerate) {
82.130 + ModelAbstractOscillator oscs;
82.131 + try {
82.132 + oscs = this.getClass().newInstance();
82.133 + } catch (InstantiationException e) {
82.134 + throw new IllegalArgumentException(e);
82.135 + } catch (IllegalAccessException e) {
82.136 + throw new IllegalArgumentException(e);
82.137 + }
82.138 + oscs.setSampleRate(samplerate);
82.139 + oscs.init();
82.140 + return oscs;
82.141 + }
82.142 +
82.143 + public ModelPerformer getPerformer() {
82.144 + // Create performer for my custom oscillirator
82.145 + ModelPerformer performer = new ModelPerformer();
82.146 + performer.getOscillators().add(this);
82.147 + return performer;
82.148 +
82.149 + }
82.150 +
82.151 + public ModelInstrument getInstrument() {
82.152 + // Create Instrument object around my performer
82.153 + SimpleInstrument ins = new SimpleInstrument();
82.154 + ins.setName(getName());
82.155 + ins.add(getPerformer());
82.156 + ins.setPatch(getPatch());
82.157 + return ins;
82.158 +
82.159 + }
82.160 +
82.161 + public Soundbank getSoundBank() {
82.162 + // Create Soundbank object around the instrument
82.163 + SimpleSoundbank sbk = new SimpleSoundbank();
82.164 + sbk.addInstrument(getInstrument());
82.165 + return sbk;
82.166 + }
82.167 +
82.168 + public String getDescription() {
82.169 + return getName();
82.170 + }
82.171 +
82.172 + public Instrument getInstrument(Patch patch) {
82.173 + Instrument ins = getInstrument();
82.174 + Patch p = ins.getPatch();
82.175 + if (p.getBank() != patch.getBank())
82.176 + return null;
82.177 + if (p.getProgram() != patch.getProgram())
82.178 + return null;
82.179 + if (p instanceof ModelPatch && patch instanceof ModelPatch) {
82.180 + if (((ModelPatch)p).isPercussion()
82.181 + != ((ModelPatch)patch).isPercussion()) {
82.182 + return null;
82.183 + }
82.184 + }
82.185 + return ins;
82.186 + }
82.187 +
82.188 + public Instrument[] getInstruments() {
82.189 + return new Instrument[]{getInstrument()};
82.190 + }
82.191 +
82.192 + public SoundbankResource[] getResources() {
82.193 + return new SoundbankResource[0];
82.194 + }
82.195 +
82.196 + public String getVendor() {
82.197 + return null;
82.198 + }
82.199 +
82.200 + public String getVersion() {
82.201 + return null;
82.202 + }
82.203 +}
83.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
83.2 +++ b/src/share/classes/com/sun/media/sound/ModelByteBuffer.java Tue Feb 03 22:02:55 2009 -0800
83.3 @@ -0,0 +1,329 @@
83.4 +/*
83.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
83.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
83.7 + *
83.8 + * This code is free software; you can redistribute it and/or modify it
83.9 + * under the terms of the GNU General Public License version 2 only, as
83.10 + * published by the Free Software Foundation. Sun designates this
83.11 + * particular file as subject to the "Classpath" exception as provided
83.12 + * by Sun in the LICENSE file that accompanied this code.
83.13 + *
83.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
83.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
83.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
83.17 + * version 2 for more details (a copy is included in the LICENSE file that
83.18 + * accompanied this code).
83.19 + *
83.20 + * You should have received a copy of the GNU General Public License version
83.21 + * 2 along with this work; if not, write to the Free Software Foundation,
83.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
83.23 + *
83.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
83.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
83.26 + * have any questions.
83.27 + */
83.28 +package com.sun.media.sound;
83.29 +
83.30 +import java.io.ByteArrayInputStream;
83.31 +import java.io.DataInputStream;
83.32 +import java.io.File;
83.33 +import java.io.IOException;
83.34 +import java.io.InputStream;
83.35 +import java.io.OutputStream;
83.36 +import java.io.RandomAccessFile;
83.37 +import java.util.Collection;
83.38 +
83.39 +/**
83.40 + * This class is a pointer to a binary array either in memory or on disk.
83.41 + *
83.42 + * @author Karl Helgason
83.43 + */
83.44 +public class ModelByteBuffer {
83.45 +
83.46 + private ModelByteBuffer root = this;
83.47 + private File file;
83.48 + private long fileoffset;
83.49 + private byte[] buffer;
83.50 + private long offset;
83.51 + private final long len;
83.52 +
83.53 + private class RandomFileInputStream extends InputStream {
83.54 +
83.55 + private RandomAccessFile raf;
83.56 + private long left;
83.57 + private long mark = 0;
83.58 + private long markleft = 0;
83.59 +
83.60 + public RandomFileInputStream() throws IOException {
83.61 + raf = new RandomAccessFile(root.file, "r");
83.62 + raf.seek(root.fileoffset + arrayOffset());
83.63 + left = capacity();
83.64 + }
83.65 +
83.66 + public int available() throws IOException {
83.67 + if (left > Integer.MAX_VALUE)
83.68 + return Integer.MAX_VALUE;
83.69 + return (int)left;
83.70 + }
83.71 +
83.72 + public synchronized void mark(int readlimit) {
83.73 + try {
83.74 + mark = raf.getFilePointer();
83.75 + markleft = left;
83.76 + } catch (IOException e) {
83.77 + //e.printStackTrace();
83.78 + }
83.79 + }
83.80 +
83.81 + public boolean markSupported() {
83.82 + return true;
83.83 + }
83.84 +
83.85 + public synchronized void reset() throws IOException {
83.86 + raf.seek(mark);
83.87 + left = markleft;
83.88 + }
83.89 +
83.90 + public long skip(long n) throws IOException {
83.91 + if( n < 0)
83.92 + return 0;
83.93 + if (n > left)
83.94 + n = left;
83.95 + long p = raf.getFilePointer();
83.96 + raf.seek(p + n);
83.97 + left -= n;
83.98 + return n;
83.99 + }
83.100 +
83.101 + public int read(byte b[], int off, int len) throws IOException {
83.102 + if (len > left)
83.103 + len = (int)left;
83.104 + if (left == 0)
83.105 + return -1;
83.106 + len = raf.read(b, off, len);
83.107 + if (len == -1)
83.108 + return -1;
83.109 + left -= len;
83.110 + return len;
83.111 + }
83.112 +
83.113 + public int read(byte[] b) throws IOException {
83.114 + int len = b.length;
83.115 + if (len > left)
83.116 + len = (int)left;
83.117 + if (left == 0)
83.118 + return -1;
83.119 + len = raf.read(b, 0, len);
83.120 + if (len == -1)
83.121 + return -1;
83.122 + left -= len;
83.123 + return len;
83.124 + }
83.125 +
83.126 + public int read() throws IOException {
83.127 + if (left == 0)
83.128 + return -1;
83.129 + int b = raf.read();
83.130 + if (b == -1)
83.131 + return -1;
83.132 + left--;
83.133 + return b;
83.134 + }
83.135 +
83.136 + public void close() throws IOException {
83.137 + raf.close();
83.138 + }
83.139 + }
83.140 +
83.141 + private ModelByteBuffer(ModelByteBuffer parent,
83.142 + long beginIndex, long endIndex, boolean independent) {
83.143 + this.root = parent.root;
83.144 + this.offset = 0;
83.145 + long parent_len = parent.len;
83.146 + if (beginIndex < 0)
83.147 + beginIndex = 0;
83.148 + if (beginIndex > parent_len)
83.149 + beginIndex = parent_len;
83.150 + if (endIndex < 0)
83.151 + endIndex = 0;
83.152 + if (endIndex > parent_len)
83.153 + endIndex = parent_len;
83.154 + if (beginIndex > endIndex)
83.155 + beginIndex = endIndex;
83.156 + offset = beginIndex;
83.157 + len = endIndex - beginIndex;
83.158 + if (independent) {
83.159 + buffer = root.buffer;
83.160 + if (root.file != null) {
83.161 + file = root.file;
83.162 + fileoffset = root.fileoffset + arrayOffset();
83.163 + offset = 0;
83.164 + } else
83.165 + offset = arrayOffset();
83.166 + root = this;
83.167 + }
83.168 + }
83.169 +
83.170 + public ModelByteBuffer(byte[] buffer) {
83.171 + this.buffer = buffer;
83.172 + this.offset = 0;
83.173 + this.len = buffer.length;
83.174 + }
83.175 +
83.176 + public ModelByteBuffer(byte[] buffer, int offset, int len) {
83.177 + this.buffer = buffer;
83.178 + this.offset = offset;
83.179 + this.len = len;
83.180 + }
83.181 +
83.182 + public ModelByteBuffer(File file) {
83.183 + this.file = file;
83.184 + this.fileoffset = 0;
83.185 + this.len = file.length();
83.186 + }
83.187 +
83.188 + public ModelByteBuffer(File file, long offset, long len) {
83.189 + this.file = file;
83.190 + this.fileoffset = offset;
83.191 + this.len = len;
83.192 + }
83.193 +
83.194 + public void writeTo(OutputStream out) throws IOException {
83.195 + if (root.file != null && root.buffer == null) {
83.196 + InputStream is = getInputStream();
83.197 + byte[] buff = new byte[1024];
83.198 + int ret;
83.199 + while ((ret = is.read(buff)) != -1)
83.200 + out.write(buff, 0, ret);
83.201 + } else
83.202 + out.write(array(), (int) arrayOffset(), (int) capacity());
83.203 + }
83.204 +
83.205 + public InputStream getInputStream() {
83.206 + if (root.file != null && root.buffer == null) {
83.207 + try {
83.208 + return new RandomFileInputStream();
83.209 + } catch (IOException e) {
83.210 + //e.printStackTrace();
83.211 + return null;
83.212 + }
83.213 + }
83.214 + return new ByteArrayInputStream(array(),
83.215 + (int)arrayOffset(), (int)capacity());
83.216 + }
83.217 +
83.218 + public ModelByteBuffer subbuffer(long beginIndex) {
83.219 + return subbuffer(beginIndex, capacity());
83.220 + }
83.221 +
83.222 + public ModelByteBuffer subbuffer(long beginIndex, long endIndex) {
83.223 + return subbuffer(beginIndex, endIndex, false);
83.224 + }
83.225 +
83.226 + public ModelByteBuffer subbuffer(long beginIndex, long endIndex,
83.227 + boolean independent) {
83.228 + return new ModelByteBuffer(this, beginIndex, endIndex, independent);
83.229 + }
83.230 +
83.231 + public byte[] array() {
83.232 + return root.buffer;
83.233 + }
83.234 +
83.235 + public long arrayOffset() {
83.236 + if (root != this)
83.237 + return root.arrayOffset() + offset;
83.238 + return offset;
83.239 + }
83.240 +
83.241 + public long capacity() {
83.242 + return len;
83.243 + }
83.244 +
83.245 + public ModelByteBuffer getRoot() {
83.246 + return root;
83.247 + }
83.248 +
83.249 + public File getFile() {
83.250 + return file;
83.251 + }
83.252 +
83.253 + public long getFilePointer() {
83.254 + return fileoffset;
83.255 + }
83.256 +
83.257 + public static void loadAll(Collection<ModelByteBuffer> col)
83.258 + throws IOException {
83.259 + File selfile = null;
83.260 + RandomAccessFile raf = null;
83.261 + try {
83.262 + for (ModelByteBuffer mbuff : col) {
83.263 + mbuff = mbuff.root;
83.264 + if (mbuff.file == null)
83.265 + continue;
83.266 + if (mbuff.buffer != null)
83.267 + continue;
83.268 + if (selfile == null || !selfile.equals(mbuff.file)) {
83.269 + if (raf != null) {
83.270 + raf.close();
83.271 + raf = null;
83.272 + }
83.273 + selfile = mbuff.file;
83.274 + raf = new RandomAccessFile(mbuff.file, "r");
83.275 + }
83.276 + raf.seek(mbuff.fileoffset);
83.277 + byte[] buffer = new byte[(int) mbuff.capacity()];
83.278 +
83.279 + int read = 0;
83.280 + int avail = buffer.length;
83.281 + while (read != avail) {
83.282 + if (avail - read > 65536) {
83.283 + raf.readFully(buffer, read, 65536);
83.284 + read += 65536;
83.285 + } else {
83.286 + raf.readFully(buffer, read, avail - read);
83.287 + read = avail;
83.288 + }
83.289 +
83.290 + }
83.291 +
83.292 + mbuff.buffer = buffer;
83.293 + mbuff.offset = 0;
83.294 + }
83.295 + } finally {
83.296 + if (raf != null)
83.297 + raf.close();
83.298 + }
83.299 + }
83.300 +
83.301 + public void load() throws IOException {
83.302 + if (root != this) {
83.303 + root.load();
83.304 + return;
83.305 + }
83.306 + if (buffer != null)
83.307 + return;
83.308 + if (file == null) {
83.309 + throw new IllegalStateException(
83.310 + "No file associated with this ByteBuffer!");
83.311 + }
83.312 +
83.313 + DataInputStream is = new DataInputStream(getInputStream());
83.314 + buffer = new byte[(int) capacity()];
83.315 + offset = 0;
83.316 + is.readFully(buffer);
83.317 + is.close();
83.318 +
83.319 + }
83.320 +
83.321 + public void unload() {
83.322 + if (root != this) {
83.323 + root.unload();
83.324 + return;
83.325 + }
83.326 + if (file == null) {
83.327 + throw new IllegalStateException(
83.328 + "No file associated with this ByteBuffer!");
83.329 + }
83.330 + root.buffer = null;
83.331 + }
83.332 +}
84.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
84.2 +++ b/src/share/classes/com/sun/media/sound/ModelByteBufferWavetable.java Tue Feb 03 22:02:55 2009 -0800
84.3 @@ -0,0 +1,281 @@
84.4 +/*
84.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
84.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
84.7 + *
84.8 + * This code is free software; you can redistribute it and/or modify it
84.9 + * under the terms of the GNU General Public License version 2 only, as
84.10 + * published by the Free Software Foundation. Sun designates this
84.11 + * particular file as subject to the "Classpath" exception as provided
84.12 + * by Sun in the LICENSE file that accompanied this code.
84.13 + *
84.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
84.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
84.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
84.17 + * version 2 for more details (a copy is included in the LICENSE file that
84.18 + * accompanied this code).
84.19 + *
84.20 + * You should have received a copy of the GNU General Public License version
84.21 + * 2 along with this work; if not, write to the Free Software Foundation,
84.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
84.23 + *
84.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
84.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
84.26 + * have any questions.
84.27 + */
84.28 +package com.sun.media.sound;
84.29 +
84.30 +import java.io.IOException;
84.31 +import java.io.InputStream;
84.32 +import javax.sound.sampled.AudioFormat;
84.33 +import javax.sound.sampled.AudioInputStream;
84.34 +import javax.sound.sampled.AudioSystem;
84.35 +import javax.sound.sampled.AudioFormat.Encoding;
84.36 +
84.37 +/**
84.38 + * Wavetable oscillator for pre-loaded data.
84.39 + *
84.40 + * @author Karl Helgason
84.41 + */
84.42 +public class ModelByteBufferWavetable implements ModelWavetable {
84.43 +
84.44 + private class Buffer8PlusInputStream extends InputStream {
84.45 +
84.46 + private boolean bigendian;
84.47 + private int framesize_pc;
84.48 + int pos = 0;
84.49 + int pos2 = 0;
84.50 + int markpos = 0;
84.51 + int markpos2 = 0;
84.52 +
84.53 + public Buffer8PlusInputStream() {
84.54 + framesize_pc = format.getFrameSize() / format.getChannels();
84.55 + bigendian = format.isBigEndian();
84.56 + }
84.57 +
84.58 + public int read(byte[] b, int off, int len) throws IOException {
84.59 + int avail = available();
84.60 + if (avail <= 0)
84.61 + return -1;
84.62 + if (len > avail)
84.63 + len = avail;
84.64 + byte[] buff1 = buffer.array();
84.65 + byte[] buff2 = buffer8.array();
84.66 + pos += buffer.arrayOffset();
84.67 + pos2 += buffer8.arrayOffset();
84.68 + if (bigendian) {
84.69 + for (int i = 0; i < len; i += (framesize_pc + 1)) {
84.70 + System.arraycopy(buff1, pos, b, i, framesize_pc);
84.71 + System.arraycopy(buff2, pos2, b, i + framesize_pc, 1);
84.72 + pos += framesize_pc;
84.73 + pos2 += 1;
84.74 + }
84.75 + } else {
84.76 + for (int i = 0; i < len; i += (framesize_pc + 1)) {
84.77 + System.arraycopy(buff2, pos2, b, i, 1);
84.78 + System.arraycopy(buff1, pos, b, i + 1, framesize_pc);
84.79 + pos += framesize_pc;
84.80 + pos2 += 1;
84.81 + }
84.82 + }
84.83 + pos -= buffer.arrayOffset();
84.84 + pos2 -= buffer8.arrayOffset();
84.85 + return len;
84.86 + }
84.87 +
84.88 + public long skip(long n) throws IOException {
84.89 + int avail = available();
84.90 + if (avail <= 0)
84.91 + return -1;
84.92 + if (n > avail)
84.93 + n = avail;
84.94 + pos += (n / (framesize_pc + 1)) * (framesize_pc);
84.95 + pos2 += n / (framesize_pc + 1);
84.96 + return super.skip(n);
84.97 + }
84.98 +
84.99 + public int read(byte[] b) throws IOException {
84.100 + return read(b, 0, b.length);
84.101 + }
84.102 +
84.103 + public int read() throws IOException {
84.104 + byte[] b = new byte[1];
84.105 + int ret = read(b, 0, 1);
84.106 + if (ret == -1)
84.107 + return -1;
84.108 + return 0 & 0xFF;
84.109 + }
84.110 +
84.111 + public boolean markSupported() {
84.112 + return true;
84.113 + }
84.114 +
84.115 + public int available() throws IOException {
84.116 + return (int)buffer.capacity() + (int)buffer8.capacity() - pos - pos2;
84.117 + }
84.118 +
84.119 + public synchronized void mark(int readlimit) {
84.120 + markpos = pos;
84.121 + markpos2 = pos2;
84.122 + }
84.123 +
84.124 + public synchronized void reset() throws IOException {
84.125 + pos = markpos;
84.126 + pos2 = markpos2;
84.127 +
84.128 + }
84.129 + }
84.130 +
84.131 + private float loopStart = -1;
84.132 + private float loopLength = -1;
84.133 + private ModelByteBuffer buffer;
84.134 + private ModelByteBuffer buffer8 = null;
84.135 + private AudioFormat format = null;
84.136 + private float pitchcorrection = 0;
84.137 + private float attenuation = 0;
84.138 + private int loopType = LOOP_TYPE_OFF;
84.139 +
84.140 + public ModelByteBufferWavetable(ModelByteBuffer buffer) {
84.141 + this.buffer = buffer;
84.142 + }
84.143 +
84.144 + public ModelByteBufferWavetable(ModelByteBuffer buffer,
84.145 + float pitchcorrection) {
84.146 + this.buffer = buffer;
84.147 + this.pitchcorrection = pitchcorrection;
84.148 + }
84.149 +
84.150 + public ModelByteBufferWavetable(ModelByteBuffer buffer, AudioFormat format) {
84.151 + this.format = format;
84.152 + this.buffer = buffer;
84.153 + }
84.154 +
84.155 + public ModelByteBufferWavetable(ModelByteBuffer buffer, AudioFormat format,
84.156 + float pitchcorrection) {
84.157 + this.format = format;
84.158 + this.buffer = buffer;
84.159 + this.pitchcorrection = pitchcorrection;
84.160 + }
84.161 +
84.162 + public void set8BitExtensionBuffer(ModelByteBuffer buffer) {
84.163 + buffer8 = buffer;
84.164 + }
84.165 +
84.166 + public ModelByteBuffer get8BitExtensionBuffer() {
84.167 + return buffer8;
84.168 + }
84.169 +
84.170 + public ModelByteBuffer getBuffer() {
84.171 + return buffer;
84.172 + }
84.173 +
84.174 + public AudioFormat getFormat() {
84.175 + if (format == null) {
84.176 + if (buffer == null)
84.177 + return null;
84.178 + InputStream is = buffer.getInputStream();
84.179 + AudioFormat format = null;
84.180 + try {
84.181 + format = AudioSystem.getAudioFileFormat(is).getFormat();
84.182 + } catch (Exception e) {
84.183 + //e.printStackTrace();
84.184 + }
84.185 + try {
84.186 + is.close();
84.187 + } catch (IOException e) {
84.188 + //e.printStackTrace();
84.189 + }
84.190 + return format;
84.191 + }
84.192 + return format;
84.193 + }
84.194 +
84.195 + public AudioFloatInputStream openStream() {
84.196 + if (buffer == null)
84.197 + return null;
84.198 + if (format == null) {
84.199 + InputStream is = buffer.getInputStream();
84.200 + AudioInputStream ais = null;
84.201 + try {
84.202 + ais = AudioSystem.getAudioInputStream(is);
84.203 + } catch (Exception e) {
84.204 + //e.printStackTrace();
84.205 + return null;
84.206 + }
84.207 + return AudioFloatInputStream.getInputStream(ais);
84.208 + }
84.209 + if (buffer.array() == null) {
84.210 + return AudioFloatInputStream.getInputStream(new AudioInputStream(
84.211 + buffer.getInputStream(), format, buffer.capacity()));
84.212 + }
84.213 + if (buffer8 != null) {
84.214 + if (format.getEncoding().equals(Encoding.PCM_SIGNED)
84.215 + || format.getEncoding().equals(Encoding.PCM_UNSIGNED)) {
84.216 + InputStream is = new Buffer8PlusInputStream();
84.217 + AudioFormat format2 = new AudioFormat(
84.218 + format.getEncoding(),
84.219 + format.getSampleRate(),
84.220 + format.getSampleSizeInBits() + 8,
84.221 + format.getChannels(),
84.222 + format.getFrameSize() + (1 * format.getChannels()),
84.223 + format.getFrameRate(),
84.224 + format.isBigEndian());
84.225 +
84.226 + AudioInputStream ais = new AudioInputStream(is, format2,
84.227 + buffer.capacity() / format.getFrameSize());
84.228 + return AudioFloatInputStream.getInputStream(ais);
84.229 + }
84.230 + }
84.231 + return AudioFloatInputStream.getInputStream(format, buffer.array(),
84.232 + (int)buffer.arrayOffset(), (int)buffer.capacity());
84.233 + }
84.234 +
84.235 + public int getChannels() {
84.236 + return getFormat().getChannels();
84.237 + }
84.238 +
84.239 + public ModelOscillatorStream open(float samplerate) {
84.240 + // ModelWavetableOscillator doesn't support ModelOscillatorStream
84.241 + return null;
84.242 + }
84.243 +
84.244 + // attenuation is in cB
84.245 + public float getAttenuation() {
84.246 + return attenuation;
84.247 + }
84.248 + // attenuation is in cB
84.249 + public void setAttenuation(float attenuation) {
84.250 + this.attenuation = attenuation;
84.251 + }
84.252 +
84.253 + public float getLoopLength() {
84.254 + return loopLength;
84.255 + }
84.256 +
84.257 + public void setLoopLength(float loopLength) {
84.258 + this.loopLength = loopLength;
84.259 + }
84.260 +
84.261 + public float getLoopStart() {
84.262 + return loopStart;
84.263 + }
84.264 +
84.265 + public void setLoopStart(float loopStart) {
84.266 + this.loopStart = loopStart;
84.267 + }
84.268 +
84.269 + public void setLoopType(int loopType) {
84.270 + this.loopType = loopType;
84.271 + }
84.272 +
84.273 + public int getLoopType() {
84.274 + return loopType;
84.275 + }
84.276 +
84.277 + public float getPitchcorrection() {
84.278 + return pitchcorrection;
84.279 + }
84.280 +
84.281 + public void setPitchcorrection(float pitchcorrection) {
84.282 + this.pitchcorrection = pitchcorrection;
84.283 + }
84.284 +}
85.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
85.2 +++ b/src/share/classes/com/sun/media/sound/ModelChannelMixer.java Tue Feb 03 22:02:55 2009 -0800
85.3 @@ -0,0 +1,50 @@
85.4 +/*
85.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
85.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
85.7 + *
85.8 + * This code is free software; you can redistribute it and/or modify it
85.9 + * under the terms of the GNU General Public License version 2 only, as
85.10 + * published by the Free Software Foundation. Sun designates this
85.11 + * particular file as subject to the "Classpath" exception as provided
85.12 + * by Sun in the LICENSE file that accompanied this code.
85.13 + *
85.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
85.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
85.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
85.17 + * version 2 for more details (a copy is included in the LICENSE file that
85.18 + * accompanied this code).
85.19 + *
85.20 + * You should have received a copy of the GNU General Public License version
85.21 + * 2 along with this work; if not, write to the Free Software Foundation,
85.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
85.23 + *
85.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
85.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
85.26 + * have any questions.
85.27 + */
85.28 +package com.sun.media.sound;
85.29 +
85.30 +import javax.sound.midi.MidiChannel;
85.31 +
85.32 +/**
85.33 + * ModelChannelMixer is used to process channel voice mix output before going
85.34 + * to master output.<br>
85.35 + * It can be used to:<br>
85.36 + * <ul>
85.37 + * <li>Implement non-voice oriented instruments.</li>
85.38 + * <li>Add insert effect to instruments; for example distortion effect.</li>
85.39 + * </ui>
85.40 + * <p>
85.41 + * <b>Warning! Classes that implements ModelChannelMixer must be thread-safe.</b>
85.42 + *
85.43 + * @author Karl Helgason
85.44 + */
85.45 +public interface ModelChannelMixer extends MidiChannel {
85.46 +
85.47 + // Used to process input audio from voices mix.
85.48 + public boolean process(float[][] buffer, int offset, int len);
85.49 +
85.50 + // Is used to trigger that this mixer is not be used
85.51 + // and it should fade out.
85.52 + public void stop();
85.53 +}
86.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
86.2 +++ b/src/share/classes/com/sun/media/sound/ModelConnectionBlock.java Tue Feb 03 22:02:55 2009 -0800
86.3 @@ -0,0 +1,135 @@
86.4 +/*
86.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
86.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
86.7 + *
86.8 + * This code is free software; you can redistribute it and/or modify it
86.9 + * under the terms of the GNU General Public License version 2 only, as
86.10 + * published by the Free Software Foundation. Sun designates this
86.11 + * particular file as subject to the "Classpath" exception as provided
86.12 + * by Sun in the LICENSE file that accompanied this code.
86.13 + *
86.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
86.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
86.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
86.17 + * version 2 for more details (a copy is included in the LICENSE file that
86.18 + * accompanied this code).
86.19 + *
86.20 + * You should have received a copy of the GNU General Public License version
86.21 + * 2 along with this work; if not, write to the Free Software Foundation,
86.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
86.23 + *
86.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
86.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
86.26 + * have any questions.
86.27 + */
86.28 +package com.sun.media.sound;
86.29 +
86.30 +/**
86.31 + * Connection blocks are used to connect source variable
86.32 + * to a destination variable.
86.33 + * For example Note On velocity can be connected to output gain.
86.34 + * In DLS this is called articulator and in SoundFonts (SF2) a modulator.
86.35 + *
86.36 + * @author Karl Helgason
86.37 + */
86.38 +public class ModelConnectionBlock {
86.39 +
86.40 + //
86.41 + // source1 * source2 * scale -> destination
86.42 + //
86.43 + private final static ModelSource[] no_sources = new ModelSource[0];
86.44 + private ModelSource[] sources = no_sources;
86.45 + private double scale = 1;
86.46 + private ModelDestination destination;
86.47 +
86.48 + public ModelConnectionBlock() {
86.49 + }
86.50 +
86.51 + public ModelConnectionBlock(double scale, ModelDestination destination) {
86.52 + this.scale = scale;
86.53 + this.destination = destination;
86.54 + }
86.55 +
86.56 + public ModelConnectionBlock(ModelSource source,
86.57 + ModelDestination destination) {
86.58 + if (source != null) {
86.59 + this.sources = new ModelSource[1];
86.60 + this.sources[0] = source;
86.61 + }
86.62 + this.destination = destination;
86.63 + }
86.64 +
86.65 + public ModelConnectionBlock(ModelSource source, double scale,
86.66 + ModelDestination destination) {
86.67 + if (source != null) {
86.68 + this.sources = new ModelSource[1];
86.69 + this.sources[0] = source;
86.70 + }
86.71 + this.scale = scale;
86.72 + this.destination = destination;
86.73 + }
86.74 +
86.75 + public ModelConnectionBlock(ModelSource source, ModelSource control,
86.76 + ModelDestination destination) {
86.77 + if (source != null) {
86.78 + if (control == null) {
86.79 + this.sources = new ModelSource[1];
86.80 + this.sources[0] = source;
86.81 + } else {
86.82 + this.sources = new ModelSource[2];
86.83 + this.sources[0] = source;
86.84 + this.sources[1] = control;
86.85 + }
86.86 + }
86.87 + this.destination = destination;
86.88 + }
86.89 +
86.90 + public ModelConnectionBlock(ModelSource source, ModelSource control,
86.91 + double scale, ModelDestination destination) {
86.92 + if (source != null) {
86.93 + if (control == null) {
86.94 + this.sources = new ModelSource[1];
86.95 + this.sources[0] = source;
86.96 + } else {
86.97 + this.sources = new ModelSource[2];
86.98 + this.sources[0] = source;
86.99 + this.sources[1] = control;
86.100 + }
86.101 + }
86.102 + this.scale = scale;
86.103 + this.destination = destination;
86.104 + }
86.105 +
86.106 + public ModelDestination getDestination() {
86.107 + return destination;
86.108 + }
86.109 +
86.110 + public void setDestination(ModelDestination destination) {
86.111 + this.destination = destination;
86.112 + }
86.113 +
86.114 + public double getScale() {
86.115 + return scale;
86.116 + }
86.117 +
86.118 + public void setScale(double scale) {
86.119 + this.scale = scale;
86.120 + }
86.121 +
86.122 + public ModelSource[] getSources() {
86.123 + return sources;
86.124 + }
86.125 +
86.126 + public void setSources(ModelSource[] source) {
86.127 + this.sources = source;
86.128 + }
86.129 +
86.130 + public void addSource(ModelSource source) {
86.131 + ModelSource[] oldsources = sources;
86.132 + sources = new ModelSource[oldsources.length + 1];
86.133 + for (int i = 0; i < oldsources.length; i++) {
86.134 + sources[i] = oldsources[i];
86.135 + }
86.136 + sources[sources.length - 1] = source;
86.137 + }
86.138 +}
87.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
87.2 +++ b/src/share/classes/com/sun/media/sound/ModelDestination.java Tue Feb 03 22:02:55 2009 -0800
87.3 @@ -0,0 +1,117 @@
87.4 +/*
87.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
87.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
87.7 + *
87.8 + * This code is free software; you can redistribute it and/or modify it
87.9 + * under the terms of the GNU General Public License version 2 only, as
87.10 + * published by the Free Software Foundation. Sun designates this
87.11 + * particular file as subject to the "Classpath" exception as provided
87.12 + * by Sun in the LICENSE file that accompanied this code.
87.13 + *
87.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
87.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
87.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
87.17 + * version 2 for more details (a copy is included in the LICENSE file that
87.18 + * accompanied this code).
87.19 + *
87.20 + * You should have received a copy of the GNU General Public License version
87.21 + * 2 along with this work; if not, write to the Free Software Foundation,
87.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
87.23 + *
87.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
87.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
87.26 + * have any questions.
87.27 + */
87.28 +package com.sun.media.sound;
87.29 +
87.30 +/**
87.31 + * This class is used to identify destinations in connection blocks,
87.32 + * see ModelConnectionBlock.
87.33 + *
87.34 + * @author Karl Helgason
87.35 + */
87.36 +public class ModelDestination {
87.37 +
87.38 + public static final ModelIdentifier DESTINATION_NONE = null;
87.39 + public static final ModelIdentifier DESTINATION_KEYNUMBER
87.40 + = new ModelIdentifier("noteon", "keynumber");
87.41 + public static final ModelIdentifier DESTINATION_VELOCITY
87.42 + = new ModelIdentifier("noteon", "velocity");
87.43 + public static final ModelIdentifier DESTINATION_PITCH
87.44 + = new ModelIdentifier("osc", "pitch"); // cent
87.45 + public static final ModelIdentifier DESTINATION_GAIN
87.46 + = new ModelIdentifier("mixer", "gain"); // cB
87.47 + public static final ModelIdentifier DESTINATION_PAN
87.48 + = new ModelIdentifier("mixer", "pan"); // 0.1 %
87.49 + public static final ModelIdentifier DESTINATION_REVERB
87.50 + = new ModelIdentifier("mixer", "reverb"); // 0.1 %
87.51 + public static final ModelIdentifier DESTINATION_CHORUS
87.52 + = new ModelIdentifier("mixer", "chorus"); // 0.1 %
87.53 + public static final ModelIdentifier DESTINATION_LFO1_DELAY
87.54 + = new ModelIdentifier("lfo", "delay", 0); // timecent
87.55 + public static final ModelIdentifier DESTINATION_LFO1_FREQ
87.56 + = new ModelIdentifier("lfo", "freq", 0); // cent
87.57 + public static final ModelIdentifier DESTINATION_LFO2_DELAY
87.58 + = new ModelIdentifier("lfo", "delay", 1); // timecent
87.59 + public static final ModelIdentifier DESTINATION_LFO2_FREQ
87.60 + = new ModelIdentifier("lfo", "freq", 1); // cent
87.61 + public static final ModelIdentifier DESTINATION_EG1_DELAY
87.62 + = new ModelIdentifier("eg", "delay", 0); // timecent
87.63 + public static final ModelIdentifier DESTINATION_EG1_ATTACK
87.64 + = new ModelIdentifier("eg", "attack", 0); // timecent
87.65 + public static final ModelIdentifier DESTINATION_EG1_HOLD
87.66 + = new ModelIdentifier("eg", "hold", 0); // timecent
87.67 + public static final ModelIdentifier DESTINATION_EG1_DECAY
87.68 + = new ModelIdentifier("eg", "decay", 0); // timecent
87.69 + public static final ModelIdentifier DESTINATION_EG1_SUSTAIN
87.70 + = new ModelIdentifier("eg", "sustain", 0);
87.71 + // 0.1 % (I want this to be value not %)
87.72 + public static final ModelIdentifier DESTINATION_EG1_RELEASE
87.73 + = new ModelIdentifier("eg", "release", 0); // timecent
87.74 + public static final ModelIdentifier DESTINATION_EG1_SHUTDOWN
87.75 + = new ModelIdentifier("eg", "shutdown", 0); // timecent
87.76 + public static final ModelIdentifier DESTINATION_EG2_DELAY
87.77 + = new ModelIdentifier("eg", "delay", 1); // timecent
87.78 + public static final ModelIdentifier DESTINATION_EG2_ATTACK
87.79 + = new ModelIdentifier("eg", "attack", 1); // timecent
87.80 + public static final ModelIdentifier DESTINATION_EG2_HOLD
87.81 + = new ModelIdentifier("eg", "hold", 1); // 0.1 %
87.82 + public static final ModelIdentifier DESTINATION_EG2_DECAY
87.83 + = new ModelIdentifier("eg", "decay", 1); // timecent
87.84 + public static final ModelIdentifier DESTINATION_EG2_SUSTAIN
87.85 + = new ModelIdentifier("eg", "sustain", 1);
87.86 + // 0.1 % ( I want this to be value not %)
87.87 + public static final ModelIdentifier DESTINATION_EG2_RELEASE
87.88 + = new ModelIdentifier("eg", "release", 1); // timecent
87.89 + public static final ModelIdentifier DESTINATION_EG2_SHUTDOWN
87.90 + = new ModelIdentifier("eg", "shutdown", 1); // timecent
87.91 + public static final ModelIdentifier DESTINATION_FILTER_FREQ
87.92 + = new ModelIdentifier("filter", "freq", 0); // cent
87.93 + public static final ModelIdentifier DESTINATION_FILTER_Q
87.94 + = new ModelIdentifier("filter", "q", 0); // cB
87.95 + private ModelIdentifier destination = DESTINATION_NONE;
87.96 + private ModelTransform transform = new ModelStandardTransform();
87.97 +
87.98 + public ModelDestination() {
87.99 + }
87.100 +
87.101 + public ModelDestination(ModelIdentifier id) {
87.102 + destination = id;
87.103 + }
87.104 +
87.105 + public ModelIdentifier getIdentifier() {
87.106 + return destination;
87.107 + }
87.108 +
87.109 + public void setIdentifier(ModelIdentifier destination) {
87.110 + this.destination = destination;
87.111 + }
87.112 +
87.113 + public ModelTransform getTransform() {
87.114 + return transform;
87.115 + }
87.116 +
87.117 + public void setTransform(ModelTransform transform) {
87.118 + this.transform = transform;
87.119 + }
87.120 +}
88.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
88.2 +++ b/src/share/classes/com/sun/media/sound/ModelDirectedPlayer.java Tue Feb 03 22:02:55 2009 -0800
88.3 @@ -0,0 +1,36 @@
88.4 +/*
88.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
88.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
88.7 + *
88.8 + * This code is free software; you can redistribute it and/or modify it
88.9 + * under the terms of the GNU General Public License version 2 only, as
88.10 + * published by the Free Software Foundation. Sun designates this
88.11 + * particular file as subject to the "Classpath" exception as provided
88.12 + * by Sun in the LICENSE file that accompanied this code.
88.13 + *
88.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
88.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
88.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
88.17 + * version 2 for more details (a copy is included in the LICENSE file that
88.18 + * accompanied this code).
88.19 + *
88.20 + * You should have received a copy of the GNU General Public License version
88.21 + * 2 along with this work; if not, write to the Free Software Foundation,
88.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
88.23 + *
88.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
88.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
88.26 + * have any questions.
88.27 + */
88.28 +package com.sun.media.sound;
88.29 +
88.30 +/**
88.31 + * ModelDirectedPlayer is the one who is directed by ModelDirector
88.32 + * to play ModelPerformer objects.
88.33 + *
88.34 + * @author Karl Helgason
88.35 + */
88.36 +public interface ModelDirectedPlayer {
88.37 +
88.38 + public void play(int performerIndex, ModelConnectionBlock[] connectionBlocks);
88.39 +}
89.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
89.2 +++ b/src/share/classes/com/sun/media/sound/ModelDirector.java Tue Feb 03 22:02:55 2009 -0800
89.3 @@ -0,0 +1,46 @@
89.4 +/*
89.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
89.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
89.7 + *
89.8 + * This code is free software; you can redistribute it and/or modify it
89.9 + * under the terms of the GNU General Public License version 2 only, as
89.10 + * published by the Free Software Foundation. Sun designates this
89.11 + * particular file as subject to the "Classpath" exception as provided
89.12 + * by Sun in the LICENSE file that accompanied this code.
89.13 + *
89.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
89.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
89.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
89.17 + * version 2 for more details (a copy is included in the LICENSE file that
89.18 + * accompanied this code).
89.19 + *
89.20 + * You should have received a copy of the GNU General Public License version
89.21 + * 2 along with this work; if not, write to the Free Software Foundation,
89.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
89.23 + *
89.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
89.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
89.26 + * have any questions.
89.27 + */
89.28 +package com.sun.media.sound;
89.29 +
89.30 +/**
89.31 + * A director chooses what performers should be played for each note on
89.32 + * and note off events.
89.33 + *
89.34 + * ModelInstrument can implement custom performer who chooses what performers
89.35 + * to play for example by sustain pedal is off or on.
89.36 + *
89.37 + * The default director (ModelStandardDirector) chooses performers
89.38 + * by there keyfrom,keyto,velfrom,velto properties.
89.39 + *
89.40 + * @author Karl Helgason
89.41 + */
89.42 +public interface ModelDirector {
89.43 +
89.44 + public void noteOn(int noteNumber, int velocity);
89.45 +
89.46 + public void noteOff(int noteNumber, int velocity);
89.47 +
89.48 + public void close();
89.49 +}
90.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
90.2 +++ b/src/share/classes/com/sun/media/sound/ModelIdentifier.java Tue Feb 03 22:02:55 2009 -0800
90.3 @@ -0,0 +1,169 @@
90.4 +/*
90.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
90.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90.7 + *
90.8 + * This code is free software; you can redistribute it and/or modify it
90.9 + * under the terms of the GNU General Public License version 2 only, as
90.10 + * published by the Free Software Foundation. Sun designates this
90.11 + * particular file as subject to the "Classpath" exception as provided
90.12 + * by Sun in the LICENSE file that accompanied this code.
90.13 + *
90.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
90.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
90.17 + * version 2 for more details (a copy is included in the LICENSE file that
90.18 + * accompanied this code).
90.19 + *
90.20 + * You should have received a copy of the GNU General Public License version
90.21 + * 2 along with this work; if not, write to the Free Software Foundation,
90.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90.23 + *
90.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
90.26 + * have any questions.
90.27 + */
90.28 +package com.sun.media.sound;
90.29 +
90.30 +/**
90.31 + * This class stores the identity of source and destinations in connection
90.32 + * blocks, see ModelConnectionBlock.
90.33 + *
90.34 + * @author Karl Helgason
90.35 + */
90.36 +public class ModelIdentifier {
90.37 +
90.38 + /*
90.39 + * Object Variable
90.40 + * ------ --------
90.41 + *
90.42 + * // INPUT parameters
90.43 + * noteon keynumber 7 bit midi value
90.44 + * velocity 7 bit midi vale
90.45 + * on 1 or 0
90.46 + *
90.47 + * midi pitch 14 bit midi value
90.48 + * channel_pressure 7 bit midi value
90.49 + * poly_pressure 7 bit midi value
90.50 + *
90.51 + * midi_cc 0 (midi control #0 7 bit midi value
90.52 + * 1 (midi control #1 7 bit midi value
90.53 + * ...
90.54 + * 127 (midi control #127 7 bit midi value
90.55 + *
90.56 + * midi_rpn 0 (midi rpn control #0) 14 bit midi value
90.57 + * 1 (midi rpn control #1) 14 bit midi value
90.58 + * ....
90.59 + *
90.60 + * // DAHDSR envelope generator
90.61 + * eg (null)
90.62 + * delay timecent
90.63 + * attack timecent
90.64 + * hold timecent
90.65 + * decay timecent
90.66 + * sustain 0.1 %
90.67 + * release timecent
90.68 + *
90.69 + * // Low frequency oscillirator (sine wave)
90.70 + * lfo (null)
90.71 + * delay timcent
90.72 + * freq cent
90.73 + *
90.74 + * // Resonance LowPass Filter 6dB slope
90.75 + * filter (null) (output/input)
90.76 + * freq cent
90.77 + * q cB
90.78 + *
90.79 + * // The oscillator with preloaded wavetable data
90.80 + * osc (null)
90.81 + * pitch cent
90.82 + *
90.83 + * // Output mixer pins
90.84 + * mixer gain cB
90.85 + * pan 0.1 %
90.86 + * reverb 0.1 %
90.87 + * chorus 0.1 %
90.88 + *
90.89 + */
90.90 + private String object = null;
90.91 + private String variable = null;
90.92 + private int instance = 0;
90.93 +
90.94 + public ModelIdentifier(String object) {
90.95 + this.object = object;
90.96 + }
90.97 +
90.98 + public ModelIdentifier(String object, int instance) {
90.99 + this.object = object;
90.100 + this.instance = instance;
90.101 + }
90.102 +
90.103 + public ModelIdentifier(String object, String variable) {
90.104 + this.object = object;
90.105 + this.variable = variable;
90.106 +
90.107 + }
90.108 +
90.109 + public ModelIdentifier(String object, String variable, int instance) {
90.110 + this.object = object;
90.111 + this.variable = variable;
90.112 + this.instance = instance;
90.113 +
90.114 + }
90.115 +
90.116 + public int getInstance() {
90.117 + return instance;
90.118 + }
90.119 +
90.120 + public void setInstance(int instance) {
90.121 + this.instance = instance;
90.122 + }
90.123 +
90.124 + public String getObject() {
90.125 + return object;
90.126 + }
90.127 +
90.128 + public void setObject(String object) {
90.129 + this.object = object;
90.130 + }
90.131 +
90.132 + public String getVariable() {
90.133 + return variable;
90.134 + }
90.135 +
90.136 + public void setVariable(String variable) {
90.137 + this.variable = variable;
90.138 + }
90.139 +
90.140 + public int hashCode() {
90.141 + int hashcode = instance;
90.142 + if(object != null) hashcode |= object.hashCode();
90.143 + if(variable != null) hashcode |= variable.hashCode();
90.144 + return hashcode;
90.145 + }
90.146 +
90.147 + public boolean equals(Object obj) {
90.148 + if (!(obj instanceof ModelIdentifier))
90.149 + return false;
90.150 +
90.151 + ModelIdentifier mobj = (ModelIdentifier)obj;
90.152 + if ((object == null) != (mobj.object == null))
90.153 + return false;
90.154 + if ((variable == null) != (mobj.variable == null))
90.155 + return false;
90.156 + if (mobj.getInstance() != getInstance())
90.157 + return false;
90.158 + if (!(object == null || object.equals(mobj.object)))
90.159 + return false;
90.160 + if (!(variable == null || variable.equals(mobj.variable)))
90.161 + return false;
90.162 + return true;
90.163 + }
90.164 +
90.165 + public String toString() {
90.166 + if (variable == null) {
90.167 + return object + "[" + instance + "]";
90.168 + } else {
90.169 + return object + "[" + instance + "]" + "." + variable;
90.170 + }
90.171 + }
90.172 +}
91.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
91.2 +++ b/src/share/classes/com/sun/media/sound/ModelInstrument.java Tue Feb 03 22:02:55 2009 -0800
91.3 @@ -0,0 +1,136 @@
91.4 +/*
91.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
91.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
91.7 + *
91.8 + * This code is free software; you can redistribute it and/or modify it
91.9 + * under the terms of the GNU General Public License version 2 only, as
91.10 + * published by the Free Software Foundation. Sun designates this
91.11 + * particular file as subject to the "Classpath" exception as provided
91.12 + * by Sun in the LICENSE file that accompanied this code.
91.13 + *
91.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
91.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
91.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
91.17 + * version 2 for more details (a copy is included in the LICENSE file that
91.18 + * accompanied this code).
91.19 + *
91.20 + * You should have received a copy of the GNU General Public License version
91.21 + * 2 along with this work; if not, write to the Free Software Foundation,
91.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
91.23 + *
91.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
91.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
91.26 + * have any questions.
91.27 + */
91.28 +package com.sun.media.sound;
91.29 +
91.30 +import javax.sound.midi.Instrument;
91.31 +import javax.sound.midi.MidiChannel;
91.32 +import javax.sound.midi.Patch;
91.33 +import javax.sound.midi.Soundbank;
91.34 +import javax.sound.sampled.AudioFormat;
91.35 +
91.36 +/**
91.37 + * The model instrument class.
91.38 + *
91.39 + * <p>The main methods to override are:<br>
91.40 + * getPerformer, getDirector, getChannelMixer.
91.41 + *
91.42 + * <p>Performers are used to define what voices which will
91.43 + * playback when using the instrument.<br>
91.44 + *
91.45 + * ChannelMixer is used to add channel-wide processing
91.46 + * on voices output or to define non-voice oriented instruments.<br>
91.47 + *
91.48 + * Director is used to change how the synthesizer
91.49 + * chooses what performers to play on midi events.
91.50 + *
91.51 + * @author Karl Helgason
91.52 + */
91.53 +public abstract class ModelInstrument extends Instrument {
91.54 +
91.55 + protected ModelInstrument(Soundbank soundbank, Patch patch, String name,
91.56 + Class<?> dataClass) {
91.57 + super(soundbank, patch, name, dataClass);
91.58 + }
91.59 +
91.60 + public ModelDirector getDirector(ModelPerformer[] performers,
91.61 + MidiChannel channel, ModelDirectedPlayer player) {
91.62 + return new ModelStandardDirector(performers, player);
91.63 + }
91.64 +
91.65 + public ModelPerformer[] getPerformers() {
91.66 + return new ModelPerformer[0];
91.67 + }
91.68 +
91.69 + public ModelChannelMixer getChannelMixer(MidiChannel channel,
91.70 + AudioFormat format) {
91.71 + return null;
91.72 + }
91.73 +
91.74 + // Get General MIDI 2 Alias patch for this instrument.
91.75 + public Patch getPatchAlias() {
91.76 + Patch patch = getPatch();
91.77 + int program = patch.getProgram();
91.78 + int bank = patch.getBank();
91.79 + if (bank != 0)
91.80 + return patch;
91.81 + boolean percussion = false;
91.82 + if (getPatch() instanceof ModelPatch)
91.83 + percussion = ((ModelPatch)getPatch()).isPercussion();
91.84 + if (percussion)
91.85 + return new Patch(0x78 << 7, program);
91.86 + else
91.87 + return new Patch(0x79 << 7, program);
91.88 + }
91.89 +
91.90 + // Return name of all the keys.
91.91 + // This information is generated from ModelPerformer.getName()
91.92 + // returned from getPerformers().
91.93 + public String[] getKeys() {
91.94 + String[] keys = new String[128];
91.95 + for (ModelPerformer performer : getPerformers()) {
91.96 + for (int k = performer.getKeyFrom(); k <= performer.getKeyTo(); k++) {
91.97 + if (k >= 0 && k < 128 && keys[k] == null) {
91.98 + String name = performer.getName();
91.99 + if (name == null)
91.100 + name = "untitled";
91.101 + keys[k] = name;
91.102 + }
91.103 + }
91.104 + }
91.105 + return keys;
91.106 + }
91.107 +
91.108 + // Return what channels this instrument will probably response
91.109 + // on General MIDI synthesizer.
91.110 + public boolean[] getChannels() {
91.111 + boolean percussion = false;
91.112 + if (getPatch() instanceof ModelPatch)
91.113 + percussion = ((ModelPatch)getPatch()).isPercussion();
91.114 +
91.115 + // Check if instrument is percussion.
91.116 + if (percussion) {
91.117 + boolean[] ch = new boolean[16];
91.118 + for (int i = 0; i < ch.length; i++)
91.119 + ch[i] = false;
91.120 + ch[9] = true;
91.121 + return ch;
91.122 + }
91.123 +
91.124 + // Check if instrument uses General MIDI 2 default banks.
91.125 + int bank = getPatch().getBank();
91.126 + if (bank >> 7 == 0x78 || bank >> 7 == 0x79) {
91.127 + boolean[] ch = new boolean[16];
91.128 + for (int i = 0; i < ch.length; i++)
91.129 + ch[i] = true;
91.130 + return ch;
91.131 + }
91.132 +
91.133 + boolean[] ch = new boolean[16];
91.134 + for (int i = 0; i < ch.length; i++)
91.135 + ch[i] = true;
91.136 + ch[9] = false;
91.137 + return ch;
91.138 + }
91.139 +}
92.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
92.2 +++ b/src/share/classes/com/sun/media/sound/ModelInstrumentComparator.java Tue Feb 03 22:02:55 2009 -0800
92.3 @@ -0,0 +1,52 @@
92.4 +/*
92.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
92.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
92.7 + *
92.8 + * This code is free software; you can redistribute it and/or modify it
92.9 + * under the terms of the GNU General Public License version 2 only, as
92.10 + * published by the Free Software Foundation. Sun designates this
92.11 + * particular file as subject to the "Classpath" exception as provided
92.12 + * by Sun in the LICENSE file that accompanied this code.
92.13 + *
92.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
92.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
92.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
92.17 + * version 2 for more details (a copy is included in the LICENSE file that
92.18 + * accompanied this code).
92.19 + *
92.20 + * You should have received a copy of the GNU General Public License version
92.21 + * 2 along with this work; if not, write to the Free Software Foundation,
92.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
92.23 + *
92.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
92.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
92.26 + * have any questions.
92.27 + */
92.28 +package com.sun.media.sound;
92.29 +
92.30 +import java.util.Comparator;
92.31 +import javax.sound.midi.Instrument;
92.32 +import javax.sound.midi.Patch;
92.33 +
92.34 +/**
92.35 + * Instrument comparator class.
92.36 + * Used to order instrument by program, bank, percussion.
92.37 + *
92.38 + * @author Karl Helgason
92.39 + */
92.40 +public class ModelInstrumentComparator implements Comparator<Instrument> {
92.41 +
92.42 + public int compare(Instrument arg0, Instrument arg1) {
92.43 + Patch p0 = arg0.getPatch();
92.44 + Patch p1 = arg1.getPatch();
92.45 + int a = p0.getBank() * 128 + p0.getProgram();
92.46 + int b = p1.getBank() * 128 + p1.getProgram();
92.47 + if (p0 instanceof ModelPatch) {
92.48 + a += ((ModelPatch)p0).isPercussion() ? 2097152 : 0;
92.49 + }
92.50 + if (p1 instanceof ModelPatch) {
92.51 + b += ((ModelPatch)p1).isPercussion() ? 2097152 : 0;
92.52 + }
92.53 + return a - b;
92.54 + }
92.55 +}
93.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
93.2 +++ b/src/share/classes/com/sun/media/sound/ModelMappedInstrument.java Tue Feb 03 22:02:55 2009 -0800
93.3 @@ -0,0 +1,62 @@
93.4 +/*
93.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
93.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
93.7 + *
93.8 + * This code is free software; you can redistribute it and/or modify it
93.9 + * under the terms of the GNU General Public License version 2 only, as
93.10 + * published by the Free Software Foundation. Sun designates this
93.11 + * particular file as subject to the "Classpath" exception as provided
93.12 + * by Sun in the LICENSE file that accompanied this code.
93.13 + *
93.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
93.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
93.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
93.17 + * version 2 for more details (a copy is included in the LICENSE file that
93.18 + * accompanied this code).
93.19 + *
93.20 + * You should have received a copy of the GNU General Public License version
93.21 + * 2 along with this work; if not, write to the Free Software Foundation,
93.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
93.23 + *
93.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
93.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
93.26 + * have any questions.
93.27 + */
93.28 +package com.sun.media.sound;
93.29 +
93.30 +import javax.sound.midi.MidiChannel;
93.31 +import javax.sound.midi.Patch;
93.32 +import javax.sound.sampled.AudioFormat;
93.33 +
93.34 +/**
93.35 + * This class is used to map instrument to another patch.
93.36 + *
93.37 + * @author Karl Helgason
93.38 + */
93.39 +public class ModelMappedInstrument extends ModelInstrument {
93.40 +
93.41 + private ModelInstrument ins;
93.42 +
93.43 + public ModelMappedInstrument(ModelInstrument ins, Patch patch) {
93.44 + super(ins.getSoundbank(), patch, ins.getName(), ins.getDataClass());
93.45 + this.ins = ins;
93.46 + }
93.47 +
93.48 + public Object getData() {
93.49 + return ins.getData();
93.50 + }
93.51 +
93.52 + public ModelPerformer[] getPerformers() {
93.53 + return ins.getPerformers();
93.54 + }
93.55 +
93.56 + public ModelDirector getDirector(ModelPerformer[] performers,
93.57 + MidiChannel channel, ModelDirectedPlayer player) {
93.58 + return ins.getDirector(performers, channel, player);
93.59 + }
93.60 +
93.61 + public ModelChannelMixer getChannelMixer(MidiChannel channel,
93.62 + AudioFormat format) {
93.63 + return ins.getChannelMixer(channel, format);
93.64 + }
93.65 +}
94.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
94.2 +++ b/src/share/classes/com/sun/media/sound/ModelOscillator.java Tue Feb 03 22:02:55 2009 -0800
94.3 @@ -0,0 +1,44 @@
94.4 +/*
94.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
94.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
94.7 + *
94.8 + * This code is free software; you can redistribute it and/or modify it
94.9 + * under the terms of the GNU General Public License version 2 only, as
94.10 + * published by the Free Software Foundation. Sun designates this
94.11 + * particular file as subject to the "Classpath" exception as provided
94.12 + * by Sun in the LICENSE file that accompanied this code.
94.13 + *
94.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
94.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
94.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
94.17 + * version 2 for more details (a copy is included in the LICENSE file that
94.18 + * accompanied this code).
94.19 + *
94.20 + * You should have received a copy of the GNU General Public License version
94.21 + * 2 along with this work; if not, write to the Free Software Foundation,
94.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
94.23 + *
94.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
94.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
94.26 + * have any questions.
94.27 + */
94.28 +package com.sun.media.sound;
94.29 +
94.30 +/**
94.31 + * This interface is used for oscillators.
94.32 + * See example in ModelDefaultOscillator which is a wavetable oscillator.
94.33 + *
94.34 + * @author Karl Helgason
94.35 + */
94.36 +public interface ModelOscillator {
94.37 +
94.38 + public int getChannels();
94.39 +
94.40 + /**
94.41 + * Attenuation is in cB.
94.42 + * @return
94.43 + */
94.44 + public float getAttenuation();
94.45 +
94.46 + public ModelOscillatorStream open(float samplerate);
94.47 +}
95.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
95.2 +++ b/src/share/classes/com/sun/media/sound/ModelOscillatorStream.java Tue Feb 03 22:02:55 2009 -0800
95.3 @@ -0,0 +1,48 @@
95.4 +/*
95.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
95.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
95.7 + *
95.8 + * This code is free software; you can redistribute it and/or modify it
95.9 + * under the terms of the GNU General Public License version 2 only, as
95.10 + * published by the Free Software Foundation. Sun designates this
95.11 + * particular file as subject to the "Classpath" exception as provided
95.12 + * by Sun in the LICENSE file that accompanied this code.
95.13 + *
95.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
95.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
95.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
95.17 + * version 2 for more details (a copy is included in the LICENSE file that
95.18 + * accompanied this code).
95.19 + *
95.20 + * You should have received a copy of the GNU General Public License version
95.21 + * 2 along with this work; if not, write to the Free Software Foundation,
95.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
95.23 + *
95.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
95.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
95.26 + * have any questions.
95.27 + */
95.28 +package com.sun.media.sound;
95.29 +
95.30 +import java.io.IOException;
95.31 +import javax.sound.midi.MidiChannel;
95.32 +import javax.sound.midi.VoiceStatus;
95.33 +
95.34 +/**
95.35 + * This interface is used for audio streams from ModelOscillator.
95.36 + *
95.37 + * @author Karl Helgason
95.38 + */
95.39 +public interface ModelOscillatorStream {
95.40 +
95.41 + public void setPitch(float pitch); // Pitch is in cents!
95.42 +
95.43 + public void noteOn(MidiChannel channel, VoiceStatus voice, int noteNumber,
95.44 + int velocity);
95.45 +
95.46 + public void noteOff(int velocity);
95.47 +
95.48 + public int read(float[][] buffer, int offset, int len) throws IOException;
95.49 +
95.50 + public void close() throws IOException;
95.51 +}
96.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
96.2 +++ b/src/share/classes/com/sun/media/sound/ModelPatch.java Tue Feb 03 22:02:55 2009 -0800
96.3 @@ -0,0 +1,52 @@
96.4 +/*
96.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
96.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
96.7 + *
96.8 + * This code is free software; you can redistribute it and/or modify it
96.9 + * under the terms of the GNU General Public License version 2 only, as
96.10 + * published by the Free Software Foundation. Sun designates this
96.11 + * particular file as subject to the "Classpath" exception as provided
96.12 + * by Sun in the LICENSE file that accompanied this code.
96.13 + *
96.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
96.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
96.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
96.17 + * version 2 for more details (a copy is included in the LICENSE file that
96.18 + * accompanied this code).
96.19 + *
96.20 + * You should have received a copy of the GNU General Public License version
96.21 + * 2 along with this work; if not, write to the Free Software Foundation,
96.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
96.23 + *
96.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
96.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
96.26 + * have any questions.
96.27 + */
96.28 +package com.sun.media.sound;
96.29 +
96.30 +import javax.sound.midi.Patch;
96.31 +
96.32 +/**
96.33 + * A extended patch object that has isPercussion function.
96.34 + * Which is necessary to identify percussion instruments
96.35 + * from melodic instruments.
96.36 + *
96.37 + * @author Karl Helgason
96.38 + */
96.39 +public class ModelPatch extends Patch {
96.40 +
96.41 + private boolean percussion = false;
96.42 +
96.43 + public ModelPatch(int bank, int program) {
96.44 + super(bank, program);
96.45 + }
96.46 +
96.47 + public ModelPatch(int bank, int program, boolean percussion) {
96.48 + super(bank, program);
96.49 + this.percussion = percussion;
96.50 + }
96.51 +
96.52 + public boolean isPercussion() {
96.53 + return percussion;
96.54 + }
96.55 +}
97.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
97.2 +++ b/src/share/classes/com/sun/media/sound/ModelPerformer.java Tue Feb 03 22:02:55 2009 -0800
97.3 @@ -0,0 +1,143 @@
97.4 +/*
97.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
97.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
97.7 + *
97.8 + * This code is free software; you can redistribute it and/or modify it
97.9 + * under the terms of the GNU General Public License version 2 only, as
97.10 + * published by the Free Software Foundation. Sun designates this
97.11 + * particular file as subject to the "Classpath" exception as provided
97.12 + * by Sun in the LICENSE file that accompanied this code.
97.13 + *
97.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
97.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
97.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
97.17 + * version 2 for more details (a copy is included in the LICENSE file that
97.18 + * accompanied this code).
97.19 + *
97.20 + * You should have received a copy of the GNU General Public License version
97.21 + * 2 along with this work; if not, write to the Free Software Foundation,
97.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
97.23 + *
97.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
97.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
97.26 + * have any questions.
97.27 + */
97.28 +package com.sun.media.sound;
97.29 +
97.30 +import java.util.ArrayList;
97.31 +import java.util.List;
97.32 +
97.33 +/**
97.34 + * This class is used to define how to synthesize audio in universal maner
97.35 + * for both SF2 and DLS instruments.
97.36 + *
97.37 + * @author Karl Helgason
97.38 + */
97.39 +public class ModelPerformer {
97.40 +
97.41 + private List<ModelOscillator> oscillators = new ArrayList<ModelOscillator>();
97.42 + private List<ModelConnectionBlock> connectionBlocks
97.43 + = new ArrayList<ModelConnectionBlock>();
97.44 + private int keyFrom = 0;
97.45 + private int keyTo = 127;
97.46 + private int velFrom = 0;
97.47 + private int velTo = 127;
97.48 + private int exclusiveClass = 0;
97.49 + private boolean releaseTrigger = false;
97.50 + private boolean selfNonExclusive = false;
97.51 + private Object userObject = null;
97.52 + private boolean addDefaultConnections = true;
97.53 + private String name = null;
97.54 +
97.55 + public String getName() {
97.56 + return name;
97.57 + }
97.58 +
97.59 + public void setName(String name) {
97.60 + this.name = name;
97.61 + }
97.62 +
97.63 + public List<ModelConnectionBlock> getConnectionBlocks() {
97.64 + return connectionBlocks;
97.65 + }
97.66 +
97.67 + public void setConnectionBlocks(List<ModelConnectionBlock> connectionBlocks) {
97.68 + this.connectionBlocks = connectionBlocks;
97.69 + }
97.70 +
97.71 + public List<ModelOscillator> getOscillators() {
97.72 + return oscillators;
97.73 + }
97.74 +
97.75 + public int getExclusiveClass() {
97.76 + return exclusiveClass;
97.77 + }
97.78 +
97.79 + public void setExclusiveClass(int exclusiveClass) {
97.80 + this.exclusiveClass = exclusiveClass;
97.81 + }
97.82 +
97.83 + public boolean isSelfNonExclusive() {
97.84 + return selfNonExclusive;
97.85 + }
97.86 +
97.87 + public void setSelfNonExclusive(boolean selfNonExclusive) {
97.88 + this.selfNonExclusive = selfNonExclusive;
97.89 + }
97.90 +
97.91 + public int getKeyFrom() {
97.92 + return keyFrom;
97.93 + }
97.94 +
97.95 + public void setKeyFrom(int keyFrom) {
97.96 + this.keyFrom = keyFrom;
97.97 + }
97.98 +
97.99 + public int getKeyTo() {
97.100 + return keyTo;
97.101 + }
97.102 +
97.103 + public void setKeyTo(int keyTo) {
97.104 + this.keyTo = keyTo;
97.105 + }
97.106 +
97.107 + public int getVelFrom() {
97.108 + return velFrom;
97.109 + }
97.110 +
97.111 + public void setVelFrom(int velFrom) {
97.112 + this.velFrom = velFrom;
97.113 + }
97.114 +
97.115 + public int getVelTo() {
97.116 + return velTo;
97.117 + }
97.118 +
97.119 + public void setVelTo(int velTo) {
97.120 + this.velTo = velTo;
97.121 + }
97.122 +
97.123 + public boolean isReleaseTriggered() {
97.124 + return releaseTrigger;
97.125 + }
97.126 +
97.127 + public void setReleaseTriggered(boolean value) {
97.128 + this.releaseTrigger = value;
97.129 + }
97.130 +
97.131 + public Object getUserObject() {
97.132 + return userObject;
97.133 + }
97.134 +
97.135 + public void setUserObject(Object object) {
97.136 + userObject = object;
97.137 + }
97.138 +
97.139 + public boolean isDefaultConnectionsEnabled() {
97.140 + return addDefaultConnections;
97.141 + }
97.142 +
97.143 + public void setDefaultConnectionsEnabled(boolean addDefaultConnections) {
97.144 + this.addDefaultConnections = addDefaultConnections;
97.145 + }
97.146 +}
98.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
98.2 +++ b/src/share/classes/com/sun/media/sound/ModelSource.java Tue Feb 03 22:02:55 2009 -0800
98.3 @@ -0,0 +1,109 @@
98.4 +/*
98.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
98.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
98.7 + *
98.8 + * This code is free software; you can redistribute it and/or modify it
98.9 + * under the terms of the GNU General Public License version 2 only, as
98.10 + * published by the Free Software Foundation. Sun designates this
98.11 + * particular file as subject to the "Classpath" exception as provided
98.12 + * by Sun in the LICENSE file that accompanied this code.
98.13 + *
98.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
98.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
98.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
98.17 + * version 2 for more details (a copy is included in the LICENSE file that
98.18 + * accompanied this code).
98.19 + *
98.20 + * You should have received a copy of the GNU General Public License version
98.21 + * 2 along with this work; if not, write to the Free Software Foundation,
98.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
98.23 + *
98.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
98.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
98.26 + * have any questions.
98.27 + */
98.28 +package com.sun.media.sound;
98.29 +
98.30 +/**
98.31 + * This class is used to identify sources in connection blocks,
98.32 + * see ModelConnectionBlock.
98.33 + *
98.34 + * @author Karl Helgason
98.35 + */
98.36 +public class ModelSource {
98.37 +
98.38 + public static final ModelIdentifier SOURCE_NONE = null;
98.39 + public static final ModelIdentifier SOURCE_NOTEON_KEYNUMBER =
98.40 + new ModelIdentifier("noteon", "keynumber"); // midi keynumber
98.41 + public static final ModelIdentifier SOURCE_NOTEON_VELOCITY =
98.42 + new ModelIdentifier("noteon", "velocity"); // midi velocity
98.43 + public static final ModelIdentifier SOURCE_EG1 =
98.44 + new ModelIdentifier("eg", null, 0);
98.45 + public static final ModelIdentifier SOURCE_EG2 =
98.46 + new ModelIdentifier("eg", null, 1);
98.47 + public static final ModelIdentifier SOURCE_LFO1 =
98.48 + new ModelIdentifier("lfo", null, 0);
98.49 + public static final ModelIdentifier SOURCE_LFO2 =
98.50 + new ModelIdentifier("lfo", null, 1);
98.51 + public static final ModelIdentifier SOURCE_MIDI_PITCH =
98.52 + new ModelIdentifier("midi", "pitch", 0); // (0..16383)
98.53 + public static final ModelIdentifier SOURCE_MIDI_CHANNEL_PRESSURE =
98.54 + new ModelIdentifier("midi", "channel_pressure", 0); // (0..127)
98.55 +// public static final ModelIdentifier SOURCE_MIDI_MONO_PRESSURE =
98.56 +// new ModelIdentifier("midi","mono_pressure",0); // (0..127)
98.57 + public static final ModelIdentifier SOURCE_MIDI_POLY_PRESSURE =
98.58 + new ModelIdentifier("midi", "poly_pressure", 0); // (0..127)
98.59 + public static final ModelIdentifier SOURCE_MIDI_CC_0 =
98.60 + new ModelIdentifier("midi_cc", "0", 0); // (0..127)
98.61 + public static final ModelIdentifier SOURCE_MIDI_RPN_0 =
98.62 + new ModelIdentifier("midi_rpn", "0", 0); // (0..16383)
98.63 + private ModelIdentifier source = SOURCE_NONE;
98.64 + private ModelTransform transform;
98.65 +
98.66 + public ModelSource() {
98.67 + this.transform = new ModelStandardTransform();
98.68 + }
98.69 +
98.70 + public ModelSource(ModelIdentifier id) {
98.71 + source = id;
98.72 + this.transform = new ModelStandardTransform();
98.73 + }
98.74 +
98.75 + public ModelSource(ModelIdentifier id, boolean direction) {
98.76 + source = id;
98.77 + this.transform = new ModelStandardTransform(direction);
98.78 + }
98.79 +
98.80 + public ModelSource(ModelIdentifier id, boolean direction, boolean polarity) {
98.81 + source = id;
98.82 + this.transform = new ModelStandardTransform(direction, polarity);
98.83 + }
98.84 +
98.85 + public ModelSource(ModelIdentifier id, boolean direction, boolean polarity,
98.86 + int transform) {
98.87 + source = id;
98.88 + this.transform =
98.89 + new ModelStandardTransform(direction, polarity, transform);
98.90 + }
98.91 +
98.92 + public ModelSource(ModelIdentifier id, ModelTransform transform) {
98.93 + source = id;
98.94 + this.transform = transform;
98.95 + }
98.96 +
98.97 + public ModelIdentifier getIdentifier() {
98.98 + return source;
98.99 + }
98.100 +
98.101 + public void setIdentifier(ModelIdentifier source) {
98.102 + this.source = source;
98.103 + }
98.104 +
98.105 + public ModelTransform getTransform() {
98.106 + return transform;
98.107 + }
98.108 +
98.109 + public void setTransform(ModelTransform transform) {
98.110 + this.transform = transform;
98.111 + }
98.112 +}
99.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
99.2 +++ b/src/share/classes/com/sun/media/sound/ModelStandardDirector.java Tue Feb 03 22:02:55 2009 -0800
99.3 @@ -0,0 +1,86 @@
99.4 +/*
99.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
99.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
99.7 + *
99.8 + * This code is free software; you can redistribute it and/or modify it
99.9 + * under the terms of the GNU General Public License version 2 only, as
99.10 + * published by the Free Software Foundation. Sun designates this
99.11 + * particular file as subject to the "Classpath" exception as provided
99.12 + * by Sun in the LICENSE file that accompanied this code.
99.13 + *
99.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
99.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
99.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
99.17 + * version 2 for more details (a copy is included in the LICENSE file that
99.18 + * accompanied this code).
99.19 + *
99.20 + * You should have received a copy of the GNU General Public License version
99.21 + * 2 along with this work; if not, write to the Free Software Foundation,
99.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
99.23 + *
99.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
99.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
99.26 + * have any questions.
99.27 + */
99.28 +package com.sun.media.sound;
99.29 +
99.30 +/**
99.31 + * A standard director who chooses performers
99.32 + * by there keyfrom,keyto,velfrom,velto properties.
99.33 + *
99.34 + * @author Karl Helgason
99.35 + */
99.36 +public class ModelStandardDirector implements ModelDirector {
99.37 +
99.38 + ModelPerformer[] performers;
99.39 + ModelDirectedPlayer player;
99.40 + boolean noteOnUsed = false;
99.41 + boolean noteOffUsed = false;
99.42 +
99.43 + public ModelStandardDirector(ModelPerformer[] performers,
99.44 + ModelDirectedPlayer player) {
99.45 + this.performers = performers;
99.46 + this.player = player;
99.47 + for (int i = 0; i < performers.length; i++) {
99.48 + ModelPerformer p = performers[i];
99.49 + if (p.isReleaseTriggered()) {
99.50 + noteOffUsed = true;
99.51 + } else {
99.52 + noteOnUsed = true;
99.53 + }
99.54 + }
99.55 + }
99.56 +
99.57 + public void close() {
99.58 + }
99.59 +
99.60 + public void noteOff(int noteNumber, int velocity) {
99.61 + if (!noteOffUsed)
99.62 + return;
99.63 + for (int i = 0; i < performers.length; i++) {
99.64 + ModelPerformer p = performers[i];
99.65 + if (p.getKeyFrom() <= noteNumber && p.getKeyTo() >= noteNumber) {
99.66 + if (p.getVelFrom() <= velocity && p.getVelTo() >= velocity) {
99.67 + if (p.isReleaseTriggered()) {
99.68 + player.play(i, null);
99.69 + }
99.70 + }
99.71 + }
99.72 + }
99.73 + }
99.74 +
99.75 + public void noteOn(int noteNumber, int velocity) {
99.76 + if (!noteOnUsed)
99.77 + return;
99.78 + for (int i = 0; i < performers.length; i++) {
99.79 + ModelPerformer p = performers[i];
99.80 + if (p.getKeyFrom() <= noteNumber && p.getKeyTo() >= noteNumber) {
99.81 + if (p.getVelFrom() <= velocity && p.getVelTo() >= velocity) {
99.82 + if (!p.isReleaseTriggered()) {
99.83 + player.play(i, null);
99.84 + }
99.85 + }
99.86 + }
99.87 + }
99.88 + }
99.89 +}
100.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
100.2 +++ b/src/share/classes/com/sun/media/sound/ModelStandardTransform.java Tue Feb 03 22:02:55 2009 -0800
100.3 @@ -0,0 +1,139 @@
100.4 +/*
100.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
100.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
100.7 + *
100.8 + * This code is free software; you can redistribute it and/or modify it
100.9 + * under the terms of the GNU General Public License version 2 only, as
100.10 + * published by the Free Software Foundation. Sun designates this
100.11 + * particular file as subject to the "Classpath" exception as provided
100.12 + * by Sun in the LICENSE file that accompanied this code.
100.13 + *
100.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
100.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
100.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
100.17 + * version 2 for more details (a copy is included in the LICENSE file that
100.18 + * accompanied this code).
100.19 + *
100.20 + * You should have received a copy of the GNU General Public License version
100.21 + * 2 along with this work; if not, write to the Free Software Foundation,
100.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
100.23 + *
100.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
100.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
100.26 + * have any questions.
100.27 + */
100.28 +package com.sun.media.sound;
100.29 +
100.30 +/**
100.31 + * A standard transformer used in connection blocks.
100.32 + * It expects input values to be between 0 and 1.
100.33 + *
100.34 + * The result of the transform is
100.35 + * between 0 and 1 if polarity = unipolar and
100.36 + * between -1 and 1 if polarity = bipolar.
100.37 + *
100.38 + * These constraints only applies to Concave, Convex and Switch transforms.
100.39 + *
100.40 + * @author Karl Helgason
100.41 + */
100.42 +public class ModelStandardTransform implements ModelTransform {
100.43 +
100.44 + public static final boolean DIRECTION_MIN2MAX = false;
100.45 + public static final boolean DIRECTION_MAX2MIN = true;
100.46 + public static final boolean POLARITY_UNIPOLAR = false;
100.47 + public static final boolean POLARITY_BIPOLAR = true;
100.48 + public static final int TRANSFORM_LINEAR = 0;
100.49 + // concave: output = (20*log10(127^2/value^2)) / 96
100.50 + public static final int TRANSFORM_CONCAVE = 1;
100.51 + // convex: same as concave except that start and end point are reversed.
100.52 + public static final int TRANSFORM_CONVEX = 2;
100.53 + // switch: if value > avg(max,min) then max else min
100.54 + public static final int TRANSFORM_SWITCH = 3;
100.55 + public static final int TRANSFORM_ABSOLUTE = 4;
100.56 + private boolean direction = DIRECTION_MIN2MAX;
100.57 + private boolean polarity = POLARITY_UNIPOLAR;
100.58 + private int transform = TRANSFORM_LINEAR;
100.59 +
100.60 + public ModelStandardTransform() {
100.61 + }
100.62 +
100.63 + public ModelStandardTransform(boolean direction) {
100.64 + this.direction = direction;
100.65 + }
100.66 +
100.67 + public ModelStandardTransform(boolean direction, boolean polarity) {
100.68 + this.direction = direction;
100.69 + this.polarity = polarity;
100.70 + }
100.71 +
100.72 + public ModelStandardTransform(boolean direction, boolean polarity,
100.73 + int transform) {
100.74 + this.direction = direction;
100.75 + this.polarity = polarity;
100.76 + this.transform = transform;
100.77 + }
100.78 +
100.79 + public double transform(double value) {
100.80 + double s;
100.81 + double a;
100.82 + if (direction == DIRECTION_MAX2MIN)
100.83 + value = 1.0 - value;
100.84 + if (polarity == POLARITY_BIPOLAR)
100.85 + value = value * 2.0 - 1.0;
100.86 + switch (transform) {
100.87 + case TRANSFORM_CONCAVE:
100.88 + s = Math.signum(value);
100.89 + a = Math.abs(value);
100.90 + a = -((5.0 / 12.0) / Math.log(10)) * Math.log(1.0 - a);
100.91 + if (a < 0)
100.92 + a = 0;
100.93 + else if (a > 1)
100.94 + a = 1;
100.95 + return s * a;
100.96 + case TRANSFORM_CONVEX:
100.97 + s = Math.signum(value);
100.98 + a = Math.abs(value);
100.99 + a = 1.0 + ((5.0 / 12.0) / Math.log(10)) * Math.log(a);
100.100 + if (a < 0)
100.101 + a = 0;
100.102 + else if (a > 1)
100.103 + a = 1;
100.104 + return s * a;
100.105 + case TRANSFORM_SWITCH:
100.106 + if (polarity == POLARITY_BIPOLAR)
100.107 + return (value > 0) ? 1 : -1;
100.108 + else
100.109 + return (value > 0.5) ? 1 : 0;
100.110 + case TRANSFORM_ABSOLUTE:
100.111 + return Math.abs(value);
100.112 + default:
100.113 + break;
100.114 + }
100.115 +
100.116 + return value;
100.117 + }
100.118 +
100.119 + public boolean getDirection() {
100.120 + return direction;
100.121 + }
100.122 +
100.123 + public void setDirection(boolean direction) {
100.124 + this.direction = direction;
100.125 + }
100.126 +
100.127 + public boolean getPolarity() {
100.128 + return polarity;
100.129 + }
100.130 +
100.131 + public void setPolarity(boolean polarity) {
100.132 + this.polarity = polarity;
100.133 + }
100.134 +
100.135 + public int getTransform() {
100.136 + return transform;
100.137 + }
100.138 +
100.139 + public void setTransform(int transform) {
100.140 + this.transform = transform;
100.141 + }
100.142 +}
101.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
101.2 +++ b/src/share/classes/com/sun/media/sound/ModelTransform.java Tue Feb 03 22:02:55 2009 -0800
101.3 @@ -0,0 +1,35 @@
101.4 +/*
101.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
101.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
101.7 + *
101.8 + * This code is free software; you can redistribute it and/or modify it
101.9 + * under the terms of the GNU General Public License version 2 only, as
101.10 + * published by the Free Software Foundation. Sun designates this
101.11 + * particular file as subject to the "Classpath" exception as provided
101.12 + * by Sun in the LICENSE file that accompanied this code.
101.13 + *
101.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
101.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
101.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
101.17 + * version 2 for more details (a copy is included in the LICENSE file that
101.18 + * accompanied this code).
101.19 + *
101.20 + * You should have received a copy of the GNU General Public License version
101.21 + * 2 along with this work; if not, write to the Free Software Foundation,
101.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
101.23 + *
101.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
101.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
101.26 + * have any questions.
101.27 + */
101.28 +package com.sun.media.sound;
101.29 +
101.30 +/**
101.31 + * Model transform interface.
101.32 + *
101.33 + * @author Karl Helgason
101.34 + */
101.35 +public interface ModelTransform {
101.36 +
101.37 + abstract public double transform(double value);
101.38 +}
102.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
102.2 +++ b/src/share/classes/com/sun/media/sound/ModelWavetable.java Tue Feb 03 22:02:55 2009 -0800
102.3 @@ -0,0 +1,49 @@
102.4 +/*
102.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
102.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
102.7 + *
102.8 + * This code is free software; you can redistribute it and/or modify it
102.9 + * under the terms of the GNU General Public License version 2 only, as
102.10 + * published by the Free Software Foundation. Sun designates this
102.11 + * particular file as subject to the "Classpath" exception as provided
102.12 + * by Sun in the LICENSE file that accompanied this code.
102.13 + *
102.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
102.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
102.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
102.17 + * version 2 for more details (a copy is included in the LICENSE file that
102.18 + * accompanied this code).
102.19 + *
102.20 + * You should have received a copy of the GNU General Public License version
102.21 + * 2 along with this work; if not, write to the Free Software Foundation,
102.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
102.23 + *
102.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
102.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
102.26 + * have any questions.
102.27 + */
102.28 +package com.sun.media.sound;
102.29 +
102.30 +/**
102.31 + * This is a wavetable oscillator interface.
102.32 + *
102.33 + * @author Karl Helgason
102.34 + */
102.35 +public interface ModelWavetable extends ModelOscillator {
102.36 +
102.37 + public static final int LOOP_TYPE_OFF = 0;
102.38 + public static final int LOOP_TYPE_FORWARD = 1;
102.39 + public static final int LOOP_TYPE_RELEASE = 2;
102.40 + public static final int LOOP_TYPE_PINGPONG = 4;
102.41 + public static final int LOOP_TYPE_REVERSE = 8;
102.42 +
102.43 + public AudioFloatInputStream openStream();
102.44 +
102.45 + public float getLoopLength();
102.46 +
102.47 + public float getLoopStart();
102.48 +
102.49 + public int getLoopType();
102.50 +
102.51 + public float getPitchcorrection();
102.52 +}
103.1 --- a/src/share/classes/com/sun/media/sound/Platform.java Thu Jan 29 21:46:48 2009 -0800
103.2 +++ b/src/share/classes/com/sun/media/sound/Platform.java Tue Feb 03 22:02:55 2009 -0800
103.3 @@ -42,8 +42,6 @@
103.4
103.5 // native library we need to load
103.6 private static final String libNameMain = "jsound";
103.7 - private static final String libNameMain2 = "jsoundhs";
103.8 -
103.9 private static final String libNameALSA = "jsoundalsa";
103.10 private static final String libNameDSound = "jsoundds";
103.11
103.12 @@ -158,9 +156,8 @@
103.13 if(Printer.trace)Printer.trace(">>Platform.loadLibraries");
103.14
103.15 try {
103.16 - // load the main libraries
103.17 + // load the main library
103.18 JSSecurityManager.loadLibrary(libNameMain);
103.19 - JSSecurityManager.loadLibrary(libNameMain2);
103.20 // just for the heck of it...
103.21 loadedLibs |= LIB_MAIN;
103.22 } catch (SecurityException e) {
104.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
104.2 +++ b/src/share/classes/com/sun/media/sound/RIFFInvalidDataException.java Tue Feb 03 22:02:55 2009 -0800
104.3 @@ -0,0 +1,43 @@
104.4 +/*
104.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
104.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
104.7 + *
104.8 + * This code is free software; you can redistribute it and/or modify it
104.9 + * under the terms of the GNU General Public License version 2 only, as
104.10 + * published by the Free Software Foundation. Sun designates this
104.11 + * particular file as subject to the "Classpath" exception as provided
104.12 + * by Sun in the LICENSE file that accompanied this code.
104.13 + *
104.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
104.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
104.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
104.17 + * version 2 for more details (a copy is included in the LICENSE file that
104.18 + * accompanied this code).
104.19 + *
104.20 + * You should have received a copy of the GNU General Public License version
104.21 + * 2 along with this work; if not, write to the Free Software Foundation,
104.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
104.23 + *
104.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
104.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
104.26 + * have any questions.
104.27 + */
104.28 +package com.sun.media.sound;
104.29 +
104.30 +/**
104.31 + * This exception is used when a RIFF file contains illegal or unexpected data.
104.32 + *
104.33 + * @author Karl Helgason
104.34 + */
104.35 +public class RIFFInvalidDataException extends InvalidDataException {
104.36 +
104.37 + private static final long serialVersionUID = 1L;
104.38 +
104.39 + public RIFFInvalidDataException() {
104.40 + super("Invalid Data!");
104.41 + }
104.42 +
104.43 + public RIFFInvalidDataException(String s) {
104.44 + super(s);
104.45 + }
104.46 +}
105.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
105.2 +++ b/src/share/classes/com/sun/media/sound/RIFFInvalidFormatException.java Tue Feb 03 22:02:55 2009 -0800
105.3 @@ -0,0 +1,44 @@
105.4 +/*
105.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
105.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
105.7 + *
105.8 + * This code is free software; you can redistribute it and/or modify it
105.9 + * under the terms of the GNU General Public License version 2 only, as
105.10 + * published by the Free Software Foundation. Sun designates this
105.11 + * particular file as subject to the "Classpath" exception as provided
105.12 + * by Sun in the LICENSE file that accompanied this code.
105.13 + *
105.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
105.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
105.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
105.17 + * version 2 for more details (a copy is included in the LICENSE file that
105.18 + * accompanied this code).
105.19 + *
105.20 + * You should have received a copy of the GNU General Public License version
105.21 + * 2 along with this work; if not, write to the Free Software Foundation,
105.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
105.23 + *
105.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
105.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
105.26 + * have any questions.
105.27 + */
105.28 +package com.sun.media.sound;
105.29 +
105.30 +/**
105.31 + * This exception is used when a reader is used to read RIFF file of a format it
105.32 + * doesn't unterstand or support.
105.33 + *
105.34 + * @author Karl Helgason
105.35 + */
105.36 +public class RIFFInvalidFormatException extends InvalidFormatException {
105.37 +
105.38 + private static final long serialVersionUID = 1L;
105.39 +
105.40 + public RIFFInvalidFormatException() {
105.41 + super("Invalid format!");
105.42 + }
105.43 +
105.44 + public RIFFInvalidFormatException(String s) {
105.45 + super(s);
105.46 + }
105.47 +}
106.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
106.2 +++ b/src/share/classes/com/sun/media/sound/RIFFReader.java Tue Feb 03 22:02:55 2009 -0800
106.3 @@ -0,0 +1,332 @@
106.4 +/*
106.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
106.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
106.7 + *
106.8 + * This code is free software; you can redistribute it and/or modify it
106.9 + * under the terms of the GNU General Public License version 2 only, as
106.10 + * published by the Free Software Foundation. Sun designates this
106.11 + * particular file as subject to the "Classpath" exception as provided
106.12 + * by Sun in the LICENSE file that accompanied this code.
106.13 + *
106.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
106.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
106.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
106.17 + * version 2 for more details (a copy is included in the LICENSE file that
106.18 + * accompanied this code).
106.19 + *
106.20 + * You should have received a copy of the GNU General Public License version
106.21 + * 2 along with this work; if not, write to the Free Software Foundation,
106.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
106.23 + *
106.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
106.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
106.26 + * have any questions.
106.27 + */
106.28 +package com.sun.media.sound;
106.29 +
106.30 +import java.io.EOFException;
106.31 +import java.io.IOException;
106.32 +import java.io.InputStream;
106.33 +
106.34 +/**
106.35 + * Resource Interchange File Format (RIFF) stream decoder.
106.36 + *
106.37 + * @author Karl Helgason
106.38 + */
106.39 +public class RIFFReader extends InputStream {
106.40 +
106.41 + private RIFFReader root;
106.42 + private long filepointer = 0;
106.43 + private String fourcc;
106.44 + private String riff_type = null;
106.45 + private long ckSize = 0;
106.46 + private InputStream stream;
106.47 + private long avail;
106.48 + private RIFFReader lastiterator = null;
106.49 +
106.50 + public RIFFReader(InputStream stream) throws IOException {
106.51 +
106.52 + if (stream instanceof RIFFReader)
106.53 + root = ((RIFFReader)stream).root;
106.54 + else
106.55 + root = this;
106.56 +
106.57 + this.stream = stream;
106.58 + avail = Integer.MAX_VALUE;
106.59 + ckSize = Integer.MAX_VALUE;
106.60 +
106.61 + // Check for RIFF null paddings,
106.62 + int b;
106.63 + while (true) {
106.64 + b = read();
106.65 + if (b == -1) {
106.66 + fourcc = ""; // don't put null value into fourcc,
106.67 + // because it is expected to
106.68 + // always contain a string value
106.69 + riff_type = null;
106.70 + avail = 0;
106.71 + return;
106.72 + }
106.73 + if (b != 0)
106.74 + break;
106.75 + }
106.76 +
106.77 + byte[] fourcc = new byte[4];
106.78 + fourcc[0] = (byte) b;
106.79 + readFully(fourcc, 1, 3);
106.80 + this.fourcc = new String(fourcc, "ascii");
106.81 + ckSize = readUnsignedInt();
106.82 +
106.83 + avail = this.ckSize;
106.84 +
106.85 + if (getFormat().equals("RIFF") || getFormat().equals("LIST")) {
106.86 + byte[] format = new byte[4];
106.87 + readFully(format);
106.88 + this.riff_type = new String(format, "ascii");
106.89 + }
106.90 + }
106.91 +
106.92 + public long getFilePointer() throws IOException {
106.93 + return root.filepointer;
106.94 + }
106.95 +
106.96 + public boolean hasNextChunk() throws IOException {
106.97 + if (lastiterator != null)
106.98 + lastiterator.finish();
106.99 + return avail != 0;
106.100 + }
106.101 +
106.102 + public RIFFReader nextChunk() throws IOException {
106.103 + if (lastiterator != null)
106.104 + lastiterator.finish();
106.105 + if (avail == 0)
106.106 + return null;
106.107 + lastiterator = new RIFFReader(this);
106.108 + return lastiterator;
106.109 + }
106.110 +
106.111 + public String getFormat() {
106.112 + return fourcc;
106.113 + }
106.114 +
106.115 + public String getType() {
106.116 + return riff_type;
106.117 + }
106.118 +
106.119 + public long getSize() {
106.120 + return ckSize;
106.121 + }
106.122 +
106.123 + public int read() throws IOException {
106.124 + if (avail == 0)
106.125 + return -1;
106.126 + int b = stream.read();
106.127 + if (b == -1)
106.128 + return -1;
106.129 + avail--;
106.130 + filepointer++;
106.131 + return b;
106.132 + }
106.133 +
106.134 + public int read(byte[] b, int offset, int len) throws IOException {
106.135 + if (avail == 0)
106.136 + return -1;
106.137 + if (len > avail) {
106.138 + int rlen = stream.read(b, offset, (int)avail);
106.139 + if (rlen != -1)
106.140 + filepointer += rlen;
106.141 + avail = 0;
106.142 + return rlen;
106.143 + } else {
106.144 + int ret = stream.read(b, offset, len);
106.145 + if (ret == -1)
106.146 + return -1;
106.147 + avail -= ret;
106.148 + filepointer += ret;
106.149 + return ret;
106.150 + }
106.151 + }
106.152 +
106.153 + public final void readFully(byte b[]) throws IOException {
106.154 + readFully(b, 0, b.length);
106.155 + }
106.156 +
106.157 + public final void readFully(byte b[], int off, int len) throws IOException {
106.158 + if (len < 0)
106.159 + throw new IndexOutOfBoundsException();
106.160 + while (len > 0) {
106.161 + int s = read(b, off, len);
106.162 + if (s < 0)
106.163 + throw new EOFException();
106.164 + if (s == 0)
106.165 + Thread.yield();
106.166 + off += s;
106.167 + len -= s;
106.168 + }
106.169 + }
106.170 +
106.171 + public final long skipBytes(long n) throws IOException {
106.172 + if (n < 0)
106.173 + return 0;
106.174 + long skipped = 0;
106.175 + while (skipped != n) {
106.176 + long s = skip(n - skipped);
106.177 + if (s < 0)
106.178 + break;
106.179 + if (s == 0)
106.180 + Thread.yield();
106.181 + skipped += s;
106.182 + }
106.183 + return skipped;
106.184 + }
106.185 +
106.186 + public long skip(long n) throws IOException {
106.187 + if (avail == 0)
106.188 + return -1;
106.189 + if (n > avail) {
106.190 + long len = stream.skip(avail);
106.191 + if (len != -1)
106.192 + filepointer += len;
106.193 + avail = 0;
106.194 + return len;
106.195 + } else {
106.196 + long ret = stream.skip(n);
106.197 + if (ret == -1)
106.198 + return -1;
106.199 + avail -= ret;
106.200 + filepointer += ret;
106.201 + return ret;
106.202 + }
106.203 + }
106.204 +
106.205 + public int available() {
106.206 + return (int)avail;
106.207 + }
106.208 +
106.209 + public void finish() throws IOException {
106.210 + if (avail != 0) {
106.211 + skipBytes(avail);
106.212 + }
106.213 + }
106.214 +
106.215 + // Read ASCII chars from stream
106.216 + public String readString(int len) throws IOException {
106.217 + byte[] buff = new byte[len];
106.218 + readFully(buff);
106.219 + for (int i = 0; i < buff.length; i++) {
106.220 + if (buff[i] == 0) {
106.221 + return new String(buff, 0, i, "ascii");
106.222 + }
106.223 + }
106.224 + return new String(buff, "ascii");
106.225 + }
106.226 +
106.227 + // Read 8 bit signed integer from stream
106.228 + public byte readByte() throws IOException {
106.229 + int ch = read();
106.230 + if (ch < 0)
106.231 + throw new EOFException();
106.232 + return (byte) ch;
106.233 + }
106.234 +
106.235 + // Read 16 bit signed integer from stream
106.236 + public short readShort() throws IOException {
106.237 + int ch1 = read();
106.238 + int ch2 = read();
106.239 + if (ch1 < 0)
106.240 + throw new EOFException();
106.241 + if (ch2 < 0)
106.242 + throw new EOFException();
106.243 + return (short)(ch1 | (ch2 << 8));
106.244 + }
106.245 +
106.246 + // Read 32 bit signed integer from stream
106.247 + public int readInt() throws IOException {
106.248 + int ch1 = read();
106.249 + int ch2 = read();
106.250 + int ch3 = read();
106.251 + int ch4 = read();
106.252 + if (ch1 < 0)
106.253 + throw new EOFException();
106.254 + if (ch2 < 0)
106.255 + throw new EOFException();
106.256 + if (ch3 < 0)
106.257 + throw new EOFException();
106.258 + if (ch4 < 0)
106.259 + throw new EOFException();
106.260 + return ch1 + (ch2 << 8) | (ch3 << 16) | (ch4 << 24);
106.261 + }
106.262 +
106.263 + // Read 64 bit signed integer from stream
106.264 + public long readLong() throws IOException {
106.265 + long ch1 = read();
106.266 + long ch2 = read();
106.267 + long ch3 = read();
106.268 + long ch4 = read();
106.269 + long ch5 = read();
106.270 + long ch6 = read();
106.271 + long ch7 = read();
106.272 + long ch8 = read();
106.273 + if (ch1 < 0)
106.274 + throw new EOFException();
106.275 + if (ch2 < 0)
106.276 + throw new EOFException();
106.277 + if (ch3 < 0)
106.278 + throw new EOFException();
106.279 + if (ch4 < 0)
106.280 + throw new EOFException();
106.281 + if (ch5 < 0)
106.282 + throw new EOFException();
106.283 + if (ch6 < 0)
106.284 + throw new EOFException();
106.285 + if (ch7 < 0)
106.286 + throw new EOFException();
106.287 + if (ch8 < 0)
106.288 + throw new EOFException();
106.289 + return ch1 | (ch2 << 8) | (ch3 << 16) | (ch4 << 24)
106.290 + | (ch5 << 32) | (ch6 << 40) | (ch7 << 48) | (ch8 << 56);
106.291 + }
106.292 +
106.293 + // Read 8 bit unsigned integer from stream
106.294 + public int readUnsignedByte() throws IOException {
106.295 + int ch = read();
106.296 + if (ch < 0)
106.297 + throw new EOFException();
106.298 + return ch;
106.299 + }
106.300 +
106.301 + // Read 16 bit unsigned integer from stream
106.302 + public int readUnsignedShort() throws IOException {
106.303 + int ch1 = read();
106.304 + int ch2 = read();
106.305 + if (ch1 < 0)
106.306 + throw new EOFException();
106.307 + if (ch2 < 0)
106.308 + throw new EOFException();
106.309 + return ch1 | (ch2 << 8);
106.310 + }
106.311 +
106.312 + // Read 32 bit unsigned integer from stream
106.313 + public long readUnsignedInt() throws IOException {
106.314 + long ch1 = read();
106.315 + long ch2 = read();
106.316 + long ch3 = read();
106.317 + long ch4 = read();
106.318 + if (ch1 < 0)
106.319 + throw new EOFException();
106.320 + if (ch2 < 0)
106.321 + throw new EOFException();
106.322 + if (ch3 < 0)
106.323 + throw new EOFException();
106.324 + if (ch4 < 0)
106.325 + throw new EOFException();
106.326 + return ch1 + (ch2 << 8) | (ch3 << 16) | (ch4 << 24);
106.327 + }
106.328 +
106.329 + public void close() throws IOException {
106.330 + finish();
106.331 + if (this == root)
106.332 + stream.close();
106.333 + stream = null;
106.334 + }
106.335 +}
107.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
107.2 +++ b/src/share/classes/com/sun/media/sound/RIFFWriter.java Tue Feb 03 22:02:55 2009 -0800
107.3 @@ -0,0 +1,365 @@
107.4 +/*
107.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
107.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
107.7 + *
107.8 + * This code is free software; you can redistribute it and/or modify it
107.9 + * under the terms of the GNU General Public License version 2 only, as
107.10 + * published by the Free Software Foundation. Sun designates this
107.11 + * particular file as subject to the "Classpath" exception as provided
107.12 + * by Sun in the LICENSE file that accompanied this code.
107.13 + *
107.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
107.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
107.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
107.17 + * version 2 for more details (a copy is included in the LICENSE file that
107.18 + * accompanied this code).
107.19 + *
107.20 + * You should have received a copy of the GNU General Public License version
107.21 + * 2 along with this work; if not, write to the Free Software Foundation,
107.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
107.23 + *
107.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
107.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
107.26 + * have any questions.
107.27 + */
107.28 +package com.sun.media.sound;
107.29 +
107.30 +import java.io.File;
107.31 +import java.io.FileNotFoundException;
107.32 +import java.io.IOException;
107.33 +import java.io.OutputStream;
107.34 +import java.io.RandomAccessFile;
107.35 +
107.36 +/**
107.37 + * Resource Interchange File Format (RIFF) stream encoder.
107.38 + *
107.39 + * @author Karl Helgason
107.40 + */
107.41 +public class RIFFWriter extends OutputStream {
107.42 +
107.43 + private interface RandomAccessWriter {
107.44 +
107.45 + public void seek(long chunksizepointer) throws IOException;
107.46 +
107.47 + public long getPointer() throws IOException;
107.48 +
107.49 + public void close() throws IOException;
107.50 +
107.51 + public void write(int b) throws IOException;
107.52 +
107.53 + public void write(byte[] b, int off, int len) throws IOException;
107.54 +
107.55 + public void write(byte[] bytes) throws IOException;
107.56 +
107.57 + public long length() throws IOException;
107.58 +
107.59 + public void setLength(long i) throws IOException;
107.60 + }
107.61 +
107.62 + private static class RandomAccessFileWriter implements RandomAccessWriter {
107.63 +
107.64 + RandomAccessFile raf;
107.65 +
107.66 + public RandomAccessFileWriter(File file) throws FileNotFoundException {
107.67 + this.raf = new RandomAccessFile(file, "rw");
107.68 + }
107.69 +
107.70 + public RandomAccessFileWriter(String name) throws FileNotFoundException {
107.71 + this.raf = new RandomAccessFile(name, "rw");
107.72 + }
107.73 +
107.74 + public void seek(long chunksizepointer) throws IOException {
107.75 + raf.seek(chunksizepointer);
107.76 + }
107.77 +
107.78 + public long getPointer() throws IOException {
107.79 + return raf.getFilePointer();
107.80 + }
107.81 +
107.82 + public void close() throws IOException {
107.83 + raf.close();
107.84 + }
107.85 +
107.86 + public void write(int b) throws IOException {
107.87 + raf.write(b);
107.88 + }
107.89 +
107.90 + public void write(byte[] b, int off, int len) throws IOException {
107.91 + raf.write(b, off, len);
107.92 + }
107.93 +
107.94 + public void write(byte[] bytes) throws IOException {
107.95 + raf.write(bytes);
107.96 + }
107.97 +
107.98 + public long length() throws IOException {
107.99 + return raf.length();
107.100 + }
107.101 +
107.102 + public void setLength(long i) throws IOException {
107.103 + raf.setLength(i);
107.104 + }
107.105 + }
107.106 +
107.107 + private static class RandomAccessByteWriter implements RandomAccessWriter {
107.108 +
107.109 + byte[] buff = new byte[32];
107.110 + int length = 0;
107.111 + int pos = 0;
107.112 + byte[] s;
107.113 + OutputStream stream;
107.114 +
107.115 + public RandomAccessByteWriter(OutputStream stream) {
107.116 + this.stream = stream;
107.117 + }
107.118 +
107.119 + public void seek(long chunksizepointer) throws IOException {
107.120 + pos = (int) chunksizepointer;
107.121 + }
107.122 +
107.123 + public long getPointer() throws IOException {
107.124 + return pos;
107.125 + }
107.126 +
107.127 + public void close() throws IOException {
107.128 + stream.write(buff, 0, length);
107.129 + stream.close();
107.130 + }
107.131 +
107.132 + public void write(int b) throws IOException {
107.133 + if (s == null)
107.134 + s = new byte[1];
107.135 + s[0] = (byte)b;
107.136 + write(s, 0, 1);
107.137 + }
107.138 +
107.139 + public void write(byte[] b, int off, int len) throws IOException {
107.140 + int newsize = pos + len;
107.141 + if (newsize > length)
107.142 + setLength(newsize);
107.143 + int end = off + len;
107.144 + for (int i = off; i < end; i++) {
107.145 + buff[pos++] = b[i];
107.146 + }
107.147 + }
107.148 +
107.149 + public void write(byte[] bytes) throws IOException {
107.150 + write(bytes, 0, bytes.length);
107.151 + }
107.152 +
107.153 + public long length() throws IOException {
107.154 + return length;
107.155 + }
107.156 +
107.157 + public void setLength(long i) throws IOException {
107.158 + length = (int) i;
107.159 + if (length > buff.length) {
107.160 + int newlen = Math.max(buff.length << 1, length);
107.161 + byte[] newbuff = new byte[newlen];
107.162 + System.arraycopy(buff, 0, newbuff, 0, buff.length);
107.163 + buff = newbuff;
107.164 + }
107.165 + }
107.166 + }
107.167 + private int chunktype = 0; // 0=RIFF, 1=LIST; 2=CHUNK
107.168 + private RandomAccessWriter raf;
107.169 + private long chunksizepointer;
107.170 + private long startpointer;
107.171 + private RIFFWriter childchunk = null;
107.172 + private boolean open = true;
107.173 + private boolean writeoverride = false;
107.174 +
107.175 + public RIFFWriter(String name, String format) throws IOException {
107.176 + this(new RandomAccessFileWriter(name), format, 0);
107.177 + }
107.178 +
107.179 + public RIFFWriter(File file, String format) throws IOException {
107.180 + this(new RandomAccessFileWriter(file), format, 0);
107.181 + }
107.182 +
107.183 + public RIFFWriter(OutputStream stream, String format) throws IOException {
107.184 + this(new RandomAccessByteWriter(stream), format, 0);
107.185 + }
107.186 +
107.187 + private RIFFWriter(RandomAccessWriter raf, String format, int chunktype)
107.188 + throws IOException {
107.189 + if (chunktype == 0)
107.190 + if (raf.length() != 0)
107.191 + raf.setLength(0);
107.192 + this.raf = raf;
107.193 + if (raf.getPointer() % 2 != 0)
107.194 + raf.write(0);
107.195 +
107.196 + if (chunktype == 0)
107.197 + raf.write("RIFF".getBytes("ascii"));
107.198 + else if (chunktype == 1)
107.199 + raf.write("LIST".getBytes("ascii"));
107.200 + else
107.201 + raf.write((format + " ").substring(0, 4).getBytes("ascii"));
107.202 +
107.203 + chunksizepointer = raf.getPointer();
107.204 + this.chunktype = 2;
107.205 + writeUnsignedInt(0);
107.206 + this.chunktype = chunktype;
107.207 + startpointer = raf.getPointer();
107.208 + if (chunktype != 2)
107.209 + raf.write((format + " ").substring(0, 4).getBytes("ascii"));
107.210 +
107.211 + }
107.212 +
107.213 + public void seek(long pos) throws IOException {
107.214 + raf.seek(pos);
107.215 + }
107.216 +
107.217 + public long getFilePointer() throws IOException {
107.218 + return raf.getPointer();
107.219 + }
107.220 +
107.221 + public void setWriteOverride(boolean writeoverride) {
107.222 + this.writeoverride = writeoverride;
107.223 + }
107.224 +
107.225 + public boolean getWriteOverride() {
107.226 + return writeoverride;
107.227 + }
107.228 +
107.229 + public void close() throws IOException {
107.230 + if (!open)
107.231 + return;
107.232 + if (childchunk != null) {
107.233 + childchunk.close();
107.234 + childchunk = null;
107.235 + }
107.236 +
107.237 + int bakchunktype = chunktype;
107.238 + long fpointer = raf.getPointer();
107.239 + raf.seek(chunksizepointer);
107.240 + chunktype = 2;
107.241 + writeUnsignedInt(fpointer - startpointer);
107.242 +
107.243 + if (bakchunktype == 0)
107.244 + raf.close();
107.245 + else
107.246 + raf.seek(fpointer);
107.247 + open = false;
107.248 + raf = null;
107.249 + }
107.250 +
107.251 + public void write(int b) throws IOException {
107.252 + if (!writeoverride) {
107.253 + if (chunktype != 2) {
107.254 + throw new IllegalArgumentException(
107.255 + "Only chunks can write bytes!");
107.256 + }
107.257 + if (childchunk != null) {
107.258 + childchunk.close();
107.259 + childchunk = null;
107.260 + }
107.261 + }
107.262 + raf.write(b);
107.263 + }
107.264 +
107.265 + public void write(byte b[], int off, int len) throws IOException {
107.266 + if (!writeoverride) {
107.267 + if (chunktype != 2) {
107.268 + throw new IllegalArgumentException(
107.269 + "Only chunks can write bytes!");
107.270 + }
107.271 + if (childchunk != null) {
107.272 + childchunk.close();
107.273 + childchunk = null;
107.274 + }
107.275 + }
107.276 + raf.write(b, off, len);
107.277 + }
107.278 +
107.279 + public RIFFWriter writeList(String format) throws IOException {
107.280 + if (chunktype == 2) {
107.281 + throw new IllegalArgumentException(
107.282 + "Only LIST and RIFF can write lists!");
107.283 + }
107.284 + if (childchunk != null) {
107.285 + childchunk.close();
107.286 + childchunk = null;
107.287 + }
107.288 + childchunk = new RIFFWriter(this.raf, format, 1);
107.289 + return childchunk;
107.290 + }
107.291 +
107.292 + public RIFFWriter writeChunk(String format) throws IOException {
107.293 + if (chunktype == 2) {
107.294 + throw new IllegalArgumentException(
107.295 + "Only LIST and RIFF can write chunks!");
107.296 + }
107.297 + if (childchunk != null) {
107.298 + childchunk.close();
107.299 + childchunk = null;
107.300 + }
107.301 + childchunk = new RIFFWriter(this.raf, format, 2);
107.302 + return childchunk;
107.303 + }
107.304 +
107.305 + // Write ASCII chars to stream
107.306 + public void writeString(String string) throws IOException {
107.307 + byte[] buff = string.getBytes();
107.308 + write(buff);
107.309 + }
107.310 +
107.311 + // Write ASCII chars to stream
107.312 + public void writeString(String string, int len) throws IOException {
107.313 + byte[] buff = string.getBytes();
107.314 + if (buff.length > len)
107.315 + write(buff, 0, len);
107.316 + else {
107.317 + write(buff);
107.318 + for (int i = buff.length; i < len; i++)
107.319 + write(0);
107.320 + }
107.321 + }
107.322 +
107.323 + // Write 8 bit signed integer to stream
107.324 + public void writeByte(int b) throws IOException {
107.325 + write(b);
107.326 + }
107.327 +
107.328 + // Write 16 bit signed integer to stream
107.329 + public void writeShort(short b) throws IOException {
107.330 + write((b >>> 0) & 0xFF);
107.331 + write((b >>> 8) & 0xFF);
107.332 + }
107.333 +
107.334 + // Write 32 bit signed integer to stream
107.335 + public void writeInt(int b) throws IOException {
107.336 + write((b >>> 0) & 0xFF);
107.337 + write((b >>> 8) & 0xFF);
107.338 + write((b >>> 16) & 0xFF);
107.339 + write((b >>> 24) & 0xFF);
107.340 + }
107.341 +
107.342 + // Write 64 bit signed integer to stream
107.343 + public void writeLong(long b) throws IOException {
107.344 + write((int) (b >>> 0) & 0xFF);
107.345 + write((int) (b >>> 8) & 0xFF);
107.346 + write((int) (b >>> 16) & 0xFF);
107.347 + write((int) (b >>> 24) & 0xFF);
107.348 + write((int) (b >>> 32) & 0xFF);
107.349 + write((int) (b >>> 40) & 0xFF);
107.350 + write((int) (b >>> 48) & 0xFF);
107.351 + write((int) (b >>> 56) & 0xFF);
107.352 + }
107.353 +
107.354 + // Write 8 bit unsigned integer to stream
107.355 + public void writeUnsignedByte(int b) throws IOException {
107.356 + writeByte((byte) b);
107.357 + }
107.358 +
107.359 + // Write 16 bit unsigned integer to stream
107.360 + public void writeUnsignedShort(int b) throws IOException {
107.361 + writeShort((short) b);
107.362 + }
107.363 +
107.364 + // Write 32 bit unsigned integer to stream
107.365 + public void writeUnsignedInt(long b) throws IOException {
107.366 + writeInt((int) b);
107.367 + }
107.368 +}
108.1 --- a/src/share/classes/com/sun/media/sound/RealTimeSequencer.java Thu Jan 29 21:46:48 2009 -0800
108.2 +++ b/src/share/classes/com/sun/media/sound/RealTimeSequencer.java Tue Feb 03 22:02:55 2009 -0800
108.3 @@ -54,10 +54,6 @@
108.4 private final static boolean DEBUG_PUMP = false;
108.5 private final static boolean DEBUG_PUMP_ALL = false;
108.6
108.7 -
108.8 - /** if true, we bridge RMF files over to the old MixerSequencer */
108.9 - private final static boolean RMF = true;
108.10 -
108.11 /**
108.12 * Event Dispatcher thread. Should be using a shared event
108.13 * dispatcher instance with a factory in EventDispatcher
108.14 @@ -145,9 +141,6 @@
108.15 private ArrayList controllerEventListeners = new ArrayList();
108.16
108.17
108.18 - /** for RMF media we need the RMF sequencer */
108.19 - private MixerSequencer seqBridge = null;
108.20 -
108.21 /** automatic connection support */
108.22 private boolean autoConnect = false;
108.23
108.24 @@ -220,21 +213,6 @@
108.25 playThread.setSequence(sequence);
108.26 }
108.27 }
108.28 - if (RMF) {
108.29 - if (seqBridge != null) {
108.30 - seqBridge.close();
108.31 - seqBridge = null;
108.32 - }
108.33 - // if previous file was an RMF, but this file is not RMF,
108.34 - // then need to call implOpen again!
108.35 - if (isOpen() && sequence != null && playThread == null) {
108.36 - try {
108.37 - implOpen();
108.38 - } catch (MidiUnavailableException mue) {
108.39 - if (Printer.err) mue.printStackTrace();
108.40 - }
108.41 - }
108.42 - }
108.43
108.44 if (Printer.trace) Printer.trace("<< RealTimeSequencer: setSequence(" + sequence +") completed");
108.45 }
108.46 @@ -249,52 +227,6 @@
108.47 return;
108.48 }
108.49
108.50 - // need to be able to detect RMF
108.51 - if (RMF) {
108.52 - MidiFileFormat fileFormat = MidiSystem.getMidiFileFormat(stream); // can throw IOException, InvalidMidiDataException
108.53 - int type = fileFormat.getType();
108.54 - int resolution = fileFormat.getResolution();
108.55 - if (Printer.debug) Printer.debug("Got file with type="+type+" and resolution="+resolution);
108.56 - if (resolution == MidiFileFormat.UNKNOWN_LENGTH) {
108.57 - // seems to be RMF
108.58 - if (seqBridge == null) {
108.59 - try {
108.60 - seqBridge = new MixerSequencer();
108.61 - if (isOpen()) {
108.62 - seqBridge.open();
108.63 - }
108.64 - } catch (MidiUnavailableException mue) {
108.65 - // uhum, strange situation. Need to cast to InvalidMidiDataException
108.66 - throw new InvalidMidiDataException(mue.getMessage());
108.67 - }
108.68 - }
108.69 - seqBridge.setSequence(stream);
108.70 - // propagate state
108.71 - seqBridge.setTempoFactor(getTempoFactor());
108.72 -
108.73 - // propagate listeners
108.74 - synchronized(metaEventListeners) {
108.75 - for (int i = 0 ; i < metaEventListeners.size(); i++) {
108.76 - seqBridge.addMetaEventListener((MetaEventListener) (metaEventListeners.get(i)));
108.77 - }
108.78 - }
108.79 - synchronized(controllerEventListeners) {
108.80 - for (int i = 0 ; i < controllerEventListeners.size(); i++) {
108.81 - ControllerListElement cve = (ControllerListElement) (controllerEventListeners.get(i));
108.82 - seqBridge.addControllerEventListener(cve.listener, cve.controllers);
108.83 - }
108.84 - }
108.85 - // disable the current sequence of RealTimeSequencer
108.86 - //setSequence((Sequence) null); -> will remove bridge again!
108.87 - this.sequence = null;
108.88 - return;
108.89 - }
108.90 - if (seqBridge != null) {
108.91 - seqBridge.close();
108.92 - seqBridge = null;
108.93 - }
108.94 - }
108.95 -
108.96 Sequence seq = MidiSystem.getSequence(stream); // can throw IOException, InvalidMidiDataException
108.97
108.98 setSequence(seq);
108.99 @@ -305,22 +237,11 @@
108.100
108.101
108.102 public Sequence getSequence() {
108.103 - if (RMF) {
108.104 - if (seqBridge != null) {
108.105 - return seqBridge.getSequence();
108.106 - }
108.107 - }
108.108 return sequence;
108.109 }
108.110
108.111
108.112 public synchronized void start() {
108.113 - if (RMF) {
108.114 - if (seqBridge != null) {
108.115 - seqBridge.start();
108.116 - return;
108.117 - }
108.118 - }
108.119 if (Printer.trace) Printer.trace(">> RealTimeSequencer: start()");
108.120
108.121 // sequencer not open: throw an exception
108.122 @@ -346,12 +267,6 @@
108.123
108.124
108.125 public synchronized void stop() {
108.126 - if (RMF) {
108.127 - if (seqBridge != null) {
108.128 - seqBridge.stop();
108.129 - return;
108.130 - }
108.131 - }
108.132 if (Printer.trace) Printer.trace(">> RealTimeSequencer: stop()");
108.133
108.134 if (!isOpen()) {
108.135 @@ -373,23 +288,11 @@
108.136
108.137
108.138 public boolean isRunning() {
108.139 - if (RMF) {
108.140 - if (seqBridge != null) {
108.141 - return seqBridge.isRunning();
108.142 - }
108.143 - }
108.144 return running;
108.145 }
108.146
108.147
108.148 public void startRecording() {
108.149 - if (RMF) {
108.150 - if (seqBridge != null) {
108.151 - seqBridge.startRecording();
108.152 - return;
108.153 - }
108.154 - }
108.155 -
108.156 if (!isOpen()) {
108.157 throw new IllegalStateException("Sequencer not open");
108.158 }
108.159 @@ -400,13 +303,6 @@
108.160
108.161
108.162 public void stopRecording() {
108.163 - if (RMF) {
108.164 - if (seqBridge != null) {
108.165 - seqBridge.stopRecording();
108.166 - return;
108.167 - }
108.168 - }
108.169 -
108.170 if (!isOpen()) {
108.171 throw new IllegalStateException("Sequencer not open");
108.172 }
108.173 @@ -415,23 +311,11 @@
108.174
108.175
108.176 public boolean isRecording() {
108.177 - if (RMF) {
108.178 - if (seqBridge != null) {
108.179 - return seqBridge.isRecording();
108.180 - }
108.181 - }
108.182 return recording;
108.183 }
108.184
108.185
108.186 public void recordEnable(Track track, int channel) {
108.187 - if (RMF) {
108.188 - if (seqBridge != null) {
108.189 - seqBridge.recordEnable(track, channel);
108.190 - return;
108.191 - }
108.192 - }
108.193 -
108.194 if (!findTrack(track)) {
108.195 throw new IllegalArgumentException("Track does not exist in the current sequence");
108.196 }
108.197 @@ -449,13 +333,6 @@
108.198
108.199
108.200 public void recordDisable(Track track) {
108.201 - if (RMF) {
108.202 - if (seqBridge != null) {
108.203 - seqBridge.recordDisable(track);
108.204 - return;
108.205 - }
108.206 - }
108.207 -
108.208 synchronized(recordingTracks) {
108.209 RecordingTrack rc = RecordingTrack.get(recordingTracks, track);
108.210 if (rc != null) {
108.211 @@ -482,11 +359,6 @@
108.212
108.213
108.214 public float getTempoInBPM() {
108.215 - if (RMF) {
108.216 - if (seqBridge != null) {
108.217 - return seqBridge.getTempoInBPM();
108.218 - }
108.219 - }
108.220 if (Printer.trace) Printer.trace(">> RealTimeSequencer: getTempoInBPM() ");
108.221
108.222 return (float) MidiUtils.convertTempo(getTempoInMPQ());
108.223 @@ -494,12 +366,6 @@
108.224
108.225
108.226 public void setTempoInBPM(float bpm) {
108.227 - if (RMF) {
108.228 - if (seqBridge != null) {
108.229 - seqBridge.setTempoInBPM(bpm);
108.230 - return;
108.231 - }
108.232 - }
108.233 if (Printer.trace) Printer.trace(">> RealTimeSequencer: setTempoInBPM() ");
108.234 if (bpm <= 0) {
108.235 // should throw IllegalArgumentException
108.236 @@ -511,12 +377,6 @@
108.237
108.238
108.239 public float getTempoInMPQ() {
108.240 - if (RMF) {
108.241 - if (seqBridge != null) {
108.242 - return seqBridge.getTempoInMPQ();
108.243 - }
108.244 - }
108.245 -
108.246 if (Printer.trace) Printer.trace(">> RealTimeSequencer: getTempoInMPQ() ");
108.247
108.248 if (needCaching()) {
108.249 @@ -537,12 +397,6 @@
108.250
108.251
108.252 public void setTempoInMPQ(float mpq) {
108.253 - if (RMF) {
108.254 - if (seqBridge != null) {
108.255 - seqBridge.setTempoInMPQ(mpq);
108.256 - return;
108.257 - }
108.258 - }
108.259 if (mpq <= 0) {
108.260 // should throw IllegalArgumentException
108.261 mpq = 1.0f;
108.262 @@ -564,12 +418,6 @@
108.263
108.264
108.265 public void setTempoFactor(float factor) {
108.266 - if (RMF) {
108.267 - if (seqBridge != null) {
108.268 - seqBridge.setTempoFactor(factor);
108.269 - return;
108.270 - }
108.271 - }
108.272 if (factor <= 0) {
108.273 // should throw IllegalArgumentException
108.274 return;
108.275 @@ -588,11 +436,6 @@
108.276
108.277
108.278 public float getTempoFactor() {
108.279 - if (RMF) {
108.280 - if (seqBridge != null) {
108.281 - return seqBridge.getTempoFactor();
108.282 - }
108.283 - }
108.284 if (Printer.trace) Printer.trace(">> RealTimeSequencer: getTempoFactor() ");
108.285
108.286 if (needCaching()) {
108.287 @@ -606,11 +449,6 @@
108.288
108.289
108.290 public long getTickLength() {
108.291 - if (RMF) {
108.292 - if (seqBridge != null) {
108.293 - return seqBridge.getTickLength();
108.294 - }
108.295 - }
108.296 if (Printer.trace) Printer.trace(">> RealTimeSequencer: getTickLength() ");
108.297
108.298 if (sequence == null) {
108.299 @@ -622,11 +460,6 @@
108.300
108.301
108.302 public synchronized long getTickPosition() {
108.303 - if (RMF) {
108.304 - if (seqBridge != null) {
108.305 - return seqBridge.getTickPosition();
108.306 - }
108.307 - }
108.308 if (Printer.trace) Printer.trace(">> RealTimeSequencer: getTickPosition() ");
108.309
108.310 if (getDataPump() == null || sequence == null) {
108.311 @@ -638,12 +471,6 @@
108.312
108.313
108.314 public synchronized void setTickPosition(long tick) {
108.315 - if (RMF) {
108.316 - if (seqBridge != null) {
108.317 - seqBridge.setTickPosition(tick);
108.318 - return;
108.319 - }
108.320 - }
108.321 if (tick < 0) {
108.322 // should throw IllegalArgumentException
108.323 return;
108.324 @@ -667,12 +494,6 @@
108.325
108.326
108.327 public long getMicrosecondLength() {
108.328 - if (RMF) {
108.329 - if (seqBridge != null) {
108.330 - return seqBridge.getMicrosecondLength();
108.331 - }
108.332 - }
108.333 -
108.334 if (Printer.trace) Printer.trace(">> RealTimeSequencer: getMicrosecondLength() ");
108.335
108.336 if (sequence == null) {
108.337 @@ -684,12 +505,6 @@
108.338
108.339
108.340 public long getMicrosecondPosition() {
108.341 - if (RMF) {
108.342 - if (seqBridge != null) {
108.343 - return seqBridge.getMicrosecondPosition();
108.344 - }
108.345 - }
108.346 -
108.347 if (Printer.trace) Printer.trace(">> RealTimeSequencer: getMicrosecondPosition() ");
108.348
108.349 if (getDataPump() == null || sequence == null) {
108.350 @@ -702,13 +517,6 @@
108.351
108.352
108.353 public void setMicrosecondPosition(long microseconds) {
108.354 - if (RMF) {
108.355 - if (seqBridge != null) {
108.356 - seqBridge.setMicrosecondPosition(microseconds);
108.357 - return;
108.358 - }
108.359 - }
108.360 -
108.361 if (microseconds < 0) {
108.362 // should throw IllegalArgumentException
108.363 return;
108.364 @@ -734,33 +542,16 @@
108.365
108.366
108.367 public void setMasterSyncMode(Sequencer.SyncMode sync) {
108.368 - if (RMF) {
108.369 - if (seqBridge != null) {
108.370 - seqBridge.setMasterSyncMode(sync);
108.371 - return;
108.372 - }
108.373 - }
108.374 // not supported
108.375 }
108.376
108.377
108.378 public Sequencer.SyncMode getMasterSyncMode() {
108.379 - if (RMF) {
108.380 - if (seqBridge != null) {
108.381 - return seqBridge.getMasterSyncMode();
108.382 - }
108.383 - }
108.384 return masterSyncMode;
108.385 }
108.386
108.387
108.388 public Sequencer.SyncMode[] getMasterSyncModes() {
108.389 - if (RMF) {
108.390 - if (seqBridge != null) {
108.391 - return seqBridge.getMasterSyncModes();
108.392 - }
108.393 - }
108.394 -
108.395 Sequencer.SyncMode[] returnedModes = new Sequencer.SyncMode[masterSyncModes.length];
108.396 System.arraycopy(masterSyncModes, 0, returnedModes, 0, masterSyncModes.length);
108.397 return returnedModes;
108.398 @@ -768,33 +559,16 @@
108.399
108.400
108.401 public void setSlaveSyncMode(Sequencer.SyncMode sync) {
108.402 - if (RMF) {
108.403 - if (seqBridge != null) {
108.404 - seqBridge.setSlaveSyncMode(sync);
108.405 - return;
108.406 - }
108.407 - }
108.408 // not supported
108.409 }
108.410
108.411
108.412 public Sequencer.SyncMode getSlaveSyncMode() {
108.413 - if (RMF) {
108.414 - if (seqBridge != null) {
108.415 - return seqBridge.getSlaveSyncMode();
108.416 - }
108.417 - }
108.418 return slaveSyncMode;
108.419 }
108.420
108.421
108.422 public Sequencer.SyncMode[] getSlaveSyncModes() {
108.423 - if (RMF) {
108.424 - if (seqBridge != null) {
108.425 - return seqBridge.getSlaveSyncModes();
108.426 - }
108.427 - }
108.428 -
108.429 Sequencer.SyncMode[] returnedModes = new Sequencer.SyncMode[slaveSyncModes.length];
108.430 System.arraycopy(slaveSyncModes, 0, returnedModes, 0, slaveSyncModes.length);
108.431 return returnedModes;
108.432 @@ -812,12 +586,6 @@
108.433
108.434
108.435 public synchronized void setTrackMute(int track, boolean mute) {
108.436 - if (RMF) {
108.437 - if (seqBridge != null) {
108.438 - seqBridge.setTrackMute(track, mute);
108.439 - return;
108.440 - }
108.441 - }
108.442 int trackCount = getTrackCount();
108.443 if (track < 0 || track >= getTrackCount()) return;
108.444 trackMuted = ensureBoolArraySize(trackMuted, trackCount);
108.445 @@ -829,11 +597,6 @@
108.446
108.447
108.448 public synchronized boolean getTrackMute(int track) {
108.449 - if (RMF) {
108.450 - if (seqBridge != null) {
108.451 - return seqBridge.getTrackMute(track);
108.452 - }
108.453 - }
108.454 if (track < 0 || track >= getTrackCount()) return false;
108.455 if (trackMuted == null || trackMuted.length <= track) return false;
108.456 return trackMuted[track];
108.457 @@ -841,12 +604,6 @@
108.458
108.459
108.460 public synchronized void setTrackSolo(int track, boolean solo) {
108.461 - if (RMF) {
108.462 - if (seqBridge != null) {
108.463 - seqBridge.setTrackSolo(track, solo);
108.464 - return;
108.465 - }
108.466 - }
108.467 int trackCount = getTrackCount();
108.468 if (track < 0 || track >= getTrackCount()) return;
108.469 trackSolo = ensureBoolArraySize(trackSolo, trackCount);
108.470 @@ -858,11 +615,6 @@
108.471
108.472
108.473 public synchronized boolean getTrackSolo(int track) {
108.474 - if (RMF) {
108.475 - if (seqBridge != null) {
108.476 - return seqBridge.getTrackSolo(track);
108.477 - }
108.478 - }
108.479 if (track < 0 || track >= getTrackCount()) return false;
108.480 if (trackSolo == null || trackSolo.length <= track) return false;
108.481 return trackSolo[track];
108.482 @@ -870,12 +622,6 @@
108.483
108.484
108.485 public boolean addMetaEventListener(MetaEventListener listener) {
108.486 - if (RMF) {
108.487 - if (seqBridge != null) {
108.488 - seqBridge.addMetaEventListener(listener);
108.489 - // do not return here!
108.490 - }
108.491 - }
108.492 synchronized(metaEventListeners) {
108.493 if (! metaEventListeners.contains(listener)) {
108.494
108.495 @@ -887,12 +633,6 @@
108.496
108.497
108.498 public void removeMetaEventListener(MetaEventListener listener) {
108.499 - if (RMF) {
108.500 - if (seqBridge != null) {
108.501 - seqBridge.removeMetaEventListener(listener);
108.502 - // do not return here!
108.503 - }
108.504 - }
108.505 synchronized(metaEventListeners) {
108.506 int index = metaEventListeners.indexOf(listener);
108.507 if (index >= 0) {
108.508 @@ -903,13 +643,6 @@
108.509
108.510
108.511 public int[] addControllerEventListener(ControllerEventListener listener, int[] controllers) {
108.512 - if (RMF) {
108.513 - if (seqBridge != null) {
108.514 - seqBridge.addControllerEventListener(listener, controllers);
108.515 - // do not return here!
108.516 - }
108.517 - }
108.518 -
108.519 synchronized(controllerEventListeners) {
108.520
108.521 // first find the listener. if we have one, add the controllers
108.522 @@ -938,12 +671,6 @@
108.523
108.524
108.525 public int[] removeControllerEventListener(ControllerEventListener listener, int[] controllers) {
108.526 - if (RMF) {
108.527 - if (seqBridge != null) {
108.528 - seqBridge.removeControllerEventListener(listener, controllers);
108.529 - // do not return here!
108.530 - }
108.531 - }
108.532 synchronized(controllerEventListeners) {
108.533 ControllerListElement cve = null;
108.534 boolean flag = false;
108.535 @@ -973,12 +700,6 @@
108.536 ////////////////// LOOPING (added in 1.5) ///////////////////////
108.537
108.538 public void setLoopStartPoint(long tick) {
108.539 - if (RMF) {
108.540 - if (seqBridge != null) {
108.541 - seqBridge.setLoopStartPoint(tick);
108.542 - return;
108.543 - }
108.544 - }
108.545 if ((tick > getTickLength())
108.546 || ((loopEnd != -1) && (tick > loopEnd))
108.547 || (tick < 0)) {
108.548 @@ -988,21 +709,10 @@
108.549 }
108.550
108.551 public long getLoopStartPoint() {
108.552 - if (RMF) {
108.553 - if (seqBridge != null) {
108.554 - return seqBridge.getLoopStartPoint();
108.555 - }
108.556 - }
108.557 return loopStart;
108.558 }
108.559
108.560 public void setLoopEndPoint(long tick) {
108.561 - if (RMF) {
108.562 - if (seqBridge != null) {
108.563 - seqBridge.setLoopEndPoint(tick);
108.564 - return;
108.565 - }
108.566 - }
108.567 if ((tick > getTickLength())
108.568 || ((loopStart > tick) && (tick != -1))
108.569 || (tick < -1)) {
108.570 @@ -1012,21 +722,10 @@
108.571 }
108.572
108.573 public long getLoopEndPoint() {
108.574 - if (RMF) {
108.575 - if (seqBridge != null) {
108.576 - return seqBridge.getLoopEndPoint();
108.577 - }
108.578 - }
108.579 return loopEnd;
108.580 }
108.581
108.582 public void setLoopCount(int count) {
108.583 - if (RMF) {
108.584 - if (seqBridge != null) {
108.585 - seqBridge.setLoopCount(count);
108.586 - return;
108.587 - }
108.588 - }
108.589 if (count != LOOP_CONTINUOUSLY
108.590 && count < 0) {
108.591 throw new IllegalArgumentException("illegal value for loop count: "+count);
108.592 @@ -1038,11 +737,6 @@
108.593 }
108.594
108.595 public int getLoopCount() {
108.596 - if (RMF) {
108.597 - if (seqBridge != null) {
108.598 - return seqBridge.getLoopCount();
108.599 - }
108.600 - }
108.601 return loopCount;
108.602 }
108.603
108.604 @@ -1053,13 +747,6 @@
108.605 */
108.606 protected void implOpen() throws MidiUnavailableException {
108.607 if (Printer.trace) Printer.trace(">> RealTimeSequencer: implOpen()");
108.608 - if (RMF) {
108.609 - if (seqBridge != null) {
108.610 - seqBridge.open();
108.611 - if (Printer.trace) Printer.trace("<< RealTimeSequencer: -> called seqBridge.open");
108.612 - return;
108.613 - }
108.614 - }
108.615
108.616 //openInternalSynth();
108.617
108.618 @@ -1095,12 +782,6 @@
108.619 synth.open();
108.620 if (synth instanceof ReferenceCountingDevice) {
108.621 rec = ((ReferenceCountingDevice) synth).getReceiverReferenceCounting();
108.622 - if (synth.getClass().toString().contains("com.sun.media.sound.MixerSynth")
108.623 - && (synth.getDefaultSoundbank() == null)) {
108.624 - // don't use this receiver if no soundbank available
108.625 - rec = null;
108.626 - synth.close();
108.627 - }
108.628 } else {
108.629 rec = synth.getReceiver();
108.630 }
108.631 @@ -1147,12 +828,6 @@
108.632
108.633
108.634 protected synchronized void implClose() {
108.635 - if (RMF) {
108.636 - if (seqBridge != null) {
108.637 - seqBridge.close();
108.638 - // don't return here!
108.639 - }
108.640 - }
108.641 if (Printer.trace) Printer.trace(">> RealTimeSequencer: implClose() ");
108.642
108.643 if (playThread == null) {
108.644 @@ -1302,12 +977,6 @@
108.645 // OVERRIDES OF ABSTRACT MIDI DEVICE METHODS
108.646
108.647 protected boolean hasReceivers() {
108.648 - if (RMF) {
108.649 - if (seqBridge != null) {
108.650 - //RMF does not allow recording
108.651 - return false;
108.652 - }
108.653 - }
108.654 return true;
108.655 }
108.656
108.657 @@ -1318,12 +987,6 @@
108.658
108.659
108.660 protected boolean hasTransmitters() {
108.661 - if (RMF) {
108.662 - if (seqBridge != null) {
108.663 - //RMF does never allow setting own receivers
108.664 - return false;
108.665 - }
108.666 - }
108.667 return true;
108.668 }
108.669
109.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
109.2 +++ b/src/share/classes/com/sun/media/sound/SF2GlobalRegion.java Tue Feb 03 22:02:55 2009 -0800
109.3 @@ -0,0 +1,33 @@
109.4 +/*
109.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
109.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
109.7 + *
109.8 + * This code is free software; you can redistribute it and/or modify it
109.9 + * under the terms of the GNU General Public License version 2 only, as
109.10 + * published by the Free Software Foundation. Sun designates this
109.11 + * particular file as subject to the "Classpath" exception as provided
109.12 + * by Sun in the LICENSE file that accompanied this code.
109.13 + *
109.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
109.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
109.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
109.17 + * version 2 for more details (a copy is included in the LICENSE file that
109.18 + * accompanied this code).
109.19 + *
109.20 + * You should have received a copy of the GNU General Public License version
109.21 + * 2 along with this work; if not, write to the Free Software Foundation,
109.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
109.23 + *
109.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
109.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
109.26 + * have any questions.
109.27 + */
109.28 +package com.sun.media.sound;
109.29 +
109.30 +/**
109.31 + * Soundfont global region.
109.32 + *
109.33 + * @author Karl Helgason
109.34 + */
109.35 +public class SF2GlobalRegion extends SF2Region {
109.36 +}
110.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
110.2 +++ b/src/share/classes/com/sun/media/sound/SF2Instrument.java Tue Feb 03 22:02:55 2009 -0800
110.3 @@ -0,0 +1,911 @@
110.4 +/*
110.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
110.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
110.7 + *
110.8 + * This code is free software; you can redistribute it and/or modify it
110.9 + * under the terms of the GNU General Public License version 2 only, as
110.10 + * published by the Free Software Foundation. Sun designates this
110.11 + * particular file as subject to the "Classpath" exception as provided
110.12 + * by Sun in the LICENSE file that accompanied this code.
110.13 + *
110.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
110.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
110.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
110.17 + * version 2 for more details (a copy is included in the LICENSE file that
110.18 + * accompanied this code).
110.19 + *
110.20 + * You should have received a copy of the GNU General Public License version
110.21 + * 2 along with this work; if not, write to the Free Software Foundation,
110.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
110.23 + *
110.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
110.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
110.26 + * have any questions.
110.27 + */
110.28 +package com.sun.media.sound;
110.29 +
110.30 +import java.util.ArrayList;
110.31 +import java.util.HashMap;
110.32 +import java.util.List;
110.33 +import java.util.Map;
110.34 +
110.35 +import javax.sound.midi.Patch;
110.36 +
110.37 +/**
110.38 + * Soundfont instrument.
110.39 + *
110.40 + * @author Karl Helgason
110.41 + */
110.42 +public class SF2Instrument extends ModelInstrument {
110.43 +
110.44 + protected String name = "";
110.45 + protected int preset = 0;
110.46 + protected int bank = 0;
110.47 + protected long library = 0;
110.48 + protected long genre = 0;
110.49 + protected long morphology = 0;
110.50 + protected SF2GlobalRegion globalregion = null;
110.51 + protected List<SF2InstrumentRegion> regions
110.52 + = new ArrayList<SF2InstrumentRegion>();
110.53 +
110.54 + public SF2Instrument() {
110.55 + super(null, null, null, null);
110.56 + }
110.57 +
110.58 + public SF2Instrument(SF2Soundbank soundbank) {
110.59 + super(soundbank, null, null, null);
110.60 + }
110.61 +
110.62 + public String getName() {
110.63 + return name;
110.64 + }
110.65 +
110.66 + public void setName(String name) {
110.67 + this.name = name;
110.68 + }
110.69 +
110.70 + public Patch getPatch() {
110.71 + if (bank == 128)
110.72 + return new ModelPatch(0, preset, true);
110.73 + else
110.74 + return new ModelPatch(bank << 7, preset, false);
110.75 + }
110.76 +
110.77 + public void setPatch(Patch patch) {
110.78 + if (patch instanceof ModelPatch && ((ModelPatch) patch).isPercussion()) {
110.79 + bank = 128;
110.80 + preset = patch.getProgram();
110.81 + } else {
110.82 + bank = patch.getBank() >> 7;
110.83 + preset = patch.getProgram();
110.84 + }
110.85 + }
110.86 +
110.87 + public Object getData() {
110.88 + return null;
110.89 + }
110.90 +
110.91 + public long getGenre() {
110.92 + return genre;
110.93 + }
110.94 +
110.95 + public void setGenre(long genre) {
110.96 + this.genre = genre;
110.97 + }
110.98 +
110.99 + public long getLibrary() {
110.100 + return library;
110.101 + }
110.102 +
110.103 + public void setLibrary(long library) {
110.104 + this.library = library;
110.105 + }
110.106 +
110.107 + public long getMorphology() {
110.108 + return morphology;
110.109 + }
110.110 +
110.111 + public void setMorphology(long morphology) {
110.112 + this.morphology = morphology;
110.113 + }
110.114 +
110.115 + public List<SF2InstrumentRegion> getRegions() {
110.116 + return regions;
110.117 + }
110.118 +
110.119 + public SF2GlobalRegion getGlobalRegion() {
110.120 + return globalregion;
110.121 + }
110.122 +
110.123 + public void setGlobalZone(SF2GlobalRegion zone) {
110.124 + globalregion = zone;
110.125 + }
110.126 +
110.127 + public String toString() {
110.128 + if (bank == 128)
110.129 + return "Drumkit: " + name + " preset #" + preset;
110.130 + else
110.131 + return "Instrument: " + name + " bank #" + bank
110.132 + + " preset #" + preset;
110.133 + }
110.134 +
110.135 + public ModelPerformer[] getPerformers() {
110.136 + int performercount = 0;
110.137 + for (SF2InstrumentRegion presetzone : regions)
110.138 + performercount += presetzone.getLayer().getRegions().size();
110.139 + ModelPerformer[] performers = new ModelPerformer[performercount];
110.140 + int pi = 0;
110.141 +
110.142 + SF2GlobalRegion presetglobal = globalregion;
110.143 + for (SF2InstrumentRegion presetzone : regions) {
110.144 + Map<Integer, Short> pgenerators = new HashMap<Integer, Short>();
110.145 + pgenerators.putAll(presetzone.getGenerators());
110.146 + if (presetglobal != null)
110.147 + pgenerators.putAll(presetglobal.getGenerators());
110.148 +
110.149 + SF2Layer layer = presetzone.getLayer();
110.150 + SF2GlobalRegion layerglobal = layer.getGlobalRegion();
110.151 + for (SF2LayerRegion layerzone : layer.getRegions()) {
110.152 + ModelPerformer performer = new ModelPerformer();
110.153 + if (layerzone.getSample() != null)
110.154 + performer.setName(layerzone.getSample().getName());
110.155 + else
110.156 + performer.setName(layer.getName());
110.157 +
110.158 + performers[pi++] = performer;
110.159 +
110.160 + int keyfrom = 0;
110.161 + int keyto = 127;
110.162 + int velfrom = 0;
110.163 + int velto = 127;
110.164 +
110.165 + if (layerzone.contains(SF2Region.GENERATOR_EXCLUSIVECLASS)) {
110.166 + performer.setExclusiveClass(layerzone.getInteger(
110.167 + SF2Region.GENERATOR_EXCLUSIVECLASS));
110.168 + }
110.169 + if (layerzone.contains(SF2Region.GENERATOR_KEYRANGE)) {
110.170 + byte[] bytes = layerzone.getBytes(
110.171 + SF2Region.GENERATOR_KEYRANGE);
110.172 + if (bytes[0] >= 0)
110.173 + if (bytes[0] > keyfrom)
110.174 + keyfrom = bytes[0];
110.175 + if (bytes[1] >= 0)
110.176 + if (bytes[1] < keyto)
110.177 + keyto = bytes[1];
110.178 + }
110.179 + if (layerzone.contains(SF2Region.GENERATOR_VELRANGE)) {
110.180 + byte[] bytes = layerzone.getBytes(
110.181 + SF2Region.GENERATOR_VELRANGE);
110.182 + if (bytes[0] >= 0)
110.183 + if (bytes[0] > velfrom)
110.184 + velfrom = bytes[0];
110.185 + if (bytes[1] >= 0)
110.186 + if (bytes[1] < velto)
110.187 + velto = bytes[1];
110.188 + }
110.189 + if (presetzone.contains(SF2Region.GENERATOR_KEYRANGE)) {
110.190 + byte[] bytes = presetzone.getBytes(
110.191 + SF2Region.GENERATOR_KEYRANGE);
110.192 + if (bytes[0] > keyfrom)
110.193 + keyfrom = bytes[0];
110.194 + if (bytes[1] < keyto)
110.195 + keyto = bytes[1];
110.196 + }
110.197 + if (presetzone.contains(SF2Region.GENERATOR_VELRANGE)) {
110.198 + byte[] bytes = presetzone.getBytes(
110.199 + SF2Region.GENERATOR_VELRANGE);
110.200 + if (bytes[0] > velfrom)
110.201 + velfrom = bytes[0];
110.202 + if (bytes[1] < velto)
110.203 + velto = bytes[1];
110.204 + }
110.205 + performer.setKeyFrom(keyfrom);
110.206 + performer.setKeyTo(keyto);
110.207 + performer.setVelFrom(velfrom);
110.208 + performer.setVelTo(velto);
110.209 +
110.210 + int startAddrsOffset = layerzone.getShort(
110.211 + SF2Region.GENERATOR_STARTADDRSOFFSET);
110.212 + int endAddrsOffset = layerzone.getShort(
110.213 + SF2Region.GENERATOR_ENDADDRSOFFSET);
110.214 + int startloopAddrsOffset = layerzone.getShort(
110.215 + SF2Region.GENERATOR_STARTLOOPADDRSOFFSET);
110.216 + int endloopAddrsOffset = layerzone.getShort(
110.217 + SF2Region.GENERATOR_ENDLOOPADDRSOFFSET);
110.218 +
110.219 + startAddrsOffset += layerzone.getShort(
110.220 + SF2Region.GENERATOR_STARTADDRSCOARSEOFFSET) * 32768;
110.221 + endAddrsOffset += layerzone.getShort(
110.222 + SF2Region.GENERATOR_ENDADDRSCOARSEOFFSET) * 32768;
110.223 + startloopAddrsOffset += layerzone.getShort(
110.224 + SF2Region.GENERATOR_STARTLOOPADDRSCOARSEOFFSET) * 32768;
110.225 + endloopAddrsOffset += layerzone.getShort(
110.226 + SF2Region.GENERATOR_ENDLOOPADDRSCOARSEOFFSET) * 32768;
110.227 + startloopAddrsOffset -= startAddrsOffset;
110.228 + endloopAddrsOffset -= startAddrsOffset;
110.229 +
110.230 + SF2Sample sample = layerzone.getSample();
110.231 + int rootkey = sample.originalPitch;
110.232 + if (layerzone.getShort(SF2Region.GENERATOR_OVERRIDINGROOTKEY) != -1) {
110.233 + rootkey = layerzone.getShort(
110.234 + SF2Region.GENERATOR_OVERRIDINGROOTKEY);
110.235 + }
110.236 + float pitchcorrection = (-rootkey * 100) + sample.pitchCorrection;
110.237 + ModelByteBuffer buff = sample.getDataBuffer();
110.238 + ModelByteBuffer buff24 = sample.getData24Buffer();
110.239 +
110.240 + if (startAddrsOffset != 0 || endAddrsOffset != 0) {
110.241 + buff = buff.subbuffer(startAddrsOffset * 2,
110.242 + buff.capacity() + endAddrsOffset * 2);
110.243 + if (buff24 != null) {
110.244 + buff24 = buff24.subbuffer(startAddrsOffset,
110.245 + buff24.capacity() + endAddrsOffset);
110.246 + }
110.247 +
110.248 + /*
110.249 + if (startAddrsOffset < 0)
110.250 + startAddrsOffset = 0;
110.251 + if (endAddrsOffset > (buff.capacity()/2-startAddrsOffset))
110.252 + startAddrsOffset = (int)buff.capacity()/2-startAddrsOffset;
110.253 + byte[] data = buff.array();
110.254 + int off = (int)buff.arrayOffset() + startAddrsOffset*2;
110.255 + int len = (int)buff.capacity() + endAddrsOffset*2;
110.256 + if (off+len > data.length)
110.257 + len = data.length - off;
110.258 + buff = new ModelByteBuffer(data, off, len);
110.259 + if(buff24 != null) {
110.260 + data = buff.array();
110.261 + off = (int)buff.arrayOffset() + startAddrsOffset;
110.262 + len = (int)buff.capacity() + endAddrsOffset;
110.263 + buff24 = new ModelByteBuffer(data, off, len);
110.264 + }
110.265 + */
110.266 + }
110.267 +
110.268 + ModelByteBufferWavetable osc = new ModelByteBufferWavetable(
110.269 + buff, sample.getFormat(), pitchcorrection);
110.270 + if (buff24 != null)
110.271 + osc.set8BitExtensionBuffer(buff24);
110.272 +
110.273 + Map<Integer, Short> generators = new HashMap<Integer, Short>();
110.274 + if (layerglobal != null)
110.275 + generators.putAll(layerglobal.getGenerators());
110.276 + generators.putAll(layerzone.getGenerators());
110.277 + for (Map.Entry<Integer, Short> gen : pgenerators.entrySet()) {
110.278 + short val;
110.279 + if (!generators.containsKey(gen.getKey()))
110.280 + val = layerzone.getShort(gen.getKey());
110.281 + else
110.282 + val = generators.get(gen.getKey());
110.283 + val += gen.getValue();
110.284 + generators.put(gen.getKey(), val);
110.285 + }
110.286 +
110.287 + // SampleMode:
110.288 + // 0 indicates a sound reproduced with no loop
110.289 + // 1 indicates a sound which loops continuously
110.290 + // 2 is unused but should be interpreted as indicating no loop
110.291 + // 3 indicates a sound which loops for the duration of key
110.292 + // depression then proceeds to play the remainder of the sample.
110.293 + int sampleMode = getGeneratorValue(generators,
110.294 + SF2Region.GENERATOR_SAMPLEMODES);
110.295 + if ((sampleMode == 1) || (sampleMode == 3)) {
110.296 + if (sample.startLoop >= 0 && sample.endLoop > 0) {
110.297 + osc.setLoopStart((int)(sample.startLoop
110.298 + + startloopAddrsOffset));
110.299 + osc.setLoopLength((int)(sample.endLoop - sample.startLoop
110.300 + + endloopAddrsOffset - startloopAddrsOffset));
110.301 + if (sampleMode == 1)
110.302 + osc.setLoopType(ModelWavetable.LOOP_TYPE_FORWARD);
110.303 + if (sampleMode == 3)
110.304 + osc.setLoopType(ModelWavetable.LOOP_TYPE_RELEASE);
110.305 + }
110.306 + }
110.307 + performer.getOscillators().add(osc);
110.308 +
110.309 +
110.310 + short volDelay = getGeneratorValue(generators,
110.311 + SF2Region.GENERATOR_DELAYVOLENV);
110.312 + short volAttack = getGeneratorValue(generators,
110.313 + SF2Region.GENERATOR_ATTACKVOLENV);
110.314 + short volHold = getGeneratorValue(generators,
110.315 + SF2Region.GENERATOR_HOLDVOLENV);
110.316 + short volDecay = getGeneratorValue(generators,
110.317 + SF2Region.GENERATOR_DECAYVOLENV);
110.318 + short volSustain = getGeneratorValue(generators,
110.319 + SF2Region.GENERATOR_SUSTAINVOLENV);
110.320 + short volRelease = getGeneratorValue(generators,
110.321 + SF2Region.GENERATOR_RELEASEVOLENV);
110.322 +
110.323 + if (volHold != -12000) {
110.324 + short volKeyNumToHold = getGeneratorValue(generators,
110.325 + SF2Region.GENERATOR_KEYNUMTOVOLENVHOLD);
110.326 + volHold += 60 * volKeyNumToHold;
110.327 + float fvalue = -volKeyNumToHold * 128;
110.328 + ModelIdentifier src = ModelSource.SOURCE_NOTEON_KEYNUMBER;
110.329 + ModelIdentifier dest = ModelDestination.DESTINATION_EG1_HOLD;
110.330 + performer.getConnectionBlocks().add(
110.331 + new ModelConnectionBlock(new ModelSource(src), fvalue,
110.332 + new ModelDestination(dest)));
110.333 + }
110.334 + if (volDecay != -12000) {
110.335 + short volKeyNumToDecay = getGeneratorValue(generators,
110.336 + SF2Region.GENERATOR_KEYNUMTOVOLENVDECAY);
110.337 + volDecay += 60 * volKeyNumToDecay;
110.338 + float fvalue = -volKeyNumToDecay * 128;
110.339 + ModelIdentifier src = ModelSource.SOURCE_NOTEON_KEYNUMBER;
110.340 + ModelIdentifier dest = ModelDestination.DESTINATION_EG1_DECAY;
110.341 + performer.getConnectionBlocks().add(
110.342 + new ModelConnectionBlock(new ModelSource(src), fvalue,
110.343 + new ModelDestination(dest)));
110.344 + }
110.345 +
110.346 + addTimecentValue(performer,
110.347 + ModelDestination.DESTINATION_EG1_DELAY, volDelay);
110.348 + addTimecentValue(performer,
110.349 + ModelDestination.DESTINATION_EG1_ATTACK, volAttack);
110.350 + addTimecentValue(performer,
110.351 + ModelDestination.DESTINATION_EG1_HOLD, volHold);
110.352 + addTimecentValue(performer,
110.353 + ModelDestination.DESTINATION_EG1_DECAY, volDecay);
110.354 + //float fvolsustain = (960-volSustain)*(1000.0f/960.0f);
110.355 +
110.356 + volSustain = (short)(1000 - volSustain);
110.357 + if (volSustain < 0)
110.358 + volSustain = 0;
110.359 + if (volSustain > 1000)
110.360 + volSustain = 1000;
110.361 +
110.362 + addValue(performer,
110.363 + ModelDestination.DESTINATION_EG1_SUSTAIN, volSustain);
110.364 + addTimecentValue(performer,
110.365 + ModelDestination.DESTINATION_EG1_RELEASE, volRelease);
110.366 +
110.367 + if (getGeneratorValue(generators,
110.368 + SF2Region.GENERATOR_MODENVTOFILTERFC) != 0
110.369 + || getGeneratorValue(generators,
110.370 + SF2Region.GENERATOR_MODENVTOPITCH) != 0) {
110.371 + short modDelay = getGeneratorValue(generators,
110.372 + SF2Region.GENERATOR_DELAYMODENV);
110.373 + short modAttack = getGeneratorValue(generators,
110.374 + SF2Region.GENERATOR_ATTACKMODENV);
110.375 + short modHold = getGeneratorValue(generators,
110.376 + SF2Region.GENERATOR_HOLDMODENV);
110.377 + short modDecay = getGeneratorValue(generators,
110.378 + SF2Region.GENERATOR_DECAYMODENV);
110.379 + short modSustain = getGeneratorValue(generators,
110.380 + SF2Region.GENERATOR_SUSTAINMODENV);
110.381 + short modRelease = getGeneratorValue(generators,
110.382 + SF2Region.GENERATOR_RELEASEMODENV);
110.383 +
110.384 +
110.385 + if (modHold != -12000) {
110.386 + short modKeyNumToHold = getGeneratorValue(generators,
110.387 + SF2Region.GENERATOR_KEYNUMTOMODENVHOLD);
110.388 + modHold += 60 * modKeyNumToHold;
110.389 + float fvalue = -modKeyNumToHold * 128;
110.390 + ModelIdentifier src = ModelSource.SOURCE_NOTEON_KEYNUMBER;
110.391 + ModelIdentifier dest = ModelDestination.DESTINATION_EG2_HOLD;
110.392 + performer.getConnectionBlocks().add(
110.393 + new ModelConnectionBlock(new ModelSource(src),
110.394 + fvalue, new ModelDestination(dest)));
110.395 + }
110.396 + if (modDecay != -12000) {
110.397 + short modKeyNumToDecay = getGeneratorValue(generators,
110.398 + SF2Region.GENERATOR_KEYNUMTOMODENVDECAY);
110.399 + modDecay += 60 * modKeyNumToDecay;
110.400 + float fvalue = -modKeyNumToDecay * 128;
110.401 + ModelIdentifier src = ModelSource.SOURCE_NOTEON_KEYNUMBER;
110.402 + ModelIdentifier dest = ModelDestination.DESTINATION_EG2_DECAY;
110.403 + performer.getConnectionBlocks().add(
110.404 + new ModelConnectionBlock(new ModelSource(src),
110.405 + fvalue, new ModelDestination(dest)));
110.406 + }
110.407 +
110.408 + addTimecentValue(performer,
110.409 + ModelDestination.DESTINATION_EG2_DELAY, modDelay);
110.410 + addTimecentValue(performer,
110.411 + ModelDestination.DESTINATION_EG2_ATTACK, modAttack);
110.412 + addTimecentValue(performer,
110.413 + ModelDestination.DESTINATION_EG2_HOLD, modHold);
110.414 + addTimecentValue(performer,
110.415 + ModelDestination.DESTINATION_EG2_DECAY, modDecay);
110.416 + if (modSustain < 0)
110.417 + modSustain = 0;
110.418 + if (modSustain > 1000)
110.419 + modSustain = 1000;
110.420 + addValue(performer, ModelDestination.DESTINATION_EG2_SUSTAIN,
110.421 + 1000 - modSustain);
110.422 + addTimecentValue(performer,
110.423 + ModelDestination.DESTINATION_EG2_RELEASE, modRelease);
110.424 +
110.425 + if (getGeneratorValue(generators,
110.426 + SF2Region.GENERATOR_MODENVTOFILTERFC) != 0) {
110.427 + double fvalue = getGeneratorValue(generators,
110.428 + SF2Region.GENERATOR_MODENVTOFILTERFC);
110.429 + ModelIdentifier src = ModelSource.SOURCE_EG2;
110.430 + ModelIdentifier dest
110.431 + = ModelDestination.DESTINATION_FILTER_FREQ;
110.432 + performer.getConnectionBlocks().add(
110.433 + new ModelConnectionBlock(new ModelSource(src),
110.434 + fvalue, new ModelDestination(dest)));
110.435 + }
110.436 +
110.437 + if (getGeneratorValue(generators,
110.438 + SF2Region.GENERATOR_MODENVTOPITCH) != 0) {
110.439 + double fvalue = getGeneratorValue(generators,
110.440 + SF2Region.GENERATOR_MODENVTOPITCH);
110.441 + ModelIdentifier src = ModelSource.SOURCE_EG2;
110.442 + ModelIdentifier dest = ModelDestination.DESTINATION_PITCH;
110.443 + performer.getConnectionBlocks().add(
110.444 + new ModelConnectionBlock(new ModelSource(src),
110.445 + fvalue, new ModelDestination(dest)));
110.446 + }
110.447 +
110.448 + }
110.449 +
110.450 + if (getGeneratorValue(generators,
110.451 + SF2Region.GENERATOR_MODLFOTOFILTERFC) != 0
110.452 + || getGeneratorValue(generators,
110.453 + SF2Region.GENERATOR_MODLFOTOPITCH) != 0
110.454 + || getGeneratorValue(generators,
110.455 + SF2Region.GENERATOR_MODLFOTOVOLUME) != 0) {
110.456 + short lfo_freq = getGeneratorValue(generators,
110.457 + SF2Region.GENERATOR_FREQMODLFO);
110.458 + short lfo_delay = getGeneratorValue(generators,
110.459 + SF2Region.GENERATOR_DELAYMODLFO);
110.460 + addTimecentValue(performer,
110.461 + ModelDestination.DESTINATION_LFO1_DELAY, lfo_delay);
110.462 + addValue(performer,
110.463 + ModelDestination.DESTINATION_LFO1_FREQ, lfo_freq);
110.464 + }
110.465 +
110.466 + short vib_freq = getGeneratorValue(generators,
110.467 + SF2Region.GENERATOR_FREQVIBLFO);
110.468 + short vib_delay = getGeneratorValue(generators,
110.469 + SF2Region.GENERATOR_DELAYVIBLFO);
110.470 + addTimecentValue(performer,
110.471 + ModelDestination.DESTINATION_LFO2_DELAY, vib_delay);
110.472 + addValue(performer,
110.473 + ModelDestination.DESTINATION_LFO2_FREQ, vib_freq);
110.474 +
110.475 +
110.476 + if (getGeneratorValue(generators,
110.477 + SF2Region.GENERATOR_VIBLFOTOPITCH) != 0) {
110.478 + double fvalue = getGeneratorValue(generators,
110.479 + SF2Region.GENERATOR_VIBLFOTOPITCH);
110.480 + ModelIdentifier src = ModelSource.SOURCE_LFO2;
110.481 + ModelIdentifier dest = ModelDestination.DESTINATION_PITCH;
110.482 + performer.getConnectionBlocks().add(
110.483 + new ModelConnectionBlock(
110.484 + new ModelSource(src,
110.485 + ModelStandardTransform.DIRECTION_MIN2MAX,
110.486 + ModelStandardTransform.POLARITY_BIPOLAR),
110.487 + fvalue, new ModelDestination(dest)));
110.488 + }
110.489 +
110.490 + if (getGeneratorValue(generators,
110.491 + SF2Region.GENERATOR_MODLFOTOFILTERFC) != 0) {
110.492 + double fvalue = getGeneratorValue(generators,
110.493 + SF2Region.GENERATOR_MODLFOTOFILTERFC);
110.494 + ModelIdentifier src = ModelSource.SOURCE_LFO1;
110.495 + ModelIdentifier dest = ModelDestination.DESTINATION_FILTER_FREQ;
110.496 + performer.getConnectionBlocks().add(
110.497 + new ModelConnectionBlock(
110.498 + new ModelSource(src,
110.499 + ModelStandardTransform.DIRECTION_MIN2MAX,
110.500 + ModelStandardTransform.POLARITY_BIPOLAR),
110.501 + fvalue, new ModelDestination(dest)));
110.502 + }
110.503 +
110.504 + if (getGeneratorValue(generators,
110.505 + SF2Region.GENERATOR_MODLFOTOPITCH) != 0) {
110.506 + double fvalue = getGeneratorValue(generators,
110.507 + SF2Region.GENERATOR_MODLFOTOPITCH);
110.508 + ModelIdentifier src = ModelSource.SOURCE_LFO1;
110.509 + ModelIdentifier dest = ModelDestination.DESTINATION_PITCH;
110.510 + performer.getConnectionBlocks().add(
110.511 + new ModelConnectionBlock(
110.512 + new ModelSource(src,
110.513 + ModelStandardTransform.DIRECTION_MIN2MAX,
110.514 + ModelStandardTransform.POLARITY_BIPOLAR),
110.515 + fvalue, new ModelDestination(dest)));
110.516 + }
110.517 +
110.518 + if (getGeneratorValue(generators,
110.519 + SF2Region.GENERATOR_MODLFOTOVOLUME) != 0) {
110.520 + double fvalue = getGeneratorValue(generators,
110.521 + SF2Region.GENERATOR_MODLFOTOVOLUME);
110.522 + ModelIdentifier src = ModelSource.SOURCE_LFO1;
110.523 + ModelIdentifier dest = ModelDestination.DESTINATION_GAIN;
110.524 + performer.getConnectionBlocks().add(
110.525 + new ModelConnectionBlock(
110.526 + new ModelSource(src,
110.527 + ModelStandardTransform.DIRECTION_MIN2MAX,
110.528 + ModelStandardTransform.POLARITY_BIPOLAR),
110.529 + fvalue, new ModelDestination(dest)));
110.530 + }
110.531 +
110.532 + if (layerzone.getShort(SF2Region.GENERATOR_KEYNUM) != -1) {
110.533 + double val = layerzone.getShort(SF2Region.GENERATOR_KEYNUM)/128.0;
110.534 + addValue(performer, ModelDestination.DESTINATION_KEYNUMBER, val);
110.535 + }
110.536 +
110.537 + if (layerzone.getShort(SF2Region.GENERATOR_VELOCITY) != -1) {
110.538 + double val = layerzone.getShort(SF2Region.GENERATOR_VELOCITY)
110.539 + / 128.0;
110.540 + addValue(performer, ModelDestination.DESTINATION_VELOCITY, val);
110.541 + }
110.542 +
110.543 + if (getGeneratorValue(generators,
110.544 + SF2Region.GENERATOR_INITIALFILTERFC) < 13500) {
110.545 + short filter_freq = getGeneratorValue(generators,
110.546 + SF2Region.GENERATOR_INITIALFILTERFC);
110.547 + short filter_q = getGeneratorValue(generators,
110.548 + SF2Region.GENERATOR_INITIALFILTERQ);
110.549 + addValue(performer,
110.550 + ModelDestination.DESTINATION_FILTER_FREQ, filter_freq);
110.551 + addValue(performer,
110.552 + ModelDestination.DESTINATION_FILTER_Q, filter_q);
110.553 + }
110.554 +
110.555 + int tune = 100 * getGeneratorValue(generators,
110.556 + SF2Region.GENERATOR_COARSETUNE);
110.557 + tune += getGeneratorValue(generators,
110.558 + SF2Region.GENERATOR_FINETUNE);
110.559 + if (tune != 0) {
110.560 + addValue(performer,
110.561 + ModelDestination.DESTINATION_PITCH, (short) tune);
110.562 + }
110.563 + if (getGeneratorValue(generators, SF2Region.GENERATOR_PAN) != 0) {
110.564 + short val = getGeneratorValue(generators,
110.565 + SF2Region.GENERATOR_PAN);
110.566 + addValue(performer, ModelDestination.DESTINATION_PAN, val);
110.567 + }
110.568 + if (getGeneratorValue(generators, SF2Region.GENERATOR_INITIALATTENUATION) != 0) {
110.569 + short val = getGeneratorValue(generators,
110.570 + SF2Region.GENERATOR_INITIALATTENUATION);
110.571 + addValue(performer,
110.572 + ModelDestination.DESTINATION_GAIN, -0.376287f * val);
110.573 + }
110.574 + if (getGeneratorValue(generators,
110.575 + SF2Region.GENERATOR_CHORUSEFFECTSSEND) != 0) {
110.576 + short val = getGeneratorValue(generators,
110.577 + SF2Region.GENERATOR_CHORUSEFFECTSSEND);
110.578 + addValue(performer, ModelDestination.DESTINATION_CHORUS, val);
110.579 + }
110.580 + if (getGeneratorValue(generators,
110.581 + SF2Region.GENERATOR_REVERBEFFECTSSEND) != 0) {
110.582 + short val = getGeneratorValue(generators,
110.583 + SF2Region.GENERATOR_REVERBEFFECTSSEND);
110.584 + addValue(performer, ModelDestination.DESTINATION_REVERB, val);
110.585 + }
110.586 + if (getGeneratorValue(generators,
110.587 + SF2Region.GENERATOR_SCALETUNING) != 100) {
110.588 + short fvalue = getGeneratorValue(generators,
110.589 + SF2Region.GENERATOR_SCALETUNING);
110.590 + if (fvalue == 0) {
110.591 + ModelIdentifier dest = ModelDestination.DESTINATION_PITCH;
110.592 + performer.getConnectionBlocks().add(
110.593 + new ModelConnectionBlock(null, rootkey * 100,
110.594 + new ModelDestination(dest)));
110.595 + } else {
110.596 + ModelIdentifier dest = ModelDestination.DESTINATION_PITCH;
110.597 + performer.getConnectionBlocks().add(
110.598 + new ModelConnectionBlock(null, rootkey * (100 - fvalue),
110.599 + new ModelDestination(dest)));
110.600 + }
110.601 +
110.602 + ModelIdentifier src = ModelSource.SOURCE_NOTEON_KEYNUMBER;
110.603 + ModelIdentifier dest = ModelDestination.DESTINATION_PITCH;
110.604 + performer.getConnectionBlocks().add(
110.605 + new ModelConnectionBlock(new ModelSource(src),
110.606 + 128 * fvalue, new ModelDestination(dest)));
110.607 +
110.608 + }
110.609 +
110.610 + performer.getConnectionBlocks().add(
110.611 + new ModelConnectionBlock(
110.612 + new ModelSource(ModelSource.SOURCE_NOTEON_VELOCITY,
110.613 + new ModelTransform() {
110.614 + public double transform(double value) {
110.615 + if (value < 0.5)
110.616 + return 1 - value * 2;
110.617 + else
110.618 + return 0;
110.619 + }
110.620 + }),
110.621 + -2400,
110.622 + new ModelDestination(
110.623 + ModelDestination.DESTINATION_FILTER_FREQ)));
110.624 +
110.625 +
110.626 + performer.getConnectionBlocks().add(
110.627 + new ModelConnectionBlock(
110.628 + new ModelSource(ModelSource.SOURCE_LFO2,
110.629 + ModelStandardTransform.DIRECTION_MIN2MAX,
110.630 + ModelStandardTransform.POLARITY_BIPOLAR,
110.631 + ModelStandardTransform.TRANSFORM_LINEAR),
110.632 + new ModelSource(new ModelIdentifier("midi_cc", "1", 0),
110.633 + ModelStandardTransform.DIRECTION_MIN2MAX,
110.634 + ModelStandardTransform.POLARITY_UNIPOLAR,
110.635 + ModelStandardTransform.TRANSFORM_LINEAR),
110.636 + 50, new ModelDestination(
110.637 + ModelDestination.DESTINATION_PITCH)));
110.638 +
110.639 + if (layer.getGlobalRegion() != null) {
110.640 + for (SF2Modulator modulator
110.641 + : layer.getGlobalRegion().getModulators()) {
110.642 + convertModulator(performer, modulator);
110.643 + }
110.644 + }
110.645 + for (SF2Modulator modulator : layerzone.getModulators())
110.646 + convertModulator(performer, modulator);
110.647 +
110.648 + if (presetglobal != null) {
110.649 + for (SF2Modulator modulator : presetglobal.getModulators())
110.650 + convertModulator(performer, modulator);
110.651 + }
110.652 + for (SF2Modulator modulator : presetzone.getModulators())
110.653 + convertModulator(performer, modulator);
110.654 +
110.655 + }
110.656 + }
110.657 + return performers;
110.658 + }
110.659 +
110.660 + private void convertModulator(ModelPerformer performer,
110.661 + SF2Modulator modulator) {
110.662 + ModelSource src1 = convertSource(modulator.getSourceOperator());
110.663 + ModelSource src2 = convertSource(modulator.getAmountSourceOperator());
110.664 + if (src1 == null && modulator.getSourceOperator() != 0)
110.665 + return;
110.666 + if (src2 == null && modulator.getAmountSourceOperator() != 0)
110.667 + return;
110.668 + double amount = modulator.getAmount();
110.669 + double[] amountcorrection = new double[1];
110.670 + ModelSource[] extrasrc = new ModelSource[1];
110.671 + amountcorrection[0] = 1;
110.672 + ModelDestination dst = convertDestination(
110.673 + modulator.getDestinationOperator(), amountcorrection, extrasrc);
110.674 + amount *= amountcorrection[0];
110.675 + if (dst == null)
110.676 + return;
110.677 + if (modulator.getTransportOperator() == SF2Modulator.TRANSFORM_ABSOLUTE) {
110.678 + ((ModelStandardTransform)dst.getTransform()).setTransform(
110.679 + ModelStandardTransform.TRANSFORM_ABSOLUTE);
110.680 + }
110.681 + ModelConnectionBlock conn = new ModelConnectionBlock(src1, src2, amount, dst);
110.682 + if (extrasrc[0] != null)
110.683 + conn.addSource(extrasrc[0]);
110.684 + performer.getConnectionBlocks().add(conn);
110.685 +
110.686 + }
110.687 +
110.688 + private static ModelSource convertSource(int src) {
110.689 + if (src == 0)
110.690 + return null;
110.691 + ModelIdentifier id = null;
110.692 + int idsrc = src & 0x7F;
110.693 + if ((src & SF2Modulator.SOURCE_MIDI_CONTROL) != 0) {
110.694 + id = new ModelIdentifier("midi_cc", Integer.toString(idsrc));
110.695 + } else {
110.696 + if (idsrc == SF2Modulator.SOURCE_NOTE_ON_VELOCITY)
110.697 + id = ModelSource.SOURCE_NOTEON_VELOCITY;
110.698 + if (idsrc == SF2Modulator.SOURCE_NOTE_ON_KEYNUMBER)
110.699 + id = ModelSource.SOURCE_NOTEON_KEYNUMBER;
110.700 + if (idsrc == SF2Modulator.SOURCE_POLY_PRESSURE)
110.701 + id = ModelSource.SOURCE_MIDI_POLY_PRESSURE;
110.702 + if (idsrc == SF2Modulator.SOURCE_CHANNEL_PRESSURE)
110.703 + id = ModelSource.SOURCE_MIDI_CHANNEL_PRESSURE;
110.704 + if (idsrc == SF2Modulator.SOURCE_PITCH_WHEEL)
110.705 + id = ModelSource.SOURCE_MIDI_PITCH;
110.706 + if (idsrc == SF2Modulator.SOURCE_PITCH_SENSITIVITY)
110.707 + id = new ModelIdentifier("midi_rpn", "0");
110.708 + }
110.709 + if (id == null)
110.710 + return null;
110.711 +
110.712 + ModelSource msrc = new ModelSource(id);
110.713 + ModelStandardTransform transform
110.714 + = (ModelStandardTransform) msrc.getTransform();
110.715 +
110.716 + if ((SF2Modulator.SOURCE_DIRECTION_MAX_MIN & src) != 0)
110.717 + transform.setDirection(ModelStandardTransform.DIRECTION_MAX2MIN);
110.718 + else
110.719 + transform.setDirection(ModelStandardTransform.DIRECTION_MIN2MAX);
110.720 +
110.721 + if ((SF2Modulator.SOURCE_POLARITY_BIPOLAR & src) != 0)
110.722 + transform.setPolarity(ModelStandardTransform.POLARITY_BIPOLAR);
110.723 + else
110.724 + transform.setPolarity(ModelStandardTransform.POLARITY_UNIPOLAR);
110.725 +
110.726 + if ((SF2Modulator.SOURCE_TYPE_CONCAVE & src) != 0)
110.727 + transform.setTransform(ModelStandardTransform.TRANSFORM_CONCAVE);
110.728 + if ((SF2Modulator.SOURCE_TYPE_CONVEX & src) != 0)
110.729 + transform.setTransform(ModelStandardTransform.TRANSFORM_CONVEX);
110.730 + if ((SF2Modulator.SOURCE_TYPE_SWITCH & src) != 0)
110.731 + transform.setTransform(ModelStandardTransform.TRANSFORM_SWITCH);
110.732 +
110.733 + return msrc;
110.734 + }
110.735 +
110.736 + protected static ModelDestination convertDestination(int dst,
110.737 + double[] amountcorrection, ModelSource[] extrasrc) {
110.738 + ModelIdentifier id = null;
110.739 + switch (dst) {
110.740 + case SF2Region.GENERATOR_INITIALFILTERFC:
110.741 + id = ModelDestination.DESTINATION_FILTER_FREQ;
110.742 + break;
110.743 + case SF2Region.GENERATOR_INITIALFILTERQ:
110.744 + id = ModelDestination.DESTINATION_FILTER_Q;
110.745 + break;
110.746 + case SF2Region.GENERATOR_CHORUSEFFECTSSEND:
110.747 + id = ModelDestination.DESTINATION_CHORUS;
110.748 + break;
110.749 + case SF2Region.GENERATOR_REVERBEFFECTSSEND:
110.750 + id = ModelDestination.DESTINATION_REVERB;
110.751 + break;
110.752 + case SF2Region.GENERATOR_PAN:
110.753 + id = ModelDestination.DESTINATION_PAN;
110.754 + break;
110.755 + case SF2Region.GENERATOR_DELAYMODLFO:
110.756 + id = ModelDestination.DESTINATION_LFO1_DELAY;
110.757 + break;
110.758 + case SF2Region.GENERATOR_FREQMODLFO:
110.759 + id = ModelDestination.DESTINATION_LFO1_FREQ;
110.760 + break;
110.761 + case SF2Region.GENERATOR_DELAYVIBLFO:
110.762 + id = ModelDestination.DESTINATION_LFO2_DELAY;
110.763 + break;
110.764 + case SF2Region.GENERATOR_FREQVIBLFO:
110.765 + id = ModelDestination.DESTINATION_LFO2_FREQ;
110.766 + break;
110.767 +
110.768 + case SF2Region.GENERATOR_DELAYMODENV:
110.769 + id = ModelDestination.DESTINATION_EG2_DELAY;
110.770 + break;
110.771 + case SF2Region.GENERATOR_ATTACKMODENV:
110.772 + id = ModelDestination.DESTINATION_EG2_ATTACK;
110.773 + break;
110.774 + case SF2Region.GENERATOR_HOLDMODENV:
110.775 + id = ModelDestination.DESTINATION_EG2_HOLD;
110.776 + break;
110.777 + case SF2Region.GENERATOR_DECAYMODENV:
110.778 + id = ModelDestination.DESTINATION_EG2_DECAY;
110.779 + break;
110.780 + case SF2Region.GENERATOR_SUSTAINMODENV:
110.781 + id = ModelDestination.DESTINATION_EG2_SUSTAIN;
110.782 + amountcorrection[0] = -1;
110.783 + break;
110.784 + case SF2Region.GENERATOR_RELEASEMODENV:
110.785 + id = ModelDestination.DESTINATION_EG2_RELEASE;
110.786 + break;
110.787 + case SF2Region.GENERATOR_DELAYVOLENV:
110.788 + id = ModelDestination.DESTINATION_EG1_DELAY;
110.789 + break;
110.790 + case SF2Region.GENERATOR_ATTACKVOLENV:
110.791 + id = ModelDestination.DESTINATION_EG1_ATTACK;
110.792 + break;
110.793 + case SF2Region.GENERATOR_HOLDVOLENV:
110.794 + id = ModelDestination.DESTINATION_EG1_HOLD;
110.795 + break;
110.796 + case SF2Region.GENERATOR_DECAYVOLENV:
110.797 + id = ModelDestination.DESTINATION_EG1_DECAY;
110.798 + break;
110.799 + case SF2Region.GENERATOR_SUSTAINVOLENV:
110.800 + id = ModelDestination.DESTINATION_EG1_SUSTAIN;
110.801 + amountcorrection[0] = -1;
110.802 + break;
110.803 + case SF2Region.GENERATOR_RELEASEVOLENV:
110.804 + id = ModelDestination.DESTINATION_EG1_RELEASE;
110.805 + break;
110.806 + case SF2Region.GENERATOR_KEYNUM:
110.807 + id = ModelDestination.DESTINATION_KEYNUMBER;
110.808 + break;
110.809 + case SF2Region.GENERATOR_VELOCITY:
110.810 + id = ModelDestination.DESTINATION_VELOCITY;
110.811 + break;
110.812 +
110.813 + case SF2Region.GENERATOR_COARSETUNE:
110.814 + amountcorrection[0] = 100;
110.815 + id = ModelDestination.DESTINATION_PITCH;
110.816 + break;
110.817 +
110.818 + case SF2Region.GENERATOR_FINETUNE:
110.819 + id = ModelDestination.DESTINATION_PITCH;
110.820 + break;
110.821 +
110.822 + case SF2Region.GENERATOR_INITIALATTENUATION:
110.823 + id = ModelDestination.DESTINATION_GAIN;
110.824 + amountcorrection[0] = -0.376287f;
110.825 + break;
110.826 +
110.827 + case SF2Region.GENERATOR_VIBLFOTOPITCH:
110.828 + id = ModelDestination.DESTINATION_PITCH;
110.829 + extrasrc[0] = new ModelSource(
110.830 + ModelSource.SOURCE_LFO2,
110.831 + ModelStandardTransform.DIRECTION_MIN2MAX,
110.832 + ModelStandardTransform.POLARITY_BIPOLAR);
110.833 + break;
110.834 +
110.835 + case SF2Region.GENERATOR_MODLFOTOPITCH:
110.836 + id = ModelDestination.DESTINATION_PITCH;
110.837 + extrasrc[0] = new ModelSource(
110.838 + ModelSource.SOURCE_LFO1,
110.839 + ModelStandardTransform.DIRECTION_MIN2MAX,
110.840 + ModelStandardTransform.POLARITY_BIPOLAR);
110.841 + break;
110.842 +
110.843 + case SF2Region.GENERATOR_MODLFOTOFILTERFC:
110.844 + id = ModelDestination.DESTINATION_FILTER_FREQ;
110.845 + extrasrc[0] = new ModelSource(
110.846 + ModelSource.SOURCE_LFO1,
110.847 + ModelStandardTransform.DIRECTION_MIN2MAX,
110.848 + ModelStandardTransform.POLARITY_BIPOLAR);
110.849 + break;
110.850 +
110.851 + case SF2Region.GENERATOR_MODLFOTOVOLUME:
110.852 + id = ModelDestination.DESTINATION_GAIN;
110.853 + amountcorrection[0] = -0.376287f;
110.854 + extrasrc[0] = new ModelSource(
110.855 + ModelSource.SOURCE_LFO1,
110.856 + ModelStandardTransform.DIRECTION_MIN2MAX,
110.857 + ModelStandardTransform.POLARITY_BIPOLAR);
110.858 + break;
110.859 +
110.860 + case SF2Region.GENERATOR_MODENVTOPITCH:
110.861 + id = ModelDestination.DESTINATION_PITCH;
110.862 + extrasrc[0] = new ModelSource(
110.863 + ModelSource.SOURCE_EG2,
110.864 + ModelStandardTransform.DIRECTION_MIN2MAX,
110.865 + ModelStandardTransform.POLARITY_BIPOLAR);
110.866 + break;
110.867 +
110.868 + case SF2Region.GENERATOR_MODENVTOFILTERFC:
110.869 + id = ModelDestination.DESTINATION_FILTER_FREQ;
110.870 + extrasrc[0] = new ModelSource(
110.871 + ModelSource.SOURCE_EG2,
110.872 + ModelStandardTransform.DIRECTION_MIN2MAX,
110.873 + ModelStandardTransform.POLARITY_BIPOLAR);
110.874 + break;
110.875 +
110.876 + default:
110.877 + break;
110.878 + }
110.879 + if (id != null)
110.880 + return new ModelDestination(id);
110.881 + return null;
110.882 + }
110.883 +
110.884 + private void addTimecentValue(ModelPerformer performer,
110.885 + ModelIdentifier dest, short value) {
110.886 + double fvalue;
110.887 + if (value == -12000)
110.888 + fvalue = Double.NEGATIVE_INFINITY;
110.889 + else
110.890 + fvalue = value;
110.891 + performer.getConnectionBlocks().add(
110.892 + new ModelConnectionBlock(fvalue, new ModelDestination(dest)));
110.893 + }
110.894 +
110.895 + private void addValue(ModelPerformer performer,
110.896 + ModelIdentifier dest, short value) {
110.897 + double fvalue = value;
110.898 + performer.getConnectionBlocks().add(
110.899 + new ModelConnectionBlock(fvalue, new ModelDestination(dest)));
110.900 + }
110.901 +
110.902 + private void addValue(ModelPerformer performer,
110.903 + ModelIdentifier dest, double value) {
110.904 + double fvalue = value;
110.905 + performer.getConnectionBlocks().add(
110.906 + new ModelConnectionBlock(fvalue, new ModelDestination(dest)));
110.907 + }
110.908 +
110.909 + private short getGeneratorValue(Map<Integer, Short> generators, int gen) {
110.910 + if (generators.containsKey(gen))
110.911 + return generators.get(gen);
110.912 + return SF2Region.getDefaultValue(gen);
110.913 + }
110.914 +}
111.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
111.2 +++ b/src/share/classes/com/sun/media/sound/SF2InstrumentRegion.java Tue Feb 03 22:02:55 2009 -0800
111.3 @@ -0,0 +1,43 @@
111.4 +/*
111.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
111.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
111.7 + *
111.8 + * This code is free software; you can redistribute it and/or modify it
111.9 + * under the terms of the GNU General Public License version 2 only, as
111.10 + * published by the Free Software Foundation. Sun designates this
111.11 + * particular file as subject to the "Classpath" exception as provided
111.12 + * by Sun in the LICENSE file that accompanied this code.
111.13 + *
111.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
111.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
111.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
111.17 + * version 2 for more details (a copy is included in the LICENSE file that
111.18 + * accompanied this code).
111.19 + *
111.20 + * You should have received a copy of the GNU General Public License version
111.21 + * 2 along with this work; if not, write to the Free Software Foundation,
111.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
111.23 + *
111.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
111.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
111.26 + * have any questions.
111.27 + */
111.28 +package com.sun.media.sound;
111.29 +
111.30 +/**
111.31 + * Soundfont instrument region.
111.32 + *
111.33 + * @author Karl Helgason
111.34 + */
111.35 +public class SF2InstrumentRegion extends SF2Region {
111.36 +
111.37 + protected SF2Layer layer;
111.38 +
111.39 + public SF2Layer getLayer() {
111.40 + return layer;
111.41 + }
111.42 +
111.43 + public void setLayer(SF2Layer layer) {
111.44 + this.layer = layer;
111.45 + }
111.46 +}
112.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
112.2 +++ b/src/share/classes/com/sun/media/sound/SF2Layer.java Tue Feb 03 22:02:55 2009 -0800
112.3 @@ -0,0 +1,78 @@
112.4 +/*
112.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
112.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
112.7 + *
112.8 + * This code is free software; you can redistribute it and/or modify it
112.9 + * under the terms of the GNU General Public License version 2 only, as
112.10 + * published by the Free Software Foundation. Sun designates this
112.11 + * particular file as subject to the "Classpath" exception as provided
112.12 + * by Sun in the LICENSE file that accompanied this code.
112.13 + *
112.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
112.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
112.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
112.17 + * version 2 for more details (a copy is included in the LICENSE file that
112.18 + * accompanied this code).
112.19 + *
112.20 + * You should have received a copy of the GNU General Public License version
112.21 + * 2 along with this work; if not, write to the Free Software Foundation,
112.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
112.23 + *
112.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
112.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
112.26 + * have any questions.
112.27 + */
112.28 +package com.sun.media.sound;
112.29 +
112.30 +import java.util.ArrayList;
112.31 +import java.util.List;
112.32 +
112.33 +import javax.sound.midi.SoundbankResource;
112.34 +
112.35 +/**
112.36 + * Soundfont layer.
112.37 + *
112.38 + * @author Karl Helgason
112.39 + */
112.40 +public class SF2Layer extends SoundbankResource {
112.41 +
112.42 + protected String name = "";
112.43 + protected SF2GlobalRegion globalregion = null;
112.44 + protected List<SF2LayerRegion> regions = new ArrayList<SF2LayerRegion>();
112.45 +
112.46 + public SF2Layer(SF2Soundbank soundBank) {
112.47 + super(soundBank, null, null);
112.48 + }
112.49 +
112.50 + public SF2Layer() {
112.51 + super(null, null, null);
112.52 + }
112.53 +
112.54 + public Object getData() {
112.55 + return null;
112.56 + }
112.57 +
112.58 + public String getName() {
112.59 + return name;
112.60 + }
112.61 +
112.62 + public void setName(String name) {
112.63 + this.name = name;
112.64 + }
112.65 +
112.66 + public List<SF2LayerRegion> getRegions() {
112.67 + return regions;
112.68 + }
112.69 +
112.70 + public SF2GlobalRegion getGlobalRegion() {
112.71 + return globalregion;
112.72 + }
112.73 +
112.74 + public void setGlobalZone(SF2GlobalRegion zone) {
112.75 + globalregion = zone;
112.76 + }
112.77 +
112.78 + public String toString() {
112.79 + return "Layer: " + name;
112.80 + }
112.81 +}
113.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
113.2 +++ b/src/share/classes/com/sun/media/sound/SF2LayerRegion.java Tue Feb 03 22:02:55 2009 -0800
113.3 @@ -0,0 +1,43 @@
113.4 +/*
113.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
113.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
113.7 + *
113.8 + * This code is free software; you can redistribute it and/or modify it
113.9 + * under the terms of the GNU General Public License version 2 only, as
113.10 + * published by the Free Software Foundation. Sun designates this
113.11 + * particular file as subject to the "Classpath" exception as provided
113.12 + * by Sun in the LICENSE file that accompanied this code.
113.13 + *
113.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
113.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
113.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
113.17 + * version 2 for more details (a copy is included in the LICENSE file that
113.18 + * accompanied this code).
113.19 + *
113.20 + * You should have received a copy of the GNU General Public License version
113.21 + * 2 along with this work; if not, write to the Free Software Foundation,
113.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
113.23 + *
113.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
113.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
113.26 + * have any questions.
113.27 + */
113.28 +package com.sun.media.sound;
113.29 +
113.30 +/**
113.31 + * Soundfont layer region.
113.32 + *
113.33 + * @author Karl Helgason
113.34 + */
113.35 +public class SF2LayerRegion extends SF2Region {
113.36 +
113.37 + protected SF2Sample sample;
113.38 +
113.39 + public SF2Sample getSample() {
113.40 + return sample;
113.41 + }
113.42 +
113.43 + public void setSample(SF2Sample sample) {
113.44 + this.sample = sample;
113.45 + }
113.46 +}
114.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
114.2 +++ b/src/share/classes/com/sun/media/sound/SF2Modulator.java Tue Feb 03 22:02:55 2009 -0800
114.3 @@ -0,0 +1,97 @@
114.4 +/*
114.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
114.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
114.7 + *
114.8 + * This code is free software; you can redistribute it and/or modify it
114.9 + * under the terms of the GNU General Public License version 2 only, as
114.10 + * published by the Free Software Foundation. Sun designates this
114.11 + * particular file as subject to the "Classpath" exception as provided
114.12 + * by Sun in the LICENSE file that accompanied this code.
114.13 + *
114.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
114.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
114.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
114.17 + * version 2 for more details (a copy is included in the LICENSE file that
114.18 + * accompanied this code).
114.19 + *
114.20 + * You should have received a copy of the GNU General Public License version
114.21 + * 2 along with this work; if not, write to the Free Software Foundation,
114.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
114.23 + *
114.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
114.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
114.26 + * have any questions.
114.27 + */
114.28 +package com.sun.media.sound;
114.29 +
114.30 +/**
114.31 + * Soundfont modulator container.
114.32 + *
114.33 + * @author Karl Helgason
114.34 + */
114.35 +public class SF2Modulator {
114.36 +
114.37 + public final static int SOURCE_NONE = 0;
114.38 + public final static int SOURCE_NOTE_ON_VELOCITY = 2;
114.39 + public final static int SOURCE_NOTE_ON_KEYNUMBER = 3;
114.40 + public final static int SOURCE_POLY_PRESSURE = 10;
114.41 + public final static int SOURCE_CHANNEL_PRESSURE = 13;
114.42 + public final static int SOURCE_PITCH_WHEEL = 14;
114.43 + public final static int SOURCE_PITCH_SENSITIVITY = 16;
114.44 + public final static int SOURCE_MIDI_CONTROL = 128 * 1;
114.45 + public final static int SOURCE_DIRECTION_MIN_MAX = 256 * 0;
114.46 + public final static int SOURCE_DIRECTION_MAX_MIN = 256 * 1;
114.47 + public final static int SOURCE_POLARITY_UNIPOLAR = 512 * 0;
114.48 + public final static int SOURCE_POLARITY_BIPOLAR = 512 * 1;
114.49 + public final static int SOURCE_TYPE_LINEAR = 1024 * 0;
114.50 + public final static int SOURCE_TYPE_CONCAVE = 1024 * 1;
114.51 + public final static int SOURCE_TYPE_CONVEX = 1024 * 2;
114.52 + public final static int SOURCE_TYPE_SWITCH = 1024 * 3;
114.53 + public final static int TRANSFORM_LINEAR = 0;
114.54 + public final static int TRANSFORM_ABSOLUTE = 2;
114.55 + protected int sourceOperator;
114.56 + protected int destinationOperator;
114.57 + protected short amount;
114.58 + protected int amountSourceOperator;
114.59 + protected int transportOperator;
114.60 +
114.61 + public short getAmount() {
114.62 + return amount;
114.63 + }
114.64 +
114.65 + public void setAmount(short amount) {
114.66 + this.amount = amount;
114.67 + }
114.68 +
114.69 + public int getAmountSourceOperator() {
114.70 + return amountSourceOperator;
114.71 + }
114.72 +
114.73 + public void setAmountSourceOperator(int amountSourceOperator) {
114.74 + this.amountSourceOperator = amountSourceOperator;
114.75 + }
114.76 +
114.77 + public int getTransportOperator() {
114.78 + return transportOperator;
114.79 + }
114.80 +
114.81 + public void setTransportOperator(int transportOperator) {
114.82 + this.transportOperator = transportOperator;
114.83 + }
114.84 +
114.85 + public int getDestinationOperator() {
114.86 + return destinationOperator;
114.87 + }
114.88 +
114.89 + public void setDestinationOperator(int destinationOperator) {
114.90 + this.destinationOperator = destinationOperator;
114.91 + }
114.92 +
114.93 + public int getSourceOperator() {
114.94 + return sourceOperator;
114.95 + }
114.96 +
114.97 + public void setSourceOperator(int sourceOperator) {
114.98 + this.sourceOperator = sourceOperator;
114.99 + }
114.100 +}
115.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
115.2 +++ b/src/share/classes/com/sun/media/sound/SF2Region.java Tue Feb 03 22:02:55 2009 -0800
115.3 @@ -0,0 +1,167 @@
115.4 +/*
115.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
115.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
115.7 + *
115.8 + * This code is free software; you can redistribute it and/or modify it
115.9 + * under the terms of the GNU General Public License version 2 only, as
115.10 + * published by the Free Software Foundation. Sun designates this
115.11 + * particular file as subject to the "Classpath" exception as provided
115.12 + * by Sun in the LICENSE file that accompanied this code.
115.13 + *
115.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
115.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
115.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
115.17 + * version 2 for more details (a copy is included in the LICENSE file that
115.18 + * accompanied this code).
115.19 + *
115.20 + * You should have received a copy of the GNU General Public License version
115.21 + * 2 along with this work; if not, write to the Free Software Foundation,
115.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
115.23 + *
115.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
115.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
115.26 + * have any questions.
115.27 + */
115.28 +package com.sun.media.sound;
115.29 +
115.30 +import java.util.ArrayList;
115.31 +import java.util.HashMap;
115.32 +import java.util.List;
115.33 +import java.util.Map;
115.34 +
115.35 +/**
115.36 + * Soundfont general region.
115.37 + *
115.38 + * @author Karl Helgason
115.39 + */
115.40 +public class SF2Region {
115.41 +
115.42 + public final static int GENERATOR_STARTADDRSOFFSET = 0;
115.43 + public final static int GENERATOR_ENDADDRSOFFSET = 1;
115.44 + public final static int GENERATOR_STARTLOOPADDRSOFFSET = 2;
115.45 + public final static int GENERATOR_ENDLOOPADDRSOFFSET = 3;
115.46 + public final static int GENERATOR_STARTADDRSCOARSEOFFSET = 4;
115.47 + public final static int GENERATOR_MODLFOTOPITCH = 5;
115.48 + public final static int GENERATOR_VIBLFOTOPITCH = 6;
115.49 + public final static int GENERATOR_MODENVTOPITCH = 7;
115.50 + public final static int GENERATOR_INITIALFILTERFC = 8;
115.51 + public final static int GENERATOR_INITIALFILTERQ = 9;
115.52 + public final static int GENERATOR_MODLFOTOFILTERFC = 10;
115.53 + public final static int GENERATOR_MODENVTOFILTERFC = 11;
115.54 + public final static int GENERATOR_ENDADDRSCOARSEOFFSET = 12;
115.55 + public final static int GENERATOR_MODLFOTOVOLUME = 13;
115.56 + public final static int GENERATOR_UNUSED1 = 14;
115.57 + public final static int GENERATOR_CHORUSEFFECTSSEND = 15;
115.58 + public final static int GENERATOR_REVERBEFFECTSSEND = 16;
115.59 + public final static int GENERATOR_PAN = 17;
115.60 + public final static int GENERATOR_UNUSED2 = 18;
115.61 + public final static int GENERATOR_UNUSED3 = 19;
115.62 + public final static int GENERATOR_UNUSED4 = 20;
115.63 + public final static int GENERATOR_DELAYMODLFO = 21;
115.64 + public final static int GENERATOR_FREQMODLFO = 22;
115.65 + public final static int GENERATOR_DELAYVIBLFO = 23;
115.66 + public final static int GENERATOR_FREQVIBLFO = 24;
115.67 + public final static int GENERATOR_DELAYMODENV = 25;
115.68 + public final static int GENERATOR_ATTACKMODENV = 26;
115.69 + public final static int GENERATOR_HOLDMODENV = 27;
115.70 + public final static int GENERATOR_DECAYMODENV = 28;
115.71 + public final static int GENERATOR_SUSTAINMODENV = 29;
115.72 + public final static int GENERATOR_RELEASEMODENV = 30;
115.73 + public final static int GENERATOR_KEYNUMTOMODENVHOLD = 31;
115.74 + public final static int GENERATOR_KEYNUMTOMODENVDECAY = 32;
115.75 + public final static int GENERATOR_DELAYVOLENV = 33;
115.76 + public final static int GENERATOR_ATTACKVOLENV = 34;
115.77 + public final static int GENERATOR_HOLDVOLENV = 35;
115.78 + public final static int GENERATOR_DECAYVOLENV = 36;
115.79 + public final static int GENERATOR_SUSTAINVOLENV = 37;
115.80 + public final static int GENERATOR_RELEASEVOLENV = 38;
115.81 + public final static int GENERATOR_KEYNUMTOVOLENVHOLD = 39;
115.82 + public final static int GENERATOR_KEYNUMTOVOLENVDECAY = 40;
115.83 + public final static int GENERATOR_INSTRUMENT = 41;
115.84 + public final static int GENERATOR_RESERVED1 = 42;
115.85 + public final static int GENERATOR_KEYRANGE = 43;
115.86 + public final static int GENERATOR_VELRANGE = 44;
115.87 + public final static int GENERATOR_STARTLOOPADDRSCOARSEOFFSET = 45;
115.88 + public final static int GENERATOR_KEYNUM = 46;
115.89 + public final static int GENERATOR_VELOCITY = 47;
115.90 + public final static int GENERATOR_INITIALATTENUATION = 48;
115.91 + public final static int GENERATOR_RESERVED2 = 49;
115.92 + public final static int GENERATOR_ENDLOOPADDRSCOARSEOFFSET = 50;
115.93 + public final static int GENERATOR_COARSETUNE = 51;
115.94 + public final static int GENERATOR_FINETUNE = 52;
115.95 + public final static int GENERATOR_SAMPLEID = 53;
115.96 + public final static int GENERATOR_SAMPLEMODES = 54;
115.97 + public final static int GENERATOR_RESERVED3 = 55;
115.98 + public final static int GENERATOR_SCALETUNING = 56;
115.99 + public final static int GENERATOR_EXCLUSIVECLASS = 57;
115.100 + public final static int GENERATOR_OVERRIDINGROOTKEY = 58;
115.101 + public final static int GENERATOR_UNUSED5 = 59;
115.102 + public final static int GENERATOR_ENDOPR = 60;
115.103 + protected Map<Integer, Short> generators = new HashMap<Integer, Short>();
115.104 + protected List<SF2Modulator> modulators = new ArrayList<SF2Modulator>();
115.105 +
115.106 + public Map<Integer, Short> getGenerators() {
115.107 + return generators;
115.108 + }
115.109 +
115.110 + public boolean contains(int generator) {
115.111 + return generators.containsKey(generator);
115.112 + }
115.113 +
115.114 + static public short getDefaultValue(int generator) {
115.115 + if (generator == 8) return (short)13500;
115.116 + if (generator == 21) return (short)-12000;
115.117 + if (generator == 23) return (short)-12000;
115.118 + if (generator == 25) return (short)-12000;
115.119 + if (generator == 26) return (short)-12000;
115.120 + if (generator == 27) return (short)-12000;
115.121 + if (generator == 28) return (short)-12000;
115.122 + if (generator == 30) return (short)-12000;
115.123 + if (generator == 33) return (short)-12000;
115.124 + if (generator == 34) return (short)-12000;
115.125 + if (generator == 35) return (short)-12000;
115.126 + if (generator == 36) return (short)-12000;
115.127 + if (generator == 38) return (short)-12000;
115.128 + if (generator == 43) return (short)0x7F00;
115.129 + if (generator == 44) return (short)0x7F00;
115.130 + if (generator == 46) return (short)-1;
115.131 + if (generator == 47) return (short)-1;
115.132 + if (generator == 56) return (short)100;
115.133 + if (generator == 58) return (short)-1;
115.134 + return 0;
115.135 + }
115.136 +
115.137 + public short getShort(int generator) {
115.138 + if (!contains(generator))
115.139 + return getDefaultValue(generator);
115.140 + return generators.get(generator);
115.141 + }
115.142 +
115.143 + public void putShort(int generator, short value) {
115.144 + generators.put(generator, value);
115.145 + }
115.146 +
115.147 + public byte[] getBytes(int generator) {
115.148 + int val = getInteger(generator);
115.149 + byte[] bytes = new byte[2];
115.150 + bytes[0] = (byte) (0xFF & val);
115.151 + bytes[1] = (byte) ((0xFF00 & val) >> 8);
115.152 + return bytes;
115.153 + }
115.154 +
115.155 + public void putBytes(int generator, byte[] bytes) {
115.156 + generators.put(generator, (short) (bytes[0] + (bytes[1] << 8)));
115.157 + }
115.158 +
115.159 + public int getInteger(int generator) {
115.160 + return 0xFFFF & getShort(generator);
115.161 + }
115.162 +
115.163 + public void putInteger(int generator, int value) {
115.164 + generators.put(generator, (short) value);
115.165 + }
115.166 +
115.167 + public List<SF2Modulator> getModulators() {
115.168 + return modulators;
115.169 + }
115.170 +}
116.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
116.2 +++ b/src/share/classes/com/sun/media/sound/SF2Sample.java Tue Feb 03 22:02:55 2009 -0800
116.3 @@ -0,0 +1,216 @@
116.4 +/*
116.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
116.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
116.7 + *
116.8 + * This code is free software; you can redistribute it and/or modify it
116.9 + * under the terms of the GNU General Public License version 2 only, as
116.10 + * published by the Free Software Foundation. Sun designates this
116.11 + * particular file as subject to the "Classpath" exception as provided
116.12 + * by Sun in the LICENSE file that accompanied this code.
116.13 + *
116.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
116.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
116.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
116.17 + * version 2 for more details (a copy is included in the LICENSE file that
116.18 + * accompanied this code).
116.19 + *
116.20 + * You should have received a copy of the GNU General Public License version
116.21 + * 2 along with this work; if not, write to the Free Software Foundation,
116.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
116.23 + *
116.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
116.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
116.26 + * have any questions.
116.27 + */
116.28 +package com.sun.media.sound;
116.29 +
116.30 +import java.io.InputStream;
116.31 +
116.32 +import javax.sound.midi.Soundbank;
116.33 +import javax.sound.midi.SoundbankResource;
116.34 +import javax.sound.sampled.AudioFormat;
116.35 +import javax.sound.sampled.AudioInputStream;
116.36 +
116.37 +/**
116.38 + * Soundfont sample storage.
116.39 + *
116.40 + * @author Karl Helgason
116.41 + */
116.42 +public class SF2Sample extends SoundbankResource {
116.43 +
116.44 + protected String name = "";
116.45 + protected long startLoop = 0;
116.46 + protected long endLoop = 0;
116.47 + protected long sampleRate = 44100;
116.48 + protected int originalPitch = 60;
116.49 + protected byte pitchCorrection = 0;
116.50 + protected int sampleLink = 0;
116.51 + protected int sampleType = 0;
116.52 + protected ModelByteBuffer data;
116.53 + protected ModelByteBuffer data24;
116.54 +
116.55 + public SF2Sample(Soundbank soundBank) {
116.56 + super(soundBank, null, AudioInputStream.class);
116.57 + }
116.58 +
116.59 + public SF2Sample() {
116.60 + super(null, null, AudioInputStream.class);
116.61 + }
116.62 +
116.63 + public Object getData() {
116.64 +
116.65 + AudioFormat format = getFormat();
116.66 + /*
116.67 + if (sampleFile != null) {
116.68 + FileInputStream fis;
116.69 + try {
116.70 + fis = new FileInputStream(sampleFile);
116.71 + RIFFReader riff = new RIFFReader(fis);
116.72 + if (!riff.getFormat().equals("RIFF")) {
116.73 + throw new RIFFInvalidDataException(
116.74 + "Input stream is not a valid RIFF stream!");
116.75 + }
116.76 + if (!riff.getType().equals("sfbk")) {
116.77 + throw new RIFFInvalidDataException(
116.78 + "Input stream is not a valid SoundFont!");
116.79 + }
116.80 + while (riff.hasNextChunk()) {
116.81 + RIFFReader chunk = riff.nextChunk();
116.82 + if (chunk.getFormat().equals("LIST")) {
116.83 + if (chunk.getType().equals("sdta")) {
116.84 + while(chunk.hasNextChunk()) {
116.85 + RIFFReader chunkchunk = chunk.nextChunk();
116.86 + if(chunkchunk.getFormat().equals("smpl")) {
116.87 + chunkchunk.skip(sampleOffset);
116.88 + return new AudioInputStream(chunkchunk,
116.89 + format, sampleLen);
116.90 + }
116.91 + }
116.92 + }
116.93 + }
116.94 + }
116.95 + return null;
116.96 + } catch (Exception e) {
116.97 + return new Throwable(e.toString());
116.98 + }
116.99 + }
116.100 + */
116.101 + InputStream is = data.getInputStream();
116.102 + if (is == null)
116.103 + return null;
116.104 + return new AudioInputStream(is, format, data.capacity());
116.105 + }
116.106 +
116.107 + public ModelByteBuffer getDataBuffer() {
116.108 + return data;
116.109 + }
116.110 +
116.111 + public ModelByteBuffer getData24Buffer() {
116.112 + return data24;
116.113 + }
116.114 +
116.115 + public AudioFormat getFormat() {
116.116 + return new AudioFormat(sampleRate, 16, 1, true, false);
116.117 + }
116.118 +
116.119 + public void setData(ModelByteBuffer data) {
116.120 + this.data = data;
116.121 + }
116.122 +
116.123 + public void setData(byte[] data) {
116.124 + this.data = new ModelByteBuffer(data);
116.125 + }
116.126 +
116.127 + public void setData(byte[] data, int offset, int length) {
116.128 + this.data = new ModelByteBuffer(data, offset, length);
116.129 + }
116.130 +
116.131 + public void setData24(ModelByteBuffer data24) {
116.132 + this.data24 = data24;
116.133 + }
116.134 +
116.135 + public void setData24(byte[] data24) {
116.136 + this.data24 = new ModelByteBuffer(data24);
116.137 + }
116.138 +
116.139 + public void setData24(byte[] data24, int offset, int length) {
116.140 + this.data24 = new ModelByteBuffer(data24, offset, length);
116.141 + }
116.142 +
116.143 + /*
116.144 + public void setData(File file, int offset, int length) {
116.145 + this.data = null;
116.146 + this.sampleFile = file;
116.147 + this.sampleOffset = offset;
116.148 + this.sampleLen = length;
116.149 + }
116.150 + */
116.151 +
116.152 + public String getName() {
116.153 + return name;
116.154 + }
116.155 +
116.156 + public void setName(String name) {
116.157 + this.name = name;
116.158 + }
116.159 +
116.160 + public long getEndLoop() {
116.161 + return endLoop;
116.162 + }
116.163 +
116.164 + public void setEndLoop(long endLoop) {
116.165 + this.endLoop = endLoop;
116.166 + }
116.167 +
116.168 + public int getOriginalPitch() {
116.169 + return originalPitch;
116.170 + }
116.171 +
116.172 + public void setOriginalPitch(int originalPitch) {
116.173 + this.originalPitch = originalPitch;
116.174 + }
116.175 +
116.176 + public byte getPitchCorrection() {
116.177 + return pitchCorrection;
116.178 + }
116.179 +
116.180 + public void setPitchCorrection(byte pitchCorrection) {
116.181 + this.pitchCorrection = pitchCorrection;
116.182 + }
116.183 +
116.184 + public int getSampleLink() {
116.185 + return sampleLink;
116.186 + }
116.187 +
116.188 + public void setSampleLink(int sampleLink) {
116.189 + this.sampleLink = sampleLink;
116.190 + }
116.191 +
116.192 + public long getSampleRate() {
116.193 + return sampleRate;
116.194 + }
116.195 +
116.196 + public void setSampleRate(long sampleRate) {
116.197 + this.sampleRate = sampleRate;
116.198 + }
116.199 +
116.200 + public int getSampleType() {
116.201 + return sampleType;
116.202 + }
116.203 +
116.204 + public void setSampleType(int sampleType) {
116.205 + this.sampleType = sampleType;
116.206 + }
116.207 +
116.208 + public long getStartLoop() {
116.209 + return startLoop;
116.210 + }
116.211 +
116.212 + public void setStartLoop(long startLoop) {
116.213 + this.startLoop = startLoop;
116.214 + }
116.215 +
116.216 + public String toString() {
116.217 + return "Sample: " + name;
116.218 + }
116.219 +}
117.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
117.2 +++ b/src/share/classes/com/sun/media/sound/SF2Soundbank.java Tue Feb 03 22:02:55 2009 -0800
117.3 @@ -0,0 +1,973 @@
117.4 +/*
117.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
117.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
117.7 + *
117.8 + * This code is free software; you can redistribute it and/or modify it
117.9 + * under the terms of the GNU General Public License version 2 only, as
117.10 + * published by the Free Software Foundation. Sun designates this
117.11 + * particular file as subject to the "Classpath" exception as provided
117.12 + * by Sun in the LICENSE file that accompanied this code.
117.13 + *
117.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
117.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
117.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
117.17 + * version 2 for more details (a copy is included in the LICENSE file that
117.18 + * accompanied this code).
117.19 + *
117.20 + * You should have received a copy of the GNU General Public License version
117.21 + * 2 along with this work; if not, write to the Free Software Foundation,
117.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
117.23 + *
117.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
117.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
117.26 + * have any questions.
117.27 + */
117.28 +package com.sun.media.sound;
117.29 +
117.30 +import java.io.File;
117.31 +import java.io.FileInputStream;
117.32 +import java.io.IOException;
117.33 +import java.io.InputStream;
117.34 +import java.io.OutputStream;
117.35 +import java.net.URL;
117.36 +import java.util.ArrayList;
117.37 +import java.util.Arrays;
117.38 +import java.util.Iterator;
117.39 +import java.util.List;
117.40 +import java.util.Map;
117.41 +
117.42 +import javax.sound.midi.Instrument;
117.43 +import javax.sound.midi.Patch;
117.44 +import javax.sound.midi.Soundbank;
117.45 +import javax.sound.midi.SoundbankResource;
117.46 +
117.47 +/**
117.48 + * A SoundFont 2.04 soundbank reader.
117.49 + *
117.50 + * Based on SoundFont 2.04 specification from:
117.51 + * <p> http://developer.creative.com <br>
117.52 + * http://www.soundfont.com/ ;
117.53 + *
117.54 + * @author Karl Helgason
117.55 + */
117.56 +public class SF2Soundbank implements Soundbank {
117.57 +
117.58 + // version of the Sound Font RIFF file
117.59 + protected int major = 2;
117.60 + protected int minor = 1;
117.61 + // target Sound Engine
117.62 + protected String targetEngine = "EMU8000";
117.63 + // Sound Font Bank Name
117.64 + protected String name = "untitled";
117.65 + // Sound ROM Name
117.66 + protected String romName = null;
117.67 + // Sound ROM Version
117.68 + protected int romVersionMajor = -1;
117.69 + protected int romVersionMinor = -1;
117.70 + // Date of Creation of the Bank
117.71 + protected String creationDate = null;
117.72 + // Sound Designers and Engineers for the Bank
117.73 + protected String engineers = null;
117.74 + // Product for which the Bank was intended
117.75 + protected String product = null;
117.76 + // Copyright message
117.77 + protected String copyright = null;
117.78 + // Comments
117.79 + protected String comments = null;
117.80 + // The SoundFont tools used to create and alter the bank
117.81 + protected String tools = null;
117.82 + // The Sample Data loaded from the SoundFont
117.83 + private ModelByteBuffer sampleData = null;
117.84 + private ModelByteBuffer sampleData24 = null;
117.85 + private File sampleFile = null;
117.86 + private boolean largeFormat = false;
117.87 + private List<SF2Instrument> instruments = new ArrayList<SF2Instrument>();
117.88 + private List<SF2Layer> layers = new ArrayList<SF2Layer>();
117.89 + private List<SF2Sample> samples = new ArrayList<SF2Sample>();
117.90 +
117.91 + public SF2Soundbank() {
117.92 + }
117.93 +
117.94 + public SF2Soundbank(URL url) throws IOException {
117.95 +
117.96 + InputStream is = url.openStream();
117.97 + try {
117.98 + readSoundbank(is);
117.99 + } finally {
117.100 + is.close();
117.101 + }
117.102 + }
117.103 +
117.104 + public SF2Soundbank(File file) throws IOException {
117.105 + largeFormat = true;
117.106 + sampleFile = file;
117.107 + InputStream is = new FileInputStream(file);
117.108 + try {
117.109 + readSoundbank(is);
117.110 + } finally {
117.111 + is.close();
117.112 + }
117.113 + }
117.114 +
117.115 + public SF2Soundbank(InputStream inputstream) throws IOException {
117.116 + readSoundbank(inputstream);
117.117 + }
117.118 +
117.119 + private void readSoundbank(InputStream inputstream) throws IOException {
117.120 + RIFFReader riff = new RIFFReader(inputstream);
117.121 + if (!riff.getFormat().equals("RIFF")) {
117.122 + throw new RIFFInvalidFormatException(
117.123 + "Input stream is not a valid RIFF stream!");
117.124 + }
117.125 + if (!riff.getType().equals("sfbk")) {
117.126 + throw new RIFFInvalidFormatException(
117.127 + "Input stream is not a valid SoundFont!");
117.128 + }
117.129 + while (riff.hasNextChunk()) {
117.130 + RIFFReader chunk = riff.nextChunk();
117.131 + if (chunk.getFormat().equals("LIST")) {
117.132 + if (chunk.getType().equals("INFO"))
117.133 + readInfoChunk(chunk);
117.134 + if (chunk.getType().equals("sdta"))
117.135 + readSdtaChunk(chunk);
117.136 + if (chunk.getType().equals("pdta"))
117.137 + readPdtaChunk(chunk);
117.138 + }
117.139 + }
117.140 + }
117.141 +
117.142 + private void readInfoChunk(RIFFReader riff) throws IOException {
117.143 + while (riff.hasNextChunk()) {
117.144 + RIFFReader chunk = riff.nextChunk();
117.145 + String format = chunk.getFormat();
117.146 + if (format.equals("ifil")) {
117.147 + major = chunk.readUnsignedShort();
117.148 + minor = chunk.readUnsignedShort();
117.149 + } else if (format.equals("isng")) {
117.150 + this.targetEngine = chunk.readString(chunk.available());
117.151 + } else if (format.equals("INAM")) {
117.152 + this.name = chunk.readString(chunk.available());
117.153 + } else if (format.equals("irom")) {
117.154 + this.romName = chunk.readString(chunk.available());
117.155 + } else if (format.equals("iver")) {
117.156 + romVersionMajor = chunk.readUnsignedShort();
117.157 + romVersionMinor = chunk.readUnsignedShort();
117.158 + } else if (format.equals("ICRD")) {
117.159 + this.creationDate = chunk.readString(chunk.available());
117.160 + } else if (format.equals("IENG")) {
117.161 + this.engineers = chunk.readString(chunk.available());
117.162 + } else if (format.equals("IPRD")) {
117.163 + this.product = chunk.readString(chunk.available());
117.164 + } else if (format.equals("ICOP")) {
117.165 + this.copyright = chunk.readString(chunk.available());
117.166 + } else if (format.equals("ICMT")) {
117.167 + this.comments = chunk.readString(chunk.available());
117.168 + } else if (format.equals("ISFT")) {
117.169 + this.tools = chunk.readString(chunk.available());
117.170 + }
117.171 +
117.172 + }
117.173 + }
117.174 +
117.175 + private void readSdtaChunk(RIFFReader riff) throws IOException {
117.176 + while (riff.hasNextChunk()) {
117.177 + RIFFReader chunk = riff.nextChunk();
117.178 + if (chunk.getFormat().equals("smpl")) {
117.179 + if (!largeFormat) {
117.180 + byte[] sampleData = new byte[chunk.available()];
117.181 +
117.182 + int read = 0;
117.183 + int avail = chunk.available();
117.184 + while (read != avail) {
117.185 + if (avail - read > 65536) {
117.186 + chunk.readFully(sampleData, read, 65536);
117.187 + read += 65536;
117.188 + } else {
117.189 + chunk.readFully(sampleData, read, avail - read);
117.190 + read = avail;
117.191 + }
117.192 +
117.193 + }
117.194 + this.sampleData = new ModelByteBuffer(sampleData);
117.195 + //chunk.read(sampleData);
117.196 + } else {
117.197 + this.sampleData = new ModelByteBuffer(sampleFile,
117.198 + chunk.getFilePointer(), chunk.available());
117.199 + }
117.200 + }
117.201 + if (chunk.getFormat().equals("sm24")) {
117.202 + if (!largeFormat) {
117.203 + byte[] sampleData24 = new byte[chunk.available()];
117.204 + //chunk.read(sampleData24);
117.205 +
117.206 + int read = 0;
117.207 + int avail = chunk.available();
117.208 + while (read != avail) {
117.209 + if (avail - read > 65536) {
117.210 + chunk.readFully(sampleData24, read, 65536);
117.211 + read += 65536;
117.212 + } else {
117.213 + chunk.readFully(sampleData24, read, avail - read);
117.214 + read = avail;
117.215 + }
117.216 +
117.217 + }
117.218 + this.sampleData24 = new ModelByteBuffer(sampleData24);
117.219 + } else {
117.220 + this.sampleData24 = new ModelByteBuffer(sampleFile,
117.221 + chunk.getFilePointer(), chunk.available());
117.222 + }
117.223 +
117.224 + }
117.225 + }
117.226 + }
117.227 +
117.228 + private void readPdtaChunk(RIFFReader riff) throws IOException {
117.229 +
117.230 + List<SF2Instrument> presets = new ArrayList<SF2Instrument>();
117.231 + List<Integer> presets_bagNdx = new ArrayList<Integer>();
117.232 + List<SF2InstrumentRegion> presets_splits_gen
117.233 + = new ArrayList<SF2InstrumentRegion>();
117.234 + List<SF2InstrumentRegion> presets_splits_mod
117.235 + = new ArrayList<SF2InstrumentRegion>();
117.236 +
117.237 + List<SF2Layer> instruments = new ArrayList<SF2Layer>();
117.238 + List<Integer> instruments_bagNdx = new ArrayList<Integer>();
117.239 + List<SF2LayerRegion> instruments_splits_gen
117.240 + = new ArrayList<SF2LayerRegion>();
117.241 + List<SF2LayerRegion> instruments_splits_mod
117.242 + = new ArrayList<SF2LayerRegion>();
117.243 +
117.244 + while (riff.hasNextChunk()) {
117.245 + RIFFReader chunk = riff.nextChunk();
117.246 + String format = chunk.getFormat();
117.247 + if (format.equals("phdr")) {
117.248 + // Preset Header / Instrument
117.249 + if (chunk.available() % 38 != 0)
117.250 + throw new RIFFInvalidDataException();
117.251 + int count = chunk.available() / 38;
117.252 + for (int i = 0; i < count; i++) {
117.253 + SF2Instrument preset = new SF2Instrument(this);
117.254 + preset.name = chunk.readString(20);
117.255 + preset.preset = chunk.readUnsignedShort();
117.256 + preset.bank = chunk.readUnsignedShort();
117.257 + presets_bagNdx.add(chunk.readUnsignedShort());
117.258 + preset.library = chunk.readUnsignedInt();
117.259 + preset.genre = chunk.readUnsignedInt();
117.260 + preset.morphology = chunk.readUnsignedInt();
117.261 + presets.add(preset);
117.262 + if (i != count - 1)
117.263 + this.instruments.add(preset);
117.264 + }
117.265 + } else if (format.equals("pbag")) {
117.266 + // Preset Zones / Instruments splits
117.267 + if (chunk.available() % 4 != 0)
117.268 + throw new RIFFInvalidDataException();
117.269 + int count = chunk.available() / 4;
117.270 +
117.271 + // Skip first record
117.272 + {
117.273 + int gencount = chunk.readUnsignedShort();
117.274 + int modcount = chunk.readUnsignedShort();
117.275 + while (presets_splits_gen.size() < gencount)
117.276 + presets_splits_gen.add(null);
117.277 + while (presets_splits_mod.size() < modcount)
117.278 + presets_splits_mod.add(null);
117.279 + count--;
117.280 + }
117.281 +
117.282 + int offset = presets_bagNdx.get(0);
117.283 + // Offset should be 0 (but just case)
117.284 + for (int i = 0; i < offset; i++) {
117.285 + if (count == 0)
117.286 + throw new RIFFInvalidDataException();
117.287 + int gencount = chunk.readUnsignedShort();
117.288 + int modcount = chunk.readUnsignedShort();
117.289 + while (presets_splits_gen.size() < gencount)
117.290 + presets_splits_gen.add(null);
117.291 + while (presets_splits_mod.size() < modcount)
117.292 + presets_splits_mod.add(null);
117.293 + count--;
117.294 + }
117.295 +
117.296 + for (int i = 0; i < presets_bagNdx.size() - 1; i++) {
117.297 + int zone_count = presets_bagNdx.get(i + 1)
117.298 + - presets_bagNdx.get(i);
117.299 + SF2Instrument preset = presets.get(i);
117.300 + for (int ii = 0; ii < zone_count; ii++) {
117.301 + if (count == 0)
117.302 + throw new RIFFInvalidDataException();
117.303 + int gencount = chunk.readUnsignedShort();
117.304 + int modcount = chunk.readUnsignedShort();
117.305 + SF2InstrumentRegion split = new SF2InstrumentRegion();
117.306 + preset.regions.add(split);
117.307 + while (presets_splits_gen.size() < gencount)
117.308 + presets_splits_gen.add(split);
117.309 + while (presets_splits_mod.size() < modcount)
117.310 + presets_splits_mod.add(split);
117.311 + count--;
117.312 + }
117.313 + }
117.314 + } else if (format.equals("pmod")) {
117.315 + // Preset Modulators / Split Modulators
117.316 + for (int i = 0; i < presets_splits_mod.size(); i++) {
117.317 + SF2Modulator modulator = new SF2Modulator();
117.318 + modulator.sourceOperator = chunk.readUnsignedShort();
117.319 + modulator.destinationOperator = chunk.readUnsignedShort();
117.320 + modulator.amount = chunk.readShort();
117.321 + modulator.amountSourceOperator = chunk.readUnsignedShort();
117.322 + modulator.transportOperator = chunk.readUnsignedShort();
117.323 + SF2InstrumentRegion split = presets_splits_mod.get(i);
117.324 + if (split != null)
117.325 + split.modulators.add(modulator);
117.326 + }
117.327 + } else if (format.equals("pgen")) {
117.328 + // Preset Generators / Split Generators
117.329 + for (int i = 0; i < presets_splits_gen.size(); i++) {
117.330 + int operator = chunk.readUnsignedShort();
117.331 + short amount = chunk.readShort();
117.332 + SF2InstrumentRegion split = presets_splits_gen.get(i);
117.333 + if (split != null)
117.334 + split.generators.put(operator, amount);
117.335 + }
117.336 + } else if (format.equals("inst")) {
117.337 + // Instrument Header / Layers
117.338 + if (chunk.available() % 22 != 0)
117.339 + throw new RIFFInvalidDataException();
117.340 + int count = chunk.available() / 22;
117.341 + for (int i = 0; i < count; i++) {
117.342 + SF2Layer layer = new SF2Layer(this);
117.343 + layer.name = chunk.readString(20);
117.344 + instruments_bagNdx.add(chunk.readUnsignedShort());
117.345 + instruments.add(layer);
117.346 + if (i != count - 1)
117.347 + this.layers.add(layer);
117.348 + }
117.349 + } else if (format.equals("ibag")) {
117.350 + // Instrument Zones / Layer splits
117.351 + if (chunk.available() % 4 != 0)
117.352 + throw new RIFFInvalidDataException();
117.353 + int count = chunk.available() / 4;
117.354 +
117.355 + // Skip first record
117.356 + {
117.357 + int gencount = chunk.readUnsignedShort();
117.358 + int modcount = chunk.readUnsignedShort();
117.359 + while (instruments_splits_gen.size() < gencount)
117.360 + instruments_splits_gen.add(null);
117.361 + while (instruments_splits_mod.size() < modcount)
117.362 + instruments_splits_mod.add(null);
117.363 + count--;
117.364 + }
117.365 +
117.366 + int offset = instruments_bagNdx.get(0);
117.367 + // Offset should be 0 (but just case)
117.368 + for (int i = 0; i < offset; i++) {
117.369 + if (count == 0)
117.370 + throw new RIFFInvalidDataException();
117.371 + int gencount = chunk.readUnsignedShort();
117.372 + int modcount = chunk.readUnsignedShort();
117.373 + while (instruments_splits_gen.size() < gencount)
117.374 + instruments_splits_gen.add(null);
117.375 + while (instruments_splits_mod.size() < modcount)
117.376 + instruments_splits_mod.add(null);
117.377 + count--;
117.378 + }
117.379 +
117.380 + for (int i = 0; i < instruments_bagNdx.size() - 1; i++) {
117.381 + int zone_count = instruments_bagNdx.get(i + 1) - instruments_bagNdx.get(i);
117.382 + SF2Layer layer = layers.get(i);
117.383 + for (int ii = 0; ii < zone_count; ii++) {
117.384 + if (count == 0)
117.385 + throw new RIFFInvalidDataException();
117.386 + int gencount = chunk.readUnsignedShort();
117.387 + int modcount = chunk.readUnsignedShort();
117.388 + SF2LayerRegion split = new SF2LayerRegion();
117.389 + layer.regions.add(split);
117.390 + while (instruments_splits_gen.size() < gencount)
117.391 + instruments_splits_gen.add(split);
117.392 + while (instruments_splits_mod.size() < modcount)
117.393 + instruments_splits_mod.add(split);
117.394 + count--;
117.395 + }
117.396 + }
117.397 +
117.398 + } else if (format.equals("imod")) {
117.399 + // Instrument Modulators / Split Modulators
117.400 + for (int i = 0; i < instruments_splits_mod.size(); i++) {
117.401 + SF2Modulator modulator = new SF2Modulator();
117.402 + modulator.sourceOperator = chunk.readUnsignedShort();
117.403 + modulator.destinationOperator = chunk.readUnsignedShort();
117.404 + modulator.amount = chunk.readShort();
117.405 + modulator.amountSourceOperator = chunk.readUnsignedShort();
117.406 + modulator.transportOperator = chunk.readUnsignedShort();
117.407 + SF2LayerRegion split = instruments_splits_gen.get(i);
117.408 + if (split != null)
117.409 + split.modulators.add(modulator);
117.410 + }
117.411 + } else if (format.equals("igen")) {
117.412 + // Instrument Generators / Split Generators
117.413 + for (int i = 0; i < instruments_splits_gen.size(); i++) {
117.414 + int operator = chunk.readUnsignedShort();
117.415 + short amount = chunk.readShort();
117.416 + SF2LayerRegion split = instruments_splits_gen.get(i);
117.417 + if (split != null)
117.418 + split.generators.put(operator, amount);
117.419 + }
117.420 + } else if (format.equals("shdr")) {
117.421 + // Sample Headers
117.422 + if (chunk.available() % 46 != 0)
117.423 + throw new RIFFInvalidDataException();
117.424 + int count = chunk.available() / 46;
117.425 + for (int i = 0; i < count; i++) {
117.426 + SF2Sample sample = new SF2Sample(this);
117.427 + sample.name = chunk.readString(20);
117.428 + long start = chunk.readUnsignedInt();
117.429 + long end = chunk.readUnsignedInt();
117.430 + sample.data = sampleData.subbuffer(start * 2, end * 2, true);
117.431 + if (sampleData24 != null)
117.432 + sample.data24 = sampleData24.subbuffer(start, end, true);
117.433 + /*
117.434 + sample.data = new ModelByteBuffer(sampleData, (int)(start*2),
117.435 + (int)((end - start)*2));
117.436 + if (sampleData24 != null)
117.437 + sample.data24 = new ModelByteBuffer(sampleData24,
117.438 + (int)start, (int)(end - start));
117.439 + */
117.440 + sample.startLoop = chunk.readUnsignedInt() - start;
117.441 + sample.endLoop = chunk.readUnsignedInt() - start;
117.442 + if (sample.startLoop < 0)
117.443 + sample.startLoop = -1;
117.444 + if (sample.endLoop < 0)
117.445 + sample.endLoop = -1;
117.446 + sample.sampleRate = chunk.readUnsignedInt();
117.447 + sample.originalPitch = chunk.readUnsignedByte();
117.448 + sample.pitchCorrection = chunk.readByte();
117.449 + sample.sampleLink = chunk.readUnsignedShort();
117.450 + sample.sampleType = chunk.readUnsignedShort();
117.451 + if (i != count - 1)
117.452 + this.samples.add(sample);
117.453 + }
117.454 + }
117.455 + }
117.456 +
117.457 + Iterator<SF2Layer> liter = this.layers.iterator();
117.458 + while (liter.hasNext()) {
117.459 + SF2Layer layer = liter.next();
117.460 + Iterator<SF2LayerRegion> siter = layer.regions.iterator();
117.461 + SF2Region globalsplit = null;
117.462 + while (siter.hasNext()) {
117.463 + SF2LayerRegion split = siter.next();
117.464 + if (split.generators.get(SF2LayerRegion.GENERATOR_SAMPLEID) != null) {
117.465 + int sampleid = split.generators.get(
117.466 + SF2LayerRegion.GENERATOR_SAMPLEID);
117.467 + split.generators.remove(SF2LayerRegion.GENERATOR_SAMPLEID);
117.468 + split.sample = samples.get(sampleid);
117.469 + } else {
117.470 + globalsplit = split;
117.471 + }
117.472 + }
117.473 + if (globalsplit != null) {
117.474 + layer.getRegions().remove(globalsplit);
117.475 + SF2GlobalRegion gsplit = new SF2GlobalRegion();
117.476 + gsplit.generators = globalsplit.generators;
117.477 + gsplit.modulators = globalsplit.modulators;
117.478 + layer.setGlobalZone(gsplit);
117.479 + }
117.480 + }
117.481 +
117.482 +
117.483 + Iterator<SF2Instrument> iiter = this.instruments.iterator();
117.484 + while (iiter.hasNext()) {
117.485 + SF2Instrument instrument = iiter.next();
117.486 + Iterator<SF2InstrumentRegion> siter = instrument.regions.iterator();
117.487 + SF2Region globalsplit = null;
117.488 + while (siter.hasNext()) {
117.489 + SF2InstrumentRegion split = siter.next();
117.490 + if (split.generators.get(SF2LayerRegion.GENERATOR_INSTRUMENT) != null) {
117.491 + int instrumentid = split.generators.get(
117.492 + SF2InstrumentRegion.GENERATOR_INSTRUMENT);
117.493 + split.generators.remove(SF2LayerRegion.GENERATOR_INSTRUMENT);
117.494 + split.layer = layers.get(instrumentid);
117.495 + } else {
117.496 + globalsplit = split;
117.497 + }
117.498 + }
117.499 +
117.500 + if (globalsplit != null) {
117.501 + instrument.getRegions().remove(globalsplit);
117.502 + SF2GlobalRegion gsplit = new SF2GlobalRegion();
117.503 + gsplit.generators = globalsplit.generators;
117.504 + gsplit.modulators = globalsplit.modulators;
117.505 + instrument.setGlobalZone(gsplit);
117.506 + }
117.507 + }
117.508 +
117.509 + }
117.510 +
117.511 + public void save(String name) throws IOException {
117.512 + writeSoundbank(new RIFFWriter(name, "sfbk"));
117.513 + }
117.514 +
117.515 + public void save(File file) throws IOException {
117.516 + writeSoundbank(new RIFFWriter(file, "sfbk"));
117.517 + }
117.518 +
117.519 + public void save(OutputStream out) throws IOException {
117.520 + writeSoundbank(new RIFFWriter(out, "sfbk"));
117.521 + }
117.522 +
117.523 + private void writeSoundbank(RIFFWriter writer) throws IOException {
117.524 + writeInfo(writer.writeList("INFO"));
117.525 + writeSdtaChunk(writer.writeList("sdta"));
117.526 + writePdtaChunk(writer.writeList("pdta"));
117.527 + writer.close();
117.528 + }
117.529 +
117.530 + private void writeInfoStringChunk(RIFFWriter writer, String name,
117.531 + String value) throws IOException {
117.532 + if (value == null)
117.533 + return;
117.534 + RIFFWriter chunk = writer.writeChunk(name);
117.535 + chunk.writeString(value);
117.536 + int len = value.getBytes("ascii").length;
117.537 + chunk.write(0);
117.538 + len++;
117.539 + if (len % 2 != 0)
117.540 + chunk.write(0);
117.541 + }
117.542 +
117.543 + private void writeInfo(RIFFWriter writer) throws IOException {
117.544 + if (this.targetEngine == null)
117.545 + this.targetEngine = "EMU8000";
117.546 + if (this.name == null)
117.547 + this.name = "";
117.548 +
117.549 + RIFFWriter ifil_chunk = writer.writeChunk("ifil");
117.550 + ifil_chunk.writeUnsignedShort(this.major);
117.551 + ifil_chunk.writeUnsignedShort(this.minor);
117.552 + writeInfoStringChunk(writer, "isng", this.targetEngine);
117.553 + writeInfoStringChunk(writer, "INAM", this.name);
117.554 + writeInfoStringChunk(writer, "irom", this.romName);
117.555 + if (romVersionMajor != -1) {
117.556 + RIFFWriter iver_chunk = writer.writeChunk("iver");
117.557 + iver_chunk.writeUnsignedShort(this.romVersionMajor);
117.558 + iver_chunk.writeUnsignedShort(this.romVersionMinor);
117.559 + }
117.560 + writeInfoStringChunk(writer, "ICRD", this.creationDate);
117.561 + writeInfoStringChunk(writer, "IENG", this.engineers);
117.562 + writeInfoStringChunk(writer, "IPRD", this.product);
117.563 + writeInfoStringChunk(writer, "ICOP", this.copyright);
117.564 + writeInfoStringChunk(writer, "ICMT", this.comments);
117.565 + writeInfoStringChunk(writer, "ISFT", this.tools);
117.566 +
117.567 + writer.close();
117.568 + }
117.569 +
117.570 + private void writeSdtaChunk(RIFFWriter writer) throws IOException {
117.571 +
117.572 + byte[] pad = new byte[32];
117.573 +
117.574 + RIFFWriter smpl_chunk = writer.writeChunk("smpl");
117.575 + for (SF2Sample sample : samples) {
117.576 + ModelByteBuffer data = sample.getDataBuffer();
117.577 + data.writeTo(smpl_chunk);
117.578 + /*
117.579 + smpl_chunk.write(data.array(),
117.580 + data.arrayOffset(),
117.581 + data.capacity());
117.582 + */
117.583 + smpl_chunk.write(pad);
117.584 + smpl_chunk.write(pad);
117.585 + }
117.586 + if (major < 2)
117.587 + return;
117.588 + if (major == 2 && minor < 4)
117.589 + return;
117.590 +
117.591 +
117.592 + for (SF2Sample sample : samples) {
117.593 + ModelByteBuffer data24 = sample.getData24Buffer();
117.594 + if (data24 == null)
117.595 + return;
117.596 + }
117.597 +
117.598 + RIFFWriter sm24_chunk = writer.writeChunk("sm24");
117.599 + for (SF2Sample sample : samples) {
117.600 + ModelByteBuffer data = sample.getData24Buffer();
117.601 + data.writeTo(sm24_chunk);
117.602 + /*
117.603 + sm24_chunk.write(data.array(),
117.604 + data.arrayOffset(),
117.605 + data.capacity());*/
117.606 + smpl_chunk.write(pad);
117.607 + }
117.608 + }
117.609 +
117.610 + private void writeModulators(RIFFWriter writer, List<SF2Modulator> modulators)
117.611 + throws IOException {
117.612 + for (SF2Modulator modulator : modulators) {
117.613 + writer.writeUnsignedShort(modulator.sourceOperator);
117.614 + writer.writeUnsignedShort(modulator.destinationOperator);
117.615 + writer.writeShort(modulator.amount);
117.616 + writer.writeUnsignedShort(modulator.amountSourceOperator);
117.617 + writer.writeUnsignedShort(modulator.transportOperator);
117.618 + }
117.619 + }
117.620 +
117.621 + private void writeGenerators(RIFFWriter writer, Map<Integer, Short> generators)
117.622 + throws IOException {
117.623 + Short keyrange = (Short) generators.get(SF2Region.GENERATOR_KEYRANGE);
117.624 + Short velrange = (Short) generators.get(SF2Region.GENERATOR_VELRANGE);
117.625 + if (keyrange != null) {
117.626 + writer.writeUnsignedShort(SF2Region.GENERATOR_KEYRANGE);
117.627 + writer.writeShort(keyrange);
117.628 + }
117.629 + if (velrange != null) {
117.630 + writer.writeUnsignedShort(SF2Region.GENERATOR_VELRANGE);
117.631 + writer.writeShort(velrange);
117.632 + }
117.633 + for (Map.Entry<Integer, Short> generator : generators.entrySet()) {
117.634 + if (generator.getKey() == SF2Region.GENERATOR_KEYRANGE)
117.635 + continue;
117.636 + if (generator.getKey() == SF2Region.GENERATOR_VELRANGE)
117.637 + continue;
117.638 + writer.writeUnsignedShort(generator.getKey());
117.639 + writer.writeShort(generator.getValue());
117.640 + }
117.641 + }
117.642 +
117.643 + private void writePdtaChunk(RIFFWriter writer) throws IOException {
117.644 +
117.645 + RIFFWriter phdr_chunk = writer.writeChunk("phdr");
117.646 + int phdr_zone_count = 0;
117.647 + for (SF2Instrument preset : this.instruments) {
117.648 + phdr_chunk.writeString(preset.name, 20);
117.649 + phdr_chunk.writeUnsignedShort(preset.preset);
117.650 + phdr_chunk.writeUnsignedShort(preset.bank);
117.651 + phdr_chunk.writeUnsignedShort(phdr_zone_count);
117.652 + if (preset.getGlobalRegion() != null)
117.653 + phdr_zone_count += 1;
117.654 + phdr_zone_count += preset.getRegions().size();
117.655 + phdr_chunk.writeUnsignedInt(preset.library);
117.656 + phdr_chunk.writeUnsignedInt(preset.genre);
117.657 + phdr_chunk.writeUnsignedInt(preset.morphology);
117.658 + }
117.659 + phdr_chunk.writeString("EOP", 20);
117.660 + phdr_chunk.writeUnsignedShort(0);
117.661 + phdr_chunk.writeUnsignedShort(0);
117.662 + phdr_chunk.writeUnsignedShort(phdr_zone_count);
117.663 + phdr_chunk.writeUnsignedInt(0);
117.664 + phdr_chunk.writeUnsignedInt(0);
117.665 + phdr_chunk.writeUnsignedInt(0);
117.666 +
117.667 +
117.668 + RIFFWriter pbag_chunk = writer.writeChunk("pbag");
117.669 + int pbag_gencount = 0;
117.670 + int pbag_modcount = 0;
117.671 + for (SF2Instrument preset : this.instruments) {
117.672 + if (preset.getGlobalRegion() != null) {
117.673 + pbag_chunk.writeUnsignedShort(pbag_gencount);
117.674 + pbag_chunk.writeUnsignedShort(pbag_modcount);
117.675 + pbag_gencount += preset.getGlobalRegion().getGenerators().size();
117.676 + pbag_modcount += preset.getGlobalRegion().getModulators().size();
117.677 + }
117.678 + for (SF2InstrumentRegion region : preset.getRegions()) {
117.679 + pbag_chunk.writeUnsignedShort(pbag_gencount);
117.680 + pbag_chunk.writeUnsignedShort(pbag_modcount);
117.681 + if (layers.indexOf(region.layer) != -1) {
117.682 + // One generator is used to reference to instrument record
117.683 + pbag_gencount += 1;
117.684 + }
117.685 + pbag_gencount += region.getGenerators().size();
117.686 + pbag_modcount += region.getModulators().size();
117.687 +
117.688 + }
117.689 + }
117.690 + pbag_chunk.writeUnsignedShort(pbag_gencount);
117.691 + pbag_chunk.writeUnsignedShort(pbag_modcount);
117.692 +
117.693 + RIFFWriter pmod_chunk = writer.writeChunk("pmod");
117.694 + for (SF2Instrument preset : this.instruments) {
117.695 + if (preset.getGlobalRegion() != null) {
117.696 + writeModulators(pmod_chunk,
117.697 + preset.getGlobalRegion().getModulators());
117.698 + }
117.699 + for (SF2InstrumentRegion region : preset.getRegions())
117.700 + writeModulators(pmod_chunk, region.getModulators());
117.701 + }
117.702 + pmod_chunk.write(new byte[10]);
117.703 +
117.704 + RIFFWriter pgen_chunk = writer.writeChunk("pgen");
117.705 + for (SF2Instrument preset : this.instruments) {
117.706 + if (preset.getGlobalRegion() != null) {
117.707 + writeGenerators(pgen_chunk,
117.708 + preset.getGlobalRegion().getGenerators());
117.709 + }
117.710 + for (SF2InstrumentRegion region : preset.getRegions()) {
117.711 + writeGenerators(pgen_chunk, region.getGenerators());
117.712 + int ix = (int) layers.indexOf(region.layer);
117.713 + if (ix != -1) {
117.714 + pgen_chunk.writeUnsignedShort(SF2Region.GENERATOR_INSTRUMENT);
117.715 + pgen_chunk.writeShort((short) ix);
117.716 + }
117.717 + }
117.718 + }
117.719 + pgen_chunk.write(new byte[4]);
117.720 +
117.721 + RIFFWriter inst_chunk = writer.writeChunk("inst");
117.722 + int inst_zone_count = 0;
117.723 + for (SF2Layer instrument : this.layers) {
117.724 + inst_chunk.writeString(instrument.name, 20);
117.725 + inst_chunk.writeUnsignedShort(inst_zone_count);
117.726 + if (instrument.getGlobalRegion() != null)
117.727 + inst_zone_count += 1;
117.728 + inst_zone_count += instrument.getRegions().size();
117.729 + }
117.730 + inst_chunk.writeString("EOI", 20);
117.731 + inst_chunk.writeUnsignedShort(inst_zone_count);
117.732 +
117.733 +
117.734 + RIFFWriter ibag_chunk = writer.writeChunk("ibag");
117.735 + int ibag_gencount = 0;
117.736 + int ibag_modcount = 0;
117.737 + for (SF2Layer instrument : this.layers) {
117.738 + if (instrument.getGlobalRegion() != null) {
117.739 + ibag_chunk.writeUnsignedShort(ibag_gencount);
117.740 + ibag_chunk.writeUnsignedShort(ibag_modcount);
117.741 + ibag_gencount
117.742 + += instrument.getGlobalRegion().getGenerators().size();
117.743 + ibag_modcount
117.744 + += instrument.getGlobalRegion().getModulators().size();
117.745 + }
117.746 + for (SF2LayerRegion region : instrument.getRegions()) {
117.747 + ibag_chunk.writeUnsignedShort(ibag_gencount);
117.748 + ibag_chunk.writeUnsignedShort(ibag_modcount);
117.749 + if (samples.indexOf(region.sample) != -1) {
117.750 + // One generator is used to reference to instrument record
117.751 + ibag_gencount += 1;
117.752 + }
117.753 + ibag_gencount += region.getGenerators().size();
117.754 + ibag_modcount += region.getModulators().size();
117.755 +
117.756 + }
117.757 + }
117.758 + ibag_chunk.writeUnsignedShort(ibag_gencount);
117.759 + ibag_chunk.writeUnsignedShort(ibag_modcount);
117.760 +
117.761 +
117.762 + RIFFWriter imod_chunk = writer.writeChunk("imod");
117.763 + for (SF2Layer instrument : this.layers) {
117.764 + if (instrument.getGlobalRegion() != null) {
117.765 + writeModulators(imod_chunk,
117.766 + instrument.getGlobalRegion().getModulators());
117.767 + }
117.768 + for (SF2LayerRegion region : instrument.getRegions())
117.769 + writeModulators(imod_chunk, region.getModulators());
117.770 + }
117.771 + imod_chunk.write(new byte[10]);
117.772 +
117.773 + RIFFWriter igen_chunk = writer.writeChunk("igen");
117.774 + for (SF2Layer instrument : this.layers) {
117.775 + if (instrument.getGlobalRegion() != null) {
117.776 + writeGenerators(igen_chunk,
117.777 + instrument.getGlobalRegion().getGenerators());
117.778 + }
117.779 + for (SF2LayerRegion region : instrument.getRegions()) {
117.780 + writeGenerators(igen_chunk, region.getGenerators());
117.781 + int ix = samples.indexOf(region.sample);
117.782 + if (ix != -1) {
117.783 + igen_chunk.writeUnsignedShort(SF2Region.GENERATOR_SAMPLEID);
117.784 + igen_chunk.writeShort((short) ix);
117.785 + }
117.786 + }
117.787 + }
117.788 + igen_chunk.write(new byte[4]);
117.789 +
117.790 +
117.791 + RIFFWriter shdr_chunk = writer.writeChunk("shdr");
117.792 + long sample_pos = 0;
117.793 + for (SF2Sample sample : samples) {
117.794 + shdr_chunk.writeString(sample.name, 20);
117.795 + long start = sample_pos;
117.796 + sample_pos += sample.data.capacity() / 2;
117.797 + long end = sample_pos;
117.798 + long startLoop = sample.startLoop + start;
117.799 + long endLoop = sample.endLoop + start;
117.800 + if (startLoop < start)
117.801 + startLoop = start;
117.802 + if (endLoop > end)
117.803 + endLoop = end;
117.804 + shdr_chunk.writeUnsignedInt(start);
117.805 + shdr_chunk.writeUnsignedInt(end);
117.806 + shdr_chunk.writeUnsignedInt(startLoop);
117.807 + shdr_chunk.writeUnsignedInt(endLoop);
117.808 + shdr_chunk.writeUnsignedInt(sample.sampleRate);
117.809 + shdr_chunk.writeUnsignedByte(sample.originalPitch);
117.810 + shdr_chunk.writeByte(sample.pitchCorrection);
117.811 + shdr_chunk.writeUnsignedShort(sample.sampleLink);
117.812 + shdr_chunk.writeUnsignedShort(sample.sampleType);
117.813 + sample_pos += 32;
117.814 + }
117.815 + shdr_chunk.writeString("EOS", 20);
117.816 + shdr_chunk.write(new byte[26]);
117.817 +
117.818 + }
117.819 +
117.820 + public String getName() {
117.821 + return name;
117.822 + }
117.823 +
117.824 + public String getVersion() {
117.825 + return major + "." + minor;
117.826 + }
117.827 +
117.828 + public String getVendor() {
117.829 + return engineers;
117.830 + }
117.831 +
117.832 + public String getDescription() {
117.833 + return comments;
117.834 + }
117.835 +
117.836 + public void setName(String s) {
117.837 + name = s;
117.838 + }
117.839 +
117.840 + public void setVendor(String s) {
117.841 + engineers = s;
117.842 + }
117.843 +
117.844 + public void setDescription(String s) {
117.845 + comments = s;
117.846 + }
117.847 +
117.848 + public SoundbankResource[] getResources() {
117.849 + SoundbankResource[] resources
117.850 + = new SoundbankResource[layers.size() + samples.size()];
117.851 + int j = 0;
117.852 + for (int i = 0; i < layers.size(); i++)
117.853 + resources[j++] = layers.get(i);
117.854 + for (int i = 0; i < samples.size(); i++)
117.855 + resources[j++] = samples.get(i);
117.856 + return resources;
117.857 + }
117.858 +
117.859 + public SF2Instrument[] getInstruments() {
117.860 + SF2Instrument[] inslist_array
117.861 + = instruments.toArray(new SF2Instrument[instruments.size()]);
117.862 + Arrays.sort(inslist_array, new ModelInstrumentComparator());
117.863 + return inslist_array;
117.864 + }
117.865 +
117.866 + public SF2Layer[] getLayers() {
117.867 + return layers.toArray(new SF2Layer[layers.size()]);
117.868 + }
117.869 +
117.870 + public SF2Sample[] getSamples() {
117.871 + return samples.toArray(new SF2Sample[samples.size()]);
117.872 + }
117.873 +
117.874 + public Instrument getInstrument(Patch patch) {
117.875 + int program = patch.getProgram();
117.876 + int bank = patch.getBank();
117.877 + boolean percussion = false;
117.878 + if (patch instanceof ModelPatch)
117.879 + percussion = ((ModelPatch)patch).isPercussion();
117.880 + for (Instrument instrument : instruments) {
117.881 + Patch patch2 = instrument.getPatch();
117.882 + int program2 = patch2.getProgram();
117.883 + int bank2 = patch2.getBank();
117.884 + if (program == program2 && bank == bank2) {
117.885 + boolean percussion2 = false;
117.886 + if (patch2 instanceof ModelPatch)
117.887 + percussion2 = ((ModelPatch) patch2).isPercussion();
117.888 + if (percussion == percussion2)
117.889 + return instrument;
117.890 + }
117.891 + }
117.892 + return null;
117.893 + }
117.894 +
117.895 + public String getCreationDate() {
117.896 + return creationDate;
117.897 + }
117.898 +
117.899 + public void setCreationDate(String creationDate) {
117.900 + this.creationDate = creationDate;
117.901 + }
117.902 +
117.903 + public String getProduct() {
117.904 + return product;
117.905 + }
117.906 +
117.907 + public void setProduct(String product) {
117.908 + this.product = product;
117.909 + }
117.910 +
117.911 + public String getRomName() {
117.912 + return romName;
117.913 + }
117.914 +
117.915 + public void setRomName(String romName) {
117.916 + this.romName = romName;
117.917 + }
117.918 +
117.919 + public int getRomVersionMajor() {
117.920 + return romVersionMajor;
117.921 + }
117.922 +
117.923 + public void setRomVersionMajor(int romVersionMajor) {
117.924 + this.romVersionMajor = romVersionMajor;
117.925 + }
117.926 +
117.927 + public int getRomVersionMinor() {
117.928 + return romVersionMinor;
117.929 + }
117.930 +
117.931 + public void setRomVersionMinor(int romVersionMinor) {
117.932 + this.romVersionMinor = romVersionMinor;
117.933 + }
117.934 +
117.935 + public String getTargetEngine() {
117.936 + return targetEngine;
117.937 + }
117.938 +
117.939 + public void setTargetEngine(String targetEngine) {
117.940 + this.targetEngine = targetEngine;
117.941 + }
117.942 +
117.943 + public String getTools() {
117.944 + return tools;
117.945 + }
117.946 +
117.947 + public void setTools(String tools) {
117.948 + this.tools = tools;
117.949 + }
117.950 +
117.951 + public void addResource(SoundbankResource resource) {
117.952 + if (resource instanceof SF2Instrument)
117.953 + instruments.add((SF2Instrument)resource);
117.954 + if (resource instanceof SF2Layer)
117.955 + layers.add((SF2Layer)resource);
117.956 + if (resource instanceof SF2Sample)
117.957 + samples.add((SF2Sample)resource);
117.958 + }
117.959 +
117.960 + public void removeResource(SoundbankResource resource) {
117.961 + if (resource instanceof SF2Instrument)
117.962 + instruments.remove((SF2Instrument)resource);
117.963 + if (resource instanceof SF2Layer)
117.964 + layers.remove((SF2Layer)resource);
117.965 + if (resource instanceof SF2Sample)
117.966 + samples.remove((SF2Sample)resource);
117.967 + }
117.968 +
117.969 + public void addInstrument(SF2Instrument resource) {
117.970 + instruments.add(resource);
117.971 + }
117.972 +
117.973 + public void removeInstrument(SF2Instrument resource) {
117.974 + instruments.remove(resource);
117.975 + }
117.976 +}
118.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
118.2 +++ b/src/share/classes/com/sun/media/sound/SF2SoundbankReader.java Tue Feb 03 22:02:55 2009 -0800
118.3 @@ -0,0 +1,73 @@
118.4 +/*
118.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
118.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
118.7 + *
118.8 + * This code is free software; you can redistribute it and/or modify it
118.9 + * under the terms of the GNU General Public License version 2 only, as
118.10 + * published by the Free Software Foundation. Sun designates this
118.11 + * particular file as subject to the "Classpath" exception as provided
118.12 + * by Sun in the LICENSE file that accompanied this code.
118.13 + *
118.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
118.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
118.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
118.17 + * version 2 for more details (a copy is included in the LICENSE file that
118.18 + * accompanied this code).
118.19 + *
118.20 + * You should have received a copy of the GNU General Public License version
118.21 + * 2 along with this work; if not, write to the Free Software Foundation,
118.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
118.23 + *
118.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
118.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
118.26 + * have any questions.
118.27 + */
118.28 +package com.sun.media.sound;
118.29 +
118.30 +import java.io.File;
118.31 +import java.io.IOException;
118.32 +import java.io.InputStream;
118.33 +import java.net.URL;
118.34 +import javax.sound.midi.InvalidMidiDataException;
118.35 +import javax.sound.midi.Soundbank;
118.36 +import javax.sound.midi.spi.SoundbankReader;
118.37 +
118.38 +/**
118.39 + * This class is used to connect the SF2SoundBank class
118.40 + * to the SoundbankReader SPI interface.
118.41 + *
118.42 + * @author Karl Helgason
118.43 + */
118.44 +public class SF2SoundbankReader extends SoundbankReader {
118.45 +
118.46 + public Soundbank getSoundbank(URL url)
118.47 + throws InvalidMidiDataException, IOException {
118.48 + try {
118.49 + return new SF2Soundbank(url);
118.50 + } catch (RIFFInvalidFormatException e) {
118.51 + return null;
118.52 + } catch(IOException ioe) {
118.53 + return null;
118.54 + }
118.55 + }
118.56 +
118.57 + public Soundbank getSoundbank(InputStream stream)
118.58 + throws InvalidMidiDataException, IOException {
118.59 + try {
118.60 + stream.mark(512);
118.61 + return new SF2Soundbank(stream);
118.62 + } catch (RIFFInvalidFormatException e) {
118.63 + stream.reset();
118.64 + return null;
118.65 + }
118.66 + }
118.67 +
118.68 + public Soundbank getSoundbank(File file)
118.69 + throws InvalidMidiDataException, IOException {
118.70 + try {
118.71 + return new SF2Soundbank(file);
118.72 + } catch (RIFFInvalidFormatException e) {
118.73 + return null;
118.74 + }
118.75 + }
118.76 +}
119.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
119.2 +++ b/src/share/classes/com/sun/media/sound/SimpleInstrument.java Tue Feb 03 22:02:55 2009 -0800
119.3 @@ -0,0 +1,196 @@
119.4 +/*
119.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
119.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
119.7 + *
119.8 + * This code is free software; you can redistribute it and/or modify it
119.9 + * under the terms of the GNU General Public License version 2 only, as
119.10 + * published by the Free Software Foundation. Sun designates this
119.11 + * particular file as subject to the "Classpath" exception as provided
119.12 + * by Sun in the LICENSE file that accompanied this code.
119.13 + *
119.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
119.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
119.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
119.17 + * version 2 for more details (a copy is included in the LICENSE file that
119.18 + * accompanied this code).
119.19 + *
119.20 + * You should have received a copy of the GNU General Public License version
119.21 + * 2 along with this work; if not, write to the Free Software Foundation,
119.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
119.23 + *
119.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
119.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
119.26 + * have any questions.
119.27 + */
119.28 +package com.sun.media.sound;
119.29 +
119.30 +import java.util.ArrayList;
119.31 +import java.util.List;
119.32 +import javax.sound.midi.Patch;
119.33 +
119.34 +/**
119.35 + * A simple instrument that is made of other ModelInstrument, ModelPerformer
119.36 + * objects.
119.37 + *
119.38 + * @author Karl Helgason
119.39 + */
119.40 +public class SimpleInstrument extends ModelInstrument {
119.41 +
119.42 + private static class SimpleInstrumentPart {
119.43 + ModelPerformer[] performers;
119.44 + int keyFrom;
119.45 + int keyTo;
119.46 + int velFrom;
119.47 + int velTo;
119.48 + int exclusiveClass;
119.49 + }
119.50 + protected int preset = 0;
119.51 + protected int bank = 0;
119.52 + protected boolean percussion = false;
119.53 + protected String name = "";
119.54 + protected List<SimpleInstrumentPart> parts
119.55 + = new ArrayList<SimpleInstrumentPart>();
119.56 +
119.57 + public SimpleInstrument() {
119.58 + super(null, null, null, null);
119.59 + }
119.60 +
119.61 + public void clear() {
119.62 + parts.clear();
119.63 + }
119.64 +
119.65 + public void add(ModelPerformer[] performers, int keyFrom, int keyTo,
119.66 + int velFrom, int velTo, int exclusiveClass) {
119.67 + SimpleInstrumentPart part = new SimpleInstrumentPart();
119.68 + part.performers = performers;
119.69 + part.keyFrom = keyFrom;
119.70 + part.keyTo = keyTo;
119.71 + part.velFrom = velFrom;
119.72 + part.velTo = velTo;
119.73 + part.exclusiveClass = exclusiveClass;
119.74 + parts.add(part);
119.75 + }
119.76 +
119.77 + public void add(ModelPerformer[] performers, int keyFrom, int keyTo,
119.78 + int velFrom, int velTo) {
119.79 + add(performers, keyFrom, keyTo, velFrom, velTo, -1);
119.80 + }
119.81 +
119.82 + public void add(ModelPerformer[] performers, int keyFrom, int keyTo) {
119.83 + add(performers, keyFrom, keyTo, 0, 127, -1);
119.84 + }
119.85 +
119.86 + public void add(ModelPerformer[] performers) {
119.87 + add(performers, 0, 127, 0, 127, -1);
119.88 + }
119.89 +
119.90 + public void add(ModelPerformer performer, int keyFrom, int keyTo,
119.91 + int velFrom, int velTo, int exclusiveClass) {
119.92 + add(new ModelPerformer[]{performer}, keyFrom, keyTo, velFrom, velTo,
119.93 + exclusiveClass);
119.94 + }
119.95 +
119.96 + public void add(ModelPerformer performer, int keyFrom, int keyTo,
119.97 + int velFrom, int velTo) {
119.98 + add(new ModelPerformer[]{performer}, keyFrom, keyTo, velFrom, velTo);
119.99 + }
119.100 +
119.101 + public void add(ModelPerformer performer, int keyFrom, int keyTo) {
119.102 + add(new ModelPerformer[]{performer}, keyFrom, keyTo);
119.103 + }
119.104 +
119.105 + public void add(ModelPerformer performer) {
119.106 + add(new ModelPerformer[]{performer});
119.107 + }
119.108 +
119.109 + public void add(ModelInstrument ins, int keyFrom, int keyTo, int velFrom,
119.110 + int velTo, int exclusiveClass) {
119.111 + add(ins.getPerformers(), keyFrom, keyTo, velFrom, velTo, exclusiveClass);
119.112 + }
119.113 +
119.114 + public void add(ModelInstrument ins, int keyFrom, int keyTo, int velFrom,
119.115 + int velTo) {
119.116 + add(ins.getPerformers(), keyFrom, keyTo, velFrom, velTo);
119.117 + }
119.118 +
119.119 + public void add(ModelInstrument ins, int keyFrom, int keyTo) {
119.120 + add(ins.getPerformers(), keyFrom, keyTo);
119.121 + }
119.122 +
119.123 + public void add(ModelInstrument ins) {
119.124 + add(ins.getPerformers());
119.125 + }
119.126 +
119.127 + public ModelPerformer[] getPerformers() {
119.128 +
119.129 + int percount = 0;
119.130 + for (SimpleInstrumentPart part : parts)
119.131 + if (part.performers != null)
119.132 + percount += part.performers.length;
119.133 +
119.134 + ModelPerformer[] performers = new ModelPerformer[percount];
119.135 + int px = 0;
119.136 + for (SimpleInstrumentPart part : parts) {
119.137 + if (part.performers != null) {
119.138 + for (ModelPerformer mperfm : part.performers) {
119.139 + ModelPerformer performer = new ModelPerformer();
119.140 + performer.setName(getName());
119.141 + performers[px++] = performer;
119.142 +
119.143 + performer.setDefaultConnectionsEnabled(
119.144 + mperfm.isDefaultConnectionsEnabled());
119.145 + performer.setKeyFrom(mperfm.getKeyFrom());
119.146 + performer.setKeyTo(mperfm.getKeyTo());
119.147 + performer.setVelFrom(mperfm.getVelFrom());
119.148 + performer.setVelTo(mperfm.getVelTo());
119.149 + performer.setExclusiveClass(mperfm.getExclusiveClass());
119.150 + performer.setSelfNonExclusive(mperfm.isSelfNonExclusive());
119.151 + performer.setReleaseTriggered(mperfm.isReleaseTriggered());
119.152 + if (part.exclusiveClass != -1)
119.153 + performer.setExclusiveClass(part.exclusiveClass);
119.154 + if (part.keyFrom > performer.getKeyFrom())
119.155 + performer.setKeyFrom(part.keyFrom);
119.156 + if (part.keyTo < performer.getKeyTo())
119.157 + performer.setKeyTo(part.keyTo);
119.158 + if (part.velFrom > performer.getVelFrom())
119.159 + performer.setVelFrom(part.velFrom);
119.160 + if (part.velTo < performer.getVelTo())
119.161 + performer.setVelTo(part.velTo);
119.162 + performer.getOscillators().addAll(mperfm.getOscillators());
119.163 + performer.getConnectionBlocks().addAll(
119.164 + mperfm.getConnectionBlocks());
119.165 + }
119.166 + }
119.167 + }
119.168 +
119.169 + return performers;
119.170 + }
119.171 +
119.172 + public Object getData() {
119.173 + return null;
119.174 + }
119.175 +
119.176 + public String getName() {
119.177 + return this.name;
119.178 + }
119.179 +
119.180 + public void setName(String name) {
119.181 + this.name = name;
119.182 + }
119.183 +
119.184 + public ModelPatch getPatch() {
119.185 + return new ModelPatch(bank, preset, percussion);
119.186 + }
119.187 +
119.188 + public void setPatch(Patch patch) {
119.189 + if (patch instanceof ModelPatch && ((ModelPatch)patch).isPercussion()) {
119.190 + percussion = true;
119.191 + bank = patch.getBank();
119.192 + preset = patch.getProgram();
119.193 + } else {
119.194 + percussion = false;
119.195 + bank = patch.getBank();
119.196 + preset = patch.getProgram();
119.197 + }
119.198 + }
119.199 +}
120.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
120.2 +++ b/src/share/classes/com/sun/media/sound/SimpleSoundbank.java Tue Feb 03 22:02:55 2009 -0800
120.3 @@ -0,0 +1,145 @@
120.4 +/*
120.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
120.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
120.7 + *
120.8 + * This code is free software; you can redistribute it and/or modify it
120.9 + * under the terms of the GNU General Public License version 2 only, as
120.10 + * published by the Free Software Foundation. Sun designates this
120.11 + * particular file as subject to the "Classpath" exception as provided
120.12 + * by Sun in the LICENSE file that accompanied this code.
120.13 + *
120.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
120.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
120.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
120.17 + * version 2 for more details (a copy is included in the LICENSE file that
120.18 + * accompanied this code).
120.19 + *
120.20 + * You should have received a copy of the GNU General Public License version
120.21 + * 2 along with this work; if not, write to the Free Software Foundation,
120.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
120.23 + *
120.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
120.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
120.26 + * have any questions.
120.27 + */
120.28 +package com.sun.media.sound;
120.29 +
120.30 +import java.util.ArrayList;
120.31 +import java.util.Arrays;
120.32 +import java.util.List;
120.33 +
120.34 +import javax.sound.midi.Instrument;
120.35 +import javax.sound.midi.Patch;
120.36 +import javax.sound.midi.Soundbank;
120.37 +import javax.sound.midi.SoundbankResource;
120.38 +
120.39 +/**
120.40 + * A simple soundbank that contains instruments and soundbankresources.
120.41 + *
120.42 + * @author Karl Helgason
120.43 + */
120.44 +public class SimpleSoundbank implements Soundbank {
120.45 +
120.46 + String name = "";
120.47 + String version = "";
120.48 + String vendor = "";
120.49 + String description = "";
120.50 + List<SoundbankResource> resources = new ArrayList<SoundbankResource>();
120.51 + List<Instrument> instruments = new ArrayList<Instrument>();
120.52 +
120.53 + public String getName() {
120.54 + return name;
120.55 + }
120.56 +
120.57 + public String getVersion() {
120.58 + return version;
120.59 + }
120.60 +
120.61 + public String getVendor() {
120.62 + return vendor;
120.63 + }
120.64 +
120.65 + public String getDescription() {
120.66 + return description;
120.67 + }
120.68 +
120.69 + public void setDescription(String description) {
120.70 + this.description = description;
120.71 + }
120.72 +
120.73 + public void setName(String name) {
120.74 + this.name = name;
120.75 + }
120.76 +
120.77 + public void setVendor(String vendor) {
120.78 + this.vendor = vendor;
120.79 + }
120.80 +
120.81 + public void setVersion(String version) {
120.82 + this.version = version;
120.83 + }
120.84 +
120.85 + public SoundbankResource[] getResources() {
120.86 + return resources.toArray(new SoundbankResource[resources.size()]);
120.87 + }
120.88 +
120.89 + public Instrument[] getInstruments() {
120.90 + Instrument[] inslist_array
120.91 + = instruments.toArray(new Instrument[resources.size()]);
120.92 + Arrays.sort(inslist_array, new ModelInstrumentComparator());
120.93 + return inslist_array;
120.94 + }
120.95 +
120.96 + public Instrument getInstrument(Patch patch) {
120.97 + int program = patch.getProgram();
120.98 + int bank = patch.getBank();
120.99 + boolean percussion = false;
120.100 + if (patch instanceof ModelPatch)
120.101 + percussion = ((ModelPatch)patch).isPercussion();
120.102 + for (Instrument instrument : instruments) {
120.103 + Patch patch2 = instrument.getPatch();
120.104 + int program2 = patch2.getProgram();
120.105 + int bank2 = patch2.getBank();
120.106 + if (program == program2 && bank == bank2) {
120.107 + boolean percussion2 = false;
120.108 + if (patch2 instanceof ModelPatch)
120.109 + percussion2 = ((ModelPatch)patch2).isPercussion();
120.110 + if (percussion == percussion2)
120.111 + return instrument;
120.112 + }
120.113 + }
120.114 + return null;
120.115 + }
120.116 +
120.117 + public void addResource(SoundbankResource resource) {
120.118 + if (resource instanceof Instrument)
120.119 + instruments.add((Instrument) resource);
120.120 + else
120.121 + resources.add(resource);
120.122 + }
120.123 +
120.124 + public void removeResource(SoundbankResource resource) {
120.125 + if (resource instanceof Instrument)
120.126 + instruments.remove((Instrument) resource);
120.127 + else
120.128 + resources.remove(resource);
120.129 + }
120.130 +
120.131 + public void addInstrument(Instrument resource) {
120.132 + instruments.add(resource);
120.133 + }
120.134 +
120.135 + public void removeInstrument(Instrument resource) {
120.136 + instruments.remove(resource);
120.137 + }
120.138 +
120.139 + public void addAllInstruments(Soundbank soundbank) {
120.140 + for (Instrument ins : soundbank.getInstruments())
120.141 + addInstrument(ins);
120.142 + }
120.143 +
120.144 + public void removeAllInstruments(Soundbank soundbank) {
120.145 + for (Instrument ins : soundbank.getInstruments())
120.146 + removeInstrument(ins);
120.147 + }
120.148 +}
121.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
121.2 +++ b/src/share/classes/com/sun/media/sound/SoftAbstractResampler.java Tue Feb 03 22:02:55 2009 -0800
121.3 @@ -0,0 +1,390 @@
121.4 +/*
121.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
121.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
121.7 + *
121.8 + * This code is free software; you can redistribute it and/or modify it
121.9 + * under the terms of the GNU General Public License version 2 only, as
121.10 + * published by the Free Software Foundation. Sun designates this
121.11 + * particular file as subject to the "Classpath" exception as provided
121.12 + * by Sun in the LICENSE file that accompanied this code.
121.13 + *
121.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
121.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
121.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
121.17 + * version 2 for more details (a copy is included in the LICENSE file that
121.18 + * accompanied this code).
121.19 + *
121.20 + * You should have received a copy of the GNU General Public License version
121.21 + * 2 along with this work; if not, write to the Free Software Foundation,
121.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
121.23 + *
121.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
121.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
121.26 + * have any questions.
121.27 + */
121.28 +package com.sun.media.sound;
121.29 +
121.30 +import java.io.IOException;
121.31 +import java.util.Arrays;
121.32 +
121.33 +import javax.sound.midi.MidiChannel;
121.34 +import javax.sound.midi.VoiceStatus;
121.35 +
121.36 +/**
121.37 + * Abstract resampler class.
121.38 + *
121.39 + * @author Karl Helgason
121.40 + */
121.41 +public abstract class SoftAbstractResampler implements SoftResampler {
121.42 +
121.43 + private class ModelAbstractResamplerStream implements SoftResamplerStreamer {
121.44 +
121.45 + AudioFloatInputStream stream;
121.46 + boolean stream_eof = false;
121.47 + int loopmode;
121.48 + boolean loopdirection = true; // true = forward
121.49 + float loopstart;
121.50 + float looplen;
121.51 + float target_pitch;
121.52 + float[] current_pitch = new float[1];
121.53 + boolean started;
121.54 + boolean eof;
121.55 + int sector_pos = 0;
121.56 + int sector_size = 400;
121.57 + int sector_loopstart = -1;
121.58 + boolean markset = false;
121.59 + int marklimit = 0;
121.60 + int streampos = 0;
121.61 + int nrofchannels = 2;
121.62 + boolean noteOff_flag = false;
121.63 + float[][] ibuffer;
121.64 + boolean ibuffer_order = true;
121.65 + float[] sbuffer;
121.66 + int pad;
121.67 + int pad2;
121.68 + float[] ix = new float[1];
121.69 + int[] ox = new int[1];
121.70 + float samplerateconv = 1;
121.71 + float pitchcorrection = 0;
121.72 +
121.73 + public ModelAbstractResamplerStream() {
121.74 + pad = getPadding();
121.75 + pad2 = getPadding() * 2;
121.76 + ibuffer = new float[2][sector_size + pad2];
121.77 + ibuffer_order = true;
121.78 + }
121.79 +
121.80 + public void noteOn(MidiChannel channel, VoiceStatus voice,
121.81 + int noteNumber, int velocity) {
121.82 + }
121.83 +
121.84 + public void noteOff(int velocity) {
121.85 + noteOff_flag = true;
121.86 + }
121.87 +
121.88 + public void open(ModelWavetable osc, float outputsamplerate)
121.89 + throws IOException {
121.90 +
121.91 + eof = false;
121.92 + nrofchannels = osc.getChannels();
121.93 + if (ibuffer.length < nrofchannels) {
121.94 + ibuffer = new float[nrofchannels][sector_size + pad2];
121.95 + }
121.96 +
121.97 + stream = osc.openStream();
121.98 + streampos = 0;
121.99 + stream_eof = false;
121.100 + pitchcorrection = osc.getPitchcorrection();
121.101 + samplerateconv
121.102 + = stream.getFormat().getSampleRate() / outputsamplerate;
121.103 + looplen = osc.getLoopLength();
121.104 + loopstart = osc.getLoopStart();
121.105 + sector_loopstart = (int) (loopstart / sector_size);
121.106 + sector_loopstart = sector_loopstart - 1;
121.107 +
121.108 + sector_pos = 0;
121.109 +
121.110 + if (sector_loopstart < 0)
121.111 + sector_loopstart = 0;
121.112 + started = false;
121.113 + loopmode = osc.getLoopType();
121.114 +
121.115 + if (loopmode != 0) {
121.116 + markset = false;
121.117 + marklimit = nrofchannels * (int) (looplen + pad2 + 1);
121.118 + } else
121.119 + markset = true;
121.120 + // loopmode = 0;
121.121 +
121.122 + target_pitch = samplerateconv;
121.123 + current_pitch[0] = samplerateconv;
121.124 +
121.125 + ibuffer_order = true;
121.126 + loopdirection = true;
121.127 + noteOff_flag = false;
121.128 +
121.129 + for (int i = 0; i < nrofchannels; i++)
121.130 + Arrays.fill(ibuffer[i], sector_size, sector_size + pad2, 0);
121.131 + ix[0] = pad;
121.132 + eof = false;
121.133 +
121.134 + ix[0] = sector_size + pad;
121.135 + sector_pos = -1;
121.136 + streampos = -sector_size;
121.137 +
121.138 + nextBuffer();
121.139 + }
121.140 +
121.141 + public void setPitch(float pitch) {
121.142 + /*
121.143 + this.pitch = (float) Math.pow(2f,
121.144 + (pitchcorrection + pitch) / 1200.0f)
121.145 + * samplerateconv;
121.146 + */
121.147 + this.target_pitch = (float)Math.exp(
121.148 + (pitchcorrection + pitch) * (Math.log(2.0) / 1200.0))
121.149 + * samplerateconv;
121.150 +
121.151 + if (!started)
121.152 + current_pitch[0] = this.target_pitch;
121.153 + }
121.154 +
121.155 + public void nextBuffer() throws IOException {
121.156 + if (ix[0] < pad) {
121.157 + if (markset) {
121.158 + // reset to target sector
121.159 + stream.reset();
121.160 + ix[0] += streampos - (sector_loopstart * sector_size);
121.161 + sector_pos = sector_loopstart;
121.162 + streampos = sector_pos * sector_size;
121.163 +
121.164 + // and go one sector backward
121.165 + ix[0] += sector_size;
121.166 + sector_pos -= 1;
121.167 + streampos -= sector_size;
121.168 + stream_eof = false;
121.169 + }
121.170 + }
121.171 +
121.172 + if (ix[0] >= sector_size + pad) {
121.173 + if (stream_eof) {
121.174 + eof = true;
121.175 + return;
121.176 + }
121.177 + }
121.178 +
121.179 + if (ix[0] >= sector_size * 4 + pad) {
121.180 + int skips = (int)((ix[0] - sector_size * 4 + pad) / sector_size);
121.181 + ix[0] -= sector_size * skips;
121.182 + sector_pos += skips;
121.183 + streampos += sector_size * skips;
121.184 + stream.skip(sector_size * skips);
121.185 + }
121.186 +
121.187 + while (ix[0] >= sector_size + pad) {
121.188 + if (!markset) {
121.189 + if (sector_pos + 1 == sector_loopstart) {
121.190 + stream.mark(marklimit);
121.191 + markset = true;
121.192 + }
121.193 + }
121.194 + ix[0] -= sector_size;
121.195 + sector_pos++;
121.196 + streampos += sector_size;
121.197 +
121.198 + for (int c = 0; c < nrofchannels; c++) {
121.199 + float[] cbuffer = ibuffer[c];
121.200 + for (int i = 0; i < pad2; i++)
121.201 + cbuffer[i] = cbuffer[i + sector_size];
121.202 + }
121.203 +
121.204 + int ret;
121.205 + if (nrofchannels == 1)
121.206 + ret = stream.read(ibuffer[0], pad2, sector_size);
121.207 + else {
121.208 + int slen = sector_size * nrofchannels;
121.209 + if (sbuffer == null || sbuffer.length < slen)
121.210 + sbuffer = new float[slen];
121.211 + int sret = stream.read(sbuffer, 0, slen);
121.212 + if (sret == -1)
121.213 + ret = -1;
121.214 + else {
121.215 + ret = sret / nrofchannels;
121.216 + for (int i = 0; i < nrofchannels; i++) {
121.217 + float[] buff = ibuffer[i];
121.218 + int ix = i;
121.219 + int ix_step = nrofchannels;
121.220 + int ox = pad2;
121.221 + for (int j = 0; j < ret; j++, ix += ix_step, ox++)
121.222 + buff[ox] = sbuffer[ix];
121.223 + }
121.224 + }
121.225 +
121.226 + }
121.227 +
121.228 + if (ret == -1) {
121.229 + ret = 0;
121.230 + stream_eof = true;
121.231 + for (int i = 0; i < nrofchannels; i++)
121.232 + Arrays.fill(ibuffer[i], pad2, pad2 + sector_size, 0f);
121.233 + return;
121.234 + }
121.235 + if (ret != sector_size) {
121.236 + for (int i = 0; i < nrofchannels; i++)
121.237 + Arrays.fill(ibuffer[i], pad2 + ret, pad2 + sector_size, 0f);
121.238 + }
121.239 +
121.240 + ibuffer_order = true;
121.241 +
121.242 + }
121.243 +
121.244 + }
121.245 +
121.246 + public void reverseBuffers() {
121.247 + ibuffer_order = !ibuffer_order;
121.248 + for (int c = 0; c < nrofchannels; c++) {
121.249 + float[] cbuff = ibuffer[c];
121.250 + int len = cbuff.length - 1;
121.251 + int len2 = cbuff.length / 2;
121.252 + for (int i = 0; i < len2; i++) {
121.253 + float x = cbuff[i];
121.254 + cbuff[i] = cbuff[len - i];
121.255 + cbuff[len - i] = x;
121.256 + }
121.257 + }
121.258 + }
121.259 +
121.260 + public int read(float[][] buffer, int offset, int len)
121.261 + throws IOException {
121.262 +
121.263 + if (eof)
121.264 + return -1;
121.265 +
121.266 + if (noteOff_flag)
121.267 + if ((loopmode & 2) != 0)
121.268 + if (loopdirection)
121.269 + loopmode = 0;
121.270 +
121.271 +
121.272 + float pitchstep = (target_pitch - current_pitch[0]) / len;
121.273 + float[] current_pitch = this.current_pitch;
121.274 + started = true;
121.275 +
121.276 + int[] ox = this.ox;
121.277 + ox[0] = offset;
121.278 + int ox_end = len + offset;
121.279 +
121.280 + float ixend = sector_size + pad;
121.281 + if (!loopdirection)
121.282 + ixend = pad;
121.283 + while (ox[0] != ox_end) {
121.284 + nextBuffer();
121.285 + if (!loopdirection) {
121.286 + // If we are in backward playing part of pingpong
121.287 + // or reverse loop
121.288 +
121.289 + if (streampos < (loopstart + pad)) {
121.290 + ixend = loopstart - streampos + pad2;
121.291 + if (ix[0] <= ixend) {
121.292 + if ((loopmode & 4) != 0) {
121.293 + // Ping pong loop, change loopdirection
121.294 + loopdirection = true;
121.295 + ixend = sector_size + pad;
121.296 + continue;
121.297 + }
121.298 +
121.299 + ix[0] += looplen;
121.300 + ixend = pad;
121.301 + continue;
121.302 + }
121.303 + }
121.304 +
121.305 + if (ibuffer_order != loopdirection)
121.306 + reverseBuffers();
121.307 +
121.308 + ix[0] = (sector_size + pad2) - ix[0];
121.309 + ixend = (sector_size + pad2) - ixend;
121.310 + ixend++;
121.311 +
121.312 + float bak_ix = ix[0];
121.313 + int bak_ox = ox[0];
121.314 + float bak_pitch = current_pitch[0];
121.315 + for (int i = 0; i < nrofchannels; i++) {
121.316 + if (buffer[i] != null) {
121.317 + ix[0] = bak_ix;
121.318 + ox[0] = bak_ox;
121.319 + current_pitch[0] = bak_pitch;
121.320 + interpolate(ibuffer[i], ix, ixend, current_pitch,
121.321 + pitchstep, buffer[i], ox, ox_end);
121.322 + }
121.323 + }
121.324 +
121.325 + ix[0] = (sector_size + pad2) - ix[0];
121.326 + ixend--;
121.327 + ixend = (sector_size + pad2) - ixend;
121.328 +
121.329 + if (eof) {
121.330 + current_pitch[0] = this.target_pitch;
121.331 + return ox[0] - offset;
121.332 + }
121.333 +
121.334 + continue;
121.335 + }
121.336 + if (loopmode != 0) {
121.337 + if (streampos + sector_size > (looplen + loopstart + pad)) {
121.338 + ixend = loopstart + looplen - streampos + pad2;
121.339 + if (ix[0] >= ixend) {
121.340 + if ((loopmode & 4) != 0 || (loopmode & 8) != 0) {
121.341 + // Ping pong or revese loop, change loopdirection
121.342 + loopdirection = false;
121.343 + ixend = pad;
121.344 + continue;
121.345 + }
121.346 + ixend = sector_size + pad;
121.347 + ix[0] -= looplen;
121.348 + continue;
121.349 + }
121.350 + }
121.351 + }
121.352 +
121.353 + if (ibuffer_order != loopdirection)
121.354 + reverseBuffers();
121.355 +
121.356 + float bak_ix = ix[0];
121.357 + int bak_ox = ox[0];
121.358 + float bak_pitch = current_pitch[0];
121.359 + for (int i = 0; i < nrofchannels; i++) {
121.360 + if (buffer[i] != null) {
121.361 + ix[0] = bak_ix;
121.362 + ox[0] = bak_ox;
121.363 + current_pitch[0] = bak_pitch;
121.364 + interpolate(ibuffer[i], ix, ixend, current_pitch,
121.365 + pitchstep, buffer[i], ox, ox_end);
121.366 + }
121.367 + }
121.368 +
121.369 + if (eof) {
121.370 + current_pitch[0] = this.target_pitch;
121.371 + return ox[0] - offset;
121.372 + }
121.373 + }
121.374 +
121.375 + current_pitch[0] = this.target_pitch;
121.376 + return len;
121.377 + }
121.378 +
121.379 + public void close() throws IOException {
121.380 + stream.close();
121.381 + }
121.382 + }
121.383 +
121.384 + public abstract int getPadding();
121.385 +
121.386 + public abstract void interpolate(float[] in, float[] in_offset,
121.387 + float in_end, float[] pitch, float pitchstep, float[] out,
121.388 + int[] out_offset, int out_end);
121.389 +
121.390 + public SoftResamplerStreamer openStreamer() {
121.391 + return new ModelAbstractResamplerStream();
121.392 + }
121.393 +}
122.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
122.2 +++ b/src/share/classes/com/sun/media/sound/SoftAudioBuffer.java Tue Feb 03 22:02:55 2009 -0800
122.3 @@ -0,0 +1,104 @@
122.4 +/*
122.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
122.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
122.7 + *
122.8 + * This code is free software; you can redistribute it and/or modify it
122.9 + * under the terms of the GNU General Public License version 2 only, as
122.10 + * published by the Free Software Foundation. Sun designates this
122.11 + * particular file as subject to the "Classpath" exception as provided
122.12 + * by Sun in the LICENSE file that accompanied this code.
122.13 + *
122.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
122.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
122.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
122.17 + * version 2 for more details (a copy is included in the LICENSE file that
122.18 + * accompanied this code).
122.19 + *
122.20 + * You should have received a copy of the GNU General Public License version
122.21 + * 2 along with this work; if not, write to the Free Software Foundation,
122.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
122.23 + *
122.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
122.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
122.26 + * have any questions.
122.27 + */
122.28 +package com.sun.media.sound;
122.29 +
122.30 +import java.util.Arrays;
122.31 +
122.32 +import javax.sound.sampled.AudioFormat;
122.33 +
122.34 +/**
122.35 + * This class is used to store audio buffer.
122.36 + *
122.37 + * @author Karl Helgason
122.38 + */
122.39 +public class SoftAudioBuffer {
122.40 +
122.41 + private int size;
122.42 + private float[] buffer;
122.43 + private boolean empty = true;
122.44 + private AudioFormat format;
122.45 + private AudioFloatConverter converter;
122.46 + private byte[] converter_buffer;
122.47 +
122.48 + public SoftAudioBuffer(int size, AudioFormat format) {
122.49 + this.size = size;
122.50 + this.format = format;
122.51 + converter = AudioFloatConverter.getConverter(format);
122.52 + }
122.53 +
122.54 + public AudioFormat getFormat() {
122.55 + return format;
122.56 + }
122.57 +
122.58 + public int getSize() {
122.59 + return size;
122.60 + }
122.61 +
122.62 + public void clear() {
122.63 + if (!empty) {
122.64 + Arrays.fill(buffer, 0);
122.65 + empty = true;
122.66 + }
122.67 + }
122.68 +
122.69 + public boolean isSilent() {
122.70 + return empty;
122.71 + }
122.72 +
122.73 + public float[] array() {
122.74 + empty = false;
122.75 + if (buffer == null)
122.76 + buffer = new float[size];
122.77 + return buffer;
122.78 + }
122.79 +
122.80 + public void get(byte[] buffer, int channel) {
122.81 +
122.82 + int framesize_pc = (format.getFrameSize() / format.getChannels());
122.83 + int c_len = size * framesize_pc;
122.84 + if (converter_buffer == null || converter_buffer.length < c_len)
122.85 + converter_buffer = new byte[c_len];
122.86 +
122.87 + if (format.getChannels() == 1) {
122.88 + converter.toByteArray(array(), size, buffer);
122.89 + } else {
122.90 + converter.toByteArray(array(), size, converter_buffer);
122.91 + if (channel >= format.getChannels())
122.92 + return;
122.93 + int z_stepover = format.getChannels() * framesize_pc;
122.94 + int k_stepover = framesize_pc;
122.95 + for (int j = 0; j < framesize_pc; j++) {
122.96 + int k = j;
122.97 + int z = channel * framesize_pc + j;
122.98 + for (int i = 0; i < size; i++) {
122.99 + buffer[z] = converter_buffer[k];
122.100 + z += z_stepover;
122.101 + k += k_stepover;
122.102 + }
122.103 + }
122.104 + }
122.105 +
122.106 + }
122.107 +}
123.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
123.2 +++ b/src/share/classes/com/sun/media/sound/SoftAudioProcessor.java Tue Feb 03 22:02:55 2009 -0800
123.3 @@ -0,0 +1,48 @@
123.4 +/*
123.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
123.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
123.7 + *
123.8 + * This code is free software; you can redistribute it and/or modify it
123.9 + * under the terms of the GNU General Public License version 2 only, as
123.10 + * published by the Free Software Foundation. Sun designates this
123.11 + * particular file as subject to the "Classpath" exception as provided
123.12 + * by Sun in the LICENSE file that accompanied this code.
123.13 + *
123.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
123.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
123.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
123.17 + * version 2 for more details (a copy is included in the LICENSE file that
123.18 + * accompanied this code).
123.19 + *
123.20 + * You should have received a copy of the GNU General Public License version
123.21 + * 2 along with this work; if not, write to the Free Software Foundation,
123.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
123.23 + *
123.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
123.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
123.26 + * have any questions.
123.27 + */
123.28 +package com.sun.media.sound;
123.29 +
123.30 +/**
123.31 + * Audio processor interface.
123.32 + *
123.33 + * @author Karl Helgason
123.34 + */
123.35 +public interface SoftAudioProcessor {
123.36 +
123.37 + public void globalParameterControlChange(int[] slothpath, long param,
123.38 + long value);
123.39 +
123.40 + public void init(float samplerate, float controlrate);
123.41 +
123.42 + public void setInput(int pin, SoftAudioBuffer input);
123.43 +
123.44 + public void setOutput(int pin, SoftAudioBuffer output);
123.45 +
123.46 + public void setMixMode(boolean mix);
123.47 +
123.48 + public void processAudio();
123.49 +
123.50 + public void processControlLogic();
123.51 +}
124.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
124.2 +++ b/src/share/classes/com/sun/media/sound/SoftAudioPusher.java Tue Feb 03 22:02:55 2009 -0800
124.3 @@ -0,0 +1,91 @@
124.4 +/*
124.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
124.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
124.7 + *
124.8 + * This code is free software; you can redistribute it and/or modify it
124.9 + * under the terms of the GNU General Public License version 2 only, as
124.10 + * published by the Free Software Foundation. Sun designates this
124.11 + * particular file as subject to the "Classpath" exception as provided
124.12 + * by Sun in the LICENSE file that accompanied this code.
124.13 + *
124.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
124.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
124.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
124.17 + * version 2 for more details (a copy is included in the LICENSE file that
124.18 + * accompanied this code).
124.19 + *
124.20 + * You should have received a copy of the GNU General Public License version
124.21 + * 2 along with this work; if not, write to the Free Software Foundation,
124.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
124.23 + *
124.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
124.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
124.26 + * have any questions.
124.27 + */
124.28 +package com.sun.media.sound;
124.29 +
124.30 +import java.io.IOException;
124.31 +
124.32 +import javax.sound.sampled.AudioInputStream;
124.33 +import javax.sound.sampled.SourceDataLine;
124.34 +
124.35 +/**
124.36 + * This is a processor object that writes into SourceDataLine
124.37 + *
124.38 + * @author Karl Helgason
124.39 + */
124.40 +public class SoftAudioPusher implements Runnable {
124.41 +
124.42 + private volatile boolean active = false;
124.43 + private SourceDataLine sourceDataLine = null;
124.44 + private Thread audiothread;
124.45 + private AudioInputStream ais;
124.46 + private byte[] buffer;
124.47 +
124.48 + public SoftAudioPusher(SourceDataLine sourceDataLine, AudioInputStream ais,
124.49 + int workbuffersizer) {
124.50 + this.ais = ais;
124.51 + this.buffer = new byte[workbuffersizer];
124.52 + this.sourceDataLine = sourceDataLine;
124.53 + }
124.54 +
124.55 + public synchronized void start() {
124.56 + if (active)
124.57 + return;
124.58 + active = true;
124.59 + audiothread = new Thread(this);
124.60 + audiothread.setPriority(Thread.MAX_PRIORITY);
124.61 + audiothread.start();
124.62 + }
124.63 +
124.64 + public synchronized void stop() {
124.65 + if (!active)
124.66 + return;
124.67 + active = false;
124.68 + try {
124.69 + audiothread.join();
124.70 + } catch (InterruptedException e) {
124.71 + //e.printStackTrace();
124.72 + }
124.73 + }
124.74 +
124.75 + public void run() {
124.76 + byte[] buffer = SoftAudioPusher.this.buffer;
124.77 + AudioInputStream ais = SoftAudioPusher.this.ais;
124.78 + SourceDataLine sourceDataLine = SoftAudioPusher.this.sourceDataLine;
124.79 +
124.80 + try {
124.81 + while (active) {
124.82 + // Read from audio source
124.83 + int count = ais.read(buffer);
124.84 + if(count < 0) break;
124.85 + // Write byte buffer to source output
124.86 + sourceDataLine.write(buffer, 0, count);
124.87 + }
124.88 + } catch (IOException e) {
124.89 + active = false;
124.90 + //e.printStackTrace();
124.91 + }
124.92 +
124.93 + }
124.94 +}
125.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
125.2 +++ b/src/share/classes/com/sun/media/sound/SoftChannel.java Tue Feb 03 22:02:55 2009 -0800
125.3 @@ -0,0 +1,1548 @@
125.4 +/*
125.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
125.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
125.7 + *
125.8 + * This code is free software; you can redistribute it and/or modify it
125.9 + * under the terms of the GNU General Public License version 2 only, as
125.10 + * published by the Free Software Foundation. Sun designates this
125.11 + * particular file as subject to the "Classpath" exception as provided
125.12 + * by Sun in the LICENSE file that accompanied this code.
125.13 + *
125.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
125.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
125.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
125.17 + * version 2 for more details (a copy is included in the LICENSE file that
125.18 + * accompanied this code).
125.19 + *
125.20 + * You should have received a copy of the GNU General Public License version
125.21 + * 2 along with this work; if not, write to the Free Software Foundation,
125.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
125.23 + *
125.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
125.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
125.26 + * have any questions.
125.27 + */
125.28 +package com.sun.media.sound;
125.29 +
125.30 +import java.util.ArrayList;
125.31 +import java.util.Arrays;
125.32 +import java.util.HashMap;
125.33 +import java.util.Iterator;
125.34 +import java.util.List;
125.35 +import java.util.Map;
125.36 +
125.37 +import javax.sound.midi.MidiChannel;
125.38 +import javax.sound.midi.Patch;
125.39 +
125.40 +/**
125.41 + * Software Synthesizer MIDI channel class.
125.42 + *
125.43 + * @author Karl Helgason
125.44 + */
125.45 +public class SoftChannel implements MidiChannel, ModelDirectedPlayer {
125.46 +
125.47 + private static boolean[] dontResetControls = new boolean[128];
125.48 + static {
125.49 + for (int i = 0; i < dontResetControls.length; i++)
125.50 + dontResetControls[i] = false;
125.51 +
125.52 + dontResetControls[0] = true; // Bank Select (MSB)
125.53 + dontResetControls[32] = true; // Bank Select (LSB)
125.54 + dontResetControls[7] = true; // Channel Volume (MSB)
125.55 + dontResetControls[8] = true; // Balance (MSB)
125.56 + dontResetControls[10] = true; // Pan (MSB)
125.57 + dontResetControls[11] = true; // Expression (MSB)
125.58 + dontResetControls[91] = true; // Effects 1 Depth (default: Reverb Send)
125.59 + dontResetControls[92] = true; // Effects 2 Depth (default: Tremolo Depth)
125.60 + dontResetControls[93] = true; // Effects 3 Depth (default: Chorus Send)
125.61 + dontResetControls[94] = true; // Effects 4 Depth (default: Celeste [Detune] Depth)
125.62 + dontResetControls[95] = true; // Effects 5 Depth (default: Phaser Depth)
125.63 + dontResetControls[70] = true; // Sound Controller 1 (default: Sound Variation)
125.64 + dontResetControls[71] = true; // Sound Controller 2 (default: Timbre / Harmonic Quality)
125.65 + dontResetControls[72] = true; // Sound Controller 3 (default: Release Time)
125.66 + dontResetControls[73] = true; // Sound Controller 4 (default: Attack Time)
125.67 + dontResetControls[74] = true; // Sound Controller 5 (default: Brightness)
125.68 + dontResetControls[75] = true; // Sound Controller 6 (GM2 default: Decay Time)
125.69 + dontResetControls[76] = true; // Sound Controller 7 (GM2 default: Vibrato Rate)
125.70 + dontResetControls[77] = true; // Sound Controller 8 (GM2 default: Vibrato Depth)
125.71 + dontResetControls[78] = true; // Sound Controller 9 (GM2 default: Vibrato Delay)
125.72 + dontResetControls[79] = true; // Sound Controller 10 (GM2 default: Undefined)
125.73 + dontResetControls[120] = true; // All Sound Off
125.74 + dontResetControls[121] = true; // Reset All Controllers
125.75 + dontResetControls[122] = true; // Local Control On/Off
125.76 + dontResetControls[123] = true; // All Notes Off
125.77 + dontResetControls[124] = true; // Omni Mode Off
125.78 + dontResetControls[125] = true; // Omni Mode On
125.79 + dontResetControls[126] = true; // Poly Mode Off
125.80 + dontResetControls[127] = true; // Poly Mode On
125.81 +
125.82 + dontResetControls[6] = true; // Data Entry (MSB)
125.83 + dontResetControls[38] = true; // Data Entry (LSB)
125.84 + dontResetControls[96] = true; // Data Increment
125.85 + dontResetControls[97] = true; // Data Decrement
125.86 + dontResetControls[98] = true; // Non-Registered Parameter Number (LSB)
125.87 + dontResetControls[99] = true; // Non-Registered Parameter Number(MSB)
125.88 + dontResetControls[100] = true; // RPN = Null
125.89 + dontResetControls[101] = true; // RPN = Null
125.90 +
125.91 + }
125.92 +
125.93 + private static final int RPN_NULL_VALUE = (127 << 7) + 127;
125.94 + private int rpn_control = RPN_NULL_VALUE;
125.95 + private int nrpn_control = RPN_NULL_VALUE;
125.96 + protected double portamento_time = 1; // keyschanges per control buffer time
125.97 + protected int[] portamento_lastnote = new int[128];
125.98 + protected int portamento_lastnote_ix = 0;
125.99 + private int portamento_control_note = -1;
125.100 + private boolean portamento = false;
125.101 + private boolean mono = false;
125.102 + private boolean mute = false;
125.103 + private boolean solo = false;
125.104 + private boolean solomute = false;
125.105 + private Object control_mutex;
125.106 + private int channel;
125.107 + private SoftVoice[] voices;
125.108 + private int bank;
125.109 + private int program;
125.110 + private SoftSynthesizer synthesizer;
125.111 + private SoftMainMixer mainmixer;
125.112 + private int[] polypressure = new int[128];
125.113 + private int channelpressure = 0;
125.114 + private int[] controller = new int[128];
125.115 + private int pitchbend;
125.116 + private double[] co_midi_pitch = new double[1];
125.117 + private double[] co_midi_channel_pressure = new double[1];
125.118 + protected SoftTuning tuning = new SoftTuning();
125.119 + protected int tuning_bank = 0;
125.120 + protected int tuning_program = 0;
125.121 + protected SoftInstrument current_instrument = null;
125.122 + protected ModelChannelMixer current_mixer = null;
125.123 + private ModelDirector current_director = null;
125.124 +
125.125 + // Controller Destination Settings
125.126 + protected int cds_control_number = -1;
125.127 + protected ModelConnectionBlock[] cds_control_connections = null;
125.128 + protected ModelConnectionBlock[] cds_channelpressure_connections = null;
125.129 + protected ModelConnectionBlock[] cds_polypressure_connections = null;
125.130 + protected boolean sustain = false;
125.131 + protected boolean[][] keybasedcontroller_active = null;
125.132 + protected double[][] keybasedcontroller_value = null;
125.133 +
125.134 + private class MidiControlObject implements SoftControl {
125.135 + double[] pitch = co_midi_pitch;
125.136 + double[] channel_pressure = co_midi_channel_pressure;
125.137 + double[] poly_pressure = new double[1];
125.138 +
125.139 + public double[] get(int instance, String name) {
125.140 + if (name == null)
125.141 + return null;
125.142 + if (name.equals("pitch"))
125.143 + return pitch;
125.144 + if (name.equals("channel_pressure"))
125.145 + return channel_pressure;
125.146 + if (name.equals("poly_pressure"))
125.147 + return poly_pressure;
125.148 + return null;
125.149 + }
125.150 + }
125.151 +
125.152 + private SoftControl[] co_midi = new SoftControl[128];
125.153 + {
125.154 + for (int i = 0; i < co_midi.length; i++) {
125.155 + co_midi[i] = new MidiControlObject();
125.156 + }
125.157 + }
125.158 +
125.159 + private double[][] co_midi_cc_cc = new double[128][1];
125.160 + private SoftControl co_midi_cc = new SoftControl() {
125.161 + double[][] cc = co_midi_cc_cc;
125.162 + public double[] get(int instance, String name) {
125.163 + if (name == null)
125.164 + return null;
125.165 + return cc[Integer.parseInt(name)];
125.166 + }
125.167 + };
125.168 + Map<Integer, int[]> co_midi_rpn_rpn_i = new HashMap<Integer, int[]>();
125.169 + Map<Integer, double[]> co_midi_rpn_rpn = new HashMap<Integer, double[]>();
125.170 + private SoftControl co_midi_rpn = new SoftControl() {
125.171 + Map<Integer, double[]> rpn = co_midi_rpn_rpn;
125.172 + public double[] get(int instance, String name) {
125.173 + if (name == null)
125.174 + return null;
125.175 + int iname = Integer.parseInt(name);
125.176 + double[] v = rpn.get(iname);
125.177 + if (v == null) {
125.178 + v = new double[1];
125.179 + rpn.put(iname, v);
125.180 + }
125.181 + return v;
125.182 + }
125.183 + };
125.184 + Map<Integer, int[]> co_midi_nrpn_nrpn_i = new HashMap<Integer, int[]>();
125.185 + Map<Integer, double[]> co_midi_nrpn_nrpn = new HashMap<Integer, double[]>();
125.186 + private SoftControl co_midi_nrpn = new SoftControl() {
125.187 + Map<Integer, double[]> nrpn = co_midi_nrpn_nrpn;
125.188 + public double[] get(int instance, String name) {
125.189 + if (name == null)
125.190 + return null;
125.191 + int iname = Integer.parseInt(name);
125.192 + double[] v = nrpn.get(iname);
125.193 + if (v == null) {
125.194 + v = new double[1];
125.195 + nrpn.put(iname, v);
125.196 + }
125.197 + return v;
125.198 + }
125.199 + };
125.200 +
125.201 + private static int restrict7Bit(int value)
125.202 + {
125.203 + if(value < 0) return 0;
125.204 + if(value > 127) return 127;
125.205 + return value;
125.206 + }
125.207 +
125.208 + private static int restrict14Bit(int value)
125.209 + {
125.210 + if(value < 0) return 0;
125.211 + if(value > 16256) return 16256;
125.212 + return value;
125.213 + }
125.214 +
125.215 + public SoftChannel(SoftSynthesizer synth, int channel) {
125.216 + this.channel = channel;
125.217 + this.voices = synth.getVoices();
125.218 + this.synthesizer = synth;
125.219 + this.mainmixer = synth.getMainMixer();
125.220 + control_mutex = synth.control_mutex;
125.221 + resetAllControllers(true);
125.222 + }
125.223 +
125.224 + private int findFreeVoice(int x) {
125.225 + for (int i = x; i < voices.length; i++)
125.226 + if (!voices[i].active)
125.227 + return i;
125.228 +
125.229 + // No free voice was found, we must steal one
125.230 +
125.231 + int vmode = synthesizer.getVoiceAllocationMode();
125.232 + if (vmode == 1) {
125.233 + // DLS Static Voice Allocation
125.234 +
125.235 + // * priority ( 10, 1-9, 11-16)
125.236 + // Search for channel to steal from
125.237 + int steal_channel = channel;
125.238 + for (int j = 0; j < voices.length; j++) {
125.239 + if (voices[j].stealer_channel == null) {
125.240 + if (steal_channel == 9) {
125.241 + steal_channel = voices[j].channel;
125.242 + } else {
125.243 + if (voices[j].channel != 9) {
125.244 + if (voices[j].channel > steal_channel)
125.245 + steal_channel = voices[j].channel;
125.246 + }
125.247 + }
125.248 + }
125.249 + }
125.250 +
125.251 + int voiceNo = -1;
125.252 +
125.253 + SoftVoice v = null;
125.254 + // Search for oldest voice in off state on steal_channel
125.255 + for (int j = 0; j < voices.length; j++) {
125.256 + if (voices[j].channel == steal_channel) {
125.257 + if (voices[j].stealer_channel == null && !voices[j].on) {
125.258 + if (v == null) {
125.259 + v = voices[j];
125.260 + voiceNo = j;
125.261 + }
125.262 + if (voices[j].voiceID < v.voiceID) {
125.263 + v = voices[j];
125.264 + voiceNo = j;
125.265 + }
125.266 + }
125.267 + }
125.268 + }
125.269 + // Search for oldest voice in on state on steal_channel
125.270 + if (voiceNo == -1) {
125.271 + for (int j = 0; j < voices.length; j++) {
125.272 + if (voices[j].channel == steal_channel) {
125.273 + if (voices[j].stealer_channel == null) {
125.274 + if (v == null) {
125.275 + v = voices[j];
125.276 + voiceNo = j;
125.277 + }
125.278 + if (voices[j].voiceID < v.voiceID) {
125.279 + v = voices[j];
125.280 + voiceNo = j;
125.281 + }
125.282 + }
125.283 + }
125.284 + }
125.285 + }
125.286 +
125.287 + return voiceNo;
125.288 +
125.289 + } else {
125.290 + // Default Voice Allocation
125.291 + // * Find voice that is on
125.292 + // and Find voice which has lowest voiceID ( oldest voice)
125.293 + // * Or find voice that is off
125.294 + // and Find voice which has lowest voiceID ( oldest voice)
125.295 +
125.296 + int voiceNo = -1;
125.297 +
125.298 + SoftVoice v = null;
125.299 + // Search for oldest voice in off state
125.300 + for (int j = 0; j < voices.length; j++) {
125.301 + if (voices[j].stealer_channel == null && !voices[j].on) {
125.302 + if (v == null) {
125.303 + v = voices[j];
125.304 + voiceNo = j;
125.305 + }
125.306 + if (voices[j].voiceID < v.voiceID) {
125.307 + v = voices[j];
125.308 + voiceNo = j;
125.309 + }
125.310 + }
125.311 + }
125.312 + // Search for oldest voice in on state
125.313 + if (voiceNo == -1) {
125.314 +
125.315 + for (int j = 0; j < voices.length; j++) {
125.316 + if (voices[j].stealer_channel == null) {
125.317 + if (v == null) {
125.318 + v = voices[j];
125.319 + voiceNo = j;
125.320 + }
125.321 + if (voices[j].voiceID < v.voiceID) {
125.322 + v = voices[j];
125.323 + voiceNo = j;
125.324 + }
125.325 + }
125.326 + }
125.327 + }
125.328 +
125.329 + return voiceNo;
125.330 + }
125.331 +
125.332 + }
125.333 +
125.334 + protected void initVoice(SoftVoice voice, SoftPerformer p, int voiceID,
125.335 + int noteNumber, int velocity, ModelConnectionBlock[] connectionBlocks,
125.336 + ModelChannelMixer channelmixer, boolean releaseTriggered) {
125.337 + if (voice.active) {
125.338 + // Voice is active , we must steal the voice
125.339 + voice.stealer_channel = this;
125.340 + voice.stealer_performer = p;
125.341 + voice.stealer_voiceID = voiceID;
125.342 + voice.stealer_noteNumber = noteNumber;
125.343 + voice.stealer_velocity = velocity;
125.344 + voice.stealer_extendedConnectionBlocks = connectionBlocks;
125.345 + voice.stealer_channelmixer = channelmixer;
125.346 + voice.stealer_releaseTriggered = releaseTriggered;
125.347 + for (int i = 0; i < voices.length; i++)
125.348 + if (voices[i].active && voices[i].voiceID == voice.voiceID)
125.349 + voices[i].soundOff();
125.350 + return;
125.351 + }
125.352 +
125.353 + voice.extendedConnectionBlocks = connectionBlocks;
125.354 + voice.channelmixer = channelmixer;
125.355 + voice.releaseTriggered = releaseTriggered;
125.356 + voice.voiceID = voiceID;
125.357 + voice.tuning = tuning;
125.358 + voice.exclusiveClass = p.exclusiveClass;
125.359 + voice.softchannel = this;
125.360 + voice.channel = channel;
125.361 + voice.bank = bank;
125.362 + voice.program = program;
125.363 + voice.instrument = current_instrument;
125.364 + voice.performer = p;
125.365 + voice.objects.clear();
125.366 + voice.objects.put("midi", co_midi[noteNumber]);
125.367 + voice.objects.put("midi_cc", co_midi_cc);
125.368 + voice.objects.put("midi_rpn", co_midi_rpn);
125.369 + voice.objects.put("midi_nrpn", co_midi_nrpn);
125.370 + voice.noteOn(noteNumber, velocity);
125.371 + voice.setMute(mute);
125.372 + voice.setSoloMute(solomute);
125.373 + if (releaseTriggered)
125.374 + return;
125.375 + if (portamento_control_note != -1) {
125.376 + voice.co_noteon_keynumber[0]
125.377 + = (tuning.getTuning(portamento_control_note) / 100.0)
125.378 + * (1f / 128f);
125.379 + voice.portamento = true;
125.380 + portamento_control_note = -1;
125.381 + } else if (portamento) {
125.382 + if (mono) {
125.383 + if (portamento_lastnote[0] != -1) {
125.384 + voice.co_noteon_keynumber[0]
125.385 + = (tuning.getTuning(portamento_lastnote[0]) / 100.0)
125.386 + * (1f / 128f);
125.387 + voice.portamento = true;
125.388 + portamento_control_note = -1;
125.389 + }
125.390 + portamento_lastnote[0] = noteNumber;
125.391 + } else {
125.392 + if (portamento_lastnote_ix != 0) {
125.393 + portamento_lastnote_ix--;
125.394 + voice.co_noteon_keynumber[0]
125.395 + = (tuning.getTuning(
125.396 + portamento_lastnote[portamento_lastnote_ix])
125.397 + / 100.0)
125.398 + * (1f / 128f);
125.399 + voice.portamento = true;
125.400 + }
125.401 + }
125.402 + }
125.403 + }
125.404 +
125.405 + public void noteOn(int noteNumber, int velocity) {
125.406 + noteNumber = restrict7Bit(noteNumber);
125.407 + velocity = restrict7Bit(velocity);
125.408 + noteOn_internal(noteNumber, velocity);
125.409 + if (current_mixer != null)
125.410 + current_mixer.noteOn(noteNumber, velocity);
125.411 + }
125.412 +
125.413 + private void noteOn_internal(int noteNumber, int velocity) {
125.414 +
125.415 + if (velocity == 0) {
125.416 + noteOff_internal(noteNumber, 64);
125.417 + return;
125.418 + }
125.419 +
125.420 + synchronized (control_mutex) {
125.421 + if (sustain) {
125.422 + sustain = false;
125.423 + for (int i = 0; i < voices.length; i++) {
125.424 + if ((voices[i].sustain || voices[i].on)
125.425 + && voices[i].channel == channel && voices[i].active
125.426 + && voices[i].note == noteNumber) {
125.427 + voices[i].sustain = false;
125.428 + voices[i].on = true;
125.429 + voices[i].noteOff(0);
125.430 + }
125.431 + }
125.432 + sustain = true;
125.433 + }
125.434 +
125.435 + mainmixer.activity();
125.436 +
125.437 + if (mono) {
125.438 + if (portamento) {
125.439 + boolean n_found = false;
125.440 + for (int i = 0; i < voices.length; i++) {
125.441 + if (voices[i].on && voices[i].channel == channel
125.442 + && voices[i].active
125.443 + && voices[i].releaseTriggered == false) {
125.444 + voices[i].portamento = true;
125.445 + voices[i].setNote(noteNumber);
125.446 + n_found = true;
125.447 + }
125.448 + }
125.449 + if (n_found) {
125.450 + portamento_lastnote[0] = noteNumber;
125.451 + return;
125.452 + }
125.453 + }
125.454 +
125.455 + if (portamento_control_note != -1) {
125.456 + boolean n_found = false;
125.457 + for (int i = 0; i < voices.length; i++) {
125.458 + if (voices[i].on && voices[i].channel == channel
125.459 + && voices[i].active
125.460 + && voices[i].note == portamento_control_note
125.461 + && voices[i].releaseTriggered == false) {
125.462 + voices[i].portamento = true;
125.463 + voices[i].setNote(noteNumber);
125.464 + n_found = true;
125.465 + }
125.466 + }
125.467 + portamento_control_note = -1;
125.468 + if (n_found)
125.469 + return;
125.470 + }
125.471 + }
125.472 +
125.473 + if (mono)
125.474 + allNotesOff();
125.475 +
125.476 + if (current_instrument == null) {
125.477 + current_instrument
125.478 + = synthesizer.findInstrument(program, bank, channel);
125.479 + if (current_instrument == null)
125.480 + return;
125.481 + if (current_mixer != null)
125.482 + mainmixer.stopMixer(current_mixer);
125.483 + current_mixer = current_instrument.getSourceInstrument()
125.484 + .getChannelMixer(this, synthesizer.getFormat());
125.485 + if (current_mixer != null)
125.486 + mainmixer.registerMixer(current_mixer);
125.487 + current_director = current_instrument.getDirector(this, this);
125.488 + applyInstrumentCustomization();
125.489 + }
125.490 + prevVoiceID = synthesizer.voiceIDCounter++;
125.491 + firstVoice = true;
125.492 + voiceNo = 0;
125.493 +
125.494 + int tunedKey = (int)(Math.round(tuning.getTuning()[noteNumber]/100.0));
125.495 + play_noteNumber = noteNumber;
125.496 + play_velocity = velocity;
125.497 + play_releasetriggered = false;
125.498 + lastVelocity[noteNumber] = velocity;
125.499 + current_director.noteOn(tunedKey, velocity);
125.500 +
125.501 + /*
125.502 + SoftPerformer[] performers = current_instrument.getPerformers();
125.503 + for (int i = 0; i < performers.length; i++) {
125.504 + SoftPerformer p = performers[i];
125.505 + if (p.keyFrom <= tunedKey && p.keyTo >= tunedKey) {
125.506 + if (p.velFrom <= velocity && p.velTo >= velocity) {
125.507 + if (firstVoice) {
125.508 + firstVoice = false;
125.509 + if (p.exclusiveClass != 0) {
125.510 + int x = p.exclusiveClass;
125.511 + for (int j = 0; j < voices.length; j++) {
125.512 + if (voices[j].active
125.513 + && voices[j].channel == channel
125.514 + && voices[j].exclusiveClass == x) {
125.515 + if (!(p.selfNonExclusive
125.516 + && voices[j].note == noteNumber))
125.517 + voices[j].shutdown();
125.518 + }
125.519 + }
125.520 + }
125.521 + }
125.522 + voiceNo = findFreeVoice(voiceNo);
125.523 + if (voiceNo == -1)
125.524 + return;
125.525 + initVoice(voices[voiceNo], p, prevVoiceID, noteNumber,
125.526 + velocity);
125.527 + }
125.528 + }
125.529 + }
125.530 + */
125.531 + }
125.532 + }
125.533 +
125.534 + public void noteOff(int noteNumber, int velocity) {
125.535 + noteNumber = restrict7Bit(noteNumber);
125.536 + velocity = restrict7Bit(velocity);
125.537 + noteOff_internal(noteNumber, velocity);
125.538 +
125.539 + if (current_mixer != null)
125.540 + current_mixer.noteOff(noteNumber, velocity);
125.541 + }
125.542 +
125.543 + private void noteOff_internal(int noteNumber, int velocity) {
125.544 + synchronized (control_mutex) {
125.545 +
125.546 + if (!mono) {
125.547 + if (portamento) {
125.548 + if (portamento_lastnote_ix != 127) {
125.549 + portamento_lastnote[portamento_lastnote_ix] = noteNumber;
125.550 + portamento_lastnote_ix++;
125.551 + }
125.552 + }
125.553 + }
125.554 +
125.555 + mainmixer.activity();
125.556 + for (int i = 0; i < voices.length; i++) {
125.557 + if (voices[i].on && voices[i].channel == channel
125.558 + && voices[i].note == noteNumber
125.559 + && voices[i].releaseTriggered == false) {
125.560 + voices[i].noteOff(velocity);
125.561 + }
125.562 + }
125.563 +
125.564 + // Try play back note-off triggered voices,
125.565 +
125.566 + if (current_instrument == null) {
125.567 + current_instrument
125.568 + = synthesizer.findInstrument(program, bank, channel);
125.569 + if (current_instrument == null)
125.570 + return;
125.571 + if (current_mixer != null)
125.572 + mainmixer.stopMixer(current_mixer);
125.573 + current_mixer = current_instrument.getSourceInstrument()
125.574 + .getChannelMixer(this, synthesizer.getFormat());
125.575 + if (current_mixer != null)
125.576 + mainmixer.registerMixer(current_mixer);
125.577 + current_director = current_instrument.getDirector(this, this);
125.578 + applyInstrumentCustomization();
125.579 +
125.580 + }
125.581 + prevVoiceID = synthesizer.voiceIDCounter++;
125.582 + firstVoice = true;
125.583 + voiceNo = 0;
125.584 +
125.585 + int tunedKey = (int)(Math.round(tuning.getTuning()[noteNumber]/100.0));
125.586 + play_noteNumber = noteNumber;
125.587 + play_velocity = lastVelocity[noteNumber];
125.588 + play_releasetriggered = true;
125.589 + current_director.noteOff(tunedKey, velocity);
125.590 +
125.591 + }
125.592 + }
125.593 + private int[] lastVelocity = new int[128];
125.594 + private int prevVoiceID;
125.595 + private boolean firstVoice = true;
125.596 + private int voiceNo = 0;
125.597 + private int play_noteNumber = 0;
125.598 + private int play_velocity = 0;
125.599 + private boolean play_releasetriggered = false;
125.600 +
125.601 + public void play(int performerIndex, ModelConnectionBlock[] connectionBlocks) {
125.602 +
125.603 + int noteNumber = play_noteNumber;
125.604 + int velocity = play_velocity;
125.605 + boolean releasetriggered = play_releasetriggered;
125.606 +
125.607 + SoftPerformer p = current_instrument.getPerformers()[performerIndex];
125.608 +
125.609 + if (firstVoice) {
125.610 + firstVoice = false;
125.611 + if (p.exclusiveClass != 0) {
125.612 + int x = p.exclusiveClass;
125.613 + for (int j = 0; j < voices.length; j++) {
125.614 + if (voices[j].active && voices[j].channel == channel
125.615 + && voices[j].exclusiveClass == x) {
125.616 + if (!(p.selfNonExclusive && voices[j].note == noteNumber))
125.617 + voices[j].shutdown();
125.618 + }
125.619 + }
125.620 + }
125.621 + }
125.622 +
125.623 + voiceNo = findFreeVoice(voiceNo);
125.624 +
125.625 + if (voiceNo == -1)
125.626 + return;
125.627 +
125.628 + initVoice(voices[voiceNo], p, prevVoiceID, noteNumber, velocity,
125.629 + connectionBlocks, current_mixer, releasetriggered);
125.630 + }
125.631 +
125.632 + public void noteOff(int noteNumber) {
125.633 + if(noteNumber < 0 || noteNumber > 127) return;
125.634 + noteOff_internal(noteNumber, 64);
125.635 + }
125.636 +
125.637 + public void setPolyPressure(int noteNumber, int pressure) {
125.638 + noteNumber = restrict7Bit(noteNumber);
125.639 + pressure = restrict7Bit(pressure);
125.640 +
125.641 + if (current_mixer != null)
125.642 + current_mixer.setPolyPressure(noteNumber, pressure);
125.643 +
125.644 + synchronized (control_mutex) {
125.645 + mainmixer.activity();
125.646 + co_midi[noteNumber].get(0, "poly_pressure")[0] = pressure*(1.0/128.0);
125.647 + polypressure[noteNumber] = pressure;
125.648 + for (int i = 0; i < voices.length; i++) {
125.649 + if (voices[i].active && voices[i].note == noteNumber)
125.650 + voices[i].setPolyPressure(pressure);
125.651 + }
125.652 + }
125.653 + }
125.654 +
125.655 + public int getPolyPressure(int noteNumber) {
125.656 + synchronized (control_mutex) {
125.657 + return polypressure[noteNumber];
125.658 + }
125.659 + }
125.660 +
125.661 + public void setChannelPressure(int pressure) {
125.662 + pressure = restrict7Bit(pressure);
125.663 + if (current_mixer != null)
125.664 + current_mixer.setChannelPressure(pressure);
125.665 + synchronized (control_mutex) {
125.666 + mainmixer.activity();
125.667 + co_midi_channel_pressure[0] = pressure * (1.0 / 128.0);
125.668 + channelpressure = pressure;
125.669 + for (int i = 0; i < voices.length; i++) {
125.670 + if (voices[i].active)
125.671 + voices[i].setChannelPressure(pressure);
125.672 + }
125.673 + }
125.674 + }
125.675 +
125.676 + public int getChannelPressure() {
125.677 + synchronized (control_mutex) {
125.678 + return channelpressure;
125.679 + }
125.680 + }
125.681 +
125.682 + protected void applyInstrumentCustomization() {
125.683 + if (cds_control_connections == null
125.684 + && cds_channelpressure_connections == null
125.685 + && cds_polypressure_connections == null) {
125.686 + return;
125.687 + }
125.688 +
125.689 + ModelInstrument src_instrument = current_instrument.getSourceInstrument();
125.690 + ModelPerformer[] performers = src_instrument.getPerformers();
125.691 + ModelPerformer[] new_performers = new ModelPerformer[performers.length];
125.692 + for (int i = 0; i < new_performers.length; i++) {
125.693 + ModelPerformer performer = performers[i];
125.694 + ModelPerformer new_performer = new ModelPerformer();
125.695 + new_performer.setName(performer.getName());
125.696 + new_performer.setExclusiveClass(performer.getExclusiveClass());
125.697 + new_performer.setKeyFrom(performer.getKeyFrom());
125.698 + new_performer.setKeyTo(performer.getKeyTo());
125.699 + new_performer.setVelFrom(performer.getVelFrom());
125.700 + new_performer.setVelTo(performer.getVelTo());
125.701 + new_performer.getOscillators().addAll(performer.getOscillators());
125.702 + new_performer.getConnectionBlocks().addAll(
125.703 + performer.getConnectionBlocks());
125.704 + new_performers[i] = new_performer;
125.705 +
125.706 + List<ModelConnectionBlock> connblocks =
125.707 + new_performer.getConnectionBlocks();
125.708 +
125.709 + if (cds_control_connections != null) {
125.710 + String cc = Integer.toString(cds_control_number);
125.711 + Iterator<ModelConnectionBlock> iter = connblocks.iterator();
125.712 + while (iter.hasNext()) {
125.713 + ModelConnectionBlock conn = iter.next();
125.714 + ModelSource[] sources = conn.getSources();
125.715 + boolean removeok = false;
125.716 + if (sources != null) {
125.717 + for (int j = 0; j < sources.length; j++) {
125.718 + ModelSource src = sources[j];
125.719 + if ("midi_cc".equals(src.getIdentifier().getObject())
125.720 + && cc.equals(src.getIdentifier().getVariable())) {
125.721 + removeok = true;
125.722 + }
125.723 + }
125.724 + }
125.725 + if (removeok)
125.726 + iter.remove();
125.727 + }
125.728 + for (int j = 0; j < cds_control_connections.length; j++)
125.729 + connblocks.add(cds_control_connections[j]);
125.730 + }
125.731 +
125.732 + if (cds_polypressure_connections != null) {
125.733 + Iterator<ModelConnectionBlock> iter = connblocks.iterator();
125.734 + while (iter.hasNext()) {
125.735 + ModelConnectionBlock conn = iter.next();
125.736 + ModelSource[] sources = conn.getSources();
125.737 + boolean removeok = false;
125.738 + if (sources != null) {
125.739 + for (int j = 0; j < sources.length; j++) {
125.740 + ModelSource src = sources[j];
125.741 + if ("midi".equals(src.getIdentifier().getObject())
125.742 + && "poly_pressure".equals(
125.743 + src.getIdentifier().getVariable())) {
125.744 + removeok = true;
125.745 + }
125.746 + }
125.747 + }
125.748 + if (removeok)
125.749 + iter.remove();
125.750 + }
125.751 + for (int j = 0; j < cds_polypressure_connections.length; j++)
125.752 + connblocks.add(cds_polypressure_connections[j]);
125.753 + }
125.754 +
125.755 +
125.756 + if (cds_channelpressure_connections != null) {
125.757 + Iterator<ModelConnectionBlock> iter = connblocks.iterator();
125.758 + while (iter.hasNext()) {
125.759 + ModelConnectionBlock conn = iter.next();
125.760 + ModelSource[] sources = conn.getSources();
125.761 + boolean removeok = false;
125.762 + if (sources != null) {
125.763 + for (int j = 0; j < sources.length; j++) {
125.764 + ModelIdentifier srcid = sources[j].getIdentifier();
125.765 + if ("midi".equals(srcid.getObject()) &&
125.766 + "channel_pressure".equals(srcid.getVariable())) {
125.767 + removeok = true;
125.768 + }
125.769 + }
125.770 + }
125.771 + if (removeok)
125.772 + iter.remove();
125.773 + }
125.774 + for (int j = 0; j < cds_channelpressure_connections.length; j++)
125.775 + connblocks.add(cds_channelpressure_connections[j]);
125.776 + }
125.777 +
125.778 + }
125.779 +
125.780 + current_instrument = new SoftInstrument(src_instrument, new_performers);
125.781 +
125.782 + }
125.783 +
125.784 + private ModelConnectionBlock[] createModelConnections(ModelIdentifier sid,
125.785 + int[] destination, int[] range) {
125.786 +
125.787 + /*
125.788 + controlled parameter (pp)|range (rr)| Description |Default
125.789 + -------------------------|----------|-------------------------|-------
125.790 + 00 Pitch Control | 28H..58H | -24..+24 semitones | 40H
125.791 + 01 Filter Cutoff Control | 00H..7FH | -9600..+9450 cents | 40H
125.792 + 02 Amplitude Control | 00H..7FH | 0..(127/64)*100 percent | 40H
125.793 + 03 LFO Pitch Depth | 00H..7FH | 0..600 cents | 0
125.794 + 04 LFO Filter Depth | 00H..7FH | 0..2400 cents | 0
125.795 + 05 LFO Amplitude Depth | 00H..7FH | 0..100 percent | 0
125.796 + */
125.797 +
125.798 + List<ModelConnectionBlock> conns = new ArrayList<ModelConnectionBlock>();
125.799 +
125.800 + for (int i = 0; i < destination.length; i++) {
125.801 + int d = destination[i];
125.802 + int r = range[i];
125.803 + if (d == 0) {
125.804 + double scale = (r - 64) * 100;
125.805 + ModelConnectionBlock conn = new ModelConnectionBlock(
125.806 + new ModelSource(sid,
125.807 + ModelStandardTransform.DIRECTION_MIN2MAX,
125.808 + ModelStandardTransform.POLARITY_UNIPOLAR,
125.809 + ModelStandardTransform.TRANSFORM_LINEAR),
125.810 + scale,
125.811 + new ModelDestination(
125.812 + new ModelIdentifier("osc", "pitch")));
125.813 + conns.add(conn);
125.814 +
125.815 + }
125.816 + if (d == 1) {
125.817 + double scale = (r / 64.0 - 1.0) * 9600.0;
125.818 + ModelConnectionBlock conn;
125.819 + if (scale > 0) {
125.820 + conn = new ModelConnectionBlock(
125.821 + new ModelSource(sid,
125.822 + ModelStandardTransform.DIRECTION_MAX2MIN,
125.823 + ModelStandardTransform.POLARITY_UNIPOLAR,
125.824 + ModelStandardTransform.TRANSFORM_LINEAR),
125.825 + -scale,
125.826 + new ModelDestination(
125.827 + ModelDestination.DESTINATION_FILTER_FREQ));
125.828 + } else {
125.829 + conn = new ModelConnectionBlock(
125.830 + new ModelSource(sid,
125.831 + ModelStandardTransform.DIRECTION_MIN2MAX,
125.832 + ModelStandardTransform.POLARITY_UNIPOLAR,
125.833 + ModelStandardTransform.TRANSFORM_LINEAR),
125.834 + scale,
125.835 + new ModelDestination(
125.836 + ModelDestination.DESTINATION_FILTER_FREQ));
125.837 + }
125.838 + conns.add(conn);
125.839 + }
125.840 + if (d == 2) {
125.841 + final double scale = (r / 64.0);
125.842 + ModelTransform mt = new ModelTransform() {
125.843 + double s = scale;
125.844 + public double transform(double value) {
125.845 + if (s < 1)
125.846 + value = s + (value * (1.0 - s));
125.847 + else if (s > 1)
125.848 + value = 1 + (value * (s - 1.0));
125.849 + else
125.850 + return 0;
125.851 + return -((5.0 / 12.0) / Math.log(10)) * Math.log(value);
125.852 + }
125.853 + };
125.854 +
125.855 + ModelConnectionBlock conn = new ModelConnectionBlock(
125.856 + new ModelSource(sid, mt), -960,
125.857 + new ModelDestination(ModelDestination.DESTINATION_GAIN));
125.858 + conns.add(conn);
125.859 +
125.860 + }
125.861 + if (d == 3) {
125.862 + double scale = (r / 64.0 - 1.0) * 9600.0;
125.863 + ModelConnectionBlock conn = new ModelConnectionBlock(
125.864 + new ModelSource(ModelSource.SOURCE_LFO1,
125.865 + ModelStandardTransform.DIRECTION_MIN2MAX,
125.866 + ModelStandardTransform.POLARITY_BIPOLAR,
125.867 + ModelStandardTransform.TRANSFORM_LINEAR),
125.868 + new ModelSource(sid,
125.869 + ModelStandardTransform.DIRECTION_MIN2MAX,
125.870 + ModelStandardTransform.POLARITY_UNIPOLAR,
125.871 + ModelStandardTransform.TRANSFORM_LINEAR),
125.872 + scale,
125.873 + new ModelDestination(
125.874 + ModelDestination.DESTINATION_PITCH));
125.875 + conns.add(conn);
125.876 + }
125.877 + if (d == 4) {
125.878 + double scale = (r / 128.0) * 2400.0;
125.879 + ModelConnectionBlock conn = new ModelConnectionBlock(
125.880 + new ModelSource(ModelSource.SOURCE_LFO1,
125.881 + ModelStandardTransform.DIRECTION_MIN2MAX,
125.882 + ModelStandardTransform.POLARITY_BIPOLAR,
125.883 + ModelStandardTransform.TRANSFORM_LINEAR),
125.884 + new ModelSource(sid,
125.885 + ModelStandardTransform.DIRECTION_MIN2MAX,
125.886 + ModelStandardTransform.POLARITY_UNIPOLAR,
125.887 + ModelStandardTransform.TRANSFORM_LINEAR),
125.888 + scale,
125.889 + new ModelDestination(
125.890 + ModelDestination.DESTINATION_FILTER_FREQ));
125.891 + conns.add(conn);
125.892 + }
125.893 + if (d == 5) {
125.894 + final double scale = (r / 127.0);
125.895 +
125.896 + ModelTransform mt = new ModelTransform() {
125.897 + double s = scale;
125.898 + public double transform(double value) {
125.899 + return -((5.0 / 12.0) / Math.log(10))
125.900 + * Math.log(1 - value * s);
125.901 + }
125.902 + };
125.903 +
125.904 + ModelConnectionBlock conn = new ModelConnectionBlock(
125.905 + new ModelSource(ModelSource.SOURCE_LFO1,
125.906 + ModelStandardTransform.DIRECTION_MIN2MAX,
125.907 + ModelStandardTransform.POLARITY_UNIPOLAR,
125.908 + ModelStandardTransform.TRANSFORM_LINEAR),
125.909 + new ModelSource(sid, mt),
125.910 + -960,
125.911 + new ModelDestination(
125.912 + ModelDestination.DESTINATION_GAIN));
125.913 + conns.add(conn);
125.914 + }
125.915 + }
125.916 +
125.917 + return conns.toArray(new ModelConnectionBlock[conns.size()]);
125.918 + }
125.919 +
125.920 + public void mapPolyPressureToDestination(int[] destination, int[] range) {
125.921 + current_instrument = null;
125.922 + if (destination.length == 0) {
125.923 + cds_polypressure_connections = null;
125.924 + return;
125.925 + }
125.926 + cds_polypressure_connections
125.927 + = createModelConnections(
125.928 + new ModelIdentifier("midi", "poly_pressure"),
125.929 + destination, range);
125.930 + }
125.931 +
125.932 + public void mapChannelPressureToDestination(int[] destination, int[] range) {
125.933 + current_instrument = null;
125.934 + if (destination.length == 0) {
125.935 + cds_channelpressure_connections = null;
125.936 + return;
125.937 + }
125.938 + cds_channelpressure_connections
125.939 + = createModelConnections(
125.940 + new ModelIdentifier("midi", "channel_pressure"),
125.941 + destination, range);
125.942 + }
125.943 +
125.944 + public void mapControlToDestination(int control, int[] destination, int[] range) {
125.945 +
125.946 + if (!((control >= 0x01 && control <= 0x1F)
125.947 + || (control >= 0x40 && control <= 0x5F))) {
125.948 + cds_control_connections = null;
125.949 + return;
125.950 + }
125.951 +
125.952 + current_instrument = null;
125.953 + cds_control_number = control;
125.954 + if (destination.length == 0) {
125.955 + cds_control_connections = null;
125.956 + return;
125.957 + }
125.958 + cds_control_connections
125.959 + = createModelConnections(
125.960 + new ModelIdentifier("midi_cc", Integer.toString(control)),
125.961 + destination, range);
125.962 + }
125.963 +
125.964 + public void controlChangePerNote(int noteNumber, int controller, int value) {
125.965 +
125.966 +/*
125.967 + CC# | nn | Name | vv | default | description
125.968 +-----|------|-------------------------|----------------|------------|-------------------------------
125.969 +7 |07H |Note Volume |00H-40H-7FH |40H |0-100-(127/64)*100(%)(Relative)
125.970 +10 |0AH |*Pan |00H-7FH absolute|Preset Value|Left-Center-Right (absolute)
125.971 +33-63|21-3FH|LSB for |01H-1FH | |
125.972 +71 |47H |Timbre/Harmonic Intensity|00H-40H-7FH |40H (???) |
125.973 +72 |48H |Release Time |00H-40H-7FH |40H (???) |
125.974 +73 |49H |Attack Time |00H-40H-7FH |40H (???) |
125.975 +74 |4AH |Brightness |00H-40H-7FH |40H (???) |
125.976 +75 |4BH |Decay Time |00H-40H-7FH |40H (???) |
125.977 +76 |4CH |Vibrato Rate |00H-40H-7FH |40H (???) |
125.978 +77 |4DH |Vibrato Depth |00H-40H-7FH |40H (???) |
125.979 +78 |4EH |Vibrato Delay |00H-40H-7FH |40H (???) |
125.980 +91 |5BH |*Reverb Send |00H-7FH absolute|Preset Value|Left-Center-Right (absolute)
125.981 +93 |5DH |*Chorus Send |00H-7FH absolute|Preset Value|Left-Center-Right (absolute)
125.982 +120 |78H |**Fine Tuning |00H-40H-7FH |40H (???) |
125.983 +121 |79H |**Coarse Tuning |00H-40H-7FH |40H (???) |
125.984 +*/
125.985 +
125.986 + if (keybasedcontroller_active == null) {
125.987 + keybasedcontroller_active = new boolean[128][];
125.988 + keybasedcontroller_value = new double[128][];
125.989 + }
125.990 + if (keybasedcontroller_active[noteNumber] == null) {
125.991 + keybasedcontroller_active[noteNumber] = new boolean[128];
125.992 + Arrays.fill(keybasedcontroller_active[noteNumber], false);
125.993 + keybasedcontroller_value[noteNumber] = new double[128];
125.994 + Arrays.fill(keybasedcontroller_value[noteNumber], 0);
125.995 + }
125.996 +
125.997 + if (value == -1) {
125.998 + keybasedcontroller_active[noteNumber][controller] = false;
125.999 + } else {
125.1000 + keybasedcontroller_active[noteNumber][controller] = true;
125.1001 + keybasedcontroller_value[noteNumber][controller] = value / 128.0;
125.1002 + }
125.1003 +
125.1004 + if (controller < 120) {
125.1005 + for (int i = 0; i < voices.length; i++)
125.1006 + if (voices[i].active)
125.1007 + voices[i].controlChange(controller, -1);
125.1008 + } else if (controller == 120) {
125.1009 + for (int i = 0; i < voices.length; i++)
125.1010 + if (voices[i].active)
125.1011 + voices[i].rpnChange(1, -1);
125.1012 + } else if (controller == 121) {
125.1013 + for (int i = 0; i < voices.length; i++)
125.1014 + if (voices[i].active)
125.1015 + voices[i].rpnChange(2, -1);
125.1016 + }
125.1017 +
125.1018 + }
125.1019 +
125.1020 + public int getControlPerNote(int noteNumber, int controller) {
125.1021 + if (keybasedcontroller_active == null)
125.1022 + return -1;
125.1023 + if (keybasedcontroller_active[noteNumber] == null)
125.1024 + return -1;
125.1025 + if (!keybasedcontroller_active[noteNumber][controller])
125.1026 + return -1;
125.1027 + return (int)(keybasedcontroller_value[noteNumber][controller] * 128);
125.1028 + }
125.1029 +
125.1030 + public void controlChange(int controller, int value) {
125.1031 + controller = restrict7Bit(controller);
125.1032 + value = restrict7Bit(value);
125.1033 + if (current_mixer != null)
125.1034 + current_mixer.controlChange(controller, value);
125.1035 +
125.1036 + synchronized (control_mutex) {
125.1037 + switch (controller) {
125.1038 + /*
125.1039 + Map<String, int[]>co_midi_rpn_rpn_i = new HashMap<String, int[]>();
125.1040 + Map<String, double[]>co_midi_rpn_rpn = new HashMap<String, double[]>();
125.1041 + Map<String, int[]>co_midi_nrpn_nrpn_i = new HashMap<String, int[]>();
125.1042 + Map<String, double[]>co_midi_nrpn_nrpn = new HashMap<String, double[]>();
125.1043 + */
125.1044 +
125.1045 + case 5:
125.1046 + // This produce asin-like curve
125.1047 + // as described in General Midi Level 2 Specification, page 6
125.1048 + double x = -Math.asin((value / 128.0) * 2 - 1) / Math.PI + 0.5;
125.1049 + x = Math.pow(100000.0, x) / 100.0; // x is now cent/msec
125.1050 + // Convert x from cent/msec to key/controlbuffertime
125.1051 + x = x / 100.0; // x is now keys/msec
125.1052 + x = x * 1000.0; // x is now keys/sec
125.1053 + x = x / synthesizer.getControlRate(); // x is now keys/controlbuffertime
125.1054 + portamento_time = x;
125.1055 + break;
125.1056 + case 6:
125.1057 + case 38:
125.1058 + case 96:
125.1059 + case 97:
125.1060 + int val = 0;
125.1061 + if (nrpn_control != RPN_NULL_VALUE) {
125.1062 + int[] val_i = co_midi_nrpn_nrpn_i.get(nrpn_control);
125.1063 + if (val_i != null)
125.1064 + val = val_i[0];
125.1065 + }
125.1066 + if (rpn_control != RPN_NULL_VALUE) {
125.1067 + int[] val_i = co_midi_rpn_rpn_i.get(rpn_control);
125.1068 + if (val_i != null)
125.1069 + val = val_i[0];
125.1070 + }
125.1071 +
125.1072 + if (controller == 6)
125.1073 + val = (val & 127) + (value << 7);
125.1074 + else if (controller == 38)
125.1075 + val = (val & (127 << 7)) + value;
125.1076 + else if (controller == 96 || controller == 97) {
125.1077 + int step = 1;
125.1078 + if (rpn_control == 2 || rpn_control == 3 || rpn_control == 4)
125.1079 + step = 128;
125.1080 + if (controller == 96)
125.1081 + val += step;
125.1082 + if (controller == 97)
125.1083 + val -= step;
125.1084 + }
125.1085 +
125.1086 + if (nrpn_control != RPN_NULL_VALUE)
125.1087 + nrpnChange(nrpn_control, val);
125.1088 + if (rpn_control != RPN_NULL_VALUE)
125.1089 + rpnChange(rpn_control, val);
125.1090 +
125.1091 + break;
125.1092 + case 64: // Hold1 (Damper) (cc#64)
125.1093 + boolean on = value >= 64;
125.1094 + if (sustain != on) {
125.1095 + sustain = on;
125.1096 + if (!on) {
125.1097 + for (int i = 0; i < voices.length; i++) {
125.1098 + if (voices[i].active && voices[i].sustain &&
125.1099 + voices[i].channel == channel) {
125.1100 + voices[i].sustain = false;
125.1101 + if (!voices[i].on) {
125.1102 + voices[i].on = true;
125.1103 + voices[i].noteOff(0);
125.1104 + }
125.1105 + }
125.1106 + }
125.1107 + } else {
125.1108 + for (int i = 0; i < voices.length; i++)
125.1109 + if (voices[i].active && voices[i].channel == channel)
125.1110 + voices[i].redamp();
125.1111 + }
125.1112 + }
125.1113 + break;
125.1114 + case 65:
125.1115 + //allNotesOff();
125.1116 + portamento = value >= 64;
125.1117 + portamento_lastnote[0] = -1;
125.1118 + /*
125.1119 + for (int i = 0; i < portamento_lastnote.length; i++)
125.1120 + portamento_lastnote[i] = -1;
125.1121 + */
125.1122 + portamento_lastnote_ix = 0;
125.1123 + break;
125.1124 + case 66: // Sostenuto (cc#66)
125.1125 + on = value >= 64;
125.1126 + if (on) {
125.1127 + for (int i = 0; i < voices.length; i++) {
125.1128 + if (voices[i].active && voices[i].on &&
125.1129 + voices[i].channel == channel) {
125.1130 + voices[i].sostenuto = true;
125.1131 + }
125.1132 + }
125.1133 + }
125.1134 + if (!on) {
125.1135 + for (int i = 0; i < voices.length; i++) {
125.1136 + if (voices[i].active && voices[i].sostenuto &&
125.1137 + voices[i].channel == channel) {
125.1138 + voices[i].sostenuto = false;
125.1139 + if (!voices[i].on) {
125.1140 + voices[i].on = true;
125.1141 + voices[i].noteOff(0);
125.1142 + }
125.1143 + }
125.1144 + }
125.1145 + }
125.1146 + break;
125.1147 + case 84:
125.1148 + portamento_control_note = value;
125.1149 + break;
125.1150 + case 98:
125.1151 + nrpn_control = (nrpn_control & (127 << 7)) + value;
125.1152 + rpn_control = RPN_NULL_VALUE;
125.1153 + break;
125.1154 + case 99:
125.1155 + nrpn_control = (nrpn_control & 127) + (value << 7);
125.1156 + rpn_control = RPN_NULL_VALUE;
125.1157 + break;
125.1158 + case 100:
125.1159 + rpn_control = (rpn_control & (127 << 7)) + value;
125.1160 + nrpn_control = RPN_NULL_VALUE;
125.1161 + break;
125.1162 + case 101:
125.1163 + rpn_control = (rpn_control & 127) + (value << 7);
125.1164 + nrpn_control = RPN_NULL_VALUE;
125.1165 + break;
125.1166 + case 120:
125.1167 + allSoundOff();
125.1168 + break;
125.1169 + case 121:
125.1170 + resetAllControllers(value == 127);
125.1171 + break;
125.1172 + case 122:
125.1173 + localControl(value >= 64);
125.1174 + break;
125.1175 + case 123:
125.1176 + allNotesOff();
125.1177 + break;
125.1178 + case 124:
125.1179 + setOmni(false);
125.1180 + break;
125.1181 + case 125:
125.1182 + setOmni(true);
125.1183 + break;
125.1184 + case 126:
125.1185 + if (value == 1)
125.1186 + setMono(true);
125.1187 + break;
125.1188 + case 127:
125.1189 + setMono(false);
125.1190 + break;
125.1191 +
125.1192 + default:
125.1193 + break;
125.1194 + }
125.1195 +
125.1196 + co_midi_cc_cc[controller][0] = value * (1.0 / 128.0);
125.1197 +
125.1198 + if (controller == 0x00) {
125.1199 + bank = /*(bank & 127) +*/ (value << 7);
125.1200 + return;
125.1201 + }
125.1202 +
125.1203 + if (controller == 0x20) {
125.1204 + bank = (bank & (127 << 7)) + value;
125.1205 + return;
125.1206 + }
125.1207 +
125.1208 + this.controller[controller] = value;
125.1209 + if(controller < 0x20)
125.1210 + this.controller[controller + 0x20] = 0;
125.1211 +
125.1212 + for (int i = 0; i < voices.length; i++)
125.1213 + if (voices[i].active)
125.1214 + voices[i].controlChange(controller, value);
125.1215 +
125.1216 + }
125.1217 + }
125.1218 +
125.1219 + public int getController(int controller) {
125.1220 + synchronized (control_mutex) {
125.1221 + // Should only return lower 7 bits,
125.1222 + // even when controller is "boosted" higher.
125.1223 + return this.controller[controller] & 127;
125.1224 + }
125.1225 + }
125.1226 +
125.1227 + public void tuningChange(int program) {
125.1228 + tuningChange(0, program);
125.1229 + }
125.1230 +
125.1231 + public void tuningChange(int bank, int program) {
125.1232 + synchronized (control_mutex) {
125.1233 + tuning = synthesizer.getTuning(new Patch(bank, program));
125.1234 + }
125.1235 + }
125.1236 +
125.1237 + public void programChange(int program) {
125.1238 + programChange(bank, program);
125.1239 + }
125.1240 +
125.1241 + public void programChange(int bank, int program) {
125.1242 + bank = restrict7Bit(bank);
125.1243 + program = restrict7Bit(program);
125.1244 + synchronized (control_mutex) {
125.1245 + mainmixer.activity();
125.1246 + this.bank = bank;
125.1247 + this.program = program;
125.1248 + current_instrument = null;
125.1249 + }
125.1250 + }
125.1251 +
125.1252 + public int getProgram() {
125.1253 + synchronized (control_mutex) {
125.1254 + return program;
125.1255 + }
125.1256 + }
125.1257 +
125.1258 + public void setPitchBend(int bend) {
125.1259 + bend = restrict14Bit(bend);
125.1260 + if (current_mixer != null)
125.1261 + current_mixer.setPitchBend(bend);
125.1262 + synchronized (control_mutex) {
125.1263 + mainmixer.activity();
125.1264 + co_midi_pitch[0] = bend * (1.0 / 16384.0);
125.1265 + pitchbend = bend;
125.1266 + for (int i = 0; i < voices.length; i++)
125.1267 + if (voices[i].active)
125.1268 + voices[i].setPitchBend(bend);
125.1269 + }
125.1270 + }
125.1271 +
125.1272 + public int getPitchBend() {
125.1273 + synchronized (control_mutex) {
125.1274 + return pitchbend;
125.1275 + }
125.1276 + }
125.1277 +
125.1278 + public void nrpnChange(int controller, int value) {
125.1279 +
125.1280 + /*
125.1281 + System.out.println("(" + channel + ").nrpnChange("
125.1282 + + Integer.toHexString(controller >> 7)
125.1283 + + " " + Integer.toHexString(controller & 127)
125.1284 + + ", " + Integer.toHexString(value >> 7)
125.1285 + + " " + Integer.toHexString(value & 127) + ")");
125.1286 + */
125.1287 +
125.1288 + if (synthesizer.getGeneralMidiMode() == 0) {
125.1289 + if (controller == (0x01 << 7) + (0x08)) // Vibrato Rate
125.1290 + controlChange(76, value >> 7);
125.1291 + if (controller == (0x01 << 7) + (0x09)) // Vibrato Depth
125.1292 + controlChange(77, value >> 7);
125.1293 + if (controller == (0x01 << 7) + (0x0A)) // Vibrato Delay
125.1294 + controlChange(78, value >> 7);
125.1295 + if (controller == (0x01 << 7) + (0x20)) // Brightness
125.1296 + controlChange(74, value >> 7);
125.1297 + if (controller == (0x01 << 7) + (0x21)) // Filter Resonance
125.1298 + controlChange(71, value >> 7);
125.1299 + if (controller == (0x01 << 7) + (0x63)) // Attack Time
125.1300 + controlChange(73, value >> 7);
125.1301 + if (controller == (0x01 << 7) + (0x64)) // Decay Time
125.1302 + controlChange(75, value >> 7);
125.1303 + if (controller == (0x01 << 7) + (0x66)) // Release Time
125.1304 + controlChange(72, value >> 7);
125.1305 +
125.1306 + if (controller >> 7 == 0x18) // Pitch coarse
125.1307 + controlChangePerNote(controller % 128, 120, value >> 7);
125.1308 + if (controller >> 7 == 0x1A) // Volume
125.1309 + controlChangePerNote(controller % 128, 7, value >> 7);
125.1310 + if (controller >> 7 == 0x1C) // Panpot
125.1311 + controlChangePerNote(controller % 128, 10, value >> 7);
125.1312 + if (controller >> 7 == 0x1D) // Reverb
125.1313 + controlChangePerNote(controller % 128, 91, value >> 7);
125.1314 + if (controller >> 7 == 0x1E) // Chorus
125.1315 + controlChangePerNote(controller % 128, 93, value >> 7);
125.1316 + }
125.1317 +
125.1318 + int[] val_i = co_midi_nrpn_nrpn_i.get(controller);
125.1319 + double[] val_d = co_midi_nrpn_nrpn.get(controller);
125.1320 + if (val_i == null) {
125.1321 + val_i = new int[1];
125.1322 + co_midi_nrpn_nrpn_i.put(controller, val_i);
125.1323 + }
125.1324 + if (val_d == null) {
125.1325 + val_d = new double[1];
125.1326 + co_midi_nrpn_nrpn.put(controller, val_d);
125.1327 + }
125.1328 + val_i[0] = value;
125.1329 + val_d[0] = val_i[0] * (1.0 / 16384.0);
125.1330 +
125.1331 + for (int i = 0; i < voices.length; i++)
125.1332 + if (voices[i].active)
125.1333 + voices[i].nrpnChange(controller, val_i[0]);
125.1334 +
125.1335 + }
125.1336 +
125.1337 + public void rpnChange(int controller, int value) {
125.1338 +
125.1339 + /*
125.1340 + System.out.println("(" + channel + ").rpnChange("
125.1341 + + Integer.toHexString(controller >> 7)
125.1342 + + " " + Integer.toHexString(controller & 127)
125.1343 + + ", " + Integer.toHexString(value >> 7)
125.1344 + + " " + Integer.toHexString(value & 127) + ")");
125.1345 + */
125.1346 +
125.1347 + if (controller == 3) {
125.1348 + tuning_program = (value >> 7) & 127;
125.1349 + tuningChange(tuning_bank, tuning_program);
125.1350 + }
125.1351 + if (controller == 4) {
125.1352 + tuning_bank = (value >> 7) & 127;
125.1353 + }
125.1354 +
125.1355 + int[] val_i = co_midi_rpn_rpn_i.get(controller);
125.1356 + double[] val_d = co_midi_rpn_rpn.get(controller);
125.1357 + if (val_i == null) {
125.1358 + val_i = new int[1];
125.1359 + co_midi_rpn_rpn_i.put(controller, val_i);
125.1360 + }
125.1361 + if (val_d == null) {
125.1362 + val_d = new double[1];
125.1363 + co_midi_rpn_rpn.put(controller, val_d);
125.1364 + }
125.1365 + val_i[0] = value;
125.1366 + val_d[0] = val_i[0] * (1.0 / 16384.0);
125.1367 +
125.1368 + for (int i = 0; i < voices.length; i++)
125.1369 + if (voices[i].active)
125.1370 + voices[i].rpnChange(controller, val_i[0]);
125.1371 + }
125.1372 +
125.1373 + public void resetAllControllers() {
125.1374 + resetAllControllers(false);
125.1375 + }
125.1376 +
125.1377 + public void resetAllControllers(boolean allControls) {
125.1378 + synchronized (control_mutex) {
125.1379 + mainmixer.activity();
125.1380 +
125.1381 + for (int i = 0; i < 128; i++) {
125.1382 + setPolyPressure(i, 0);
125.1383 + }
125.1384 + setChannelPressure(0);
125.1385 + setPitchBend(8192);
125.1386 + for (int i = 0; i < 128; i++) {
125.1387 + if (!dontResetControls[i])
125.1388 + controlChange(i, 0);
125.1389 + }
125.1390 +
125.1391 + controlChange(71, 64); // Filter Resonance
125.1392 + controlChange(72, 64); // Release Time
125.1393 + controlChange(73, 64); // Attack Time
125.1394 + controlChange(74, 64); // Brightness
125.1395 + controlChange(75, 64); // Decay Time
125.1396 + controlChange(76, 64); // Vibrato Rate
125.1397 + controlChange(77, 64); // Vibrato Depth
125.1398 + controlChange(78, 64); // Vibrato Delay
125.1399 +
125.1400 + controlChange(8, 64); // Balance
125.1401 + controlChange(11, 127); // Expression
125.1402 + controlChange(98, 127); // NRPN Null
125.1403 + controlChange(99, 127); // NRPN Null
125.1404 + controlChange(100, 127); // RPN = Null
125.1405 + controlChange(101, 127); // RPN = Null
125.1406 +
125.1407 + // see DLS 2.1 (Power-on Default Values)
125.1408 + if (allControls) {
125.1409 +
125.1410 + keybasedcontroller_active = null;
125.1411 + keybasedcontroller_value = null;
125.1412 +
125.1413 + controlChange(7, 100); // Volume
125.1414 + controlChange(10, 64); // Pan
125.1415 + controlChange(91, 40); // Reverb
125.1416 +
125.1417 + for (int controller : co_midi_rpn_rpn.keySet()) {
125.1418 + // don't reset tuning settings
125.1419 + if (controller != 3 && controller != 4)
125.1420 + rpnChange(controller, 0);
125.1421 + }
125.1422 + for (int controller : co_midi_nrpn_nrpn.keySet())
125.1423 + nrpnChange(controller, 0);
125.1424 + rpnChange(0, 2 << 7); // Bitch Bend sensitivity
125.1425 + rpnChange(1, 64 << 7); // Channel fine tunning
125.1426 + rpnChange(2, 64 << 7); // Channel Coarse Tuning
125.1427 + rpnChange(5, 64); // Modulation Depth, +/- 50 cent
125.1428 +
125.1429 + tuning_bank = 0;
125.1430 + tuning_program = 0;
125.1431 + tuning = new SoftTuning();
125.1432 +
125.1433 + }
125.1434 +
125.1435 + }
125.1436 + }
125.1437 +
125.1438 + public void allNotesOff() {
125.1439 + if (current_mixer != null)
125.1440 + current_mixer.allNotesOff();
125.1441 + synchronized (control_mutex) {
125.1442 + for (int i = 0; i < voices.length; i++)
125.1443 + if (voices[i].on && voices[i].channel == channel
125.1444 + && voices[i].releaseTriggered == false) {
125.1445 + voices[i].noteOff(0);
125.1446 + }
125.1447 + }
125.1448 + }
125.1449 +
125.1450 + public void allSoundOff() {
125.1451 + if (current_mixer != null)
125.1452 + current_mixer.allSoundOff();
125.1453 + synchronized (control_mutex) {
125.1454 + for (int i = 0; i < voices.length; i++)
125.1455 + if (voices[i].on && voices[i].channel == channel)
125.1456 + voices[i].soundOff();
125.1457 + }
125.1458 + }
125.1459 +
125.1460 + public boolean localControl(boolean on) {
125.1461 + return false;
125.1462 + }
125.1463 +
125.1464 + public void setMono(boolean on) {
125.1465 + if (current_mixer != null)
125.1466 + current_mixer.setMono(on);
125.1467 + synchronized (control_mutex) {
125.1468 + allNotesOff();
125.1469 + mono = on;
125.1470 + }
125.1471 + }
125.1472 +
125.1473 + public boolean getMono() {
125.1474 + synchronized (control_mutex) {
125.1475 + return mono;
125.1476 + }
125.1477 + }
125.1478 +
125.1479 + public void setOmni(boolean on) {
125.1480 + if (current_mixer != null)
125.1481 + current_mixer.setOmni(on);
125.1482 + allNotesOff();
125.1483 + // Omni is not supported by GM2
125.1484 + }
125.1485 +
125.1486 + public boolean getOmni() {
125.1487 + return false;
125.1488 + }
125.1489 +
125.1490 + public void setMute(boolean mute) {
125.1491 + if (current_mixer != null)
125.1492 + current_mixer.setMute(mute);
125.1493 + synchronized (control_mutex) {
125.1494 + this.mute = mute;
125.1495 + for (int i = 0; i < voices.length; i++)
125.1496 + if (voices[i].active && voices[i].channel == channel)
125.1497 + voices[i].setMute(mute);
125.1498 + }
125.1499 + }
125.1500 +
125.1501 + public boolean getMute() {
125.1502 + synchronized (control_mutex) {
125.1503 + return mute;
125.1504 + }
125.1505 + }
125.1506 +
125.1507 + public void setSolo(boolean soloState) {
125.1508 + if (current_mixer != null)
125.1509 + current_mixer.setSolo(soloState);
125.1510 +
125.1511 + synchronized (control_mutex) {
125.1512 + this.solo = soloState;
125.1513 +
125.1514 + boolean soloinuse = false;
125.1515 + for (SoftChannel c : synthesizer.channels) {
125.1516 + if (c.solo) {
125.1517 + soloinuse = true;
125.1518 + break;
125.1519 + }
125.1520 + }
125.1521 +
125.1522 + if (!soloinuse) {
125.1523 + for (SoftChannel c : synthesizer.channels)
125.1524 + c.setSoloMute(false);
125.1525 + return;
125.1526 + }
125.1527 +
125.1528 + for (SoftChannel c : synthesizer.channels)
125.1529 + c.setSoloMute(!c.solo);
125.1530 +
125.1531 + }
125.1532 +
125.1533 + }
125.1534 +
125.1535 + private void setSoloMute(boolean mute) {
125.1536 + synchronized (control_mutex) {
125.1537 + if (solomute == mute)
125.1538 + return;
125.1539 + this.solomute = mute;
125.1540 + for (int i = 0; i < voices.length; i++)
125.1541 + if (voices[i].active && voices[i].channel == channel)
125.1542 + voices[i].setSoloMute(solomute);
125.1543 + }
125.1544 + }
125.1545 +
125.1546 + public boolean getSolo() {
125.1547 + synchronized (control_mutex) {
125.1548 + return solo;
125.1549 + }
125.1550 + }
125.1551 +}
126.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
126.2 +++ b/src/share/classes/com/sun/media/sound/SoftChannelProxy.java Tue Feb 03 22:02:55 2009 -0800
126.3 @@ -0,0 +1,202 @@
126.4 +/*
126.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
126.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
126.7 + *
126.8 + * This code is free software; you can redistribute it and/or modify it
126.9 + * under the terms of the GNU General Public License version 2 only, as
126.10 + * published by the Free Software Foundation. Sun designates this
126.11 + * particular file as subject to the "Classpath" exception as provided
126.12 + * by Sun in the LICENSE file that accompanied this code.
126.13 + *
126.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
126.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
126.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
126.17 + * version 2 for more details (a copy is included in the LICENSE file that
126.18 + * accompanied this code).
126.19 + *
126.20 + * You should have received a copy of the GNU General Public License version
126.21 + * 2 along with this work; if not, write to the Free Software Foundation,
126.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
126.23 + *
126.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
126.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
126.26 + * have any questions.
126.27 + */
126.28 +package com.sun.media.sound;
126.29 +
126.30 +import javax.sound.midi.MidiChannel;
126.31 +
126.32 +/**
126.33 + * A MidiChannel proxy object used for external access to synthesizer internal
126.34 + * channel objects.
126.35 + *
126.36 + * @author Karl Helgason
126.37 + */
126.38 +public class SoftChannelProxy implements MidiChannel {
126.39 +
126.40 + private MidiChannel channel = null;
126.41 +
126.42 + public MidiChannel getChannel() {
126.43 + return channel;
126.44 + }
126.45 +
126.46 + public void setChannel(MidiChannel channel) {
126.47 + this.channel = channel;
126.48 + }
126.49 +
126.50 + public void allNotesOff() {
126.51 + if (channel == null)
126.52 + return;
126.53 + channel.allNotesOff();
126.54 + }
126.55 +
126.56 + public void allSoundOff() {
126.57 + if (channel == null)
126.58 + return;
126.59 + channel.allSoundOff();
126.60 + }
126.61 +
126.62 + public void controlChange(int controller, int value) {
126.63 + if (channel == null)
126.64 + return;
126.65 + channel.controlChange(controller, value);
126.66 + }
126.67 +
126.68 + public int getChannelPressure() {
126.69 + if (channel == null)
126.70 + return 0;
126.71 + return channel.getChannelPressure();
126.72 + }
126.73 +
126.74 + public int getController(int controller) {
126.75 + if (channel == null)
126.76 + return 0;
126.77 + return channel.getController(controller);
126.78 + }
126.79 +
126.80 + public boolean getMono() {
126.81 + if (channel == null)
126.82 + return false;
126.83 + return channel.getMono();
126.84 + }
126.85 +
126.86 + public boolean getMute() {
126.87 + if (channel == null)
126.88 + return false;
126.89 + return channel.getMute();
126.90 + }
126.91 +
126.92 + public boolean getOmni() {
126.93 + if (channel == null)
126.94 + return false;
126.95 + return channel.getOmni();
126.96 + }
126.97 +
126.98 + public int getPitchBend() {
126.99 + if (channel == null)
126.100 + return 8192;
126.101 + return channel.getPitchBend();
126.102 + }
126.103 +
126.104 + public int getPolyPressure(int noteNumber) {
126.105 + if (channel == null)
126.106 + return 0;
126.107 + return channel.getPolyPressure(noteNumber);
126.108 + }
126.109 +
126.110 + public int getProgram() {
126.111 + if (channel == null)
126.112 + return 0;
126.113 + return channel.getProgram();
126.114 + }
126.115 +
126.116 + public boolean getSolo() {
126.117 + if (channel == null)
126.118 + return false;
126.119 + return channel.getSolo();
126.120 + }
126.121 +
126.122 + public boolean localControl(boolean on) {
126.123 + if (channel == null)
126.124 + return false;
126.125 + return channel.localControl(on);
126.126 + }
126.127 +
126.128 + public void noteOff(int noteNumber) {
126.129 + if (channel == null)
126.130 + return;
126.131 + channel.noteOff(noteNumber);
126.132 + }
126.133 +
126.134 + public void noteOff(int noteNumber, int velocity) {
126.135 + if (channel == null)
126.136 + return;
126.137 + channel.noteOff(noteNumber, velocity);
126.138 + }
126.139 +
126.140 + public void noteOn(int noteNumber, int velocity) {
126.141 + if (channel == null)
126.142 + return;
126.143 + channel.noteOn(noteNumber, velocity);
126.144 + }
126.145 +
126.146 + public void programChange(int program) {
126.147 + if (channel == null)
126.148 + return;
126.149 + channel.programChange(program);
126.150 + }
126.151 +
126.152 + public void programChange(int bank, int program) {
126.153 + if (channel == null)
126.154 + return;
126.155 + channel.programChange(bank, program);
126.156 + }
126.157 +
126.158 + public void resetAllControllers() {
126.159 + if (channel == null)
126.160 + return;
126.161 + channel.resetAllControllers();
126.162 + }
126.163 +
126.164 + public void setChannelPressure(int pressure) {
126.165 + if (channel == null)
126.166 + return;
126.167 + channel.setChannelPressure(pressure);
126.168 + }
126.169 +
126.170 + public void setMono(boolean on) {
126.171 + if (channel == null)
126.172 + return;
126.173 + channel.setMono(on);
126.174 + }
126.175 +
126.176 + public void setMute(boolean mute) {
126.177 + if (channel == null)
126.178 + return;
126.179 + channel.setMute(mute);
126.180 + }
126.181 +
126.182 + public void setOmni(boolean on) {
126.183 + if (channel == null)
126.184 + return;
126.185 + channel.setOmni(on);
126.186 + }
126.187 +
126.188 + public void setPitchBend(int bend) {
126.189 + if (channel == null)
126.190 + return;
126.191 + channel.setPitchBend(bend);
126.192 + }
126.193 +
126.194 + public void setPolyPressure(int noteNumber, int pressure) {
126.195 + if (channel == null)
126.196 + return;
126.197 + channel.setPolyPressure(noteNumber, pressure);
126.198 + }
126.199 +
126.200 + public void setSolo(boolean soloState) {
126.201 + if (channel == null)
126.202 + return;
126.203 + channel.setSolo(soloState);
126.204 + }
126.205 +}
127.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
127.2 +++ b/src/share/classes/com/sun/media/sound/SoftChorus.java Tue Feb 03 22:02:55 2009 -0800
127.3 @@ -0,0 +1,341 @@
127.4 +/*
127.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
127.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
127.7 + *
127.8 + * This code is free software; you can redistribute it and/or modify it
127.9 + * under the terms of the GNU General Public License version 2 only, as
127.10 + * published by the Free Software Foundation. Sun designates this
127.11 + * particular file as subject to the "Classpath" exception as provided
127.12 + * by Sun in the LICENSE file that accompanied this code.
127.13 + *
127.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
127.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
127.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
127.17 + * version 2 for more details (a copy is included in the LICENSE file that
127.18 + * accompanied this code).
127.19 + *
127.20 + * You should have received a copy of the GNU General Public License version
127.21 + * 2 along with this work; if not, write to the Free Software Foundation,
127.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
127.23 + *
127.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
127.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
127.26 + * have any questions.
127.27 + */
127.28 +package com.sun.media.sound;
127.29 +
127.30 +import java.util.Arrays;
127.31 +
127.32 +/**
127.33 + * A chorus effect made using LFO and variable delay. One for each channel
127.34 + * (left,right), with different starting phase for stereo effect.
127.35 + *
127.36 + * @author Karl Helgason
127.37 + */
127.38 +public class SoftChorus implements SoftAudioProcessor {
127.39 +
127.40 + private static class VariableDelay {
127.41 +
127.42 + private float[] delaybuffer;
127.43 + private int rovepos = 0;
127.44 + private volatile float gain = 1;
127.45 + private volatile float rgain = 0;
127.46 + private volatile float delay = 0;
127.47 + private float lastdelay = 0;
127.48 + private volatile float feedback = 0;
127.49 +
127.50 + public VariableDelay(int maxbuffersize) {
127.51 + delaybuffer = new float[maxbuffersize];
127.52 + }
127.53 +
127.54 + public void setDelay(float delay) {
127.55 + this.delay = delay;
127.56 + }
127.57 +
127.58 + public void setFeedBack(float feedback) {
127.59 + this.feedback = feedback;
127.60 + }
127.61 +
127.62 + public void setGain(float gain) {
127.63 + this.gain = gain;
127.64 + }
127.65 +
127.66 + public void setReverbSendGain(float rgain) {
127.67 + this.rgain = rgain;
127.68 + }
127.69 +
127.70 + public void processMix(float[] in, float[] out, float[] rout) {
127.71 + float gain = this.gain;
127.72 + float delay = this.delay;
127.73 + float feedback = this.feedback;
127.74 +
127.75 + float[] delaybuffer = this.delaybuffer;
127.76 + int len = in.length;
127.77 + float delaydelta = (delay - lastdelay) / len;
127.78 + int rnlen = delaybuffer.length;
127.79 + int rovepos = this.rovepos;
127.80 +
127.81 + if (rout == null)
127.82 + for (int i = 0; i < len; i++) {
127.83 + float r = rovepos - (lastdelay + 2) + rnlen;
127.84 + int ri = (int) r;
127.85 + float s = r - ri;
127.86 + float a = delaybuffer[ri % rnlen];
127.87 + float b = delaybuffer[(ri + 1) % rnlen];
127.88 + float o = a * (1 - s) + b * (s);
127.89 + out[i] += o * gain;
127.90 + delaybuffer[rovepos] = in[i] + o * feedback;
127.91 + rovepos = (rovepos + 1) % rnlen;
127.92 + lastdelay += delaydelta;
127.93 + }
127.94 + else
127.95 + for (int i = 0; i < len; i++) {
127.96 + float r = rovepos - (lastdelay + 2) + rnlen;
127.97 + int ri = (int) r;
127.98 + float s = r - ri;
127.99 + float a = delaybuffer[ri % rnlen];
127.100 + float b = delaybuffer[(ri + 1) % rnlen];
127.101 + float o = a * (1 - s) + b * (s);
127.102 + out[i] += o * gain;
127.103 + rout[i] += o * rgain;
127.104 + delaybuffer[rovepos] = in[i] + o * feedback;
127.105 + rovepos = (rovepos + 1) % rnlen;
127.106 + lastdelay += delaydelta;
127.107 + }
127.108 + this.rovepos = rovepos;
127.109 + lastdelay = delay;
127.110 + }
127.111 +
127.112 + public void processReplace(float[] in, float[] out, float[] rout) {
127.113 + Arrays.fill(out, 0);
127.114 + Arrays.fill(rout, 0);
127.115 + processMix(in, out, rout);
127.116 + }
127.117 + }
127.118 +
127.119 + private static class LFODelay {
127.120 +
127.121 + private volatile double c_cos_delta;
127.122 + private volatile double c_sin_delta;
127.123 + private double c_cos = 1;
127.124 + private double c_sin = 0;
127.125 + private double depth = 0;
127.126 + private VariableDelay vdelay;
127.127 + private double samplerate;
127.128 + private double controlrate;
127.129 +
127.130 + public LFODelay(double samplerate, double controlrate) {
127.131 + this.samplerate = samplerate;
127.132 + this.controlrate = controlrate;
127.133 + // vdelay = new VariableDelay((int)(samplerate*4));
127.134 + vdelay = new VariableDelay((int) ((this.depth + 10) * 2));
127.135 +
127.136 + }
127.137 +
127.138 + public void setDepth(double depth) {
127.139 + this.depth = depth * samplerate;
127.140 + vdelay = new VariableDelay((int) ((this.depth + 10) * 2));
127.141 + }
127.142 +
127.143 + public void setRate(double rate) {
127.144 + double g = (Math.PI * 2) * (rate / controlrate);
127.145 + c_cos_delta = Math.cos(g);
127.146 + c_sin_delta = Math.sin(g);
127.147 + }
127.148 +
127.149 + public void setPhase(double phase) {
127.150 + c_cos = Math.cos(phase);
127.151 + c_sin = Math.sin(phase);
127.152 + }
127.153 +
127.154 + public void setFeedBack(float feedback) {
127.155 + vdelay.setFeedBack(feedback);
127.156 + }
127.157 +
127.158 + public void setGain(float gain) {
127.159 + vdelay.setGain(gain);
127.160 + }
127.161 +
127.162 + public void setReverbSendGain(float rgain) {
127.163 + vdelay.setReverbSendGain(rgain);
127.164 + }
127.165 +
127.166 + public void processMix(float[] in, float[] out, float[] rout) {
127.167 + c_cos = c_cos * c_cos_delta - c_sin * c_sin_delta;
127.168 + c_sin = c_cos * c_sin_delta + c_sin * c_cos_delta;
127.169 + vdelay.setDelay((float) (depth * 0.5 * (c_cos + 2)));
127.170 + vdelay.processMix(in, out, rout);
127.171 + }
127.172 +
127.173 + public void processReplace(float[] in, float[] out, float[] rout) {
127.174 + c_cos = c_cos * c_cos_delta - c_sin * c_sin_delta;
127.175 + c_sin = c_cos * c_sin_delta + c_sin * c_cos_delta;
127.176 + vdelay.setDelay((float) (depth * 0.5 * (c_cos + 2)));
127.177 + vdelay.processReplace(in, out, rout);
127.178 +
127.179 + }
127.180 + }
127.181 + private boolean mix = true;
127.182 + private SoftAudioBuffer inputA;
127.183 + private SoftAudioBuffer left;
127.184 + private SoftAudioBuffer right;
127.185 + private SoftAudioBuffer reverb;
127.186 + private LFODelay vdelay1L;
127.187 + private LFODelay vdelay1R;
127.188 + private float rgain = 0;
127.189 + private boolean dirty = true;
127.190 + private double dirty_vdelay1L_rate;
127.191 + private double dirty_vdelay1R_rate;
127.192 + private double dirty_vdelay1L_depth;
127.193 + private double dirty_vdelay1R_depth;
127.194 + private float dirty_vdelay1L_feedback;
127.195 + private float dirty_vdelay1R_feedback;
127.196 + private float dirty_vdelay1L_reverbsendgain;
127.197 + private float dirty_vdelay1R_reverbsendgain;
127.198 + private float controlrate;
127.199 +
127.200 + public void init(float samplerate, float controlrate) {
127.201 + this.controlrate = controlrate;
127.202 + vdelay1L = new LFODelay(samplerate, controlrate);
127.203 + vdelay1R = new LFODelay(samplerate, controlrate);
127.204 + vdelay1L.setGain(1.0f); // %
127.205 + vdelay1R.setGain(1.0f); // %
127.206 + vdelay1L.setPhase(0.5 * Math.PI);
127.207 + vdelay1R.setPhase(0);
127.208 +
127.209 + globalParameterControlChange(new int[]{0x01 * 128 + 0x02}, 0, 2);
127.210 + }
127.211 +
127.212 + public void globalParameterControlChange(int[] slothpath, long param,
127.213 + long value) {
127.214 + if (slothpath.length == 1) {
127.215 + if (slothpath[0] == 0x01 * 128 + 0x02) {
127.216 + if (param == 0) { // Chorus Type
127.217 + switch ((int)value) {
127.218 + case 0: // Chorus 1 0 (0%) 3 (0.4Hz) 5 (1.9ms) 0 (0%)
127.219 + globalParameterControlChange(slothpath, 3, 0);
127.220 + globalParameterControlChange(slothpath, 1, 3);
127.221 + globalParameterControlChange(slothpath, 2, 5);
127.222 + globalParameterControlChange(slothpath, 4, 0);
127.223 + break;
127.224 + case 1: // Chorus 2 5 (4%) 9 (1.1Hz) 19 (6.3ms) 0 (0%)
127.225 + globalParameterControlChange(slothpath, 3, 5);
127.226 + globalParameterControlChange(slothpath, 1, 9);
127.227 + globalParameterControlChange(slothpath, 2, 19);
127.228 + globalParameterControlChange(slothpath, 4, 0);
127.229 + break;
127.230 + case 2: // Chorus 3 8 (6%) 3 (0.4Hz) 19 (6.3ms) 0 (0%)
127.231 + globalParameterControlChange(slothpath, 3, 8);
127.232 + globalParameterControlChange(slothpath, 1, 3);
127.233 + globalParameterControlChange(slothpath, 2, 19);
127.234 + globalParameterControlChange(slothpath, 4, 0);
127.235 + break;
127.236 + case 3: // Chorus 4 16 (12%) 9 (1.1Hz) 16 (5.3ms) 0 (0%)
127.237 + globalParameterControlChange(slothpath, 3, 16);
127.238 + globalParameterControlChange(slothpath, 1, 9);
127.239 + globalParameterControlChange(slothpath, 2, 16);
127.240 + globalParameterControlChange(slothpath, 4, 0);
127.241 + break;
127.242 + case 4: // FB Chorus 64 (49%) 2 (0.2Hz) 24 (7.8ms) 0 (0%)
127.243 + globalParameterControlChange(slothpath, 3, 64);
127.244 + globalParameterControlChange(slothpath, 1, 2);
127.245 + globalParameterControlChange(slothpath, 2, 24);
127.246 + globalParameterControlChange(slothpath, 4, 0);
127.247 + break;
127.248 + case 5: // Flanger 112 (86%) 1 (0.1Hz) 5 (1.9ms) 0 (0%)
127.249 + globalParameterControlChange(slothpath, 3, 112);
127.250 + globalParameterControlChange(slothpath, 1, 1);
127.251 + globalParameterControlChange(slothpath, 2, 5);
127.252 + globalParameterControlChange(slothpath, 4, 0);
127.253 + break;
127.254 + default:
127.255 + break;
127.256 + }
127.257 + } else if (param == 1) { // Mod Rate
127.258 + dirty_vdelay1L_rate = (value * 0.122);
127.259 + dirty_vdelay1R_rate = (value * 0.122);
127.260 + dirty = true;
127.261 + } else if (param == 2) { // Mod Depth
127.262 + dirty_vdelay1L_depth = ((value + 1) / 3200.0);
127.263 + dirty_vdelay1R_depth = ((value + 1) / 3200.0);
127.264 + dirty = true;
127.265 + } else if (param == 3) { // Feedback
127.266 + dirty_vdelay1L_feedback = (value * 0.00763f);
127.267 + dirty_vdelay1R_feedback = (value * 0.00763f);
127.268 + dirty = true;
127.269 + }
127.270 + if (param == 4) { // Send to Reverb
127.271 + rgain = value * 0.00787f;
127.272 + dirty_vdelay1L_reverbsendgain = (value * 0.00787f);
127.273 + dirty_vdelay1R_reverbsendgain = (value * 0.00787f);
127.274 + dirty = true;
127.275 + }
127.276 +
127.277 + }
127.278 + }
127.279 + }
127.280 +
127.281 + public void processControlLogic() {
127.282 + if (dirty) {
127.283 + dirty = false;
127.284 + vdelay1L.setRate(dirty_vdelay1L_rate);
127.285 + vdelay1R.setRate(dirty_vdelay1R_rate);
127.286 + vdelay1L.setDepth(dirty_vdelay1L_depth);
127.287 + vdelay1R.setDepth(dirty_vdelay1R_depth);
127.288 + vdelay1L.setFeedBack(dirty_vdelay1L_feedback);
127.289 + vdelay1R.setFeedBack(dirty_vdelay1R_feedback);
127.290 + vdelay1L.setReverbSendGain(dirty_vdelay1L_reverbsendgain);
127.291 + vdelay1R.setReverbSendGain(dirty_vdelay1R_reverbsendgain);
127.292 + }
127.293 + }
127.294 + double silentcounter = 1000;
127.295 +
127.296 + public void processAudio() {
127.297 +
127.298 + if (inputA.isSilent()) {
127.299 + silentcounter += 1 / controlrate;
127.300 +
127.301 + if (silentcounter > 1) {
127.302 + if (!mix) {
127.303 + left.clear();
127.304 + right.clear();
127.305 + }
127.306 + return;
127.307 + }
127.308 + } else
127.309 + silentcounter = 0;
127.310 +
127.311 + float[] inputA = this.inputA.array();
127.312 + float[] left = this.left.array();
127.313 + float[] right = this.right == null ? null : this.right.array();
127.314 + float[] reverb = rgain != 0 ? this.reverb.array() : null;
127.315 +
127.316 + if (mix) {
127.317 + vdelay1L.processMix(inputA, left, reverb);
127.318 + if (right != null)
127.319 + vdelay1R.processMix(inputA, right, reverb);
127.320 + } else {
127.321 + vdelay1L.processReplace(inputA, left, reverb);
127.322 + if (right != null)
127.323 + vdelay1R.processReplace(inputA, right, reverb);
127.324 + }
127.325 + }
127.326 +
127.327 + public void setInput(int pin, SoftAudioBuffer input) {
127.328 + if (pin == 0)
127.329 + inputA = input;
127.330 + }
127.331 +
127.332 + public void setMixMode(boolean mix) {
127.333 + this.mix = mix;
127.334 + }
127.335 +
127.336 + public void setOutput(int pin, SoftAudioBuffer output) {
127.337 + if (pin == 0)
127.338 + left = output;
127.339 + if (pin == 1)
127.340 + right = output;
127.341 + if (pin == 2)
127.342 + reverb = output;
127.343 + }
127.344 +}
128.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
128.2 +++ b/src/share/classes/com/sun/media/sound/SoftControl.java Tue Feb 03 22:02:55 2009 -0800
128.3 @@ -0,0 +1,36 @@
128.4 +/*
128.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
128.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
128.7 + *
128.8 + * This code is free software; you can redistribute it and/or modify it
128.9 + * under the terms of the GNU General Public License version 2 only, as
128.10 + * published by the Free Software Foundation. Sun designates this
128.11 + * particular file as subject to the "Classpath" exception as provided
128.12 + * by Sun in the LICENSE file that accompanied this code.
128.13 + *
128.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
128.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
128.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
128.17 + * version 2 for more details (a copy is included in the LICENSE file that
128.18 + * accompanied this code).
128.19 + *
128.20 + * You should have received a copy of the GNU General Public License version
128.21 + * 2 along with this work; if not, write to the Free Software Foundation,
128.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
128.23 + *
128.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
128.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
128.26 + * have any questions.
128.27 + */
128.28 +package com.sun.media.sound;
128.29 +
128.30 +/**
128.31 + * <code>SoftControl</code> are the basic controls
128.32 + * used for control-rate processing.
128.33 + *
128.34 + * @author Karl Helgason
128.35 + */
128.36 +public interface SoftControl {
128.37 +
128.38 + public double[] get(int instance, String name);
128.39 +}
129.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
129.2 +++ b/src/share/classes/com/sun/media/sound/SoftCubicResampler.java Tue Feb 03 22:02:55 2009 -0800
129.3 @@ -0,0 +1,87 @@
129.4 +/*
129.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
129.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
129.7 + *
129.8 + * This code is free software; you can redistribute it and/or modify it
129.9 + * under the terms of the GNU General Public License version 2 only, as
129.10 + * published by the Free Software Foundation. Sun designates this
129.11 + * particular file as subject to the "Classpath" exception as provided
129.12 + * by Sun in the LICENSE file that accompanied this code.
129.13 + *
129.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
129.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
129.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
129.17 + * version 2 for more details (a copy is included in the LICENSE file that
129.18 + * accompanied this code).
129.19 + *
129.20 + * You should have received a copy of the GNU General Public License version
129.21 + * 2 along with this work; if not, write to the Free Software Foundation,
129.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
129.23 + *
129.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
129.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
129.26 + * have any questions.
129.27 + */
129.28 +package com.sun.media.sound;
129.29 +
129.30 +/**
129.31 + * A resampler that uses third-order (cubic) interpolation.
129.32 + *
129.33 + * @author Karl Helgason
129.34 + */
129.35 +public class SoftCubicResampler extends SoftAbstractResampler {
129.36 +
129.37 + public int getPadding() {
129.38 + return 3;
129.39 + }
129.40 +
129.41 + public void interpolate(float[] in, float[] in_offset, float in_end,
129.42 + float[] startpitch, float pitchstep, float[] out, int[] out_offset,
129.43 + int out_end) {
129.44 + float pitch = startpitch[0];
129.45 + float ix = in_offset[0];
129.46 + int ox = out_offset[0];
129.47 + float ix_end = in_end;
129.48 + int ox_end = out_end;
129.49 + if (pitchstep == 0) {
129.50 + while (ix < ix_end && ox < ox_end) {
129.51 + int iix = (int) ix;
129.52 + float fix = ix - iix;
129.53 + float y0 = in[iix - 1];
129.54 + float y1 = in[iix];
129.55 + float y2 = in[iix + 1];
129.56 + float y3 = in[iix + 2];
129.57 + float a0 = y3 - y2 + y1 - y0;
129.58 + float a1 = y0 - y1 - a0;
129.59 + float a2 = y2 - y0;
129.60 + float a3 = y1;
129.61 + //float fix2 = fix * fix;
129.62 + //out[ox++] = (a0 * fix + a1) * fix2 + (a2 * fix + a3);
129.63 + out[ox++] = ((a0 * fix + a1) * fix + a2) * fix + a3;
129.64 + ix += pitch;
129.65 + }
129.66 + } else {
129.67 + while (ix < ix_end && ox < ox_end) {
129.68 + int iix = (int) ix;
129.69 + float fix = ix - iix;
129.70 + float y0 = in[iix - 1];
129.71 + float y1 = in[iix];
129.72 + float y2 = in[iix + 1];
129.73 + float y3 = in[iix + 2];
129.74 + float a0 = y3 - y2 + y1 - y0;
129.75 + float a1 = y0 - y1 - a0;
129.76 + float a2 = y2 - y0;
129.77 + float a3 = y1;
129.78 + //float fix2 = fix * fix;
129.79 + //out[ox++] = (a0 * fix + a1) * fix2 + (a2 * fix + a3);
129.80 + out[ox++] = ((a0 * fix + a1) * fix + a2) * fix + a3;
129.81 + ix += pitch;
129.82 + pitch += pitchstep;
129.83 + }
129.84 + }
129.85 + in_offset[0] = ix;
129.86 + out_offset[0] = ox;
129.87 + startpitch[0] = pitch;
129.88 +
129.89 + }
129.90 +}
130.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
130.2 +++ b/src/share/classes/com/sun/media/sound/SoftEnvelopeGenerator.java Tue Feb 03 22:02:55 2009 -0800
130.3 @@ -0,0 +1,298 @@
130.4 +/*
130.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
130.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
130.7 + *
130.8 + * This code is free software; you can redistribute it and/or modify it
130.9 + * under the terms of the GNU General Public License version 2 only, as
130.10 + * published by the Free Software Foundation. Sun designates this
130.11 + * particular file as subject to the "Classpath" exception as provided
130.12 + * by Sun in the LICENSE file that accompanied this code.
130.13 + *
130.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
130.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
130.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
130.17 + * version 2 for more details (a copy is included in the LICENSE file that
130.18 + * accompanied this code).
130.19 + *
130.20 + * You should have received a copy of the GNU General Public License version
130.21 + * 2 along with this work; if not, write to the Free Software Foundation,
130.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
130.23 + *
130.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
130.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
130.26 + * have any questions.
130.27 + */
130.28 +package com.sun.media.sound;
130.29 +
130.30 +/**
130.31 + * AHDSR control signal envelope generator.
130.32 + *
130.33 + * @author Karl Helgason
130.34 + */
130.35 +public class SoftEnvelopeGenerator implements SoftProcess {
130.36 +
130.37 + public final static int EG_OFF = 0;
130.38 + public final static int EG_DELAY = 1;
130.39 + public final static int EG_ATTACK = 2;
130.40 + public final static int EG_HOLD = 3;
130.41 + public final static int EG_DECAY = 4;
130.42 + public final static int EG_SUSTAIN = 5;
130.43 + public final static int EG_RELEASE = 6;
130.44 + public final static int EG_SHUTDOWN = 7;
130.45 + public final static int EG_END = 8;
130.46 + int max_count = 10;
130.47 + int used_count = 0;
130.48 + private int[] stage = new int[max_count];
130.49 + private int[] stage_ix = new int[max_count];
130.50 + private double[] stage_v = new double[max_count];
130.51 + private int[] stage_count = new int[max_count];
130.52 + private double[][] on = new double[max_count][1];
130.53 + private double[][] active = new double[max_count][1];
130.54 + private double[][] out = new double[max_count][1];
130.55 + private double[][] delay = new double[max_count][1];
130.56 + private double[][] attack = new double[max_count][1];
130.57 + private double[][] hold = new double[max_count][1];
130.58 + private double[][] decay = new double[max_count][1];
130.59 + private double[][] sustain = new double[max_count][1];
130.60 + private double[][] release = new double[max_count][1];
130.61 + private double[][] shutdown = new double[max_count][1];
130.62 + private double[][] release2 = new double[max_count][1];
130.63 + private double[][] attack2 = new double[max_count][1];
130.64 + private double[][] decay2 = new double[max_count][1];
130.65 + private double control_time = 0;
130.66 +
130.67 + public void reset() {
130.68 + for (int i = 0; i < used_count; i++) {
130.69 + stage[i] = 0;
130.70 + on[i][0] = 0;
130.71 + out[i][0] = 0;
130.72 + delay[i][0] = 0;
130.73 + attack[i][0] = 0;
130.74 + hold[i][0] = 0;
130.75 + decay[i][0] = 0;
130.76 + sustain[i][0] = 0;
130.77 + release[i][0] = 0;
130.78 + shutdown[i][0] = 0;
130.79 + attack2[i][0] = 0;
130.80 + decay2[i][0] = 0;
130.81 + release2[i][0] = 0;
130.82 + }
130.83 + used_count = 0;
130.84 + }
130.85 +
130.86 + public void init(SoftSynthesizer synth) {
130.87 + control_time = 1.0 / synth.getControlRate();
130.88 + processControlLogic();
130.89 + }
130.90 +
130.91 + public double[] get(int instance, String name) {
130.92 + if (instance >= used_count)
130.93 + used_count = instance + 1;
130.94 + if (name == null)
130.95 + return out[instance];
130.96 + if (name.equals("on"))
130.97 + return on[instance];
130.98 + if (name.equals("active"))
130.99 + return active[instance];
130.100 + if (name.equals("delay"))
130.101 + return delay[instance];
130.102 + if (name.equals("attack"))
130.103 + return attack[instance];
130.104 + if (name.equals("hold"))
130.105 + return hold[instance];
130.106 + if (name.equals("decay"))
130.107 + return decay[instance];
130.108 + if (name.equals("sustain"))
130.109 + return sustain[instance];
130.110 + if (name.equals("release"))
130.111 + return release[instance];
130.112 + if (name.equals("shutdown"))
130.113 + return shutdown[instance];
130.114 + if (name.equals("attack2"))
130.115 + return attack2[instance];
130.116 + if (name.equals("decay2"))
130.117 + return decay2[instance];
130.118 + if (name.equals("release2"))
130.119 + return release2[instance];
130.120 +
130.121 + return null;
130.122 + }
130.123 +
130.124 + public void processControlLogic() {
130.125 + for (int i = 0; i < used_count; i++) {
130.126 +
130.127 + if (stage[i] == EG_END)
130.128 + continue;
130.129 +
130.130 + if ((stage[i] > EG_OFF) && (stage[i] < EG_RELEASE)) {
130.131 + if (on[i][0] < 0.5) {
130.132 + if (on[i][0] < -0.5) {
130.133 + stage_count[i] = (int)(Math.pow(2,
130.134 + this.shutdown[i][0] / 1200.0) / control_time);
130.135 + if (stage_count[i] < 0)
130.136 + stage_count[i] = 0;
130.137 + stage_v[i] = out[i][0];
130.138 + stage_ix[i] = 0;
130.139 + stage[i] = EG_SHUTDOWN;
130.140 + } else {
130.141 + if ((release2[i][0] < 0.000001) && release[i][0] < 0
130.142 + && Double.isInfinite(release[i][0])) {
130.143 + out[i][0] = 0;
130.144 + active[i][0] = 0;
130.145 + stage[i] = EG_END;
130.146 + continue;
130.147 + }
130.148 +
130.149 + stage_count[i] = (int)(Math.pow(2,
130.150 + this.release[i][0] / 1200.0) / control_time);
130.151 + stage_count[i]
130.152 + += (int)(this.release2[i][0]/(control_time * 1000));
130.153 + if (stage_count[i] < 0)
130.154 + stage_count[i] = 0;
130.155 + // stage_v[i] = out[i][0];
130.156 + stage_ix[i] = 0;
130.157 +
130.158 + double m = 1 - out[i][0];
130.159 + stage_ix[i] = (int)(stage_count[i] * m);
130.160 +
130.161 + stage[i] = EG_RELEASE;
130.162 + }
130.163 + }
130.164 + }
130.165 +
130.166 + switch (stage[i]) {
130.167 + case EG_OFF:
130.168 + active[i][0] = 1;
130.169 + if (on[i][0] < 0.5)
130.170 + break;
130.171 + stage[i] = EG_DELAY;
130.172 + stage_ix[i] = (int)(Math.pow(2,
130.173 + this.delay[i][0] / 1200.0) / control_time);
130.174 + if (stage_ix[i] < 0)
130.175 + stage_ix[i] = 0;
130.176 + case EG_DELAY:
130.177 + if (stage_ix[i] == 0) {
130.178 + double attack = this.attack[i][0];
130.179 + double attack2 = this.attack2[i][0];
130.180 +
130.181 + if (attack2 < 0.000001
130.182 + && (attack < 0 && Double.isInfinite(attack))) {
130.183 + out[i][0] = 1;
130.184 + stage[i] = EG_HOLD;
130.185 + stage_count[i] = (int)(Math.pow(2,
130.186 + this.hold[i][0] / 1200.0) / control_time);
130.187 + stage_ix[i] = 0;
130.188 + } else {
130.189 + stage[i] = EG_ATTACK;
130.190 + stage_count[i] = (int)(Math.pow(2,
130.191 + attack / 1200.0) / control_time);
130.192 + stage_count[i] += (int)(attack2 / (control_time * 1000));
130.193 + if (stage_count[i] < 0)
130.194 + stage_count[i] = 0;
130.195 + stage_ix[i] = 0;
130.196 + }
130.197 + } else
130.198 + stage_ix[i]--;
130.199 + break;
130.200 + case EG_ATTACK:
130.201 + stage_ix[i]++;
130.202 + if (stage_ix[i] >= stage_count[i]) {
130.203 + out[i][0] = 1;
130.204 + stage[i] = EG_HOLD;
130.205 + } else {
130.206 + // CONVEX attack
130.207 + double a = ((double)stage_ix[i]) / ((double)stage_count[i]);
130.208 + a = 1 + ((40.0 / 96.0) / Math.log(10)) * Math.log(a);
130.209 + if (a < 0)
130.210 + a = 0;
130.211 + else if (a > 1)
130.212 + a = 1;
130.213 + out[i][0] = a;
130.214 + }
130.215 + break;
130.216 + case EG_HOLD:
130.217 + stage_ix[i]++;
130.218 + if (stage_ix[i] >= stage_count[i]) {
130.219 + stage[i] = EG_DECAY;
130.220 + stage_count[i] = (int)(Math.pow(2,
130.221 + this.decay[i][0] / 1200.0) / control_time);
130.222 + stage_count[i] += (int)(this.decay2[i][0]/(control_time*1000));
130.223 + if (stage_count[i] < 0)
130.224 + stage_count[i] = 0;
130.225 + stage_ix[i] = 0;
130.226 + }
130.227 + break;
130.228 + case EG_DECAY:
130.229 + stage_ix[i]++;
130.230 + double sustain = this.sustain[i][0] * (1.0 / 1000.0);
130.231 + if (stage_ix[i] >= stage_count[i]) {
130.232 + out[i][0] = sustain;
130.233 + stage[i] = EG_SUSTAIN;
130.234 + if (sustain < 0.001) {
130.235 + out[i][0] = 0;
130.236 + active[i][0] = 0;
130.237 + stage[i] = EG_END;
130.238 + }
130.239 + } else {
130.240 + double m = ((double)stage_ix[i]) / ((double)stage_count[i]);
130.241 + out[i][0] = (1 - m) + sustain * m;
130.242 + }
130.243 + break;
130.244 + case EG_SUSTAIN:
130.245 + break;
130.246 + case EG_RELEASE:
130.247 + stage_ix[i]++;
130.248 + if (stage_ix[i] >= stage_count[i]) {
130.249 + out[i][0] = 0;
130.250 + active[i][0] = 0;
130.251 + stage[i] = EG_END;
130.252 + } else {
130.253 + double m = ((double)stage_ix[i]) / ((double)stage_count[i]);
130.254 + out[i][0] = (1 - m); // *stage_v[i];
130.255 +
130.256 + if (on[i][0] < -0.5) {
130.257 + stage_count[i] = (int)(Math.pow(2,
130.258 + this.shutdown[i][0] / 1200.0) / control_time);
130.259 + if (stage_count[i] < 0)
130.260 + stage_count[i] = 0;
130.261 + stage_v[i] = out[i][0];
130.262 + stage_ix[i] = 0;
130.263 + stage[i] = EG_SHUTDOWN;
130.264 + }
130.265 +
130.266 + // re-damping
130.267 + if (on[i][0] > 0.5) {
130.268 + sustain = this.sustain[i][0] * (1.0 / 1000.0);
130.269 + if (out[i][0] > sustain) {
130.270 + stage[i] = EG_DECAY;
130.271 + stage_count[i] = (int)(Math.pow(2,
130.272 + this.decay[i][0] / 1200.0) / control_time);
130.273 + stage_count[i] +=
130.274 + (int)(this.decay2[i][0]/(control_time*1000));
130.275 + if (stage_count[i] < 0)
130.276 + stage_count[i] = 0;
130.277 + m = (out[i][0] - 1) / (sustain - 1);
130.278 + stage_ix[i] = (int) (stage_count[i] * m);
130.279 + }
130.280 + }
130.281 +
130.282 + }
130.283 + break;
130.284 + case EG_SHUTDOWN:
130.285 + stage_ix[i]++;
130.286 + if (stage_ix[i] >= stage_count[i]) {
130.287 + out[i][0] = 0;
130.288 + active[i][0] = 0;
130.289 + stage[i] = EG_END;
130.290 + } else {
130.291 + double m = ((double)stage_ix[i]) / ((double)stage_count[i]);
130.292 + out[i][0] = (1 - m) * stage_v[i];
130.293 + }
130.294 + break;
130.295 + default:
130.296 + break;
130.297 + }
130.298 + }
130.299 +
130.300 + }
130.301 +}
131.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
131.2 +++ b/src/share/classes/com/sun/media/sound/SoftFilter.java Tue Feb 03 22:02:55 2009 -0800
131.3 @@ -0,0 +1,614 @@
131.4 +/*
131.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
131.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
131.7 + *
131.8 + * This code is free software; you can redistribute it and/or modify it
131.9 + * under the terms of the GNU General Public License version 2 only, as
131.10 + * published by the Free Software Foundation. Sun designates this
131.11 + * particular file as subject to the "Classpath" exception as provided
131.12 + * by Sun in the LICENSE file that accompanied this code.
131.13 + *
131.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
131.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
131.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
131.17 + * version 2 for more details (a copy is included in the LICENSE file that
131.18 + * accompanied this code).
131.19 + *
131.20 + * You should have received a copy of the GNU General Public License version
131.21 + * 2 along with this work; if not, write to the Free Software Foundation,
131.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
131.23 + *
131.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
131.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
131.26 + * have any questions.
131.27 + */
131.28 +package com.sun.media.sound;
131.29 +
131.30 +/**
131.31 + * Infinite impulse response (IIR) filter class.
131.32 + *
131.33 + * The filters where implemented and adapted using algorithms from musicdsp.org
131.34 + * archive: 1-RC and C filter, Simple 2-pole LP LP and HP filter, biquad,
131.35 + * tweaked butterworth RBJ Audio-EQ-Cookbook, EQ filter kookbook
131.36 + *
131.37 + * @author Karl Helgason
131.38 + */
131.39 +public class SoftFilter {
131.40 +
131.41 + public final static int FILTERTYPE_LP6 = 0x00;
131.42 + public final static int FILTERTYPE_LP12 = 0x01;
131.43 + public final static int FILTERTYPE_HP12 = 0x11;
131.44 + public final static int FILTERTYPE_BP12 = 0x21;
131.45 + public final static int FILTERTYPE_NP12 = 0x31;
131.46 + public final static int FILTERTYPE_LP24 = 0x03;
131.47 + public final static int FILTERTYPE_HP24 = 0x13;
131.48 +
131.49 + //
131.50 + // 0x0 = 1st-order, 6 dB/oct
131.51 + // 0x1 = 2nd-order, 12 dB/oct
131.52 + // 0x2 = 3rd-order, 18 dB/oct
131.53 + // 0x3 = 4th-order, 24 db/oct
131.54 + //
131.55 + // 0x00 = LP, Low Pass Filter
131.56 + // 0x10 = HP, High Pass Filter
131.57 + // 0x20 = BP, Band Pass Filter
131.58 + // 0x30 = NP, Notch or Band Elimination Filter
131.59 + //
131.60 + private int filtertype = FILTERTYPE_LP6;
131.61 + private float samplerate;
131.62 + private float x1;
131.63 + private float x2;
131.64 + private float y1;
131.65 + private float y2;
131.66 + private float xx1;
131.67 + private float xx2;
131.68 + private float yy1;
131.69 + private float yy2;
131.70 + private float a0;
131.71 + private float a1;
131.72 + private float a2;
131.73 + private float b1;
131.74 + private float b2;
131.75 + private float q;
131.76 + private float gain = 1;
131.77 + private float wet = 0;
131.78 + private float last_wet = 0;
131.79 + private float last_a0;
131.80 + private float last_a1;
131.81 + private float last_a2;
131.82 + private float last_b1;
131.83 + private float last_b2;
131.84 + private float last_q;
131.85 + private float last_gain;
131.86 + private boolean last_set = false;
131.87 + private double cutoff = 44100;
131.88 + private double resonancedB = 0;
131.89 + private boolean dirty = true;
131.90 +
131.91 + public SoftFilter(float samplerate) {
131.92 + this.samplerate = samplerate;
131.93 + dirty = true;
131.94 + }
131.95 +
131.96 + public void setFrequency(double cent) {
131.97 + if (cutoff == cent)
131.98 + return;
131.99 + cutoff = cent;
131.100 + dirty = true;
131.101 + }
131.102 +
131.103 + public void setResonance(double db) {
131.104 + if (resonancedB == db)
131.105 + return;
131.106 + resonancedB = db;
131.107 + dirty = true;
131.108 + }
131.109 +
131.110 + public void reset() {
131.111 + dirty = true;
131.112 + last_set = false;
131.113 + x1 = 0;
131.114 + x2 = 0;
131.115 + y1 = 0;
131.116 + y2 = 0;
131.117 + xx1 = 0;
131.118 + xx2 = 0;
131.119 + yy1 = 0;
131.120 + yy2 = 0;
131.121 + wet = 0.0f;
131.122 + gain = 1.0f;
131.123 + a0 = 0;
131.124 + a1 = 0;
131.125 + a2 = 0;
131.126 + b1 = 0;
131.127 + b2 = 0;
131.128 + }
131.129 +
131.130 + public void setFilterType(int filtertype) {
131.131 + this.filtertype = filtertype;
131.132 + }
131.133 +
131.134 + public void processAudio(SoftAudioBuffer sbuffer) {
131.135 + if (filtertype == FILTERTYPE_LP6)
131.136 + filter1(sbuffer);
131.137 + if (filtertype == FILTERTYPE_LP12)
131.138 + filter2(sbuffer);
131.139 + if (filtertype == FILTERTYPE_HP12)
131.140 + filter2(sbuffer);
131.141 + if (filtertype == FILTERTYPE_BP12)
131.142 + filter2(sbuffer);
131.143 + if (filtertype == FILTERTYPE_NP12)
131.144 + filter2(sbuffer);
131.145 + if (filtertype == FILTERTYPE_LP24)
131.146 + filter4(sbuffer);
131.147 + if (filtertype == FILTERTYPE_HP24)
131.148 + filter4(sbuffer);
131.149 + }
131.150 +
131.151 + public void filter4(SoftAudioBuffer sbuffer) {
131.152 +
131.153 + float[] buffer = sbuffer.array();
131.154 +
131.155 + if (dirty) {
131.156 + filter2calc();
131.157 + dirty = false;
131.158 + }
131.159 + if (!last_set) {
131.160 + last_a0 = a0;
131.161 + last_a1 = a1;
131.162 + last_a2 = a2;
131.163 + last_b1 = b1;
131.164 + last_b2 = b2;
131.165 + last_gain = gain;
131.166 + last_wet = wet;
131.167 + last_set = true;
131.168 + }
131.169 +
131.170 + if (wet > 0 || last_wet > 0) {
131.171 +
131.172 + int len = buffer.length;
131.173 + float a0 = this.last_a0;
131.174 + float a1 = this.last_a1;
131.175 + float a2 = this.last_a2;
131.176 + float b1 = this.last_b1;
131.177 + float b2 = this.last_b2;
131.178 + float gain = this.last_gain;
131.179 + float wet = this.last_wet;
131.180 + float a0_delta = (this.a0 - this.last_a0) / len;
131.181 + float a1_delta = (this.a1 - this.last_a1) / len;
131.182 + float a2_delta = (this.a2 - this.last_a2) / len;
131.183 + float b1_delta = (this.b1 - this.last_b1) / len;
131.184 + float b2_delta = (this.b2 - this.last_b2) / len;
131.185 + float gain_delta = (this.gain - this.last_gain) / len;
131.186 + float wet_delta = (this.wet - this.last_wet) / len;
131.187 + float x1 = this.x1;
131.188 + float x2 = this.x2;
131.189 + float y1 = this.y1;
131.190 + float y2 = this.y2;
131.191 + float xx1 = this.xx1;
131.192 + float xx2 = this.xx2;
131.193 + float yy1 = this.yy1;
131.194 + float yy2 = this.yy2;
131.195 +
131.196 + if (wet_delta != 0) {
131.197 + for (int i = 0; i < len; i++) {
131.198 + a0 += a0_delta;
131.199 + a1 += a1_delta;
131.200 + a2 += a2_delta;
131.201 + b1 += b1_delta;
131.202 + b2 += b2_delta;
131.203 + gain += gain_delta;
131.204 + wet += wet_delta;
131.205 + float x = buffer[i];
131.206 + float y = (a0*x + a1*x1 + a2*x2 - b1*y1 - b2*y2);
131.207 + float xx = (y * gain) * wet + (x) * (1 - wet);
131.208 + x2 = x1;
131.209 + x1 = x;
131.210 + y2 = y1;
131.211 + y1 = y;
131.212 + float yy = (a0*xx + a1*xx1 + a2*xx2 - b1*yy1 - b2*yy2);
131.213 + buffer[i] = (yy * gain) * wet + (xx) * (1 - wet);
131.214 + xx2 = xx1;
131.215 + xx1 = xx;
131.216 + yy2 = yy1;
131.217 + yy1 = yy;
131.218 + }
131.219 + } else if (a0_delta == 0 && a1_delta == 0 && a2_delta == 0
131.220 + && b1_delta == 0 && b2_delta == 0) {
131.221 + for (int i = 0; i < len; i++) {
131.222 + float x = buffer[i];
131.223 + float y = (a0*x + a1*x1 + a2*x2 - b1*y1 - b2*y2);
131.224 + float xx = (y * gain) * wet + (x) * (1 - wet);
131.225 + x2 = x1;
131.226 + x1 = x;
131.227 + y2 = y1;
131.228 + y1 = y;
131.229 + float yy = (a0*xx + a1*xx1 + a2*xx2 - b1*yy1 - b2*yy2);
131.230 + buffer[i] = (yy * gain) * wet + (xx) * (1 - wet);
131.231 + xx2 = xx1;
131.232 + xx1 = xx;
131.233 + yy2 = yy1;
131.234 + yy1 = yy;
131.235 + }
131.236 + } else {
131.237 + for (int i = 0; i < len; i++) {
131.238 + a0 += a0_delta;
131.239 + a1 += a1_delta;
131.240 + a2 += a2_delta;
131.241 + b1 += b1_delta;
131.242 + b2 += b2_delta;
131.243 + gain += gain_delta;
131.244 + float x = buffer[i];
131.245 + float y = (a0*x + a1*x1 + a2*x2 - b1*y1 - b2*y2);
131.246 + float xx = (y * gain) * wet + (x) * (1 - wet);
131.247 + x2 = x1;
131.248 + x1 = x;
131.249 + y2 = y1;
131.250 + y1 = y;
131.251 + float yy = (a0*xx + a1*xx1 + a2*xx2 - b1*yy1 - b2*yy2);
131.252 + buffer[i] = (yy * gain) * wet + (xx) * (1 - wet);
131.253 + xx2 = xx1;
131.254 + xx1 = xx;
131.255 + yy2 = yy1;
131.256 + yy1 = yy;
131.257 + }
131.258 + }
131.259 +
131.260 + if (Math.abs(x1) < 1.0E-8)
131.261 + x1 = 0;
131.262 + if (Math.abs(x2) < 1.0E-8)
131.263 + x2 = 0;
131.264 + if (Math.abs(y1) < 1.0E-8)
131.265 + y1 = 0;
131.266 + if (Math.abs(y2) < 1.0E-8)
131.267 + y2 = 0;
131.268 + this.x1 = x1;
131.269 + this.x2 = x2;
131.270 + this.y1 = y1;
131.271 + this.y2 = y2;
131.272 + this.xx1 = xx1;
131.273 + this.xx2 = xx2;
131.274 + this.yy1 = yy1;
131.275 + this.yy2 = yy2;
131.276 + }
131.277 +
131.278 + this.last_a0 = this.a0;
131.279 + this.last_a1 = this.a1;
131.280 + this.last_a2 = this.a2;
131.281 + this.last_b1 = this.b1;
131.282 + this.last_b2 = this.b2;
131.283 + this.last_gain = this.gain;
131.284 + this.last_wet = this.wet;
131.285 +
131.286 + }
131.287 +
131.288 + private double sinh(double x) {
131.289 + return (Math.exp(x) - Math.exp(-x)) * 0.5;
131.290 + }
131.291 +
131.292 + public void filter2calc() {
131.293 +
131.294 + double resonancedB = this.resonancedB;
131.295 + if (resonancedB < 0)
131.296 + resonancedB = 0; // Negative dB are illegal.
131.297 + if (resonancedB > 30)
131.298 + resonancedB = 30; // At least 22.5 dB is needed.
131.299 + if (filtertype == FILTERTYPE_LP24 || filtertype == FILTERTYPE_HP24)
131.300 + resonancedB *= 0.6;
131.301 +
131.302 + if (filtertype == FILTERTYPE_BP12) {
131.303 + wet = 1;
131.304 + double r = (cutoff / samplerate);
131.305 + if (r > 0.45)
131.306 + r = 0.45;
131.307 +
131.308 + double bandwidth = Math.PI * Math.pow(10.0, -(resonancedB / 20));
131.309 +
131.310 + double omega = 2 * Math.PI * r;
131.311 + double cs = Math.cos(omega);
131.312 + double sn = Math.sin(omega);
131.313 + double alpha = sn * sinh((Math.log(2)*bandwidth*omega) / (sn * 2));
131.314 +
131.315 + double b0 = alpha;
131.316 + double b1 = 0;
131.317 + double b2 = -alpha;
131.318 + double a0 = 1 + alpha;
131.319 + double a1 = -2 * cs;
131.320 + double a2 = 1 - alpha;
131.321 +
131.322 + double cf = 1.0 / a0;
131.323 + this.b1 = (float) (a1 * cf);
131.324 + this.b2 = (float) (a2 * cf);
131.325 + this.a0 = (float) (b0 * cf);
131.326 + this.a1 = (float) (b1 * cf);
131.327 + this.a2 = (float) (b2 * cf);
131.328 + }
131.329 +
131.330 + if (filtertype == FILTERTYPE_NP12) {
131.331 + wet = 1;
131.332 + double r = (cutoff / samplerate);
131.333 + if (r > 0.45)
131.334 + r = 0.45;
131.335 +
131.336 + double bandwidth = Math.PI * Math.pow(10.0, -(resonancedB / 20));
131.337 +
131.338 + double omega = 2 * Math.PI * r;
131.339 + double cs = Math.cos(omega);
131.340 + double sn = Math.sin(omega);
131.341 + double alpha = sn * sinh((Math.log(2)*bandwidth*omega) / (sn*2));
131.342 +
131.343 + double b0 = 1;
131.344 + double b1 = -2 * cs;
131.345 + double b2 = 1;
131.346 + double a0 = 1 + alpha;
131.347 + double a1 = -2 * cs;
131.348 + double a2 = 1 - alpha;
131.349 +
131.350 + double cf = 1.0 / a0;
131.351 + this.b1 = (float)(a1 * cf);
131.352 + this.b2 = (float)(a2 * cf);
131.353 + this.a0 = (float)(b0 * cf);
131.354 + this.a1 = (float)(b1 * cf);
131.355 + this.a2 = (float)(b2 * cf);
131.356 + }
131.357 +
131.358 + if (filtertype == FILTERTYPE_LP12 || filtertype == FILTERTYPE_LP24) {
131.359 + double r = (cutoff / samplerate);
131.360 + if (r > 0.45) {
131.361 + if (wet == 0) {
131.362 + if (resonancedB < 0.00001)
131.363 + wet = 0.0f;
131.364 + else
131.365 + wet = 1.0f;
131.366 + }
131.367 + r = 0.45;
131.368 + } else
131.369 + wet = 1.0f;
131.370 +
131.371 + double c = 1.0 / (Math.tan(Math.PI * r));
131.372 + double csq = c * c;
131.373 + double resonance = Math.pow(10.0, -(resonancedB / 20));
131.374 + double q = Math.sqrt(2.0f) * resonance;
131.375 + double a0 = 1.0 / (1.0 + (q * c) + (csq));
131.376 + double a1 = 2.0 * a0;
131.377 + double a2 = a0;
131.378 + double b1 = (2.0 * a0) * (1.0 - csq);
131.379 + double b2 = a0 * (1.0 - (q * c) + csq);
131.380 +
131.381 + this.a0 = (float)a0;
131.382 + this.a1 = (float)a1;
131.383 + this.a2 = (float)a2;
131.384 + this.b1 = (float)b1;
131.385 + this.b2 = (float)b2;
131.386 +
131.387 + }
131.388 +
131.389 + if (filtertype == FILTERTYPE_HP12 || filtertype == FILTERTYPE_HP24) {
131.390 + double r = (cutoff / samplerate);
131.391 + if (r > 0.45)
131.392 + r = 0.45;
131.393 + if (r < 0.0001)
131.394 + r = 0.0001;
131.395 + wet = 1.0f;
131.396 + double c = (Math.tan(Math.PI * (r)));
131.397 + double csq = c * c;
131.398 + double resonance = Math.pow(10.0, -(resonancedB / 20));
131.399 + double q = Math.sqrt(2.0f) * resonance;
131.400 + double a0 = 1.0 / (1.0 + (q * c) + (csq));
131.401 + double a1 = -2.0 * a0;
131.402 + double a2 = a0;
131.403 + double b1 = (2.0 * a0) * (csq - 1.0);
131.404 + double b2 = a0 * (1.0 - (q * c) + csq);
131.405 +
131.406 + this.a0 = (float)a0;
131.407 + this.a1 = (float)a1;
131.408 + this.a2 = (float)a2;
131.409 + this.b1 = (float)b1;
131.410 + this.b2 = (float)b2;
131.411 +
131.412 + }
131.413 +
131.414 + }
131.415 +
131.416 + public void filter2(SoftAudioBuffer sbuffer) {
131.417 +
131.418 + float[] buffer = sbuffer.array();
131.419 +
131.420 + if (dirty) {
131.421 + filter2calc();
131.422 + dirty = false;
131.423 + }
131.424 + if (!last_set) {
131.425 + last_a0 = a0;
131.426 + last_a1 = a1;
131.427 + last_a2 = a2;
131.428 + last_b1 = b1;
131.429 + last_b2 = b2;
131.430 + last_q = q;
131.431 + last_gain = gain;
131.432 + last_wet = wet;
131.433 + last_set = true;
131.434 + }
131.435 +
131.436 + if (wet > 0 || last_wet > 0) {
131.437 +
131.438 + int len = buffer.length;
131.439 + float a0 = this.last_a0;
131.440 + float a1 = this.last_a1;
131.441 + float a2 = this.last_a2;
131.442 + float b1 = this.last_b1;
131.443 + float b2 = this.last_b2;
131.444 + float gain = this.last_gain;
131.445 + float wet = this.last_wet;
131.446 + float a0_delta = (this.a0 - this.last_a0) / len;
131.447 + float a1_delta = (this.a1 - this.last_a1) / len;
131.448 + float a2_delta = (this.a2 - this.last_a2) / len;
131.449 + float b1_delta = (this.b1 - this.last_b1) / len;
131.450 + float b2_delta = (this.b2 - this.last_b2) / len;
131.451 + float gain_delta = (this.gain - this.last_gain) / len;
131.452 + float wet_delta = (this.wet - this.last_wet) / len;
131.453 + float x1 = this.x1;
131.454 + float x2 = this.x2;
131.455 + float y1 = this.y1;
131.456 + float y2 = this.y2;
131.457 +
131.458 + if (wet_delta != 0) {
131.459 + for (int i = 0; i < len; i++) {
131.460 + a0 += a0_delta;
131.461 + a1 += a1_delta;
131.462 + a2 += a2_delta;
131.463 + b1 += b1_delta;
131.464 + b2 += b2_delta;
131.465 + gain += gain_delta;
131.466 + wet += wet_delta;
131.467 + float x = buffer[i];
131.468 + float y = (a0*x + a1*x1 + a2*x2 - b1*y1 - b2*y2);
131.469 + buffer[i] = (y * gain) * wet + (x) * (1 - wet);
131.470 + x2 = x1;
131.471 + x1 = x;
131.472 + y2 = y1;
131.473 + y1 = y;
131.474 + }
131.475 + } else if (a0_delta == 0 && a1_delta == 0 && a2_delta == 0
131.476 + && b1_delta == 0 && b2_delta == 0) {
131.477 + for (int i = 0; i < len; i++) {
131.478 + float x = buffer[i];
131.479 + float y = (a0*x + a1*x1 + a2*x2 - b1*y1 - b2*y2);
131.480 + buffer[i] = y * gain;
131.481 + x2 = x1;
131.482 + x1 = x;
131.483 + y2 = y1;
131.484 + y1 = y;
131.485 + }
131.486 + } else {
131.487 + for (int i = 0; i < len; i++) {
131.488 + a0 += a0_delta;
131.489 + a1 += a1_delta;
131.490 + a2 += a2_delta;
131.491 + b1 += b1_delta;
131.492 + b2 += b2_delta;
131.493 + gain += gain_delta;
131.494 + float x = buffer[i];
131.495 + float y = (a0*x + a1*x1 + a2*x2 - b1*y1 - b2*y2);
131.496 + buffer[i] = y * gain;
131.497 + x2 = x1;
131.498 + x1 = x;
131.499 + y2 = y1;
131.500 + y1 = y;
131.501 + }
131.502 + }
131.503 +
131.504 + if (Math.abs(x1) < 1.0E-8)
131.505 + x1 = 0;
131.506 + if (Math.abs(x2) < 1.0E-8)
131.507 + x2 = 0;
131.508 + if (Math.abs(y1) < 1.0E-8)
131.509 + y1 = 0;
131.510 + if (Math.abs(y2) < 1.0E-8)
131.511 + y2 = 0;
131.512 + this.x1 = x1;
131.513 + this.x2 = x2;
131.514 + this.y1 = y1;
131.515 + this.y2 = y2;
131.516 + }
131.517 +
131.518 + this.last_a0 = this.a0;
131.519 + this.last_a1 = this.a1;
131.520 + this.last_a2 = this.a2;
131.521 + this.last_b1 = this.b1;
131.522 + this.last_b2 = this.b2;
131.523 + this.last_q = this.q;
131.524 + this.last_gain = this.gain;
131.525 + this.last_wet = this.wet;
131.526 +
131.527 + }
131.528 +
131.529 + public void filter1calc() {
131.530 + if (cutoff < 120)
131.531 + cutoff = 120;
131.532 + double c = (7.0 / 6.0) * Math.PI * 2 * cutoff / samplerate;
131.533 + if (c > 1)
131.534 + c = 1;
131.535 + a0 = (float)(Math.sqrt(1 - Math.cos(c)) * Math.sqrt(0.5 * Math.PI));
131.536 + if (resonancedB < 0)
131.537 + resonancedB = 0;
131.538 + if (resonancedB > 20)
131.539 + resonancedB = 20;
131.540 + q = (float)(Math.sqrt(0.5) * Math.pow(10.0, -(resonancedB / 20)));
131.541 + gain = (float)Math.pow(10, -((resonancedB)) / 40.0);
131.542 + if (wet == 0.0f)
131.543 + if (resonancedB > 0.00001 || c < 0.9999999)
131.544 + wet = 1.0f;
131.545 + }
131.546 +
131.547 + public void filter1(SoftAudioBuffer sbuffer) {
131.548 +
131.549 + float[] buffer = sbuffer.array();
131.550 +
131.551 + if (dirty) {
131.552 + filter1calc();
131.553 + dirty = false;
131.554 + }
131.555 + if (!last_set) {
131.556 + last_a0 = a0;
131.557 + last_q = q;
131.558 + last_gain = gain;
131.559 + last_wet = wet;
131.560 + last_set = true;
131.561 + }
131.562 +
131.563 + if (wet > 0 || last_wet > 0) {
131.564 +
131.565 + int len = buffer.length;
131.566 + float a0 = this.last_a0;
131.567 + float q = this.last_q;
131.568 + float gain = this.last_gain;
131.569 + float wet = this.last_wet;
131.570 + float a0_delta = (this.a0 - this.last_a0) / len;
131.571 + float q_delta = (this.q - this.last_q) / len;
131.572 + float gain_delta = (this.gain - this.last_gain) / len;
131.573 + float wet_delta = (this.wet - this.last_wet) / len;
131.574 + float y2 = this.y2;
131.575 + float y1 = this.y1;
131.576 +
131.577 + if (wet_delta != 0) {
131.578 + for (int i = 0; i < len; i++) {
131.579 + a0 += a0_delta;
131.580 + q += q_delta;
131.581 + gain += gain_delta;
131.582 + wet += wet_delta;
131.583 + y1 = (1 - q * a0) * y1 - (a0) * y2 + (a0) * buffer[i];
131.584 + y2 = (1 - q * a0) * y2 + (a0) * y1;
131.585 + buffer[i] = y2 * gain * wet + buffer[i] * (1 - wet);
131.586 + }
131.587 + } else if (a0_delta == 0 && q_delta == 0) {
131.588 + for (int i = 0; i < len; i++) {
131.589 + y1 = (1 - q * a0) * y1 - (a0) * y2 + (a0) * buffer[i];
131.590 + y2 = (1 - q * a0) * y2 + (a0) * y1;
131.591 + buffer[i] = y2 * gain;
131.592 + }
131.593 + } else {
131.594 + for (int i = 0; i < len; i++) {
131.595 + a0 += a0_delta;
131.596 + q += q_delta;
131.597 + gain += gain_delta;
131.598 + y1 = (1 - q * a0) * y1 - (a0) * y2 + (a0) * buffer[i];
131.599 + y2 = (1 - q * a0) * y2 + (a0) * y1;
131.600 + buffer[i] = y2 * gain;
131.601 + }
131.602 + }
131.603 +
131.604 + if (Math.abs(y2) < 1.0E-8)
131.605 + y2 = 0;
131.606 + if (Math.abs(y1) < 1.0E-8)
131.607 + y1 = 0;
131.608 + this.y2 = y2;
131.609 + this.y1 = y1;
131.610 + }
131.611 +
131.612 + this.last_a0 = this.a0;
131.613 + this.last_q = this.q;
131.614 + this.last_gain = this.gain;
131.615 + this.last_wet = this.wet;
131.616 + }
131.617 +}
132.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
132.2 +++ b/src/share/classes/com/sun/media/sound/SoftInstrument.java Tue Feb 03 22:02:55 2009 -0800
132.3 @@ -0,0 +1,82 @@
132.4 +/*
132.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
132.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
132.7 + *
132.8 + * This code is free software; you can redistribute it and/or modify it
132.9 + * under the terms of the GNU General Public License version 2 only, as
132.10 + * published by the Free Software Foundation. Sun designates this
132.11 + * particular file as subject to the "Classpath" exception as provided
132.12 + * by Sun in the LICENSE file that accompanied this code.
132.13 + *
132.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
132.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
132.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
132.17 + * version 2 for more details (a copy is included in the LICENSE file that
132.18 + * accompanied this code).
132.19 + *
132.20 + * You should have received a copy of the GNU General Public License version
132.21 + * 2 along with this work; if not, write to the Free Software Foundation,
132.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
132.23 + *
132.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
132.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
132.26 + * have any questions.
132.27 + */
132.28 +package com.sun.media.sound;
132.29 +
132.30 +import javax.sound.midi.Instrument;
132.31 +import javax.sound.midi.MidiChannel;
132.32 +
132.33 +/**
132.34 + * Software synthesizer internal instrument.
132.35 + *
132.36 + * @author Karl Helgason
132.37 + */
132.38 +public class SoftInstrument extends Instrument {
132.39 +
132.40 + private SoftPerformer[] performers;
132.41 + private ModelPerformer[] modelperformers;
132.42 + private Object data;
132.43 + private ModelInstrument ins;
132.44 +
132.45 + public SoftInstrument(ModelInstrument ins) {
132.46 + super(ins.getSoundbank(), ins.getPatch(), ins.getName(),
132.47 + ins.getDataClass());
132.48 + data = ins.getData();
132.49 + this.ins = ins;
132.50 + initPerformers(((ModelInstrument)ins).getPerformers());
132.51 + }
132.52 +
132.53 + public SoftInstrument(ModelInstrument ins,
132.54 + ModelPerformer[] overrideperformers) {
132.55 + super(ins.getSoundbank(), ins.getPatch(), ins.getName(),
132.56 + ins.getDataClass());
132.57 + data = ins.getData();
132.58 + this.ins = ins;
132.59 + initPerformers(overrideperformers);
132.60 + }
132.61 +
132.62 + private void initPerformers(ModelPerformer[] modelperformers) {
132.63 + this.modelperformers = modelperformers;
132.64 + performers = new SoftPerformer[modelperformers.length];
132.65 + for (int i = 0; i < modelperformers.length; i++)
132.66 + performers[i] = new SoftPerformer(modelperformers[i]);
132.67 + }
132.68 +
132.69 + public ModelDirector getDirector(MidiChannel channel,
132.70 + ModelDirectedPlayer player) {
132.71 + return ins.getDirector(modelperformers, channel, player);
132.72 + }
132.73 +
132.74 + public ModelInstrument getSourceInstrument() {
132.75 + return ins;
132.76 + }
132.77 +
132.78 + public Object getData() {
132.79 + return data;
132.80 + }
132.81 +
132.82 + public SoftPerformer[] getPerformers() {
132.83 + return performers;
132.84 + }
132.85 +}
133.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
133.2 +++ b/src/share/classes/com/sun/media/sound/SoftJitterCorrector.java Tue Feb 03 22:02:55 2009 -0800
133.3 @@ -0,0 +1,276 @@
133.4 +/*
133.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
133.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
133.7 + *
133.8 + * This code is free software; you can redistribute it and/or modify it
133.9 + * under the terms of the GNU General Public License version 2 only, as
133.10 + * published by the Free Software Foundation. Sun designates this
133.11 + * particular file as subject to the "Classpath" exception as provided
133.12 + * by Sun in the LICENSE file that accompanied this code.
133.13 + *
133.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
133.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
133.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
133.17 + * version 2 for more details (a copy is included in the LICENSE file that
133.18 + * accompanied this code).
133.19 + *
133.20 + * You should have received a copy of the GNU General Public License version
133.21 + * 2 along with this work; if not, write to the Free Software Foundation,
133.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
133.23 + *
133.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
133.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
133.26 + * have any questions.
133.27 + */
133.28 +package com.sun.media.sound;
133.29 +
133.30 +import java.io.EOFException;
133.31 +import java.io.IOException;
133.32 +import java.io.InputStream;
133.33 +
133.34 +import javax.sound.sampled.AudioFormat;
133.35 +import javax.sound.sampled.AudioInputStream;
133.36 +
133.37 +/**
133.38 + * A jitter corrector to be used with SoftAudioPusher.
133.39 + *
133.40 + * @author Karl Helgason
133.41 + */
133.42 +public class SoftJitterCorrector extends AudioInputStream {
133.43 +
133.44 + private static class JitterStream extends InputStream {
133.45 +
133.46 + static int MAX_BUFFER_SIZE = 1048576;
133.47 + boolean active = true;
133.48 + Thread thread;
133.49 + AudioInputStream stream;
133.50 + // Cyclic buffer
133.51 + int writepos = 0;
133.52 + int readpos = 0;
133.53 + byte[][] buffers;
133.54 + Object buffers_mutex = new Object();
133.55 +
133.56 + // Adapative Drift Statistics
133.57 + int w_count = 1000;
133.58 + int w_min_tol = 2;
133.59 + int w_max_tol = 10;
133.60 + int w = 0;
133.61 + int w_min = -1;
133.62 + // Current read buffer
133.63 + int bbuffer_pos = 0;
133.64 + int bbuffer_max = 0;
133.65 + byte[] bbuffer = null;
133.66 +
133.67 + public byte[] nextReadBuffer() {
133.68 + synchronized (buffers_mutex) {
133.69 + if (writepos > readpos) {
133.70 + int w_m = writepos - readpos;
133.71 + if (w_m < w_min)
133.72 + w_min = w_m;
133.73 +
133.74 + int buffpos = readpos;
133.75 + readpos++;
133.76 + return buffers[buffpos % buffers.length];
133.77 + }
133.78 + w_min = -1;
133.79 + w = w_count - 1;
133.80 + }
133.81 + while (true) {
133.82 + try {
133.83 + Thread.sleep(1);
133.84 + } catch (InterruptedException e) {
133.85 + //e.printStackTrace();
133.86 + return null;
133.87 + }
133.88 + synchronized (buffers_mutex) {
133.89 + if (writepos > readpos) {
133.90 + w = 0;
133.91 + w_min = -1;
133.92 + w = w_count - 1;
133.93 + int buffpos = readpos;
133.94 + readpos++;
133.95 + return buffers[buffpos % buffers.length];
133.96 + }
133.97 + }
133.98 + }
133.99 + }
133.100 +
133.101 + public byte[] nextWriteBuffer() {
133.102 + synchronized (buffers_mutex) {
133.103 + return buffers[writepos % buffers.length];
133.104 + }
133.105 + }
133.106 +
133.107 + public void commit() {
133.108 + synchronized (buffers_mutex) {
133.109 + writepos++;
133.110 + if ((writepos - readpos) > buffers.length) {
133.111 + int newsize = (writepos - readpos) + 10;
133.112 + newsize = Math.max(buffers.length * 2, newsize);
133.113 + buffers = new byte[newsize][buffers[0].length];
133.114 + }
133.115 + }
133.116 + }
133.117 +
133.118 + public JitterStream(AudioInputStream s, int buffersize,
133.119 + int smallbuffersize) {
133.120 + this.w_count = 10 * (buffersize / smallbuffersize);
133.121 + if (w_count < 100)
133.122 + w_count = 100;
133.123 + this.buffers
133.124 + = new byte[(buffersize/smallbuffersize)+10][smallbuffersize];
133.125 + this.bbuffer_max = MAX_BUFFER_SIZE / smallbuffersize;
133.126 + this.stream = s;
133.127 +
133.128 +
133.129 + Runnable runnable = new Runnable() {
133.130 +
133.131 + public void run() {
133.132 + AudioFormat format = stream.getFormat();
133.133 + int bufflen = buffers[0].length;
133.134 + int frames = bufflen / format.getFrameSize();
133.135 + long nanos = (long) (frames * 1000000000.0
133.136 + / format.getSampleRate());
133.137 + long now = System.nanoTime();
133.138 + long next = now + nanos;
133.139 + int correction = 0;
133.140 + while (true) {
133.141 + synchronized (JitterStream.this) {
133.142 + if (!active)
133.143 + break;
133.144 + }
133.145 + int curbuffsize;
133.146 + synchronized (buffers) {
133.147 + curbuffsize = writepos - readpos;
133.148 + if (correction == 0) {
133.149 + w++;
133.150 + if (w_min != Integer.MAX_VALUE) {
133.151 + if (w == w_count) {
133.152 + correction = 0;
133.153 + if (w_min < w_min_tol) {
133.154 + correction = (w_min_tol + w_max_tol)
133.155 + / 2 - w_min;
133.156 + }
133.157 + if (w_min > w_max_tol) {
133.158 + correction = (w_min_tol + w_max_tol)
133.159 + / 2 - w_min;
133.160 + }
133.161 + w = 0;
133.162 + w_min = Integer.MAX_VALUE;
133.163 + }
133.164 + }
133.165 + }
133.166 + }
133.167 + while (curbuffsize > bbuffer_max) {
133.168 + synchronized (buffers) {
133.169 + curbuffsize = writepos - readpos;
133.170 + }
133.171 + synchronized (JitterStream.this) {
133.172 + if (!active)
133.173 + break;
133.174 + }
133.175 + try {
133.176 + Thread.sleep(1);
133.177 + } catch (InterruptedException e) {
133.178 + //e.printStackTrace();
133.179 + }
133.180 + }
133.181 +
133.182 + if (correction < 0)
133.183 + correction++;
133.184 + else {
133.185 + byte[] buff = nextWriteBuffer();
133.186 + try {
133.187 + int n = 0;
133.188 + while (n != buff.length) {
133.189 + int s = stream.read(buff, n, buff.length
133.190 + - n);
133.191 + if (s < 0)
133.192 + throw new EOFException();
133.193 + if (s == 0)
133.194 + Thread.yield();
133.195 + n += s;
133.196 + }
133.197 + } catch (IOException e1) {
133.198 + //e1.printStackTrace();
133.199 + }
133.200 + commit();
133.201 + }
133.202 +
133.203 + if (correction > 0) {
133.204 + correction--;
133.205 + next = System.nanoTime() + nanos;
133.206 + continue;
133.207 + }
133.208 + long wait = next - System.nanoTime();
133.209 + if (wait > 0) {
133.210 + try {
133.211 + Thread.sleep(wait / 1000000L);
133.212 + } catch (InterruptedException e) {
133.213 + //e.printStackTrace();
133.214 + }
133.215 + }
133.216 + next += nanos;
133.217 + }
133.218 + }
133.219 + };
133.220 +
133.221 + thread = new Thread(runnable);
133.222 + thread.setPriority(Thread.MAX_PRIORITY);
133.223 + thread.start();
133.224 + }
133.225 +
133.226 + public void close() throws IOException {
133.227 + synchronized (this) {
133.228 + active = false;
133.229 + }
133.230 + try {
133.231 + thread.join();
133.232 + } catch (InterruptedException e) {
133.233 + //e.printStackTrace();
133.234 + }
133.235 + stream.close();
133.236 + }
133.237 +
133.238 + public int read() throws IOException {
133.239 + byte[] b = new byte[1];
133.240 + if (read(b) == -1)
133.241 + return -1;
133.242 + return b[0] & 0xFF;
133.243 + }
133.244 +
133.245 + public void fillBuffer() {
133.246 + bbuffer = nextReadBuffer();
133.247 + bbuffer_pos = 0;
133.248 + }
133.249 +
133.250 + public int read(byte[] b, int off, int len) {
133.251 + if (bbuffer == null)
133.252 + fillBuffer();
133.253 + int bbuffer_len = bbuffer.length;
133.254 + int offlen = off + len;
133.255 + while (off < offlen) {
133.256 + if (available() == 0)
133.257 + fillBuffer();
133.258 + else {
133.259 + byte[] bbuffer = this.bbuffer;
133.260 + int bbuffer_pos = this.bbuffer_pos;
133.261 + while (off < offlen && bbuffer_pos < bbuffer_len)
133.262 + b[off++] = bbuffer[bbuffer_pos++];
133.263 + this.bbuffer_pos = bbuffer_pos;
133.264 + }
133.265 + }
133.266 + return len;
133.267 + }
133.268 +
133.269 + public int available() {
133.270 + return bbuffer.length - bbuffer_pos;
133.271 + }
133.272 + }
133.273 +
133.274 + public SoftJitterCorrector(AudioInputStream stream, int buffersize,
133.275 + int smallbuffersize) {
133.276 + super(new JitterStream(stream, buffersize, smallbuffersize),
133.277 + stream.getFormat(), stream.getFrameLength());
133.278 + }
133.279 +}
134.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
134.2 +++ b/src/share/classes/com/sun/media/sound/SoftLanczosResampler.java Tue Feb 03 22:02:55 2009 -0800
134.3 @@ -0,0 +1,118 @@
134.4 +/*
134.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
134.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
134.7 + *
134.8 + * This code is free software; you can redistribute it and/or modify it
134.9 + * under the terms of the GNU General Public License version 2 only, as
134.10 + * published by the Free Software Foundation. Sun designates this
134.11 + * particular file as subject to the "Classpath" exception as provided
134.12 + * by Sun in the LICENSE file that accompanied this code.
134.13 + *
134.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
134.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
134.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
134.17 + * version 2 for more details (a copy is included in the LICENSE file that
134.18 + * accompanied this code).
134.19 + *
134.20 + * You should have received a copy of the GNU General Public License version
134.21 + * 2 along with this work; if not, write to the Free Software Foundation,
134.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
134.23 + *
134.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
134.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
134.26 + * have any questions.
134.27 + */
134.28 +package com.sun.media.sound;
134.29 +
134.30 +/**
134.31 + * Lanczos interpolation resampler.
134.32 + *
134.33 + * @author Karl Helgason
134.34 + */
134.35 +public class SoftLanczosResampler extends SoftAbstractResampler {
134.36 +
134.37 + float[][] sinc_table;
134.38 + int sinc_table_fsize = 2000;
134.39 + int sinc_table_size = 5;
134.40 + int sinc_table_center = sinc_table_size / 2;
134.41 +
134.42 + public SoftLanczosResampler() {
134.43 + super();
134.44 + sinc_table = new float[sinc_table_fsize][];
134.45 + for (int i = 0; i < sinc_table_fsize; i++) {
134.46 + sinc_table[i] = sincTable(sinc_table_size, -i
134.47 + / ((float) sinc_table_fsize));
134.48 + }
134.49 + }
134.50 +
134.51 + // Normalized sinc function
134.52 + public static double sinc(double x) {
134.53 + return (x == 0.0) ? 1.0 : Math.sin(Math.PI * x) / (Math.PI * x);
134.54 + }
134.55 +
134.56 + // Generate sinc table
134.57 + public static float[] sincTable(int size, float offset) {
134.58 + int center = size / 2;
134.59 + float[] w = new float[size];
134.60 + for (int k = 0; k < size; k++) {
134.61 + float x = (-center + k + offset);
134.62 + if (x < -2 || x > 2)
134.63 + w[k] = 0;
134.64 + else if (x == 0)
134.65 + w[k] = 1;
134.66 + else {
134.67 + w[k] = (float)(2.0 * Math.sin(Math.PI * x)
134.68 + * Math.sin(Math.PI * x / 2.0)
134.69 + / ((Math.PI * x) * (Math.PI * x)));
134.70 + }
134.71 + }
134.72 + return w;
134.73 + }
134.74 +
134.75 + public int getPadding() // must be at least half of sinc_table_size
134.76 + {
134.77 + return sinc_table_size / 2 + 2;
134.78 + }
134.79 +
134.80 + public void interpolate(float[] in, float[] in_offset, float in_end,
134.81 + float[] startpitch, float pitchstep, float[] out, int[] out_offset,
134.82 + int out_end) {
134.83 + float pitch = startpitch[0];
134.84 + float ix = in_offset[0];
134.85 + int ox = out_offset[0];
134.86 + float ix_end = in_end;
134.87 + int ox_end = out_end;
134.88 +
134.89 + if (pitchstep == 0) {
134.90 + while (ix < ix_end && ox < ox_end) {
134.91 + int iix = (int) ix;
134.92 + float[] sinc_table
134.93 + = this.sinc_table[(int) ((ix - iix) * sinc_table_fsize)];
134.94 + int xx = iix - sinc_table_center;
134.95 + float y = 0;
134.96 + for (int i = 0; i < sinc_table_size; i++, xx++)
134.97 + y += in[xx] * sinc_table[i];
134.98 + out[ox++] = y;
134.99 + ix += pitch;
134.100 + }
134.101 + } else {
134.102 + while (ix < ix_end && ox < ox_end) {
134.103 + int iix = (int) ix;
134.104 + float[] sinc_table
134.105 + = this.sinc_table[(int) ((ix - iix) * sinc_table_fsize)];
134.106 + int xx = iix - sinc_table_center;
134.107 + float y = 0;
134.108 + for (int i = 0; i < sinc_table_size; i++, xx++)
134.109 + y += in[xx] * sinc_table[i];
134.110 + out[ox++] = y;
134.111 +
134.112 + ix += pitch;
134.113 + pitch += pitchstep;
134.114 + }
134.115 + }
134.116 + in_offset[0] = ix;
134.117 + out_offset[0] = ox;
134.118 + startpitch[0] = pitch;
134.119 +
134.120 + }
134.121 +}
135.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
135.2 +++ b/src/share/classes/com/sun/media/sound/SoftLimiter.java Tue Feb 03 22:02:55 2009 -0800
135.3 @@ -0,0 +1,191 @@
135.4 +/*
135.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
135.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
135.7 + *
135.8 + * This code is free software; you can redistribute it and/or modify it
135.9 + * under the terms of the GNU General Public License version 2 only, as
135.10 + * published by the Free Software Foundation. Sun designates this
135.11 + * particular file as subject to the "Classpath" exception as provided
135.12 + * by Sun in the LICENSE file that accompanied this code.
135.13 + *
135.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
135.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
135.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
135.17 + * version 2 for more details (a copy is included in the LICENSE file that
135.18 + * accompanied this code).
135.19 + *
135.20 + * You should have received a copy of the GNU General Public License version
135.21 + * 2 along with this work; if not, write to the Free Software Foundation,
135.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
135.23 + *
135.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
135.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
135.26 + * have any questions.
135.27 + */
135.28 +package com.sun.media.sound;
135.29 +
135.30 +/**
135.31 + * A simple look-ahead volume limiter with very fast attack and fast release.
135.32 + * This filter is used for preventing clipping.
135.33 + *
135.34 + * @author Karl Helgason
135.35 + */
135.36 +public class SoftLimiter implements SoftAudioProcessor {
135.37 +
135.38 + float lastmax = 0;
135.39 + float gain = 1;
135.40 + float[] temp_bufferL;
135.41 + float[] temp_bufferR;
135.42 + boolean mix = false;
135.43 + SoftAudioBuffer bufferL;
135.44 + SoftAudioBuffer bufferR;
135.45 + SoftAudioBuffer bufferLout;
135.46 + SoftAudioBuffer bufferRout;
135.47 + float controlrate;
135.48 +
135.49 + public void init(float samplerate, float controlrate) {
135.50 + this.controlrate = controlrate;
135.51 + }
135.52 +
135.53 + public void setInput(int pin, SoftAudioBuffer input) {
135.54 + if (pin == 0)
135.55 + bufferL = input;
135.56 + if (pin == 1)
135.57 + bufferR = input;
135.58 + }
135.59 +
135.60 + public void setOutput(int pin, SoftAudioBuffer output) {
135.61 + if (pin == 0)
135.62 + bufferLout = output;
135.63 + if (pin == 1)
135.64 + bufferRout = output;
135.65 + }
135.66 +
135.67 + public void setMixMode(boolean mix) {
135.68 + this.mix = mix;
135.69 + }
135.70 +
135.71 + public void globalParameterControlChange(int[] slothpath, long param,
135.72 + long value) {
135.73 + }
135.74 +
135.75 + double silentcounter = 0;
135.76 +
135.77 + public void processAudio() {
135.78 + if (this.bufferL.isSilent()
135.79 + && (this.bufferR == null || this.bufferR.isSilent())) {
135.80 + silentcounter += 1 / controlrate;
135.81 +
135.82 + if (silentcounter > 60) {
135.83 + if (!mix) {
135.84 + bufferLout.clear();
135.85 + bufferRout.clear();
135.86 + }
135.87 + return;
135.88 + }
135.89 + } else
135.90 + silentcounter = 0;
135.91 +
135.92 + float[] bufferL = this.bufferL.array();
135.93 + float[] bufferR = this.bufferR == null ? null : this.bufferR.array();
135.94 + float[] bufferLout = this.bufferLout.array();
135.95 + float[] bufferRout = this.bufferRout == null
135.96 + ? null : this.bufferRout.array();
135.97 +
135.98 + if (temp_bufferL == null || temp_bufferL.length < bufferL.length)
135.99 + temp_bufferL = new float[bufferL.length];
135.100 + if (bufferR != null)
135.101 + if (temp_bufferR == null || temp_bufferR.length < bufferR.length)
135.102 + temp_bufferR = new float[bufferR.length];
135.103 +
135.104 + float max = 0;
135.105 + int len = bufferL.length;
135.106 +
135.107 + if (bufferR == null) {
135.108 + for (int i = 0; i < len; i++) {
135.109 + if (bufferL[i] > max)
135.110 + max = bufferL[i];
135.111 + if (-bufferL[i] > max)
135.112 + max = -bufferL[i];
135.113 + }
135.114 + } else {
135.115 + for (int i = 0; i < len; i++) {
135.116 + if (bufferL[i] > max)
135.117 + max = bufferL[i];
135.118 + if (bufferR[i] > max)
135.119 + max = bufferR[i];
135.120 + if (-bufferL[i] > max)
135.121 + max = -bufferL[i];
135.122 + if (-bufferR[i] > max)
135.123 + max = -bufferR[i];
135.124 + }
135.125 + }
135.126 +
135.127 + float lmax = lastmax;
135.128 + lastmax = max;
135.129 + if (lmax > max)
135.130 + max = lmax;
135.131 +
135.132 + float newgain = 1;
135.133 + if (max > 0.99f)
135.134 + newgain = 0.99f / max;
135.135 + else
135.136 + newgain = 1;
135.137 +
135.138 + if (newgain > gain)
135.139 + newgain = (newgain + gain * 9) / 10f;
135.140 +
135.141 + float gaindelta = (newgain - gain) / len;
135.142 + if (mix) {
135.143 + if (bufferR == null) {
135.144 + for (int i = 0; i < len; i++) {
135.145 + gain += gaindelta;
135.146 + float bL = bufferL[i];
135.147 + float tL = temp_bufferL[i];
135.148 + temp_bufferL[i] = bL;
135.149 + bufferLout[i] += tL * gain;
135.150 + }
135.151 + } else {
135.152 + for (int i = 0; i < len; i++) {
135.153 + gain += gaindelta;
135.154 + float bL = bufferL[i];
135.155 + float bR = bufferR[i];
135.156 + float tL = temp_bufferL[i];
135.157 + float tR = temp_bufferR[i];
135.158 + temp_bufferL[i] = bL;
135.159 + temp_bufferR[i] = bR;
135.160 + bufferLout[i] += tL * gain;
135.161 + bufferRout[i] += tR * gain;
135.162 + }
135.163 + }
135.164 +
135.165 + } else {
135.166 + if (bufferR == null) {
135.167 + for (int i = 0; i < len; i++) {
135.168 + gain += gaindelta;
135.169 + float bL = bufferL[i];
135.170 + float tL = temp_bufferL[i];
135.171 + temp_bufferL[i] = bL;
135.172 + bufferLout[i] = tL * gain;
135.173 + }
135.174 + } else {
135.175 + for (int i = 0; i < len; i++) {
135.176 + gain += gaindelta;
135.177 + float bL = bufferL[i];
135.178 + float bR = bufferR[i];
135.179 + float tL = temp_bufferL[i];
135.180 + float tR = temp_bufferR[i];
135.181 + temp_bufferL[i] = bL;
135.182 + temp_bufferR[i] = bR;
135.183 + bufferLout[i] = tL * gain;
135.184 + bufferRout[i] = tR * gain;
135.185 + }
135.186 + }
135.187 +
135.188 + }
135.189 + gain = newgain;
135.190 + }
135.191 +
135.192 + public void processControlLogic() {
135.193 + }
135.194 +}
136.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
136.2 +++ b/src/share/classes/com/sun/media/sound/SoftLinearResampler.java Tue Feb 03 22:02:55 2009 -0800
136.3 @@ -0,0 +1,70 @@
136.4 +/*
136.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
136.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
136.7 + *
136.8 + * This code is free software; you can redistribute it and/or modify it
136.9 + * under the terms of the GNU General Public License version 2 only, as
136.10 + * published by the Free Software Foundation. Sun designates this
136.11 + * particular file as subject to the "Classpath" exception as provided
136.12 + * by Sun in the LICENSE file that accompanied this code.
136.13 + *
136.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
136.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
136.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
136.17 + * version 2 for more details (a copy is included in the LICENSE file that
136.18 + * accompanied this code).
136.19 + *
136.20 + * You should have received a copy of the GNU General Public License version
136.21 + * 2 along with this work; if not, write to the Free Software Foundation,
136.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
136.23 + *
136.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
136.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
136.26 + * have any questions.
136.27 + */
136.28 +package com.sun.media.sound;
136.29 +
136.30 +/**
136.31 + * A resampler that uses first-order (linear) interpolation.
136.32 + *
136.33 + * @author Karl Helgason
136.34 + */
136.35 +public class SoftLinearResampler extends SoftAbstractResampler {
136.36 +
136.37 + public int getPadding() {
136.38 + return 2;
136.39 + }
136.40 +
136.41 + public void interpolate(float[] in, float[] in_offset, float in_end,
136.42 + float[] startpitch, float pitchstep, float[] out, int[] out_offset,
136.43 + int out_end) {
136.44 +
136.45 + float pitch = startpitch[0];
136.46 + float ix = in_offset[0];
136.47 + int ox = out_offset[0];
136.48 + float ix_end = in_end;
136.49 + int ox_end = out_end;
136.50 + if (pitchstep == 0f) {
136.51 + while (ix < ix_end && ox < ox_end) {
136.52 + int iix = (int) ix;
136.53 + float fix = ix - iix;
136.54 + float i = in[iix];
136.55 + out[ox++] = i + (in[iix + 1] - i) * fix;
136.56 + ix += pitch;
136.57 + }
136.58 + } else {
136.59 + while (ix < ix_end && ox < ox_end) {
136.60 + int iix = (int) ix;
136.61 + float fix = ix - iix;
136.62 + float i = in[iix];
136.63 + out[ox++] = i + (in[iix + 1] - i) * fix;
136.64 + ix += pitch;
136.65 + pitch += pitchstep;
136.66 + }
136.67 + }
136.68 + in_offset[0] = ix;
136.69 + out_offset[0] = ox;
136.70 + startpitch[0] = pitch;
136.71 +
136.72 + }
136.73 +}
137.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
137.2 +++ b/src/share/classes/com/sun/media/sound/SoftLinearResampler2.java Tue Feb 03 22:02:55 2009 -0800
137.3 @@ -0,0 +1,108 @@
137.4 +/*
137.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
137.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
137.7 + *
137.8 + * This code is free software; you can redistribute it and/or modify it
137.9 + * under the terms of the GNU General Public License version 2 only, as
137.10 + * published by the Free Software Foundation. Sun designates this
137.11 + * particular file as subject to the "Classpath" exception as provided
137.12 + * by Sun in the LICENSE file that accompanied this code.
137.13 + *
137.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
137.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
137.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
137.17 + * version 2 for more details (a copy is included in the LICENSE file that
137.18 + * accompanied this code).
137.19 + *
137.20 + * You should have received a copy of the GNU General Public License version
137.21 + * 2 along with this work; if not, write to the Free Software Foundation,
137.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
137.23 + *
137.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
137.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
137.26 + * have any questions.
137.27 + */
137.28 +package com.sun.media.sound;
137.29 +
137.30 +/**
137.31 + * A resampler that uses first-order (linear) interpolation.
137.32 + *
137.33 + * This one doesn't perform float to int casting inside the processing loop.
137.34 + *
137.35 + * @author Karl Helgason
137.36 + */
137.37 +public class SoftLinearResampler2 extends SoftAbstractResampler {
137.38 +
137.39 + public int getPadding() {
137.40 + return 2;
137.41 + }
137.42 +
137.43 + public void interpolate(float[] in, float[] in_offset, float in_end,
137.44 + float[] startpitch, float pitchstep, float[] out, int[] out_offset,
137.45 + int out_end) {
137.46 +
137.47 + float pitch = startpitch[0];
137.48 + float ix = in_offset[0];
137.49 + int ox = out_offset[0];
137.50 + float ix_end = in_end;
137.51 + int ox_end = out_end;
137.52 +
137.53 + // Check if we have do anything
137.54 + if (!(ix < ix_end && ox < ox_end))
137.55 + return;
137.56 +
137.57 + // 15 bit shift was choosed because
137.58 + // it resulted in no drift between p_ix and ix.
137.59 + int p_ix = (int) (ix * (1 << 15));
137.60 + int p_ix_end = (int) (ix_end * (1 << 15));
137.61 + int p_pitch = (int) (pitch * (1 << 15));
137.62 + // Pitch needs to recalculated
137.63 + // to ensure no drift between p_ix and ix.
137.64 + pitch = p_pitch * (1f / (1 << 15));
137.65 +
137.66 + if (pitchstep == 0f) {
137.67 +
137.68 + // To reduce
137.69 + // while (p_ix < p_ix_end && ox < ox_end)
137.70 + // into
137.71 + // while (ox < ox_end)
137.72 + // We need to calculate new ox_end value.
137.73 + int p_ix_len = p_ix_end - p_ix;
137.74 + int p_mod = p_ix_len % p_pitch;
137.75 + if (p_mod != 0)
137.76 + p_ix_len += p_pitch - p_mod;
137.77 + int ox_end2 = ox + p_ix_len / p_pitch;
137.78 + if (ox_end2 < ox_end)
137.79 + ox_end = ox_end2;
137.80 +
137.81 + while (ox < ox_end) {
137.82 + int iix = p_ix >> 15;
137.83 + float fix = ix - iix;
137.84 + float i = in[iix];
137.85 + out[ox++] = i + (in[iix + 1] - i) * fix;
137.86 + p_ix += p_pitch;
137.87 + ix += pitch;
137.88 + }
137.89 +
137.90 + } else {
137.91 +
137.92 + int p_pitchstep = (int) (pitchstep * (1 << 15));
137.93 + pitchstep = p_pitchstep * (1f / (1 << 15));
137.94 +
137.95 + while (p_ix < p_ix_end && ox < ox_end) {
137.96 + int iix = p_ix >> 15;
137.97 + float fix = ix - iix;
137.98 + float i = in[iix];
137.99 + out[ox++] = i + (in[iix + 1] - i) * fix;
137.100 + ix += pitch;
137.101 + p_ix += p_pitch;
137.102 + pitch += pitchstep;
137.103 + p_pitch += p_pitchstep;
137.104 + }
137.105 + }
137.106 + in_offset[0] = ix;
137.107 + out_offset[0] = ox;
137.108 + startpitch[0] = pitch;
137.109 +
137.110 + }
137.111 +}
138.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
138.2 +++ b/src/share/classes/com/sun/media/sound/SoftLowFrequencyOscillator.java Tue Feb 03 22:02:55 2009 -0800
138.3 @@ -0,0 +1,122 @@
138.4 +/*
138.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
138.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
138.7 + *
138.8 + * This code is free software; you can redistribute it and/or modify it
138.9 + * under the terms of the GNU General Public License version 2 only, as
138.10 + * published by the Free Software Foundation. Sun designates this
138.11 + * particular file as subject to the "Classpath" exception as provided
138.12 + * by Sun in the LICENSE file that accompanied this code.
138.13 + *
138.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
138.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
138.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
138.17 + * version 2 for more details (a copy is included in the LICENSE file that
138.18 + * accompanied this code).
138.19 + *
138.20 + * You should have received a copy of the GNU General Public License version
138.21 + * 2 along with this work; if not, write to the Free Software Foundation,
138.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
138.23 + *
138.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
138.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
138.26 + * have any questions.
138.27 + */
138.28 +package com.sun.media.sound;
138.29 +
138.30 +/**
138.31 + * LFO control signal generator.
138.32 + *
138.33 + * @author Karl Helgason
138.34 + */
138.35 +public class SoftLowFrequencyOscillator implements SoftProcess {
138.36 +
138.37 + private int max_count = 10;
138.38 + private int used_count = 0;
138.39 + private double[][] out = new double[max_count][1];
138.40 + private double[][] delay = new double[max_count][1];
138.41 + private double[][] delay2 = new double[max_count][1];
138.42 + private double[][] freq = new double[max_count][1];
138.43 + private int[] delay_counter = new int[max_count];
138.44 + private double[] sin_phase = new double[max_count];
138.45 + private double[] sin_stepfreq = new double[max_count];
138.46 + private double[] sin_step = new double[max_count];
138.47 + private double control_time = 0;
138.48 + private double sin_factor = 0;
138.49 + private static double PI2 = 2.0 * Math.PI;
138.50 +
138.51 + public void reset() {
138.52 + for (int i = 0; i < used_count; i++) {
138.53 + out[i][0] = 0;
138.54 + delay[i][0] = 0;
138.55 + delay2[i][0] = 0;
138.56 + freq[i][0] = 0;
138.57 + delay_counter[i] = 0;
138.58 + sin_phase[i] = 0;
138.59 + sin_stepfreq[i] = 0;
138.60 + sin_step[i] = 0;
138.61 + }
138.62 + used_count = 0;
138.63 + }
138.64 +
138.65 + public void init(SoftSynthesizer synth) {
138.66 + control_time = 1.0 / synth.getControlRate();
138.67 + sin_factor = control_time * 2 * Math.PI;
138.68 + for (int i = 0; i < used_count; i++) {
138.69 + delay_counter[i] = (int)(Math.pow(2,
138.70 + this.delay[i][0] / 1200.0) / control_time);
138.71 + delay_counter[i] += (int)(delay2[i][0] / (control_time * 1000));
138.72 + }
138.73 + processControlLogic();
138.74 + }
138.75 +
138.76 + public void processControlLogic() {
138.77 + for (int i = 0; i < used_count; i++) {
138.78 + if (delay_counter[i] > 0) {
138.79 + delay_counter[i]--;
138.80 + out[i][0] = 0.5;
138.81 + } else {
138.82 + double f = freq[i][0];
138.83 +
138.84 + if (sin_stepfreq[i] != f) {
138.85 + sin_stepfreq[i] = f;
138.86 + double fr = 440.0 * Math.exp(
138.87 + (f - 6900.0) * (Math.log(2) / 1200.0));
138.88 + sin_step[i] = fr * sin_factor;
138.89 + }
138.90 + /*
138.91 + double fr = 440.0 * Math.pow(2.0,
138.92 + (freq[i][0] - 6900.0) / 1200.0);
138.93 + sin_phase[i] += fr * sin_factor;
138.94 + */
138.95 + /*
138.96 + sin_phase[i] += sin_step[i];
138.97 + while (sin_phase[i] > PI2)
138.98 + sin_phase[i] -= PI2;
138.99 + out[i][0] = 0.5 + Math.sin(sin_phase[i]) * 0.5;
138.100 + */
138.101 + double p = sin_phase[i];
138.102 + p += sin_step[i];
138.103 + while (p > PI2)
138.104 + p -= PI2;
138.105 + out[i][0] = 0.5 + Math.sin(p) * 0.5;
138.106 + sin_phase[i] = p;
138.107 +
138.108 + }
138.109 + }
138.110 + }
138.111 +
138.112 + public double[] get(int instance, String name) {
138.113 + if (instance >= used_count)
138.114 + used_count = instance + 1;
138.115 + if (name == null)
138.116 + return out[instance];
138.117 + if (name.equals("delay"))
138.118 + return delay[instance];
138.119 + if (name.equals("delay2"))
138.120 + return delay2[instance];
138.121 + if (name.equals("freq"))
138.122 + return freq[instance];
138.123 + return null;
138.124 + }
138.125 +}
139.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
139.2 +++ b/src/share/classes/com/sun/media/sound/SoftMainMixer.java Tue Feb 03 22:02:55 2009 -0800
139.3 @@ -0,0 +1,982 @@
139.4 +/*
139.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
139.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
139.7 + *
139.8 + * This code is free software; you can redistribute it and/or modify it
139.9 + * under the terms of the GNU General Public License version 2 only, as
139.10 + * published by the Free Software Foundation. Sun designates this
139.11 + * particular file as subject to the "Classpath" exception as provided
139.12 + * by Sun in the LICENSE file that accompanied this code.
139.13 + *
139.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
139.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
139.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
139.17 + * version 2 for more details (a copy is included in the LICENSE file that
139.18 + * accompanied this code).
139.19 + *
139.20 + * You should have received a copy of the GNU General Public License version
139.21 + * 2 along with this work; if not, write to the Free Software Foundation,
139.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
139.23 + *
139.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
139.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
139.26 + * have any questions.
139.27 + */
139.28 +package com.sun.media.sound;
139.29 +
139.30 +import java.io.IOException;
139.31 +import java.io.InputStream;
139.32 +import java.util.Arrays;
139.33 +import java.util.HashSet;
139.34 +import java.util.Iterator;
139.35 +import java.util.Set;
139.36 +import java.util.TreeMap;
139.37 +import java.util.Map.Entry;
139.38 +
139.39 +import javax.sound.midi.MidiMessage;
139.40 +import javax.sound.midi.Patch;
139.41 +import javax.sound.midi.ShortMessage;
139.42 +import javax.sound.sampled.AudioInputStream;
139.43 +import javax.sound.sampled.AudioSystem;
139.44 +
139.45 +/**
139.46 + * Software synthesizer main audio mixer.
139.47 + *
139.48 + * @author Karl Helgason
139.49 + */
139.50 +public class SoftMainMixer {
139.51 +
139.52 + public final static int CHANNEL_LEFT = 0;
139.53 + public final static int CHANNEL_RIGHT = 1;
139.54 + public final static int CHANNEL_EFFECT1 = 2;
139.55 + public final static int CHANNEL_EFFECT2 = 3;
139.56 + public final static int CHANNEL_EFFECT3 = 4;
139.57 + public final static int CHANNEL_EFFECT4 = 5;
139.58 + public final static int CHANNEL_LEFT_DRY = 10;
139.59 + public final static int CHANNEL_RIGHT_DRY = 11;
139.60 + public final static int CHANNEL_SCRATCH1 = 12;
139.61 + public final static int CHANNEL_SCRATCH2 = 13;
139.62 + public final static int CHANNEL_CHANNELMIXER_LEFT = 14;
139.63 + public final static int CHANNEL_CHANNELMIXER_RIGHT = 15;
139.64 + protected boolean active_sensing_on = false;
139.65 + private long msec_last_activity = -1;
139.66 + private boolean pusher_silent = false;
139.67 + private int pusher_silent_count = 0;
139.68 + private long msec_pos = 0;
139.69 + protected boolean readfully = true;
139.70 + private Object control_mutex;
139.71 + private SoftSynthesizer synth;
139.72 + private int nrofchannels = 2;
139.73 + private SoftVoice[] voicestatus = null;
139.74 + private SoftAudioBuffer[] buffers;
139.75 + private SoftReverb reverb;
139.76 + private SoftAudioProcessor chorus;
139.77 + private SoftAudioProcessor agc;
139.78 + private long msec_buffer_len = 0;
139.79 + protected TreeMap<Long, Object> midimessages = new TreeMap<Long, Object>();
139.80 + double last_volume_left = 1.0;
139.81 + double last_volume_right = 1.0;
139.82 + private double[] co_master_balance = new double[1];
139.83 + private double[] co_master_volume = new double[1];
139.84 + private double[] co_master_coarse_tuning = new double[1];
139.85 + private double[] co_master_fine_tuning = new double[1];
139.86 + private AudioInputStream ais;
139.87 + private Set<ModelChannelMixer> registeredMixers = null;
139.88 + private Set<ModelChannelMixer> stoppedMixers = null;
139.89 + private ModelChannelMixer[] cur_registeredMixers = null;
139.90 + protected SoftControl co_master = new SoftControl() {
139.91 +
139.92 + double[] balance = co_master_balance;
139.93 + double[] volume = co_master_volume;
139.94 + double[] coarse_tuning = co_master_coarse_tuning;
139.95 + double[] fine_tuning = co_master_fine_tuning;
139.96 +
139.97 + public double[] get(int instance, String name) {
139.98 + if (name == null)
139.99 + return null;
139.100 + if (name.equals("balance"))
139.101 + return balance;
139.102 + if (name.equals("volume"))
139.103 + return volume;
139.104 + if (name.equals("coarse_tuning"))
139.105 + return coarse_tuning;
139.106 + if (name.equals("fine_tuning"))
139.107 + return fine_tuning;
139.108 + return null;
139.109 + }
139.110 + };
139.111 +
139.112 + private void processSystemExclusiveMessage(byte[] data) {
139.113 + synchronized (synth.control_mutex) {
139.114 + activity();
139.115 +
139.116 + // Universal Non-Real-Time SysEx
139.117 + if ((data[1] & 0xFF) == 0x7E) {
139.118 + int deviceID = data[2] & 0xFF;
139.119 + if (deviceID == 0x7F || deviceID == synth.getDeviceID()) {
139.120 + int subid1 = data[3] & 0xFF;
139.121 + int subid2;
139.122 + switch (subid1) {
139.123 + case 0x08: // MIDI Tuning Standard
139.124 + subid2 = data[4] & 0xFF;
139.125 + switch (subid2) {
139.126 + case 0x01: // BULK TUNING DUMP
139.127 + {
139.128 + // http://www.midi.org/about-midi/tuning.shtml
139.129 + SoftTuning tuning = synth.getTuning(new Patch(0,
139.130 + data[5] & 0xFF));
139.131 + tuning.load(data);
139.132 + break;
139.133 + }
139.134 + case 0x04: // KEY-BASED TUNING DUMP
139.135 + case 0x05: // SCALE/OCTAVE TUNING DUMP, 1 byte format
139.136 + case 0x06: // SCALE/OCTAVE TUNING DUMP, 2 byte format
139.137 + case 0x07: // SINGLE NOTE TUNING CHANGE (NON REAL-TIME)
139.138 + // (BANK)
139.139 + {
139.140 + // http://www.midi.org/about-midi/tuning_extens.shtml
139.141 + SoftTuning tuning = synth.getTuning(new Patch(
139.142 + data[5] & 0xFF, data[6] & 0xFF));
139.143 + tuning.load(data);
139.144 + break;
139.145 + }
139.146 + case 0x08: // scale/octave tuning 1-byte form (Non
139.147 + // Real-Time)
139.148 + case 0x09: // scale/octave tuning 2-byte form (Non
139.149 + // Real-Time)
139.150 + {
139.151 + // http://www.midi.org/about-midi/tuning-scale.shtml
139.152 + SoftTuning tuning = new SoftTuning(data);
139.153 + int channelmask = (data[5] & 0xFF) * 16384
139.154 + + (data[6] & 0xFF) * 128 + (data[7] & 0xFF);
139.155 + SoftChannel[] channels = synth.channels;
139.156 + for (int i = 0; i < channels.length; i++)
139.157 + if ((channelmask & (1 << i)) != 0)
139.158 + channels[i].tuning = tuning;
139.159 + break;
139.160 + }
139.161 + default:
139.162 + break;
139.163 + }
139.164 + break;
139.165 + case 0x09: // General Midi Message
139.166 + subid2 = data[4] & 0xFF;
139.167 + switch (subid2) {
139.168 + case 0x01: // General Midi 1 On
139.169 + synth.setGeneralMidiMode(1);
139.170 + reset();
139.171 + break;
139.172 + case 0x02: // General Midi Off
139.173 + synth.setGeneralMidiMode(0);
139.174 + reset();
139.175 + break;
139.176 + case 0x03: // General MidI Level 2 On
139.177 + synth.setGeneralMidiMode(2);
139.178 + reset();
139.179 + break;
139.180 + default:
139.181 + break;
139.182 + }
139.183 + break;
139.184 + case 0x0A: // DLS Message
139.185 + subid2 = data[4] & 0xFF;
139.186 + switch (subid2) {
139.187 + case 0x01: // DLS On
139.188 + if (synth.getGeneralMidiMode() == 0)
139.189 + synth.setGeneralMidiMode(1);
139.190 + synth.voice_allocation_mode = 1;
139.191 + reset();
139.192 + break;
139.193 + case 0x02: // DLS Off
139.194 + synth.setGeneralMidiMode(0);
139.195 + synth.voice_allocation_mode = 0;
139.196 + reset();
139.197 + break;
139.198 + case 0x03: // DLS Static Voice Allocation Off
139.199 + synth.voice_allocation_mode = 0;
139.200 + break;
139.201 + case 0x04: // DLS Static Voice Allocation On
139.202 + synth.voice_allocation_mode = 1;
139.203 + break;
139.204 + default:
139.205 + break;
139.206 + }
139.207 + break;
139.208 +
139.209 + default:
139.210 + break;
139.211 + }
139.212 + }
139.213 + }
139.214 +
139.215 + // Universal Real-Time SysEx
139.216 + if ((data[1] & 0xFF) == 0x7F) {
139.217 + int deviceID = data[2] & 0xFF;
139.218 + if (deviceID == 0x7F || deviceID == synth.getDeviceID()) {
139.219 + int subid1 = data[3] & 0xFF;
139.220 + int subid2;
139.221 + switch (subid1) {
139.222 + case 0x04: // Device Control
139.223 +
139.224 + subid2 = data[4] & 0xFF;
139.225 + switch (subid2) {
139.226 + case 0x01: // Master Volume
139.227 + case 0x02: // Master Balane
139.228 + case 0x03: // Master fine tuning
139.229 + case 0x04: // Master coarse tuning
139.230 + int val = (data[5] & 0x7F)
139.231 + + ((data[6] & 0x7F) * 128);
139.232 + if (subid2 == 0x01)
139.233 + setVolume(val);
139.234 + else if (subid2 == 0x02)
139.235 + setBalance(val);
139.236 + else if (subid2 == 0x03)
139.237 + setFineTuning(val);
139.238 + else if (subid2 == 0x04)
139.239 + setCoarseTuning(val);
139.240 + break;
139.241 + case 0x05: // Global Parameter Control
139.242 + int ix = 5;
139.243 + int slotPathLen = (data[ix++] & 0xFF);
139.244 + int paramWidth = (data[ix++] & 0xFF);
139.245 + int valueWidth = (data[ix++] & 0xFF);
139.246 + int[] slotPath = new int[slotPathLen];
139.247 + for (int i = 0; i < slotPathLen; i++) {
139.248 + int msb = (data[ix++] & 0xFF);
139.249 + int lsb = (data[ix++] & 0xFF);
139.250 + slotPath[i] = msb * 128 + lsb;
139.251 + }
139.252 + int paramCount = (data.length - 1 - ix)
139.253 + / (paramWidth + valueWidth);
139.254 + long[] params = new long[paramCount];
139.255 + long[] values = new long[paramCount];
139.256 + for (int i = 0; i < paramCount; i++) {
139.257 + values[i] = 0;
139.258 + for (int j = 0; j < paramWidth; j++)
139.259 + params[i] = params[i] * 128
139.260 + + (data[ix++] & 0xFF);
139.261 + for (int j = 0; j < valueWidth; j++)
139.262 + values[i] = values[i] * 128
139.263 + + (data[ix++] & 0xFF);
139.264 +
139.265 + }
139.266 + globalParameterControlChange(slotPath, params, values);
139.267 + break;
139.268 + default:
139.269 + break;
139.270 + }
139.271 + break;
139.272 +
139.273 + case 0x08: // MIDI Tuning Standard
139.274 + subid2 = data[4] & 0xFF;
139.275 + switch (subid2) {
139.276 + case 0x02: // SINGLE NOTE TUNING CHANGE (REAL-TIME)
139.277 + {
139.278 + // http://www.midi.org/about-midi/tuning.shtml
139.279 + SoftTuning tuning = synth.getTuning(new Patch(0,
139.280 + data[5] & 0xFF));
139.281 + tuning.load(data);
139.282 + SoftVoice[] voices = synth.getVoices();
139.283 + for (int i = 0; i < voices.length; i++)
139.284 + if (voices[i].active)
139.285 + if (voices[i].tuning == tuning)
139.286 + voices[i].updateTuning(tuning);
139.287 + break;
139.288 + }
139.289 + case 0x07: // SINGLE NOTE TUNING CHANGE (REAL-TIME)
139.290 + // (BANK)
139.291 + {
139.292 + // http://www.midi.org/about-midi/tuning_extens.shtml
139.293 + SoftTuning tuning = synth.getTuning(new Patch(
139.294 + data[5] & 0xFF, data[6] & 0xFF));
139.295 + tuning.load(data);
139.296 + SoftVoice[] voices = synth.getVoices();
139.297 + for (int i = 0; i < voices.length; i++)
139.298 + if (voices[i].active)
139.299 + if (voices[i].tuning == tuning)
139.300 + voices[i].updateTuning(tuning);
139.301 + break;
139.302 + }
139.303 + case 0x08: // scale/octave tuning 1-byte form
139.304 + //(Real-Time)
139.305 + case 0x09: // scale/octave tuning 2-byte form
139.306 + // (Real-Time)
139.307 + {
139.308 + // http://www.midi.org/about-midi/tuning-scale.shtml
139.309 + SoftTuning tuning = new SoftTuning(data);
139.310 + int channelmask = (data[5] & 0xFF) * 16384
139.311 + + (data[6] & 0xFF) * 128 + (data[7] & 0xFF);
139.312 + SoftChannel[] channels = synth.channels;
139.313 + for (int i = 0; i < channels.length; i++)
139.314 + if ((channelmask & (1 << i)) != 0)
139.315 + channels[i].tuning = tuning;
139.316 + SoftVoice[] voices = synth.getVoices();
139.317 + for (int i = 0; i < voices.length; i++)
139.318 + if (voices[i].active)
139.319 + if ((channelmask & (1 << (voices[i].channel))) != 0)
139.320 + voices[i].updateTuning(tuning);
139.321 + break;
139.322 + }
139.323 + default:
139.324 + break;
139.325 + }
139.326 + break;
139.327 + case 0x09: // Control Destination Settings
139.328 + subid2 = data[4] & 0xFF;
139.329 + switch (subid2) {
139.330 + case 0x01: // Channel Pressure
139.331 + {
139.332 + int[] destinations = new int[(data.length - 7) / 2];
139.333 + int[] ranges = new int[(data.length - 7) / 2];
139.334 + int ix = 0;
139.335 + for (int j = 6; j < data.length - 1; j += 2) {
139.336 + destinations[ix] = data[j] & 0xFF;
139.337 + ranges[ix] = data[j + 1] & 0xFF;
139.338 + ix++;
139.339 + }
139.340 + int channel = data[5] & 0xFF;
139.341 + SoftChannel softchannel = synth.channels[channel];
139.342 + softchannel.mapChannelPressureToDestination(
139.343 + destinations, ranges);
139.344 + break;
139.345 + }
139.346 + case 0x02: // Poly Pressure
139.347 + {
139.348 + int[] destinations = new int[(data.length - 7) / 2];
139.349 + int[] ranges = new int[(data.length - 7) / 2];
139.350 + int ix = 0;
139.351 + for (int j = 6; j < data.length - 1; j += 2) {
139.352 + destinations[ix] = data[j] & 0xFF;
139.353 + ranges[ix] = data[j + 1] & 0xFF;
139.354 + ix++;
139.355 + }
139.356 + int channel = data[5] & 0xFF;
139.357 + SoftChannel softchannel = synth.channels[channel];
139.358 + softchannel.mapPolyPressureToDestination(
139.359 + destinations, ranges);
139.360 + break;
139.361 + }
139.362 + case 0x03: // Control Change
139.363 + {
139.364 + int[] destinations = new int[(data.length - 7) / 2];
139.365 + int[] ranges = new int[(data.length - 7) / 2];
139.366 + int ix = 0;
139.367 + for (int j = 7; j < data.length - 1; j += 2) {
139.368 + destinations[ix] = data[j] & 0xFF;
139.369 + ranges[ix] = data[j + 1] & 0xFF;
139.370 + ix++;
139.371 + }
139.372 + int channel = data[5] & 0xFF;
139.373 + SoftChannel softchannel = synth.channels[channel];
139.374 + int control = data[6] & 0xFF;
139.375 + softchannel.mapControlToDestination(control,
139.376 + destinations, ranges);
139.377 + break;
139.378 + }
139.379 + default:
139.380 + break;
139.381 + }
139.382 + break;
139.383 +
139.384 + case 0x0A: // Key Based Instrument Control
139.385 + {
139.386 + subid2 = data[4] & 0xFF;
139.387 + switch (subid2) {
139.388 + case 0x01: // Basic Message
139.389 + int channel = data[5] & 0xFF;
139.390 + int keynumber = data[6] & 0xFF;
139.391 + SoftChannel softchannel = synth.channels[channel];
139.392 + for (int j = 7; j < data.length - 1; j += 2) {
139.393 + int controlnumber = data[j] & 0xFF;
139.394 + int controlvalue = data[j + 1] & 0xFF;
139.395 + softchannel.controlChangePerNote(keynumber,
139.396 + controlnumber, controlvalue);
139.397 + }
139.398 + break;
139.399 + default:
139.400 + break;
139.401 + }
139.402 + break;
139.403 + }
139.404 + default:
139.405 + break;
139.406 + }
139.407 + }
139.408 + }
139.409 +
139.410 + }
139.411 + }
139.412 +
139.413 + private void processMessages(long timeStamp) {
139.414 + Iterator<Entry<Long, Object>> iter = midimessages.entrySet().iterator();
139.415 + while (iter.hasNext()) {
139.416 + Entry<Long, Object> entry = iter.next();
139.417 + if (entry.getKey() > (timeStamp + 100))
139.418 + return;
139.419 + processMessage(entry.getValue());
139.420 + iter.remove();
139.421 + }
139.422 + }
139.423 +
139.424 + protected void processAudioBuffers() {
139.425 + for (int i = 0; i < buffers.length; i++) {
139.426 + buffers[i].clear();
139.427 + }
139.428 +
139.429 + double volume_left;
139.430 + double volume_right;
139.431 +
139.432 + ModelChannelMixer[] act_registeredMixers;
139.433 +
139.434 + // perform control logic
139.435 + synchronized (control_mutex) {
139.436 +
139.437 + processMessages(msec_pos);
139.438 +
139.439 + if (active_sensing_on) {
139.440 + // Active Sensing
139.441 + // if no message occurs for max 1000 ms
139.442 + // then do AllSoundOff on all channels
139.443 + if ((msec_pos - msec_last_activity) > 1000000) {
139.444 + active_sensing_on = false;
139.445 + for (SoftChannel c : synth.channels)
139.446 + c.allSoundOff();
139.447 + }
139.448 +
139.449 + }
139.450 +
139.451 + for (int i = 0; i < voicestatus.length; i++)
139.452 + if (voicestatus[i].active)
139.453 + voicestatus[i].processControlLogic();
139.454 + msec_pos += msec_buffer_len;
139.455 +
139.456 + double volume = co_master_volume[0];
139.457 + volume_left = volume;
139.458 + volume_right = volume;
139.459 +
139.460 + double balance = co_master_balance[0];
139.461 + if (balance > 0.5)
139.462 + volume_left *= (1 - balance) * 2;
139.463 + else
139.464 + volume_right *= balance * 2;
139.465 +
139.466 + chorus.processControlLogic();
139.467 + reverb.processControlLogic();
139.468 + agc.processControlLogic();
139.469 +
139.470 + if (cur_registeredMixers == null) {
139.471 + if (registeredMixers != null) {
139.472 + cur_registeredMixers =
139.473 + new ModelChannelMixer[registeredMixers.size()];
139.474 + registeredMixers.toArray(cur_registeredMixers);
139.475 + }
139.476 + }
139.477 +
139.478 + act_registeredMixers = cur_registeredMixers;
139.479 + if (act_registeredMixers != null)
139.480 + if (act_registeredMixers.length == 0)
139.481 + act_registeredMixers = null;
139.482 +
139.483 + }
139.484 +
139.485 + if (act_registeredMixers != null) {
139.486 +
139.487 + // Reroute default left,right output
139.488 + // to channelmixer left,right input/output
139.489 + SoftAudioBuffer leftbak = buffers[CHANNEL_LEFT];
139.490 + SoftAudioBuffer rightbak = buffers[CHANNEL_RIGHT];
139.491 + buffers[CHANNEL_LEFT] = buffers[CHANNEL_CHANNELMIXER_LEFT];
139.492 + buffers[CHANNEL_RIGHT] = buffers[CHANNEL_CHANNELMIXER_LEFT];
139.493 +
139.494 + int bufferlen = buffers[CHANNEL_LEFT].getSize();
139.495 +
139.496 + float[][] cbuffer = new float[nrofchannels][];
139.497 + cbuffer[0] = buffers[CHANNEL_LEFT].array();
139.498 + if (nrofchannels != 1)
139.499 + cbuffer[1] = buffers[CHANNEL_RIGHT].array();
139.500 +
139.501 + float[][] obuffer = new float[nrofchannels][];
139.502 + obuffer[0] = leftbak.array();
139.503 + if (nrofchannels != 1)
139.504 + obuffer[1] = rightbak.array();
139.505 +
139.506 + for (ModelChannelMixer cmixer : act_registeredMixers) {
139.507 + for (int i = 0; i < cbuffer.length; i++)
139.508 + Arrays.fill(cbuffer[i], 0);
139.509 + boolean hasactivevoices = false;
139.510 + for (int i = 0; i < voicestatus.length; i++)
139.511 + if (voicestatus[i].active)
139.512 + if (voicestatus[i].channelmixer == cmixer) {
139.513 + voicestatus[i].processAudioLogic(buffers);
139.514 + hasactivevoices = true;
139.515 + }
139.516 + if (!cmixer.process(cbuffer, 0, bufferlen)) {
139.517 + synchronized (control_mutex) {
139.518 + registeredMixers.remove(cmixer);
139.519 + cur_registeredMixers = null;
139.520 + }
139.521 + }
139.522 +
139.523 + for (int i = 0; i < cbuffer.length; i++) {
139.524 + float[] cbuff = cbuffer[i];
139.525 + float[] obuff = obuffer[i];
139.526 + for (int j = 0; j < bufferlen; j++)
139.527 + obuff[j] += cbuff[j];
139.528 + }
139.529 +
139.530 + if (!hasactivevoices) {
139.531 + synchronized (control_mutex) {
139.532 + if (stoppedMixers != null) {
139.533 + if (stoppedMixers.contains(cmixer)) {
139.534 + stoppedMixers.remove(cmixer);
139.535 + cmixer.stop();
139.536 + }
139.537 + }
139.538 + }
139.539 + }
139.540 +
139.541 + }
139.542 +
139.543 + buffers[CHANNEL_LEFT] = leftbak;
139.544 + buffers[CHANNEL_RIGHT] = rightbak;
139.545 +
139.546 + }
139.547 +
139.548 + for (int i = 0; i < voicestatus.length; i++)
139.549 + if (voicestatus[i].active)
139.550 + if (voicestatus[i].channelmixer == null)
139.551 + voicestatus[i].processAudioLogic(buffers);
139.552 +
139.553 + // Run effects
139.554 + if (synth.chorus_on)
139.555 + chorus.processAudio();
139.556 +
139.557 + if (synth.reverb_on)
139.558 + reverb.processAudio();
139.559 +
139.560 + if (nrofchannels == 1)
139.561 + volume_left = (volume_left + volume_right) / 2;
139.562 +
139.563 + // Set Volume / Balance
139.564 + if (last_volume_left != volume_left || last_volume_right != volume_right) {
139.565 + float[] left = buffers[CHANNEL_LEFT].array();
139.566 + float[] right = buffers[CHANNEL_RIGHT].array();
139.567 + int bufferlen = buffers[CHANNEL_LEFT].getSize();
139.568 +
139.569 + float amp;
139.570 + float amp_delta;
139.571 + amp = (float)(last_volume_left * last_volume_left);
139.572 + amp_delta = (float)((volume_left * volume_left - amp) / bufferlen);
139.573 + for (int i = 0; i < bufferlen; i++) {
139.574 + amp += amp_delta;
139.575 + left[i] *= amp;
139.576 + }
139.577 + if (nrofchannels != 1) {
139.578 + amp = (float)(last_volume_right * last_volume_right);
139.579 + amp_delta = (float)((volume_right*volume_right - amp) / bufferlen);
139.580 + for (int i = 0; i < bufferlen; i++) {
139.581 + amp += amp_delta;
139.582 + right[i] *= volume_right;
139.583 + }
139.584 + }
139.585 + last_volume_left = volume_left;
139.586 + last_volume_right = volume_right;
139.587 +
139.588 + } else {
139.589 + if (volume_left != 1.0 || volume_right != 1.0) {
139.590 + float[] left = buffers[CHANNEL_LEFT].array();
139.591 + float[] right = buffers[CHANNEL_RIGHT].array();
139.592 + int bufferlen = buffers[CHANNEL_LEFT].getSize();
139.593 + float amp;
139.594 + amp = (float) (volume_left * volume_left);
139.595 + for (int i = 0; i < bufferlen; i++)
139.596 + left[i] *= amp;
139.597 + if (nrofchannels != 1) {
139.598 + amp = (float)(volume_right * volume_right);
139.599 + for (int i = 0; i < bufferlen; i++)
139.600 + right[i] *= amp;
139.601 + }
139.602 +
139.603 + }
139.604 + }
139.605 +
139.606 + if(buffers[CHANNEL_LEFT].isSilent()
139.607 + && buffers[CHANNEL_RIGHT].isSilent())
139.608 + {
139.609 + pusher_silent_count++;
139.610 + if(pusher_silent_count > 5)
139.611 + {
139.612 + pusher_silent_count = 0;
139.613 + synchronized (control_mutex) {
139.614 + pusher_silent = true;
139.615 + if(synth.weakstream != null)
139.616 + synth.weakstream.setInputStream(null);
139.617 + }
139.618 + }
139.619 + }
139.620 + else
139.621 + pusher_silent_count = 0;
139.622 +
139.623 + if (synth.agc_on)
139.624 + agc.processAudio();
139.625 +
139.626 + }
139.627 +
139.628 + // Must only we called within control_mutex synchronization
139.629 + public void activity()
139.630 + {
139.631 + msec_last_activity = msec_pos;
139.632 + if(pusher_silent)
139.633 + {
139.634 + pusher_silent = false;
139.635 + if(synth.weakstream != null)
139.636 + synth.weakstream.setInputStream(ais);
139.637 + }
139.638 + }
139.639 +
139.640 + public void stopMixer(ModelChannelMixer mixer) {
139.641 + if (stoppedMixers == null)
139.642 + stoppedMixers = new HashSet<ModelChannelMixer>();
139.643 + stoppedMixers.add(mixer);
139.644 + }
139.645 +
139.646 + public void registerMixer(ModelChannelMixer mixer) {
139.647 + if (registeredMixers == null)
139.648 + registeredMixers = new HashSet<ModelChannelMixer>();
139.649 + registeredMixers.add(mixer);
139.650 + cur_registeredMixers = null;
139.651 + }
139.652 +
139.653 + public SoftMainMixer(SoftSynthesizer synth) {
139.654 + this.synth = synth;
139.655 +
139.656 + msec_pos = 0;
139.657 +
139.658 + co_master_balance[0] = 0.5;
139.659 + co_master_volume[0] = 1;
139.660 + co_master_coarse_tuning[0] = 0.5;
139.661 + co_master_fine_tuning[0] = 0.5;
139.662 +
139.663 + msec_buffer_len = (long) (1000000.0 / synth.getControlRate());
139.664 +
139.665 + nrofchannels = synth.getFormat().getChannels();
139.666 +
139.667 + int buffersize = (int) (synth.getFormat().getSampleRate()
139.668 + / synth.getControlRate());
139.669 +
139.670 + control_mutex = synth.control_mutex;
139.671 + buffers = new SoftAudioBuffer[16];
139.672 + for (int i = 0; i < buffers.length; i++) {
139.673 + buffers[i] = new SoftAudioBuffer(buffersize, synth.getFormat());
139.674 + }
139.675 + voicestatus = synth.getVoices();
139.676 +
139.677 + reverb = new SoftReverb();
139.678 + chorus = new SoftChorus();
139.679 + agc = new SoftLimiter();
139.680 +
139.681 + float samplerate = synth.getFormat().getSampleRate();
139.682 + float controlrate = synth.getControlRate();
139.683 + reverb.init(samplerate, controlrate);
139.684 + chorus.init(samplerate, controlrate);
139.685 + agc.init(samplerate, controlrate);
139.686 +
139.687 + reverb.setLightMode(synth.reverb_light);
139.688 +
139.689 + reverb.setMixMode(true);
139.690 + chorus.setMixMode(true);
139.691 + agc.setMixMode(false);
139.692 +
139.693 + chorus.setInput(0, buffers[CHANNEL_EFFECT2]);
139.694 + chorus.setOutput(0, buffers[CHANNEL_LEFT]);
139.695 + if (nrofchannels != 1)
139.696 + chorus.setOutput(1, buffers[CHANNEL_RIGHT]);
139.697 + chorus.setOutput(2, buffers[CHANNEL_EFFECT1]);
139.698 +
139.699 + reverb.setInput(0, buffers[CHANNEL_EFFECT1]);
139.700 + reverb.setOutput(0, buffers[CHANNEL_LEFT]);
139.701 + if (nrofchannels != 1)
139.702 + reverb.setOutput(1, buffers[CHANNEL_RIGHT]);
139.703 +
139.704 + agc.setInput(0, buffers[CHANNEL_LEFT]);
139.705 + if (nrofchannels != 1)
139.706 + agc.setInput(1, buffers[CHANNEL_RIGHT]);
139.707 + agc.setOutput(0, buffers[CHANNEL_LEFT]);
139.708 + if (nrofchannels != 1)
139.709 + agc.setOutput(1, buffers[CHANNEL_RIGHT]);
139.710 +
139.711 + InputStream in = new InputStream() {
139.712 +
139.713 + private SoftAudioBuffer[] buffers = SoftMainMixer.this.buffers;
139.714 + private int nrofchannels
139.715 + = SoftMainMixer.this.synth.getFormat().getChannels();
139.716 + private int buffersize = buffers[0].getSize();
139.717 + private byte[] bbuffer = new byte[buffersize
139.718 + * (SoftMainMixer.this.synth.getFormat()
139.719 + .getSampleSizeInBits() / 8)
139.720 + * nrofchannels];
139.721 + private int bbuffer_pos = 0;
139.722 + private byte[] single = new byte[1];
139.723 +
139.724 + public void fillBuffer() {
139.725 + /*
139.726 + boolean pusher_silent2;
139.727 + synchronized (control_mutex) {
139.728 + pusher_silent2 = pusher_silent;
139.729 + }
139.730 + if(!pusher_silent2)*/
139.731 + processAudioBuffers();
139.732 + for (int i = 0; i < nrofchannels; i++)
139.733 + buffers[i].get(bbuffer, i);
139.734 + bbuffer_pos = 0;
139.735 + }
139.736 +
139.737 + public int read(byte[] b, int off, int len) {
139.738 + int bbuffer_len = bbuffer.length;
139.739 + int offlen = off + len;
139.740 + int orgoff = off;
139.741 + byte[] bbuffer = this.bbuffer;
139.742 + while (off < offlen) {
139.743 + if (available() == 0)
139.744 + fillBuffer();
139.745 + else {
139.746 + int bbuffer_pos = this.bbuffer_pos;
139.747 + while (off < offlen && bbuffer_pos < bbuffer_len)
139.748 + b[off++] = bbuffer[bbuffer_pos++];
139.749 + this.bbuffer_pos = bbuffer_pos;
139.750 + if (!readfully)
139.751 + return off - orgoff;
139.752 + }
139.753 + }
139.754 + return len;
139.755 + }
139.756 +
139.757 + public int read() throws IOException {
139.758 + int ret = read(single);
139.759 + if (ret == -1)
139.760 + return -1;
139.761 + return single[0] & 0xFF;
139.762 + }
139.763 +
139.764 + public int available() {
139.765 + return bbuffer.length - bbuffer_pos;
139.766 + }
139.767 +
139.768 + public void close() {
139.769 + SoftMainMixer.this.synth.close();
139.770 + }
139.771 + };
139.772 +
139.773 + ais = new AudioInputStream(in, synth.getFormat(), AudioSystem.NOT_SPECIFIED);
139.774 +
139.775 + }
139.776 +
139.777 + public AudioInputStream getInputStream() {
139.778 + return ais;
139.779 + }
139.780 +
139.781 + public void reset() {
139.782 +
139.783 + SoftChannel[] channels = synth.channels;
139.784 + for (int i = 0; i < channels.length; i++) {
139.785 + channels[i].allSoundOff();
139.786 + channels[i].resetAllControllers(true);
139.787 +
139.788 + if (synth.getGeneralMidiMode() == 2) {
139.789 + if (i == 9)
139.790 + channels[i].programChange(0, 0x78 * 128);
139.791 + else
139.792 + channels[i].programChange(0, 0x79 * 128);
139.793 + } else
139.794 + channels[i].programChange(0, 0);
139.795 + }
139.796 + setVolume(0x7F * 128 + 0x7F);
139.797 + setBalance(0x40 * 128 + 0x00);
139.798 + setCoarseTuning(0x40 * 128 + 0x00);
139.799 + setFineTuning(0x40 * 128 + 0x00);
139.800 + // Reset Reverb
139.801 + globalParameterControlChange(
139.802 + new int[]{0x01 * 128 + 0x01}, new long[]{0}, new long[]{4});
139.803 + // Reset Chorus
139.804 + globalParameterControlChange(
139.805 + new int[]{0x01 * 128 + 0x02}, new long[]{0}, new long[]{2});
139.806 + }
139.807 +
139.808 + public void setVolume(int value) {
139.809 + synchronized (control_mutex) {
139.810 + co_master_volume[0] = value / 16384.0;
139.811 + }
139.812 + }
139.813 +
139.814 + public void setBalance(int value) {
139.815 + synchronized (control_mutex) {
139.816 + co_master_balance[0] = value / 16384.0;
139.817 + }
139.818 + }
139.819 +
139.820 + public void setFineTuning(int value) {
139.821 + synchronized (control_mutex) {
139.822 + co_master_fine_tuning[0] = value / 16384.0;
139.823 + }
139.824 + }
139.825 +
139.826 + public void setCoarseTuning(int value) {
139.827 + synchronized (control_mutex) {
139.828 + co_master_coarse_tuning[0] = value / 16384.0;
139.829 + }
139.830 + }
139.831 +
139.832 + public int getVolume() {
139.833 + synchronized (control_mutex) {
139.834 + return (int) (co_master_volume[0] * 16384.0);
139.835 + }
139.836 + }
139.837 +
139.838 + public int getBalance() {
139.839 + synchronized (control_mutex) {
139.840 + return (int) (co_master_balance[0] * 16384.0);
139.841 + }
139.842 + }
139.843 +
139.844 + public int getFineTuning() {
139.845 + synchronized (control_mutex) {
139.846 + return (int) (co_master_fine_tuning[0] * 16384.0);
139.847 + }
139.848 + }
139.849 +
139.850 + public int getCoarseTuning() {
139.851 + synchronized (control_mutex) {
139.852 + return (int) (co_master_coarse_tuning[0] * 16384.0);
139.853 + }
139.854 + }
139.855 +
139.856 + public void globalParameterControlChange(int[] slothpath, long[] params,
139.857 + long[] paramsvalue) {
139.858 + if (slothpath.length == 0)
139.859 + return;
139.860 +
139.861 + synchronized (control_mutex) {
139.862 +
139.863 + // slothpath: 01xx are reserved only for GM2
139.864 +
139.865 + if (slothpath[0] == 0x01 * 128 + 0x01) {
139.866 + for (int i = 0; i < paramsvalue.length; i++) {
139.867 + reverb.globalParameterControlChange(slothpath, params[i],
139.868 + paramsvalue[i]);
139.869 + }
139.870 + }
139.871 + if (slothpath[0] == 0x01 * 128 + 0x02) {
139.872 + for (int i = 0; i < paramsvalue.length; i++) {
139.873 + chorus.globalParameterControlChange(slothpath, params[i],
139.874 + paramsvalue[i]);
139.875 + }
139.876 +
139.877 + }
139.878 +
139.879 + }
139.880 + }
139.881 +
139.882 + public void processMessage(Object object) {
139.883 + if (object instanceof byte[])
139.884 + processMessage((byte[]) object);
139.885 + if (object instanceof MidiMessage)
139.886 + processMessage((MidiMessage)object);
139.887 + }
139.888 +
139.889 + public void processMessage(MidiMessage message) {
139.890 + if (message instanceof ShortMessage) {
139.891 + ShortMessage sms = (ShortMessage)message;
139.892 + processMessage(sms.getChannel(), sms.getCommand(),
139.893 + sms.getData1(), sms.getData2());
139.894 + return;
139.895 + }
139.896 + processMessage(message.getMessage());
139.897 + }
139.898 +
139.899 + public void processMessage(byte[] data) {
139.900 + int status = 0;
139.901 + if (data.length > 0)
139.902 + status = data[0] & 0xFF;
139.903 +
139.904 + if (status == 0xF0) {
139.905 + processSystemExclusiveMessage(data);
139.906 + return;
139.907 + }
139.908 +
139.909 + int cmd = (status & 0xF0);
139.910 + int ch = (status & 0x0F);
139.911 +
139.912 + int data1;
139.913 + int data2;
139.914 + if (data.length > 1)
139.915 + data1 = data[1] & 0xFF;
139.916 + else
139.917 + data1 = 0;
139.918 + if (data.length > 2)
139.919 + data2 = data[2] & 0xFF;
139.920 + else
139.921 + data2 = 0;
139.922 +
139.923 + processMessage(ch, cmd, data1, data2);
139.924 +
139.925 + }
139.926 +
139.927 + public void processMessage(int ch, int cmd, int data1, int data2) {
139.928 + synchronized (synth.control_mutex) {
139.929 + activity();
139.930 + }
139.931 +
139.932 + if (cmd == 0xF0) {
139.933 + int status = cmd | ch;
139.934 + switch (status) {
139.935 + case ShortMessage.ACTIVE_SENSING:
139.936 + synchronized (synth.control_mutex) {
139.937 + active_sensing_on = true;
139.938 + }
139.939 + break;
139.940 + default:
139.941 + break;
139.942 + }
139.943 + return;
139.944 + }
139.945 +
139.946 + SoftChannel[] channels = synth.channels;
139.947 + if (ch >= channels.length)
139.948 + return;
139.949 + SoftChannel softchannel = channels[ch];
139.950 +
139.951 + switch (cmd) {
139.952 + case ShortMessage.NOTE_ON:
139.953 + softchannel.noteOn(data1, data2);
139.954 + break;
139.955 + case ShortMessage.NOTE_OFF:
139.956 + softchannel.noteOff(data1, data2);
139.957 + break;
139.958 + case ShortMessage.POLY_PRESSURE:
139.959 + softchannel.setPolyPressure(data1, data2);
139.960 + break;
139.961 + case ShortMessage.CONTROL_CHANGE:
139.962 + softchannel.controlChange(data1, data2);
139.963 + break;
139.964 + case ShortMessage.PROGRAM_CHANGE:
139.965 + softchannel.programChange(data1);
139.966 + break;
139.967 + case ShortMessage.CHANNEL_PRESSURE:
139.968 + softchannel.setChannelPressure(data1);
139.969 + break;
139.970 + case ShortMessage.PITCH_BEND:
139.971 + softchannel.setPitchBend(data1 + data2 * 128);
139.972 + break;
139.973 + default:
139.974 + break;
139.975 + }
139.976 +
139.977 + }
139.978 +
139.979 + public long getMicrosecondPosition() {
139.980 + return msec_pos;
139.981 + }
139.982 +
139.983 + public void close() {
139.984 + }
139.985 +}
140.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
140.2 +++ b/src/share/classes/com/sun/media/sound/SoftMidiAudioFileReader.java Tue Feb 03 22:02:55 2009 -0800
140.3 @@ -0,0 +1,214 @@
140.4 +/*
140.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
140.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
140.7 + *
140.8 + * This code is free software; you can redistribute it and/or modify it
140.9 + * under the terms of the GNU General Public License version 2 only, as
140.10 + * published by the Free Software Foundation. Sun designates this
140.11 + * particular file as subject to the "Classpath" exception as provided
140.12 + * by Sun in the LICENSE file that accompanied this code.
140.13 + *
140.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
140.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
140.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
140.17 + * version 2 for more details (a copy is included in the LICENSE file that
140.18 + * accompanied this code).
140.19 + *
140.20 + * You should have received a copy of the GNU General Public License version
140.21 + * 2 along with this work; if not, write to the Free Software Foundation,
140.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
140.23 + *
140.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
140.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
140.26 + * have any questions.
140.27 + */
140.28 +package com.sun.media.sound;
140.29 +
140.30 +import java.io.File;
140.31 +import java.io.IOException;
140.32 +import java.io.InputStream;
140.33 +import java.net.URL;
140.34 +
140.35 +import javax.sound.midi.InvalidMidiDataException;
140.36 +import javax.sound.midi.MetaMessage;
140.37 +import javax.sound.midi.MidiEvent;
140.38 +import javax.sound.midi.MidiMessage;
140.39 +import javax.sound.midi.MidiSystem;
140.40 +import javax.sound.midi.MidiUnavailableException;
140.41 +import javax.sound.midi.Receiver;
140.42 +import javax.sound.midi.Sequence;
140.43 +import javax.sound.midi.Track;
140.44 +import javax.sound.sampled.AudioFileFormat;
140.45 +import javax.sound.sampled.AudioFormat;
140.46 +import javax.sound.sampled.AudioInputStream;
140.47 +import javax.sound.sampled.UnsupportedAudioFileException;
140.48 +import javax.sound.sampled.AudioFileFormat.Type;
140.49 +import javax.sound.sampled.spi.AudioFileReader;
140.50 +
140.51 +/**
140.52 + * MIDI File Audio Renderer/Reader
140.53 + *
140.54 + * @author Karl Helgason
140.55 + */
140.56 +public class SoftMidiAudioFileReader extends AudioFileReader {
140.57 +
140.58 + public static final Type MIDI = new Type("MIDI", "mid");
140.59 + private static AudioFormat format = new AudioFormat(44100, 16, 2, true, false);
140.60 +
140.61 + public AudioFileFormat getAudioFileFormat(Sequence seq)
140.62 + throws UnsupportedAudioFileException, IOException {
140.63 +
140.64 + long totallen = seq.getMicrosecondLength() / 1000000;
140.65 + long len = (long) (format.getFrameRate() * (totallen + 4));
140.66 + return new AudioFileFormat(MIDI, format, (int) len);
140.67 + }
140.68 +
140.69 + public AudioInputStream getAudioInputStream(Sequence seq)
140.70 + throws UnsupportedAudioFileException, IOException {
140.71 + AudioSynthesizer synth = (AudioSynthesizer) new SoftSynthesizer();
140.72 + AudioInputStream stream;
140.73 + Receiver recv;
140.74 + try {
140.75 + stream = synth.openStream(format, null);
140.76 + recv = synth.getReceiver();
140.77 + } catch (MidiUnavailableException e) {
140.78 + throw new IOException(e.toString());
140.79 + }
140.80 + float divtype = seq.getDivisionType();
140.81 + Track[] tracks = seq.getTracks();
140.82 + int[] trackspos = new int[tracks.length];
140.83 + int mpq = 500000;
140.84 + int seqres = seq.getResolution();
140.85 + long lasttick = 0;
140.86 + long curtime = 0;
140.87 + while (true) {
140.88 + MidiEvent selevent = null;
140.89 + int seltrack = -1;
140.90 + for (int i = 0; i < tracks.length; i++) {
140.91 + int trackpos = trackspos[i];
140.92 + Track track = tracks[i];
140.93 + if (trackpos < track.size()) {
140.94 + MidiEvent event = track.get(trackpos);
140.95 + if (selevent == null || event.getTick() < selevent.getTick()) {
140.96 + selevent = event;
140.97 + seltrack = i;
140.98 + }
140.99 + }
140.100 + }
140.101 + if (seltrack == -1)
140.102 + break;
140.103 + trackspos[seltrack]++;
140.104 + long tick = selevent.getTick();
140.105 + if (divtype == Sequence.PPQ)
140.106 + curtime += ((tick - lasttick) * mpq) / seqres;
140.107 + else
140.108 + curtime = (long) ((tick * 1000000.0 * divtype) / seqres);
140.109 + lasttick = tick;
140.110 + MidiMessage msg = selevent.getMessage();
140.111 + if (msg instanceof MetaMessage) {
140.112 + if (divtype == Sequence.PPQ) {
140.113 + if (((MetaMessage) msg).getType() == 0x51) {
140.114 + byte[] data = ((MetaMessage) msg).getData();
140.115 + mpq = ((data[0] & 0xff) << 16)
140.116 + | ((data[1] & 0xff) << 8) | (data[2] & 0xff);
140.117 + }
140.118 + }
140.119 + } else {
140.120 + recv.send(msg, curtime);
140.121 + }
140.122 + }
140.123 +
140.124 + long totallen = curtime / 1000000;
140.125 + long len = (long) (stream.getFormat().getFrameRate() * (totallen + 4));
140.126 + stream = new AudioInputStream(stream, stream.getFormat(), len);
140.127 + return stream;
140.128 + }
140.129 +
140.130 + public AudioInputStream getAudioInputStream(InputStream inputstream)
140.131 + throws UnsupportedAudioFileException, IOException {
140.132 +
140.133 + inputstream.mark(200);
140.134 + Sequence seq;
140.135 + try {
140.136 + seq = MidiSystem.getSequence(inputstream);
140.137 + } catch (InvalidMidiDataException e) {
140.138 + inputstream.reset();
140.139 + throw new UnsupportedAudioFileException();
140.140 + } catch (IOException e) {
140.141 + inputstream.reset();
140.142 + throw new UnsupportedAudioFileException();
140.143 + }
140.144 + return getAudioInputStream(seq);
140.145 + }
140.146 +
140.147 + public AudioFileFormat getAudioFileFormat(URL url)
140.148 + throws UnsupportedAudioFileException, IOException {
140.149 + Sequence seq;
140.150 + try {
140.151 + seq = MidiSystem.getSequence(url);
140.152 + } catch (InvalidMidiDataException e) {
140.153 + throw new UnsupportedAudioFileException();
140.154 + } catch (IOException e) {
140.155 + throw new UnsupportedAudioFileException();
140.156 + }
140.157 + return getAudioFileFormat(seq);
140.158 + }
140.159 +
140.160 + public AudioFileFormat getAudioFileFormat(File file)
140.161 + throws UnsupportedAudioFileException, IOException {
140.162 + Sequence seq;
140.163 + try {
140.164 + seq = MidiSystem.getSequence(file);
140.165 + } catch (InvalidMidiDataException e) {
140.166 + throw new UnsupportedAudioFileException();
140.167 + } catch (IOException e) {
140.168 + throw new UnsupportedAudioFileException();
140.169 + }
140.170 + return getAudioFileFormat(seq);
140.171 + }
140.172 +
140.173 + public AudioInputStream getAudioInputStream(URL url)
140.174 + throws UnsupportedAudioFileException, IOException {
140.175 + Sequence seq;
140.176 + try {
140.177 + seq = MidiSystem.getSequence(url);
140.178 + } catch (InvalidMidiDataException e) {
140.179 + throw new UnsupportedAudioFileException();
140.180 + } catch (IOException e) {
140.181 + throw new UnsupportedAudioFileException();
140.182 + }
140.183 + return getAudioInputStream(seq);
140.184 + }
140.185 +
140.186 + public AudioInputStream getAudioInputStream(File file)
140.187 + throws UnsupportedAudioFileException, IOException {
140.188 + if (!file.getName().toLowerCase().endsWith(".mid"))
140.189 + throw new UnsupportedAudioFileException();
140.190 + Sequence seq;
140.191 + try {
140.192 + seq = MidiSystem.getSequence(file);
140.193 + } catch (InvalidMidiDataException e) {
140.194 + throw new UnsupportedAudioFileException();
140.195 + } catch (IOException e) {
140.196 + throw new UnsupportedAudioFileException();
140.197 + }
140.198 + return getAudioInputStream(seq);
140.199 + }
140.200 +
140.201 + public AudioFileFormat getAudioFileFormat(InputStream inputstream)
140.202 + throws UnsupportedAudioFileException, IOException {
140.203 +
140.204 + inputstream.mark(200);
140.205 + Sequence seq;
140.206 + try {
140.207 + seq = MidiSystem.getSequence(inputstream);
140.208 + } catch (InvalidMidiDataException e) {
140.209 + inputstream.reset();
140.210 + throw new UnsupportedAudioFileException();
140.211 + } catch (IOException e) {
140.212 + inputstream.reset();
140.213 + throw new UnsupportedAudioFileException();
140.214 + }
140.215 + return getAudioFileFormat(seq);
140.216 + }
140.217 +}
141.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
141.2 +++ b/src/share/classes/com/sun/media/sound/SoftMixingClip.java Tue Feb 03 22:02:55 2009 -0800
141.3 @@ -0,0 +1,539 @@
141.4 +/*
141.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
141.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
141.7 + *
141.8 + * This code is free software; you can redistribute it and/or modify it
141.9 + * under the terms of the GNU General Public License version 2 only, as
141.10 + * published by the Free Software Foundation. Sun designates this
141.11 + * particular file as subject to the "Classpath" exception as provided
141.12 + * by Sun in the LICENSE file that accompanied this code.
141.13 + *
141.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
141.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
141.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
141.17 + * version 2 for more details (a copy is included in the LICENSE file that
141.18 + * accompanied this code).
141.19 + *
141.20 + * You should have received a copy of the GNU General Public License version
141.21 + * 2 along with this work; if not, write to the Free Software Foundation,
141.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
141.23 + *
141.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
141.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
141.26 + * have any questions.
141.27 + */
141.28 +package com.sun.media.sound;
141.29 +
141.30 +import java.io.ByteArrayOutputStream;
141.31 +import java.io.IOException;
141.32 +import java.io.InputStream;
141.33 +import java.util.Arrays;
141.34 +
141.35 +import javax.sound.sampled.AudioFormat;
141.36 +import javax.sound.sampled.AudioInputStream;
141.37 +import javax.sound.sampled.AudioSystem;
141.38 +import javax.sound.sampled.Clip;
141.39 +import javax.sound.sampled.DataLine;
141.40 +import javax.sound.sampled.LineEvent;
141.41 +import javax.sound.sampled.LineUnavailableException;
141.42 +
141.43 +/**
141.44 + * Clip implemention for the SoftMixingMixer.
141.45 + *
141.46 + * @author Karl Helgason
141.47 + */
141.48 +public class SoftMixingClip extends SoftMixingDataLine implements Clip {
141.49 +
141.50 + private AudioFormat format;
141.51 +
141.52 + private int framesize;
141.53 +
141.54 + private byte[] data;
141.55 +
141.56 + private InputStream datastream = new InputStream() {
141.57 +
141.58 + public int read() throws IOException {
141.59 + byte[] b = new byte[1];
141.60 + int ret = read(b);
141.61 + if (ret < 0)
141.62 + return ret;
141.63 + return b[0] & 0xFF;
141.64 + }
141.65 +
141.66 + public int read(byte[] b, int off, int len) throws IOException {
141.67 +
141.68 + if (_loopcount != 0) {
141.69 + int bloopend = _loopend * framesize;
141.70 + int bloopstart = _loopstart * framesize;
141.71 + int pos = _frameposition * framesize;
141.72 +
141.73 + if (pos + len >= bloopend)
141.74 + if (pos < bloopend) {
141.75 + int offend = off + len;
141.76 + int o = off;
141.77 + while (off != offend) {
141.78 + if (pos == bloopend) {
141.79 + if (_loopcount == 0)
141.80 + break;
141.81 + pos = bloopstart;
141.82 + if (_loopcount != LOOP_CONTINUOUSLY)
141.83 + _loopcount--;
141.84 + }
141.85 + len = offend - off;
141.86 + int left = bloopend - pos;
141.87 + if (len > left)
141.88 + len = left;
141.89 + System.arraycopy(data, pos, b, off, len);
141.90 + off += len;
141.91 + }
141.92 + if (_loopcount == 0) {
141.93 + len = offend - off;
141.94 + int left = bloopend - pos;
141.95 + if (len > left)
141.96 + len = left;
141.97 + System.arraycopy(data, pos, b, off, len);
141.98 + off += len;
141.99 + }
141.100 + _frameposition = pos / framesize;
141.101 + return o - off;
141.102 + }
141.103 + }
141.104 +
141.105 + int pos = _frameposition * framesize;
141.106 + int left = bufferSize - pos;
141.107 + if (left == 0)
141.108 + return -1;
141.109 + if (len > left)
141.110 + len = left;
141.111 + System.arraycopy(data, pos, b, off, len);
141.112 + _frameposition += len / framesize;
141.113 + return len;
141.114 + }
141.115 +
141.116 + };
141.117 +
141.118 + private int offset;
141.119 +
141.120 + private int bufferSize;
141.121 +
141.122 + private float[] readbuffer;
141.123 +
141.124 + private boolean open = false;
141.125 +
141.126 + private AudioFormat outputformat;
141.127 +
141.128 + private int out_nrofchannels;
141.129 +
141.130 + private int in_nrofchannels;
141.131 +
141.132 + private int frameposition = 0;
141.133 +
141.134 + private boolean frameposition_sg = false;
141.135 +
141.136 + private boolean active_sg = false;
141.137 +
141.138 + private int loopstart = 0;
141.139 +
141.140 + private int loopend = -1;
141.141 +
141.142 + private boolean active = false;
141.143 +
141.144 + private int loopcount = 0;
141.145 +
141.146 + private boolean _active = false;
141.147 +
141.148 + private int _frameposition = 0;
141.149 +
141.150 + private boolean loop_sg = false;
141.151 +
141.152 + private int _loopcount = 0;
141.153 +
141.154 + private int _loopstart = 0;
141.155 +
141.156 + private int _loopend = -1;
141.157 +
141.158 + private float _rightgain;
141.159 +
141.160 + private float _leftgain;
141.161 +
141.162 + private float _eff1gain;
141.163 +
141.164 + private float _eff2gain;
141.165 +
141.166 + private AudioFloatInputStream afis;
141.167 +
141.168 + protected SoftMixingClip(SoftMixingMixer mixer, DataLine.Info info) {
141.169 + super(mixer, info);
141.170 + }
141.171 +
141.172 + protected void processControlLogic() {
141.173 +
141.174 + _rightgain = rightgain;
141.175 + _leftgain = leftgain;
141.176 + _eff1gain = eff1gain;
141.177 + _eff2gain = eff2gain;
141.178 +
141.179 + if (active_sg) {
141.180 + _active = active;
141.181 + active_sg = false;
141.182 + } else {
141.183 + active = _active;
141.184 + }
141.185 +
141.186 + if (frameposition_sg) {
141.187 + _frameposition = frameposition;
141.188 + frameposition_sg = false;
141.189 + afis = null;
141.190 + } else {
141.191 + frameposition = _frameposition;
141.192 + }
141.193 + if (loop_sg) {
141.194 + _loopcount = loopcount;
141.195 + _loopstart = loopstart;
141.196 + _loopend = loopend;
141.197 + }
141.198 +
141.199 + if (afis == null) {
141.200 + afis = AudioFloatInputStream.getInputStream(new AudioInputStream(
141.201 + datastream, format, AudioSystem.NOT_SPECIFIED));
141.202 +
141.203 + if (Math.abs(format.getSampleRate() - outputformat.getSampleRate()) > 0.000001)
141.204 + afis = new AudioFloatInputStreamResampler(afis, outputformat);
141.205 + }
141.206 +
141.207 + }
141.208 +
141.209 + protected void processAudioLogic(SoftAudioBuffer[] buffers) {
141.210 + if (_active) {
141.211 + float[] left = buffers[SoftMixingMainMixer.CHANNEL_LEFT].array();
141.212 + float[] right = buffers[SoftMixingMainMixer.CHANNEL_RIGHT].array();
141.213 + int bufferlen = buffers[SoftMixingMainMixer.CHANNEL_LEFT].getSize();
141.214 +
141.215 + int readlen = bufferlen * in_nrofchannels;
141.216 + if (readbuffer == null || readbuffer.length < readlen) {
141.217 + readbuffer = new float[readlen];
141.218 + }
141.219 + int ret = 0;
141.220 + try {
141.221 + ret = afis.read(readbuffer);
141.222 + if (ret == -1) {
141.223 + _active = false;
141.224 + return;
141.225 + }
141.226 + if (ret != in_nrofchannels)
141.227 + Arrays.fill(readbuffer, ret, readlen, 0);
141.228 + } catch (IOException e) {
141.229 + }
141.230 +
141.231 + int in_c = in_nrofchannels;
141.232 + for (int i = 0, ix = 0; i < bufferlen; i++, ix += in_c) {
141.233 + left[i] += readbuffer[ix] * _leftgain;
141.234 + }
141.235 +
141.236 + if (out_nrofchannels != 1) {
141.237 + if (in_nrofchannels == 1) {
141.238 + for (int i = 0, ix = 0; i < bufferlen; i++, ix += in_c) {
141.239 + right[i] += readbuffer[ix] * _rightgain;
141.240 + }
141.241 + } else {
141.242 + for (int i = 0, ix = 1; i < bufferlen; i++, ix += in_c) {
141.243 + right[i] += readbuffer[ix] * _rightgain;
141.244 + }
141.245 + }
141.246 +
141.247 + }
141.248 +
141.249 + if (_eff1gain > 0.0002) {
141.250 +
141.251 + float[] eff1 = buffers[SoftMixingMainMixer.CHANNEL_EFFECT1]
141.252 + .array();
141.253 + for (int i = 0, ix = 0; i < bufferlen; i++, ix += in_c) {
141.254 + eff1[i] += readbuffer[ix] * _eff1gain;
141.255 + }
141.256 + if (in_nrofchannels == 2) {
141.257 + for (int i = 0, ix = 1; i < bufferlen; i++, ix += in_c) {
141.258 + eff1[i] += readbuffer[ix] * _eff1gain;
141.259 + }
141.260 + }
141.261 + }
141.262 +
141.263 + if (_eff2gain > 0.0002) {
141.264 + float[] eff2 = buffers[SoftMixingMainMixer.CHANNEL_EFFECT2]
141.265 + .array();
141.266 + for (int i = 0, ix = 0; i < bufferlen; i++, ix += in_c) {
141.267 + eff2[i] += readbuffer[ix] * _eff2gain;
141.268 + }
141.269 + if (in_nrofchannels == 2) {
141.270 + for (int i = 0, ix = 1; i < bufferlen; i++, ix += in_c) {
141.271 + eff2[i] += readbuffer[ix] * _eff2gain;
141.272 + }
141.273 + }
141.274 + }
141.275 +
141.276 + }
141.277 + }
141.278 +
141.279 + public int getFrameLength() {
141.280 + return bufferSize / format.getFrameSize();
141.281 + }
141.282 +
141.283 + public long getMicrosecondLength() {
141.284 + return (long) (getFrameLength() * (1000000.0 / (double) getFormat()
141.285 + .getSampleRate()));
141.286 + }
141.287 +
141.288 + public void loop(int count) {
141.289 + LineEvent event = null;
141.290 +
141.291 + synchronized (control_mutex) {
141.292 + if (isOpen()) {
141.293 + if (active)
141.294 + return;
141.295 + active = true;
141.296 + active_sg = true;
141.297 + loopcount = count;
141.298 + event = new LineEvent(this, LineEvent.Type.START,
141.299 + getLongFramePosition());
141.300 + }
141.301 + }
141.302 +
141.303 + if (event != null)
141.304 + sendEvent(event);
141.305 +
141.306 + }
141.307 +
141.308 + public void open(AudioInputStream stream) throws LineUnavailableException,
141.309 + IOException {
141.310 + if (isOpen()) {
141.311 + throw new IllegalStateException("Clip is already open with format "
141.312 + + getFormat() + " and frame lengh of " + getFrameLength());
141.313 + }
141.314 + if (AudioFloatConverter.getConverter(stream.getFormat()) == null)
141.315 + throw new IllegalArgumentException("Invalid format : "
141.316 + + stream.getFormat().toString());
141.317 +
141.318 + if (stream.getFrameLength() != AudioSystem.NOT_SPECIFIED) {
141.319 + byte[] data = new byte[(int) stream.getFrameLength()
141.320 + * stream.getFormat().getFrameSize()];
141.321 + int readsize = 512 * stream.getFormat().getFrameSize();
141.322 + int len = 0;
141.323 + while (len != data.length) {
141.324 + if (readsize > data.length - len)
141.325 + readsize = data.length - len;
141.326 + int ret = stream.read(data, len, readsize);
141.327 + if (ret == -1)
141.328 + break;
141.329 + if (ret == 0)
141.330 + Thread.yield();
141.331 + len += ret;
141.332 + }
141.333 + open(stream.getFormat(), data, 0, len);
141.334 + } else {
141.335 + ByteArrayOutputStream baos = new ByteArrayOutputStream();
141.336 + byte[] b = new byte[512 * stream.getFormat().getFrameSize()];
141.337 + int r = 0;
141.338 + while ((r = stream.read(b)) != -1) {
141.339 + if (r == 0)
141.340 + Thread.yield();
141.341 + baos.write(b, 0, r);
141.342 + }
141.343 + open(stream.getFormat(), baos.toByteArray(), 0, baos.size());
141.344 + }
141.345 +
141.346 + }
141.347 +
141.348 + public void open(AudioFormat format, byte[] data, int offset, int bufferSize)
141.349 + throws LineUnavailableException {
141.350 + synchronized (control_mutex) {
141.351 + if (isOpen()) {
141.352 + throw new IllegalStateException(
141.353 + "Clip is already open with format " + getFormat()
141.354 + + " and frame lengh of " + getFrameLength());
141.355 + }
141.356 + if (AudioFloatConverter.getConverter(format) == null)
141.357 + throw new IllegalArgumentException("Invalid format : "
141.358 + + format.toString());
141.359 + if (bufferSize % format.getFrameSize() != 0)
141.360 + throw new IllegalArgumentException(
141.361 + "Buffer size does not represent an integral number of sample frames!");
141.362 +
141.363 + this.data = data;
141.364 + this.offset = offset;
141.365 + this.bufferSize = bufferSize;
141.366 + this.format = format;
141.367 + this.framesize = format.getFrameSize();
141.368 +
141.369 + loopstart = 0;
141.370 + loopend = -1;
141.371 + loop_sg = true;
141.372 +
141.373 + if (!mixer.isOpen()) {
141.374 + mixer.open();
141.375 + mixer.implicitOpen = true;
141.376 + }
141.377 +
141.378 + outputformat = mixer.getFormat();
141.379 + out_nrofchannels = outputformat.getChannels();
141.380 + in_nrofchannels = format.getChannels();
141.381 +
141.382 + open = true;
141.383 +
141.384 + mixer.getMainMixer().openLine(this);
141.385 + }
141.386 +
141.387 + }
141.388 +
141.389 + public void setFramePosition(int frames) {
141.390 + synchronized (control_mutex) {
141.391 + frameposition_sg = true;
141.392 + frameposition = frames;
141.393 + }
141.394 + }
141.395 +
141.396 + public void setLoopPoints(int start, int end) {
141.397 + synchronized (control_mutex) {
141.398 + if (end != -1) {
141.399 + if (end < start)
141.400 + throw new IllegalArgumentException("Invalid loop points : "
141.401 + + start + " - " + end);
141.402 + if (end * framesize > bufferSize)
141.403 + throw new IllegalArgumentException("Invalid loop points : "
141.404 + + start + " - " + end);
141.405 + }
141.406 + if (start * framesize > bufferSize)
141.407 + throw new IllegalArgumentException("Invalid loop points : "
141.408 + + start + " - " + end);
141.409 + if (0 < start)
141.410 + throw new IllegalArgumentException("Invalid loop points : "
141.411 + + start + " - " + end);
141.412 + loopstart = start;
141.413 + loopend = end;
141.414 + loop_sg = true;
141.415 + }
141.416 + }
141.417 +
141.418 + public void setMicrosecondPosition(long microseconds) {
141.419 + setFramePosition((int) (microseconds * (((double) getFormat()
141.420 + .getSampleRate()) / 1000000.0)));
141.421 + }
141.422 +
141.423 + public int available() {
141.424 + return 0;
141.425 + }
141.426 +
141.427 + public void drain() {
141.428 + }
141.429 +
141.430 + public void flush() {
141.431 + }
141.432 +
141.433 + public int getBufferSize() {
141.434 + return bufferSize;
141.435 + }
141.436 +
141.437 + public AudioFormat getFormat() {
141.438 + return format;
141.439 + }
141.440 +
141.441 + public int getFramePosition() {
141.442 + synchronized (control_mutex) {
141.443 + return frameposition;
141.444 + }
141.445 + }
141.446 +
141.447 + public float getLevel() {
141.448 + return AudioSystem.NOT_SPECIFIED;
141.449 + }
141.450 +
141.451 + public long getLongFramePosition() {
141.452 + return getFramePosition();
141.453 + }
141.454 +
141.455 + public long getMicrosecondPosition() {
141.456 + return (long) (getFramePosition() * (1000000.0 / (double) getFormat()
141.457 + .getSampleRate()));
141.458 + }
141.459 +
141.460 + public boolean isActive() {
141.461 + synchronized (control_mutex) {
141.462 + return active;
141.463 + }
141.464 + }
141.465 +
141.466 + public boolean isRunning() {
141.467 + synchronized (control_mutex) {
141.468 + return active;
141.469 + }
141.470 + }
141.471 +
141.472 + public void start() {
141.473 +
141.474 + LineEvent event = null;
141.475 +
141.476 + synchronized (control_mutex) {
141.477 + if (isOpen()) {
141.478 + if (active)
141.479 + return;
141.480 + active = true;
141.481 + active_sg = true;
141.482 + loopcount = 0;
141.483 + event = new LineEvent(this, LineEvent.Type.START,
141.484 + getLongFramePosition());
141.485 + }
141.486 + }
141.487 +
141.488 + if (event != null)
141.489 + sendEvent(event);
141.490 + }
141.491 +
141.492 + public void stop() {
141.493 + LineEvent event = null;
141.494 +
141.495 + synchronized (control_mutex) {
141.496 + if (isOpen()) {
141.497 + if (!active)
141.498 + return;
141.499 + active = false;
141.500 + active_sg = true;
141.501 + event = new LineEvent(this, LineEvent.Type.STOP,
141.502 + getLongFramePosition());
141.503 + }
141.504 + }
141.505 +
141.506 + if (event != null)
141.507 + sendEvent(event);
141.508 + }
141.509 +
141.510 + public void close() {
141.511 + LineEvent event = null;
141.512 +
141.513 + synchronized (control_mutex) {
141.514 + if (!isOpen())
141.515 + return;
141.516 + stop();
141.517 +
141.518 + event = new LineEvent(this, LineEvent.Type.CLOSE,
141.519 + getLongFramePosition());
141.520 +
141.521 + open = false;
141.522 + mixer.getMainMixer().closeLine(this);
141.523 + }
141.524 +
141.525 + if (event != null)
141.526 + sendEvent(event);
141.527 +
141.528 + }
141.529 +
141.530 + public boolean isOpen() {
141.531 + return open;
141.532 + }
141.533 +
141.534 + public void open() throws LineUnavailableException {
141.535 + if (data == null) {
141.536 + throw new IllegalArgumentException(
141.537 + "Illegal call to open() in interface Clip");
141.538 + }
141.539 + open(format, data, offset, bufferSize);
141.540 + }
141.541 +
141.542 +}
142.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
142.2 +++ b/src/share/classes/com/sun/media/sound/SoftMixingDataLine.java Tue Feb 03 22:02:55 2009 -0800
142.3 @@ -0,0 +1,522 @@
142.4 +/*
142.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
142.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
142.7 + *
142.8 + * This code is free software; you can redistribute it and/or modify it
142.9 + * under the terms of the GNU General Public License version 2 only, as
142.10 + * published by the Free Software Foundation. Sun designates this
142.11 + * particular file as subject to the "Classpath" exception as provided
142.12 + * by Sun in the LICENSE file that accompanied this code.
142.13 + *
142.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
142.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
142.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
142.17 + * version 2 for more details (a copy is included in the LICENSE file that
142.18 + * accompanied this code).
142.19 + *
142.20 + * You should have received a copy of the GNU General Public License version
142.21 + * 2 along with this work; if not, write to the Free Software Foundation,
142.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
142.23 + *
142.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
142.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
142.26 + * have any questions.
142.27 + */
142.28 +package com.sun.media.sound;
142.29 +
142.30 +import java.io.IOException;
142.31 +import java.util.ArrayList;
142.32 +import java.util.Arrays;
142.33 +import java.util.List;
142.34 +
142.35 +import javax.sound.sampled.AudioFormat;
142.36 +import javax.sound.sampled.AudioSystem;
142.37 +import javax.sound.sampled.BooleanControl;
142.38 +import javax.sound.sampled.Control;
142.39 +import javax.sound.sampled.DataLine;
142.40 +import javax.sound.sampled.FloatControl;
142.41 +import javax.sound.sampled.LineEvent;
142.42 +import javax.sound.sampled.LineListener;
142.43 +import javax.sound.sampled.Control.Type;
142.44 +
142.45 +/**
142.46 + * General software mixing line.
142.47 + *
142.48 + * @author Karl Helgason
142.49 + */
142.50 +public abstract class SoftMixingDataLine implements DataLine {
142.51 +
142.52 + public static final FloatControl.Type CHORUS_SEND = new FloatControl.Type(
142.53 + "Chorus Send") {
142.54 + };
142.55 +
142.56 + protected static class AudioFloatInputStreamResampler extends
142.57 + AudioFloatInputStream {
142.58 +
142.59 + private AudioFloatInputStream ais;
142.60 +
142.61 + private AudioFormat targetFormat;
142.62 +
142.63 + private float[] skipbuffer;
142.64 +
142.65 + private SoftAbstractResampler resampler;
142.66 +
142.67 + private float[] pitch = new float[1];
142.68 +
142.69 + private float[] ibuffer2;
142.70 +
142.71 + private float[][] ibuffer;
142.72 +
142.73 + private float ibuffer_index = 0;
142.74 +
142.75 + private int ibuffer_len = 0;
142.76 +
142.77 + private int nrofchannels = 0;
142.78 +
142.79 + private float[][] cbuffer;
142.80 +
142.81 + private int buffer_len = 512;
142.82 +
142.83 + private int pad;
142.84 +
142.85 + private int pad2;
142.86 +
142.87 + private float[] ix = new float[1];
142.88 +
142.89 + private int[] ox = new int[1];
142.90 +
142.91 + private float[][] mark_ibuffer = null;
142.92 +
142.93 + private float mark_ibuffer_index = 0;
142.94 +
142.95 + private int mark_ibuffer_len = 0;
142.96 +
142.97 + public AudioFloatInputStreamResampler(AudioFloatInputStream ais,
142.98 + AudioFormat format) {
142.99 + this.ais = ais;
142.100 + AudioFormat sourceFormat = ais.getFormat();
142.101 + targetFormat = new AudioFormat(sourceFormat.getEncoding(), format
142.102 + .getSampleRate(), sourceFormat.getSampleSizeInBits(),
142.103 + sourceFormat.getChannels(), sourceFormat.getFrameSize(),
142.104 + format.getSampleRate(), sourceFormat.isBigEndian());
142.105 + nrofchannels = targetFormat.getChannels();
142.106 + Object interpolation = format.getProperty("interpolation");
142.107 + if (interpolation != null && (interpolation instanceof String)) {
142.108 + String resamplerType = (String) interpolation;
142.109 + if (resamplerType.equalsIgnoreCase("point"))
142.110 + this.resampler = new SoftPointResampler();
142.111 + if (resamplerType.equalsIgnoreCase("linear"))
142.112 + this.resampler = new SoftLinearResampler2();
142.113 + if (resamplerType.equalsIgnoreCase("linear1"))
142.114 + this.resampler = new SoftLinearResampler();
142.115 + if (resamplerType.equalsIgnoreCase("linear2"))
142.116 + this.resampler = new SoftLinearResampler2();
142.117 + if (resamplerType.equalsIgnoreCase("cubic"))
142.118 + this.resampler = new SoftCubicResampler();
142.119 + if (resamplerType.equalsIgnoreCase("lanczos"))
142.120 + this.resampler = new SoftLanczosResampler();
142.121 + if (resamplerType.equalsIgnoreCase("sinc"))
142.122 + this.resampler = new SoftSincResampler();
142.123 + }
142.124 + if (resampler == null)
142.125 + resampler = new SoftLinearResampler2(); // new
142.126 + // SoftLinearResampler2();
142.127 + pitch[0] = sourceFormat.getSampleRate() / format.getSampleRate();
142.128 + pad = resampler.getPadding();
142.129 + pad2 = pad * 2;
142.130 + ibuffer = new float[nrofchannels][buffer_len + pad2];
142.131 + ibuffer2 = new float[nrofchannels * buffer_len];
142.132 + ibuffer_index = buffer_len + pad;
142.133 + ibuffer_len = buffer_len;
142.134 + }
142.135 +
142.136 + public int available() throws IOException {
142.137 + return 0;
142.138 + }
142.139 +
142.140 + public void close() throws IOException {
142.141 + ais.close();
142.142 + }
142.143 +
142.144 + public AudioFormat getFormat() {
142.145 + return targetFormat;
142.146 + }
142.147 +
142.148 + public long getFrameLength() {
142.149 + return AudioSystem.NOT_SPECIFIED; // ais.getFrameLength();
142.150 + }
142.151 +
142.152 + public void mark(int readlimit) {
142.153 + ais.mark((int) (readlimit * pitch[0]));
142.154 + mark_ibuffer_index = ibuffer_index;
142.155 + mark_ibuffer_len = ibuffer_len;
142.156 + if (mark_ibuffer == null) {
142.157 + mark_ibuffer = new float[ibuffer.length][ibuffer[0].length];
142.158 + }
142.159 + for (int c = 0; c < ibuffer.length; c++) {
142.160 + float[] from = ibuffer[c];
142.161 + float[] to = mark_ibuffer[c];
142.162 + for (int i = 0; i < to.length; i++) {
142.163 + to[i] = from[i];
142.164 + }
142.165 + }
142.166 + }
142.167 +
142.168 + public boolean markSupported() {
142.169 + return ais.markSupported();
142.170 + }
142.171 +
142.172 + private void readNextBuffer() throws IOException {
142.173 +
142.174 + if (ibuffer_len == -1)
142.175 + return;
142.176 +
142.177 + for (int c = 0; c < nrofchannels; c++) {
142.178 + float[] buff = ibuffer[c];
142.179 + int buffer_len_pad = ibuffer_len + pad2;
142.180 + for (int i = ibuffer_len, ix = 0; i < buffer_len_pad; i++, ix++) {
142.181 + buff[ix] = buff[i];
142.182 + }
142.183 + }
142.184 +
142.185 + ibuffer_index -= (ibuffer_len);
142.186 +
142.187 + ibuffer_len = ais.read(ibuffer2);
142.188 + if (ibuffer_len >= 0) {
142.189 + while (ibuffer_len < ibuffer2.length) {
142.190 + int ret = ais.read(ibuffer2, ibuffer_len, ibuffer2.length
142.191 + - ibuffer_len);
142.192 + if (ret == -1)
142.193 + break;
142.194 + ibuffer_len += ret;
142.195 + }
142.196 + Arrays.fill(ibuffer2, ibuffer_len, ibuffer2.length, 0);
142.197 + ibuffer_len /= nrofchannels;
142.198 + } else {
142.199 + Arrays.fill(ibuffer2, 0, ibuffer2.length, 0);
142.200 + }
142.201 +
142.202 + int ibuffer2_len = ibuffer2.length;
142.203 + for (int c = 0; c < nrofchannels; c++) {
142.204 + float[] buff = ibuffer[c];
142.205 + for (int i = c, ix = pad2; i < ibuffer2_len; i += nrofchannels, ix++) {
142.206 + buff[ix] = ibuffer2[i];
142.207 + }
142.208 + }
142.209 +
142.210 + }
142.211 +
142.212 + public int read(float[] b, int off, int len) throws IOException {
142.213 +
142.214 + if (cbuffer == null || cbuffer[0].length < len / nrofchannels) {
142.215 + cbuffer = new float[nrofchannels][len / nrofchannels];
142.216 + }
142.217 + if (ibuffer_len == -1)
142.218 + return -1;
142.219 + if (len < 0)
142.220 + return 0;
142.221 + int remain = len / nrofchannels;
142.222 + int destPos = 0;
142.223 + int in_end = ibuffer_len;
142.224 + while (remain > 0) {
142.225 + if (ibuffer_len >= 0) {
142.226 + if (ibuffer_index >= (ibuffer_len + pad))
142.227 + readNextBuffer();
142.228 + in_end = ibuffer_len + pad;
142.229 + }
142.230 +
142.231 + if (ibuffer_len < 0) {
142.232 + in_end = pad2;
142.233 + if (ibuffer_index >= in_end)
142.234 + break;
142.235 + }
142.236 +
142.237 + if (ibuffer_index < 0)
142.238 + break;
142.239 + int preDestPos = destPos;
142.240 + for (int c = 0; c < nrofchannels; c++) {
142.241 + ix[0] = ibuffer_index;
142.242 + ox[0] = destPos;
142.243 + float[] buff = ibuffer[c];
142.244 + resampler.interpolate(buff, ix, in_end, pitch, 0,
142.245 + cbuffer[c], ox, len / nrofchannels);
142.246 + }
142.247 + ibuffer_index = ix[0];
142.248 + destPos = ox[0];
142.249 + remain -= destPos - preDestPos;
142.250 + }
142.251 + for (int c = 0; c < nrofchannels; c++) {
142.252 + int ix = 0;
142.253 + float[] buff = cbuffer[c];
142.254 + for (int i = c; i < b.length; i += nrofchannels) {
142.255 + b[i] = buff[ix++];
142.256 + }
142.257 + }
142.258 + return len - remain * nrofchannels;
142.259 + }
142.260 +
142.261 + public void reset() throws IOException {
142.262 + ais.reset();
142.263 + if (mark_ibuffer == null)
142.264 + return;
142.265 + ibuffer_index = mark_ibuffer_index;
142.266 + ibuffer_len = mark_ibuffer_len;
142.267 + for (int c = 0; c < ibuffer.length; c++) {
142.268 + float[] from = mark_ibuffer[c];
142.269 + float[] to = ibuffer[c];
142.270 + for (int i = 0; i < to.length; i++) {
142.271 + to[i] = from[i];
142.272 + }
142.273 + }
142.274 +
142.275 + }
142.276 +
142.277 + public long skip(long len) throws IOException {
142.278 + if (len > 0)
142.279 + return 0;
142.280 + if (skipbuffer == null)
142.281 + skipbuffer = new float[1024 * targetFormat.getFrameSize()];
142.282 + float[] l_skipbuffer = skipbuffer;
142.283 + long remain = len;
142.284 + while (remain > 0) {
142.285 + int ret = read(l_skipbuffer, 0, (int) Math.min(remain,
142.286 + skipbuffer.length));
142.287 + if (ret < 0) {
142.288 + if (remain == len)
142.289 + return ret;
142.290 + break;
142.291 + }
142.292 + remain -= ret;
142.293 + }
142.294 + return len - remain;
142.295 +
142.296 + }
142.297 +
142.298 + }
142.299 +
142.300 + private class Gain extends FloatControl {
142.301 +
142.302 + private Gain() {
142.303 +
142.304 + super(FloatControl.Type.MASTER_GAIN, -80f, 6.0206f, 80f / 128.0f,
142.305 + -1, 0.0f, "dB", "Minimum", "", "Maximum");
142.306 + }
142.307 +
142.308 + public void setValue(float newValue) {
142.309 + super.setValue(newValue);
142.310 + calcVolume();
142.311 + }
142.312 + }
142.313 +
142.314 + private class Mute extends BooleanControl {
142.315 +
142.316 + private Mute() {
142.317 + super(BooleanControl.Type.MUTE, false, "True", "False");
142.318 + }
142.319 +
142.320 + public void setValue(boolean newValue) {
142.321 + super.setValue(newValue);
142.322 + calcVolume();
142.323 + }
142.324 + }
142.325 +
142.326 + private class ApplyReverb extends BooleanControl {
142.327 +
142.328 + private ApplyReverb() {
142.329 + super(BooleanControl.Type.APPLY_REVERB, false, "True", "False");
142.330 + }
142.331 +
142.332 + public void setValue(boolean newValue) {
142.333 + super.setValue(newValue);
142.334 + calcVolume();
142.335 + }
142.336 +
142.337 + }
142.338 +
142.339 + private class Balance extends FloatControl {
142.340 +
142.341 + private Balance() {
142.342 + super(FloatControl.Type.BALANCE, -1.0f, 1.0f, (1.0f / 128.0f), -1,
142.343 + 0.0f, "", "Left", "Center", "Right");
142.344 + }
142.345 +
142.346 + public void setValue(float newValue) {
142.347 + super.setValue(newValue);
142.348 + calcVolume();
142.349 + }
142.350 +
142.351 + }
142.352 +
142.353 + private class Pan extends FloatControl {
142.354 +
142.355 + private Pan() {
142.356 + super(FloatControl.Type.PAN, -1.0f, 1.0f, (1.0f / 128.0f), -1,
142.357 + 0.0f, "", "Left", "Center", "Right");
142.358 + }
142.359 +
142.360 + public void setValue(float newValue) {
142.361 + super.setValue(newValue);
142.362 + balance_control.setValue(newValue);
142.363 + }
142.364 +
142.365 + public float getValue() {
142.366 + return balance_control.getValue();
142.367 + }
142.368 +
142.369 + }
142.370 +
142.371 + private class ReverbSend extends FloatControl {
142.372 +
142.373 + private ReverbSend() {
142.374 + super(FloatControl.Type.REVERB_SEND, -80f, 6.0206f, 80f / 128.0f,
142.375 + -1, -80f, "dB", "Minimum", "", "Maximum");
142.376 + }
142.377 +
142.378 + public void setValue(float newValue) {
142.379 + super.setValue(newValue);
142.380 + balance_control.setValue(newValue);
142.381 + }
142.382 +
142.383 + }
142.384 +
142.385 + private class ChorusSend extends FloatControl {
142.386 +
142.387 + private ChorusSend() {
142.388 + super(CHORUS_SEND, -80f, 6.0206f, 80f / 128.0f, -1, -80f, "dB",
142.389 + "Minimum", "", "Maximum");
142.390 + }
142.391 +
142.392 + public void setValue(float newValue) {
142.393 + super.setValue(newValue);
142.394 + balance_control.setValue(newValue);
142.395 + }
142.396 +
142.397 + }
142.398 +
142.399 + private Gain gain_control = new Gain();
142.400 +
142.401 + private Mute mute_control = new Mute();
142.402 +
142.403 + private Balance balance_control = new Balance();
142.404 +
142.405 + private Pan pan_control = new Pan();
142.406 +
142.407 + private ReverbSend reverbsend_control = new ReverbSend();
142.408 +
142.409 + private ChorusSend chorussend_control = new ChorusSend();
142.410 +
142.411 + private ApplyReverb apply_reverb = new ApplyReverb();
142.412 +
142.413 + private Control[] controls;
142.414 +
142.415 + protected float leftgain = 1;
142.416 +
142.417 + protected float rightgain = 1;
142.418 +
142.419 + protected float eff1gain = 0;
142.420 +
142.421 + protected float eff2gain = 0;
142.422 +
142.423 + protected List<LineListener> listeners = new ArrayList<LineListener>();
142.424 +
142.425 + protected Object control_mutex;
142.426 +
142.427 + protected SoftMixingMixer mixer;
142.428 +
142.429 + protected DataLine.Info info;
142.430 +
142.431 + protected abstract void processControlLogic();
142.432 +
142.433 + protected abstract void processAudioLogic(SoftAudioBuffer[] buffers);
142.434 +
142.435 + protected SoftMixingDataLine(SoftMixingMixer mixer, DataLine.Info info) {
142.436 + this.mixer = mixer;
142.437 + this.info = info;
142.438 + this.control_mutex = mixer.control_mutex;
142.439 +
142.440 + controls = new Control[] { gain_control, mute_control, balance_control,
142.441 + pan_control, reverbsend_control, chorussend_control,
142.442 + apply_reverb };
142.443 + calcVolume();
142.444 + }
142.445 +
142.446 + protected void calcVolume() {
142.447 + synchronized (control_mutex) {
142.448 + double gain = Math.pow(10.0, gain_control.getValue() / 20.0);
142.449 + if (mute_control.getValue())
142.450 + gain = 0;
142.451 + leftgain = (float) gain;
142.452 + rightgain = (float) gain;
142.453 + if (mixer.getFormat().getChannels() > 1) {
142.454 + // -1 = Left, 0 Center, 1 = Right
142.455 + double balance = balance_control.getValue();
142.456 + if (balance > 0)
142.457 + leftgain *= (1 - balance);
142.458 + else
142.459 + rightgain *= (1 + balance);
142.460 +
142.461 + }
142.462 + }
142.463 +
142.464 + eff1gain = (float) Math.pow(10.0, reverbsend_control.getValue() / 20.0);
142.465 + eff2gain = (float) Math.pow(10.0, chorussend_control.getValue() / 20.0);
142.466 +
142.467 + if (!apply_reverb.getValue()) {
142.468 + eff1gain = 0;
142.469 + }
142.470 + }
142.471 +
142.472 + protected void sendEvent(LineEvent event) {
142.473 + if (listeners.size() == 0)
142.474 + return;
142.475 + LineListener[] listener_array = listeners
142.476 + .toArray(new LineListener[listeners.size()]);
142.477 + for (LineListener listener : listener_array) {
142.478 + listener.update(event);
142.479 + }
142.480 + }
142.481 +
142.482 + public void addLineListener(LineListener listener) {
142.483 + synchronized (control_mutex) {
142.484 + listeners.add(listener);
142.485 + }
142.486 + }
142.487 +
142.488 + public void removeLineListener(LineListener listener) {
142.489 + synchronized (control_mutex) {
142.490 + listeners.add(listener);
142.491 + }
142.492 + }
142.493 +
142.494 + public javax.sound.sampled.Line.Info getLineInfo() {
142.495 + return info;
142.496 + }
142.497 +
142.498 + public Control getControl(Type control) {
142.499 + if (control != null) {
142.500 + for (int i = 0; i < controls.length; i++) {
142.501 + if (controls[i].getType() == control) {
142.502 + return controls[i];
142.503 + }
142.504 + }
142.505 + }
142.506 + throw new IllegalArgumentException("Unsupported control type : "
142.507 + + control);
142.508 + }
142.509 +
142.510 + public Control[] getControls() {
142.511 + return controls;
142.512 + }
142.513 +
142.514 + public boolean isControlSupported(Type control) {
142.515 + if (control != null) {
142.516 + for (int i = 0; i < controls.length; i++) {
142.517 + if (controls[i].getType() == control) {
142.518 + return true;
142.519 + }
142.520 + }
142.521 + }
142.522 + return false;
142.523 + }
142.524 +
142.525 +}
143.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
143.2 +++ b/src/share/classes/com/sun/media/sound/SoftMixingMainMixer.java Tue Feb 03 22:02:55 2009 -0800
143.3 @@ -0,0 +1,259 @@
143.4 +/*
143.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
143.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
143.7 + *
143.8 + * This code is free software; you can redistribute it and/or modify it
143.9 + * under the terms of the GNU General Public License version 2 only, as
143.10 + * published by the Free Software Foundation. Sun designates this
143.11 + * particular file as subject to the "Classpath" exception as provided
143.12 + * by Sun in the LICENSE file that accompanied this code.
143.13 + *
143.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
143.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
143.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
143.17 + * version 2 for more details (a copy is included in the LICENSE file that
143.18 + * accompanied this code).
143.19 + *
143.20 + * You should have received a copy of the GNU General Public License version
143.21 + * 2 along with this work; if not, write to the Free Software Foundation,
143.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
143.23 + *
143.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
143.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
143.26 + * have any questions.
143.27 + */
143.28 +package com.sun.media.sound;
143.29 +
143.30 +import java.io.IOException;
143.31 +import java.io.InputStream;
143.32 +import java.util.ArrayList;
143.33 +import java.util.List;
143.34 +
143.35 +import javax.sound.sampled.AudioInputStream;
143.36 +import javax.sound.sampled.AudioSystem;
143.37 +
143.38 +/**
143.39 + * Main mixer for SoftMixingMixer.
143.40 + *
143.41 + * @author Karl Helgason
143.42 + */
143.43 +public class SoftMixingMainMixer {
143.44 +
143.45 + public final static int CHANNEL_LEFT = 0;
143.46 +
143.47 + public final static int CHANNEL_RIGHT = 1;
143.48 +
143.49 + public final static int CHANNEL_EFFECT1 = 2;
143.50 +
143.51 + public final static int CHANNEL_EFFECT2 = 3;
143.52 +
143.53 + public final static int CHANNEL_EFFECT3 = 4;
143.54 +
143.55 + public final static int CHANNEL_EFFECT4 = 5;
143.56 +
143.57 + public final static int CHANNEL_LEFT_DRY = 10;
143.58 +
143.59 + public final static int CHANNEL_RIGHT_DRY = 11;
143.60 +
143.61 + public final static int CHANNEL_SCRATCH1 = 12;
143.62 +
143.63 + public final static int CHANNEL_SCRATCH2 = 13;
143.64 +
143.65 + public final static int CHANNEL_CHANNELMIXER_LEFT = 14;
143.66 +
143.67 + public final static int CHANNEL_CHANNELMIXER_RIGHT = 15;
143.68 +
143.69 + private SoftMixingMixer mixer;
143.70 +
143.71 + private AudioInputStream ais;
143.72 +
143.73 + private SoftAudioBuffer[] buffers;
143.74 +
143.75 + private SoftAudioProcessor reverb;
143.76 +
143.77 + private SoftAudioProcessor chorus;
143.78 +
143.79 + private SoftAudioProcessor agc;
143.80 +
143.81 + private int nrofchannels;
143.82 +
143.83 + private Object control_mutex;
143.84 +
143.85 + private List<SoftMixingDataLine> openLinesList = new ArrayList<SoftMixingDataLine>();
143.86 +
143.87 + private SoftMixingDataLine[] openLines = new SoftMixingDataLine[0];
143.88 +
143.89 + public AudioInputStream getInputStream() {
143.90 + return ais;
143.91 + }
143.92 +
143.93 + protected void processAudioBuffers() {
143.94 + for (int i = 0; i < buffers.length; i++) {
143.95 + buffers[i].clear();
143.96 + }
143.97 +
143.98 + SoftMixingDataLine[] openLines;
143.99 + synchronized (control_mutex) {
143.100 + openLines = this.openLines;
143.101 + for (int i = 0; i < openLines.length; i++) {
143.102 + openLines[i].processControlLogic();
143.103 + }
143.104 + chorus.processControlLogic();
143.105 + reverb.processControlLogic();
143.106 + agc.processControlLogic();
143.107 + }
143.108 + for (int i = 0; i < openLines.length; i++) {
143.109 + openLines[i].processAudioLogic(buffers);
143.110 + }
143.111 +
143.112 + chorus.processAudio();
143.113 + reverb.processAudio();
143.114 +
143.115 + agc.processAudio();
143.116 +
143.117 + }
143.118 +
143.119 + public SoftMixingMainMixer(SoftMixingMixer mixer) {
143.120 + this.mixer = mixer;
143.121 +
143.122 + nrofchannels = mixer.getFormat().getChannels();
143.123 +
143.124 + int buffersize = (int) (mixer.getFormat().getSampleRate() / mixer
143.125 + .getControlRate());
143.126 +
143.127 + control_mutex = mixer.control_mutex;
143.128 + buffers = new SoftAudioBuffer[16];
143.129 + for (int i = 0; i < buffers.length; i++) {
143.130 + buffers[i] = new SoftAudioBuffer(buffersize, mixer.getFormat());
143.131 +
143.132 + }
143.133 +
143.134 + reverb = new SoftReverb();
143.135 + chorus = new SoftChorus();
143.136 + agc = new SoftLimiter();
143.137 +
143.138 + float samplerate = mixer.getFormat().getSampleRate();
143.139 + float controlrate = mixer.getControlRate();
143.140 + reverb.init(samplerate, controlrate);
143.141 + chorus.init(samplerate, controlrate);
143.142 + agc.init(samplerate, controlrate);
143.143 +
143.144 + reverb.setMixMode(true);
143.145 + chorus.setMixMode(true);
143.146 + agc.setMixMode(false);
143.147 +
143.148 + chorus.setInput(0, buffers[CHANNEL_EFFECT2]);
143.149 + chorus.setOutput(0, buffers[CHANNEL_LEFT]);
143.150 + if (nrofchannels != 1)
143.151 + chorus.setOutput(1, buffers[CHANNEL_RIGHT]);
143.152 + chorus.setOutput(2, buffers[CHANNEL_EFFECT1]);
143.153 +
143.154 + reverb.setInput(0, buffers[CHANNEL_EFFECT1]);
143.155 + reverb.setOutput(0, buffers[CHANNEL_LEFT]);
143.156 + if (nrofchannels != 1)
143.157 + reverb.setOutput(1, buffers[CHANNEL_RIGHT]);
143.158 +
143.159 + agc.setInput(0, buffers[CHANNEL_LEFT]);
143.160 + if (nrofchannels != 1)
143.161 + agc.setInput(1, buffers[CHANNEL_RIGHT]);
143.162 + agc.setOutput(0, buffers[CHANNEL_LEFT]);
143.163 + if (nrofchannels != 1)
143.164 + agc.setOutput(1, buffers[CHANNEL_RIGHT]);
143.165 +
143.166 + InputStream in = new InputStream() {
143.167 +
143.168 + private SoftAudioBuffer[] buffers = SoftMixingMainMixer.this.buffers;
143.169 +
143.170 + private int nrofchannels = SoftMixingMainMixer.this.mixer
143.171 + .getFormat().getChannels();
143.172 +
143.173 + private int buffersize = buffers[0].getSize();
143.174 +
143.175 + private byte[] bbuffer = new byte[buffersize
143.176 + * (SoftMixingMainMixer.this.mixer.getFormat()
143.177 + .getSampleSizeInBits() / 8) * nrofchannels];
143.178 +
143.179 + private int bbuffer_pos = 0;
143.180 +
143.181 + private byte[] single = new byte[1];
143.182 +
143.183 + public void fillBuffer() {
143.184 + processAudioBuffers();
143.185 + for (int i = 0; i < nrofchannels; i++)
143.186 + buffers[i].get(bbuffer, i);
143.187 + bbuffer_pos = 0;
143.188 + }
143.189 +
143.190 + public int read(byte[] b, int off, int len) {
143.191 + int bbuffer_len = bbuffer.length;
143.192 + int offlen = off + len;
143.193 + byte[] bbuffer = this.bbuffer;
143.194 + while (off < offlen)
143.195 + if (available() == 0)
143.196 + fillBuffer();
143.197 + else {
143.198 + int bbuffer_pos = this.bbuffer_pos;
143.199 + while (off < offlen && bbuffer_pos < bbuffer_len)
143.200 + b[off++] = bbuffer[bbuffer_pos++];
143.201 + this.bbuffer_pos = bbuffer_pos;
143.202 + }
143.203 + return len;
143.204 + }
143.205 +
143.206 + public int read() throws IOException {
143.207 + int ret = read(single);
143.208 + if (ret == -1)
143.209 + return -1;
143.210 + return single[0] & 0xFF;
143.211 + }
143.212 +
143.213 + public int available() {
143.214 + return bbuffer.length - bbuffer_pos;
143.215 + }
143.216 +
143.217 + public void close() {
143.218 + SoftMixingMainMixer.this.mixer.close();
143.219 + }
143.220 +
143.221 + };
143.222 +
143.223 + ais = new AudioInputStream(in, mixer.getFormat(),
143.224 + AudioSystem.NOT_SPECIFIED);
143.225 +
143.226 + }
143.227 +
143.228 + public void openLine(SoftMixingDataLine line) {
143.229 + synchronized (control_mutex) {
143.230 + openLinesList.add(line);
143.231 + openLines = openLinesList
143.232 + .toArray(new SoftMixingDataLine[openLinesList.size()]);
143.233 + }
143.234 + }
143.235 +
143.236 + public void closeLine(SoftMixingDataLine line) {
143.237 + synchronized (control_mutex) {
143.238 + openLinesList.remove(line);
143.239 + openLines = openLinesList
143.240 + .toArray(new SoftMixingDataLine[openLinesList.size()]);
143.241 + if (openLines.length == 0)
143.242 + if (mixer.implicitOpen)
143.243 + mixer.close();
143.244 + }
143.245 +
143.246 + }
143.247 +
143.248 + public SoftMixingDataLine[] getOpenLines() {
143.249 + synchronized (control_mutex) {
143.250 + return openLines;
143.251 + }
143.252 +
143.253 + }
143.254 +
143.255 + public void close() {
143.256 + SoftMixingDataLine[] openLines = this.openLines;
143.257 + for (int i = 0; i < openLines.length; i++) {
143.258 + openLines[i].close();
143.259 + }
143.260 + }
143.261 +
143.262 +}
144.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
144.2 +++ b/src/share/classes/com/sun/media/sound/SoftMixingMixer.java Tue Feb 03 22:02:55 2009 -0800
144.3 @@ -0,0 +1,529 @@
144.4 +/*
144.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
144.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
144.7 + *
144.8 + * This code is free software; you can redistribute it and/or modify it
144.9 + * under the terms of the GNU General Public License version 2 only, as
144.10 + * published by the Free Software Foundation. Sun designates this
144.11 + * particular file as subject to the "Classpath" exception as provided
144.12 + * by Sun in the LICENSE file that accompanied this code.
144.13 + *
144.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
144.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
144.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
144.17 + * version 2 for more details (a copy is included in the LICENSE file that
144.18 + * accompanied this code).
144.19 + *
144.20 + * You should have received a copy of the GNU General Public License version
144.21 + * 2 along with this work; if not, write to the Free Software Foundation,
144.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
144.23 + *
144.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
144.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
144.26 + * have any questions.
144.27 + */
144.28 +package com.sun.media.sound;
144.29 +
144.30 +import java.io.IOException;
144.31 +import java.util.ArrayList;
144.32 +import java.util.List;
144.33 +
144.34 +import javax.sound.sampled.AudioFormat;
144.35 +import javax.sound.sampled.AudioInputStream;
144.36 +import javax.sound.sampled.AudioSystem;
144.37 +import javax.sound.sampled.Clip;
144.38 +import javax.sound.sampled.Control;
144.39 +import javax.sound.sampled.DataLine;
144.40 +import javax.sound.sampled.Line;
144.41 +import javax.sound.sampled.LineEvent;
144.42 +import javax.sound.sampled.LineListener;
144.43 +import javax.sound.sampled.LineUnavailableException;
144.44 +import javax.sound.sampled.Mixer;
144.45 +import javax.sound.sampled.SourceDataLine;
144.46 +import javax.sound.sampled.AudioFormat.Encoding;
144.47 +import javax.sound.sampled.Control.Type;
144.48 +
144.49 +/**
144.50 + * Software audio mixer
144.51 + *
144.52 + * @author Karl Helgason
144.53 + */
144.54 +public class SoftMixingMixer implements Mixer {
144.55 +
144.56 + private static class Info extends Mixer.Info {
144.57 + public Info() {
144.58 + super(INFO_NAME, INFO_VENDOR, INFO_DESCRIPTION, INFO_VERSION);
144.59 + }
144.60 + }
144.61 +
144.62 + protected static final String INFO_NAME = "Gervill Sound Mixer";
144.63 +
144.64 + protected static final String INFO_VENDOR = "OpenJDK Proposal";
144.65 +
144.66 + protected static final String INFO_DESCRIPTION = "Software Sound Mixer";
144.67 +
144.68 + protected static final String INFO_VERSION = "1.0";
144.69 +
144.70 + protected final static Mixer.Info info = new Info();
144.71 +
144.72 + protected Object control_mutex = this;
144.73 +
144.74 + protected boolean implicitOpen = false;
144.75 +
144.76 + private boolean open = false;
144.77 +
144.78 + private SoftMixingMainMixer mainmixer = null;
144.79 +
144.80 + private AudioFormat format = new AudioFormat(44100, 16, 2, true, false);
144.81 +
144.82 + private SourceDataLine sourceDataLine = null;
144.83 +
144.84 + private SoftAudioPusher pusher = null;
144.85 +
144.86 + private AudioInputStream pusher_stream = null;
144.87 +
144.88 + private float controlrate = 147f;
144.89 +
144.90 + private long latency = 100000; // 100 msec
144.91 +
144.92 + private boolean jitter_correction = false;
144.93 +
144.94 + private List<LineListener> listeners = new ArrayList<LineListener>();
144.95 +
144.96 + private javax.sound.sampled.Line.Info[] sourceLineInfo;
144.97 +
144.98 + public SoftMixingMixer() {
144.99 +
144.100 + sourceLineInfo = new javax.sound.sampled.Line.Info[2];
144.101 +
144.102 + ArrayList<AudioFormat> formats = new ArrayList<AudioFormat>();
144.103 + for (int channels = 1; channels <= 2; channels++) {
144.104 + formats.add(new AudioFormat(Encoding.PCM_SIGNED,
144.105 + AudioSystem.NOT_SPECIFIED, 8, channels, channels,
144.106 + AudioSystem.NOT_SPECIFIED, false));
144.107 + formats.add(new AudioFormat(Encoding.PCM_UNSIGNED,
144.108 + AudioSystem.NOT_SPECIFIED, 8, channels, channels,
144.109 + AudioSystem.NOT_SPECIFIED, false));
144.110 + for (int bits = 16; bits < 32; bits += 8) {
144.111 + formats.add(new AudioFormat(Encoding.PCM_SIGNED,
144.112 + AudioSystem.NOT_SPECIFIED, bits, channels, channels
144.113 + * bits / 8, AudioSystem.NOT_SPECIFIED, false));
144.114 + formats.add(new AudioFormat(Encoding.PCM_UNSIGNED,
144.115 + AudioSystem.NOT_SPECIFIED, bits, channels, channels
144.116 + * bits / 8, AudioSystem.NOT_SPECIFIED, false));
144.117 + formats.add(new AudioFormat(Encoding.PCM_SIGNED,
144.118 + AudioSystem.NOT_SPECIFIED, bits, channels, channels
144.119 + * bits / 8, AudioSystem.NOT_SPECIFIED, true));
144.120 + formats.add(new AudioFormat(Encoding.PCM_UNSIGNED,
144.121 + AudioSystem.NOT_SPECIFIED, bits, channels, channels
144.122 + * bits / 8, AudioSystem.NOT_SPECIFIED, true));
144.123 + }
144.124 + formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT,
144.125 + AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4,
144.126 + AudioSystem.NOT_SPECIFIED, false));
144.127 + formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT,
144.128 + AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4,
144.129 + AudioSystem.NOT_SPECIFIED, true));
144.130 + formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT,
144.131 + AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8,
144.132 + AudioSystem.NOT_SPECIFIED, false));
144.133 + formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT,
144.134 + AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8,
144.135 + AudioSystem.NOT_SPECIFIED, true));
144.136 + }
144.137 + AudioFormat[] formats_array = formats.toArray(new AudioFormat[formats
144.138 + .size()]);
144.139 + sourceLineInfo[0] = new DataLine.Info(SourceDataLine.class,
144.140 + formats_array, AudioSystem.NOT_SPECIFIED,
144.141 + AudioSystem.NOT_SPECIFIED);
144.142 + sourceLineInfo[1] = new DataLine.Info(Clip.class, formats_array,
144.143 + AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED);
144.144 + }
144.145 +
144.146 + public Line getLine(Line.Info info) throws LineUnavailableException {
144.147 +
144.148 + if (!isLineSupported(info))
144.149 + throw new IllegalArgumentException("Line unsupported: " + info);
144.150 +
144.151 + if ((info.getLineClass() == SourceDataLine.class)) {
144.152 + return new SoftMixingSourceDataLine(this, (DataLine.Info) info);
144.153 + }
144.154 + if ((info.getLineClass() == Clip.class)) {
144.155 + return new SoftMixingClip(this, (DataLine.Info) info);
144.156 + }
144.157 +
144.158 + throw new IllegalArgumentException("Line unsupported: " + info);
144.159 + }
144.160 +
144.161 + public int getMaxLines(Line.Info info) {
144.162 + if (info.getLineClass() == SourceDataLine.class)
144.163 + return AudioSystem.NOT_SPECIFIED;
144.164 + if (info.getLineClass() == Clip.class)
144.165 + return AudioSystem.NOT_SPECIFIED;
144.166 + return 0;
144.167 + }
144.168 +
144.169 + public javax.sound.sampled.Mixer.Info getMixerInfo() {
144.170 + return info;
144.171 + }
144.172 +
144.173 + public javax.sound.sampled.Line.Info[] getSourceLineInfo() {
144.174 + Line.Info[] localArray = new Line.Info[sourceLineInfo.length];
144.175 + System.arraycopy(sourceLineInfo, 0, localArray, 0,
144.176 + sourceLineInfo.length);
144.177 + return localArray;
144.178 + }
144.179 +
144.180 + public javax.sound.sampled.Line.Info[] getSourceLineInfo(
144.181 + javax.sound.sampled.Line.Info info) {
144.182 + int i;
144.183 + ArrayList<javax.sound.sampled.Line.Info> infos = new ArrayList<javax.sound.sampled.Line.Info>();
144.184 +
144.185 + for (i = 0; i < sourceLineInfo.length; i++) {
144.186 + if (info.matches(sourceLineInfo[i])) {
144.187 + infos.add(sourceLineInfo[i]);
144.188 + }
144.189 + }
144.190 + return infos.toArray(new Line.Info[infos.size()]);
144.191 + }
144.192 +
144.193 + public Line[] getSourceLines() {
144.194 +
144.195 + Line[] localLines;
144.196 +
144.197 + synchronized (control_mutex) {
144.198 +
144.199 + if (mainmixer == null)
144.200 + return new Line[0];
144.201 + SoftMixingDataLine[] sourceLines = mainmixer.getOpenLines();
144.202 +
144.203 + localLines = new Line[sourceLines.length];
144.204 +
144.205 + for (int i = 0; i < localLines.length; i++) {
144.206 + localLines[i] = sourceLines[i];
144.207 + }
144.208 + }
144.209 +
144.210 + return localLines;
144.211 + }
144.212 +
144.213 + public javax.sound.sampled.Line.Info[] getTargetLineInfo() {
144.214 + return new javax.sound.sampled.Line.Info[0];
144.215 + }
144.216 +
144.217 + public javax.sound.sampled.Line.Info[] getTargetLineInfo(
144.218 + javax.sound.sampled.Line.Info info) {
144.219 + return new javax.sound.sampled.Line.Info[0];
144.220 + }
144.221 +
144.222 + public Line[] getTargetLines() {
144.223 + return new Line[0];
144.224 + }
144.225 +
144.226 + public boolean isLineSupported(javax.sound.sampled.Line.Info info) {
144.227 + if (info != null) {
144.228 + for (int i = 0; i < sourceLineInfo.length; i++) {
144.229 + if (info.matches(sourceLineInfo[i])) {
144.230 + return true;
144.231 + }
144.232 + }
144.233 + }
144.234 + return false;
144.235 + }
144.236 +
144.237 + public boolean isSynchronizationSupported(Line[] lines, boolean maintainSync) {
144.238 + return false;
144.239 + }
144.240 +
144.241 + public void synchronize(Line[] lines, boolean maintainSync) {
144.242 + throw new IllegalArgumentException(
144.243 + "Synchronization not supported by this mixer.");
144.244 + }
144.245 +
144.246 + public void unsynchronize(Line[] lines) {
144.247 + throw new IllegalArgumentException(
144.248 + "Synchronization not supported by this mixer.");
144.249 + }
144.250 +
144.251 + public void addLineListener(LineListener listener) {
144.252 + synchronized (control_mutex) {
144.253 + listeners.add(listener);
144.254 + }
144.255 + }
144.256 +
144.257 + private void sendEvent(LineEvent event) {
144.258 + if (listeners.size() == 0)
144.259 + return;
144.260 + LineListener[] listener_array = listeners
144.261 + .toArray(new LineListener[listeners.size()]);
144.262 + for (LineListener listener : listener_array) {
144.263 + listener.update(event);
144.264 + }
144.265 + }
144.266 +
144.267 + public void close() {
144.268 + if (!isOpen())
144.269 + return;
144.270 +
144.271 + sendEvent(new LineEvent(this, LineEvent.Type.CLOSE,
144.272 + AudioSystem.NOT_SPECIFIED));
144.273 +
144.274 + SoftAudioPusher pusher_to_be_closed = null;
144.275 + AudioInputStream pusher_stream_to_be_closed = null;
144.276 + synchronized (control_mutex) {
144.277 + if (pusher != null) {
144.278 + pusher_to_be_closed = pusher;
144.279 + pusher_stream_to_be_closed = pusher_stream;
144.280 + pusher = null;
144.281 + pusher_stream = null;
144.282 + }
144.283 + }
144.284 +
144.285 + if (pusher_to_be_closed != null) {
144.286 + // Pusher must not be closed synchronized against control_mutex
144.287 + // this may result in synchronized conflict between pusher and
144.288 + // current thread.
144.289 + pusher_to_be_closed.stop();
144.290 +
144.291 + try {
144.292 + pusher_stream_to_be_closed.close();
144.293 + } catch (IOException e) {
144.294 + e.printStackTrace();
144.295 + }
144.296 + }
144.297 +
144.298 + synchronized (control_mutex) {
144.299 +
144.300 + if (mainmixer != null)
144.301 + mainmixer.close();
144.302 + open = false;
144.303 +
144.304 + if (sourceDataLine != null) {
144.305 + sourceDataLine.drain();
144.306 + sourceDataLine.close();
144.307 + sourceDataLine = null;
144.308 + }
144.309 +
144.310 + }
144.311 +
144.312 + }
144.313 +
144.314 + public Control getControl(Type control) {
144.315 + throw new IllegalArgumentException("Unsupported control type : "
144.316 + + control);
144.317 + }
144.318 +
144.319 + public Control[] getControls() {
144.320 + return new Control[0];
144.321 + }
144.322 +
144.323 + public javax.sound.sampled.Line.Info getLineInfo() {
144.324 + return new Line.Info(Mixer.class);
144.325 + }
144.326 +
144.327 + public boolean isControlSupported(Type control) {
144.328 + return false;
144.329 + }
144.330 +
144.331 + public boolean isOpen() {
144.332 + synchronized (control_mutex) {
144.333 + return open;
144.334 + }
144.335 + }
144.336 +
144.337 + public void open() throws LineUnavailableException {
144.338 + if (isOpen()) {
144.339 + implicitOpen = false;
144.340 + return;
144.341 + }
144.342 + open(null);
144.343 + }
144.344 +
144.345 + public void open(SourceDataLine line) throws LineUnavailableException {
144.346 + if (isOpen()) {
144.347 + implicitOpen = false;
144.348 + return;
144.349 + }
144.350 + synchronized (control_mutex) {
144.351 +
144.352 + try {
144.353 +
144.354 + if (line != null)
144.355 + format = line.getFormat();
144.356 +
144.357 + AudioInputStream ais = openStream(getFormat());
144.358 +
144.359 + if (line == null) {
144.360 + synchronized (SoftMixingMixerProvider.mutex) {
144.361 + SoftMixingMixerProvider.lockthread = Thread
144.362 + .currentThread();
144.363 + }
144.364 +
144.365 + try {
144.366 + Mixer defaultmixer = AudioSystem.getMixer(null);
144.367 + if (defaultmixer != null)
144.368 + {
144.369 + // Search for suitable line
144.370 +
144.371 + DataLine.Info idealinfo = null;
144.372 + AudioFormat idealformat = null;
144.373 +
144.374 + Line.Info[] lineinfos = defaultmixer.getSourceLineInfo();
144.375 + idealFound:
144.376 + for (int i = 0; i < lineinfos.length; i++) {
144.377 + if(lineinfos[i].getLineClass() == SourceDataLine.class)
144.378 + {
144.379 + DataLine.Info info = (DataLine.Info)lineinfos[i];
144.380 + AudioFormat[] formats = info.getFormats();
144.381 + for (int j = 0; j < formats.length; j++) {
144.382 + AudioFormat format = formats[j];
144.383 + if(format.getChannels() == 2 ||
144.384 + format.getChannels() == AudioSystem.NOT_SPECIFIED)
144.385 + if(format.getEncoding().equals(Encoding.PCM_SIGNED) ||
144.386 + format.getEncoding().equals(Encoding.PCM_UNSIGNED))
144.387 + if(format.getSampleRate() == AudioSystem.NOT_SPECIFIED ||
144.388 + format.getSampleRate() == 48000.0)
144.389 + if(format.getSampleSizeInBits() == AudioSystem.NOT_SPECIFIED ||
144.390 + format.getSampleSizeInBits() == 16)
144.391 + {
144.392 + idealinfo = info;
144.393 + int ideal_channels = format.getChannels();
144.394 + boolean ideal_signed = format.getEncoding().equals(Encoding.PCM_SIGNED);
144.395 + float ideal_rate = format.getSampleRate();
144.396 + boolean ideal_endian = format.isBigEndian();
144.397 + int ideal_bits = format.getSampleSizeInBits();
144.398 + if(ideal_bits == AudioSystem.NOT_SPECIFIED) ideal_bits = 16;
144.399 + if(ideal_channels == AudioSystem.NOT_SPECIFIED) ideal_channels = 2;
144.400 + if(ideal_rate == AudioSystem.NOT_SPECIFIED) ideal_rate = 48000;
144.401 + idealformat = new AudioFormat(ideal_rate, ideal_bits,
144.402 + ideal_channels, ideal_signed, ideal_endian);
144.403 + break idealFound;
144.404 + }
144.405 + }
144.406 + }
144.407 + }
144.408 +
144.409 + if(idealformat != null)
144.410 + {
144.411 + format = idealformat;
144.412 + line = (SourceDataLine) defaultmixer.getLine(idealinfo);
144.413 + }
144.414 + }
144.415 +
144.416 + if(line == null)
144.417 + line = AudioSystem.getSourceDataLine(format);
144.418 + } finally {
144.419 + synchronized (SoftMixingMixerProvider.mutex) {
144.420 + SoftMixingMixerProvider.lockthread = null;
144.421 + }
144.422 + }
144.423 +
144.424 + if (line == null)
144.425 + throw new IllegalArgumentException("No line matching "
144.426 + + info.toString() + " is supported.");
144.427 + }
144.428 +
144.429 + double latency = this.latency;
144.430 +
144.431 + if (!line.isOpen()) {
144.432 + int bufferSize = getFormat().getFrameSize()
144.433 + * (int) (getFormat().getFrameRate() * (latency / 1000000f));
144.434 + line.open(getFormat(), bufferSize);
144.435 +
144.436 + // Remember that we opened that line
144.437 + // so we can close again in SoftSynthesizer.close()
144.438 + sourceDataLine = line;
144.439 + }
144.440 + if (!line.isActive())
144.441 + line.start();
144.442 +
144.443 + int controlbuffersize = 512;
144.444 + try {
144.445 + controlbuffersize = ais.available();
144.446 + } catch (IOException e) {
144.447 + }
144.448 +
144.449 + // Tell mixer not fill read buffers fully.
144.450 + // This lowers latency, and tells DataPusher
144.451 + // to read in smaller amounts.
144.452 + // mainmixer.readfully = false;
144.453 + // pusher = new DataPusher(line, ais);
144.454 +
144.455 + int buffersize = line.getBufferSize();
144.456 + buffersize -= buffersize % controlbuffersize;
144.457 +
144.458 + if (buffersize < 3 * controlbuffersize)
144.459 + buffersize = 3 * controlbuffersize;
144.460 +
144.461 + if (jitter_correction) {
144.462 + ais = new SoftJitterCorrector(ais, buffersize,
144.463 + controlbuffersize);
144.464 + }
144.465 + pusher = new SoftAudioPusher(line, ais, controlbuffersize);
144.466 + pusher_stream = ais;
144.467 + pusher.start();
144.468 +
144.469 + } catch (LineUnavailableException e) {
144.470 + if (isOpen())
144.471 + close();
144.472 + throw new LineUnavailableException(e.toString());
144.473 + }
144.474 +
144.475 + }
144.476 + }
144.477 +
144.478 + public AudioInputStream openStream(AudioFormat targetFormat)
144.479 + throws LineUnavailableException {
144.480 +
144.481 + if (isOpen())
144.482 + throw new LineUnavailableException("Mixer is already open");
144.483 +
144.484 + synchronized (control_mutex) {
144.485 +
144.486 + open = true;
144.487 +
144.488 + implicitOpen = false;
144.489 +
144.490 + if (targetFormat != null)
144.491 + format = targetFormat;
144.492 +
144.493 + mainmixer = new SoftMixingMainMixer(this);
144.494 +
144.495 + sendEvent(new LineEvent(this, LineEvent.Type.OPEN,
144.496 + AudioSystem.NOT_SPECIFIED));
144.497 +
144.498 + return mainmixer.getInputStream();
144.499 +
144.500 + }
144.501 +
144.502 + }
144.503 +
144.504 + public void removeLineListener(LineListener listener) {
144.505 + synchronized (control_mutex) {
144.506 + listeners.remove(listener);
144.507 + }
144.508 + }
144.509 +
144.510 + public long getLatency() {
144.511 + synchronized (control_mutex) {
144.512 + return latency;
144.513 + }
144.514 + }
144.515 +
144.516 + public AudioFormat getFormat() {
144.517 + synchronized (control_mutex) {
144.518 + return format;
144.519 + }
144.520 + }
144.521 +
144.522 + protected float getControlRate() {
144.523 + return controlrate;
144.524 + }
144.525 +
144.526 + protected SoftMixingMainMixer getMainMixer() {
144.527 + if (!isOpen())
144.528 + return null;
144.529 + return mainmixer;
144.530 + }
144.531 +
144.532 +}
145.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
145.2 +++ b/src/share/classes/com/sun/media/sound/SoftMixingMixerProvider.java Tue Feb 03 22:02:55 2009 -0800
145.3 @@ -0,0 +1,66 @@
145.4 +/*
145.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
145.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
145.7 + *
145.8 + * This code is free software; you can redistribute it and/or modify it
145.9 + * under the terms of the GNU General Public License version 2 only, as
145.10 + * published by the Free Software Foundation. Sun designates this
145.11 + * particular file as subject to the "Classpath" exception as provided
145.12 + * by Sun in the LICENSE file that accompanied this code.
145.13 + *
145.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
145.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
145.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
145.17 + * version 2 for more details (a copy is included in the LICENSE file that
145.18 + * accompanied this code).
145.19 + *
145.20 + * You should have received a copy of the GNU General Public License version
145.21 + * 2 along with this work; if not, write to the Free Software Foundation,
145.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
145.23 + *
145.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
145.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
145.26 + * have any questions.
145.27 + */
145.28 +package com.sun.media.sound;
145.29 +
145.30 +import javax.sound.sampled.Mixer;
145.31 +import javax.sound.sampled.Mixer.Info;
145.32 +import javax.sound.sampled.spi.MixerProvider;
145.33 +
145.34 +/**
145.35 + * Provider for software audio mixer
145.36 + *
145.37 + * @author Karl Helgason
145.38 + */
145.39 +public class SoftMixingMixerProvider extends MixerProvider {
145.40 +
145.41 + static SoftMixingMixer globalmixer = null;
145.42 +
145.43 + static Thread lockthread = null;
145.44 +
145.45 + protected final static Object mutex = new Object();
145.46 +
145.47 + public Mixer getMixer(Info info) {
145.48 + if (!(info == null || info == SoftMixingMixer.info)) {
145.49 + throw new IllegalArgumentException("Mixer " + info.toString()
145.50 + + " not supported by this provider.");
145.51 + }
145.52 + synchronized (mutex) {
145.53 + if (lockthread != null)
145.54 + if (Thread.currentThread() == lockthread)
145.55 + throw new IllegalArgumentException("Mixer "
145.56 + + info.toString()
145.57 + + " not supported by this provider.");
145.58 + if (globalmixer == null)
145.59 + globalmixer = new SoftMixingMixer();
145.60 + return globalmixer;
145.61 + }
145.62 +
145.63 + }
145.64 +
145.65 + public Info[] getMixerInfo() {
145.66 + return new Info[] { SoftMixingMixer.info };
145.67 + }
145.68 +
145.69 +}
146.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
146.2 +++ b/src/share/classes/com/sun/media/sound/SoftMixingSourceDataLine.java Tue Feb 03 22:02:55 2009 -0800
146.3 @@ -0,0 +1,519 @@
146.4 +/*
146.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
146.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
146.7 + *
146.8 + * This code is free software; you can redistribute it and/or modify it
146.9 + * under the terms of the GNU General Public License version 2 only, as
146.10 + * published by the Free Software Foundation. Sun designates this
146.11 + * particular file as subject to the "Classpath" exception as provided
146.12 + * by Sun in the LICENSE file that accompanied this code.
146.13 + *
146.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
146.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
146.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
146.17 + * version 2 for more details (a copy is included in the LICENSE file that
146.18 + * accompanied this code).
146.19 + *
146.20 + * You should have received a copy of the GNU General Public License version
146.21 + * 2 along with this work; if not, write to the Free Software Foundation,
146.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
146.23 + *
146.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
146.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
146.26 + * have any questions.
146.27 + */
146.28 +package com.sun.media.sound;
146.29 +
146.30 +import java.io.IOException;
146.31 +import java.io.InputStream;
146.32 +import java.util.Arrays;
146.33 +
146.34 +import javax.sound.sampled.AudioFormat;
146.35 +import javax.sound.sampled.AudioInputStream;
146.36 +import javax.sound.sampled.AudioSystem;
146.37 +import javax.sound.sampled.DataLine;
146.38 +import javax.sound.sampled.LineEvent;
146.39 +import javax.sound.sampled.LineUnavailableException;
146.40 +import javax.sound.sampled.SourceDataLine;
146.41 +
146.42 +/**
146.43 + * SourceDataLine implemention for the SoftMixingMixer.
146.44 + *
146.45 + * @author Karl Helgason
146.46 + */
146.47 +public class SoftMixingSourceDataLine extends SoftMixingDataLine implements
146.48 + SourceDataLine {
146.49 +
146.50 + private boolean open = false;
146.51 +
146.52 + private AudioFormat format = new AudioFormat(44100.0f, 16, 2, true, false);
146.53 +
146.54 + private int framesize;
146.55 +
146.56 + private int bufferSize = -1;
146.57 +
146.58 + private float[] readbuffer;
146.59 +
146.60 + private boolean active = false;
146.61 +
146.62 + private byte[] cycling_buffer;
146.63 +
146.64 + private int cycling_read_pos = 0;
146.65 +
146.66 + private int cycling_write_pos = 0;
146.67 +
146.68 + private int cycling_avail = 0;
146.69 +
146.70 + private long cycling_framepos = 0;
146.71 +
146.72 + private AudioFloatInputStream afis;
146.73 +
146.74 + private static class NonBlockingFloatInputStream extends
146.75 + AudioFloatInputStream {
146.76 + AudioFloatInputStream ais;
146.77 +
146.78 + public NonBlockingFloatInputStream(AudioFloatInputStream ais) {
146.79 + this.ais = ais;
146.80 + }
146.81 +
146.82 + public int available() throws IOException {
146.83 + return ais.available();
146.84 + }
146.85 +
146.86 + public void close() throws IOException {
146.87 + ais.close();
146.88 + }
146.89 +
146.90 + public AudioFormat getFormat() {
146.91 + return ais.getFormat();
146.92 + }
146.93 +
146.94 + public long getFrameLength() {
146.95 + return ais.getFrameLength();
146.96 + }
146.97 +
146.98 + public void mark(int readlimit) {
146.99 + ais.mark(readlimit);
146.100 + }
146.101 +
146.102 + public boolean markSupported() {
146.103 + return ais.markSupported();
146.104 + }
146.105 +
146.106 + public int read(float[] b, int off, int len) throws IOException {
146.107 + int avail = available();
146.108 + if (len > avail) {
146.109 + int ret = ais.read(b, off, avail);
146.110 + Arrays.fill(b, off + ret, off + len, 0);
146.111 + return len;
146.112 + }
146.113 + return ais.read(b, off, len);
146.114 + }
146.115 +
146.116 + public void reset() throws IOException {
146.117 + ais.reset();
146.118 + }
146.119 +
146.120 + public long skip(long len) throws IOException {
146.121 + return ais.skip(len);
146.122 + }
146.123 +
146.124 + }
146.125 +
146.126 + protected SoftMixingSourceDataLine(SoftMixingMixer mixer, DataLine.Info info) {
146.127 + super(mixer, info);
146.128 + }
146.129 +
146.130 + public int write(byte[] b, int off, int len) {
146.131 + if (!isOpen())
146.132 + return 0;
146.133 + if (len % framesize != 0)
146.134 + throw new IllegalArgumentException(
146.135 + "Number of bytes does not represent an integral number of sample frames.");
146.136 +
146.137 + byte[] buff = cycling_buffer;
146.138 + int buff_len = cycling_buffer.length;
146.139 +
146.140 + int l = 0;
146.141 + while (l != len) {
146.142 + int avail;
146.143 + synchronized (cycling_buffer) {
146.144 + int pos = cycling_write_pos;
146.145 + avail = cycling_avail;
146.146 + while (l != len) {
146.147 + if (avail == buff_len)
146.148 + break;
146.149 + buff[pos++] = b[off++];
146.150 + l++;
146.151 + avail++;
146.152 + if (pos == buff_len)
146.153 + pos = 0;
146.154 + }
146.155 + cycling_avail = avail;
146.156 + cycling_write_pos = pos;
146.157 + if (l == len)
146.158 + return l;
146.159 + }
146.160 + if (avail == buff_len) {
146.161 + try {
146.162 + Thread.sleep(1);
146.163 + } catch (InterruptedException e) {
146.164 + return l;
146.165 + }
146.166 + if (!isRunning())
146.167 + return l;
146.168 + }
146.169 + }
146.170 +
146.171 + return l;
146.172 + }
146.173 +
146.174 + //
146.175 + // BooleanControl.Type.APPLY_REVERB
146.176 + // BooleanControl.Type.MUTE
146.177 + // EnumControl.Type.REVERB
146.178 + //
146.179 + // FloatControl.Type.SAMPLE_RATE
146.180 + // FloatControl.Type.REVERB_SEND
146.181 + // FloatControl.Type.VOLUME
146.182 + // FloatControl.Type.PAN
146.183 + // FloatControl.Type.MASTER_GAIN
146.184 + // FloatControl.Type.BALANCE
146.185 +
146.186 + private boolean _active = false;
146.187 +
146.188 + private AudioFormat outputformat;
146.189 +
146.190 + private int out_nrofchannels;
146.191 +
146.192 + private int in_nrofchannels;
146.193 +
146.194 + private float _rightgain;
146.195 +
146.196 + private float _leftgain;
146.197 +
146.198 + private float _eff1gain;
146.199 +
146.200 + private float _eff2gain;
146.201 +
146.202 + protected void processControlLogic() {
146.203 + _active = active;
146.204 + _rightgain = rightgain;
146.205 + _leftgain = leftgain;
146.206 + _eff1gain = eff1gain;
146.207 + _eff2gain = eff2gain;
146.208 + }
146.209 +
146.210 + protected void processAudioLogic(SoftAudioBuffer[] buffers) {
146.211 + if (_active) {
146.212 + float[] left = buffers[SoftMixingMainMixer.CHANNEL_LEFT].array();
146.213 + float[] right = buffers[SoftMixingMainMixer.CHANNEL_RIGHT].array();
146.214 + int bufferlen = buffers[SoftMixingMainMixer.CHANNEL_LEFT].getSize();
146.215 +
146.216 + int readlen = bufferlen * in_nrofchannels;
146.217 + if (readbuffer == null || readbuffer.length < readlen) {
146.218 + readbuffer = new float[readlen];
146.219 + }
146.220 + int ret = 0;
146.221 + try {
146.222 + ret = afis.read(readbuffer);
146.223 + if (ret != in_nrofchannels)
146.224 + Arrays.fill(readbuffer, ret, readlen, 0);
146.225 + } catch (IOException e) {
146.226 + }
146.227 +
146.228 + int in_c = in_nrofchannels;
146.229 + for (int i = 0, ix = 0; i < bufferlen; i++, ix += in_c) {
146.230 + left[i] += readbuffer[ix] * _leftgain;
146.231 + }
146.232 + if (out_nrofchannels != 1) {
146.233 + if (in_nrofchannels == 1) {
146.234 + for (int i = 0, ix = 0; i < bufferlen; i++, ix += in_c) {
146.235 + right[i] += readbuffer[ix] * _rightgain;
146.236 + }
146.237 + } else {
146.238 + for (int i = 0, ix = 1; i < bufferlen; i++, ix += in_c) {
146.239 + right[i] += readbuffer[ix] * _rightgain;
146.240 + }
146.241 + }
146.242 +
146.243 + }
146.244 +
146.245 + if (_eff1gain > 0.0001) {
146.246 + float[] eff1 = buffers[SoftMixingMainMixer.CHANNEL_EFFECT1]
146.247 + .array();
146.248 + for (int i = 0, ix = 0; i < bufferlen; i++, ix += in_c) {
146.249 + eff1[i] += readbuffer[ix] * _eff1gain;
146.250 + }
146.251 + if (in_nrofchannels == 2) {
146.252 + for (int i = 0, ix = 1; i < bufferlen; i++, ix += in_c) {
146.253 + eff1[i] += readbuffer[ix] * _eff1gain;
146.254 + }
146.255 + }
146.256 + }
146.257 +
146.258 + if (_eff2gain > 0.0001) {
146.259 + float[] eff2 = buffers[SoftMixingMainMixer.CHANNEL_EFFECT2]
146.260 + .array();
146.261 + for (int i = 0, ix = 0; i < bufferlen; i++, ix += in_c) {
146.262 + eff2[i] += readbuffer[ix] * _eff2gain;
146.263 + }
146.264 + if (in_nrofchannels == 2) {
146.265 + for (int i = 0, ix = 1; i < bufferlen; i++, ix += in_c) {
146.266 + eff2[i] += readbuffer[ix] * _eff2gain;
146.267 + }
146.268 + }
146.269 + }
146.270 +
146.271 + }
146.272 + }
146.273 +
146.274 + public void open() throws LineUnavailableException {
146.275 + open(format);
146.276 + }
146.277 +
146.278 + public void open(AudioFormat format) throws LineUnavailableException {
146.279 + if (bufferSize == -1)
146.280 + bufferSize = ((int) (format.getFrameRate() / 2))
146.281 + * format.getFrameSize();
146.282 + open(format, bufferSize);
146.283 + }
146.284 +
146.285 + public void open(AudioFormat format, int bufferSize)
146.286 + throws LineUnavailableException {
146.287 +
146.288 + LineEvent event = null;
146.289 +
146.290 + if (bufferSize < format.getFrameSize() * 32)
146.291 + bufferSize = format.getFrameSize() * 32;
146.292 +
146.293 + synchronized (control_mutex) {
146.294 +
146.295 + if (!isOpen()) {
146.296 + if (!mixer.isOpen()) {
146.297 + mixer.open();
146.298 + mixer.implicitOpen = true;
146.299 + }
146.300 +
146.301 + event = new LineEvent(this, LineEvent.Type.OPEN, 0);
146.302 +
146.303 + this.bufferSize = bufferSize - bufferSize
146.304 + % format.getFrameSize();
146.305 + this.format = format;
146.306 + this.framesize = format.getFrameSize();
146.307 + this.outputformat = mixer.getFormat();
146.308 + out_nrofchannels = outputformat.getChannels();
146.309 + in_nrofchannels = format.getChannels();
146.310 +
146.311 + open = true;
146.312 +
146.313 + mixer.getMainMixer().openLine(this);
146.314 +
146.315 + cycling_buffer = new byte[framesize * bufferSize];
146.316 + cycling_read_pos = 0;
146.317 + cycling_write_pos = 0;
146.318 + cycling_avail = 0;
146.319 + cycling_framepos = 0;
146.320 +
146.321 + InputStream cycling_inputstream = new InputStream() {
146.322 +
146.323 + public int read() throws IOException {
146.324 + byte[] b = new byte[1];
146.325 + int ret = read(b);
146.326 + if (ret < 0)
146.327 + return ret;
146.328 + return b[0] & 0xFF;
146.329 + }
146.330 +
146.331 + public int available() throws IOException {
146.332 + synchronized (cycling_buffer) {
146.333 + return cycling_avail;
146.334 + }
146.335 + }
146.336 +
146.337 + public int read(byte[] b, int off, int len)
146.338 + throws IOException {
146.339 +
146.340 + synchronized (cycling_buffer) {
146.341 + if (len > cycling_avail)
146.342 + len = cycling_avail;
146.343 + int pos = cycling_read_pos;
146.344 + byte[] buff = cycling_buffer;
146.345 + int buff_len = buff.length;
146.346 + for (int i = 0; i < len; i++) {
146.347 + b[off++] = buff[pos];
146.348 + pos++;
146.349 + if (pos == buff_len)
146.350 + pos = 0;
146.351 + }
146.352 + cycling_read_pos = pos;
146.353 + cycling_avail -= len;
146.354 + cycling_framepos += len / framesize;
146.355 + }
146.356 + return len;
146.357 + }
146.358 +
146.359 + };
146.360 +
146.361 + afis = AudioFloatInputStream
146.362 + .getInputStream(new AudioInputStream(
146.363 + cycling_inputstream, format,
146.364 + AudioSystem.NOT_SPECIFIED));
146.365 + afis = new NonBlockingFloatInputStream(afis);
146.366 +
146.367 + if (Math.abs(format.getSampleRate()
146.368 + - outputformat.getSampleRate()) > 0.000001)
146.369 + afis = new AudioFloatInputStreamResampler(afis,
146.370 + outputformat);
146.371 +
146.372 + } else {
146.373 + if (!format.matches(getFormat())) {
146.374 + throw new IllegalStateException(
146.375 + "Line is already open with format " + getFormat()
146.376 + + " and bufferSize " + getBufferSize());
146.377 + }
146.378 + }
146.379 +
146.380 + }
146.381 +
146.382 + if (event != null)
146.383 + sendEvent(event);
146.384 +
146.385 + }
146.386 +
146.387 + public int available() {
146.388 + synchronized (cycling_buffer) {
146.389 + return cycling_buffer.length - cycling_avail;
146.390 + }
146.391 + }
146.392 +
146.393 + public void drain() {
146.394 + while (true) {
146.395 + int avail;
146.396 + synchronized (cycling_buffer) {
146.397 + avail = cycling_avail;
146.398 + }
146.399 + if (avail != 0)
146.400 + return;
146.401 + try {
146.402 + Thread.sleep(1);
146.403 + } catch (InterruptedException e) {
146.404 + return;
146.405 + }
146.406 + }
146.407 + }
146.408 +
146.409 + public void flush() {
146.410 + synchronized (cycling_buffer) {
146.411 + cycling_read_pos = 0;
146.412 + cycling_write_pos = 0;
146.413 + cycling_avail = 0;
146.414 + }
146.415 + }
146.416 +
146.417 + public int getBufferSize() {
146.418 + synchronized (control_mutex) {
146.419 + return bufferSize;
146.420 + }
146.421 + }
146.422 +
146.423 + public AudioFormat getFormat() {
146.424 + synchronized (control_mutex) {
146.425 + return format;
146.426 + }
146.427 + }
146.428 +
146.429 + public int getFramePosition() {
146.430 + return (int) getLongFramePosition();
146.431 + }
146.432 +
146.433 + public float getLevel() {
146.434 + return AudioSystem.NOT_SPECIFIED;
146.435 + }
146.436 +
146.437 + public long getLongFramePosition() {
146.438 + synchronized (cycling_buffer) {
146.439 + return cycling_framepos;
146.440 + }
146.441 + }
146.442 +
146.443 + public long getMicrosecondPosition() {
146.444 + return (long) (getLongFramePosition() * (1000000.0 / (double) getFormat()
146.445 + .getSampleRate()));
146.446 + }
146.447 +
146.448 + public boolean isActive() {
146.449 + synchronized (control_mutex) {
146.450 + return active;
146.451 + }
146.452 + }
146.453 +
146.454 + public boolean isRunning() {
146.455 + synchronized (control_mutex) {
146.456 + return active;
146.457 + }
146.458 + }
146.459 +
146.460 + public void start() {
146.461 +
146.462 + LineEvent event = null;
146.463 +
146.464 + synchronized (control_mutex) {
146.465 + if (isOpen()) {
146.466 + if (active)
146.467 + return;
146.468 + active = true;
146.469 + event = new LineEvent(this, LineEvent.Type.START,
146.470 + getLongFramePosition());
146.471 + }
146.472 + }
146.473 +
146.474 + if (event != null)
146.475 + sendEvent(event);
146.476 + }
146.477 +
146.478 + public void stop() {
146.479 + LineEvent event = null;
146.480 +
146.481 + synchronized (control_mutex) {
146.482 + if (isOpen()) {
146.483 + if (!active)
146.484 + return;
146.485 + active = false;
146.486 + event = new LineEvent(this, LineEvent.Type.STOP,
146.487 + getLongFramePosition());
146.488 + }
146.489 + }
146.490 +
146.491 + if (event != null)
146.492 + sendEvent(event);
146.493 + }
146.494 +
146.495 + public void close() {
146.496 +
146.497 + LineEvent event = null;
146.498 +
146.499 + synchronized (control_mutex) {
146.500 + if (!isOpen())
146.501 + return;
146.502 + stop();
146.503 +
146.504 + event = new LineEvent(this, LineEvent.Type.CLOSE,
146.505 + getLongFramePosition());
146.506 +
146.507 + open = false;
146.508 + mixer.getMainMixer().closeLine(this);
146.509 + }
146.510 +
146.511 + if (event != null)
146.512 + sendEvent(event);
146.513 +
146.514 + }
146.515 +
146.516 + public boolean isOpen() {
146.517 + synchronized (control_mutex) {
146.518 + return open;
146.519 + }
146.520 + }
146.521 +
146.522 +}
147.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
147.2 +++ b/src/share/classes/com/sun/media/sound/SoftPerformer.java Tue Feb 03 22:02:55 2009 -0800
147.3 @@ -0,0 +1,775 @@
147.4 +/*
147.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
147.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
147.7 + *
147.8 + * This code is free software; you can redistribute it and/or modify it
147.9 + * under the terms of the GNU General Public License version 2 only, as
147.10 + * published by the Free Software Foundation. Sun designates this
147.11 + * particular file as subject to the "Classpath" exception as provided
147.12 + * by Sun in the LICENSE file that accompanied this code.
147.13 + *
147.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
147.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
147.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
147.17 + * version 2 for more details (a copy is included in the LICENSE file that
147.18 + * accompanied this code).
147.19 + *
147.20 + * You should have received a copy of the GNU General Public License version
147.21 + * 2 along with this work; if not, write to the Free Software Foundation,
147.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
147.23 + *
147.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
147.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
147.26 + * have any questions.
147.27 + */
147.28 +package com.sun.media.sound;
147.29 +
147.30 +import java.util.ArrayList;
147.31 +import java.util.Arrays;
147.32 +import java.util.Comparator;
147.33 +import java.util.HashMap;
147.34 +import java.util.List;
147.35 +import java.util.Map;
147.36 +
147.37 +/**
147.38 + * This class decodes information from ModelPeformer for use in SoftVoice.
147.39 + * It also adds default connections if they where missing in ModelPerformer.
147.40 + *
147.41 + * @author Karl Helgason
147.42 + */
147.43 +public class SoftPerformer {
147.44 +
147.45 + static ModelConnectionBlock[] defaultconnections
147.46 + = new ModelConnectionBlock[42];
147.47 +
147.48 + static {
147.49 + int o = 0;
147.50 + defaultconnections[o++] = new ModelConnectionBlock(
147.51 + new ModelSource(
147.52 + new ModelIdentifier("noteon", "on", 0),
147.53 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.54 + ModelStandardTransform.POLARITY_UNIPOLAR,
147.55 + ModelStandardTransform.TRANSFORM_LINEAR),
147.56 + 1, new ModelDestination(new ModelIdentifier("eg", "on", 0)));
147.57 +
147.58 + defaultconnections[o++] = new ModelConnectionBlock(
147.59 + new ModelSource(
147.60 + new ModelIdentifier("noteon", "on", 0),
147.61 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.62 + ModelStandardTransform.POLARITY_UNIPOLAR,
147.63 + ModelStandardTransform.TRANSFORM_LINEAR),
147.64 + 1, new ModelDestination(new ModelIdentifier("eg", "on", 1)));
147.65 +
147.66 + defaultconnections[o++] = new ModelConnectionBlock(
147.67 + new ModelSource(
147.68 + new ModelIdentifier("eg", "active", 0),
147.69 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.70 + ModelStandardTransform.POLARITY_UNIPOLAR,
147.71 + ModelStandardTransform.TRANSFORM_LINEAR),
147.72 + 1, new ModelDestination(new ModelIdentifier("mixer", "active", 0)));
147.73 +
147.74 + defaultconnections[o++] = new ModelConnectionBlock(
147.75 + new ModelSource(
147.76 + new ModelIdentifier("eg", 0),
147.77 + ModelStandardTransform.DIRECTION_MAX2MIN,
147.78 + ModelStandardTransform.POLARITY_UNIPOLAR,
147.79 + ModelStandardTransform.TRANSFORM_LINEAR),
147.80 + -960, new ModelDestination(new ModelIdentifier("mixer", "gain")));
147.81 +
147.82 + defaultconnections[o++] = new ModelConnectionBlock(
147.83 + new ModelSource(
147.84 + new ModelIdentifier("noteon", "velocity"),
147.85 + ModelStandardTransform.DIRECTION_MAX2MIN,
147.86 + ModelStandardTransform.POLARITY_UNIPOLAR,
147.87 + ModelStandardTransform.TRANSFORM_CONCAVE),
147.88 + -960, new ModelDestination(new ModelIdentifier("mixer", "gain")));
147.89 +
147.90 + defaultconnections[o++] = new ModelConnectionBlock(
147.91 + new ModelSource(
147.92 + new ModelIdentifier("midi", "pitch"),
147.93 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.94 + ModelStandardTransform.POLARITY_BIPOLAR,
147.95 + ModelStandardTransform.TRANSFORM_LINEAR),
147.96 + new ModelSource(new ModelIdentifier("midi_rpn", "0"),
147.97 + new ModelTransform() {
147.98 + public double transform(double value) {
147.99 + int v = (int) (value * 16384.0);
147.100 + int msb = v >> 7;
147.101 + int lsb = v & 127;
147.102 + return msb * 100 + lsb;
147.103 + }
147.104 + }),
147.105 + new ModelDestination(new ModelIdentifier("osc", "pitch")));
147.106 +
147.107 + defaultconnections[o++] = new ModelConnectionBlock(
147.108 + new ModelSource(
147.109 + new ModelIdentifier("noteon", "keynumber"),
147.110 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.111 + ModelStandardTransform.POLARITY_UNIPOLAR,
147.112 + ModelStandardTransform.TRANSFORM_LINEAR),
147.113 + 12800, new ModelDestination(new ModelIdentifier("osc", "pitch")));
147.114 +
147.115 + defaultconnections[o++] = new ModelConnectionBlock(
147.116 + new ModelSource(
147.117 + new ModelIdentifier("midi_cc", "7"),
147.118 + ModelStandardTransform.DIRECTION_MAX2MIN,
147.119 + ModelStandardTransform.POLARITY_UNIPOLAR,
147.120 + ModelStandardTransform.TRANSFORM_CONCAVE),
147.121 + -960, new ModelDestination(new ModelIdentifier("mixer", "gain")));
147.122 +
147.123 + defaultconnections[o++] = new ModelConnectionBlock(
147.124 + new ModelSource(
147.125 + new ModelIdentifier("midi_cc", "8"),
147.126 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.127 + ModelStandardTransform.POLARITY_UNIPOLAR,
147.128 + ModelStandardTransform.TRANSFORM_LINEAR),
147.129 + 1000, new ModelDestination(new ModelIdentifier("mixer", "balance")));
147.130 +
147.131 + defaultconnections[o++] = new ModelConnectionBlock(
147.132 + new ModelSource(
147.133 + new ModelIdentifier("midi_cc", "10"),
147.134 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.135 + ModelStandardTransform.POLARITY_UNIPOLAR,
147.136 + ModelStandardTransform.TRANSFORM_LINEAR),
147.137 + 1000, new ModelDestination(new ModelIdentifier("mixer", "pan")));
147.138 +
147.139 + defaultconnections[o++] = new ModelConnectionBlock(
147.140 + new ModelSource(
147.141 + new ModelIdentifier("midi_cc", "11"),
147.142 + ModelStandardTransform.DIRECTION_MAX2MIN,
147.143 + ModelStandardTransform.POLARITY_UNIPOLAR,
147.144 + ModelStandardTransform.TRANSFORM_CONCAVE),
147.145 + -960, new ModelDestination(new ModelIdentifier("mixer", "gain")));
147.146 +
147.147 + defaultconnections[o++] = new ModelConnectionBlock(
147.148 + new ModelSource(
147.149 + new ModelIdentifier("midi_cc", "91"),
147.150 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.151 + ModelStandardTransform.POLARITY_UNIPOLAR,
147.152 + ModelStandardTransform.TRANSFORM_LINEAR),
147.153 + 1000, new ModelDestination(new ModelIdentifier("mixer", "reverb")));
147.154 +
147.155 + defaultconnections[o++] = new ModelConnectionBlock(
147.156 + new ModelSource(
147.157 + new ModelIdentifier("midi_cc", "93"),
147.158 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.159 + ModelStandardTransform.POLARITY_UNIPOLAR,
147.160 + ModelStandardTransform.TRANSFORM_LINEAR),
147.161 + 1000, new ModelDestination(new ModelIdentifier("mixer", "chorus")));
147.162 +
147.163 + defaultconnections[o++] = new ModelConnectionBlock(
147.164 + new ModelSource(
147.165 + new ModelIdentifier("midi_cc", "71"),
147.166 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.167 + ModelStandardTransform.POLARITY_BIPOLAR,
147.168 + ModelStandardTransform.TRANSFORM_LINEAR),
147.169 + 200, new ModelDestination(new ModelIdentifier("filter", "q")));
147.170 + defaultconnections[o++] = new ModelConnectionBlock(
147.171 + new ModelSource(
147.172 + new ModelIdentifier("midi_cc", "74"),
147.173 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.174 + ModelStandardTransform.POLARITY_BIPOLAR,
147.175 + ModelStandardTransform.TRANSFORM_LINEAR),
147.176 + 9600, new ModelDestination(new ModelIdentifier("filter", "freq")));
147.177 +
147.178 + defaultconnections[o++] = new ModelConnectionBlock(
147.179 + new ModelSource(
147.180 + new ModelIdentifier("midi_cc", "72"),
147.181 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.182 + ModelStandardTransform.POLARITY_BIPOLAR,
147.183 + ModelStandardTransform.TRANSFORM_LINEAR),
147.184 + 6000, new ModelDestination(new ModelIdentifier("eg", "release2")));
147.185 +
147.186 + defaultconnections[o++] = new ModelConnectionBlock(
147.187 + new ModelSource(
147.188 + new ModelIdentifier("midi_cc", "73"),
147.189 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.190 + ModelStandardTransform.POLARITY_BIPOLAR,
147.191 + ModelStandardTransform.TRANSFORM_LINEAR),
147.192 + 2000, new ModelDestination(new ModelIdentifier("eg", "attack2")));
147.193 +
147.194 + defaultconnections[o++] = new ModelConnectionBlock(
147.195 + new ModelSource(
147.196 + new ModelIdentifier("midi_cc", "75"),
147.197 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.198 + ModelStandardTransform.POLARITY_BIPOLAR,
147.199 + ModelStandardTransform.TRANSFORM_LINEAR),
147.200 + 6000, new ModelDestination(new ModelIdentifier("eg", "decay2")));
147.201 +
147.202 + defaultconnections[o++] = new ModelConnectionBlock(
147.203 + new ModelSource(
147.204 + new ModelIdentifier("midi_cc", "67"),
147.205 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.206 + ModelStandardTransform.POLARITY_UNIPOLAR,
147.207 + ModelStandardTransform.TRANSFORM_SWITCH),
147.208 + -50, new ModelDestination(ModelDestination.DESTINATION_GAIN));
147.209 +
147.210 + defaultconnections[o++] = new ModelConnectionBlock(
147.211 + new ModelSource(
147.212 + new ModelIdentifier("midi_cc", "67"),
147.213 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.214 + ModelStandardTransform.POLARITY_UNIPOLAR,
147.215 + ModelStandardTransform.TRANSFORM_SWITCH),
147.216 + -2400, new ModelDestination(ModelDestination.DESTINATION_FILTER_FREQ));
147.217 +
147.218 + defaultconnections[o++] = new ModelConnectionBlock(
147.219 + new ModelSource(
147.220 + new ModelIdentifier("midi_rpn", "1"),
147.221 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.222 + ModelStandardTransform.POLARITY_BIPOLAR,
147.223 + ModelStandardTransform.TRANSFORM_LINEAR),
147.224 + 100, new ModelDestination(new ModelIdentifier("osc", "pitch")));
147.225 +
147.226 + defaultconnections[o++] = new ModelConnectionBlock(
147.227 + new ModelSource(
147.228 + new ModelIdentifier("midi_rpn", "2"),
147.229 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.230 + ModelStandardTransform.POLARITY_BIPOLAR,
147.231 + ModelStandardTransform.TRANSFORM_LINEAR),
147.232 + 12800, new ModelDestination(new ModelIdentifier("osc", "pitch")));
147.233 +
147.234 + defaultconnections[o++] = new ModelConnectionBlock(
147.235 + new ModelSource(
147.236 + new ModelIdentifier("master", "fine_tuning"),
147.237 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.238 + ModelStandardTransform.POLARITY_BIPOLAR,
147.239 + ModelStandardTransform.TRANSFORM_LINEAR),
147.240 + 100, new ModelDestination(new ModelIdentifier("osc", "pitch")));
147.241 +
147.242 + defaultconnections[o++] = new ModelConnectionBlock(
147.243 + new ModelSource(
147.244 + new ModelIdentifier("master", "coarse_tuning"),
147.245 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.246 + ModelStandardTransform.POLARITY_BIPOLAR,
147.247 + ModelStandardTransform.TRANSFORM_LINEAR),
147.248 + 12800, new ModelDestination(new ModelIdentifier("osc", "pitch")));
147.249 +
147.250 + defaultconnections[o++] = new ModelConnectionBlock(13500,
147.251 + new ModelDestination(new ModelIdentifier("filter", "freq", 0)));
147.252 +
147.253 + defaultconnections[o++] = new ModelConnectionBlock(
147.254 + Float.NEGATIVE_INFINITY, new ModelDestination(
147.255 + new ModelIdentifier("eg", "delay", 0)));
147.256 + defaultconnections[o++] = new ModelConnectionBlock(
147.257 + Float.NEGATIVE_INFINITY, new ModelDestination(
147.258 + new ModelIdentifier("eg", "attack", 0)));
147.259 + defaultconnections[o++] = new ModelConnectionBlock(
147.260 + Float.NEGATIVE_INFINITY, new ModelDestination(
147.261 + new ModelIdentifier("eg", "hold", 0)));
147.262 + defaultconnections[o++] = new ModelConnectionBlock(
147.263 + Float.NEGATIVE_INFINITY, new ModelDestination(
147.264 + new ModelIdentifier("eg", "decay", 0)));
147.265 + defaultconnections[o++] = new ModelConnectionBlock(1000,
147.266 + new ModelDestination(new ModelIdentifier("eg", "sustain", 0)));
147.267 + defaultconnections[o++] = new ModelConnectionBlock(
147.268 + Float.NEGATIVE_INFINITY, new ModelDestination(
147.269 + new ModelIdentifier("eg", "release", 0)));
147.270 + defaultconnections[o++] = new ModelConnectionBlock(1200.0
147.271 + * Math.log(0.015) / Math.log(2), new ModelDestination(
147.272 + new ModelIdentifier("eg", "shutdown", 0))); // 15 msec default
147.273 +
147.274 + defaultconnections[o++] = new ModelConnectionBlock(
147.275 + Float.NEGATIVE_INFINITY, new ModelDestination(
147.276 + new ModelIdentifier("eg", "delay", 1)));
147.277 + defaultconnections[o++] = new ModelConnectionBlock(
147.278 + Float.NEGATIVE_INFINITY, new ModelDestination(
147.279 + new ModelIdentifier("eg", "attack", 1)));
147.280 + defaultconnections[o++] = new ModelConnectionBlock(
147.281 + Float.NEGATIVE_INFINITY, new ModelDestination(
147.282 + new ModelIdentifier("eg", "hold", 1)));
147.283 + defaultconnections[o++] = new ModelConnectionBlock(
147.284 + Float.NEGATIVE_INFINITY, new ModelDestination(
147.285 + new ModelIdentifier("eg", "decay", 1)));
147.286 + defaultconnections[o++] = new ModelConnectionBlock(1000,
147.287 + new ModelDestination(new ModelIdentifier("eg", "sustain", 1)));
147.288 + defaultconnections[o++] = new ModelConnectionBlock(
147.289 + Float.NEGATIVE_INFINITY, new ModelDestination(
147.290 + new ModelIdentifier("eg", "release", 1)));
147.291 +
147.292 + defaultconnections[o++] = new ModelConnectionBlock(-8.51318,
147.293 + new ModelDestination(new ModelIdentifier("lfo", "freq", 0)));
147.294 + defaultconnections[o++] = new ModelConnectionBlock(
147.295 + Float.NEGATIVE_INFINITY, new ModelDestination(
147.296 + new ModelIdentifier("lfo", "delay", 0)));
147.297 + defaultconnections[o++] = new ModelConnectionBlock(-8.51318,
147.298 + new ModelDestination(new ModelIdentifier("lfo", "freq", 1)));
147.299 + defaultconnections[o++] = new ModelConnectionBlock(
147.300 + Float.NEGATIVE_INFINITY, new ModelDestination(
147.301 + new ModelIdentifier("lfo", "delay", 1)));
147.302 +
147.303 + }
147.304 + public int keyFrom = 0;
147.305 + public int keyTo = 127;
147.306 + public int velFrom = 0;
147.307 + public int velTo = 127;
147.308 + public int exclusiveClass = 0;
147.309 + public boolean selfNonExclusive = false;
147.310 + public boolean forcedVelocity = false;
147.311 + public boolean forcedKeynumber = false;
147.312 + public ModelPerformer performer;
147.313 + public ModelConnectionBlock[] connections;
147.314 + public ModelOscillator[] oscillators;
147.315 + public Map<Integer, int[]> midi_rpn_connections = new HashMap<Integer, int[]>();
147.316 + public Map<Integer, int[]> midi_nrpn_connections = new HashMap<Integer, int[]>();
147.317 + public int[][] midi_ctrl_connections;
147.318 + public int[][] midi_connections;
147.319 + public int[] ctrl_connections;
147.320 + private List<Integer> ctrl_connections_list = new ArrayList<Integer>();
147.321 +
147.322 + private static class KeySortComparator implements Comparator<ModelSource> {
147.323 +
147.324 + public int compare(ModelSource o1, ModelSource o2) {
147.325 + return o1.getIdentifier().toString().compareTo(
147.326 + o2.getIdentifier().toString());
147.327 + }
147.328 + }
147.329 + private static KeySortComparator keySortComparator = new KeySortComparator();
147.330 +
147.331 + private String extractKeys(ModelConnectionBlock conn) {
147.332 + StringBuffer sb = new StringBuffer();
147.333 + if (conn.getSources() != null) {
147.334 + sb.append("[");
147.335 + ModelSource[] srcs = conn.getSources();
147.336 + ModelSource[] srcs2 = new ModelSource[srcs.length];
147.337 + for (int i = 0; i < srcs.length; i++)
147.338 + srcs2[i] = srcs[i];
147.339 + Arrays.sort(srcs2, keySortComparator);
147.340 + for (int i = 0; i < srcs.length; i++) {
147.341 + sb.append(srcs[i].getIdentifier());
147.342 + sb.append(";");
147.343 + }
147.344 + sb.append("]");
147.345 + }
147.346 + sb.append(";");
147.347 + if (conn.getDestination() != null) {
147.348 + sb.append(conn.getDestination().getIdentifier());
147.349 + }
147.350 + sb.append(";");
147.351 + return sb.toString();
147.352 + }
147.353 +
147.354 + private void processSource(ModelSource src, int ix) {
147.355 + ModelIdentifier id = src.getIdentifier();
147.356 + String o = id.getObject();
147.357 + if (o.equals("midi_cc"))
147.358 + processMidiControlSource(src, ix);
147.359 + else if (o.equals("midi_rpn"))
147.360 + processMidiRpnSource(src, ix);
147.361 + else if (o.equals("midi_nrpn"))
147.362 + processMidiNrpnSource(src, ix);
147.363 + else if (o.equals("midi"))
147.364 + processMidiSource(src, ix);
147.365 + else if (o.equals("noteon"))
147.366 + processNoteOnSource(src, ix);
147.367 + else if (o.equals("osc"))
147.368 + return;
147.369 + else if (o.equals("mixer"))
147.370 + return;
147.371 + else
147.372 + ctrl_connections_list.add(ix);
147.373 + }
147.374 +
147.375 + private void processMidiControlSource(ModelSource src, int ix) {
147.376 + String v = src.getIdentifier().getVariable();
147.377 + if (v == null)
147.378 + return;
147.379 + int c = Integer.parseInt(v);
147.380 + if (midi_ctrl_connections[c] == null)
147.381 + midi_ctrl_connections[c] = new int[]{ix};
147.382 + else {
147.383 + int[] olda = midi_ctrl_connections[c];
147.384 + int[] newa = new int[olda.length + 1];
147.385 + for (int i = 0; i < olda.length; i++)
147.386 + newa[i] = olda[i];
147.387 + newa[newa.length - 1] = ix;
147.388 + midi_ctrl_connections[c] = newa;
147.389 + }
147.390 + }
147.391 +
147.392 + private void processNoteOnSource(ModelSource src, int ix) {
147.393 + String v = src.getIdentifier().getVariable();
147.394 + int c = -1;
147.395 + if (v.equals("on"))
147.396 + c = 3;
147.397 + if (v.equals("keynumber"))
147.398 + c = 4;
147.399 + if (c == -1)
147.400 + return;
147.401 + if (midi_connections[c] == null)
147.402 + midi_connections[c] = new int[]{ix};
147.403 + else {
147.404 + int[] olda = midi_connections[c];
147.405 + int[] newa = new int[olda.length + 1];
147.406 + for (int i = 0; i < olda.length; i++)
147.407 + newa[i] = olda[i];
147.408 + newa[newa.length - 1] = ix;
147.409 + midi_connections[c] = newa;
147.410 + }
147.411 + }
147.412 +
147.413 + private void processMidiSource(ModelSource src, int ix) {
147.414 + String v = src.getIdentifier().getVariable();
147.415 + int c = -1;
147.416 + if (v.equals("pitch"))
147.417 + c = 0;
147.418 + if (v.equals("channel_pressure"))
147.419 + c = 1;
147.420 + if (v.equals("poly_pressure"))
147.421 + c = 2;
147.422 + if (c == -1)
147.423 + return;
147.424 + if (midi_connections[c] == null)
147.425 + midi_connections[c] = new int[]{ix};
147.426 + else {
147.427 + int[] olda = midi_connections[c];
147.428 + int[] newa = new int[olda.length + 1];
147.429 + for (int i = 0; i < olda.length; i++)
147.430 + newa[i] = olda[i];
147.431 + newa[newa.length - 1] = ix;
147.432 + midi_connections[c] = newa;
147.433 + }
147.434 + }
147.435 +
147.436 + private void processMidiRpnSource(ModelSource src, int ix) {
147.437 + String v = src.getIdentifier().getVariable();
147.438 + if (v == null)
147.439 + return;
147.440 + int c = Integer.parseInt(v);
147.441 + if (midi_rpn_connections.get(c) == null)
147.442 + midi_rpn_connections.put(c, new int[]{ix});
147.443 + else {
147.444 + int[] olda = midi_rpn_connections.get(c);
147.445 + int[] newa = new int[olda.length + 1];
147.446 + for (int i = 0; i < olda.length; i++)
147.447 + newa[i] = olda[i];
147.448 + newa[newa.length - 1] = ix;
147.449 + midi_rpn_connections.put(c, newa);
147.450 + }
147.451 + }
147.452 +
147.453 + private void processMidiNrpnSource(ModelSource src, int ix) {
147.454 + String v = src.getIdentifier().getVariable();
147.455 + if (v == null)
147.456 + return;
147.457 + int c = Integer.parseInt(v);
147.458 + if (midi_nrpn_connections.get(c) == null)
147.459 + midi_nrpn_connections.put(c, new int[]{ix});
147.460 + else {
147.461 + int[] olda = midi_nrpn_connections.get(c);
147.462 + int[] newa = new int[olda.length + 1];
147.463 + for (int i = 0; i < olda.length; i++)
147.464 + newa[i] = olda[i];
147.465 + newa[newa.length - 1] = ix;
147.466 + midi_nrpn_connections.put(c, newa);
147.467 + }
147.468 + }
147.469 +
147.470 + public SoftPerformer(ModelPerformer performer) {
147.471 + this.performer = performer;
147.472 +
147.473 + keyFrom = performer.getKeyFrom();
147.474 + keyTo = performer.getKeyTo();
147.475 + velFrom = performer.getVelFrom();
147.476 + velTo = performer.getVelTo();
147.477 + exclusiveClass = performer.getExclusiveClass();
147.478 + selfNonExclusive = performer.isSelfNonExclusive();
147.479 +
147.480 + Map<String, ModelConnectionBlock> connmap = new HashMap<String, ModelConnectionBlock>();
147.481 +
147.482 + List<ModelConnectionBlock> performer_connections = new ArrayList<ModelConnectionBlock>();
147.483 + performer_connections.addAll(performer.getConnectionBlocks());
147.484 +
147.485 + if (performer.isDefaultConnectionsEnabled()) {
147.486 +
147.487 + // Add modulation depth range (RPN 5) to the modulation wheel (cc#1)
147.488 +
147.489 + boolean isModulationWheelConectionFound = false;
147.490 + for (int j = 0; j < performer_connections.size(); j++) {
147.491 + ModelConnectionBlock connection = performer_connections.get(j);
147.492 + ModelSource[] sources = connection.getSources();
147.493 + ModelDestination dest = connection.getDestination();
147.494 + boolean isModulationWheelConection = false;
147.495 + if (dest != null && sources != null && sources.length > 1) {
147.496 + for (int i = 0; i < sources.length; i++) {
147.497 + // check if connection block has the source "modulation
147.498 + // wheel cc#1"
147.499 + if (sources[i].getIdentifier().getObject().equals(
147.500 + "midi_cc")) {
147.501 + if (sources[i].getIdentifier().getVariable()
147.502 + .equals("1")) {
147.503 + isModulationWheelConection = true;
147.504 + isModulationWheelConectionFound = true;
147.505 + break;
147.506 + }
147.507 + }
147.508 + }
147.509 + }
147.510 + if (isModulationWheelConection) {
147.511 +
147.512 + ModelConnectionBlock newconnection = new ModelConnectionBlock();
147.513 + newconnection.setSources(connection.getSources());
147.514 + newconnection.setDestination(connection.getDestination());
147.515 + newconnection.addSource(new ModelSource(
147.516 + new ModelIdentifier("midi_rpn", "5")));
147.517 + newconnection.setScale(connection.getScale() * 256.0);
147.518 + performer_connections.set(j, newconnection);
147.519 + }
147.520 + }
147.521 +
147.522 + if (!isModulationWheelConectionFound) {
147.523 + ModelConnectionBlock conn = new ModelConnectionBlock(
147.524 + new ModelSource(ModelSource.SOURCE_LFO1,
147.525 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.526 + ModelStandardTransform.POLARITY_BIPOLAR,
147.527 + ModelStandardTransform.TRANSFORM_LINEAR),
147.528 + new ModelSource(new ModelIdentifier("midi_cc", "1", 0),
147.529 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.530 + ModelStandardTransform.POLARITY_UNIPOLAR,
147.531 + ModelStandardTransform.TRANSFORM_LINEAR),
147.532 + 50,
147.533 + new ModelDestination(ModelDestination.DESTINATION_PITCH));
147.534 + conn.addSource(new ModelSource(new ModelIdentifier("midi_rpn",
147.535 + "5")));
147.536 + conn.setScale(conn.getScale() * 256.0);
147.537 + performer_connections.add(conn);
147.538 +
147.539 + }
147.540 +
147.541 + // Let Aftertouch to behave just like modulation wheel (cc#1)
147.542 + boolean channel_pressure_set = false;
147.543 + boolean poly_pressure = false;
147.544 + ModelConnectionBlock mod_cc_1_connection = null;
147.545 + int mod_cc_1_connection_src_ix = 0;
147.546 +
147.547 + for (ModelConnectionBlock connection : performer_connections) {
147.548 + ModelSource[] sources = connection.getSources();
147.549 + ModelDestination dest = connection.getDestination();
147.550 + // if(dest != null && sources != null)
147.551 + if (dest != null && sources != null) {
147.552 + for (int i = 0; i < sources.length; i++) {
147.553 + ModelIdentifier srcid = sources[i].getIdentifier();
147.554 + // check if connection block has the source "modulation
147.555 + // wheel cc#1"
147.556 + if (srcid.getObject().equals("midi_cc")) {
147.557 + if (srcid.getVariable().equals("1")) {
147.558 + mod_cc_1_connection = connection;
147.559 + mod_cc_1_connection_src_ix = i;
147.560 + }
147.561 + }
147.562 + // check if channel or poly pressure are already
147.563 + // connected
147.564 + if (srcid.getObject().equals("midi")) {
147.565 + if (srcid.getVariable().equals("channel_pressure"))
147.566 + channel_pressure_set = true;
147.567 + if (srcid.getVariable().equals("poly_pressure"))
147.568 + poly_pressure = true;
147.569 + }
147.570 + }
147.571 + }
147.572 +
147.573 + }
147.574 +
147.575 + if (mod_cc_1_connection != null) {
147.576 + if (!channel_pressure_set) {
147.577 + ModelConnectionBlock mc = new ModelConnectionBlock();
147.578 + mc.setDestination(mod_cc_1_connection.getDestination());
147.579 + mc.setScale(mod_cc_1_connection.getScale());
147.580 + ModelSource[] src_list = mod_cc_1_connection.getSources();
147.581 + ModelSource[] src_list_new = new ModelSource[src_list.length];
147.582 + for (int i = 0; i < src_list_new.length; i++)
147.583 + src_list_new[i] = src_list[i];
147.584 + src_list_new[mod_cc_1_connection_src_ix] = new ModelSource(
147.585 + new ModelIdentifier("midi", "channel_pressure"));
147.586 + mc.setSources(src_list_new);
147.587 + connmap.put(extractKeys(mc), mc);
147.588 + }
147.589 + if (!poly_pressure) {
147.590 + ModelConnectionBlock mc = new ModelConnectionBlock();
147.591 + mc.setDestination(mod_cc_1_connection.getDestination());
147.592 + mc.setScale(mod_cc_1_connection.getScale());
147.593 + ModelSource[] src_list = mod_cc_1_connection.getSources();
147.594 + ModelSource[] src_list_new = new ModelSource[src_list.length];
147.595 + for (int i = 0; i < src_list_new.length; i++)
147.596 + src_list_new[i] = src_list[i];
147.597 + src_list_new[mod_cc_1_connection_src_ix] = new ModelSource(
147.598 + new ModelIdentifier("midi", "poly_pressure"));
147.599 + mc.setSources(src_list_new);
147.600 + connmap.put(extractKeys(mc), mc);
147.601 + }
147.602 + }
147.603 +
147.604 + // Enable Vibration Sound Controllers : 76, 77, 78
147.605 + ModelConnectionBlock found_vib_connection = null;
147.606 + for (ModelConnectionBlock connection : performer_connections) {
147.607 + ModelSource[] sources = connection.getSources();
147.608 + if (sources.length != 0
147.609 + && sources[0].getIdentifier().getObject().equals("lfo")) {
147.610 + if (connection.getDestination().getIdentifier().equals(
147.611 + ModelDestination.DESTINATION_PITCH)) {
147.612 + if (found_vib_connection == null)
147.613 + found_vib_connection = connection;
147.614 + else {
147.615 + if (found_vib_connection.getSources().length > sources.length)
147.616 + found_vib_connection = connection;
147.617 + else if (found_vib_connection.getSources()[0]
147.618 + .getIdentifier().getInstance() < 1) {
147.619 + if (found_vib_connection.getSources()[0]
147.620 + .getIdentifier().getInstance() >
147.621 + sources[0].getIdentifier().getInstance()) {
147.622 + found_vib_connection = connection;
147.623 + }
147.624 + }
147.625 + }
147.626 +
147.627 + }
147.628 + }
147.629 + }
147.630 +
147.631 + int instance = 1;
147.632 +
147.633 + if (found_vib_connection != null) {
147.634 + instance = found_vib_connection.getSources()[0].getIdentifier()
147.635 + .getInstance();
147.636 + }
147.637 + ModelConnectionBlock connection;
147.638 +
147.639 + connection = new ModelConnectionBlock(
147.640 + new ModelSource(new ModelIdentifier("midi_cc", "78"),
147.641 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.642 + ModelStandardTransform.POLARITY_BIPOLAR,
147.643 + ModelStandardTransform.TRANSFORM_LINEAR),
147.644 + 2000, new ModelDestination(
147.645 + new ModelIdentifier("lfo", "delay2", instance)));
147.646 + connmap.put(extractKeys(connection), connection);
147.647 +
147.648 + final double scale = found_vib_connection == null ? 0
147.649 + : found_vib_connection.getScale();
147.650 + connection = new ModelConnectionBlock(
147.651 + new ModelSource(new ModelIdentifier("lfo", instance)),
147.652 + new ModelSource(new ModelIdentifier("midi_cc", "77"),
147.653 + new ModelTransform() {
147.654 + double s = scale;
147.655 + public double transform(double value) {
147.656 + value = value * 2 - 1;
147.657 + value *= 600;
147.658 + if (s == 0) {
147.659 + return value;
147.660 + } else if (s > 0) {
147.661 + if (value < -s)
147.662 + value = -s;
147.663 + return value;
147.664 + } else {
147.665 + if (value < s)
147.666 + value = -s;
147.667 + return -value;
147.668 + }
147.669 + }
147.670 + }), new ModelDestination(ModelDestination.DESTINATION_PITCH));
147.671 + connmap.put(extractKeys(connection), connection);
147.672 +
147.673 + connection = new ModelConnectionBlock(
147.674 + new ModelSource(new ModelIdentifier("midi_cc", "76"),
147.675 + ModelStandardTransform.DIRECTION_MIN2MAX,
147.676 + ModelStandardTransform.POLARITY_BIPOLAR,
147.677 + ModelStandardTransform.TRANSFORM_LINEAR),
147.678 + 2400, new ModelDestination(
147.679 + new ModelIdentifier("lfo", "freq", instance)));
147.680 + connmap.put(extractKeys(connection), connection);
147.681 +
147.682 + }
147.683 +
147.684 + // Add default connection blocks
147.685 + if (performer.isDefaultConnectionsEnabled())
147.686 + for (ModelConnectionBlock connection : defaultconnections)
147.687 + connmap.put(extractKeys(connection), connection);
147.688 + // Add connection blocks from modelperformer
147.689 + for (ModelConnectionBlock connection : performer_connections)
147.690 + connmap.put(extractKeys(connection), connection);
147.691 + // seperate connection blocks : Init time, Midi Time, Midi/Control Time,
147.692 + // Control Time
147.693 + List<ModelConnectionBlock> connections = new ArrayList<ModelConnectionBlock>();
147.694 +
147.695 + midi_ctrl_connections = new int[128][];
147.696 + for (int i = 0; i < midi_ctrl_connections.length; i++) {
147.697 + midi_ctrl_connections[i] = null;
147.698 + }
147.699 + midi_connections = new int[5][];
147.700 + for (int i = 0; i < midi_connections.length; i++) {
147.701 + midi_connections[i] = null;
147.702 + }
147.703 +
147.704 + int ix = 0;
147.705 + boolean mustBeOnTop = false;
147.706 +
147.707 + for (ModelConnectionBlock connection : connmap.values()) {
147.708 + if (connection.getDestination() != null) {
147.709 + ModelDestination dest = connection.getDestination();
147.710 + ModelIdentifier id = dest.getIdentifier();
147.711 + if (id.getObject().equals("noteon")) {
147.712 + mustBeOnTop = true;
147.713 + if (id.getVariable().equals("keynumber"))
147.714 + forcedKeynumber = true;
147.715 + if (id.getVariable().equals("velocity"))
147.716 + forcedVelocity = true;
147.717 + }
147.718 + }
147.719 + if (mustBeOnTop) {
147.720 + connections.add(0, connection);
147.721 + mustBeOnTop = false;
147.722 + } else
147.723 + connections.add(connection);
147.724 + }
147.725 +
147.726 + for (ModelConnectionBlock connection : connections) {
147.727 + if (connection.getSources() != null) {
147.728 + ModelSource[] srcs = connection.getSources();
147.729 + for (int i = 0; i < srcs.length; i++) {
147.730 + processSource(srcs[i], ix);
147.731 + }
147.732 + }
147.733 + ix++;
147.734 + }
147.735 +
147.736 + this.connections = new ModelConnectionBlock[connections.size()];
147.737 + connections.toArray(this.connections);
147.738 +
147.739 + this.ctrl_connections = new int[ctrl_connections_list.size()];
147.740 +
147.741 + for (int i = 0; i < this.ctrl_connections.length; i++)
147.742 + this.ctrl_connections[i] = ctrl_connections_list.get(i);
147.743 +
147.744 + oscillators = new ModelOscillator[performer.getOscillators().size()];
147.745 + performer.getOscillators().toArray(oscillators);
147.746 +
147.747 + for (ModelConnectionBlock conn : connections) {
147.748 + if (conn.getDestination() != null) {
147.749 + if (isUnnecessaryTransform(conn.getDestination().getTransform())) {
147.750 + conn.getDestination().setTransform(null);
147.751 + }
147.752 + }
147.753 + if (conn.getSources() != null) {
147.754 + for (ModelSource src : conn.getSources()) {
147.755 + if (isUnnecessaryTransform(src.getTransform())) {
147.756 + src.setTransform(null);
147.757 + }
147.758 + }
147.759 + }
147.760 + }
147.761 +
147.762 + }
147.763 +
147.764 + private static boolean isUnnecessaryTransform(ModelTransform transform) {
147.765 + if (transform == null)
147.766 + return false;
147.767 + if (!(transform instanceof ModelStandardTransform))
147.768 + return false;
147.769 + ModelStandardTransform stransform = (ModelStandardTransform)transform;
147.770 + if (stransform.getDirection() != ModelStandardTransform.DIRECTION_MIN2MAX)
147.771 + return false;
147.772 + if (stransform.getPolarity() != ModelStandardTransform.POLARITY_UNIPOLAR)
147.773 + return false;
147.774 + if (stransform.getTransform() != ModelStandardTransform.TRANSFORM_LINEAR)
147.775 + return false;
147.776 + return false;
147.777 + }
147.778 +}
148.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
148.2 +++ b/src/share/classes/com/sun/media/sound/SoftPointResampler.java Tue Feb 03 22:02:55 2009 -0800
148.3 @@ -0,0 +1,63 @@
148.4 +/*
148.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
148.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
148.7 + *
148.8 + * This code is free software; you can redistribute it and/or modify it
148.9 + * under the terms of the GNU General Public License version 2 only, as
148.10 + * published by the Free Software Foundation. Sun designates this
148.11 + * particular file as subject to the "Classpath" exception as provided
148.12 + * by Sun in the LICENSE file that accompanied this code.
148.13 + *
148.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
148.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
148.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
148.17 + * version 2 for more details (a copy is included in the LICENSE file that
148.18 + * accompanied this code).
148.19 + *
148.20 + * You should have received a copy of the GNU General Public License version
148.21 + * 2 along with this work; if not, write to the Free Software Foundation,
148.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
148.23 + *
148.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
148.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
148.26 + * have any questions.
148.27 + */
148.28 +package com.sun.media.sound;
148.29 +
148.30 +/**
148.31 + * A resampler that uses 0-order (nearest-neighbor) interpolation.
148.32 + *
148.33 + * @author Karl Helgason
148.34 + */
148.35 +public class SoftPointResampler extends SoftAbstractResampler {
148.36 +
148.37 + public int getPadding() {
148.38 + return 100;
148.39 + }
148.40 +
148.41 + public void interpolate(float[] in, float[] in_offset, float in_end,
148.42 + float[] startpitch, float pitchstep, float[] out, int[] out_offset,
148.43 + int out_end) {
148.44 + float pitch = startpitch[0];
148.45 + float ix = in_offset[0];
148.46 + int ox = out_offset[0];
148.47 + float ix_end = in_end;
148.48 + float ox_end = out_end;
148.49 + if (pitchstep == 0) {
148.50 + while (ix < ix_end && ox < ox_end) {
148.51 + out[ox++] = in[(int) ix];
148.52 + ix += pitch;
148.53 + }
148.54 + } else {
148.55 + while (ix < ix_end && ox < ox_end) {
148.56 + out[ox++] = in[(int) ix];
148.57 + ix += pitch;
148.58 + pitch += pitchstep;
148.59 + }
148.60 + }
148.61 + in_offset[0] = ix;
148.62 + out_offset[0] = ox;
148.63 + startpitch[0] = pitch;
148.64 +
148.65 + }
148.66 +}
149.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
149.2 +++ b/src/share/classes/com/sun/media/sound/SoftProcess.java Tue Feb 03 22:02:55 2009 -0800
149.3 @@ -0,0 +1,41 @@
149.4 +/*
149.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
149.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
149.7 + *
149.8 + * This code is free software; you can redistribute it and/or modify it
149.9 + * under the terms of the GNU General Public License version 2 only, as
149.10 + * published by the Free Software Foundation. Sun designates this
149.11 + * particular file as subject to the "Classpath" exception as provided
149.12 + * by Sun in the LICENSE file that accompanied this code.
149.13 + *
149.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
149.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
149.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
149.17 + * version 2 for more details (a copy is included in the LICENSE file that
149.18 + * accompanied this code).
149.19 + *
149.20 + * You should have received a copy of the GNU General Public License version
149.21 + * 2 along with this work; if not, write to the Free Software Foundation,
149.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
149.23 + *
149.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
149.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
149.26 + * have any questions.
149.27 + */
149.28 +package com.sun.media.sound;
149.29 +
149.30 +/**
149.31 + * Control signal processor interface
149.32 + *
149.33 + * @author Karl Helgason
149.34 + */
149.35 +public interface SoftProcess extends SoftControl {
149.36 +
149.37 + public void init(SoftSynthesizer synth);
149.38 +
149.39 + public double[] get(int instance, String name);
149.40 +
149.41 + public void processControlLogic();
149.42 +
149.43 + public void reset();
149.44 +}
150.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
150.2 +++ b/src/share/classes/com/sun/media/sound/SoftProvider.java Tue Feb 03 22:02:55 2009 -0800
150.3 @@ -0,0 +1,51 @@
150.4 +/*
150.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
150.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
150.7 + *
150.8 + * This code is free software; you can redistribute it and/or modify it
150.9 + * under the terms of the GNU General Public License version 2 only, as
150.10 + * published by the Free Software Foundation. Sun designates this
150.11 + * particular file as subject to the "Classpath" exception as provided
150.12 + * by Sun in the LICENSE file that accompanied this code.
150.13 + *
150.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
150.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
150.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
150.17 + * version 2 for more details (a copy is included in the LICENSE file that
150.18 + * accompanied this code).
150.19 + *
150.20 + * You should have received a copy of the GNU General Public License version
150.21 + * 2 along with this work; if not, write to the Free Software Foundation,
150.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
150.23 + *
150.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
150.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
150.26 + * have any questions.
150.27 + */
150.28 +package com.sun.media.sound;
150.29 +
150.30 +import javax.sound.midi.MidiDevice;
150.31 +import javax.sound.midi.MidiDevice.Info;
150.32 +import javax.sound.midi.spi.MidiDeviceProvider;
150.33 +
150.34 +/**
150.35 + * Software synthesizer provider class.
150.36 + *
150.37 + * @author Karl Helgason
150.38 + */
150.39 +public class SoftProvider extends MidiDeviceProvider {
150.40 +
150.41 + protected final static Info softinfo = SoftSynthesizer.info;
150.42 + private static Info[] softinfos = {softinfo};
150.43 +
150.44 + public MidiDevice.Info[] getDeviceInfo() {
150.45 + return softinfos;
150.46 + }
150.47 +
150.48 + public MidiDevice getDevice(MidiDevice.Info info) {
150.49 + if (info == softinfo) {
150.50 + return new SoftSynthesizer();
150.51 + }
150.52 + return null;
150.53 + }
150.54 +}
151.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
151.2 +++ b/src/share/classes/com/sun/media/sound/SoftReceiver.java Tue Feb 03 22:02:55 2009 -0800
151.3 @@ -0,0 +1,83 @@
151.4 +/*
151.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
151.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
151.7 + *
151.8 + * This code is free software; you can redistribute it and/or modify it
151.9 + * under the terms of the GNU General Public License version 2 only, as
151.10 + * published by the Free Software Foundation. Sun designates this
151.11 + * particular file as subject to the "Classpath" exception as provided
151.12 + * by Sun in the LICENSE file that accompanied this code.
151.13 + *
151.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
151.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
151.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
151.17 + * version 2 for more details (a copy is included in the LICENSE file that
151.18 + * accompanied this code).
151.19 + *
151.20 + * You should have received a copy of the GNU General Public License version
151.21 + * 2 along with this work; if not, write to the Free Software Foundation,
151.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
151.23 + *
151.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
151.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
151.26 + * have any questions.
151.27 + */
151.28 +package com.sun.media.sound;
151.29 +
151.30 +import java.util.TreeMap;
151.31 +
151.32 +import javax.sound.midi.MidiMessage;
151.33 +import javax.sound.midi.Receiver;
151.34 +import javax.sound.midi.ShortMessage;
151.35 +
151.36 +/**
151.37 + * Software synthesizer MIDI receiver class.
151.38 + *
151.39 + * @author Karl Helgason
151.40 + */
151.41 +public class SoftReceiver implements Receiver {
151.42 +
151.43 + protected boolean open = true;
151.44 + private Object control_mutex;
151.45 + private SoftSynthesizer synth;
151.46 + protected TreeMap<Long, Object> midimessages;
151.47 + protected SoftMainMixer mainmixer;
151.48 +
151.49 + public SoftReceiver(SoftSynthesizer synth) {
151.50 + this.control_mutex = synth.control_mutex;
151.51 + this.synth = synth;
151.52 + this.mainmixer = synth.getMainMixer();
151.53 + if (mainmixer != null)
151.54 + this.midimessages = mainmixer.midimessages;
151.55 + }
151.56 +
151.57 + public void send(MidiMessage message, long timeStamp) {
151.58 +
151.59 + synchronized (control_mutex) {
151.60 + if (!open)
151.61 + throw new IllegalStateException("Receiver is not open");
151.62 + }
151.63 +
151.64 + if (timeStamp != -1) {
151.65 + synchronized (control_mutex) {
151.66 + while (midimessages.get(timeStamp) != null)
151.67 + timeStamp++;
151.68 + if (message instanceof ShortMessage
151.69 + && (((ShortMessage)message).getChannel() > 0xF)) {
151.70 + midimessages.put(timeStamp, message.clone());
151.71 + } else {
151.72 + midimessages.put(timeStamp, message.getMessage());
151.73 + }
151.74 + }
151.75 + } else {
151.76 + mainmixer.processMessage(message);
151.77 + }
151.78 + }
151.79 +
151.80 + public void close() {
151.81 + synchronized (control_mutex) {
151.82 + open = false;
151.83 + }
151.84 + synth.removeReceiver(this);
151.85 + }
151.86 +}
152.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
152.2 +++ b/src/share/classes/com/sun/media/sound/SoftResampler.java Tue Feb 03 22:02:55 2009 -0800
152.3 @@ -0,0 +1,35 @@
152.4 +/*
152.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
152.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
152.7 + *
152.8 + * This code is free software; you can redistribute it and/or modify it
152.9 + * under the terms of the GNU General Public License version 2 only, as
152.10 + * published by the Free Software Foundation. Sun designates this
152.11 + * particular file as subject to the "Classpath" exception as provided
152.12 + * by Sun in the LICENSE file that accompanied this code.
152.13 + *
152.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
152.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
152.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
152.17 + * version 2 for more details (a copy is included in the LICENSE file that
152.18 + * accompanied this code).
152.19 + *
152.20 + * You should have received a copy of the GNU General Public License version
152.21 + * 2 along with this work; if not, write to the Free Software Foundation,
152.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
152.23 + *
152.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
152.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
152.26 + * have any questions.
152.27 + */
152.28 +package com.sun.media.sound;
152.29 +
152.30 +/**
152.31 + * Basic resampler interface.
152.32 + *
152.33 + * @author Karl Helgason
152.34 + */
152.35 +public interface SoftResampler {
152.36 +
152.37 + public SoftResamplerStreamer openStreamer();
152.38 +}
153.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
153.2 +++ b/src/share/classes/com/sun/media/sound/SoftResamplerStreamer.java Tue Feb 03 22:02:55 2009 -0800
153.3 @@ -0,0 +1,38 @@
153.4 +/*
153.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
153.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
153.7 + *
153.8 + * This code is free software; you can redistribute it and/or modify it
153.9 + * under the terms of the GNU General Public License version 2 only, as
153.10 + * published by the Free Software Foundation. Sun designates this
153.11 + * particular file as subject to the "Classpath" exception as provided
153.12 + * by Sun in the LICENSE file that accompanied this code.
153.13 + *
153.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
153.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
153.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
153.17 + * version 2 for more details (a copy is included in the LICENSE file that
153.18 + * accompanied this code).
153.19 + *
153.20 + * You should have received a copy of the GNU General Public License version
153.21 + * 2 along with this work; if not, write to the Free Software Foundation,
153.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
153.23 + *
153.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
153.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
153.26 + * have any questions.
153.27 + */
153.28 +package com.sun.media.sound;
153.29 +
153.30 +import java.io.IOException;
153.31 +
153.32 +/**
153.33 + * Resampler stream interface.
153.34 + *
153.35 + * @author Karl Helgason
153.36 + */
153.37 +public interface SoftResamplerStreamer extends ModelOscillatorStream {
153.38 +
153.39 + public void open(ModelWavetable osc, float outputsamplerate)
153.40 + throws IOException;
153.41 +}
154.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
154.2 +++ b/src/share/classes/com/sun/media/sound/SoftReverb.java Tue Feb 03 22:02:55 2009 -0800
154.3 @@ -0,0 +1,515 @@
154.4 +/*
154.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
154.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
154.7 + *
154.8 + * This code is free software; you can redistribute it and/or modify it
154.9 + * under the terms of the GNU General Public License version 2 only, as
154.10 + * published by the Free Software Foundation. Sun designates this
154.11 + * particular file as subject to the "Classpath" exception as provided
154.12 + * by Sun in the LICENSE file that accompanied this code.
154.13 + *
154.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
154.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
154.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
154.17 + * version 2 for more details (a copy is included in the LICENSE file that
154.18 + * accompanied this code).
154.19 + *
154.20 + * You should have received a copy of the GNU General Public License version
154.21 + * 2 along with this work; if not, write to the Free Software Foundation,
154.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
154.23 + *
154.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
154.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
154.26 + * have any questions.
154.27 + */
154.28 +package com.sun.media.sound;
154.29 +
154.30 +import java.util.Arrays;
154.31 +
154.32 +/**
154.33 + * Reverb effect based on allpass/comb filters. First audio is send to 8
154.34 + * parelled comb filters and then mixed together and then finally send thru 3
154.35 + * different allpass filters.
154.36 + *
154.37 + * @author Karl Helgason
154.38 + */
154.39 +public class SoftReverb implements SoftAudioProcessor {
154.40 +
154.41 + private final static class Delay {
154.42 +
154.43 + private float[] delaybuffer;
154.44 + private int rovepos = 0;
154.45 +
154.46 + public Delay() {
154.47 + delaybuffer = null;
154.48 + }
154.49 +
154.50 + public void setDelay(int delay) {
154.51 + if (delay == 0)
154.52 + delaybuffer = null;
154.53 + else
154.54 + delaybuffer = new float[delay];
154.55 + rovepos = 0;
154.56 + }
154.57 +
154.58 + public void processReplace(float[] inout) {
154.59 + if (delaybuffer == null)
154.60 + return;
154.61 + int len = inout.length;
154.62 + int rnlen = delaybuffer.length;
154.63 + int rovepos = this.rovepos;
154.64 +
154.65 + for (int i = 0; i < len; i++) {
154.66 + float x = inout[i];
154.67 + inout[i] = delaybuffer[rovepos];
154.68 + delaybuffer[rovepos] = x;
154.69 + if (++rovepos == rnlen)
154.70 + rovepos = 0;
154.71 + }
154.72 + this.rovepos = rovepos;
154.73 + }
154.74 + }
154.75 +
154.76 + private final static class AllPass {
154.77 +
154.78 + private final float[] delaybuffer;
154.79 + private final int delaybuffersize;
154.80 + private int rovepos = 0;
154.81 + private float feedback;
154.82 +
154.83 + public AllPass(int size) {
154.84 + delaybuffer = new float[size];
154.85 + delaybuffersize = size;
154.86 + }
154.87 +
154.88 + public void setFeedBack(float feedback) {
154.89 + this.feedback = feedback;
154.90 + }
154.91 +
154.92 + public void processReplace(float inout[]) {
154.93 + int len = inout.length;
154.94 + int delaybuffersize = this.delaybuffersize;
154.95 + int rovepos = this.rovepos;
154.96 + for (int i = 0; i < len; i++) {
154.97 + float delayout = delaybuffer[rovepos];
154.98 + float input = inout[i];
154.99 + inout[i] = delayout - input;
154.100 + delaybuffer[rovepos] = input + delayout * feedback;
154.101 + if (++rovepos == delaybuffersize)
154.102 + rovepos = 0;
154.103 + }
154.104 + this.rovepos = rovepos;
154.105 + }
154.106 +
154.107 + public void processReplace(float in[], float out[]) {
154.108 + int len = in.length;
154.109 + int delaybuffersize = this.delaybuffersize;
154.110 + int rovepos = this.rovepos;
154.111 + for (int i = 0; i < len; i++) {
154.112 + float delayout = delaybuffer[rovepos];
154.113 + float input = in[i];
154.114 + out[i] = delayout - input;
154.115 + delaybuffer[rovepos] = input + delayout * feedback;
154.116 + if (++rovepos == delaybuffersize)
154.117 + rovepos = 0;
154.118 + }
154.119 + this.rovepos = rovepos;
154.120 + }
154.121 + }
154.122 +
154.123 + private final static class Comb {
154.124 +
154.125 + private final float[] delaybuffer;
154.126 + private final int delaybuffersize;
154.127 + private int rovepos = 0;
154.128 + private float feedback;
154.129 + private float filtertemp = 0;
154.130 + private float filtercoeff1 = 0;
154.131 + private float filtercoeff2 = 1;
154.132 +
154.133 + public Comb(int size) {
154.134 + delaybuffer = new float[size];
154.135 + delaybuffersize = size;
154.136 + }
154.137 +
154.138 + public void setFeedBack(float feedback) {
154.139 + this.feedback = feedback;
154.140 + filtercoeff2 = (1 - filtercoeff1)* feedback;
154.141 + }
154.142 +
154.143 + public void processMix(float in[], float out[]) {
154.144 + int len = in.length;
154.145 + int delaybuffersize = this.delaybuffersize;
154.146 + int rovepos = this.rovepos;
154.147 + float filtertemp = this.filtertemp;
154.148 + float filtercoeff1 = this.filtercoeff1;
154.149 + float filtercoeff2 = this.filtercoeff2;
154.150 + for (int i = 0; i < len; i++) {
154.151 + float delayout = delaybuffer[rovepos];
154.152 + // One Pole Lowpass Filter
154.153 + filtertemp = (delayout * filtercoeff2)
154.154 + + (filtertemp * filtercoeff1);
154.155 + out[i] += delayout;
154.156 + delaybuffer[rovepos] = in[i] + filtertemp;
154.157 + if (++rovepos == delaybuffersize)
154.158 + rovepos = 0;
154.159 + }
154.160 + this.filtertemp = filtertemp;
154.161 + this.rovepos = rovepos;
154.162 + }
154.163 +
154.164 + public void processReplace(float in[], float out[]) {
154.165 + int len = in.length;
154.166 + int delaybuffersize = this.delaybuffersize;
154.167 + int rovepos = this.rovepos;
154.168 + float filtertemp = this.filtertemp;
154.169 + float filtercoeff1 = this.filtercoeff1;
154.170 + float filtercoeff2 = this.filtercoeff2;
154.171 + for (int i = 0; i < len; i++) {
154.172 + float delayout = delaybuffer[rovepos];
154.173 + // One Pole Lowpass Filter
154.174 + filtertemp = (delayout * filtercoeff2)
154.175 + + (filtertemp * filtercoeff1);
154.176 + out[i] = delayout;
154.177 + delaybuffer[rovepos] = in[i] + filtertemp;
154.178 + if (++rovepos == delaybuffersize)
154.179 + rovepos = 0;
154.180 + }
154.181 + this.filtertemp = filtertemp;
154.182 + this.rovepos = rovepos;
154.183 + }
154.184 +
154.185 + public void setDamp(float val) {
154.186 + filtercoeff1 = val;
154.187 + filtercoeff2 = (1 - filtercoeff1)* feedback;
154.188 + }
154.189 + }
154.190 + private float roomsize;
154.191 + private float damp;
154.192 + private float gain = 1;
154.193 + private Delay delay;
154.194 + private Comb[] combL;
154.195 + private Comb[] combR;
154.196 + private AllPass[] allpassL;
154.197 + private AllPass[] allpassR;
154.198 + private float[] input;
154.199 + private float[] out;
154.200 + private float[] pre1;
154.201 + private float[] pre2;
154.202 + private float[] pre3;
154.203 + private boolean denormal_flip = false;
154.204 + private boolean mix = true;
154.205 + private SoftAudioBuffer inputA;
154.206 + private SoftAudioBuffer left;
154.207 + private SoftAudioBuffer right;
154.208 + private boolean dirty = true;
154.209 + private float dirty_roomsize;
154.210 + private float dirty_damp;
154.211 + private float dirty_predelay;
154.212 + private float dirty_gain;
154.213 + private float samplerate;
154.214 + private boolean light = true;
154.215 +
154.216 + public void init(float samplerate, float controlrate) {
154.217 + this.samplerate = samplerate;
154.218 +
154.219 + double freqscale = ((double) samplerate) / 44100.0;
154.220 + // freqscale = 1.0/ freqscale;
154.221 +
154.222 + int stereospread = 23;
154.223 +
154.224 + delay = new Delay();
154.225 +
154.226 + combL = new Comb[8];
154.227 + combR = new Comb[8];
154.228 + combL[0] = new Comb((int) (freqscale * (1116)));
154.229 + combR[0] = new Comb((int) (freqscale * (1116 + stereospread)));
154.230 + combL[1] = new Comb((int) (freqscale * (1188)));
154.231 + combR[1] = new Comb((int) (freqscale * (1188 + stereospread)));
154.232 + combL[2] = new Comb((int) (freqscale * (1277)));
154.233 + combR[2] = new Comb((int) (freqscale * (1277 + stereospread)));
154.234 + combL[3] = new Comb((int) (freqscale * (1356)));
154.235 + combR[3] = new Comb((int) (freqscale * (1356 + stereospread)));
154.236 + combL[4] = new Comb((int) (freqscale * (1422)));
154.237 + combR[4] = new Comb((int) (freqscale * (1422 + stereospread)));
154.238 + combL[5] = new Comb((int) (freqscale * (1491)));
154.239 + combR[5] = new Comb((int) (freqscale * (1491 + stereospread)));
154.240 + combL[6] = new Comb((int) (freqscale * (1557)));
154.241 + combR[6] = new Comb((int) (freqscale * (1557 + stereospread)));
154.242 + combL[7] = new Comb((int) (freqscale * (1617)));
154.243 + combR[7] = new Comb((int) (freqscale * (1617 + stereospread)));
154.244 +
154.245 + allpassL = new AllPass[4];
154.246 + allpassR = new AllPass[4];
154.247 + allpassL[0] = new AllPass((int) (freqscale * (556)));
154.248 + allpassR[0] = new AllPass((int) (freqscale * (556 + stereospread)));
154.249 + allpassL[1] = new AllPass((int) (freqscale * (441)));
154.250 + allpassR[1] = new AllPass((int) (freqscale * (441 + stereospread)));
154.251 + allpassL[2] = new AllPass((int) (freqscale * (341)));
154.252 + allpassR[2] = new AllPass((int) (freqscale * (341 + stereospread)));
154.253 + allpassL[3] = new AllPass((int) (freqscale * (225)));
154.254 + allpassR[3] = new AllPass((int) (freqscale * (225 + stereospread)));
154.255 +
154.256 + for (int i = 0; i < allpassL.length; i++) {
154.257 + allpassL[i].setFeedBack(0.5f);
154.258 + allpassR[i].setFeedBack(0.5f);
154.259 + }
154.260 +
154.261 + /* Init other settings */
154.262 + globalParameterControlChange(new int[]{0x01 * 128 + 0x01}, 0, 4);
154.263 +
154.264 + }
154.265 +
154.266 + public void setInput(int pin, SoftAudioBuffer input) {
154.267 + if (pin == 0)
154.268 + inputA = input;
154.269 + }
154.270 +
154.271 + public void setOutput(int pin, SoftAudioBuffer output) {
154.272 + if (pin == 0)
154.273 + left = output;
154.274 + if (pin == 1)
154.275 + right = output;
154.276 + }
154.277 +
154.278 + public void setMixMode(boolean mix) {
154.279 + this.mix = mix;
154.280 + }
154.281 +
154.282 + private boolean silent = true;
154.283 +
154.284 + public void processAudio() {
154.285 + boolean silent_input = this.inputA.isSilent();
154.286 + if(!silent_input)
154.287 + silent = false;
154.288 + if(silent)
154.289 + {
154.290 + if (!mix) {
154.291 + left.clear();
154.292 + right.clear();
154.293 + }
154.294 + return;
154.295 + }
154.296 +
154.297 + float[] inputA = this.inputA.array();
154.298 + float[] left = this.left.array();
154.299 + float[] right = this.right == null ? null : this.right.array();
154.300 +
154.301 + int numsamples = inputA.length;
154.302 + if (input == null || input.length < numsamples)
154.303 + input = new float[numsamples];
154.304 +
154.305 + float again = gain * 0.018f / 2;
154.306 +
154.307 + denormal_flip = !denormal_flip;
154.308 + if(denormal_flip)
154.309 + for (int i = 0; i < numsamples; i++)
154.310 + input[i] = inputA[i] * again + 1E-20f;
154.311 + else
154.312 + for (int i = 0; i < numsamples; i++)
154.313 + input[i] = inputA[i] * again - 1E-20f;
154.314 +
154.315 + delay.processReplace(input);
154.316 +
154.317 + if(light && (right != null))
154.318 + {
154.319 + if (pre1 == null || pre1.length < numsamples)
154.320 + {
154.321 + pre1 = new float[numsamples];
154.322 + pre2 = new float[numsamples];
154.323 + pre3 = new float[numsamples];
154.324 + }
154.325 +
154.326 + for (int i = 0; i < allpassL.length; i++)
154.327 + allpassL[i].processReplace(input);
154.328 +
154.329 + combL[0].processReplace(input, pre3);
154.330 + combL[1].processReplace(input, pre3);
154.331 +
154.332 + combL[2].processReplace(input, pre1);
154.333 + for (int i = 4; i < combL.length-2; i+=2)
154.334 + combL[i].processMix(input, pre1);
154.335 +
154.336 + combL[3].processReplace(input, pre2);;
154.337 + for (int i = 5; i < combL.length-2; i+=2)
154.338 + combL[i].processMix(input, pre2);
154.339 +
154.340 + if (!mix)
154.341 + {
154.342 + Arrays.fill(right, 0);
154.343 + Arrays.fill(left, 0);
154.344 + }
154.345 + for (int i = combR.length-2; i < combR.length; i++)
154.346 + combR[i].processMix(input, right);
154.347 + for (int i = combL.length-2; i < combL.length; i++)
154.348 + combL[i].processMix(input, left);
154.349 +
154.350 + for (int i = 0; i < numsamples; i++)
154.351 + {
154.352 + float p = pre1[i] - pre2[i];
154.353 + float m = pre3[i];
154.354 + left[i] += m + p;
154.355 + right[i] += m - p;
154.356 + }
154.357 + }
154.358 + else
154.359 + {
154.360 + if (out == null || out.length < numsamples)
154.361 + out = new float[numsamples];
154.362 +
154.363 + if (right != null) {
154.364 + if (!mix)
154.365 + Arrays.fill(right, 0);
154.366 + allpassR[0].processReplace(input, out);
154.367 + for (int i = 1; i < allpassR.length; i++)
154.368 + allpassR[i].processReplace(out);
154.369 + for (int i = 0; i < combR.length; i++)
154.370 + combR[i].processMix(out, right);
154.371 + }
154.372 +
154.373 + if (!mix)
154.374 + Arrays.fill(left, 0);
154.375 + allpassL[0].processReplace(input, out);
154.376 + for (int i = 1; i < allpassL.length; i++)
154.377 + allpassL[i].processReplace(out);
154.378 + for (int i = 0; i < combL.length; i++)
154.379 + combL[i].processMix(out, left);
154.380 + }
154.381 +
154.382 +
154.383 +
154.384 +
154.385 +
154.386 +
154.387 + if (silent_input) {
154.388 + silent = true;
154.389 + for (int i = 0; i < numsamples; i++)
154.390 + {
154.391 + float v = left[i];
154.392 + if(v > 1E-10 || v < -1E-10)
154.393 + {
154.394 + silent = false;
154.395 + break;
154.396 + }
154.397 + }
154.398 + }
154.399 +
154.400 + }
154.401 +
154.402 + public void globalParameterControlChange(int[] slothpath, long param,
154.403 + long value) {
154.404 + if (slothpath.length == 1) {
154.405 + if (slothpath[0] == 0x01 * 128 + 0x01) {
154.406 +
154.407 + if (param == 0) {
154.408 + if (value == 0) {
154.409 + // Small Room A small size room with a length
154.410 + // of 5m or so.
154.411 + dirty_roomsize = (1.1f);
154.412 + dirty_damp = (5000);
154.413 + dirty_predelay = (0);
154.414 + dirty_gain = (4);
154.415 + dirty = true;
154.416 + }
154.417 + if (value == 1) {
154.418 + // Medium Room A medium size room with a length
154.419 + // of 10m or so.
154.420 + dirty_roomsize = (1.3f);
154.421 + dirty_damp = (5000);
154.422 + dirty_predelay = (0);
154.423 + dirty_gain = (3);
154.424 + dirty = true;
154.425 + }
154.426 + if (value == 2) {
154.427 + // Large Room A large size room suitable for
154.428 + // live performances.
154.429 + dirty_roomsize = (1.5f);
154.430 + dirty_damp = (5000);
154.431 + dirty_predelay = (0);
154.432 + dirty_gain = (2);
154.433 + dirty = true;
154.434 + }
154.435 + if (value == 3) {
154.436 + // Medium Hall A medium size concert hall.
154.437 + dirty_roomsize = (1.8f);
154.438 + dirty_damp = (24000);
154.439 + dirty_predelay = (0.02f);
154.440 + dirty_gain = (1.5f);
154.441 + dirty = true;
154.442 + }
154.443 + if (value == 4) {
154.444 + // Large Hall A large size concert hall
154.445 + // suitable for a full orchestra.
154.446 + dirty_roomsize = (1.8f);
154.447 + dirty_damp = (24000);
154.448 + dirty_predelay = (0.03f);
154.449 + dirty_gain = (1.5f);
154.450 + dirty = true;
154.451 + }
154.452 + if (value == 8) {
154.453 + // Plate A plate reverb simulation.
154.454 + dirty_roomsize = (1.3f);
154.455 + dirty_damp = (2500);
154.456 + dirty_predelay = (0);
154.457 + dirty_gain = (6);
154.458 + dirty = true;
154.459 + }
154.460 + } else if (param == 1) {
154.461 + dirty_roomsize = ((float) (Math.exp((value - 40) * 0.025)));
154.462 + dirty = true;
154.463 + }
154.464 +
154.465 + }
154.466 + }
154.467 + }
154.468 +
154.469 + public void processControlLogic() {
154.470 + if (dirty) {
154.471 + dirty = false;
154.472 + setRoomSize(dirty_roomsize);
154.473 + setDamp(dirty_damp);
154.474 + setPreDelay(dirty_predelay);
154.475 + setGain(dirty_gain);
154.476 + }
154.477 + }
154.478 +
154.479 + public void setRoomSize(float value) {
154.480 + roomsize = 1 - (0.17f / value);
154.481 +
154.482 + for (int i = 0; i < combL.length; i++) {
154.483 + combL[i].feedback = roomsize;
154.484 + combR[i].feedback = roomsize;
154.485 + }
154.486 + }
154.487 +
154.488 + public void setPreDelay(float value) {
154.489 + delay.setDelay((int)(value * samplerate));
154.490 + }
154.491 +
154.492 + public void setGain(float gain) {
154.493 + this.gain = gain;
154.494 + }
154.495 +
154.496 + public void setDamp(float value) {
154.497 + double x = (value / samplerate) * (2 * Math.PI);
154.498 + double cx = 2 - Math.cos(x);
154.499 + damp = (float)(cx - Math.sqrt(cx * cx - 1));
154.500 + if (damp > 1)
154.501 + damp = 1;
154.502 + if (damp < 0)
154.503 + damp = 0;
154.504 +
154.505 + // damp = value * 0.4f;
154.506 + for (int i = 0; i < combL.length; i++) {
154.507 + combL[i].setDamp(damp);
154.508 + combR[i].setDamp(damp);
154.509 + }
154.510 +
154.511 + }
154.512 +
154.513 + public void setLightMode(boolean light)
154.514 + {
154.515 + this.light = light;
154.516 + }
154.517 +}
154.518 +
155.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
155.2 +++ b/src/share/classes/com/sun/media/sound/SoftShortMessage.java Tue Feb 03 22:02:55 2009 -0800
155.3 @@ -0,0 +1,58 @@
155.4 +/*
155.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
155.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
155.7 + *
155.8 + * This code is free software; you can redistribute it and/or modify it
155.9 + * under the terms of the GNU General Public License version 2 only, as
155.10 + * published by the Free Software Foundation. Sun designates this
155.11 + * particular file as subject to the "Classpath" exception as provided
155.12 + * by Sun in the LICENSE file that accompanied this code.
155.13 + *
155.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
155.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
155.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
155.17 + * version 2 for more details (a copy is included in the LICENSE file that
155.18 + * accompanied this code).
155.19 + *
155.20 + * You should have received a copy of the GNU General Public License version
155.21 + * 2 along with this work; if not, write to the Free Software Foundation,
155.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
155.23 + *
155.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
155.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
155.26 + * have any questions.
155.27 + */
155.28 +package com.sun.media.sound;
155.29 +
155.30 +import javax.sound.midi.InvalidMidiDataException;
155.31 +import javax.sound.midi.ShortMessage;
155.32 +
155.33 +/**
155.34 + * A short message class that support for than 16 midi channels.
155.35 + *
155.36 + * @author Karl Helgason
155.37 + */
155.38 +public class SoftShortMessage extends ShortMessage {
155.39 +
155.40 + int channel = 0;
155.41 +
155.42 + public int getChannel() {
155.43 + return channel;
155.44 + }
155.45 +
155.46 + public void setMessage(int command, int channel, int data1, int data2)
155.47 + throws InvalidMidiDataException {
155.48 + this.channel = channel;
155.49 + super.setMessage(command, channel & 0xF, data1, data2);
155.50 + }
155.51 +
155.52 + public Object clone() {
155.53 + SoftShortMessage clone = new SoftShortMessage();
155.54 + try {
155.55 + clone.setMessage(getCommand(), getChannel(), getData1(), getData2());
155.56 + } catch (InvalidMidiDataException e) {
155.57 + throw new IllegalArgumentException(e);
155.58 + }
155.59 + return clone;
155.60 + }
155.61 +}
156.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
156.2 +++ b/src/share/classes/com/sun/media/sound/SoftSincResampler.java Tue Feb 03 22:02:55 2009 -0800
156.3 @@ -0,0 +1,139 @@
156.4 +/*
156.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
156.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
156.7 + *
156.8 + * This code is free software; you can redistribute it and/or modify it
156.9 + * under the terms of the GNU General Public License version 2 only, as
156.10 + * published by the Free Software Foundation. Sun designates this
156.11 + * particular file as subject to the "Classpath" exception as provided
156.12 + * by Sun in the LICENSE file that accompanied this code.
156.13 + *
156.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
156.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
156.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
156.17 + * version 2 for more details (a copy is included in the LICENSE file that
156.18 + * accompanied this code).
156.19 + *
156.20 + * You should have received a copy of the GNU General Public License version
156.21 + * 2 along with this work; if not, write to the Free Software Foundation,
156.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
156.23 + *
156.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
156.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
156.26 + * have any questions.
156.27 + */
156.28 +package com.sun.media.sound;
156.29 +
156.30 +/**
156.31 + * Hann windowed sinc interpolation resampler with anti-alias filtering.
156.32 + *
156.33 + * Using 30 points for the interpolation.
156.34 + *
156.35 + * @author Karl Helgason
156.36 + */
156.37 +public class SoftSincResampler extends SoftAbstractResampler {
156.38 +
156.39 + float[][][] sinc_table;
156.40 + int sinc_scale_size = 100;
156.41 + int sinc_table_fsize = 800;
156.42 + int sinc_table_size = 30;
156.43 + int sinc_table_center = sinc_table_size / 2;
156.44 +
156.45 + public SoftSincResampler() {
156.46 + super();
156.47 + sinc_table = new float[sinc_scale_size][sinc_table_fsize][];
156.48 + for (int s = 0; s < sinc_scale_size; s++) {
156.49 + float scale = (float) (1.0 / (1.0 + Math.pow(s, 1.1) / 10.0));
156.50 + for (int i = 0; i < sinc_table_fsize; i++) {
156.51 + sinc_table[s][i] = sincTable(sinc_table_size,
156.52 + -i / ((float)sinc_table_fsize), scale);
156.53 + }
156.54 + }
156.55 + }
156.56 +
156.57 + // Normalized sinc function
156.58 + public static double sinc(double x) {
156.59 + return (x == 0.0) ? 1.0 : Math.sin(Math.PI * x) / (Math.PI * x);
156.60 + }
156.61 +
156.62 + // Generate hann window suitable for windowing sinc
156.63 + public static float[] wHanning(int size, float offset) {
156.64 + float[] window_table = new float[size];
156.65 + for (int k = 0; k < size; k++) {
156.66 + window_table[k] = (float)(-0.5
156.67 + * Math.cos(2.0 * Math.PI * (double)(k + offset)
156.68 + / (double) size) + 0.5);
156.69 + }
156.70 + return window_table;
156.71 + }
156.72 +
156.73 + // Generate sinc table
156.74 + public static float[] sincTable(int size, float offset, float scale) {
156.75 + int center = size / 2;
156.76 + float[] w = wHanning(size, offset);
156.77 + for (int k = 0; k < size; k++)
156.78 + w[k] *= sinc((-center + k + offset) * scale) * scale;
156.79 + return w;
156.80 + }
156.81 +
156.82 + public int getPadding() // must be at least half of sinc_table_size
156.83 + {
156.84 + return sinc_table_size / 2 + 2;
156.85 + }
156.86 +
156.87 + public void interpolate(float[] in, float[] in_offset, float in_end,
156.88 + float[] startpitch, float pitchstep, float[] out, int[] out_offset,
156.89 + int out_end) {
156.90 + float pitch = startpitch[0];
156.91 + float ix = in_offset[0];
156.92 + int ox = out_offset[0];
156.93 + float ix_end = in_end;
156.94 + int ox_end = out_end;
156.95 + int max_p = sinc_scale_size - 1;
156.96 + if (pitchstep == 0) {
156.97 +
156.98 + int p = (int) ((pitch - 1) * 10.0f);
156.99 + if (p < 0)
156.100 + p = 0;
156.101 + else if (p > max_p)
156.102 + p = max_p;
156.103 + float[][] sinc_table_f = this.sinc_table[p];
156.104 + while (ix < ix_end && ox < ox_end) {
156.105 + int iix = (int) ix;
156.106 + float[] sinc_table =
156.107 + sinc_table_f[(int)((ix - iix) * sinc_table_fsize)];
156.108 + int xx = iix - sinc_table_center;
156.109 + float y = 0;
156.110 + for (int i = 0; i < sinc_table_size; i++, xx++)
156.111 + y += in[xx] * sinc_table[i];
156.112 + out[ox++] = y;
156.113 + ix += pitch;
156.114 + }
156.115 + } else {
156.116 + while (ix < ix_end && ox < ox_end) {
156.117 + int iix = (int) ix;
156.118 + int p = (int) ((pitch - 1) * 10.0f);
156.119 + if (p < 0)
156.120 + p = 0;
156.121 + else if (p > max_p)
156.122 + p = max_p;
156.123 + float[][] sinc_table_f = this.sinc_table[p];
156.124 +
156.125 + float[] sinc_table =
156.126 + sinc_table_f[(int)((ix - iix) * sinc_table_fsize)];
156.127 + int xx = iix - sinc_table_center;
156.128 + float y = 0;
156.129 + for (int i = 0; i < sinc_table_size; i++, xx++)
156.130 + y += in[xx] * sinc_table[i];
156.131 + out[ox++] = y;
156.132 +
156.133 + ix += pitch;
156.134 + pitch += pitchstep;
156.135 + }
156.136 + }
156.137 + in_offset[0] = ix;
156.138 + out_offset[0] = ox;
156.139 + startpitch[0] = pitch;
156.140 +
156.141 + }
156.142 +}
157.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
157.2 +++ b/src/share/classes/com/sun/media/sound/SoftSynthesizer.java Tue Feb 03 22:02:55 2009 -0800
157.3 @@ -0,0 +1,1179 @@
157.4 +/*
157.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
157.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
157.7 + *
157.8 + * This code is free software; you can redistribute it and/or modify it
157.9 + * under the terms of the GNU General Public License version 2 only, as
157.10 + * published by the Free Software Foundation. Sun designates this
157.11 + * particular file as subject to the "Classpath" exception as provided
157.12 + * by Sun in the LICENSE file that accompanied this code.
157.13 + *
157.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
157.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
157.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
157.17 + * version 2 for more details (a copy is included in the LICENSE file that
157.18 + * accompanied this code).
157.19 + *
157.20 + * You should have received a copy of the GNU General Public License version
157.21 + * 2 along with this work; if not, write to the Free Software Foundation,
157.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
157.23 + *
157.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
157.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
157.26 + * have any questions.
157.27 + */
157.28 +
157.29 +package com.sun.media.sound;
157.30 +
157.31 +import java.io.File;
157.32 +import java.io.IOException;
157.33 +import java.io.InputStream;
157.34 +import java.lang.ref.WeakReference;
157.35 +import java.security.AccessControlException;
157.36 +import java.util.ArrayList;
157.37 +import java.util.Arrays;
157.38 +import java.util.HashMap;
157.39 +import java.util.List;
157.40 +import java.util.Map;
157.41 +
157.42 +import javax.sound.midi.Instrument;
157.43 +import javax.sound.midi.MidiChannel;
157.44 +import javax.sound.midi.MidiDevice;
157.45 +import javax.sound.midi.MidiSystem;
157.46 +import javax.sound.midi.MidiUnavailableException;
157.47 +import javax.sound.midi.Patch;
157.48 +import javax.sound.midi.Receiver;
157.49 +import javax.sound.midi.Soundbank;
157.50 +import javax.sound.midi.Transmitter;
157.51 +import javax.sound.midi.VoiceStatus;
157.52 +import javax.sound.sampled.AudioFormat;
157.53 +import javax.sound.sampled.AudioInputStream;
157.54 +import javax.sound.sampled.AudioSystem;
157.55 +import javax.sound.sampled.LineUnavailableException;
157.56 +import javax.sound.sampled.SourceDataLine;
157.57 +
157.58 +/**
157.59 + * The software synthesizer class.
157.60 + *
157.61 + * @author Karl Helgason
157.62 + */
157.63 +public class SoftSynthesizer implements AudioSynthesizer,
157.64 + ReferenceCountingDevice {
157.65 +
157.66 + protected static class WeakAudioStream extends InputStream
157.67 + {
157.68 + private volatile AudioInputStream stream;
157.69 + public SoftAudioPusher pusher = null;
157.70 + public AudioInputStream jitter_stream = null;
157.71 + public SourceDataLine sourceDataLine = null;
157.72 + private WeakReference<AudioInputStream> weak_stream_link;
157.73 + private AudioFloatConverter converter;
157.74 + private float[] silentbuffer = null;
157.75 + private int samplesize;
157.76 +
157.77 + public void setInputStream(AudioInputStream stream)
157.78 + {
157.79 + this.stream = stream;
157.80 + }
157.81 +
157.82 + public int available() throws IOException {
157.83 + AudioInputStream local_stream = stream;
157.84 + if(local_stream != null)
157.85 + return local_stream.available();
157.86 + return 0;
157.87 + }
157.88 +
157.89 + public int read() throws IOException {
157.90 + byte[] b = new byte[1];
157.91 + if (read(b) == -1)
157.92 + return -1;
157.93 + return b[0] & 0xFF;
157.94 + }
157.95 +
157.96 + public int read(byte[] b, int off, int len) throws IOException {
157.97 + AudioInputStream local_stream = stream;
157.98 + if(local_stream != null)
157.99 + return local_stream.read(b, off, len);
157.100 + else
157.101 + {
157.102 + int flen = len / samplesize;
157.103 + if(silentbuffer == null || silentbuffer.length < flen)
157.104 + silentbuffer = new float[flen];
157.105 + converter.toByteArray(silentbuffer, flen, b, off);
157.106 +
157.107 + if(pusher != null)
157.108 + if(weak_stream_link.get() == null)
157.109 + {
157.110 + Runnable runnable = new Runnable()
157.111 + {
157.112 + SoftAudioPusher _pusher = pusher;
157.113 + AudioInputStream _jitter_stream = jitter_stream;
157.114 + SourceDataLine _sourceDataLine = sourceDataLine;
157.115 + public void run()
157.116 + {
157.117 + _pusher.stop();
157.118 + if(_jitter_stream != null)
157.119 + try {
157.120 + _jitter_stream.close();
157.121 + } catch (IOException e) {
157.122 + e.printStackTrace();
157.123 + }
157.124 + if(_sourceDataLine != null)
157.125 + _sourceDataLine.close();
157.126 + }
157.127 + };
157.128 + pusher = null;
157.129 + jitter_stream = null;
157.130 + sourceDataLine = null;
157.131 + new Thread(runnable).start();
157.132 + }
157.133 + return len;
157.134 + }
157.135 + }
157.136 +
157.137 + public WeakAudioStream(AudioInputStream stream) {
157.138 + this.stream = stream;
157.139 + weak_stream_link = new WeakReference<AudioInputStream>(stream);
157.140 + converter = AudioFloatConverter.getConverter(stream.getFormat());
157.141 + samplesize = stream.getFormat().getFrameSize() / stream.getFormat().getChannels();
157.142 + }
157.143 +
157.144 + public AudioInputStream getAudioInputStream()
157.145 + {
157.146 + return new AudioInputStream(this, stream.getFormat(), AudioSystem.NOT_SPECIFIED);
157.147 + }
157.148 +
157.149 + public void close() throws IOException
157.150 + {
157.151 + AudioInputStream astream = weak_stream_link.get();
157.152 + if(astream != null)
157.153 + astream.close();
157.154 + }
157.155 + }
157.156 +
157.157 + private static class Info extends MidiDevice.Info {
157.158 + public Info() {
157.159 + super(INFO_NAME, INFO_VENDOR, INFO_DESCRIPTION, INFO_VERSION);
157.160 + }
157.161 + }
157.162 +
157.163 + protected static final String INFO_NAME = "Gervill";
157.164 + protected static final String INFO_VENDOR = "OpenJDK";
157.165 + protected static final String INFO_DESCRIPTION = "Software MIDI Synthesizer";
157.166 + protected static final String INFO_VERSION = "1.0";
157.167 + protected final static MidiDevice.Info info = new Info();
157.168 +
157.169 + private static SourceDataLine testline = null;
157.170 +
157.171 + private static Soundbank defaultSoundBank = null;
157.172 +
157.173 + protected WeakAudioStream weakstream = null;
157.174 +
157.175 + protected Object control_mutex = this;
157.176 +
157.177 + protected int voiceIDCounter = 0;
157.178 +
157.179 + // 0: default
157.180 + // 1: DLS Voice Allocation
157.181 + protected int voice_allocation_mode = 0;
157.182 +
157.183 + protected boolean reverb_light = true;
157.184 + protected boolean reverb_on = true;
157.185 + protected boolean chorus_on = true;
157.186 + protected boolean agc_on = true;
157.187 +
157.188 + protected SoftChannel[] channels;
157.189 + protected SoftChannelProxy[] external_channels = null;
157.190 +
157.191 + private boolean largemode = false;
157.192 +
157.193 + // 0: GM Mode off (default)
157.194 + // 1: GM Level 1
157.195 + // 2: GM Level 2
157.196 + private int gmmode = 0;
157.197 +
157.198 + private int deviceid = 0;
157.199 +
157.200 + private AudioFormat format = new AudioFormat(44100, 16, 2, true, false);
157.201 +
157.202 + private SourceDataLine sourceDataLine = null;
157.203 +
157.204 + private SoftAudioPusher pusher = null;
157.205 + private AudioInputStream pusher_stream = null;
157.206 +
157.207 + private float controlrate = 147f;
157.208 +
157.209 + private boolean open = false;
157.210 + private boolean implicitOpen = false;
157.211 +
157.212 + private String resamplerType = "linear";
157.213 + private SoftResampler resampler = new SoftLinearResampler();
157.214 +
157.215 + private int number_of_midi_channels = 16;
157.216 + private int maxpoly = 64;
157.217 + private long latency = 200000; // 200 msec
157.218 + private boolean jitter_correction = false;
157.219 +
157.220 + private SoftMainMixer mainmixer;
157.221 + private SoftVoice[] voices;
157.222 +
157.223 + private Map<String, SoftTuning> tunings
157.224 + = new HashMap<String, SoftTuning>();
157.225 + private Map<String, SoftInstrument> inslist
157.226 + = new HashMap<String, SoftInstrument>();
157.227 + private Map<String, ModelInstrument> availlist
157.228 + = new HashMap<String, ModelInstrument>();
157.229 + private Map<String, ModelInstrument> loadedlist
157.230 + = new HashMap<String, ModelInstrument>();
157.231 +
157.232 + private ArrayList<Receiver> recvslist = new ArrayList<Receiver>();
157.233 +
157.234 + private void getBuffers(ModelInstrument instrument,
157.235 + List<ModelByteBuffer> buffers) {
157.236 + for (ModelPerformer performer : instrument.getPerformers()) {
157.237 + if (performer.getOscillators() != null) {
157.238 + for (ModelOscillator osc : performer.getOscillators()) {
157.239 + if (osc instanceof ModelByteBufferWavetable) {
157.240 + ModelByteBufferWavetable w = (ModelByteBufferWavetable)osc;
157.241 + ModelByteBuffer buff = w.getBuffer();
157.242 + if (buff != null)
157.243 + buffers.add(buff);
157.244 + buff = w.get8BitExtensionBuffer();
157.245 + if (buff != null)
157.246 + buffers.add(buff);
157.247 + }
157.248 + }
157.249 + }
157.250 + }
157.251 + }
157.252 +
157.253 + private boolean loadSamples(List<ModelInstrument> instruments) {
157.254 + if (largemode)
157.255 + return true;
157.256 + List<ModelByteBuffer> buffers = new ArrayList<ModelByteBuffer>();
157.257 + for (ModelInstrument instrument : instruments)
157.258 + getBuffers(instrument, buffers);
157.259 + try {
157.260 + ModelByteBuffer.loadAll(buffers);
157.261 + } catch (IOException e) {
157.262 + return false;
157.263 + }
157.264 + return true;
157.265 + }
157.266 +
157.267 + private boolean loadInstruments(List<ModelInstrument> instruments) {
157.268 + if (!isOpen())
157.269 + return false;
157.270 + if (!loadSamples(instruments))
157.271 + return false;
157.272 +
157.273 + synchronized (control_mutex) {
157.274 + if (channels != null)
157.275 + for (SoftChannel c : channels)
157.276 + c.current_instrument = null;
157.277 + for (Instrument instrument : instruments) {
157.278 + String pat = patchToString(instrument.getPatch());
157.279 + availlist.remove(pat);
157.280 + SoftInstrument softins
157.281 + = new SoftInstrument((ModelInstrument) instrument);
157.282 + inslist.put(pat, softins);
157.283 + loadedlist.put(pat, (ModelInstrument) instrument);
157.284 + }
157.285 + }
157.286 +
157.287 + return true;
157.288 + }
157.289 +
157.290 + private void processPropertyInfo(Map<String, Object> info) {
157.291 + AudioSynthesizerPropertyInfo[] items = getPropertyInfo(info);
157.292 +
157.293 + String resamplerType = (String)items[0].value;
157.294 + if (resamplerType.equalsIgnoreCase("point"))
157.295 + {
157.296 + this.resampler = new SoftPointResampler();
157.297 + this.resamplerType = "point";
157.298 + }
157.299 + else if (resamplerType.equalsIgnoreCase("linear"))
157.300 + {
157.301 + this.resampler = new SoftLinearResampler2();
157.302 + this.resamplerType = "linear";
157.303 + }
157.304 + else if (resamplerType.equalsIgnoreCase("linear1"))
157.305 + {
157.306 + this.resampler = new SoftLinearResampler();
157.307 + this.resamplerType = "linear1";
157.308 + }
157.309 + else if (resamplerType.equalsIgnoreCase("linear2"))
157.310 + {
157.311 + this.resampler = new SoftLinearResampler2();
157.312 + this.resamplerType = "linear2";
157.313 + }
157.314 + else if (resamplerType.equalsIgnoreCase("cubic"))
157.315 + {
157.316 + this.resampler = new SoftCubicResampler();
157.317 + this.resamplerType = "cubic";
157.318 + }
157.319 + else if (resamplerType.equalsIgnoreCase("lanczos"))
157.320 + {
157.321 + this.resampler = new SoftLanczosResampler();
157.322 + this.resamplerType = "lanczos";
157.323 + }
157.324 + else if (resamplerType.equalsIgnoreCase("sinc"))
157.325 + {
157.326 + this.resampler = new SoftSincResampler();
157.327 + this.resamplerType = "sinc";
157.328 + }
157.329 +
157.330 + setFormat((AudioFormat)items[2].value);
157.331 + controlrate = (Float)items[1].value;
157.332 + latency = (Long)items[3].value;
157.333 + deviceid = (Integer)items[4].value;
157.334 + maxpoly = (Integer)items[5].value;
157.335 + reverb_on = (Boolean)items[6].value;
157.336 + chorus_on = (Boolean)items[7].value;
157.337 + agc_on = (Boolean)items[8].value;
157.338 + largemode = (Boolean)items[9].value;
157.339 + number_of_midi_channels = (Integer)items[10].value;
157.340 + jitter_correction = (Boolean)items[11].value;
157.341 + reverb_light = (Boolean)items[12].value;
157.342 + }
157.343 +
157.344 + private String patchToString(Patch patch) {
157.345 + if (patch instanceof ModelPatch && ((ModelPatch) patch).isPercussion())
157.346 + return "p." + patch.getProgram() + "." + patch.getBank();
157.347 + else
157.348 + return patch.getProgram() + "." + patch.getBank();
157.349 + }
157.350 +
157.351 + private void setFormat(AudioFormat format) {
157.352 + if (format.getChannels() > 2) {
157.353 + throw new IllegalArgumentException(
157.354 + "Only mono and stereo audio supported.");
157.355 + }
157.356 + if (AudioFloatConverter.getConverter(format) == null)
157.357 + throw new IllegalArgumentException("Audio format not supported.");
157.358 + this.format = format;
157.359 + }
157.360 +
157.361 + protected void removeReceiver(Receiver recv) {
157.362 + boolean perform_close = false;
157.363 + synchronized (control_mutex) {
157.364 + if (recvslist.remove(recv)) {
157.365 + if (implicitOpen && recvslist.isEmpty())
157.366 + perform_close = true;
157.367 + }
157.368 + }
157.369 + if (perform_close)
157.370 + close();
157.371 + }
157.372 +
157.373 + protected SoftMainMixer getMainMixer() {
157.374 + if (!isOpen())
157.375 + return null;
157.376 + return mainmixer;
157.377 + }
157.378 +
157.379 + protected SoftInstrument findInstrument(int program, int bank, int channel) {
157.380 +
157.381 + // Add support for GM2 banks 0x78 and 0x79
157.382 + // as specified in DLS 2.2 in Section 1.4.6
157.383 + // which allows using percussion and melodic instruments
157.384 + // on all channels
157.385 + if (bank >> 7 == 0x78 || bank >> 7 == 0x79) {
157.386 + SoftInstrument current_instrument
157.387 + = inslist.get(program + "." + bank);
157.388 + if (current_instrument != null)
157.389 + return current_instrument;
157.390 +
157.391 + String p_plaf;
157.392 + if (bank >> 7 == 0x78)
157.393 + p_plaf = "p.";
157.394 + else
157.395 + p_plaf = "";
157.396 +
157.397 + // Instrument not found fallback to MSB:bank, LSB:0
157.398 + current_instrument = inslist.get(p_plaf + program + "."
157.399 + + ((bank & 128) << 7));
157.400 + if (current_instrument != null)
157.401 + return current_instrument;
157.402 + // Instrument not found fallback to MSB:0, LSB:bank
157.403 + current_instrument = inslist.get(p_plaf + program + "."
157.404 + + (bank & 128));
157.405 + if (current_instrument != null)
157.406 + return current_instrument;
157.407 + // Instrument not found fallback to MSB:0, LSB:0
157.408 + current_instrument = inslist.get(p_plaf + program + ".0");
157.409 + if (current_instrument != null)
157.410 + return current_instrument;
157.411 + // Instrument not found fallback to MSB:0, LSB:0, program=0
157.412 + current_instrument = inslist.get(p_plaf + program + "0.0");
157.413 + if (current_instrument != null)
157.414 + return current_instrument;
157.415 + return null;
157.416 + }
157.417 +
157.418 + // Channel 10 uses percussion instruments
157.419 + String p_plaf;
157.420 + if (channel == 9)
157.421 + p_plaf = "p.";
157.422 + else
157.423 + p_plaf = "";
157.424 +
157.425 + SoftInstrument current_instrument
157.426 + = inslist.get(p_plaf + program + "." + bank);
157.427 + if (current_instrument != null)
157.428 + return current_instrument;
157.429 + // Instrument not found fallback to MSB:0, LSB:0
157.430 + current_instrument = inslist.get(p_plaf + program + ".0");
157.431 + if (current_instrument != null)
157.432 + return current_instrument;
157.433 + // Instrument not found fallback to MSB:0, LSB:0, program=0
157.434 + current_instrument = inslist.get(p_plaf + "0.0");
157.435 + if (current_instrument != null)
157.436 + return current_instrument;
157.437 + return null;
157.438 + }
157.439 +
157.440 + protected int getVoiceAllocationMode() {
157.441 + return voice_allocation_mode;
157.442 + }
157.443 +
157.444 + protected int getGeneralMidiMode() {
157.445 + return gmmode;
157.446 + }
157.447 +
157.448 + protected void setGeneralMidiMode(int gmmode) {
157.449 + this.gmmode = gmmode;
157.450 + }
157.451 +
157.452 + protected int getDeviceID() {
157.453 + return deviceid;
157.454 + }
157.455 +
157.456 + protected float getControlRate() {
157.457 + return controlrate;
157.458 + }
157.459 +
157.460 + protected SoftVoice[] getVoices() {
157.461 + return voices;
157.462 + }
157.463 +
157.464 + protected SoftTuning getTuning(Patch patch) {
157.465 + String t_id = patchToString(patch);
157.466 + SoftTuning tuning = tunings.get(t_id);
157.467 + if (tuning == null) {
157.468 + tuning = new SoftTuning(patch);
157.469 + tunings.put(t_id, tuning);
157.470 + }
157.471 + return tuning;
157.472 + }
157.473 +
157.474 + public long getLatency() {
157.475 + synchronized (control_mutex) {
157.476 + return latency;
157.477 + }
157.478 + }
157.479 +
157.480 + public AudioFormat getFormat() {
157.481 + synchronized (control_mutex) {
157.482 + return format;
157.483 + }
157.484 + }
157.485 +
157.486 + public int getMaxPolyphony() {
157.487 + synchronized (control_mutex) {
157.488 + return maxpoly;
157.489 + }
157.490 + }
157.491 +
157.492 + public MidiChannel[] getChannels() {
157.493 +
157.494 + synchronized (control_mutex) {
157.495 + // if (external_channels == null) => the synthesizer is not open,
157.496 + // create 16 proxy channels
157.497 + // otherwise external_channels has the same length as channels array
157.498 + if (external_channels == null) {
157.499 + external_channels = new SoftChannelProxy[16];
157.500 + for (int i = 0; i < external_channels.length; i++)
157.501 + external_channels[i] = new SoftChannelProxy();
157.502 + }
157.503 + MidiChannel[] ret;
157.504 + if (isOpen())
157.505 + ret = new MidiChannel[channels.length];
157.506 + else
157.507 + ret = new MidiChannel[16];
157.508 + for (int i = 0; i < ret.length; i++)
157.509 + ret[i] = external_channels[i];
157.510 + return ret;
157.511 + }
157.512 + }
157.513 +
157.514 + public VoiceStatus[] getVoiceStatus() {
157.515 + if (!isOpen()) {
157.516 + VoiceStatus[] tempVoiceStatusArray
157.517 + = new VoiceStatus[getMaxPolyphony()];
157.518 + for (int i = 0; i < tempVoiceStatusArray.length; i++) {
157.519 + VoiceStatus b = new VoiceStatus();
157.520 + b.active = false;
157.521 + b.bank = 0;
157.522 + b.channel = 0;
157.523 + b.note = 0;
157.524 + b.program = 0;
157.525 + b.volume = 0;
157.526 + tempVoiceStatusArray[i] = b;
157.527 + }
157.528 + return tempVoiceStatusArray;
157.529 + }
157.530 +
157.531 + synchronized (control_mutex) {
157.532 + VoiceStatus[] tempVoiceStatusArray = new VoiceStatus[voices.length];
157.533 + for (int i = 0; i < voices.length; i++) {
157.534 + VoiceStatus a = voices[i];
157.535 + VoiceStatus b = new VoiceStatus();
157.536 + b.active = a.active;
157.537 + b.bank = a.bank;
157.538 + b.channel = a.channel;
157.539 + b.note = a.note;
157.540 + b.program = a.program;
157.541 + b.volume = a.volume;
157.542 + tempVoiceStatusArray[i] = b;
157.543 + }
157.544 + return tempVoiceStatusArray;
157.545 + }
157.546 + }
157.547 +
157.548 + public boolean isSoundbankSupported(Soundbank soundbank) {
157.549 + for (Instrument ins: soundbank.getInstruments())
157.550 + if (!(ins instanceof ModelInstrument))
157.551 + return false;
157.552 + return true;
157.553 + }
157.554 +
157.555 + public boolean loadInstrument(Instrument instrument) {
157.556 + if (instrument == null || (!(instrument instanceof ModelInstrument))) {
157.557 + throw new IllegalArgumentException("Unsupported instrument: " +
157.558 + instrument);
157.559 + }
157.560 + List<ModelInstrument> instruments = new ArrayList<ModelInstrument>();
157.561 + instruments.add((ModelInstrument)instrument);
157.562 + return loadInstruments(instruments);
157.563 + }
157.564 +
157.565 + public void unloadInstrument(Instrument instrument) {
157.566 + if (instrument == null || (!(instrument instanceof ModelInstrument))) {
157.567 + throw new IllegalArgumentException("Unsupported instrument: " +
157.568 + instrument);
157.569 + }
157.570 + if (!isOpen())
157.571 + return;
157.572 +
157.573 + String pat = patchToString(instrument.getPatch());
157.574 + synchronized (control_mutex) {
157.575 + for (SoftChannel c: channels)
157.576 + c.current_instrument = null;
157.577 + inslist.remove(pat);
157.578 + loadedlist.remove(pat);
157.579 + availlist.remove(pat);
157.580 + }
157.581 + }
157.582 +
157.583 + public boolean remapInstrument(Instrument from, Instrument to) {
157.584 +
157.585 + if (from == null)
157.586 + throw new NullPointerException();
157.587 + if (to == null)
157.588 + throw new NullPointerException();
157.589 + if (!(from instanceof ModelInstrument)) {
157.590 + throw new IllegalArgumentException("Unsupported instrument: " +
157.591 + from.toString());
157.592 + }
157.593 + if (!(to instanceof ModelInstrument)) {
157.594 + throw new IllegalArgumentException("Unsupported instrument: " +
157.595 + to.toString());
157.596 + }
157.597 + if (!isOpen())
157.598 + return false;
157.599 +
157.600 + synchronized (control_mutex) {
157.601 + if (!loadedlist.containsValue(to) && !availlist.containsValue(to))
157.602 + throw new IllegalArgumentException("Instrument to is not loaded.");
157.603 + unloadInstrument(from);
157.604 + ModelMappedInstrument mfrom = new ModelMappedInstrument(
157.605 + (ModelInstrument)to, from.getPatch());
157.606 + return loadInstrument(mfrom);
157.607 + }
157.608 + }
157.609 +
157.610 + public synchronized Soundbank getDefaultSoundbank() {
157.611 + if (defaultSoundBank == null) {
157.612 + try {
157.613 + File javahome = new File(System.getProperties().getProperty(
157.614 + "java.home"));
157.615 + File libaudio = new File(new File(javahome, "lib"), "audio");
157.616 +
157.617 + if (libaudio.exists()) {
157.618 + File foundfile = null;
157.619 + File[] files = libaudio.listFiles();
157.620 + if (files != null) {
157.621 + for (int i = 0; i < files.length; i++) {
157.622 + File file = files[i];
157.623 + if (file.isFile()) {
157.624 + String lname = file.getName().toLowerCase();
157.625 + if (lname.endsWith(".sf2") ||
157.626 + lname.endsWith(".dls")) {
157.627 + if (foundfile == null || (file.length() >
157.628 + foundfile.length())) {
157.629 + foundfile = file;
157.630 + }
157.631 + }
157.632 + }
157.633 + }
157.634 + }
157.635 + if (foundfile != null) {
157.636 + try {
157.637 + Soundbank sbk = MidiSystem.getSoundbank(foundfile);
157.638 + defaultSoundBank = sbk;
157.639 + return defaultSoundBank;
157.640 + } catch (Exception e) {
157.641 + //e.printStackTrace();
157.642 + }
157.643 + }
157.644 + }
157.645 +
157.646 + if (System.getProperties().getProperty("os.name")
157.647 + .startsWith("Windows")) {
157.648 + File gm_dls = new File(System.getenv("SystemRoot")
157.649 + + "\\system32\\drivers\\gm.dls");
157.650 + if (gm_dls.exists()) {
157.651 + try {
157.652 + Soundbank sbk = MidiSystem.getSoundbank(gm_dls);
157.653 + defaultSoundBank = sbk;
157.654 + return defaultSoundBank;
157.655 + } catch (Exception e) {
157.656 + //e.printStackTrace();
157.657 + }
157.658 + }
157.659 + }
157.660 + } catch (AccessControlException e) {
157.661 + } catch (Exception e) {
157.662 + //e.printStackTrace();
157.663 + }
157.664 +
157.665 + File userhome = null;
157.666 + File emg_soundbank_file = null;
157.667 +
157.668 + /*
157.669 + * Try to load saved generated soundbank
157.670 + */
157.671 + try {
157.672 + userhome = new File(System.getProperty("user.home"),
157.673 + ".gervill");
157.674 + emg_soundbank_file = new File(userhome, "soundbank-emg.sf2");
157.675 + Soundbank sbk = MidiSystem.getSoundbank(emg_soundbank_file);
157.676 + defaultSoundBank = sbk;
157.677 + return defaultSoundBank;
157.678 + } catch (AccessControlException e) {
157.679 + } catch (Exception e) {
157.680 + //e.printStackTrace();
157.681 + }
157.682 +
157.683 + try {
157.684 +
157.685 + /*
157.686 + * Generate emergency soundbank
157.687 + */
157.688 + defaultSoundBank = EmergencySoundbank.createSoundbank();
157.689 +
157.690 + /*
157.691 + * Save generated soundbank to disk for faster future use.
157.692 + */
157.693 + if(defaultSoundBank != null)
157.694 + {
157.695 + if(!userhome.exists()) userhome.mkdirs();
157.696 + if(!emg_soundbank_file.exists())
157.697 + ((SF2Soundbank)defaultSoundBank).save(emg_soundbank_file);
157.698 + }
157.699 + } catch (Exception e) {
157.700 + //e.printStackTrace();
157.701 + }
157.702 +
157.703 + }
157.704 + return defaultSoundBank;
157.705 + }
157.706 +
157.707 + public Instrument[] getAvailableInstruments() {
157.708 + if (!isOpen()) {
157.709 + Soundbank defsbk = getDefaultSoundbank();
157.710 + if (defsbk == null)
157.711 + return new Instrument[0];
157.712 + return defsbk.getInstruments();
157.713 + }
157.714 +
157.715 + synchronized (control_mutex) {
157.716 + ModelInstrument[] inslist_array =
157.717 + new ModelInstrument[availlist.values().size()];
157.718 + availlist.values().toArray(inslist_array);
157.719 + Arrays.sort(inslist_array, new ModelInstrumentComparator());
157.720 + return inslist_array;
157.721 + }
157.722 + }
157.723 +
157.724 + public Instrument[] getLoadedInstruments() {
157.725 + if (!isOpen())
157.726 + return new Instrument[0];
157.727 +
157.728 + synchronized (control_mutex) {
157.729 + ModelInstrument[] inslist_array =
157.730 + new ModelInstrument[loadedlist.values().size()];
157.731 + loadedlist.values().toArray(inslist_array);
157.732 + Arrays.sort(inslist_array, new ModelInstrumentComparator());
157.733 + return inslist_array;
157.734 + }
157.735 + }
157.736 +
157.737 + public boolean loadAllInstruments(Soundbank soundbank) {
157.738 + List<ModelInstrument> instruments = new ArrayList<ModelInstrument>();
157.739 + for (Instrument ins: soundbank.getInstruments()) {
157.740 + if (ins == null || !(ins instanceof ModelInstrument)) {
157.741 + throw new IllegalArgumentException(
157.742 + "Unsupported instrument: " + ins);
157.743 + }
157.744 + instruments.add((ModelInstrument)ins);
157.745 + }
157.746 + return loadInstruments(instruments);
157.747 + }
157.748 +
157.749 + public void unloadAllInstruments(Soundbank soundbank) {
157.750 + if (soundbank == null || !isSoundbankSupported(soundbank))
157.751 + throw new IllegalArgumentException("Unsupported soundbank: " + soundbank);
157.752 +
157.753 + if (!isOpen())
157.754 + return;
157.755 +
157.756 + for (Instrument ins: soundbank.getInstruments()) {
157.757 + if (ins instanceof ModelInstrument) {
157.758 + unloadInstrument(ins);
157.759 + }
157.760 + }
157.761 + }
157.762 +
157.763 + public boolean loadInstruments(Soundbank soundbank, Patch[] patchList) {
157.764 + List<ModelInstrument> instruments = new ArrayList<ModelInstrument>();
157.765 + for (Patch patch: patchList) {
157.766 + Instrument ins = soundbank.getInstrument(patch);
157.767 + if (ins == null || !(ins instanceof ModelInstrument)) {
157.768 + throw new IllegalArgumentException(
157.769 + "Unsupported instrument: " + ins);
157.770 + }
157.771 + instruments.add((ModelInstrument)ins);
157.772 + }
157.773 + return loadInstruments(instruments);
157.774 + }
157.775 +
157.776 + public void unloadInstruments(Soundbank soundbank, Patch[] patchList) {
157.777 + if (soundbank == null || !isSoundbankSupported(soundbank))
157.778 + throw new IllegalArgumentException("Unsupported soundbank: " + soundbank);
157.779 +
157.780 + if (!isOpen())
157.781 + return;
157.782 +
157.783 + for (Patch pat: patchList) {
157.784 + Instrument ins = soundbank.getInstrument(pat);
157.785 + if (ins instanceof ModelInstrument) {
157.786 + unloadInstrument(ins);
157.787 + }
157.788 + }
157.789 + }
157.790 +
157.791 + public MidiDevice.Info getDeviceInfo() {
157.792 + return info;
157.793 + }
157.794 +
157.795 + public AudioSynthesizerPropertyInfo[] getPropertyInfo(Map<String, Object> info) {
157.796 + List<AudioSynthesizerPropertyInfo> list =
157.797 + new ArrayList<AudioSynthesizerPropertyInfo>();
157.798 +
157.799 + AudioSynthesizerPropertyInfo item;
157.800 +
157.801 + // If info != null or synthesizer is closed
157.802 + // we return how the synthesizer will be set on next open
157.803 + // If info == null and synthesizer is open
157.804 + // we return current synthesizer properties.
157.805 + boolean o = info == null && open;
157.806 +
157.807 + item = new AudioSynthesizerPropertyInfo("interpolation", o?resamplerType:"linear");
157.808 + item.choices = new String[]{"linear", "linear1", "linear2", "cubic",
157.809 + "lanczos", "sinc", "point"};
157.810 + item.description = "Interpolation method";
157.811 + list.add(item);
157.812 +
157.813 + item = new AudioSynthesizerPropertyInfo("control rate", o?controlrate:147f);
157.814 + item.description = "Control rate";
157.815 + list.add(item);
157.816 +
157.817 + item = new AudioSynthesizerPropertyInfo("format",
157.818 + o?format:new AudioFormat(44100, 16, 2, true, false));
157.819 + item.description = "Default audio format";
157.820 + list.add(item);
157.821 +
157.822 + item = new AudioSynthesizerPropertyInfo("latency", o?latency:120000L);
157.823 + item.description = "Default latency";
157.824 + list.add(item);
157.825 +
157.826 + item = new AudioSynthesizerPropertyInfo("device id", o?deviceid:0);
157.827 + item.description = "Device ID for SysEx Messages";
157.828 + list.add(item);
157.829 +
157.830 + item = new AudioSynthesizerPropertyInfo("max polyphony", o?maxpoly:64);
157.831 + item.description = "Maximum polyphony";
157.832 + list.add(item);
157.833 +
157.834 + item = new AudioSynthesizerPropertyInfo("reverb", o?reverb_on:true);
157.835 + item.description = "Turn reverb effect on or off";
157.836 + list.add(item);
157.837 +
157.838 + item = new AudioSynthesizerPropertyInfo("chorus", o?chorus_on:true);
157.839 + item.description = "Turn chorus effect on or off";
157.840 + list.add(item);
157.841 +
157.842 + item = new AudioSynthesizerPropertyInfo("auto gain control", o?agc_on:true);
157.843 + item.description = "Turn auto gain control on or off";
157.844 + list.add(item);
157.845 +
157.846 + item = new AudioSynthesizerPropertyInfo("large mode", o?largemode:false);
157.847 + item.description = "Turn large mode on or off.";
157.848 + list.add(item);
157.849 +
157.850 + item = new AudioSynthesizerPropertyInfo("midi channels", o?channels.length:16);
157.851 + item.description = "Number of midi channels.";
157.852 + list.add(item);
157.853 +
157.854 + item = new AudioSynthesizerPropertyInfo("jitter correction", o?jitter_correction:true);
157.855 + item.description = "Turn jitter correction on or off.";
157.856 + list.add(item);
157.857 +
157.858 + item = new AudioSynthesizerPropertyInfo("light reverb", o?reverb_light:true);
157.859 + item.description = "Turn light reverb mode on or off";
157.860 + list.add(item);
157.861 +
157.862 + AudioSynthesizerPropertyInfo[] items;
157.863 + items = list.toArray(new AudioSynthesizerPropertyInfo[list.size()]);
157.864 +
157.865 + if (info != null)
157.866 + for (AudioSynthesizerPropertyInfo item2: items) {
157.867 + Object v = info.get(item2.name);
157.868 + Class c = (item2.valueClass);
157.869 + if (v != null)
157.870 + if (c.isInstance(v))
157.871 + item2.value = v;
157.872 + }
157.873 +
157.874 + return items;
157.875 + }
157.876 +
157.877 + public void open() throws MidiUnavailableException {
157.878 + if (isOpen()) {
157.879 + synchronized (control_mutex) {
157.880 + implicitOpen = false;
157.881 + }
157.882 + return;
157.883 + }
157.884 + open(null, null);
157.885 + }
157.886 +
157.887 + public void open(SourceDataLine line, Map<String, Object> info) throws MidiUnavailableException {
157.888 + if (isOpen()) {
157.889 + synchronized (control_mutex) {
157.890 + implicitOpen = false;
157.891 + }
157.892 + return;
157.893 + }
157.894 + synchronized (control_mutex) {
157.895 + try {
157.896 + if (line != null)
157.897 + setFormat(line.getFormat());
157.898 +
157.899 + AudioInputStream ais = openStream(getFormat(), info);
157.900 +
157.901 + weakstream = new WeakAudioStream(ais);
157.902 + ais = weakstream.getAudioInputStream();
157.903 +
157.904 + if (line == null)
157.905 + {
157.906 + if(testline != null)
157.907 + line = testline;
157.908 + else
157.909 + line = AudioSystem.getSourceDataLine(getFormat());
157.910 + }
157.911 +
157.912 + double latency = this.latency;
157.913 +
157.914 + if (!line.isOpen()) {
157.915 + int bufferSize = getFormat().getFrameSize()
157.916 + * (int)(getFormat().getFrameRate() * (latency/1000000f));
157.917 + line.open(getFormat(), bufferSize);
157.918 +
157.919 + // Remember that we opened that line
157.920 + // so we can close again in SoftSynthesizer.close()
157.921 + sourceDataLine = line;
157.922 + }
157.923 + if (!line.isActive())
157.924 + line.start();
157.925 +
157.926 + int controlbuffersize = 512;
157.927 + try {
157.928 + controlbuffersize = ais.available();
157.929 + } catch (IOException e) {
157.930 + }
157.931 +
157.932 + // Tell mixer not fill read buffers fully.
157.933 + // This lowers latency, and tells DataPusher
157.934 + // to read in smaller amounts.
157.935 + //mainmixer.readfully = false;
157.936 + //pusher = new DataPusher(line, ais);
157.937 +
157.938 + int buffersize = line.getBufferSize();
157.939 + buffersize -= buffersize % controlbuffersize;
157.940 +
157.941 + if (buffersize < 3 * controlbuffersize)
157.942 + buffersize = 3 * controlbuffersize;
157.943 +
157.944 + if (jitter_correction) {
157.945 + ais = new SoftJitterCorrector(ais, buffersize,
157.946 + controlbuffersize);
157.947 + if(weakstream != null)
157.948 + weakstream.jitter_stream = ais;
157.949 + }
157.950 + pusher = new SoftAudioPusher(line, ais, controlbuffersize);
157.951 + pusher_stream = ais;
157.952 + pusher.start();
157.953 +
157.954 + if(weakstream != null)
157.955 + {
157.956 + weakstream.pusher = pusher;
157.957 + weakstream.sourceDataLine = sourceDataLine;
157.958 + }
157.959 +
157.960 +
157.961 +
157.962 + } catch (LineUnavailableException e) {
157.963 + if (isOpen())
157.964 + close();
157.965 + // am: need MidiUnavailableException(Throwable) ctor!
157.966 + throw new MidiUnavailableException(e.toString());
157.967 + }
157.968 +
157.969 + }
157.970 + }
157.971 +
157.972 + public AudioInputStream openStream(AudioFormat targetFormat,
157.973 + Map<String, Object> info) throws MidiUnavailableException {
157.974 +
157.975 + if (isOpen())
157.976 + throw new MidiUnavailableException("Synthesizer is already open");
157.977 +
157.978 + synchronized (control_mutex) {
157.979 +
157.980 + gmmode = 0;
157.981 + voice_allocation_mode = 0;
157.982 +
157.983 + processPropertyInfo(info);
157.984 +
157.985 + open = true;
157.986 + implicitOpen = false;
157.987 +
157.988 + if (targetFormat != null)
157.989 + setFormat(targetFormat);
157.990 +
157.991 + Soundbank defbank = getDefaultSoundbank();
157.992 + if (defbank != null) {
157.993 + loadAllInstruments(defbank);
157.994 + availlist.putAll(loadedlist);
157.995 + loadedlist.clear();
157.996 + }
157.997 +
157.998 + voices = new SoftVoice[maxpoly];
157.999 + for (int i = 0; i < maxpoly; i++)
157.1000 + voices[i] = new SoftVoice(this);
157.1001 +
157.1002 + mainmixer = new SoftMainMixer(this);
157.1003 +
157.1004 + channels = new SoftChannel[number_of_midi_channels];
157.1005 + for (int i = 0; i < channels.length; i++)
157.1006 + channels[i] = new SoftChannel(this, i);
157.1007 +
157.1008 + if (external_channels == null) {
157.1009 + // Always create external_channels array
157.1010 + // with 16 or more channels
157.1011 + // so getChannels works correctly
157.1012 + // when the synhtesizer is closed.
157.1013 + if (channels.length < 16)
157.1014 + external_channels = new SoftChannelProxy[16];
157.1015 + else
157.1016 + external_channels = new SoftChannelProxy[channels.length];
157.1017 + for (int i = 0; i < external_channels.length; i++)
157.1018 + external_channels[i] = new SoftChannelProxy();
157.1019 + } else {
157.1020 + // We must resize external_channels array
157.1021 + // but we must also copy the old SoftChannelProxy
157.1022 + // into the new one
157.1023 + if (channels.length > external_channels.length) {
157.1024 + SoftChannelProxy[] new_external_channels
157.1025 + = new SoftChannelProxy[channels.length];
157.1026 + for (int i = 0; i < external_channels.length; i++)
157.1027 + new_external_channels[i] = external_channels[i];
157.1028 + for (int i = external_channels.length;
157.1029 + i < new_external_channels.length; i++) {
157.1030 + new_external_channels[i] = new SoftChannelProxy();
157.1031 + }
157.1032 + }
157.1033 + }
157.1034 +
157.1035 + for (int i = 0; i < channels.length; i++)
157.1036 + external_channels[i].setChannel(channels[i]);
157.1037 +
157.1038 + for (SoftVoice voice: getVoices())
157.1039 + voice.resampler = resampler.openStreamer();
157.1040 +
157.1041 + for (Receiver recv: getReceivers()) {
157.1042 + SoftReceiver srecv = ((SoftReceiver)recv);
157.1043 + srecv.open = open;
157.1044 + srecv.mainmixer = mainmixer;
157.1045 + srecv.midimessages = mainmixer.midimessages;
157.1046 + }
157.1047 +
157.1048 + return mainmixer.getInputStream();
157.1049 + }
157.1050 + }
157.1051 +
157.1052 + public void close() {
157.1053 +
157.1054 + if (!isOpen())
157.1055 + return;
157.1056 +
157.1057 + SoftAudioPusher pusher_to_be_closed = null;
157.1058 + AudioInputStream pusher_stream_to_be_closed = null;
157.1059 + synchronized (control_mutex) {
157.1060 + if (pusher != null) {
157.1061 + pusher_to_be_closed = pusher;
157.1062 + pusher_stream_to_be_closed = pusher_stream;
157.1063 + pusher = null;
157.1064 + pusher_stream = null;
157.1065 + }
157.1066 + }
157.1067 +
157.1068 + if (pusher_to_be_closed != null) {
157.1069 + // Pusher must not be closed synchronized against control_mutex,
157.1070 + // this may result in synchronized conflict between pusher
157.1071 + // and current thread.
157.1072 + pusher_to_be_closed.stop();
157.1073 +
157.1074 + try {
157.1075 + pusher_stream_to_be_closed.close();
157.1076 + } catch (IOException e) {
157.1077 + //e.printStackTrace();
157.1078 + }
157.1079 + }
157.1080 +
157.1081 + synchronized (control_mutex) {
157.1082 +
157.1083 + if (mainmixer != null)
157.1084 + mainmixer.close();
157.1085 + open = false;
157.1086 + implicitOpen = false;
157.1087 + mainmixer = null;
157.1088 + voices = null;
157.1089 + channels = null;
157.1090 +
157.1091 + if (external_channels != null)
157.1092 + for (int i = 0; i < external_channels.length; i++)
157.1093 + external_channels[i].setChannel(null);
157.1094 +
157.1095 + if (sourceDataLine != null) {
157.1096 + sourceDataLine.close();
157.1097 + sourceDataLine = null;
157.1098 + }
157.1099 +
157.1100 + inslist.clear();
157.1101 + availlist.clear();
157.1102 + loadedlist.clear();
157.1103 + tunings.clear();
157.1104 +
157.1105 + while (recvslist.size() != 0)
157.1106 + recvslist.get(recvslist.size() - 1).close();
157.1107 +
157.1108 + }
157.1109 + }
157.1110 +
157.1111 + public boolean isOpen() {
157.1112 + synchronized (control_mutex) {
157.1113 + return open;
157.1114 + }
157.1115 + }
157.1116 +
157.1117 + public long getMicrosecondPosition() {
157.1118 +
157.1119 + if (!isOpen())
157.1120 + return 0;
157.1121 +
157.1122 + synchronized (control_mutex) {
157.1123 + return mainmixer.getMicrosecondPosition();
157.1124 + }
157.1125 + }
157.1126 +
157.1127 + public int getMaxReceivers() {
157.1128 + return -1;
157.1129 + }
157.1130 +
157.1131 + public int getMaxTransmitters() {
157.1132 + return 0;
157.1133 + }
157.1134 +
157.1135 + public Receiver getReceiver() throws MidiUnavailableException {
157.1136 +
157.1137 + synchronized (control_mutex) {
157.1138 + SoftReceiver receiver = new SoftReceiver(this);
157.1139 + receiver.open = open;
157.1140 + recvslist.add(receiver);
157.1141 + return receiver;
157.1142 + }
157.1143 + }
157.1144 +
157.1145 + public List<Receiver> getReceivers() {
157.1146 +
157.1147 + synchronized (control_mutex) {
157.1148 + ArrayList<Receiver> recvs = new ArrayList<Receiver>();
157.1149 + recvs.addAll(recvslist);
157.1150 + return recvs;
157.1151 + }
157.1152 + }
157.1153 +
157.1154 + public Transmitter getTransmitter() throws MidiUnavailableException {
157.1155 +
157.1156 + throw new MidiUnavailableException("No transmitter available");
157.1157 + }
157.1158 +
157.1159 + public List<Transmitter> getTransmitters() {
157.1160 +
157.1161 + return new ArrayList<Transmitter>();
157.1162 + }
157.1163 +
157.1164 + public Receiver getReceiverReferenceCounting()
157.1165 + throws MidiUnavailableException {
157.1166 +
157.1167 + if (!isOpen()) {
157.1168 + open();
157.1169 + synchronized (control_mutex) {
157.1170 + implicitOpen = true;
157.1171 + }
157.1172 + }
157.1173 +
157.1174 + return getReceiver();
157.1175 + }
157.1176 +
157.1177 + public Transmitter getTransmitterReferenceCounting()
157.1178 + throws MidiUnavailableException {
157.1179 +
157.1180 + throw new MidiUnavailableException("No transmitter available");
157.1181 + }
157.1182 +}
158.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
158.2 +++ b/src/share/classes/com/sun/media/sound/SoftTuning.java Tue Feb 03 22:02:55 2009 -0800
158.3 @@ -0,0 +1,256 @@
158.4 +/*
158.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
158.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
158.7 + *
158.8 + * This code is free software; you can redistribute it and/or modify it
158.9 + * under the terms of the GNU General Public License version 2 only, as
158.10 + * published by the Free Software Foundation. Sun designates this
158.11 + * particular file as subject to the "Classpath" exception as provided
158.12 + * by Sun in the LICENSE file that accompanied this code.
158.13 + *
158.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
158.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
158.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
158.17 + * version 2 for more details (a copy is included in the LICENSE file that
158.18 + * accompanied this code).
158.19 + *
158.20 + * You should have received a copy of the GNU General Public License version
158.21 + * 2 along with this work; if not, write to the Free Software Foundation,
158.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
158.23 + *
158.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
158.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
158.26 + * have any questions.
158.27 + */
158.28 +package com.sun.media.sound;
158.29 +
158.30 +import java.io.UnsupportedEncodingException;
158.31 +
158.32 +import javax.sound.midi.Patch;
158.33 +
158.34 +/**
158.35 + * A tuning program container, for use with MIDI Tuning.
158.36 + * See: http://www.midi.org
158.37 + *
158.38 + * @author Karl Helgason
158.39 + */
158.40 +public class SoftTuning {
158.41 +
158.42 + private String name = null;
158.43 + private double[] tuning = new double[128];
158.44 + private Patch patch = null;
158.45 +
158.46 + public SoftTuning() {
158.47 + name = "12-TET";
158.48 + for (int i = 0; i < tuning.length; i++)
158.49 + tuning[i] = i * 100;
158.50 + }
158.51 +
158.52 + public SoftTuning(byte[] data) {
158.53 + for (int i = 0; i < tuning.length; i++)
158.54 + tuning[i] = i * 100;
158.55 + load(data);
158.56 + }
158.57 +
158.58 + public SoftTuning(Patch patch) {
158.59 + this.patch = patch;
158.60 + name = "12-TET";
158.61 + for (int i = 0; i < tuning.length; i++)
158.62 + tuning[i] = i * 100;
158.63 + }
158.64 +
158.65 + public SoftTuning(Patch patch, byte[] data) {
158.66 + this.patch = patch;
158.67 + for (int i = 0; i < tuning.length; i++)
158.68 + tuning[i] = i * 100;
158.69 + load(data);
158.70 + }
158.71 +
158.72 + private boolean checksumOK(byte[] data) {
158.73 + int x = data[1] & 0xFF;
158.74 + for (int i = 2; i < data.length - 2; i++)
158.75 + x = x ^ (data[i] & 0xFF);
158.76 + return (data[data.length - 2] & 0xFF) == (x & 127);
158.77 + }
158.78 +
158.79 + /*
158.80 + private boolean checksumOK2(byte[] data) {
158.81 + int x = data[1] & 0xFF; // 7E
158.82 + x = x ^ (data[2] & 0xFF); // <device ID>
158.83 + x = x ^ (data[4] & 0xFF); // nn
158.84 + x = x ^ (data[5] & 0xFF); // tt
158.85 + for (int i = 22; i < data.length - 2; i++)
158.86 + x = x ^ (data[i] & 0xFF);
158.87 + return (data[data.length - 2] & 0xFF) == (x & 127);
158.88 + }
158.89 + */
158.90 + public void load(byte[] data) {
158.91 + // Universal Non-Real-Time / Real-Time SysEx
158.92 + if ((data[1] & 0xFF) == 0x7E || (data[1] & 0xFF) == 0x7F) {
158.93 + int subid1 = data[3] & 0xFF;
158.94 + switch (subid1) {
158.95 + case 0x08: // MIDI Tuning Standard
158.96 + int subid2 = data[4] & 0xFF;
158.97 + switch (subid2) {
158.98 + case 0x01: // BULK TUNING DUMP (NON-REAL-TIME)
158.99 + {
158.100 + // http://www.midi.org/about-midi/tuning.shtml
158.101 + //if (!checksumOK2(data))
158.102 + // break;
158.103 + try {
158.104 + name = new String(data, 6, 16, "ascii");
158.105 + } catch (UnsupportedEncodingException e) {
158.106 + name = null;
158.107 + }
158.108 + int r = 22;
158.109 + for (int i = 0; i < 128; i++) {
158.110 + int xx = data[r++] & 0xFF;
158.111 + int yy = data[r++] & 0xFF;
158.112 + int zz = data[r++] & 0xFF;
158.113 + if (!(xx == 127 && yy == 127 && zz == 127))
158.114 + tuning[i] = 100.0 *
158.115 + (((xx * 16384) + (yy * 128) + zz) / 16384.0);
158.116 + }
158.117 + break;
158.118 + }
158.119 + case 0x02: // SINGLE NOTE TUNING CHANGE (REAL-TIME)
158.120 + {
158.121 + // http://www.midi.org/about-midi/tuning.shtml
158.122 + int ll = data[6] & 0xFF;
158.123 + int r = 7;
158.124 + for (int i = 0; i < ll; i++) {
158.125 + int kk = data[r++] & 0xFF;
158.126 + int xx = data[r++] & 0xFF;
158.127 + int yy = data[r++] & 0xFF;
158.128 + int zz = data[r++] & 0xFF;
158.129 + if (!(xx == 127 && yy == 127 && zz == 127))
158.130 + tuning[kk] = 100.0*(((xx*16384) + (yy*128) + zz)/16384.0);
158.131 + }
158.132 + break;
158.133 + }
158.134 + case 0x04: // KEY-BASED TUNING DUMP (NON-REAL-TIME)
158.135 + {
158.136 + // http://www.midi.org/about-midi/tuning_extens.shtml
158.137 + if (!checksumOK(data))
158.138 + break;
158.139 + try {
158.140 + name = new String(data, 7, 16, "ascii");
158.141 + } catch (UnsupportedEncodingException e) {
158.142 + name = null;
158.143 + }
158.144 + int r = 23;
158.145 + for (int i = 0; i < 128; i++) {
158.146 + int xx = data[r++] & 0xFF;
158.147 + int yy = data[r++] & 0xFF;
158.148 + int zz = data[r++] & 0xFF;
158.149 + if (!(xx == 127 && yy == 127 && zz == 127))
158.150 + tuning[i] = 100.0*(((xx*16384) + (yy*128) + zz)/16384.0);
158.151 + }
158.152 + break;
158.153 + }
158.154 + case 0x05: // SCALE/OCTAVE TUNING DUMP, 1 byte format
158.155 + // (NON-REAL-TIME)
158.156 + {
158.157 + // http://www.midi.org/about-midi/tuning_extens.shtml
158.158 + if (!checksumOK(data))
158.159 + break;
158.160 + try {
158.161 + name = new String(data, 7, 16, "ascii");
158.162 + } catch (UnsupportedEncodingException e) {
158.163 + name = null;
158.164 + }
158.165 + int[] octave_tuning = new int[12];
158.166 + for (int i = 0; i < 12; i++)
158.167 + octave_tuning[i] = (data[i + 23] & 0xFF) - 64;
158.168 + for (int i = 0; i < tuning.length; i++)
158.169 + tuning[i] = i * 100 + octave_tuning[i % 12];
158.170 + break;
158.171 + }
158.172 + case 0x06: // SCALE/OCTAVE TUNING DUMP, 2 byte format
158.173 + // (NON-REAL-TIME)
158.174 + {
158.175 + // http://www.midi.org/about-midi/tuning_extens.shtml
158.176 + if (!checksumOK(data))
158.177 + break;
158.178 + try {
158.179 + name = new String(data, 7, 16, "ascii");
158.180 + } catch (UnsupportedEncodingException e) {
158.181 + name = null;
158.182 + }
158.183 + double[] octave_tuning = new double[12];
158.184 + for (int i = 0; i < 12; i++) {
158.185 + int v = (data[i * 2 + 23] & 0xFF) * 128
158.186 + + (data[i * 2 + 24] & 0xFF);
158.187 + octave_tuning[i] = (v / 8192.0 - 1) * 100.0;
158.188 + }
158.189 + for (int i = 0; i < tuning.length; i++)
158.190 + tuning[i] = i * 100 + octave_tuning[i % 12];
158.191 + break;
158.192 + }
158.193 + case 0x07: // SINGLE NOTE TUNING CHANGE (NON
158.194 + // REAL-TIME/REAL-TIME) (BANK)
158.195 + // http://www.midi.org/about-midi/tuning_extens.shtml
158.196 + int ll = data[7] & 0xFF;
158.197 + int r = 8;
158.198 + for (int i = 0; i < ll; i++) {
158.199 + int kk = data[r++] & 0xFF;
158.200 + int xx = data[r++] & 0xFF;
158.201 + int yy = data[r++] & 0xFF;
158.202 + int zz = data[r++] & 0xFF;
158.203 + if (!(xx == 127 && yy == 127 && zz == 127))
158.204 + tuning[kk] = 100.0
158.205 + * (((xx*16384) + (yy*128) + zz) / 16384.0);
158.206 + }
158.207 + break;
158.208 + case 0x08: // scale/octave tuning 1-byte form (Non
158.209 + // Real-Time/REAL-TIME)
158.210 + {
158.211 + // http://www.midi.org/about-midi/tuning-scale.shtml
158.212 + int[] octave_tuning = new int[12];
158.213 + for (int i = 0; i < 12; i++)
158.214 + octave_tuning[i] = (data[i + 8] & 0xFF) - 64;
158.215 + for (int i = 0; i < tuning.length; i++)
158.216 + tuning[i] = i * 100 + octave_tuning[i % 12];
158.217 + break;
158.218 + }
158.219 + case 0x09: // scale/octave tuning 2-byte form (Non
158.220 + // Real-Time/REAL-TIME)
158.221 + {
158.222 + // http://www.midi.org/about-midi/tuning-scale.shtml
158.223 + double[] octave_tuning = new double[12];
158.224 + for (int i = 0; i < 12; i++) {
158.225 + int v = (data[i * 2 + 8] & 0xFF) * 128
158.226 + + (data[i * 2 + 9] & 0xFF);
158.227 + octave_tuning[i] = (v / 8192.0 - 1) * 100.0;
158.228 + }
158.229 + for (int i = 0; i < tuning.length; i++)
158.230 + tuning[i] = i * 100 + octave_tuning[i % 12];
158.231 + break;
158.232 + }
158.233 + default:
158.234 + break;
158.235 + }
158.236 + }
158.237 + }
158.238 + }
158.239 +
158.240 + public double[] getTuning() {
158.241 + return tuning;
158.242 + }
158.243 +
158.244 + public double getTuning(int noteNumber) {
158.245 + return tuning[noteNumber];
158.246 + }
158.247 +
158.248 + public Patch getPatch() {
158.249 + return patch;
158.250 + }
158.251 +
158.252 + public String getName() {
158.253 + return name;
158.254 + }
158.255 +
158.256 + public void setName(String name) {
158.257 + this.name = name;
158.258 + }
158.259 +}
159.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
159.2 +++ b/src/share/classes/com/sun/media/sound/SoftVoice.java Tue Feb 03 22:02:55 2009 -0800
159.3 @@ -0,0 +1,841 @@
159.4 +/*
159.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
159.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
159.7 + *
159.8 + * This code is free software; you can redistribute it and/or modify it
159.9 + * under the terms of the GNU General Public License version 2 only, as
159.10 + * published by the Free Software Foundation. Sun designates this
159.11 + * particular file as subject to the "Classpath" exception as provided
159.12 + * by Sun in the LICENSE file that accompanied this code.
159.13 + *
159.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
159.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
159.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
159.17 + * version 2 for more details (a copy is included in the LICENSE file that
159.18 + * accompanied this code).
159.19 + *
159.20 + * You should have received a copy of the GNU General Public License version
159.21 + * 2 along with this work; if not, write to the Free Software Foundation,
159.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
159.23 + *
159.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
159.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
159.26 + * have any questions.
159.27 + */
159.28 +package com.sun.media.sound;
159.29 +
159.30 +import java.io.IOException;
159.31 +import java.util.Arrays;
159.32 +import java.util.HashMap;
159.33 +import java.util.Map;
159.34 +
159.35 +import javax.sound.midi.VoiceStatus;
159.36 +
159.37 +/**
159.38 + * Software synthesizer voice class.
159.39 + *
159.40 + * @author Karl Helgason
159.41 + */
159.42 +public class SoftVoice extends VoiceStatus {
159.43 +
159.44 + public int exclusiveClass = 0;
159.45 + public boolean releaseTriggered = false;
159.46 + private int noteOn_noteNumber = 0;
159.47 + private int noteOn_velocity = 0;
159.48 + private int noteOff_velocity = 0;
159.49 + protected ModelChannelMixer channelmixer = null;
159.50 + protected double tunedKey = 0;
159.51 + protected SoftTuning tuning = null;
159.52 + protected SoftChannel stealer_channel = null;
159.53 + protected ModelConnectionBlock[] stealer_extendedConnectionBlocks = null;
159.54 + protected SoftPerformer stealer_performer = null;
159.55 + protected ModelChannelMixer stealer_channelmixer = null;
159.56 + protected int stealer_voiceID = -1;
159.57 + protected int stealer_noteNumber = 0;
159.58 + protected int stealer_velocity = 0;
159.59 + protected boolean stealer_releaseTriggered = false;
159.60 + protected int voiceID = -1;
159.61 + protected boolean sustain = false;
159.62 + protected boolean sostenuto = false;
159.63 + protected boolean portamento = false;
159.64 + private SoftFilter filter_left;
159.65 + private SoftFilter filter_right;
159.66 + private SoftProcess eg = new SoftEnvelopeGenerator();
159.67 + private SoftProcess lfo = new SoftLowFrequencyOscillator();
159.68 + protected Map<String, SoftControl> objects =
159.69 + new HashMap<String, SoftControl>();
159.70 + protected SoftSynthesizer synthesizer;
159.71 + protected SoftInstrument instrument;
159.72 + protected SoftPerformer performer;
159.73 + protected SoftChannel softchannel = null;
159.74 + protected boolean on = false;
159.75 + private boolean audiostarted = false;
159.76 + private boolean started = false;
159.77 + private boolean stopping = false;
159.78 + private float osc_attenuation = 0.0f;
159.79 + private ModelOscillatorStream osc_stream;
159.80 + private int osc_stream_nrofchannels;
159.81 + private float[][] osc_buff = new float[2][];
159.82 + private boolean osc_stream_off_transmitted = false;
159.83 + private boolean out_mixer_end = false;
159.84 + private float out_mixer_left = 0;
159.85 + private float out_mixer_right = 0;
159.86 + private float out_mixer_effect1 = 0;
159.87 + private float out_mixer_effect2 = 0;
159.88 + private float last_out_mixer_left = 0;
159.89 + private float last_out_mixer_right = 0;
159.90 + private float last_out_mixer_effect1 = 0;
159.91 + private float last_out_mixer_effect2 = 0;
159.92 + protected ModelConnectionBlock[] extendedConnectionBlocks = null;
159.93 + private ModelConnectionBlock[] connections;
159.94 + // Last value added to destination
159.95 + private double[] connections_last = new double[50];
159.96 + // Pointer to source value
159.97 + private double[][][] connections_src = new double[50][3][];
159.98 + // Key-based override (if any)
159.99 + private int[][] connections_src_kc = new int[50][3];
159.100 + // Pointer to destination value
159.101 + private double[][] connections_dst = new double[50][];
159.102 + private boolean soundoff = false;
159.103 + private float lastMuteValue = 0;
159.104 + private float lastSoloMuteValue = 0;
159.105 + protected double[] co_noteon_keynumber = new double[1];
159.106 + protected double[] co_noteon_velocity = new double[1];
159.107 + protected double[] co_noteon_on = new double[1];
159.108 + private SoftControl co_noteon = new SoftControl() {
159.109 + double[] keynumber = co_noteon_keynumber;
159.110 + double[] velocity = co_noteon_velocity;
159.111 + double[] on = co_noteon_on;
159.112 + public double[] get(int instance, String name) {
159.113 + if (name == null)
159.114 + return null;
159.115 + if (name.equals("keynumber"))
159.116 + return keynumber;
159.117 + if (name.equals("velocity"))
159.118 + return velocity;
159.119 + if (name.equals("on"))
159.120 + return on;
159.121 + return null;
159.122 + }
159.123 + };
159.124 + private double[] co_mixer_active = new double[1];
159.125 + private double[] co_mixer_gain = new double[1];
159.126 + private double[] co_mixer_pan = new double[1];
159.127 + private double[] co_mixer_balance = new double[1];
159.128 + private double[] co_mixer_reverb = new double[1];
159.129 + private double[] co_mixer_chorus = new double[1];
159.130 + private SoftControl co_mixer = new SoftControl() {
159.131 + double[] active = co_mixer_active;
159.132 + double[] gain = co_mixer_gain;
159.133 + double[] pan = co_mixer_pan;
159.134 + double[] balance = co_mixer_balance;
159.135 + double[] reverb = co_mixer_reverb;
159.136 + double[] chorus = co_mixer_chorus;
159.137 + public double[] get(int instance, String name) {
159.138 + if (name == null)
159.139 + return null;
159.140 + if (name.equals("active"))
159.141 + return active;
159.142 + if (name.equals("gain"))
159.143 + return gain;
159.144 + if (name.equals("pan"))
159.145 + return pan;
159.146 + if (name.equals("balance"))
159.147 + return balance;
159.148 + if (name.equals("reverb"))
159.149 + return reverb;
159.150 + if (name.equals("chorus"))
159.151 + return chorus;
159.152 + return null;
159.153 + }
159.154 + };
159.155 + private double[] co_osc_pitch = new double[1];
159.156 + private SoftControl co_osc = new SoftControl() {
159.157 + double[] pitch = co_osc_pitch;
159.158 + public double[] get(int instance, String name) {
159.159 + if (name == null)
159.160 + return null;
159.161 + if (name.equals("pitch"))
159.162 + return pitch;
159.163 + return null;
159.164 + }
159.165 + };
159.166 + private double[] co_filter_freq = new double[1];
159.167 + private double[] co_filter_type = new double[1];
159.168 + private double[] co_filter_q = new double[1];
159.169 + private SoftControl co_filter = new SoftControl() {
159.170 + double[] freq = co_filter_freq;
159.171 + double[] ftype = co_filter_type;
159.172 + double[] q = co_filter_q;
159.173 + public double[] get(int instance, String name) {
159.174 + if (name == null)
159.175 + return null;
159.176 + if (name.equals("freq"))
159.177 + return freq;
159.178 + if (name.equals("type"))
159.179 + return ftype;
159.180 + if (name.equals("q"))
159.181 + return q;
159.182 + return null;
159.183 + }
159.184 + };
159.185 + protected SoftResamplerStreamer resampler;
159.186 + private int nrofchannels;
159.187 +
159.188 + public SoftVoice(SoftSynthesizer synth) {
159.189 + synthesizer = synth;
159.190 + filter_left = new SoftFilter(synth.getFormat().getSampleRate());
159.191 + filter_right = new SoftFilter(synth.getFormat().getSampleRate());
159.192 + nrofchannels = synth.getFormat().getChannels();
159.193 + }
159.194 +
159.195 + private int getValueKC(ModelIdentifier id) {
159.196 + if (id.getObject().equals("midi_cc")) {
159.197 + int ic = Integer.parseInt(id.getVariable());
159.198 + if (ic != 0 && ic != 32) {
159.199 + if (ic < 120)
159.200 + return ic;
159.201 + }
159.202 + } else if (id.getObject().equals("midi_rpn")) {
159.203 + if (id.getVariable().equals("1"))
159.204 + return 120; // Fine tuning
159.205 + if (id.getVariable().equals("2"))
159.206 + return 121; // Coarse tuning
159.207 + }
159.208 + return -1;
159.209 + }
159.210 +
159.211 + private double[] getValue(ModelIdentifier id) {
159.212 + SoftControl o = objects.get(id.getObject());
159.213 + if (o == null)
159.214 + return null;
159.215 + return o.get(id.getInstance(), id.getVariable());
159.216 + }
159.217 +
159.218 + private double transformValue(double value, ModelSource src) {
159.219 + if (src.getTransform() != null)
159.220 + return src.getTransform().transform(value);
159.221 + else
159.222 + return value;
159.223 + }
159.224 +
159.225 + private double transformValue(double value, ModelDestination dst) {
159.226 + if (dst.getTransform() != null)
159.227 + return dst.getTransform().transform(value);
159.228 + else
159.229 + return value;
159.230 + }
159.231 +
159.232 + private double processKeyBasedController(double value, int keycontrol) {
159.233 + if (keycontrol == -1)
159.234 + return value;
159.235 + if (softchannel.keybasedcontroller_active != null)
159.236 + if (softchannel.keybasedcontroller_active[note] != null)
159.237 + if (softchannel.keybasedcontroller_active[note][keycontrol]) {
159.238 + double key_controlvalue =
159.239 + softchannel.keybasedcontroller_value[note][keycontrol];
159.240 + if (keycontrol == 10 || keycontrol == 91 || keycontrol == 93)
159.241 + return key_controlvalue;
159.242 + value += key_controlvalue * 2.0 - 1.0;
159.243 + if (value > 1)
159.244 + value = 1;
159.245 + else if (value < 0)
159.246 + value = 0;
159.247 + }
159.248 + return value;
159.249 + }
159.250 +
159.251 + private void processConnection(int ix) {
159.252 + ModelConnectionBlock conn = connections[ix];
159.253 + double[][] src = connections_src[ix];
159.254 + double[] dst = connections_dst[ix];
159.255 + if (dst == null || Double.isInfinite(dst[0]))
159.256 + return;
159.257 +
159.258 + double value = conn.getScale();
159.259 + if (softchannel.keybasedcontroller_active == null) {
159.260 + ModelSource[] srcs = conn.getSources();
159.261 + for (int i = 0; i < srcs.length; i++) {
159.262 + value *= transformValue(src[i][0], srcs[i]);
159.263 + if (value == 0)
159.264 + break;
159.265 + }
159.266 + } else {
159.267 + ModelSource[] srcs = conn.getSources();
159.268 + int[] src_kc = connections_src_kc[ix];
159.269 + for (int i = 0; i < srcs.length; i++) {
159.270 + value *= transformValue(processKeyBasedController(src[i][0],
159.271 + src_kc[i]), srcs[i]);
159.272 + if (value == 0)
159.273 + break;
159.274 + }
159.275 + }
159.276 +
159.277 + value = transformValue(value, conn.getDestination());
159.278 + dst[0] = dst[0] - connections_last[ix] + value;
159.279 + connections_last[ix] = value;
159.280 + // co_mixer_gain[0] = 0;
159.281 + }
159.282 +
159.283 + protected void updateTuning(SoftTuning newtuning) {
159.284 + tunedKey = tuning.getTuning(note) / 100.0;
159.285 + if (!portamento) {
159.286 + co_noteon_keynumber[0] = tunedKey * (1.0 / 128.0);
159.287 + int[] c = performer.midi_connections[4];
159.288 + if (c == null)
159.289 + return;
159.290 + for (int i = 0; i < c.length; i++)
159.291 + processConnection(c[i]);
159.292 + }
159.293 + }
159.294 +
159.295 + protected void setNote(int noteNumber) {
159.296 + note = noteNumber;
159.297 + tunedKey = tuning.getTuning(noteNumber) / 100.0;
159.298 + }
159.299 +
159.300 + protected void noteOn(int noteNumber, int velocity) {
159.301 +
159.302 + sustain = false;
159.303 + sostenuto = false;
159.304 + portamento = false;
159.305 +
159.306 + soundoff = false;
159.307 + on = true;
159.308 + active = true;
159.309 + started = true;
159.310 + // volume = velocity;
159.311 +
159.312 + noteOn_noteNumber = noteNumber;
159.313 + noteOn_velocity = velocity;
159.314 +
159.315 + lastMuteValue = 0;
159.316 + lastSoloMuteValue = 0;
159.317 +
159.318 + setNote(noteNumber);
159.319 +
159.320 + if (performer.forcedKeynumber)
159.321 + co_noteon_keynumber[0] = 0;
159.322 + else
159.323 + co_noteon_keynumber[0] = tunedKey * (1f / 128f);
159.324 + if (performer.forcedVelocity)
159.325 + co_noteon_velocity[0] = 0;
159.326 + else
159.327 + co_noteon_velocity[0] = velocity * (1f / 128f);
159.328 + co_mixer_active[0] = 0;
159.329 + co_mixer_gain[0] = 0;
159.330 + co_mixer_pan[0] = 0;
159.331 + co_mixer_balance[0] = 0;
159.332 + co_mixer_reverb[0] = 0;
159.333 + co_mixer_chorus[0] = 0;
159.334 + co_osc_pitch[0] = 0;
159.335 + co_filter_freq[0] = 0;
159.336 + co_filter_q[0] = 0;
159.337 + co_filter_type[0] = 0;
159.338 + co_noteon_on[0] = 1;
159.339 +
159.340 + eg.reset();
159.341 + lfo.reset();
159.342 + filter_left.reset();
159.343 + filter_right.reset();
159.344 +
159.345 + objects.put("master", synthesizer.getMainMixer().co_master);
159.346 + objects.put("eg", eg);
159.347 + objects.put("lfo", lfo);
159.348 + objects.put("noteon", co_noteon);
159.349 + objects.put("osc", co_osc);
159.350 + objects.put("mixer", co_mixer);
159.351 + objects.put("filter", co_filter);
159.352 +
159.353 + connections = performer.connections;
159.354 +
159.355 + if (connections_last == null
159.356 + || connections_last.length < connections.length) {
159.357 + connections_last = new double[connections.length];
159.358 + }
159.359 + if (connections_src == null
159.360 + || connections_src.length < connections.length) {
159.361 + connections_src = new double[connections.length][][];
159.362 + connections_src_kc = new int[connections.length][];
159.363 + }
159.364 + if (connections_dst == null
159.365 + || connections_dst.length < connections.length) {
159.366 + connections_dst = new double[connections.length][];
159.367 + }
159.368 + for (int i = 0; i < connections.length; i++) {
159.369 + ModelConnectionBlock conn = connections[i];
159.370 + connections_last[i] = 0;
159.371 + if (conn.getSources() != null) {
159.372 + ModelSource[] srcs = conn.getSources();
159.373 + if (connections_src[i] == null
159.374 + || connections_src[i].length < srcs.length) {
159.375 + connections_src[i] = new double[srcs.length][];
159.376 + connections_src_kc[i] = new int[srcs.length];
159.377 + }
159.378 + double[][] src = connections_src[i];
159.379 + int[] src_kc = connections_src_kc[i];
159.380 + connections_src[i] = src;
159.381 + for (int j = 0; j < srcs.length; j++) {
159.382 + src_kc[j] = getValueKC(srcs[j].getIdentifier());
159.383 + src[j] = getValue(srcs[j].getIdentifier());
159.384 + }
159.385 + }
159.386 +
159.387 + if (conn.getDestination() != null)
159.388 + connections_dst[i] = getValue(conn.getDestination()
159.389 + .getIdentifier());
159.390 + else
159.391 + connections_dst[i] = null;
159.392 + }
159.393 +
159.394 + for (int i = 0; i < connections.length; i++)
159.395 + processConnection(i);
159.396 +
159.397 + if (extendedConnectionBlocks != null) {
159.398 + for (ModelConnectionBlock connection: extendedConnectionBlocks) {
159.399 + double value = 0;
159.400 +
159.401 + if (softchannel.keybasedcontroller_active == null) {
159.402 + for (ModelSource src: connection.getSources()) {
159.403 + double x = getValue(src.getIdentifier())[0];
159.404 + ModelTransform t = src.getTransform();
159.405 + if (t == null)
159.406 + value += x;
159.407 + else
159.408 + value += t.transform(x);
159.409 + }
159.410 + } else {
159.411 + for (ModelSource src: connection.getSources()) {
159.412 + double x = getValue(src.getIdentifier())[0];
159.413 + x = processKeyBasedController(x,
159.414 + getValueKC(src.getIdentifier()));
159.415 + ModelTransform t = src.getTransform();
159.416 + if (t == null)
159.417 + value += x;
159.418 + else
159.419 + value += t.transform(x);
159.420 + }
159.421 + }
159.422 +
159.423 + ModelDestination dest = connection.getDestination();
159.424 + ModelTransform t = dest.getTransform();
159.425 + if (t != null)
159.426 + value = t.transform(value);
159.427 + getValue(dest.getIdentifier())[0] += value;
159.428 + }
159.429 + }
159.430 +
159.431 + eg.init(synthesizer);
159.432 + lfo.init(synthesizer);
159.433 +
159.434 + }
159.435 +
159.436 + protected void setPolyPressure(int pressure) {
159.437 + int[] c = performer.midi_connections[2];
159.438 + if (c == null)
159.439 + return;
159.440 + for (int i = 0; i < c.length; i++)
159.441 + processConnection(c[i]);
159.442 + }
159.443 +
159.444 + protected void setChannelPressure(int pressure) {
159.445 + int[] c = performer.midi_connections[1];
159.446 + if (c == null)
159.447 + return;
159.448 + for (int i = 0; i < c.length; i++)
159.449 + processConnection(c[i]);
159.450 + }
159.451 +
159.452 + protected void controlChange(int controller, int value) {
159.453 + int[] c = performer.midi_ctrl_connections[controller];
159.454 + if (c == null)
159.455 + return;
159.456 + for (int i = 0; i < c.length; i++)
159.457 + processConnection(c[i]);
159.458 + }
159.459 +
159.460 + protected void nrpnChange(int controller, int value) {
159.461 + int[] c = performer.midi_nrpn_connections.get(controller);
159.462 + if (c == null)
159.463 + return;
159.464 + for (int i = 0; i < c.length; i++)
159.465 + processConnection(c[i]);
159.466 + }
159.467 +
159.468 + protected void rpnChange(int controller, int value) {
159.469 + int[] c = performer.midi_rpn_connections.get(controller);
159.470 + if (c == null)
159.471 + return;
159.472 + for (int i = 0; i < c.length; i++)
159.473 + processConnection(c[i]);
159.474 + }
159.475 +
159.476 + protected void setPitchBend(int bend) {
159.477 + int[] c = performer.midi_connections[0];
159.478 + if (c == null)
159.479 + return;
159.480 + for (int i = 0; i < c.length; i++)
159.481 + processConnection(c[i]);
159.482 + }
159.483 +
159.484 + protected void setMute(boolean mute) {
159.485 + co_mixer_gain[0] -= lastMuteValue;
159.486 + lastMuteValue = mute ? -960 : 0;
159.487 + co_mixer_gain[0] += lastMuteValue;
159.488 + }
159.489 +
159.490 + protected void setSoloMute(boolean mute) {
159.491 + co_mixer_gain[0] -= lastSoloMuteValue;
159.492 + lastSoloMuteValue = mute ? -960 : 0;
159.493 + co_mixer_gain[0] += lastSoloMuteValue;
159.494 + }
159.495 +
159.496 + protected void shutdown() {
159.497 + if (co_noteon_on[0] < -0.5)
159.498 + return;
159.499 + on = false;
159.500 +
159.501 + co_noteon_on[0] = -1;
159.502 +
159.503 + int[] c = performer.midi_connections[3];
159.504 + if (c == null)
159.505 + return;
159.506 + for (int i = 0; i < c.length; i++)
159.507 + processConnection(c[i]);
159.508 + }
159.509 +
159.510 + protected void soundOff() {
159.511 + on = false;
159.512 + soundoff = true;
159.513 + }
159.514 +
159.515 + protected void noteOff(int velocity) {
159.516 + if (!on)
159.517 + return;
159.518 + on = false;
159.519 +
159.520 + noteOff_velocity = velocity;
159.521 +
159.522 + if (softchannel.sustain) {
159.523 + sustain = true;
159.524 + return;
159.525 + }
159.526 + if (sostenuto)
159.527 + return;
159.528 +
159.529 + co_noteon_on[0] = 0;
159.530 +
159.531 + int[] c = performer.midi_connections[3];
159.532 + if (c == null)
159.533 + return;
159.534 + for (int i = 0; i < c.length; i++)
159.535 + processConnection(c[i]);
159.536 + }
159.537 +
159.538 + protected void redamp() {
159.539 + if (co_noteon_on[0] > 0.5)
159.540 + return;
159.541 + if (co_noteon_on[0] < -0.5)
159.542 + return; // don't redamp notes in shutdown stage
159.543 +
159.544 + sustain = true;
159.545 + co_noteon_on[0] = 1;
159.546 +
159.547 + int[] c = performer.midi_connections[3];
159.548 + if (c == null)
159.549 + return;
159.550 + for (int i = 0; i < c.length; i++)
159.551 + processConnection(c[i]);
159.552 + }
159.553 +
159.554 + protected void processControlLogic() {
159.555 + if (stopping) {
159.556 + active = false;
159.557 + stopping = false;
159.558 + audiostarted = false;
159.559 + if (osc_stream != null)
159.560 + try {
159.561 + osc_stream.close();
159.562 + } catch (IOException e) {
159.563 + //e.printStackTrace();
159.564 + }
159.565 +
159.566 + if (stealer_channel != null) {
159.567 + stealer_channel.initVoice(this, stealer_performer,
159.568 + stealer_voiceID, stealer_noteNumber, stealer_velocity,
159.569 + stealer_extendedConnectionBlocks, stealer_channelmixer,
159.570 + stealer_releaseTriggered);
159.571 + stealer_releaseTriggered = false;
159.572 + stealer_channel = null;
159.573 + stealer_performer = null;
159.574 + stealer_voiceID = -1;
159.575 + stealer_noteNumber = 0;
159.576 + stealer_velocity = 0;
159.577 + stealer_extendedConnectionBlocks = null;
159.578 + stealer_channelmixer = null;
159.579 + }
159.580 + }
159.581 + if (started) {
159.582 + audiostarted = true;
159.583 +
159.584 + ModelOscillator osc = performer.oscillators[0];
159.585 +
159.586 + osc_stream_off_transmitted = false;
159.587 + if (osc instanceof ModelWavetable) {
159.588 + try {
159.589 + resampler.open((ModelWavetable)osc,
159.590 + synthesizer.getFormat().getSampleRate());
159.591 + osc_stream = resampler;
159.592 + } catch (IOException e) {
159.593 + //e.printStackTrace();
159.594 + }
159.595 + } else {
159.596 + osc_stream = osc.open(synthesizer.getFormat().getSampleRate());
159.597 + }
159.598 + osc_attenuation = osc.getAttenuation();
159.599 + osc_stream_nrofchannels = osc.getChannels();
159.600 + if (osc_buff == null || osc_buff.length < osc_stream_nrofchannels)
159.601 + osc_buff = new float[osc_stream_nrofchannels][];
159.602 +
159.603 + if (osc_stream != null)
159.604 + osc_stream.noteOn(softchannel, this, noteOn_noteNumber,
159.605 + noteOn_velocity);
159.606 +
159.607 +
159.608 + }
159.609 + if (audiostarted) {
159.610 + if (portamento) {
159.611 + double note_delta = tunedKey - (co_noteon_keynumber[0] * 128);
159.612 + double note_delta_a = Math.abs(note_delta);
159.613 + if (note_delta_a < 0.0000000001) {
159.614 + co_noteon_keynumber[0] = tunedKey * (1.0 / 128.0);
159.615 + portamento = false;
159.616 + } else {
159.617 + if (note_delta_a > softchannel.portamento_time)
159.618 + note_delta = Math.signum(note_delta)
159.619 + * softchannel.portamento_time;
159.620 + co_noteon_keynumber[0] += note_delta * (1.0 / 128.0);
159.621 + }
159.622 +
159.623 + int[] c = performer.midi_connections[4];
159.624 + if (c == null)
159.625 + return;
159.626 + for (int i = 0; i < c.length; i++)
159.627 + processConnection(c[i]);
159.628 + }
159.629 +
159.630 + eg.processControlLogic();
159.631 + lfo.processControlLogic();
159.632 +
159.633 + for (int i = 0; i < performer.ctrl_connections.length; i++)
159.634 + processConnection(performer.ctrl_connections[i]);
159.635 +
159.636 + osc_stream.setPitch((float)co_osc_pitch[0]);
159.637 +
159.638 + int filter_type = (int)co_filter_type[0];
159.639 + double filter_freq;
159.640 +
159.641 + if (co_filter_freq[0] == 13500.0)
159.642 + filter_freq = 19912.126958213175;
159.643 + else
159.644 + filter_freq = 440.0 * Math.exp(
159.645 + ((co_filter_freq[0]) - 6900.0) *
159.646 + (Math.log(2.0) / 1200.0));
159.647 + /*
159.648 + filter_freq = 440.0 * Math.pow(2.0,
159.649 + ((co_filter_freq[0]) - 6900.0) / 1200.0);*/
159.650 + /*
159.651 + * double velocity = co_noteon_velocity[0]; if(velocity < 0.5)
159.652 + * filter_freq *= ((velocity * 2)*0.75 + 0.25);
159.653 + */
159.654 +
159.655 + double q = co_filter_q[0] / 10.0;
159.656 + filter_left.setFilterType(filter_type);
159.657 + filter_left.setFrequency(filter_freq);
159.658 + filter_left.setResonance(q);
159.659 + filter_right.setFilterType(filter_type);
159.660 + filter_right.setFrequency(filter_freq);
159.661 + filter_right.setResonance(q);
159.662 + /*
159.663 + float gain = (float) Math.pow(10,
159.664 + (-osc_attenuation + co_mixer_gain[0]) / 200.0);
159.665 + */
159.666 + float gain = (float)Math.exp(
159.667 + (-osc_attenuation + co_mixer_gain[0])*(Math.log(10) / 200.0));
159.668 +
159.669 + if (co_mixer_gain[0] <= -960)
159.670 + gain = 0;
159.671 +
159.672 + if (soundoff) {
159.673 + stopping = true;
159.674 + gain = 0;
159.675 + /*
159.676 + * if(co_mixer_gain[0] > -960)
159.677 + * co_mixer_gain[0] -= 960;
159.678 + */
159.679 + }
159.680 +
159.681 + volume = (int)(Math.sqrt(gain) * 128);
159.682 +
159.683 + // gain *= 0.2;
159.684 +
159.685 + double pan = co_mixer_pan[0] * (1.0 / 1000.0);
159.686 + // System.out.println("pan = " + pan);
159.687 + if (pan < 0)
159.688 + pan = 0;
159.689 + else if (pan > 1)
159.690 + pan = 1;
159.691 +
159.692 + if (pan == 0.5) {
159.693 + out_mixer_left = gain * 0.7071067811865476f;
159.694 + out_mixer_right = out_mixer_left;
159.695 + } else {
159.696 + out_mixer_left = gain * (float)Math.cos(pan * Math.PI * 0.5);
159.697 + out_mixer_right = gain * (float)Math.sin(pan * Math.PI * 0.5);
159.698 + }
159.699 +
159.700 + double balance = co_mixer_balance[0] * (1.0 / 1000.0);
159.701 + if (balance != 0.5) {
159.702 + if (balance > 0.5)
159.703 + out_mixer_left *= (1 - balance) * 2;
159.704 + else
159.705 + out_mixer_right *= balance * 2;
159.706 + }
159.707 +
159.708 + if (synthesizer.reverb_on) {
159.709 + out_mixer_effect1 = (float)(co_mixer_reverb[0] * (1.0 / 1000.0));
159.710 + out_mixer_effect1 *= gain;
159.711 + } else
159.712 + out_mixer_effect1 = 0;
159.713 + if (synthesizer.chorus_on) {
159.714 + out_mixer_effect2 = (float)(co_mixer_chorus[0] * (1.0 / 1000.0));
159.715 + out_mixer_effect2 *= gain;
159.716 + } else
159.717 + out_mixer_effect2 = 0;
159.718 + out_mixer_end = co_mixer_active[0] < 0.5;
159.719 +
159.720 + if (!on)
159.721 + if (!osc_stream_off_transmitted) {
159.722 + osc_stream_off_transmitted = true;
159.723 + if (osc_stream != null)
159.724 + osc_stream.noteOff(noteOff_velocity);
159.725 + }
159.726 +
159.727 + }
159.728 + if (started) {
159.729 + last_out_mixer_left = out_mixer_left;
159.730 + last_out_mixer_right = out_mixer_right;
159.731 + last_out_mixer_effect1 = out_mixer_effect1;
159.732 + last_out_mixer_effect2 = out_mixer_effect2;
159.733 + started = false;
159.734 + }
159.735 +
159.736 + }
159.737 +
159.738 + protected void mixAudioStream(SoftAudioBuffer in, SoftAudioBuffer out,
159.739 + float amp_from, float amp_to) {
159.740 + int bufferlen = in.getSize();
159.741 + if (amp_from < 0.000000001 && amp_to < 0.000000001)
159.742 + return;
159.743 + if (amp_from == amp_to) {
159.744 + float[] fout = out.array();
159.745 + float[] fin = in.array();
159.746 + for (int i = 0; i < bufferlen; i++)
159.747 + fout[i] += fin[i] * amp_to;
159.748 + } else {
159.749 + float amp = amp_from;
159.750 + float amp_delta = (amp_to - amp_from) / bufferlen;
159.751 + float[] fout = out.array();
159.752 + float[] fin = in.array();
159.753 + for (int i = 0; i < bufferlen; i++) {
159.754 + amp += amp_delta;
159.755 + fout[i] += fin[i] * amp;
159.756 + }
159.757 + }
159.758 +
159.759 + }
159.760 +
159.761 + protected void processAudioLogic(SoftAudioBuffer[] buffer) {
159.762 + if (!audiostarted)
159.763 + return;
159.764 +
159.765 + int bufferlen = buffer[0].getSize();
159.766 +
159.767 + try {
159.768 + osc_buff[0] = buffer[SoftMainMixer.CHANNEL_LEFT_DRY].array();
159.769 + if (nrofchannels != 1)
159.770 + osc_buff[1] = buffer[SoftMainMixer.CHANNEL_RIGHT_DRY].array();
159.771 + int ret = osc_stream.read(osc_buff, 0, bufferlen);
159.772 + if (ret == -1) {
159.773 + stopping = true;
159.774 + return;
159.775 + }
159.776 + if (ret != bufferlen) {
159.777 + Arrays.fill(osc_buff[0], ret, bufferlen, 0f);
159.778 + if (nrofchannels != 1)
159.779 + Arrays.fill(osc_buff[1], ret, bufferlen, 0f);
159.780 + }
159.781 +
159.782 + } catch (IOException e) {
159.783 + //e.printStackTrace();
159.784 + }
159.785 +
159.786 + SoftAudioBuffer left = buffer[SoftMainMixer.CHANNEL_LEFT];
159.787 + SoftAudioBuffer right = buffer[SoftMainMixer.CHANNEL_RIGHT];
159.788 + SoftAudioBuffer eff1 = buffer[SoftMainMixer.CHANNEL_EFFECT1];
159.789 + SoftAudioBuffer eff2 = buffer[SoftMainMixer.CHANNEL_EFFECT2];
159.790 + SoftAudioBuffer leftdry = buffer[SoftMainMixer.CHANNEL_LEFT_DRY];
159.791 + SoftAudioBuffer rightdry = buffer[SoftMainMixer.CHANNEL_RIGHT_DRY];
159.792 +
159.793 + if (osc_stream_nrofchannels == 1)
159.794 + rightdry = null;
159.795 +
159.796 + if (!Double.isInfinite(co_filter_freq[0])) {
159.797 + filter_left.processAudio(leftdry);
159.798 + if (rightdry != null)
159.799 + filter_right.processAudio(rightdry);
159.800 + }
159.801 +
159.802 + if (nrofchannels == 1) {
159.803 + out_mixer_left = (out_mixer_left + out_mixer_right) / 2;
159.804 + mixAudioStream(leftdry, left, last_out_mixer_left, out_mixer_left);
159.805 + if (rightdry != null)
159.806 + mixAudioStream(rightdry, left, last_out_mixer_left,
159.807 + out_mixer_left);
159.808 + } else {
159.809 + mixAudioStream(leftdry, left, last_out_mixer_left, out_mixer_left);
159.810 + if (rightdry != null)
159.811 + mixAudioStream(rightdry, right, last_out_mixer_right,
159.812 + out_mixer_right);
159.813 + else
159.814 + mixAudioStream(leftdry, right, last_out_mixer_right,
159.815 + out_mixer_right);
159.816 + }
159.817 +
159.818 + if (rightdry == null) {
159.819 + mixAudioStream(leftdry, eff1, last_out_mixer_effect1,
159.820 + out_mixer_effect1);
159.821 + mixAudioStream(leftdry, eff2, last_out_mixer_effect2,
159.822 + out_mixer_effect2);
159.823 + } else {
159.824 + mixAudioStream(leftdry, eff1, last_out_mixer_effect1 * 0.5f,
159.825 + out_mixer_effect1 * 0.5f);
159.826 + mixAudioStream(leftdry, eff2, last_out_mixer_effect2 * 0.5f,
159.827 + out_mixer_effect2 * 0.5f);
159.828 + mixAudioStream(rightdry, eff1, last_out_mixer_effect1 * 0.5f,
159.829 + out_mixer_effect1 * 0.5f);
159.830 + mixAudioStream(rightdry, eff2, last_out_mixer_effect2 * 0.5f,
159.831 + out_mixer_effect2 * 0.5f);
159.832 + }
159.833 +
159.834 + last_out_mixer_left = out_mixer_left;
159.835 + last_out_mixer_right = out_mixer_right;
159.836 + last_out_mixer_effect1 = out_mixer_effect1;
159.837 + last_out_mixer_effect2 = out_mixer_effect2;
159.838 +
159.839 + if (out_mixer_end) {
159.840 + stopping = true;
159.841 + }
159.842 +
159.843 + }
159.844 +}
160.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
160.2 +++ b/src/share/classes/com/sun/media/sound/WaveExtensibleFileReader.java Tue Feb 03 22:02:55 2009 -0800
160.3 @@ -0,0 +1,339 @@
160.4 +/*
160.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
160.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
160.7 + *
160.8 + * This code is free software; you can redistribute it and/or modify it
160.9 + * under the terms of the GNU General Public License version 2 only, as
160.10 + * published by the Free Software Foundation. Sun designates this
160.11 + * particular file as subject to the "Classpath" exception as provided
160.12 + * by Sun in the LICENSE file that accompanied this code.
160.13 + *
160.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
160.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
160.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
160.17 + * version 2 for more details (a copy is included in the LICENSE file that
160.18 + * accompanied this code).
160.19 + *
160.20 + * You should have received a copy of the GNU General Public License version
160.21 + * 2 along with this work; if not, write to the Free Software Foundation,
160.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
160.23 + *
160.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
160.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
160.26 + * have any questions.
160.27 + */
160.28 +package com.sun.media.sound;
160.29 +
160.30 +import java.io.BufferedInputStream;
160.31 +import java.io.File;
160.32 +import java.io.FileInputStream;
160.33 +import java.io.IOException;
160.34 +import java.io.InputStream;
160.35 +import java.net.URL;
160.36 +import java.util.HashMap;
160.37 +import java.util.Map;
160.38 +
160.39 +import javax.sound.sampled.AudioFileFormat;
160.40 +import javax.sound.sampled.AudioFormat;
160.41 +import javax.sound.sampled.AudioInputStream;
160.42 +import javax.sound.sampled.AudioSystem;
160.43 +import javax.sound.sampled.UnsupportedAudioFileException;
160.44 +import javax.sound.sampled.AudioFormat.Encoding;
160.45 +import javax.sound.sampled.spi.AudioFileReader;
160.46 +
160.47 +/**
160.48 + * WAVE file reader for files using format WAVE_FORMAT_EXTENSIBLE (0xFFFE).
160.49 + *
160.50 + * @author Karl Helgason
160.51 + */
160.52 +public class WaveExtensibleFileReader extends AudioFileReader {
160.53 +
160.54 + static private class GUID {
160.55 + long i1;
160.56 +
160.57 + int s1;
160.58 +
160.59 + int s2;
160.60 +
160.61 + int x1;
160.62 +
160.63 + int x2;
160.64 +
160.65 + int x3;
160.66 +
160.67 + int x4;
160.68 +
160.69 + int x5;
160.70 +
160.71 + int x6;
160.72 +
160.73 + int x7;
160.74 +
160.75 + int x8;
160.76 +
160.77 + private GUID() {
160.78 + }
160.79 +
160.80 + public GUID(long i1, int s1, int s2, int x1, int x2, int x3, int x4,
160.81 + int x5, int x6, int x7, int x8) {
160.82 + this.i1 = i1;
160.83 + this.s1 = s1;
160.84 + this.s2 = s2;
160.85 + this.x1 = x1;
160.86 + this.x2 = x2;
160.87 + this.x3 = x3;
160.88 + this.x4 = x4;
160.89 + this.x5 = x5;
160.90 + this.x6 = x6;
160.91 + this.x7 = x7;
160.92 + this.x8 = x8;
160.93 + }
160.94 +
160.95 + public static GUID read(RIFFReader riff) throws IOException {
160.96 + GUID d = new GUID();
160.97 + d.i1 = riff.readUnsignedInt();
160.98 + d.s1 = riff.readUnsignedShort();
160.99 + d.s2 = riff.readUnsignedShort();
160.100 + d.x1 = riff.readUnsignedByte();
160.101 + d.x2 = riff.readUnsignedByte();
160.102 + d.x3 = riff.readUnsignedByte();
160.103 + d.x4 = riff.readUnsignedByte();
160.104 + d.x5 = riff.readUnsignedByte();
160.105 + d.x6 = riff.readUnsignedByte();
160.106 + d.x7 = riff.readUnsignedByte();
160.107 + d.x8 = riff.readUnsignedByte();
160.108 + return d;
160.109 + }
160.110 +
160.111 + public int hashCode() {
160.112 + return (int) i1;
160.113 + }
160.114 +
160.115 + public boolean equals(Object obj) {
160.116 + if (!(obj instanceof GUID))
160.117 + return false;
160.118 + GUID t = (GUID) obj;
160.119 + if (i1 != t.i1)
160.120 + return false;
160.121 + if (s1 != t.s1)
160.122 + return false;
160.123 + if (s2 != t.s2)
160.124 + return false;
160.125 + if (x1 != t.x1)
160.126 + return false;
160.127 + if (x2 != t.x2)
160.128 + return false;
160.129 + if (x3 != t.x3)
160.130 + return false;
160.131 + if (x4 != t.x4)
160.132 + return false;
160.133 + if (x5 != t.x5)
160.134 + return false;
160.135 + if (x6 != t.x6)
160.136 + return false;
160.137 + if (x7 != t.x7)
160.138 + return false;
160.139 + if (x8 != t.x8)
160.140 + return false;
160.141 + return true;
160.142 + }
160.143 +
160.144 + }
160.145 +
160.146 + private static String[] channelnames = { "FL", "FR", "FC", "LF",
160.147 + "BL",
160.148 + "BR", // 5.1
160.149 + "FLC", "FLR", "BC", "SL", "SR", "TC", "TFL", "TFC", "TFR", "TBL",
160.150 + "TBC", "TBR" };
160.151 +
160.152 + private static String[] allchannelnames = { "w1", "w2", "w3", "w4", "w5",
160.153 + "w6", "w7", "w8", "w9", "w10", "w11", "w12", "w13", "w14", "w15",
160.154 + "w16", "w17", "w18", "w19", "w20", "w21", "w22", "w23", "w24",
160.155 + "w25", "w26", "w27", "w28", "w29", "w30", "w31", "w32", "w33",
160.156 + "w34", "w35", "w36", "w37", "w38", "w39", "w40", "w41", "w42",
160.157 + "w43", "w44", "w45", "w46", "w47", "w48", "w49", "w50", "w51",
160.158 + "w52", "w53", "w54", "w55", "w56", "w57", "w58", "w59", "w60",
160.159 + "w61", "w62", "w63", "w64" };
160.160 +
160.161 + private static GUID SUBTYPE_PCM = new GUID(0x00000001, 0x0000, 0x0010,
160.162 + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71);
160.163 +
160.164 + private static GUID SUBTYPE_IEEE_FLOAT = new GUID(0x00000003, 0x0000,
160.165 + 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71);
160.166 +
160.167 + private String decodeChannelMask(long channelmask) {
160.168 + StringBuffer sb = new StringBuffer();
160.169 + long m = 1;
160.170 + for (int i = 0; i < allchannelnames.length; i++) {
160.171 + if ((channelmask & m) != 0L) {
160.172 + if (i < channelnames.length) {
160.173 + sb.append(channelnames[i] + " ");
160.174 + } else {
160.175 + sb.append(allchannelnames[i] + " ");
160.176 + }
160.177 + }
160.178 + m *= 2L;
160.179 + }
160.180 + if (sb.length() == 0)
160.181 + return null;
160.182 + return sb.substring(0, sb.length() - 1);
160.183 +
160.184 + }
160.185 +
160.186 + public AudioFileFormat getAudioFileFormat(InputStream stream)
160.187 + throws UnsupportedAudioFileException, IOException {
160.188 +
160.189 + stream.mark(200);
160.190 + AudioFileFormat format;
160.191 + try {
160.192 + format = internal_getAudioFileFormat(stream);
160.193 + } finally {
160.194 + stream.reset();
160.195 + }
160.196 + return format;
160.197 + }
160.198 +
160.199 + private AudioFileFormat internal_getAudioFileFormat(InputStream stream)
160.200 + throws UnsupportedAudioFileException, IOException {
160.201 +
160.202 + RIFFReader riffiterator = new RIFFReader(stream);
160.203 + if (!riffiterator.getFormat().equals("RIFF"))
160.204 + throw new UnsupportedAudioFileException();
160.205 + if (!riffiterator.getType().equals("WAVE"))
160.206 + throw new UnsupportedAudioFileException();
160.207 +
160.208 + boolean fmt_found = false;
160.209 + boolean data_found = false;
160.210 +
160.211 + int channels = 1;
160.212 + long samplerate = 1;
160.213 + // long framerate = 1;
160.214 + int framesize = 1;
160.215 + int bits = 1;
160.216 + int validBitsPerSample = 1;
160.217 + long channelMask = 0;
160.218 + GUID subFormat = null;
160.219 +
160.220 + while (riffiterator.hasNextChunk()) {
160.221 + RIFFReader chunk = riffiterator.nextChunk();
160.222 +
160.223 + if (chunk.getFormat().equals("fmt ")) {
160.224 + fmt_found = true;
160.225 +
160.226 + int format = chunk.readUnsignedShort();
160.227 + if (format != 0xFFFE)
160.228 + throw new UnsupportedAudioFileException(); // WAVE_FORMAT_EXTENSIBLE
160.229 + // only
160.230 + channels = chunk.readUnsignedShort();
160.231 + samplerate = chunk.readUnsignedInt();
160.232 + /* framerate = */chunk.readUnsignedInt();
160.233 + framesize = chunk.readUnsignedShort();
160.234 + bits = chunk.readUnsignedShort();
160.235 + int cbSize = chunk.readUnsignedShort();
160.236 + if (cbSize != 22)
160.237 + throw new UnsupportedAudioFileException();
160.238 + validBitsPerSample = chunk.readUnsignedShort();
160.239 + if (validBitsPerSample > bits)
160.240 + throw new UnsupportedAudioFileException();
160.241 + channelMask = chunk.readUnsignedInt();
160.242 + subFormat = GUID.read(chunk);
160.243 +
160.244 + }
160.245 + if (chunk.getFormat().equals("data")) {
160.246 + data_found = true;
160.247 + break;
160.248 + }
160.249 + }
160.250 +
160.251 + if (!fmt_found)
160.252 + throw new UnsupportedAudioFileException();
160.253 + if (!data_found)
160.254 + throw new UnsupportedAudioFileException();
160.255 +
160.256 + Map<String, Object> p = new HashMap<String, Object>();
160.257 + String s_channelmask = decodeChannelMask(channelMask);
160.258 + if (s_channelmask != null)
160.259 + p.put("channelOrder", s_channelmask);
160.260 + if (channelMask != 0)
160.261 + p.put("channelMask", channelMask);
160.262 + // validBitsPerSample is only informational for PCM data,
160.263 + // data is still encode according to SampleSizeInBits.
160.264 + p.put("validBitsPerSample", validBitsPerSample);
160.265 +
160.266 + AudioFormat audioformat = null;
160.267 + if (subFormat.equals(SUBTYPE_PCM)) {
160.268 + if (bits == 8) {
160.269 + audioformat = new AudioFormat(Encoding.PCM_UNSIGNED,
160.270 + samplerate, bits, channels, framesize, samplerate,
160.271 + false, p);
160.272 + } else {
160.273 + audioformat = new AudioFormat(Encoding.PCM_SIGNED, samplerate,
160.274 + bits, channels, framesize, samplerate, false, p);
160.275 + }
160.276 + } else if (subFormat.equals(SUBTYPE_IEEE_FLOAT)) {
160.277 + audioformat = new AudioFormat(AudioFloatConverter.PCM_FLOAT,
160.278 + samplerate, bits, channels, framesize, samplerate, false, p);
160.279 + } else
160.280 + throw new UnsupportedAudioFileException();
160.281 +
160.282 + AudioFileFormat fileformat = new AudioFileFormat(
160.283 + AudioFileFormat.Type.WAVE, audioformat,
160.284 + AudioSystem.NOT_SPECIFIED);
160.285 + return fileformat;
160.286 + }
160.287 +
160.288 + public AudioInputStream getAudioInputStream(InputStream stream)
160.289 + throws UnsupportedAudioFileException, IOException {
160.290 +
160.291 + AudioFileFormat format = getAudioFileFormat(stream);
160.292 + RIFFReader riffiterator = new RIFFReader(stream);
160.293 + if (!riffiterator.getFormat().equals("RIFF"))
160.294 + throw new UnsupportedAudioFileException();
160.295 + if (!riffiterator.getType().equals("WAVE"))
160.296 + throw new UnsupportedAudioFileException();
160.297 + while (riffiterator.hasNextChunk()) {
160.298 + RIFFReader chunk = riffiterator.nextChunk();
160.299 + if (chunk.getFormat().equals("data")) {
160.300 + return new AudioInputStream(chunk, format.getFormat(), chunk
160.301 + .getSize());
160.302 + }
160.303 + }
160.304 + throw new UnsupportedAudioFileException();
160.305 + }
160.306 +
160.307 + public AudioFileFormat getAudioFileFormat(URL url)
160.308 + throws UnsupportedAudioFileException, IOException {
160.309 + InputStream stream = url.openStream();
160.310 + AudioFileFormat format;
160.311 + try {
160.312 + format = getAudioFileFormat(new BufferedInputStream(stream));
160.313 + } finally {
160.314 + stream.close();
160.315 + }
160.316 + return format;
160.317 + }
160.318 +
160.319 + public AudioFileFormat getAudioFileFormat(File file)
160.320 + throws UnsupportedAudioFileException, IOException {
160.321 + InputStream stream = new FileInputStream(file);
160.322 + AudioFileFormat format;
160.323 + try {
160.324 + format = getAudioFileFormat(new BufferedInputStream(stream));
160.325 + } finally {
160.326 + stream.close();
160.327 + }
160.328 + return format;
160.329 + }
160.330 +
160.331 + public AudioInputStream getAudioInputStream(URL url)
160.332 + throws UnsupportedAudioFileException, IOException {
160.333 + return getAudioInputStream(new BufferedInputStream(url.openStream()));
160.334 + }
160.335 +
160.336 + public AudioInputStream getAudioInputStream(File file)
160.337 + throws UnsupportedAudioFileException, IOException {
160.338 + return getAudioInputStream(new BufferedInputStream(new FileInputStream(
160.339 + file)));
160.340 + }
160.341 +
160.342 +}
161.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
161.2 +++ b/src/share/classes/com/sun/media/sound/WaveFloatFileReader.java Tue Feb 03 22:02:55 2009 -0800
161.3 @@ -0,0 +1,166 @@
161.4 +/*
161.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
161.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
161.7 + *
161.8 + * This code is free software; you can redistribute it and/or modify it
161.9 + * under the terms of the GNU General Public License version 2 only, as
161.10 + * published by the Free Software Foundation. Sun designates this
161.11 + * particular file as subject to the "Classpath" exception as provided
161.12 + * by Sun in the LICENSE file that accompanied this code.
161.13 + *
161.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
161.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
161.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
161.17 + * version 2 for more details (a copy is included in the LICENSE file that
161.18 + * accompanied this code).
161.19 + *
161.20 + * You should have received a copy of the GNU General Public License version
161.21 + * 2 along with this work; if not, write to the Free Software Foundation,
161.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
161.23 + *
161.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
161.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
161.26 + * have any questions.
161.27 + */
161.28 +package com.sun.media.sound;
161.29 +
161.30 +import java.io.BufferedInputStream;
161.31 +import java.io.File;
161.32 +import java.io.FileInputStream;
161.33 +import java.io.IOException;
161.34 +import java.io.InputStream;
161.35 +import java.net.URL;
161.36 +
161.37 +import javax.sound.sampled.AudioFileFormat;
161.38 +import javax.sound.sampled.AudioFormat;
161.39 +import javax.sound.sampled.AudioInputStream;
161.40 +import javax.sound.sampled.AudioSystem;
161.41 +import javax.sound.sampled.UnsupportedAudioFileException;
161.42 +import javax.sound.sampled.spi.AudioFileReader;
161.43 +
161.44 +/**
161.45 + * Floating-point encoded (format 3) WAVE file loader.
161.46 + *
161.47 + * @author Karl Helgason
161.48 + */
161.49 +public class WaveFloatFileReader extends AudioFileReader {
161.50 +
161.51 + public AudioFileFormat getAudioFileFormat(InputStream stream)
161.52 + throws UnsupportedAudioFileException, IOException {
161.53 +
161.54 + stream.mark(200);
161.55 + AudioFileFormat format;
161.56 + try {
161.57 + format = internal_getAudioFileFormat(stream);
161.58 + } finally {
161.59 + stream.reset();
161.60 + }
161.61 + return format;
161.62 + }
161.63 +
161.64 + private AudioFileFormat internal_getAudioFileFormat(InputStream stream)
161.65 + throws UnsupportedAudioFileException, IOException {
161.66 +
161.67 + RIFFReader riffiterator = new RIFFReader(stream);
161.68 + if (!riffiterator.getFormat().equals("RIFF"))
161.69 + throw new UnsupportedAudioFileException();
161.70 + if (!riffiterator.getType().equals("WAVE"))
161.71 + throw new UnsupportedAudioFileException();
161.72 +
161.73 + boolean fmt_found = false;
161.74 + boolean data_found = false;
161.75 +
161.76 + int channels = 1;
161.77 + long samplerate = 1;
161.78 + int framesize = 1;
161.79 + int bits = 1;
161.80 +
161.81 + while (riffiterator.hasNextChunk()) {
161.82 + RIFFReader chunk = riffiterator.nextChunk();
161.83 +
161.84 + if (chunk.getFormat().equals("fmt ")) {
161.85 + fmt_found = true;
161.86 +
161.87 + int format = chunk.readUnsignedShort();
161.88 + if (format != 3) // WAVE_FORMAT_IEEE_FLOAT only
161.89 + throw new UnsupportedAudioFileException();
161.90 + channels = chunk.readUnsignedShort();
161.91 + samplerate = chunk.readUnsignedInt();
161.92 + /* framerate = */chunk.readUnsignedInt();
161.93 + framesize = chunk.readUnsignedShort();
161.94 + bits = chunk.readUnsignedShort();
161.95 + }
161.96 + if (chunk.getFormat().equals("data")) {
161.97 + data_found = true;
161.98 + break;
161.99 + }
161.100 + }
161.101 +
161.102 + if (!fmt_found)
161.103 + throw new UnsupportedAudioFileException();
161.104 + if (!data_found)
161.105 + throw new UnsupportedAudioFileException();
161.106 +
161.107 + AudioFormat audioformat = new AudioFormat(
161.108 + AudioFloatConverter.PCM_FLOAT, samplerate, bits, channels,
161.109 + framesize, samplerate, false);
161.110 + AudioFileFormat fileformat = new AudioFileFormat(
161.111 + AudioFileFormat.Type.WAVE, audioformat,
161.112 + AudioSystem.NOT_SPECIFIED);
161.113 + return fileformat;
161.114 + }
161.115 +
161.116 + public AudioInputStream getAudioInputStream(InputStream stream)
161.117 + throws UnsupportedAudioFileException, IOException {
161.118 +
161.119 + AudioFileFormat format = getAudioFileFormat(stream);
161.120 + RIFFReader riffiterator = new RIFFReader(stream);
161.121 + if (!riffiterator.getFormat().equals("RIFF"))
161.122 + throw new UnsupportedAudioFileException();
161.123 + if (!riffiterator.getType().equals("WAVE"))
161.124 + throw new UnsupportedAudioFileException();
161.125 + while (riffiterator.hasNextChunk()) {
161.126 + RIFFReader chunk = riffiterator.nextChunk();
161.127 + if (chunk.getFormat().equals("data")) {
161.128 + return new AudioInputStream(chunk, format.getFormat(),
161.129 + chunk.getSize());
161.130 + }
161.131 + }
161.132 + throw new UnsupportedAudioFileException();
161.133 + }
161.134 +
161.135 + public AudioFileFormat getAudioFileFormat(URL url)
161.136 + throws UnsupportedAudioFileException, IOException {
161.137 + InputStream stream = url.openStream();
161.138 + AudioFileFormat format;
161.139 + try {
161.140 + format = getAudioFileFormat(new BufferedInputStream(stream));
161.141 + } finally {
161.142 + stream.close();
161.143 + }
161.144 + return format;
161.145 + }
161.146 +
161.147 + public AudioFileFormat getAudioFileFormat(File file)
161.148 + throws UnsupportedAudioFileException, IOException {
161.149 + InputStream stream = new FileInputStream(file);
161.150 + AudioFileFormat format;
161.151 + try {
161.152 + format = getAudioFileFormat(new BufferedInputStream(stream));
161.153 + } finally {
161.154 + stream.close();
161.155 + }
161.156 + return format;
161.157 + }
161.158 +
161.159 + public AudioInputStream getAudioInputStream(URL url)
161.160 + throws UnsupportedAudioFileException, IOException {
161.161 + return getAudioInputStream(new BufferedInputStream(url.openStream()));
161.162 + }
161.163 +
161.164 + public AudioInputStream getAudioInputStream(File file)
161.165 + throws UnsupportedAudioFileException, IOException {
161.166 + return getAudioInputStream(new BufferedInputStream(new FileInputStream(
161.167 + file)));
161.168 + }
161.169 +}
162.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
162.2 +++ b/src/share/classes/com/sun/media/sound/WaveFloatFileWriter.java Tue Feb 03 22:02:55 2009 -0800
162.3 @@ -0,0 +1,147 @@
162.4 +/*
162.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
162.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
162.7 + *
162.8 + * This code is free software; you can redistribute it and/or modify it
162.9 + * under the terms of the GNU General Public License version 2 only, as
162.10 + * published by the Free Software Foundation. Sun designates this
162.11 + * particular file as subject to the "Classpath" exception as provided
162.12 + * by Sun in the LICENSE file that accompanied this code.
162.13 + *
162.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
162.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
162.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
162.17 + * version 2 for more details (a copy is included in the LICENSE file that
162.18 + * accompanied this code).
162.19 + *
162.20 + * You should have received a copy of the GNU General Public License version
162.21 + * 2 along with this work; if not, write to the Free Software Foundation,
162.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
162.23 + *
162.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
162.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
162.26 + * have any questions.
162.27 + */
162.28 +package com.sun.media.sound;
162.29 +
162.30 +import java.io.File;
162.31 +import java.io.IOException;
162.32 +import java.io.OutputStream;
162.33 +
162.34 +import javax.sound.sampled.AudioFileFormat;
162.35 +import javax.sound.sampled.AudioFormat;
162.36 +import javax.sound.sampled.AudioInputStream;
162.37 +import javax.sound.sampled.AudioSystem;
162.38 +import javax.sound.sampled.AudioFileFormat.Type;
162.39 +import javax.sound.sampled.spi.AudioFileWriter;
162.40 +
162.41 +/**
162.42 + * Floating-point encoded (format 3) WAVE file writer.
162.43 + *
162.44 + * @author Karl Helgason
162.45 + */
162.46 +public class WaveFloatFileWriter extends AudioFileWriter {
162.47 +
162.48 + public Type[] getAudioFileTypes() {
162.49 + return new Type[] { Type.WAVE };
162.50 + }
162.51 +
162.52 + public Type[] getAudioFileTypes(AudioInputStream stream) {
162.53 +
162.54 + if (!stream.getFormat().getEncoding().equals(
162.55 + AudioFloatConverter.PCM_FLOAT))
162.56 + return new Type[0];
162.57 + return new Type[] { Type.WAVE };
162.58 + }
162.59 +
162.60 + private void checkFormat(AudioFileFormat.Type type, AudioInputStream stream) {
162.61 + if (!Type.WAVE.equals(type))
162.62 + throw new IllegalArgumentException("File type " + type
162.63 + + " not supported.");
162.64 + if (!stream.getFormat().getEncoding().equals(
162.65 + AudioFloatConverter.PCM_FLOAT))
162.66 + throw new IllegalArgumentException("File format "
162.67 + + stream.getFormat() + " not supported.");
162.68 + }
162.69 +
162.70 + public void write(AudioInputStream stream, RIFFWriter writer)
162.71 + throws IOException {
162.72 +
162.73 + RIFFWriter fmt_chunk = writer.writeChunk("fmt ");
162.74 +
162.75 + AudioFormat format = stream.getFormat();
162.76 + fmt_chunk.writeUnsignedShort(3); // WAVE_FORMAT_IEEE_FLOAT
162.77 + fmt_chunk.writeUnsignedShort(format.getChannels());
162.78 + fmt_chunk.writeUnsignedInt((int) format.getSampleRate());
162.79 + fmt_chunk.writeUnsignedInt(((int) format.getFrameRate())
162.80 + * format.getFrameSize());
162.81 + fmt_chunk.writeUnsignedShort(format.getFrameSize());
162.82 + fmt_chunk.writeUnsignedShort(format.getSampleSizeInBits());
162.83 + fmt_chunk.close();
162.84 + RIFFWriter data_chunk = writer.writeChunk("data");
162.85 + byte[] buff = new byte[1024];
162.86 + int len;
162.87 + while ((len = stream.read(buff, 0, buff.length)) != -1)
162.88 + data_chunk.write(buff, 0, len);
162.89 + data_chunk.close();
162.90 + }
162.91 +
162.92 + private static class NoCloseOutputStream extends OutputStream {
162.93 + OutputStream out;
162.94 +
162.95 + public NoCloseOutputStream(OutputStream out) {
162.96 + this.out = out;
162.97 + }
162.98 +
162.99 + public void write(int b) throws IOException {
162.100 + out.write(b);
162.101 + }
162.102 +
162.103 + public void flush() throws IOException {
162.104 + out.flush();
162.105 + }
162.106 +
162.107 + public void write(byte[] b, int off, int len) throws IOException {
162.108 + out.write(b, off, len);
162.109 + }
162.110 +
162.111 + public void write(byte[] b) throws IOException {
162.112 + out.write(b);
162.113 + }
162.114 + }
162.115 +
162.116 + private AudioInputStream toLittleEndian(AudioInputStream ais) {
162.117 + AudioFormat format = ais.getFormat();
162.118 + AudioFormat targetFormat = new AudioFormat(format.getEncoding(), format
162.119 + .getSampleRate(), format.getSampleSizeInBits(), format
162.120 + .getChannels(), format.getFrameSize(), format.getFrameRate(),
162.121 + false);
162.122 + return AudioSystem.getAudioInputStream(targetFormat, ais);
162.123 + }
162.124 +
162.125 + public int write(AudioInputStream stream, Type fileType, OutputStream out)
162.126 + throws IOException {
162.127 +
162.128 + checkFormat(fileType, stream);
162.129 + if (stream.getFormat().isBigEndian())
162.130 + stream = toLittleEndian(stream);
162.131 + RIFFWriter writer = new RIFFWriter(new NoCloseOutputStream(out), "WAVE");
162.132 + write(stream, writer);
162.133 + int fpointer = (int) writer.getFilePointer();
162.134 + writer.close();
162.135 + return fpointer;
162.136 + }
162.137 +
162.138 + public int write(AudioInputStream stream, Type fileType, File out)
162.139 + throws IOException {
162.140 + checkFormat(fileType, stream);
162.141 + if (stream.getFormat().isBigEndian())
162.142 + stream = toLittleEndian(stream);
162.143 + RIFFWriter writer = new RIFFWriter(out, "WAVE");
162.144 + write(stream, writer);
162.145 + int fpointer = (int) writer.getFilePointer();
162.146 + writer.close();
162.147 + return fpointer;
162.148 + }
162.149 +
162.150 +}
163.1 --- a/src/share/classes/com/sun/media/sound/services/javax.sound.midi.spi.MidiDeviceProvider Thu Jan 29 21:46:48 2009 -0800
163.2 +++ b/src/share/classes/com/sun/media/sound/services/javax.sound.midi.spi.MidiDeviceProvider Tue Feb 03 22:02:55 2009 -0800
163.3 @@ -1,5 +1,5 @@
163.4 # Providers for midi devices
163.5 -com.sun.media.sound.MixerSynthProvider
163.6 com.sun.media.sound.RealTimeSequencerProvider
163.7 com.sun.media.sound.MidiOutDeviceProvider
163.8 com.sun.media.sound.MidiInDeviceProvider
163.9 +com.sun.media.sound.SoftProvider
164.1 --- a/src/share/classes/com/sun/media/sound/services/javax.sound.midi.spi.MidiFileReader Thu Jan 29 21:46:48 2009 -0800
164.2 +++ b/src/share/classes/com/sun/media/sound/services/javax.sound.midi.spi.MidiFileReader Tue Feb 03 22:02:55 2009 -0800
164.3 @@ -1,3 +1,2 @@
164.4 # Providers for midi sequences
164.5 com.sun.media.sound.StandardMidiFileReader
164.6 -com.sun.media.sound.RmfFileReader
165.1 --- a/src/share/classes/com/sun/media/sound/services/javax.sound.midi.spi.SoundbankReader Thu Jan 29 21:46:48 2009 -0800
165.2 +++ b/src/share/classes/com/sun/media/sound/services/javax.sound.midi.spi.SoundbankReader Tue Feb 03 22:02:55 2009 -0800
165.3 @@ -1,2 +1,5 @@
165.4 # Providers for Soundbanks
165.5 -com.sun.media.sound.HsbParser
165.6 +com.sun.media.sound.SF2SoundbankReader
165.7 +com.sun.media.sound.DLSSoundbankReader
165.8 +com.sun.media.sound.AudioFileSoundbankReader
165.9 +com.sun.media.sound.JARSoundbankReader
166.1 --- a/src/share/classes/com/sun/media/sound/services/javax.sound.sampled.spi.AudioFileReader Thu Jan 29 21:46:48 2009 -0800
166.2 +++ b/src/share/classes/com/sun/media/sound/services/javax.sound.sampled.spi.AudioFileReader Tue Feb 03 22:02:55 2009 -0800
166.3 @@ -2,3 +2,5 @@
166.4 com.sun.media.sound.AuFileReader
166.5 com.sun.media.sound.AiffFileReader
166.6 com.sun.media.sound.WaveFileReader
166.7 +com.sun.media.sound.WaveFloatFileReader
166.8 +com.sun.media.sound.SoftMidiAudioFileReader
167.1 --- a/src/share/classes/com/sun/media/sound/services/javax.sound.sampled.spi.FormatConversionProvider Thu Jan 29 21:46:48 2009 -0800
167.2 +++ b/src/share/classes/com/sun/media/sound/services/javax.sound.sampled.spi.FormatConversionProvider Tue Feb 03 22:02:55 2009 -0800
167.3 @@ -2,3 +2,4 @@
167.4 com.sun.media.sound.UlawCodec
167.5 com.sun.media.sound.AlawCodec
167.6 com.sun.media.sound.PCMtoPCMCodec
167.7 +com.sun.media.sound.AudioFloatFormatConverter
168.1 --- a/src/share/classes/com/sun/media/sound/services/javax.sound.sampled.spi.MixerProvider Thu Jan 29 21:46:48 2009 -0800
168.2 +++ b/src/share/classes/com/sun/media/sound/services/javax.sound.sampled.spi.MixerProvider Tue Feb 03 22:02:55 2009 -0800
168.3 @@ -1,5 +1,3 @@
168.4 # last mixer is default mixer
168.5 com.sun.media.sound.PortMixerProvider
168.6 -com.sun.media.sound.SimpleInputDeviceProvider
168.7 -com.sun.media.sound.HeadspaceMixerProvider
168.8 com.sun.media.sound.DirectAudioDeviceProvider
169.1 --- a/src/share/classes/java/beans/EventHandler.java Thu Jan 29 21:46:48 2009 -0800
169.2 +++ b/src/share/classes/java/beans/EventHandler.java Tue Feb 03 22:02:55 2009 -0800
169.3 @@ -1,5 +1,5 @@
169.4 /*
169.5 - * Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved.
169.6 + * Copyright 2000-2009 Sun Microsystems, Inc. All Rights Reserved.
169.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
169.8 *
169.9 * This code is free software; you can redistribute it and/or modify it
169.10 @@ -385,16 +385,16 @@
169.11 try {
169.12 Method getter = null;
169.13 if (target != null) {
169.14 - getter = ReflectionUtils.getMethod(target.getClass(),
169.15 + getter = Statement.getMethod(target.getClass(),
169.16 "get" + NameGenerator.capitalize(first),
169.17 new Class[]{});
169.18 if (getter == null) {
169.19 - getter = ReflectionUtils.getMethod(target.getClass(),
169.20 + getter = Statement.getMethod(target.getClass(),
169.21 "is" + NameGenerator.capitalize(first),
169.22 new Class[]{});
169.23 }
169.24 if (getter == null) {
169.25 - getter = ReflectionUtils.getMethod(target.getClass(), first, new Class[]{});
169.26 + getter = Statement.getMethod(target.getClass(), first, new Class[]{});
169.27 }
169.28 }
169.29 if (getter == null) {
169.30 @@ -462,10 +462,10 @@
169.31 target = applyGetters(target, action.substring(0, lastDot));
169.32 action = action.substring(lastDot + 1);
169.33 }
169.34 - Method targetMethod = ReflectionUtils.getMethod(
169.35 + Method targetMethod = Statement.getMethod(
169.36 target.getClass(), action, argTypes);
169.37 if (targetMethod == null) {
169.38 - targetMethod = ReflectionUtils.getMethod(target.getClass(),
169.39 + targetMethod = Statement.getMethod(target.getClass(),
169.40 "set" + NameGenerator.capitalize(action), argTypes);
169.41 }
169.42 if (targetMethod == null) {
170.1 --- a/src/share/classes/java/beans/MetaData.java Thu Jan 29 21:46:48 2009 -0800
170.2 +++ b/src/share/classes/java/beans/MetaData.java Tue Feb 03 22:02:55 2009 -0800
170.3 @@ -24,6 +24,8 @@
170.4 */
170.5 package java.beans;
170.6
170.7 +import com.sun.beans.finder.PrimitiveWrapperMap;
170.8 +
170.9 import java.awt.AWTKeyStroke;
170.10 import java.awt.BorderLayout;
170.11 import java.awt.Dimension;
170.12 @@ -204,7 +206,7 @@
170.13 if (c.isPrimitive()) {
170.14 Field field = null;
170.15 try {
170.16 - field = ReflectionUtils.typeToClass(c).getDeclaredField("TYPE");
170.17 + field = PrimitiveWrapperMap.getType(c.getName()).getDeclaredField("TYPE");
170.18 } catch (NoSuchFieldException ex) {
170.19 System.err.println("Unknown primitive type: " + c);
170.20 }
171.1 --- a/src/share/classes/java/beans/ReflectionUtils.java Thu Jan 29 21:46:48 2009 -0800
171.2 +++ b/src/share/classes/java/beans/ReflectionUtils.java Tue Feb 03 22:02:55 2009 -0800
171.3 @@ -1,5 +1,5 @@
171.4 /*
171.5 - * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
171.6 + * Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved.
171.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
171.8 *
171.9 * This code is free software; you can redistribute it and/or modify it
171.10 @@ -24,20 +24,7 @@
171.11 */
171.12 package java.beans;
171.13
171.14 -import java.lang.reflect.Constructor;
171.15 import java.lang.reflect.Field;
171.16 -import java.lang.reflect.Method;
171.17 -import java.lang.reflect.Modifier;
171.18 -
171.19 -import java.lang.ref.Reference;
171.20 -import java.lang.ref.SoftReference;
171.21 -
171.22 -import java.util.*;
171.23 -
171.24 -import com.sun.beans.ObjectHandler;
171.25 -import sun.reflect.misc.MethodUtil;
171.26 -import sun.reflect.misc.ConstructorUtil;
171.27 -import sun.reflect.misc.ReflectUtil;
171.28
171.29 /**
171.30 * A utility class for reflectively finding methods, constuctors and fields
171.31 @@ -45,12 +32,6 @@
171.32 */
171.33 class ReflectionUtils {
171.34
171.35 - private static Reference methodCacheRef;
171.36 -
171.37 - public static Class typeToClass(Class type) {
171.38 - return type.isPrimitive() ? ObjectHandler.typeNameToClass(type.getName()) : type;
171.39 - }
171.40 -
171.41 public static boolean isPrimitive(Class type) {
171.42 return primitiveTypeFor(type) != null;
171.43 }
171.44 @@ -69,346 +50,6 @@
171.45 }
171.46
171.47 /**
171.48 - * Tests each element on the class arrays for assignability.
171.49 - *
171.50 - * @param argClasses arguments to be tested
171.51 - * @param argTypes arguments from Method
171.52 - * @return true if each class in argTypes is assignable from the
171.53 - * corresponding class in argClasses.
171.54 - */
171.55 - private static boolean matchArguments(Class[] argClasses, Class[] argTypes) {
171.56 - return matchArguments(argClasses, argTypes, false);
171.57 - }
171.58 -
171.59 - /**
171.60 - * Tests each element on the class arrays for equality.
171.61 - *
171.62 - * @param argClasses arguments to be tested
171.63 - * @param argTypes arguments from Method
171.64 - * @return true if each class in argTypes is equal to the
171.65 - * corresponding class in argClasses.
171.66 - */
171.67 - private static boolean matchExplicitArguments(Class[] argClasses, Class[] argTypes) {
171.68 - return matchArguments(argClasses, argTypes, true);
171.69 - }
171.70 -
171.71 - private static boolean matchArguments(Class[] argClasses,
171.72 - Class[] argTypes, boolean explicit) {
171.73 -
171.74 - boolean match = (argClasses.length == argTypes.length);
171.75 - for(int j = 0; j < argClasses.length && match; j++) {
171.76 - Class argType = argTypes[j];
171.77 - if (argType.isPrimitive()) {
171.78 - argType = typeToClass(argType);
171.79 - }
171.80 - if (explicit) {
171.81 - // Test each element for equality
171.82 - if (argClasses[j] != argType) {
171.83 - match = false;
171.84 - }
171.85 - } else {
171.86 - // Consider null an instance of all classes.
171.87 - if (argClasses[j] != null &&
171.88 - !(argType.isAssignableFrom(argClasses[j]))) {
171.89 - match = false;
171.90 - }
171.91 - }
171.92 - }
171.93 - return match;
171.94 - }
171.95 -
171.96 - /**
171.97 - * @return the method which best matches the signature or throw an exception
171.98 - * if it can't be found or the method is ambiguous.
171.99 - */
171.100 - static Method getPublicMethod(Class declaringClass, String methodName,
171.101 - Class[] argClasses) throws NoSuchMethodException {
171.102 - Method m;
171.103 -
171.104 - m = findPublicMethod(declaringClass, methodName, argClasses);
171.105 - if (m == null)
171.106 - throw new NoSuchMethodException(declaringClass.getName() + "." + methodName);
171.107 - return m;
171.108 - }
171.109 -
171.110 - /**
171.111 - * @return the method which best matches the signature or null if it cant be found or
171.112 - * the method is ambiguous.
171.113 - */
171.114 - public static Method findPublicMethod(Class declaringClass, String methodName,
171.115 - Class[] argClasses) {
171.116 - // Many methods are "getters" which take no arguments.
171.117 - // This permits the following optimisation which
171.118 - // avoids the expensive call to getMethods().
171.119 - if (argClasses.length == 0) {
171.120 - try {
171.121 - return MethodUtil.getMethod(declaringClass, methodName, argClasses);
171.122 - }
171.123 - catch (NoSuchMethodException e) {
171.124 - return null;
171.125 - } catch (SecurityException se) {
171.126 - // fall through
171.127 - }
171.128 - }
171.129 - Method[] methods = MethodUtil.getPublicMethods(declaringClass);
171.130 - List list = new ArrayList();
171.131 - for(int i = 0; i < methods.length; i++) {
171.132 - // Collect all the methods which match the signature.
171.133 - Method method = methods[i];
171.134 - if (method.getName().equals(methodName)) {
171.135 - if (matchArguments(argClasses, method.getParameterTypes())) {
171.136 - list.add(method);
171.137 - }
171.138 - }
171.139 - }
171.140 - if (list.size() > 0) {
171.141 - if (list.size() == 1) {
171.142 - return (Method)list.get(0);
171.143 - }
171.144 - else {
171.145 - ListIterator iterator = list.listIterator();
171.146 - Method method;
171.147 - while (iterator.hasNext()) {
171.148 - method = (Method)iterator.next();
171.149 - if (matchExplicitArguments(argClasses, method.getParameterTypes())) {
171.150 - return method;
171.151 - }
171.152 - }
171.153 - // There are more than one method which matches this signature.
171.154 - // try to return the most specific method.
171.155 - return getMostSpecificMethod(list, argClasses);
171.156 - }
171.157 - }
171.158 - return null;
171.159 - }
171.160 -
171.161 - /**
171.162 - * Return the most specific method from the list of methods which
171.163 - * matches the args. The most specific method will have the most
171.164 - * number of equal parameters or will be closest in the inheritance
171.165 - * heirarchy to the runtime execution arguments.
171.166 - * <p>
171.167 - * See the JLS section 15.12
171.168 - * http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#20448
171.169 - *
171.170 - * @param methods List of methods which already have the same param length
171.171 - * and arg types are assignable to param types
171.172 - * @param args an array of param types to match
171.173 - * @return method or null if a specific method cannot be determined
171.174 - */
171.175 - private static Method getMostSpecificMethod(List methods, Class[] args) {
171.176 - Method method = null;
171.177 -
171.178 - int matches = 0;
171.179 - int lastMatch = matches;
171.180 -
171.181 - ListIterator iterator = methods.listIterator();
171.182 - while (iterator.hasNext()) {
171.183 - Method m = (Method)iterator.next();
171.184 - Class[] mArgs = m.getParameterTypes();
171.185 - matches = 0;
171.186 - for (int i = 0; i < args.length; i++) {
171.187 - Class mArg = mArgs[i];
171.188 - if (mArg.isPrimitive()) {
171.189 - mArg = typeToClass(mArg);
171.190 - }
171.191 - if (args[i] == mArg) {
171.192 - matches++;
171.193 - }
171.194 - }
171.195 - if (matches == 0 && lastMatch == 0) {
171.196 - if (method == null) {
171.197 - method = m;
171.198 - } else {
171.199 - // Test existing method. We already know that the args can
171.200 - // be assigned to all the method params. However, if the
171.201 - // current method parameters is higher in the inheritance
171.202 - // hierarchy then replace it.
171.203 - if (!matchArguments(method.getParameterTypes(),
171.204 - m.getParameterTypes())) {
171.205 - method = m;
171.206 - }
171.207 - }
171.208 - } else if (matches > lastMatch) {
171.209 - lastMatch = matches;
171.210 - method = m;
171.211 - } else if (matches == lastMatch) {
171.212 - // ambiguous method selection.
171.213 - method = null;
171.214 - }
171.215 - }
171.216 - return method;
171.217 - }
171.218 -
171.219 - /**
171.220 - * @return the method or null if it can't be found or is ambiguous.
171.221 - */
171.222 - public static Method findMethod(Class targetClass, String methodName,
171.223 - Class[] argClasses) {
171.224 - Method m = findPublicMethod(targetClass, methodName, argClasses);
171.225 - if (m != null && Modifier.isPublic(m.getDeclaringClass().getModifiers())) {
171.226 - return m;
171.227 - }
171.228 -
171.229 - /*
171.230 - Search the interfaces for a public version of this method.
171.231 -
171.232 - Example: the getKeymap() method of a JTextField
171.233 - returns a package private implementation of the
171.234 - of the public Keymap interface. In the Keymap
171.235 - interface there are a number of "properties" one
171.236 - being the "resolveParent" property implied by the
171.237 - getResolveParent() method. This getResolveParent()
171.238 - cannot be called reflectively because the class
171.239 - itself is not public. Instead we search the class's
171.240 - interfaces and find the getResolveParent()
171.241 - method of the Keymap interface - on which invoke
171.242 - may be applied without error.
171.243 -
171.244 - So in :-
171.245 -
171.246 - JTextField o = new JTextField("Hello, world");
171.247 - Keymap km = o.getKeymap();
171.248 - Method m1 = km.getClass().getMethod("getResolveParent", new Class[0]);
171.249 - Method m2 = Keymap.class.getMethod("getResolveParent", new Class[0]);
171.250 -
171.251 - Methods m1 and m2 are different. The invocation of method
171.252 - m1 unconditionally throws an IllegalAccessException where
171.253 - the invocation of m2 will invoke the implementation of the
171.254 - method. Note that (ignoring the overloading of arguments)
171.255 - there is only one implementation of the named method which
171.256 - may be applied to this target.
171.257 - */
171.258 - for(Class type = targetClass; type != null; type = type.getSuperclass()) {
171.259 - Class[] interfaces = type.getInterfaces();
171.260 - for(int i = 0; i < interfaces.length; i++) {
171.261 - m = findPublicMethod(interfaces[i], methodName, argClasses);
171.262 - if (m != null) {
171.263 - return m;
171.264 - }
171.265 - }
171.266 - }
171.267 - return null;
171.268 - }
171.269 -
171.270 - /**
171.271 - * A class that represents the unique elements of a method that will be a
171.272 - * key in the method cache.
171.273 - */
171.274 - private static class Signature {
171.275 - private Class targetClass;
171.276 - private String methodName;
171.277 - private Class[] argClasses;
171.278 -
171.279 - private volatile int hashCode = 0;
171.280 -
171.281 - public Signature(Class targetClass, String methodName, Class[] argClasses) {
171.282 - this.targetClass = targetClass;
171.283 - this.methodName = methodName;
171.284 - this.argClasses = argClasses;
171.285 - }
171.286 -
171.287 - public boolean equals(Object o2) {
171.288 - if (this == o2) {
171.289 - return true;
171.290 - }
171.291 - Signature that = (Signature)o2;
171.292 - if (!(targetClass == that.targetClass)) {
171.293 - return false;
171.294 - }
171.295 - if (!(methodName.equals(that.methodName))) {
171.296 - return false;
171.297 - }
171.298 - if (argClasses.length != that.argClasses.length) {
171.299 - return false;
171.300 - }
171.301 - for (int i = 0; i < argClasses.length; i++) {
171.302 - if (!(argClasses[i] == that.argClasses[i])) {
171.303 - return false;
171.304 - }
171.305 - }
171.306 - return true;
171.307 - }
171.308 -
171.309 - /**
171.310 - * Hash code computed using algorithm suggested in
171.311 - * Effective Java, Item 8.
171.312 - */
171.313 - public int hashCode() {
171.314 - if (hashCode == 0) {
171.315 - int result = 17;
171.316 - result = 37 * result + targetClass.hashCode();
171.317 - result = 37 * result + methodName.hashCode();
171.318 - if (argClasses != null) {
171.319 - for (int i = 0; i < argClasses.length; i++) {
171.320 - result = 37 * result + ((argClasses[i] == null) ? 0 :
171.321 - argClasses[i].hashCode());
171.322 - }
171.323 - }
171.324 - hashCode = result;
171.325 - }
171.326 - return hashCode;
171.327 - }
171.328 - }
171.329 -
171.330 - /**
171.331 - * A wrapper to findMethod(), which will search or populate the method
171.332 - * in a cache.
171.333 - * @throws exception if the method is ambiguios.
171.334 - */
171.335 - public static synchronized Method getMethod(Class targetClass,
171.336 - String methodName,
171.337 - Class[] argClasses) {
171.338 - Object signature = new Signature(targetClass, methodName, argClasses);
171.339 -
171.340 - Method method = null;
171.341 - Map methodCache = null;
171.342 - boolean cache = false;
171.343 - if (ReflectUtil.isPackageAccessible(targetClass)) {
171.344 - cache = true;
171.345 - }
171.346 -
171.347 - if (cache && methodCacheRef != null &&
171.348 - (methodCache = (Map)methodCacheRef.get()) != null) {
171.349 - method = (Method)methodCache.get(signature);
171.350 - if (method != null) {
171.351 - return method;
171.352 - }
171.353 - }
171.354 - method = findMethod(targetClass, methodName, argClasses);
171.355 - if (cache && method != null) {
171.356 - if (methodCache == null) {
171.357 - methodCache = new HashMap();
171.358 - methodCacheRef = new SoftReference(methodCache);
171.359 - }
171.360 - methodCache.put(signature, method);
171.361 - }
171.362 - return method;
171.363 - }
171.364 -
171.365 - /**
171.366 - * Return a constructor on the class with the arguments.
171.367 - *
171.368 - * @throws exception if the method is ambiguios.
171.369 - */
171.370 - public static Constructor getConstructor(Class cls, Class[] args) {
171.371 - Constructor constructor = null;
171.372 -
171.373 - // PENDING: Implement the resolutuion of ambiguities properly.
171.374 - Constructor[] ctors = ConstructorUtil.getConstructors(cls);
171.375 - for(int i = 0; i < ctors.length; i++) {
171.376 - if (matchArguments(args, ctors[i].getParameterTypes())) {
171.377 - constructor = ctors[i];
171.378 - }
171.379 - }
171.380 - return constructor;
171.381 - }
171.382 -
171.383 - public static Object getPrivateField(Object instance, Class cls, String name) {
171.384 - return getPrivateField(instance, cls, name, null);
171.385 - }
171.386 -
171.387 - /**
171.388 * Returns the value of a private field.
171.389 *
171.390 * @param instance object instance
172.1 --- a/src/share/classes/java/beans/Statement.java Thu Jan 29 21:46:48 2009 -0800
172.2 +++ b/src/share/classes/java/beans/Statement.java Tue Feb 03 22:02:55 2009 -0800
172.3 @@ -1,5 +1,5 @@
172.4 /*
172.5 - * Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved.
172.6 + * Copyright 2000-2009 Sun Microsystems, Inc. All Rights Reserved.
172.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
172.8 *
172.9 * This code is free software; you can redistribute it and/or modify it
172.10 @@ -31,6 +31,8 @@
172.11 import java.lang.reflect.Method;
172.12
172.13 import com.sun.beans.finder.ClassFinder;
172.14 +import com.sun.beans.finder.ConstructorFinder;
172.15 +import com.sun.beans.finder.MethodFinder;
172.16 import sun.reflect.misc.MethodUtil;
172.17
172.18 /**
172.19 @@ -195,13 +197,18 @@
172.20 argClasses[0] == String.class) {
172.21 return new Character(((String)arguments[0]).charAt(0));
172.22 }
172.23 - m = ReflectionUtils.getConstructor((Class)target, argClasses);
172.24 + try {
172.25 + m = ConstructorFinder.findConstructor((Class)target, argClasses);
172.26 + }
172.27 + catch (NoSuchMethodException exception) {
172.28 + m = null;
172.29 + }
172.30 }
172.31 if (m == null && target != Class.class) {
172.32 - m = ReflectionUtils.getMethod((Class)target, methodName, argClasses);
172.33 + m = getMethod((Class)target, methodName, argClasses);
172.34 }
172.35 if (m == null) {
172.36 - m = ReflectionUtils.getMethod(Class.class, methodName, argClasses);
172.37 + m = getMethod(Class.class, methodName, argClasses);
172.38 }
172.39 }
172.40 else {
172.41 @@ -224,7 +231,7 @@
172.42 return null;
172.43 }
172.44 }
172.45 - m = ReflectionUtils.getMethod(target.getClass(), methodName, argClasses);
172.46 + m = getMethod(target.getClass(), methodName, argClasses);
172.47 }
172.48 if (m != null) {
172.49 try {
172.50 @@ -289,4 +296,13 @@
172.51 result.append(");");
172.52 return result.toString();
172.53 }
172.54 +
172.55 + static Method getMethod(Class<?> type, String name, Class<?>... args) {
172.56 + try {
172.57 + return MethodFinder.findMethod(type, name, args);
172.58 + }
172.59 + catch (NoSuchMethodException exception) {
172.60 + return null;
172.61 + }
172.62 + }
172.63 }
173.1 --- a/src/share/classes/java/beans/XMLDecoder.java Thu Jan 29 21:46:48 2009 -0800
173.2 +++ b/src/share/classes/java/beans/XMLDecoder.java Tue Feb 03 22:02:55 2009 -0800
173.3 @@ -1,5 +1,5 @@
173.4 /*
173.5 - * Copyright 2000-2005 Sun Microsystems, Inc. All Rights Reserved.
173.6 + * Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved.
173.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
173.8 *
173.9 * This code is free software; you can redistribute it and/or modify it
173.10 @@ -24,19 +24,14 @@
173.11 */
173.12 package java.beans;
173.13
173.14 -import com.sun.beans.ObjectHandler;
173.15 +import com.sun.beans.decoder.DocumentHandler;
173.16
173.17 +import java.io.Closeable;
173.18 import java.io.InputStream;
173.19 import java.io.IOException;
173.20
173.21 -import java.lang.ref.Reference;
173.22 -import java.lang.ref.WeakReference;
173.23 -
173.24 -import org.xml.sax.SAXException;
173.25 -
173.26 -import javax.xml.parsers.SAXParserFactory;
173.27 -import javax.xml.parsers.ParserConfigurationException;
173.28 -import javax.xml.parsers.SAXParser;
173.29 +import org.xml.sax.InputSource;
173.30 +import org.xml.sax.helpers.DefaultHandler;
173.31
173.32 /**
173.33 * The <code>XMLDecoder</code> class is used to read XML documents
173.34 @@ -66,11 +61,11 @@
173.35 * @author Philip Milne
173.36 */
173.37 public class XMLDecoder {
173.38 - private InputStream in;
173.39 + private final DocumentHandler handler = new DocumentHandler();
173.40 + private final InputSource input;
173.41 private Object owner;
173.42 - private ExceptionListener exceptionListener;
173.43 - private ObjectHandler handler;
173.44 - private Reference clref;
173.45 + private Object[] array;
173.46 + private int index;
173.47
173.48 /**
173.49 * Creates a new input stream for reading archives
173.50 @@ -126,36 +121,45 @@
173.51 */
173.52 public XMLDecoder(InputStream in, Object owner,
173.53 ExceptionListener exceptionListener, ClassLoader cl) {
173.54 - this.in = in;
173.55 - setOwner(owner);
173.56 - setExceptionListener(exceptionListener);
173.57 - setClassLoader(cl);
173.58 + this(new InputSource(in), owner, exceptionListener, cl);
173.59 }
173.60
173.61
173.62 /**
173.63 - * Set the class loader used to instantiate objects for this stream.
173.64 + * Creates a new decoder to parse XML archives
173.65 + * created by the {@code XMLEncoder} class.
173.66 + * If the input source {@code is} is {@code null},
173.67 + * no exception is thrown and no parsing is performed.
173.68 + * This behavior is similar to behavior of other constructors
173.69 + * that use {@code InputStream} as a parameter.
173.70 *
173.71 - * @param cl a classloader to use; if null then the default class loader
173.72 - * will be used
173.73 + * @param is the input source to parse
173.74 + *
173.75 + * @since 1.7
173.76 */
173.77 - private void setClassLoader(ClassLoader cl) {
173.78 - if (cl != null) {
173.79 - this.clref = new WeakReference(cl);
173.80 - }
173.81 + public XMLDecoder(InputSource is) {
173.82 + this(is, null, null, null);
173.83 }
173.84
173.85 /**
173.86 - * Return the class loader used to instantiate objects. If the class loader
173.87 - * has not been explicitly set then null is returned.
173.88 + * Creates a new decoder to parse XML archives
173.89 + * created by the {@code XMLEncoder} class.
173.90 *
173.91 - * @return the class loader used to instantiate objects
173.92 + * @param is the input source to parse
173.93 + * @param owner the owner of this decoder
173.94 + * @param el the exception handler for the parser,
173.95 + * or {@code null} to use the default exception handler
173.96 + * @param cl the class loader used for instantiating objects,
173.97 + * or {@code null} to use the default class loader
173.98 + *
173.99 + * @since 1.7
173.100 */
173.101 - private ClassLoader getClassLoader() {
173.102 - if (clref != null) {
173.103 - return (ClassLoader)clref.get();
173.104 - }
173.105 - return null;
173.106 + private XMLDecoder(InputSource is, Object owner, ExceptionListener el, ClassLoader cl) {
173.107 + this.input = is;
173.108 + this.owner = owner;
173.109 + setExceptionListener(el);
173.110 + this.handler.setClassLoader(cl);
173.111 + this.handler.setOwner(this);
173.112 }
173.113
173.114 /**
173.115 @@ -163,8 +167,14 @@
173.116 * with this stream.
173.117 */
173.118 public void close() {
173.119 + if (parsingComplete()) {
173.120 + close(this.input.getCharacterStream());
173.121 + close(this.input.getByteStream());
173.122 + }
173.123 + }
173.124 +
173.125 + private void close(Closeable in) {
173.126 if (in != null) {
173.127 - getHandler();
173.128 try {
173.129 in.close();
173.130 }
173.131 @@ -174,6 +184,17 @@
173.132 }
173.133 }
173.134
173.135 + private boolean parsingComplete() {
173.136 + if (this.input == null) {
173.137 + return false;
173.138 + }
173.139 + if (this.array == null) {
173.140 + this.handler.parse(this.input);
173.141 + this.array = this.handler.getObjects();
173.142 + }
173.143 + return true;
173.144 + }
173.145 +
173.146 /**
173.147 * Sets the exception handler for this stream to <code>exceptionListener</code>.
173.148 * The exception handler is notified when this stream catches recoverable
173.149 @@ -185,7 +206,10 @@
173.150 * @see #getExceptionListener
173.151 */
173.152 public void setExceptionListener(ExceptionListener exceptionListener) {
173.153 - this.exceptionListener = exceptionListener;
173.154 + if (exceptionListener == null) {
173.155 + exceptionListener = Statement.defaultExceptionListener;
173.156 + }
173.157 + this.handler.setExceptionListener(exceptionListener);
173.158 }
173.159
173.160 /**
173.161 @@ -197,8 +221,7 @@
173.162 * @see #setExceptionListener
173.163 */
173.164 public ExceptionListener getExceptionListener() {
173.165 - return (exceptionListener != null) ? exceptionListener :
173.166 - Statement.defaultExceptionListener;
173.167 + return this.handler.getExceptionListener();
173.168 }
173.169
173.170 /**
173.171 @@ -212,10 +235,9 @@
173.172 * @see XMLEncoder#writeObject
173.173 */
173.174 public Object readObject() {
173.175 - if (in == null) {
173.176 - return null;
173.177 - }
173.178 - return getHandler().dequeueResult();
173.179 + return (parsingComplete())
173.180 + ? this.array[this.index++]
173.181 + : null;
173.182 }
173.183
173.184 /**
173.185 @@ -241,33 +263,32 @@
173.186 }
173.187
173.188 /**
173.189 - * Returns the object handler for input stream.
173.190 - * The object handler is created if necessary.
173.191 + * Creates a new handler for SAX parser
173.192 + * that can be used to parse embedded XML archives
173.193 + * created by the {@code XMLEncoder} class.
173.194 *
173.195 - * @return the object handler
173.196 + * The {@code owner} should be used if parsed XML document contains
173.197 + * the method call within context of the <java> element.
173.198 + * The {@code null} value may cause illegal parsing in such case.
173.199 + * The same problem may occur, if the {@code owner} class
173.200 + * does not contain expected method to call. See details <a
173.201 + * href="http://java.sun.com/products/jfc/tsc/articles/persistence3/">here</a>.
173.202 + *
173.203 + * @param owner the owner of the default handler
173.204 + * that can be used as a value of <java> element
173.205 + * @param el the exception handler for the parser,
173.206 + * or {@code null} to use the default exception handler
173.207 + * @param cl the class loader used for instantiating objects,
173.208 + * or {@code null} to use the default class loader
173.209 + * @return an instance of {@code DefaultHandler} for SAX parser
173.210 + *
173.211 + * @since 1.7
173.212 */
173.213 - private ObjectHandler getHandler() {
173.214 - if ( handler == null ) {
173.215 - SAXParserFactory factory = SAXParserFactory.newInstance();
173.216 - try {
173.217 - SAXParser parser = factory.newSAXParser();
173.218 - handler = new ObjectHandler( this, getClassLoader() );
173.219 - parser.parse( in, handler );
173.220 - }
173.221 - catch ( ParserConfigurationException e ) {
173.222 - getExceptionListener().exceptionThrown( e );
173.223 - }
173.224 - catch ( SAXException se ) {
173.225 - Exception e = se.getException();
173.226 - if ( e == null ) {
173.227 - e = se;
173.228 - }
173.229 - getExceptionListener().exceptionThrown( e );
173.230 - }
173.231 - catch ( IOException ioe ) {
173.232 - getExceptionListener().exceptionThrown( ioe );
173.233 - }
173.234 - }
173.235 + public static DefaultHandler createHandler(Object owner, ExceptionListener el, ClassLoader cl) {
173.236 + DocumentHandler handler = new DocumentHandler();
173.237 + handler.setOwner(owner);
173.238 + handler.setExceptionListener(el);
173.239 + handler.setClassLoader(cl);
173.240 return handler;
173.241 }
173.242 }
174.1 --- a/src/share/classes/java/util/Calendar.java Thu Jan 29 21:46:48 2009 -0800
174.2 +++ b/src/share/classes/java/util/Calendar.java Tue Feb 03 22:02:55 2009 -0800
174.3 @@ -1190,7 +1190,9 @@
174.4 */
174.5 public void set(int field, int value)
174.6 {
174.7 - if (isLenient() && areFieldsSet && !areAllFieldsSet) {
174.8 + // If the fields are partially normalized, calculate all the
174.9 + // fields before changing any fields.
174.10 + if (areFieldsSet && !areAllFieldsSet) {
174.11 computeFields();
174.12 }
174.13 internalSet(field, value);
175.1 --- a/src/share/classes/java/util/CurrencyData.properties Thu Jan 29 21:46:48 2009 -0800
175.2 +++ b/src/share/classes/java/util/CurrencyData.properties Tue Feb 03 22:02:55 2009 -0800
175.3 @@ -441,12 +441,16 @@
175.4 RU=RUB
175.5 # RWANDA
175.6 RW=RWF
175.7 +# SAINT BARTHELEMY
175.8 +BL=EUR
175.9 # SAINT HELENA
175.10 SH=SHP
175.11 # SAINT KITTS AND NEVIS
175.12 KN=XCD
175.13 # SAINT LUCIA
175.14 LC=XCD
175.15 +# SAINT MARTIN
175.16 +MF=EUR
175.17 # SAINT PIERRE AND MIQUELON
175.18 PM=EUR
175.19 # SAINT VINCENT AND THE GRENADINES
176.1 --- a/src/share/classes/java/util/LocaleISOData.java Thu Jan 29 21:46:48 2009 -0800
176.2 +++ b/src/share/classes/java/util/LocaleISOData.java Tue Feb 03 22:02:55 2009 -0800
176.3 @@ -250,6 +250,7 @@
176.4 + "BH" + "BHR" // Bahrain, Kingdom of
176.5 + "BI" + "BDI" // Burundi, Republic of
176.6 + "BJ" + "BEN" // Benin, People's Republic of
176.7 + + "BL" + "BLM" // Saint Barth\u00e9lemy
176.8 + "BM" + "BMU" // Bermuda
176.9 + "BN" + "BRN" // Brunei Darussalam
176.10 + "BO" + "BOL" // Bolivia, Republic of
176.11 @@ -273,7 +274,7 @@
176.12 + "CN" + "CHN" // China, People's Republic of
176.13 + "CO" + "COL" // Colombia, Republic of
176.14 + "CR" + "CRI" // Costa Rica, Republic of
176.15 - + "CS" + "SCG" // Serbia and Montenegro
176.16 +// + "CS" + "SCG" // Serbia and Montenegro
176.17 + "CU" + "CUB" // Cuba, Republic of
176.18 + "CV" + "CPV" // Cape Verde, Republic of
176.19 + "CX" + "CXR" // Christmas Island
176.20 @@ -363,6 +364,7 @@
176.21 + "MC" + "MCO" // Monaco, Principality of
176.22 + "MD" + "MDA" // Moldova, Republic of
176.23 + "ME" + "MNE" // Montenegro, Republic of
176.24 + + "MF" + "MAF" // Saint Martin
176.25 + "MG" + "MDG" // Madagascar, Republic of
176.26 + "MH" + "MHL" // Marshall Islands
176.27 + "MK" + "MKD" // Macedonia, the former Yugoslav Republic of
177.1 --- a/src/share/classes/javax/swing/ImageIcon.java Thu Jan 29 21:46:48 2009 -0800
177.2 +++ b/src/share/classes/javax/swing/ImageIcon.java Tue Feb 03 22:02:55 2009 -0800
177.3 @@ -86,7 +86,7 @@
177.4
177.5 static {
177.6 component = new Component() {};
177.7 - AccessController.doPrivileged(new PrivilegedAction() {
177.8 + AccessController.doPrivileged(new PrivilegedAction<Object>() {
177.9 public Object run() {
177.10 try {
177.11 // 6482575 - clear the appContext field so as not to leak it
178.1 --- a/src/share/classes/javax/swing/ProgressMonitor.java Thu Jan 29 21:46:48 2009 -0800
178.2 +++ b/src/share/classes/javax/swing/ProgressMonitor.java Tue Feb 03 22:02:55 2009 -0800
178.3 @@ -78,7 +78,7 @@
178.4 * @author James Gosling
178.5 * @author Lynn Monsanto (accessibility)
178.6 */
178.7 -public class ProgressMonitor extends Object implements Accessible
178.8 +public class ProgressMonitor implements Accessible
178.9 {
178.10 private ProgressMonitor root;
178.11 private JDialog dialog;
178.12 @@ -186,7 +186,7 @@
178.13 }
178.14 if (window instanceof SwingUtilities.SharedOwnerFrame) {
178.15 WindowListener ownerShutdownListener =
178.16 - (WindowListener)SwingUtilities.getSharedOwnerFrameShutdownListener();
178.17 + SwingUtilities.getSharedOwnerFrameShutdownListener();
178.18 dialog.addWindowListener(ownerShutdownListener);
178.19 }
178.20 Container contentPane = dialog.getContentPane();
178.21 @@ -273,7 +273,7 @@
178.22 if (dT >= millisToDecideToPopup) {
178.23 int predictedCompletionTime;
178.24 if (nv > min) {
178.25 - predictedCompletionTime = (int)((long)dT *
178.26 + predictedCompletionTime = (int)(dT *
178.27 (max - min) /
178.28 (nv - min));
178.29 }
178.30 @@ -691,10 +691,7 @@
178.31 * object does not have an Accessible parent
178.32 */
178.33 public Accessible getAccessibleParent() {
178.34 - if (dialog != null) {
178.35 - return (Accessible)dialog;
178.36 - }
178.37 - return null;
178.38 + return dialog;
178.39 }
178.40
178.41 /*
178.42 @@ -768,7 +765,7 @@
178.43 if (myBar != null) {
178.44 Component c = myBar.getParent();
178.45 if (c instanceof Accessible) {
178.46 - return ((Accessible)c).getAccessibleContext();
178.47 + return c.getAccessibleContext();
178.48 }
178.49 }
178.50 return null;
179.1 --- a/src/share/classes/javax/swing/RepaintManager.java Thu Jan 29 21:46:48 2009 -0800
179.2 +++ b/src/share/classes/javax/swing/RepaintManager.java Tue Feb 03 22:02:55 2009 -0800
179.3 @@ -1305,9 +1305,12 @@
179.4 if (doubleBufferingEnabled && !nativeDoubleBuffering) {
179.5 switch (bufferStrategyType) {
179.6 case BUFFER_STRATEGY_NOT_SPECIFIED:
179.7 - if (((SunToolkit)Toolkit.getDefaultToolkit()).
179.8 - useBufferPerWindow()) {
179.9 - paintManager = new BufferStrategyPaintManager();
179.10 + Toolkit tk = Toolkit.getDefaultToolkit();
179.11 + if (tk instanceof SunToolkit) {
179.12 + SunToolkit stk = (SunToolkit) tk;
179.13 + if (stk.useBufferPerWindow()) {
179.14 + paintManager = new BufferStrategyPaintManager();
179.15 + }
179.16 }
179.17 break;
179.18 case BUFFER_STRATEGY_SPECIFIED_ON:
179.19 @@ -1329,9 +1332,16 @@
179.20
179.21 private void scheduleProcessingRunnable(AppContext context) {
179.22 if (processingRunnable.markPending()) {
179.23 - SunToolkit.getSystemEventQueueImplPP(context).
179.24 - postEvent(new InvocationEvent(Toolkit.getDefaultToolkit(),
179.25 - processingRunnable));
179.26 + Toolkit tk = Toolkit.getDefaultToolkit();
179.27 + if (tk instanceof SunToolkit) {
179.28 + SunToolkit.getSystemEventQueueImplPP(context).
179.29 + postEvent(new InvocationEvent(Toolkit.getDefaultToolkit(),
179.30 + processingRunnable));
179.31 + } else {
179.32 + Toolkit.getDefaultToolkit().getSystemEventQueue().
179.33 + postEvent(new InvocationEvent(Toolkit.getDefaultToolkit(),
179.34 + processingRunnable));
179.35 + }
179.36 }
179.37 }
179.38
180.1 --- a/src/share/classes/javax/swing/SwingWorker.java Thu Jan 29 21:46:48 2009 -0800
180.2 +++ b/src/share/classes/javax/swing/SwingWorker.java Tue Feb 03 22:02:55 2009 -0800
180.3 @@ -282,7 +282,7 @@
180.4 * is finished.
180.5 */
180.6 DONE
180.7 - };
180.8 + }
180.9
180.10 /**
180.11 * Constructs this {@code SwingWorker}.
180.12 @@ -825,7 +825,7 @@
180.13 }
180.14 private static class DoSubmitAccumulativeRunnable
180.15 extends AccumulativeRunnable<Runnable> implements ActionListener {
180.16 - private final static int DELAY = (int) (1000 / 30);
180.17 + private final static int DELAY = 1000 / 30;
180.18 @Override
180.19 protected void run(List<Runnable> args) {
180.20 for (Runnable runnable : args) {
181.1 --- a/src/share/classes/javax/swing/colorchooser/AbstractColorChooserPanel.java Thu Jan 29 21:46:48 2009 -0800
181.2 +++ b/src/share/classes/javax/swing/colorchooser/AbstractColorChooserPanel.java Tue Feb 03 22:02:55 2009 -0800
181.3 @@ -26,6 +26,8 @@
181.4 package javax.swing.colorchooser;
181.5
181.6 import java.awt.*;
181.7 +import java.beans.PropertyChangeEvent;
181.8 +import java.beans.PropertyChangeListener;
181.9 import javax.swing.*;
181.10
181.11 /**
181.12 @@ -47,6 +49,15 @@
181.13 */
181.14 public abstract class AbstractColorChooserPanel extends JPanel {
181.15
181.16 + private final PropertyChangeListener enabledListener = new PropertyChangeListener() {
181.17 + public void propertyChange(PropertyChangeEvent event) {
181.18 + Object value = event.getNewValue();
181.19 + if (value instanceof Boolean) {
181.20 + setEnabled((Boolean) value);
181.21 + }
181.22 + }
181.23 + };
181.24 +
181.25 /**
181.26 *
181.27 */
181.28 @@ -142,6 +153,8 @@
181.29 throw new RuntimeException ("This chooser panel is already installed");
181.30 }
181.31 chooser = enclosingChooser;
181.32 + chooser.addPropertyChangeListener("enabled", enabledListener);
181.33 + setEnabled(chooser.isEnabled());
181.34 buildChooser();
181.35 updateChooser();
181.36 }
181.37 @@ -151,6 +164,7 @@
181.38 * If override this, be sure to call <code>super</code>.
181.39 */
181.40 public void uninstallChooserPanel(JColorChooser enclosingChooser) {
181.41 + chooser.removePropertyChangeListener("enabled", enabledListener);
181.42 chooser = null;
181.43 }
181.44
182.1 --- a/src/share/classes/javax/swing/colorchooser/ColorChooserPanel.java Thu Jan 29 21:46:48 2009 -0800
182.2 +++ b/src/share/classes/javax/swing/colorchooser/ColorChooserPanel.java Tue Feb 03 22:02:55 2009 -0800
182.3 @@ -26,6 +26,8 @@
182.4 package javax.swing.colorchooser;
182.5
182.6 import java.awt.Color;
182.7 +import java.awt.Component;
182.8 +import java.awt.Container;
182.9 import java.awt.GridBagConstraints;
182.10 import java.awt.GridBagLayout;
182.11 import java.beans.PropertyChangeEvent;
182.12 @@ -57,6 +59,21 @@
182.13 }
182.14
182.15 @Override
182.16 + public void setEnabled(boolean enabled) {
182.17 + super.setEnabled(enabled);
182.18 + setEnabled(this, enabled);
182.19 + }
182.20 +
182.21 + private static void setEnabled(Container container, boolean enabled) {
182.22 + for (Component component : container.getComponents()) {
182.23 + component.setEnabled(enabled);
182.24 + if (component instanceof Container) {
182.25 + setEnabled((Container) component, enabled);
182.26 + }
182.27 + }
182.28 + }
182.29 +
182.30 + @Override
182.31 public void updateChooser() {
182.32 Color color = getColorFromModel();
182.33 if (color != null) {
183.1 --- a/src/share/classes/javax/swing/colorchooser/DefaultColorSelectionModel.java Thu Jan 29 21:46:48 2009 -0800
183.2 +++ b/src/share/classes/javax/swing/colorchooser/DefaultColorSelectionModel.java Tue Feb 03 22:02:55 2009 -0800
183.3 @@ -128,8 +128,7 @@
183.4 * @since 1.4
183.5 */
183.6 public ChangeListener[] getChangeListeners() {
183.7 - return (ChangeListener[])listenerList.getListeners(
183.8 - ChangeListener.class);
183.9 + return listenerList.getListeners(ChangeListener.class);
183.10 }
183.11
183.12 /**
184.1 --- a/src/share/classes/javax/swing/colorchooser/DefaultSwatchChooserPanel.java Thu Jan 29 21:46:48 2009 -0800
184.2 +++ b/src/share/classes/javax/swing/colorchooser/DefaultSwatchChooserPanel.java Tue Feb 03 22:02:55 2009 -0800
184.3 @@ -170,7 +170,6 @@
184.4 superHolder.add(mainHolder, gbc);
184.5 gbc.insets = oldInsets;
184.6
184.7 - recentSwatchPanel.addMouseListener(recentSwatchListener);
184.8 recentSwatchPanel.setInheritsPopupMenu(true);
184.9 JPanel recentHolder = new JPanel( new BorderLayout() );
184.10 recentHolder.setBorder(border);
184.11 @@ -212,16 +211,20 @@
184.12
184.13 class RecentSwatchListener extends MouseAdapter implements Serializable {
184.14 public void mousePressed(MouseEvent e) {
184.15 - Color color = recentSwatchPanel.getColorForLocation(e.getX(), e.getY());
184.16 - setSelectedColor(color);
184.17 + if (isEnabled()) {
184.18 + Color color = recentSwatchPanel.getColorForLocation(e.getX(), e.getY());
184.19 + setSelectedColor(color);
184.20 + }
184.21 }
184.22 }
184.23
184.24 class MainSwatchListener extends MouseAdapter implements Serializable {
184.25 public void mousePressed(MouseEvent e) {
184.26 - Color color = swatchPanel.getColorForLocation(e.getX(), e.getY());
184.27 - setSelectedColor(color);
184.28 - recentSwatchPanel.setMostRecentColor(color);
184.29 + if (isEnabled()) {
184.30 + Color color = swatchPanel.getColorForLocation(e.getX(), e.getY());
184.31 + setSelectedColor(color);
184.32 + recentSwatchPanel.setMostRecentColor(color);
184.33 + }
184.34 }
184.35 }
184.36
185.1 --- a/src/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java Thu Jan 29 21:46:48 2009 -0800
185.2 +++ b/src/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java Tue Feb 03 22:02:55 2009 -0800
185.3 @@ -1132,13 +1132,18 @@
185.4 private void changeDirectory(File dir) {
185.5 JFileChooser fc = getFileChooser();
185.6 // Traverse shortcuts on Windows
185.7 - if (dir != null && File.separatorChar == '\\' && dir.getPath().endsWith(".lnk")) {
185.8 + if (dir != null && FilePane.usesShellFolder(fc)) {
185.9 try {
185.10 - File linkedTo = ShellFolder.getShellFolder(dir).getLinkLocation();
185.11 - if (linkedTo != null && fc.isTraversable(linkedTo)) {
185.12 - dir = linkedTo;
185.13 - } else {
185.14 - return;
185.15 + ShellFolder shellFolder = ShellFolder.getShellFolder(dir);
185.16 +
185.17 + if (shellFolder.isLink()) {
185.18 + File linkedTo = shellFolder.getLinkLocation();
185.19 +
185.20 + if (linkedTo != null && fc.isTraversable(linkedTo)) {
185.21 + dir = linkedTo;
185.22 + } else {
185.23 + return;
185.24 + }
185.25 }
185.26 } catch (FileNotFoundException ex) {
185.27 return;
186.1 --- a/src/share/classes/javax/swing/plaf/basic/BasicSliderUI.java Thu Jan 29 21:46:48 2009 -0800
186.2 +++ b/src/share/classes/javax/swing/plaf/basic/BasicSliderUI.java Tue Feb 03 22:02:55 2009 -0800
186.3 @@ -836,18 +836,24 @@
186.4 */
186.5 protected Integer getHighestValue() {
186.6 Dictionary dictionary = slider.getLabelTable();
186.7 - if (dictionary != null) {
186.8 - Enumeration keys = dictionary.keys();
186.9 - int max = slider.getMinimum() - 1;
186.10 - while (keys.hasMoreElements()) {
186.11 - max = Math.max(max, ((Integer)keys.nextElement()).intValue());
186.12 +
186.13 + if (dictionary == null) {
186.14 + return null;
186.15 + }
186.16 +
186.17 + Enumeration keys = dictionary.keys();
186.18 +
186.19 + Integer max = null;
186.20 +
186.21 + while (keys.hasMoreElements()) {
186.22 + Integer i = (Integer) keys.nextElement();
186.23 +
186.24 + if (max == null || i > max) {
186.25 + max = i;
186.26 }
186.27 - if (max == slider.getMinimum() - 1) {
186.28 - return null;
186.29 - }
186.30 - return max;
186.31 }
186.32 - return null;
186.33 +
186.34 + return max;
186.35 }
186.36
186.37 /**
186.38 @@ -859,18 +865,24 @@
186.39 */
186.40 protected Integer getLowestValue() {
186.41 Dictionary dictionary = slider.getLabelTable();
186.42 - if (dictionary != null) {
186.43 - Enumeration keys = dictionary.keys();
186.44 - int min = slider.getMaximum() + 1;
186.45 - while (keys.hasMoreElements()) {
186.46 - min = Math.min(min, ((Integer)keys.nextElement()).intValue());
186.47 +
186.48 + if (dictionary == null) {
186.49 + return null;
186.50 + }
186.51 +
186.52 + Enumeration keys = dictionary.keys();
186.53 +
186.54 + Integer min = null;
186.55 +
186.56 + while (keys.hasMoreElements()) {
186.57 + Integer i = (Integer) keys.nextElement();
186.58 +
186.59 + if (min == null || i < min) {
186.60 + min = i;
186.61 }
186.62 - if (min == slider.getMaximum() + 1) {
186.63 - return null;
186.64 - }
186.65 - return min;
186.66 }
186.67 - return null;
186.68 +
186.69 + return min;
186.70 }
186.71
186.72
187.1 --- a/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java Thu Jan 29 21:46:48 2009 -0800
187.2 +++ b/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java Tue Feb 03 22:02:55 2009 -0800
187.3 @@ -68,8 +68,6 @@
187.4 private JToggleButton listViewButton;
187.5 private JToggleButton detailsViewButton;
187.6
187.7 - private boolean useShellFolder;
187.8 -
187.9 private JButton approveButton;
187.10 private JButton cancelButton;
187.11
187.12 @@ -204,10 +202,6 @@
187.13 public ListSelectionListener createListSelectionListener() {
187.14 return MetalFileChooserUI.this.createListSelectionListener(getFileChooser());
187.15 }
187.16 -
187.17 - public boolean usesShellFolder() {
187.18 - return useShellFolder;
187.19 - }
187.20 }
187.21
187.22 public void installComponents(JFileChooser fc) {
187.23 @@ -219,8 +213,6 @@
187.24 filePane = new FilePane(new MetalFileChooserUIAccessor());
187.25 fc.addPropertyChangeListener(filePane);
187.26
187.27 - updateUseShellFolder();
187.28 -
187.29 // ********************************* //
187.30 // **** Construct the top panel **** //
187.31 // ********************************* //
187.32 @@ -448,19 +440,6 @@
187.33 groupLabels(new AlignedLabel[] { fileNameLabel, filesOfTypeLabel });
187.34 }
187.35
187.36 - private void updateUseShellFolder() {
187.37 - // Decide whether to use the ShellFolder class to populate shortcut
187.38 - // panel and combobox.
187.39 - JFileChooser fc = getFileChooser();
187.40 - Boolean prop =
187.41 - (Boolean)fc.getClientProperty("FileChooser.useShellFolder");
187.42 - if (prop != null) {
187.43 - useShellFolder = prop.booleanValue();
187.44 - } else {
187.45 - useShellFolder = fc.getFileSystemView().equals(FileSystemView.getFileSystemView());
187.46 - }
187.47 - }
187.48 -
187.49 protected JPanel getButtonPanel() {
187.50 if (buttonPanel == null) {
187.51 buttonPanel = new JPanel();
187.52 @@ -786,7 +765,6 @@
187.53 cc.applyComponentOrientation(o);
187.54 }
187.55 } else if (s == "FileChooser.useShellFolder") {
187.56 - updateUseShellFolder();
187.57 doDirectoryChanged(e);
187.58 } else if (s.equals("ancestor")) {
187.59 if (e.getOldValue() == null && e.getNewValue() != null) {
187.60 @@ -953,6 +931,8 @@
187.61 return;
187.62 }
187.63
187.64 + boolean useShellFolder = FilePane.usesShellFolder(chooser);
187.65 +
187.66 directories.clear();
187.67
187.68 File[] baseFolders;
188.1 --- a/src/share/classes/javax/swing/plaf/synth/SynthParser.java Thu Jan 29 21:46:48 2009 -0800
188.2 +++ b/src/share/classes/javax/swing/plaf/synth/SynthParser.java Tue Feb 03 22:02:55 2009 -0800
188.3 @@ -59,16 +59,16 @@
188.4 import javax.xml.parsers.SAXParser;
188.5 import javax.xml.parsers.SAXParserFactory;
188.6
188.7 -import org.xml.sax.AttributeList;
188.8 -import org.xml.sax.HandlerBase;
188.9 +import org.xml.sax.Attributes;
188.10 import org.xml.sax.InputSource;
188.11 import org.xml.sax.Locator;
188.12 import org.xml.sax.SAXException;
188.13 import org.xml.sax.SAXParseException;
188.14 +import org.xml.sax.helpers.DefaultHandler;
188.15
188.16 -import com.sun.beans.ObjectHandler;
188.17 +import com.sun.beans.decoder.DocumentHandler;
188.18
188.19 -class SynthParser extends HandlerBase {
188.20 +class SynthParser extends DefaultHandler {
188.21 //
188.22 // Known element names
188.23 //
188.24 @@ -119,7 +119,7 @@
188.25 /**
188.26 * Lazily created, used for anything we don't understand.
188.27 */
188.28 - private ObjectHandler _handler;
188.29 + private DocumentHandler _handler;
188.30
188.31 /**
188.32 * Indicates the depth of how many elements we've encountered but don't
188.33 @@ -292,8 +292,9 @@
188.34 /**
188.35 * Handles beans persistance.
188.36 */
188.37 - private ObjectHandler getHandler() {
188.38 + private DocumentHandler getHandler() {
188.39 if (_handler == null) {
188.40 + _handler = new DocumentHandler();
188.41 if (_urlResourceBase != null) {
188.42 // getHandler() is never called before parse() so it is safe
188.43 // to create a URLClassLoader with _resourceBase.
188.44 @@ -304,14 +305,13 @@
188.45 URL[] urls = new URL[] { getResource(".") };
188.46 ClassLoader parent = Thread.currentThread().getContextClassLoader();
188.47 ClassLoader urlLoader = new URLClassLoader(urls, parent);
188.48 - _handler = new ObjectHandler(null, urlLoader);
188.49 + _handler.setClassLoader(urlLoader);
188.50 } else {
188.51 - _handler = new ObjectHandler(null,
188.52 - _classResourceBase.getClassLoader());
188.53 + _handler.setClassLoader(_classResourceBase.getClassLoader());
188.54 }
188.55
188.56 for (String key : _mapping.keySet()) {
188.57 - _handler.register(key, _mapping.get(key));
188.58 + _handler.setVariable(key, _mapping.get(key));
188.59 }
188.60 }
188.61 return _handler;
188.62 @@ -336,8 +336,8 @@
188.63 private Object lookup(String key, Class type) throws SAXException {
188.64 Object value;
188.65 if (_handler != null) {
188.66 - if ((value = _handler.lookup(key)) != null) {
188.67 - return checkCast(value, type);
188.68 + if (_handler.hasVariable(key)) {
188.69 + return checkCast(_handler.getVariable(key), type);
188.70 }
188.71 }
188.72 value = _mapping.get(key);
188.73 @@ -354,11 +354,11 @@
188.74 private void register(String key, Object value) throws SAXException {
188.75 if (key != null) {
188.76 if (_mapping.get(key) != null ||
188.77 - (_handler != null && _handler.lookup(key) != null)) {
188.78 + (_handler != null && _handler.hasVariable(key))) {
188.79 throw new SAXException("ID " + key + " is already defined");
188.80 }
188.81 if (_handler != null) {
188.82 - _handler.register(key, value);
188.83 + _handler.setVariable(key, value);
188.84 }
188.85 else {
188.86 _mapping.put(key, value);
188.87 @@ -400,12 +400,12 @@
188.88 // The following methods are invoked from startElement/stopElement
188.89 //
188.90
188.91 - private void startStyle(AttributeList attributes) throws SAXException {
188.92 + private void startStyle(Attributes attributes) throws SAXException {
188.93 String id = null;
188.94
188.95 _style = null;
188.96 for(int i = attributes.getLength() - 1; i >= 0; i--) {
188.97 - String key = attributes.getName(i);
188.98 + String key = attributes.getQName(i);
188.99 if (key.equals(ATTRIBUTE_CLONE)) {
188.100 _style = (ParsedSynthStyle)((ParsedSynthStyle)lookup(
188.101 attributes.getValue(i), ParsedSynthStyle.class)).
188.102 @@ -421,7 +421,7 @@
188.103 register(id, _style);
188.104 }
188.105
188.106 - private void endStyle() throws SAXException {
188.107 + private void endStyle() {
188.108 int size = _stylePainters.size();
188.109 if (size > 0) {
188.110 _style.setPainters(_stylePainters.toArray(new ParsedSynthStyle.PainterInfo[size]));
188.111 @@ -435,14 +435,14 @@
188.112 _style = null;
188.113 }
188.114
188.115 - private void startState(AttributeList attributes) throws SAXException {
188.116 + private void startState(Attributes attributes) throws SAXException {
188.117 ParsedSynthStyle.StateInfo stateInfo = null;
188.118 int state = 0;
188.119 String id = null;
188.120
188.121 _stateInfo = null;
188.122 for(int i = attributes.getLength() - 1; i >= 0; i--) {
188.123 - String key = attributes.getName(i);
188.124 + String key = attributes.getQName(i);
188.125 if (key.equals(ATTRIBUTE_ID)) {
188.126 id = attributes.getValue(i);
188.127 }
188.128 @@ -496,7 +496,7 @@
188.129 _stateInfos.add(_stateInfo);
188.130 }
188.131
188.132 - private void endState() throws SAXException {
188.133 + private void endState() {
188.134 int size = _statePainters.size();
188.135 if (size > 0) {
188.136 _stateInfo.setPainters(_statePainters.toArray(new ParsedSynthStyle.PainterInfo[size]));
188.137 @@ -505,7 +505,7 @@
188.138 _stateInfo = null;
188.139 }
188.140
188.141 - private void startFont(AttributeList attributes) throws SAXException {
188.142 + private void startFont(Attributes attributes) throws SAXException {
188.143 Font font = null;
188.144 int style = Font.PLAIN;
188.145 int size = 0;
188.146 @@ -513,7 +513,7 @@
188.147 String name = null;
188.148
188.149 for(int i = attributes.getLength() - 1; i >= 0; i--) {
188.150 - String key = attributes.getName(i);
188.151 + String key = attributes.getQName(i);
188.152 if (key.equals(ATTRIBUTE_ID)) {
188.153 id = attributes.getValue(i);
188.154 }
188.155 @@ -568,13 +568,13 @@
188.156 }
188.157 }
188.158
188.159 - private void startColor(AttributeList attributes) throws SAXException {
188.160 + private void startColor(Attributes attributes) throws SAXException {
188.161 Color color = null;
188.162 String id = null;
188.163
188.164 _colorTypes.clear();
188.165 for(int i = attributes.getLength() - 1; i >= 0; i--) {
188.166 - String key = attributes.getName(i);
188.167 + String key = attributes.getQName(i);
188.168 if (key.equals(ATTRIBUTE_ID)) {
188.169 id = attributes.getValue(i);
188.170 }
188.171 @@ -697,7 +697,7 @@
188.172 }
188.173 }
188.174
188.175 - private void startProperty(AttributeList attributes,
188.176 + private void startProperty(Attributes attributes,
188.177 Object property) throws SAXException {
188.178 Object value = null;
188.179 String key = null;
188.180 @@ -707,7 +707,7 @@
188.181 String aValue = null;
188.182
188.183 for(int i = attributes.getLength() - 1; i >= 0; i--) {
188.184 - String aName = attributes.getName(i);
188.185 + String aName = attributes.getQName(i);
188.186 if (aName.equals(ATTRIBUTE_TYPE)) {
188.187 String type = attributes.getValue(i).toUpperCase();
188.188 if (type.equals("IDREF")) {
188.189 @@ -795,11 +795,11 @@
188.190 }
188.191 }
188.192
188.193 - private void startGraphics(AttributeList attributes) throws SAXException {
188.194 + private void startGraphics(Attributes attributes) throws SAXException {
188.195 SynthGraphicsUtils graphics = null;
188.196
188.197 for(int i = attributes.getLength() - 1; i >= 0; i--) {
188.198 - String key = attributes.getName(i);
188.199 + String key = attributes.getQName(i);
188.200 if (key.equals(ATTRIBUTE_IDREF)) {
188.201 graphics = (SynthGraphicsUtils)lookup(attributes.getValue(i),
188.202 SynthGraphicsUtils.class);
188.203 @@ -813,7 +813,7 @@
188.204 }
188.205 }
188.206
188.207 - private void startInsets(AttributeList attributes) throws SAXException {
188.208 + private void startInsets(Attributes attributes) throws SAXException {
188.209 int top = 0;
188.210 int bottom = 0;
188.211 int left = 0;
188.212 @@ -822,7 +822,7 @@
188.213 String id = null;
188.214
188.215 for(int i = attributes.getLength() - 1; i >= 0; i--) {
188.216 - String key = attributes.getName(i);
188.217 + String key = attributes.getQName(i);
188.218
188.219 try {
188.220 if (key.equals(ATTRIBUTE_IDREF)) {
188.221 @@ -858,13 +858,13 @@
188.222 }
188.223 }
188.224
188.225 - private void startBind(AttributeList attributes) throws SAXException {
188.226 + private void startBind(Attributes attributes) throws SAXException {
188.227 ParsedSynthStyle style = null;
188.228 String path = null;
188.229 int type = -1;
188.230
188.231 for(int i = attributes.getLength() - 1; i >= 0; i--) {
188.232 - String key = attributes.getName(i);
188.233 + String key = attributes.getQName(i);
188.234
188.235 if (key.equals(ATTRIBUTE_STYLE)) {
188.236 style = (ParsedSynthStyle)lookup(attributes.getValue(i),
188.237 @@ -899,7 +899,7 @@
188.238 }
188.239 }
188.240
188.241 - private void startPainter(AttributeList attributes, String type) throws SAXException {
188.242 + private void startPainter(Attributes attributes, String type) throws SAXException {
188.243 Insets sourceInsets = null;
188.244 Insets destInsets = null;
188.245 String path = null;
188.246 @@ -915,7 +915,7 @@
188.247 boolean paintCenterSpecified = false;
188.248
188.249 for(int i = attributes.getLength() - 1; i >= 0; i--) {
188.250 - String key = attributes.getName(i);
188.251 + String key = attributes.getQName(i);
188.252 String value = attributes.getValue(i);
188.253
188.254 if (key.equals(ATTRIBUTE_ID)) {
188.255 @@ -1042,12 +1042,12 @@
188.256 painters.add(painterInfo);
188.257 }
188.258
188.259 - private void startImageIcon(AttributeList attributes) throws SAXException {
188.260 + private void startImageIcon(Attributes attributes) throws SAXException {
188.261 String path = null;
188.262 String id = null;
188.263
188.264 for(int i = attributes.getLength() - 1; i >= 0; i--) {
188.265 - String key = attributes.getName(i);
188.266 + String key = attributes.getQName(i);
188.267
188.268 if (key.equals(ATTRIBUTE_ID)) {
188.269 id = attributes.getValue(i);
188.270 @@ -1062,12 +1062,11 @@
188.271 register(id, new LazyImageIcon(getResource(path)));
188.272 }
188.273
188.274 - private void startOpaque(AttributeList attributes) throws
188.275 - SAXException {
188.276 + private void startOpaque(Attributes attributes) {
188.277 if (_style != null) {
188.278 _style.setOpaque(true);
188.279 for(int i = attributes.getLength() - 1; i >= 0; i--) {
188.280 - String key = attributes.getName(i);
188.281 + String key = attributes.getQName(i);
188.282
188.283 if (key.equals(ATTRIBUTE_VALUE)) {
188.284 _style.setOpaque("true".equals(attributes.getValue(i).
188.285 @@ -1077,12 +1076,12 @@
188.286 }
188.287 }
188.288
188.289 - private void startInputMap(AttributeList attributes) throws SAXException {
188.290 + private void startInputMap(Attributes attributes) throws SAXException {
188.291 _inputMapBindings.clear();
188.292 _inputMapID = null;
188.293 if (_style != null) {
188.294 for(int i = attributes.getLength() - 1; i >= 0; i--) {
188.295 - String key = attributes.getName(i);
188.296 + String key = attributes.getQName(i);
188.297
188.298 if (key.equals(ATTRIBUTE_ID)) {
188.299 _inputMapID = attributes.getValue(i);
188.300 @@ -1101,7 +1100,7 @@
188.301 _inputMapID = null;
188.302 }
188.303
188.304 - private void startBindKey(AttributeList attributes) throws SAXException {
188.305 + private void startBindKey(Attributes attributes) throws SAXException {
188.306 if (_inputMapID == null) {
188.307 // Not in an inputmap, bail.
188.308 return;
188.309 @@ -1110,7 +1109,7 @@
188.310 String key = null;
188.311 String value = null;
188.312 for(int i = attributes.getLength() - 1; i >= 0; i--) {
188.313 - String aKey = attributes.getName(i);
188.314 + String aKey = attributes.getQName(i);
188.315
188.316 if (aKey.equals(ATTRIBUTE_KEY)) {
188.317 key = attributes.getValue(i);
188.318 @@ -1129,26 +1128,26 @@
188.319 }
188.320
188.321 //
188.322 - // SAX methods, these forward to the ObjectHandler if we don't know
188.323 + // SAX methods, these forward to the DocumentHandler if we don't know
188.324 // the element name.
188.325 //
188.326
188.327 public InputSource resolveEntity(String publicId, String systemId)
188.328 - throws SAXException {
188.329 + throws IOException, SAXException {
188.330 if (isForwarding()) {
188.331 return getHandler().resolveEntity(publicId, systemId);
188.332 }
188.333 return null;
188.334 }
188.335
188.336 - public void notationDecl(String name, String publicId, String systemId) {
188.337 + public void notationDecl(String name, String publicId, String systemId) throws SAXException {
188.338 if (isForwarding()) {
188.339 getHandler().notationDecl(name, publicId, systemId);
188.340 }
188.341 }
188.342
188.343 public void unparsedEntityDecl(String name, String publicId,
188.344 - String systemId, String notationName) {
188.345 + String systemId, String notationName) throws SAXException {
188.346 if (isForwarding()) {
188.347 getHandler().unparsedEntityDecl(name, publicId, systemId,
188.348 notationName);
188.349 @@ -1173,7 +1172,7 @@
188.350 }
188.351 }
188.352
188.353 - public void startElement(String name, AttributeList attributes)
188.354 + public void startElement(String uri, String local, String name, Attributes attributes)
188.355 throws SAXException {
188.356 name = name.intern();
188.357 if (name == ELEMENT_STYLE) {
188.358 @@ -1223,18 +1222,18 @@
188.359 }
188.360 else if (name != ELEMENT_SYNTH) {
188.361 if (_depth++ == 0) {
188.362 - getHandler().reset();
188.363 + getHandler().startDocument();
188.364 }
188.365 - getHandler().startElement(name, attributes);
188.366 + getHandler().startElement(uri, local, name, attributes);
188.367 }
188.368 }
188.369
188.370 - public void endElement(String name) throws SAXException {
188.371 + public void endElement(String uri, String local, String name) throws SAXException {
188.372 if (isForwarding()) {
188.373 - getHandler().endElement(name);
188.374 + getHandler().endElement(uri, local, name);
188.375 _depth--;
188.376 if (!isForwarding()) {
188.377 - getHandler().reset();
188.378 + getHandler().startDocument();
188.379 }
188.380 }
188.381 else {
189.1 --- a/src/share/classes/javax/swing/table/DefaultTableColumnModel.java Thu Jan 29 21:46:48 2009 -0800
189.2 +++ b/src/share/classes/javax/swing/table/DefaultTableColumnModel.java Tue Feb 03 22:02:55 2009 -0800
189.3 @@ -190,7 +190,7 @@
189.4 fireColumnMoved(new TableColumnModelEvent(this, columnIndex, newIndex));
189.5 return;
189.6 }
189.7 - aColumn = (TableColumn)tableColumns.elementAt(columnIndex);
189.8 + aColumn = tableColumns.elementAt(columnIndex);
189.9
189.10 tableColumns.removeElementAt(columnIndex);
189.11 boolean selected = selectionModel.isSelectedIndex(columnIndex);
189.12 @@ -291,7 +291,7 @@
189.13 * at <code>columnIndex</code>
189.14 */
189.15 public TableColumn getColumn(int columnIndex) {
189.16 - return (TableColumn)tableColumns.elementAt(columnIndex);
189.17 + return tableColumns.elementAt(columnIndex);
189.18 }
189.19
189.20 /**
189.21 @@ -504,8 +504,7 @@
189.22 * @since 1.4
189.23 */
189.24 public TableColumnModelListener[] getColumnModelListeners() {
189.25 - return (TableColumnModelListener[])listenerList.getListeners(
189.26 - TableColumnModelListener.class);
189.27 + return listenerList.getListeners(TableColumnModelListener.class);
189.28 }
189.29
189.30 //
190.1 --- a/src/share/classes/javax/swing/tree/DefaultMutableTreeNode.java Thu Jan 29 21:46:48 2009 -0800
190.2 +++ b/src/share/classes/javax/swing/tree/DefaultMutableTreeNode.java Tue Feb 03 22:02:55 2009 -0800
190.3 @@ -84,7 +84,7 @@
190.4 *
190.5 * @author Rob Davis
190.6 */
190.7 -public class DefaultMutableTreeNode extends Object implements Cloneable,
190.8 +public class DefaultMutableTreeNode implements Cloneable,
190.9 MutableTreeNode, Serializable
190.10 {
190.11 private static final long serialVersionUID = -4298474751201349152L;
190.12 @@ -1251,7 +1251,7 @@
190.13 * @return a copy of this node
190.14 */
190.15 public Object clone() {
190.16 - DefaultMutableTreeNode newNode = null;
190.17 + DefaultMutableTreeNode newNode;
190.18
190.19 try {
190.20 newNode = (DefaultMutableTreeNode)super.clone();
190.21 @@ -1297,24 +1297,22 @@
190.22 userObject = tValues[1];
190.23 }
190.24
190.25 - final class PreorderEnumeration implements Enumeration<TreeNode> {
190.26 - protected Stack stack;
190.27 + private final class PreorderEnumeration implements Enumeration<TreeNode> {
190.28 + private final Stack<Enumeration> stack = new Stack<Enumeration>();
190.29
190.30 public PreorderEnumeration(TreeNode rootNode) {
190.31 super();
190.32 - Vector v = new Vector(1);
190.33 + Vector<TreeNode> v = new Vector<TreeNode>(1);
190.34 v.addElement(rootNode); // PENDING: don't really need a vector
190.35 - stack = new Stack();
190.36 stack.push(v.elements());
190.37 }
190.38
190.39 public boolean hasMoreElements() {
190.40 - return (!stack.empty() &&
190.41 - ((Enumeration)stack.peek()).hasMoreElements());
190.42 + return (!stack.empty() && stack.peek().hasMoreElements());
190.43 }
190.44
190.45 public TreeNode nextElement() {
190.46 - Enumeration enumer = (Enumeration)stack.peek();
190.47 + Enumeration enumer = stack.peek();
190.48 TreeNode node = (TreeNode)enumer.nextElement();
190.49 Enumeration children = node.children();
190.50
190.51 @@ -1353,8 +1351,7 @@
190.52 if (subtree.hasMoreElements()) {
190.53 retval = subtree.nextElement();
190.54 } else if (children.hasMoreElements()) {
190.55 - subtree = new PostorderEnumeration(
190.56 - (TreeNode)children.nextElement());
190.57 + subtree = new PostorderEnumeration(children.nextElement());
190.58 retval = subtree.nextElement();
190.59 } else {
190.60 retval = root;
190.61 @@ -1373,7 +1370,7 @@
190.62
190.63 public BreadthFirstEnumeration(TreeNode rootNode) {
190.64 super();
190.65 - Vector v = new Vector(1);
190.66 + Vector<TreeNode> v = new Vector<TreeNode>(1);
190.67 v.addElement(rootNode); // PENDING: don't really need a vector
190.68 queue = new Queue();
190.69 queue.enqueue(v.elements());
191.1 --- a/src/share/classes/javax/swing/undo/CompoundEdit.java Thu Jan 29 21:46:48 2009 -0800
191.2 +++ b/src/share/classes/javax/swing/undo/CompoundEdit.java Tue Feb 03 22:02:55 2009 -0800
191.3 @@ -59,7 +59,7 @@
191.4 super.undo();
191.5 int i = edits.size();
191.6 while (i-- > 0) {
191.7 - UndoableEdit e = (UndoableEdit)edits.elementAt(i);
191.8 + UndoableEdit e = edits.elementAt(i);
191.9 e.undo();
191.10 }
191.11 }
191.12 @@ -85,7 +85,7 @@
191.13 protected UndoableEdit lastEdit() {
191.14 int count = edits.size();
191.15 if (count > 0)
191.16 - return (UndoableEdit)edits.elementAt(count-1);
191.17 + return edits.elementAt(count-1);
191.18 else
191.19 return null;
191.20 }
191.21 @@ -98,7 +98,7 @@
191.22 int size = edits.size();
191.23 for (int i = size-1; i >= 0; i--)
191.24 {
191.25 - UndoableEdit e = (UndoableEdit)edits.elementAt(i);
191.26 + UndoableEdit e = edits.elementAt(i);
191.27 // System.out.println("CompoundEdit(" + i + "): Discarding " +
191.28 // e.getUndoPresentationName());
191.29 e.die();
192.1 --- a/src/share/classes/sun/beans/editors/EnumEditor.java Thu Jan 29 21:46:48 2009 -0800
192.2 +++ b/src/share/classes/sun/beans/editors/EnumEditor.java Tue Feb 03 22:02:55 2009 -0800
192.3 @@ -67,7 +67,7 @@
192.4 }
192.5
192.6 public void setValue( Object value ) {
192.7 - if ( ( value != null ) && ( this.type != value.getClass() ) ) {
192.8 + if ( ( value != null ) && !this.type.isInstance( value ) ) {
192.9 throw new IllegalArgumentException( "Unsupported value: " + value );
192.10 }
192.11 Object oldValue;
193.1 --- a/src/share/classes/sun/swing/FilePane.java Thu Jan 29 21:46:48 2009 -0800
193.2 +++ b/src/share/classes/sun/swing/FilePane.java Tue Feb 03 22:02:55 2009 -0800
193.3 @@ -689,7 +689,7 @@
193.4
193.5 void updateColumnInfo() {
193.6 File dir = chooser.getCurrentDirectory();
193.7 - if (dir != null && fileChooserUIAccessor.usesShellFolder()) {
193.8 + if (dir != null && usesShellFolder(chooser)) {
193.9 try {
193.10 dir = ShellFolder.getShellFolder(dir);
193.11 } catch (FileNotFoundException e) {
193.12 @@ -1947,7 +1947,7 @@
193.13 if (f instanceof ShellFolder) {
193.14 return ((ShellFolder) f).isFileSystem();
193.15 } else {
193.16 - if (fileChooserUIAccessor.usesShellFolder()) {
193.17 + if (usesShellFolder(getFileChooser())) {
193.18 try {
193.19 return ShellFolder.getShellFolder(f).isFileSystem();
193.20 } catch (FileNotFoundException ex) {
193.21 @@ -1961,6 +1961,16 @@
193.22 }
193.23 }
193.24
193.25 + /**
193.26 + * Returns true if specified FileChooser should use ShellFolder
193.27 + */
193.28 + public static boolean usesShellFolder(JFileChooser chooser) {
193.29 + Boolean prop = (Boolean) chooser.getClientProperty("FileChooser.useShellFolder");
193.30 +
193.31 + return prop == null ? chooser.getFileSystemView().equals(FileSystemView.getFileSystemView())
193.32 + : prop.booleanValue();
193.33 + }
193.34 +
193.35 // This interface is used to access methods in the FileChooserUI
193.36 // that are not public.
193.37 public interface FileChooserUIAccessor {
193.38 @@ -1975,6 +1985,5 @@
193.39 public Action getNewFolderAction();
193.40 public MouseListener createDoubleClickListener(JList list);
193.41 public ListSelectionListener createListSelectionListener();
193.42 - public boolean usesShellFolder();
193.43 }
193.44 }
194.1 --- a/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java Thu Jan 29 21:46:48 2009 -0800
194.2 +++ b/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java Tue Feb 03 22:02:55 2009 -0800
194.3 @@ -71,8 +71,6 @@
194.4 private JToggleButton listViewButton;
194.5 private JToggleButton detailsViewButton;
194.6
194.7 - private boolean useShellFolder;
194.8 -
194.9 private boolean readOnly;
194.10
194.11 private JPanel buttonPanel;
194.12 @@ -185,10 +183,6 @@
194.13 public ListSelectionListener createListSelectionListener() {
194.14 return SynthFileChooserUIImpl.this.createListSelectionListener(getFileChooser());
194.15 }
194.16 -
194.17 - public boolean usesShellFolder() {
194.18 - return useShellFolder;
194.19 - }
194.20 }
194.21
194.22 protected void installDefaults(JFileChooser fc) {
194.23 @@ -201,8 +195,6 @@
194.24
194.25 SynthContext context = getContext(fc, ENABLED);
194.26
194.27 - updateUseShellFolder();
194.28 -
194.29 fc.setLayout(new BorderLayout(0, 11));
194.30
194.31 // ********************************* //
194.32 @@ -432,20 +424,6 @@
194.33 super.uninstallListeners(fc);
194.34 }
194.35
194.36 - private void updateUseShellFolder() {
194.37 - // Decide whether to use the ShellFolder class to populate shortcut
194.38 - // panel and combobox.
194.39 - JFileChooser fc = getFileChooser();
194.40 - Boolean prop =
194.41 - (Boolean)fc.getClientProperty("FileChooser.useShellFolder");
194.42 - if (prop != null) {
194.43 - useShellFolder = prop.booleanValue();
194.44 - } else {
194.45 - useShellFolder = fc.getFileSystemView().equals(FileSystemView.getFileSystemView());
194.46 - }
194.47 - }
194.48 -
194.49 -
194.50 private String fileNameString(File file) {
194.51 if (file == null) {
194.52 return null;
194.53 @@ -761,6 +739,8 @@
194.54 return;
194.55 }
194.56
194.57 + boolean useShellFolder = FilePane.usesShellFolder(chooser);
194.58 +
194.59 int oldSize = directories.size();
194.60 directories.clear();
194.61 if (oldSize > 0) {
195.1 --- a/src/share/classes/sun/text/resources/FormatData_th.java Thu Jan 29 21:46:48 2009 -0800
195.2 +++ b/src/share/classes/sun/text/resources/FormatData_th.java Tue Feb 03 22:02:55 2009 -0800
195.3 @@ -47,6 +47,19 @@
195.4 * Overrides ListResourceBundle
195.5 */
195.6 protected final Object[][] getContents() {
195.7 + String[] dateTimePatterns = new String[] {
195.8 + "H' \u0e19\u0e32\u0e2c\u0e34\u0e01\u0e32 'm' \u0e19\u0e32\u0e17\u0e35 'ss' \u0e27\u0e34\u0e19\u0e32\u0e17\u0e35'", // full time pattern
195.9 + "H' \u0e19\u0e32\u0e2c\u0e34\u0e01\u0e32 'm' \u0e19\u0e32\u0e17\u0e35'", // long time pattern
195.10 + "H:mm:ss", // medium time pattern
195.11 + "H:mm' \u0e19.'", // short time pattern (modified) -- add ' \u0e19.'
195.12 + // (it means something like "o'clock" in english)
195.13 + "EEEE'\u0e17\u0e35\u0e48 'd MMMM G yyyy", // full date pattern
195.14 + "d MMMM yyyy", // long date pattern
195.15 + "d MMM yyyy", // medium date pattern
195.16 + "d/M/yyyy", // short date pattern
195.17 + "{1}, {0}" // date-time pattern
195.18 + };
195.19 +
195.20 return new Object[][] {
195.21 { "MonthNames",
195.22 new String[] {
195.23 @@ -129,18 +142,10 @@
195.24 }
195.25 },
195.26 { "sun.util.BuddhistCalendar.DateTimePatterns",
195.27 - new String[] {
195.28 - "H' \u0e19\u0e32\u0e2c\u0e34\u0e01\u0e32 'm' \u0e19\u0e32\u0e17\u0e35 'ss' \u0e27\u0e34\u0e19\u0e32\u0e17\u0e35'", // full time pattern
195.29 - "H' \u0e19\u0e32\u0e2c\u0e34\u0e01\u0e32 'm' \u0e19\u0e32\u0e17\u0e35'", // long time pattern
195.30 - "H:mm:ss", // medium time pattern
195.31 - "H:mm' \u0e19.'", // short time pattern (modified) -- add ' \u0e19.'
195.32 - // (it means something like "o'clock" in english)
195.33 - "EEEE'\u0e17\u0e35\u0e48 'd MMMM G yyyy", // full date pattern
195.34 - "d MMMM yyyy", // long date pattern
195.35 - "d MMM yyyy", // medium date pattern
195.36 - "d/M/yyyy", // short date pattern
195.37 - "{1}, {0}" // date-time pattern
195.38 - }
195.39 + dateTimePatterns
195.40 + },
195.41 + { "DateTimePatterns",
195.42 + dateTimePatterns
195.43 },
195.44 { "DateTimePatternChars", "GanjkHmsSEDFwWxhKzZ" },
195.45 };
196.1 --- a/src/share/classes/sun/util/resources/LocaleNames.properties Thu Jan 29 21:46:48 2009 -0800
196.2 +++ b/src/share/classes/sun/util/resources/LocaleNames.properties Tue Feb 03 22:02:55 2009 -0800
196.3 @@ -257,6 +257,7 @@
196.4 BH=Bahrain
196.5 BI=Burundi
196.6 BJ=Benin
196.7 +BL=Saint Barth\u00e9lemy
196.8 BM=Bermuda
196.9 BN=Brunei
196.10 BO=Bolivia
196.11 @@ -370,6 +371,7 @@
196.12 MC=Monaco
196.13 MD=Moldova
196.14 ME=Montenegro
196.15 +MF=Saint Martin
196.16 MG=Madagascar
196.17 MH=Marshall Islands
196.18 MK=Macedonia
197.1 --- a/src/share/classes/sun/util/resources/TimeZoneNames.java Thu Jan 29 21:46:48 2009 -0800
197.2 +++ b/src/share/classes/sun/util/resources/TimeZoneNames.java Tue Feb 03 22:02:55 2009 -0800
197.3 @@ -141,6 +141,8 @@
197.4 "Malaysia Summer Time", "MYST"};
197.5 String NORONHA[] = new String[] {"Fernando de Noronha Time", "FNT",
197.6 "Fernando de Noronha Summer Time", "FNST"};
197.7 + String NPT[] = new String[] {"Nepal Time", "NPT",
197.8 + "Nepal Summer Time", "NPST"};
197.9 String NST[] = new String[] {"Newfoundland Standard Time", "NST",
197.10 "Newfoundland Daylight Time", "NDT"};
197.11 String NZST[] = new String[] {"New Zealand Standard Time", "NZST",
197.12 @@ -151,6 +153,8 @@
197.13 "Pakistan Summer Time", "PKST"};
197.14 String PST[] = new String[] {"Pacific Standard Time", "PST",
197.15 "Pacific Daylight Time", "PDT"};
197.16 + String RST[] = new String[] {"Eastern Standard Time", "EST",
197.17 + "Central Daylight Time", "CDT"};
197.18 String SAST[] = new String[] {"South Africa Standard Time", "SAST",
197.19 "South Africa Summer Time", "SAST"};
197.20 String SBT[] = new String[] {"Solomon Is. Time", "SBT",
197.21 @@ -290,6 +294,7 @@
197.22 {"America/Argentina/La_Rioja", AGT},
197.23 {"America/Argentina/Mendoza", AGT},
197.24 {"America/Argentina/Rio_Gallegos", AGT},
197.25 + {"America/Argentina/Salta", AGT},
197.26 {"America/Argentina/San_Juan", AGT},
197.27 {"America/Argentina/San_Luis", AGT},
197.28 {"America/Argentina/Tucuman", AGT},
197.29 @@ -407,7 +412,7 @@
197.30 {"America/Rankin_Inlet", CST},
197.31 {"America/Recife", BRT},
197.32 {"America/Regina", CST},
197.33 - {"America/Resolute", EST},
197.34 + {"America/Resolute", RST},
197.35 {"America/Rio_Branco", AMT},
197.36 {"America/Rosario", AGT},
197.37 {"America/Santarem", BRT},
197.38 @@ -505,8 +510,8 @@
197.39 "Petropavlovsk-Kamchatski Summer Time", "PETST"}},
197.40 {"Asia/Karachi", PKT},
197.41 {"Asia/Kashgar", CTT},
197.42 - {"Asia/Katmandu", new String[] {"Nepal Time", "NPT",
197.43 - "Nepal Summer Time", "NPST"}},
197.44 + {"Asia/Kathmandu", NPT},
197.45 + {"Asia/Katmandu", NPT},
197.46 {"Asia/Kolkata", IST},
197.47 {"Asia/Krasnoyarsk", new String[] {"Krasnoyarsk Time", "KRAT",
197.48 "Krasnoyarsk Summer Time", "KRAST"}},
198.1 --- a/src/share/classes/sun/util/resources/TimeZoneNames_de.java Thu Jan 29 21:46:48 2009 -0800
198.2 +++ b/src/share/classes/sun/util/resources/TimeZoneNames_de.java Tue Feb 03 22:02:55 2009 -0800
198.3 @@ -141,6 +141,8 @@
198.4 "Malaysische Sommerzeit", "MYST"};
198.5 String NORONHA[] = new String[] {"Fernando de Noronha Zeit", "FNT",
198.6 "Fernando de Noronha Sommerzeit", "FNST"};
198.7 + String NPT[] = new String[] {"Nepalesische Zeit", "NPT",
198.8 + "Nepalesische Sommerzeit", "NPST"};
198.9 String NST[] = new String[] {"Neufundland Normalzeit", "NST",
198.10 "Neufundland Sommerzeit", "NDT"};
198.11 String NZST[] = new String[] {"Neuseeland Normalzeit", "NZST",
198.12 @@ -151,6 +153,8 @@
198.13 "Pakistanische Sommerzeit", "PKST"};
198.14 String PST[] = new String[] {"Pazifische Normalzeit", "PST",
198.15 "Pazifische Sommerzeit", "PDT"};
198.16 + String RST[] = new String[] {"\u00d6stliche Normalzeit", "EST",
198.17 + "Zentrale Sommerzeit", "CDT"};
198.18 String SAST[] = new String[] {"S\u00fcdafrikanische Normalzeit", "SAST",
198.19 "S\u00fcdafrikanische Sommerzeit", "SAST"};
198.20 String SBT[] = new String[] {"Salomoninseln Zeit", "SBT",
198.21 @@ -290,6 +294,7 @@
198.22 {"America/Argentina/La_Rioja", AGT},
198.23 {"America/Argentina/Mendoza", AGT},
198.24 {"America/Argentina/Rio_Gallegos", AGT},
198.25 + {"America/Argentina/Salta", AGT},
198.26 {"America/Argentina/San_Juan", AGT},
198.27 {"America/Argentina/San_Luis", AGT},
198.28 {"America/Argentina/Tucuman", AGT},
198.29 @@ -407,7 +412,7 @@
198.30 {"America/Rankin_Inlet", CST},
198.31 {"America/Recife", BRT},
198.32 {"America/Regina", CST},
198.33 - {"America/Resolute", EST},
198.34 + {"America/Resolute", RST},
198.35 {"America/Rio_Branco", AMT},
198.36 {"America/Rosario", AGT},
198.37 {"America/Santarem", BRT},
198.38 @@ -505,8 +510,8 @@
198.39 "Petropawlowsk-Kamtschatkische Sommerzeit", "PETST"}},
198.40 {"Asia/Karachi", PKT},
198.41 {"Asia/Kashgar", CTT},
198.42 - {"Asia/Katmandu", new String[] {"Nepalesische Zeit", "NPT",
198.43 - "Nepalesische Sommerzeit", "NPST"}},
198.44 + {"Asia/Kathmandu", NPT},
198.45 + {"Asia/Katmandu", NPT},
198.46 {"Asia/Kolkata", IST},
198.47 {"Asia/Krasnoyarsk", new String[] {"Krasnojarsker Zeit", "KRAT",
198.48 "Krasnojarsker Sommerzeit", "KRAST"}},
199.1 --- a/src/share/classes/sun/util/resources/TimeZoneNames_es.java Thu Jan 29 21:46:48 2009 -0800
199.2 +++ b/src/share/classes/sun/util/resources/TimeZoneNames_es.java Tue Feb 03 22:02:55 2009 -0800
199.3 @@ -141,6 +141,8 @@
199.4 "Hora de verano de Malasia", "MYST"};
199.5 String NORONHA[] = new String[] {"Hora de Fernando de Noronha", "FNT",
199.6 "Hora de verano de Fernando de Noronha", "FNST"};
199.7 + String NPT[] = new String[] {"Hora de Nepal", "NPT",
199.8 + "Hora de verano de Nepal", "NPST"};
199.9 String NST[] = new String[] {"Hora est\u00e1ndar de Terranova", "NST",
199.10 "Hora de verano de Terranova", "NDT"};
199.11 String NZST[] = new String[] {"Hora est\u00e1ndar de Nueva Zelanda", "NZST",
199.12 @@ -151,6 +153,8 @@
199.13 "Hora de verano de Pakist\u00e1n", "PKST"};
199.14 String PST[] = new String[] {"Hora est\u00e1ndar del Pac\u00edfico", "PST",
199.15 "Hora de verano del Pac\u00edfico", "PDT"};
199.16 + String RST[] = new String[] {"Hora est\u00e1ndar Oriental", "EST",
199.17 + "Hora de verano Central", "CDT"};
199.18 String SAST[] = new String[] {"Hora est\u00e1ndar de Sud\u00e1frica", "SAST",
199.19 "Hora de verano de Sud\u00e1frica", "SAST"};
199.20 String SBT[] = new String[] {"Hora de las Islas Solomon", "SBT",
199.21 @@ -290,6 +294,7 @@
199.22 {"America/Argentina/La_Rioja", AGT},
199.23 {"America/Argentina/Mendoza", AGT},
199.24 {"America/Argentina/Rio_Gallegos", AGT},
199.25 + {"America/Argentina/Salta", AGT},
199.26 {"America/Argentina/San_Juan", AGT},
199.27 {"America/Argentina/San_Luis", AGT},
199.28 {"America/Argentina/Tucuman", AGT},
199.29 @@ -407,7 +412,7 @@
199.30 {"America/Rankin_Inlet", CST},
199.31 {"America/Recife", BRT},
199.32 {"America/Regina", CST},
199.33 - {"America/Resolute", EST},
199.34 + {"America/Resolute", RST},
199.35 {"America/Rio_Branco", AMT},
199.36 {"America/Rosario", AGT},
199.37 {"America/Santarem", BRT},
199.38 @@ -505,8 +510,8 @@
199.39 "Hora de verano de Petropavlovsk-Kamchatski", "PETST"}},
199.40 {"Asia/Karachi", PKT},
199.41 {"Asia/Kashgar", CTT},
199.42 - {"Asia/Katmandu", new String[] {"Hora de Nepal", "NPT",
199.43 - "Hora de verano de Nepal", "NPST"}},
199.44 + {"Asia/Kathmandu", NPT},
199.45 + {"Asia/Katmandu", NPT},
199.46 {"Asia/Kolkata", IST},
199.47 {"Asia/Krasnoyarsk", new String[] {"Hora de Krasnoyarsk", "KRAT",
199.48 "Hora de verano de Krasnoyarsk", "KRAST"}},
200.1 --- a/src/share/classes/sun/util/resources/TimeZoneNames_fr.java Thu Jan 29 21:46:48 2009 -0800
200.2 +++ b/src/share/classes/sun/util/resources/TimeZoneNames_fr.java Tue Feb 03 22:02:55 2009 -0800
200.3 @@ -141,6 +141,8 @@
200.4 "Heure d'\u00e9t\u00e9 de Malaisie", "MYST"};
200.5 String NORONHA[] = new String[] {"Heure de Fernando de Noronha", "FNT",
200.6 "Heure d'\u00e9t\u00e9 de Fernando de Noronha", "FNST"};
200.7 + String NPT[] = new String[] {"Heure du N\u00e9pal", "NPT",
200.8 + "Heure d'\u00e9t\u00e9 du N\u00e9pal", "NPST"};
200.9 String NST[] = new String[] {"Heure normale de Terre-Neuve", "NST",
200.10 "Heure avanc\u00e9e de Terre-Neuve", "NDT"} ;
200.11 String NZST[] = new String[] {"Heure normale de Nouvelle-Z\u00e9lande", "NZST",
200.12 @@ -151,6 +153,8 @@
200.13 "Heure d'\u00e9t\u00e9 du Pakistan", "PKST"} ;
200.14 String PST[] = new String[] {"Heure normale du Pacifique", "PST",
200.15 "Heure avanc\u00e9e du Pacifique", "PDT"} ;
200.16 + String RST[] = new String[] {"Heure normale de l'Est", "EST",
200.17 + "Heure avanc\u00e9e du Centre", "CDT"} ;
200.18 String SAST[] = new String[] {"Heure normale d'Afrique du Sud", "SAST",
200.19 "Heure d'\u00e9t\u00e9 d'Afrique du Sud", "SAST"} ;
200.20 String SBT[] = new String[] {"Heure des \u00celes Salomon", "SBT",
200.21 @@ -290,6 +294,7 @@
200.22 {"America/Argentina/La_Rioja", AGT},
200.23 {"America/Argentina/Mendoza", AGT},
200.24 {"America/Argentina/Rio_Gallegos", AGT},
200.25 + {"America/Argentina/Salta", AGT},
200.26 {"America/Argentina/San_Juan", AGT},
200.27 {"America/Argentina/San_Luis", AGT},
200.28 {"America/Argentina/Tucuman", AGT},
200.29 @@ -407,7 +412,7 @@
200.30 {"America/Rankin_Inlet", CST},
200.31 {"America/Recife", BRT},
200.32 {"America/Regina", CST},
200.33 - {"America/Resolute", EST},
200.34 + {"America/Resolute", RST},
200.35 {"America/Rio_Branco", AMT},
200.36 {"America/Rosario", AGT},
200.37 {"America/Santarem", BRT},
200.38 @@ -505,8 +510,8 @@
200.39 "Heure d'\u00e9t\u00e9 de Petropavlovsk-Kamchatski", "PETST"}},
200.40 {"Asia/Karachi", PKT},
200.41 {"Asia/Kashgar", CTT},
200.42 - {"Asia/Katmandu", new String[] {"Heure du N\u00e9pal", "NPT",
200.43 - "Heure d'\u00e9t\u00e9 du N\u00e9pal", "NPST"}},
200.44 + {"Asia/Kathmandu", NPT},
200.45 + {"Asia/Katmandu", NPT},
200.46 {"Asia/Kolkata", IST},
200.47 {"Asia/Krasnoyarsk", new String[] {"Heure de Krasno\u00efarsk", "KRAT",
200.48 "Heure d'\u00e9t\u00e9 de Krasno\u00efarsk", "KRAST"}},
201.1 --- a/src/share/classes/sun/util/resources/TimeZoneNames_it.java Thu Jan 29 21:46:48 2009 -0800
201.2 +++ b/src/share/classes/sun/util/resources/TimeZoneNames_it.java Tue Feb 03 22:02:55 2009 -0800
201.3 @@ -141,6 +141,8 @@
201.4 "Ora estiva della Malaysia", "MYST"};
201.5 String NORONHA[] = new String[] {"Ora di Fernando de Noronha", "FNT",
201.6 "Ora estiva di Fernando de Noronha", "FNST"};
201.7 + String NPT[] = new String[] {"Ora del Nepal", "NPT",
201.8 + "Ora estiva del Nepal", "NPST"};
201.9 String NST[] = new String[] {"Ora solare di Terranova", "NST",
201.10 "Ora legale di Terranova", "NDT"};
201.11 String NZST[] = new String[] {"Ora solare della Nuova Zelanda", "NZST",
201.12 @@ -151,6 +153,8 @@
201.13 "Ora estiva del Pakistan", "PKST"};
201.14 String PST[] = new String[] {"Ora solare della costa occidentale USA", "PST",
201.15 "Ora legale della costa occidentale USA", "PDT"};
201.16 + String RST[] = new String[] {"Ora solare USA orientale", "EST",
201.17 + "Ora legale USA centrale", "CDT"};
201.18 String SAST[] = new String[] {"Ora solare del Sudafrica", "SAST",
201.19 "Ora estiva del Sudafrica", "SAST"};
201.20 String SBT[] = new String[] {"Ora delle Isole Salomone", "SBT",
201.21 @@ -290,6 +294,7 @@
201.22 {"America/Argentina/La_Rioja", AGT},
201.23 {"America/Argentina/Mendoza", AGT},
201.24 {"America/Argentina/Rio_Gallegos", AGT},
201.25 + {"America/Argentina/Salta", AGT},
201.26 {"America/Argentina/San_Juan", AGT},
201.27 {"America/Argentina/San_Luis", AGT},
201.28 {"America/Argentina/Tucuman", AGT},
201.29 @@ -407,7 +412,7 @@
201.30 {"America/Rankin_Inlet", CST},
201.31 {"America/Recife", BRT},
201.32 {"America/Regina", CST},
201.33 - {"America/Resolute", EST},
201.34 + {"America/Resolute", RST},
201.35 {"America/Rio_Branco", AMT},
201.36 {"America/Rosario", AGT},
201.37 {"America/Santarem", BRT},
201.38 @@ -505,8 +510,8 @@
201.39 "Ora estiva di Petropavlovsk-Kamchatski", "PETST"}},
201.40 {"Asia/Karachi", PKT},
201.41 {"Asia/Kashgar", CTT},
201.42 - {"Asia/Katmandu", new String[] {"Ora del Nepal", "NPT",
201.43 - "Ora estiva del Nepal", "NPST"}},
201.44 + {"Asia/Kathmandu", NPT},
201.45 + {"Asia/Katmandu", NPT},
201.46 {"Asia/Kolkata", IST},
201.47 {"Asia/Krasnoyarsk", new String[] {"Ora di Krasnojarsk", "KRAT",
201.48 "Ora estiva di Krasnojarsk", "KRAST"}},
202.1 --- a/src/share/classes/sun/util/resources/TimeZoneNames_ja.java Thu Jan 29 21:46:48 2009 -0800
202.2 +++ b/src/share/classes/sun/util/resources/TimeZoneNames_ja.java Tue Feb 03 22:02:55 2009 -0800
202.3 @@ -141,6 +141,8 @@
202.4 "\u30de\u30ec\u30fc\u30b7\u30a2\u590f\u6642\u9593", "MYST"};
202.5 String NORONHA[] = new String[] {"\u30d5\u30a7\u30eb\u30ca\u30f3\u30c9\u30fb\u30c7\u30fb\u30ce\u30ed\u30fc\u30cb\u30e3\u6642\u9593", "FNT",
202.6 "\u30d5\u30a7\u30eb\u30ca\u30f3\u30c9\u30fb\u30c7\u30fb\u30ce\u30ed\u30fc\u30cb\u30e3\u590f\u6642\u9593", "FNST"};
202.7 + String NPT[] = new String[] {"\u30cd\u30d1\u30fc\u30eb\u6642\u9593", "NPT",
202.8 + "\u30cd\u30d1\u30fc\u30eb\u590f\u6642\u9593", "NPST"};
202.9 String NST[] = new String[] {"\u30cb\u30e5\u30fc\u30d5\u30a1\u30f3\u30c9\u30e9\u30f3\u30c9\u6a19\u6e96\u6642", "NST",
202.10 "\u30cb\u30e5\u30fc\u30d5\u30a1\u30f3\u30c9\u30e9\u30f3\u30c9\u590f\u6642\u9593", "NDT"};
202.11 String NZST[] = new String[] {"\u30cb\u30e5\u30fc\u30b8\u30fc\u30e9\u30f3\u30c9\u6a19\u6e96\u6642", "NZST",
202.12 @@ -151,6 +153,8 @@
202.13 "\u30d1\u30ad\u30b9\u30bf\u30f3\u590f\u6642\u9593", "PKST"};
202.14 String PST[] = new String[] {"\u592a\u5e73\u6d0b\u6a19\u6e96\u6642", "PST",
202.15 "\u592a\u5e73\u6d0b\u590f\u6642\u9593", "PDT"};
202.16 + String RST[] = new String[] {"\u6771\u90e8\u6a19\u6e96\u6642", "EST",
202.17 + "\u4e2d\u90e8\u590f\u6642\u9593", "CDT"};
202.18 String SAST[] = new String[] {"\u5357\u30a2\u30d5\u30ea\u30ab\u6a19\u6e96\u6642", "SAST",
202.19 "\u5357\u30a2\u30d5\u30ea\u30ab\u590f\u6642\u9593", "SAST"};
202.20 String SBT[] = new String[] {"\u30bd\u30ed\u30e2\u30f3\u8af8\u5cf6\u6642\u9593", "SBT",
202.21 @@ -290,6 +294,7 @@
202.22 {"America/Argentina/La_Rioja", AGT},
202.23 {"America/Argentina/Mendoza", AGT},
202.24 {"America/Argentina/Rio_Gallegos", AGT},
202.25 + {"America/Argentina/Salta", AGT},
202.26 {"America/Argentina/San_Juan", AGT},
202.27 {"America/Argentina/San_Luis", AGT},
202.28 {"America/Argentina/Tucuman", AGT},
202.29 @@ -407,7 +412,7 @@
202.30 {"America/Rankin_Inlet", CST},
202.31 {"America/Recife", BRT},
202.32 {"America/Regina", CST},
202.33 - {"America/Resolute", EST},
202.34 + {"America/Resolute", RST},
202.35 {"America/Rio_Branco", AMT},
202.36 {"America/Rosario", AGT},
202.37 {"America/Santarem", BRT},
202.38 @@ -505,8 +510,8 @@
202.39 "\u30da\u30c8\u30ed\u30d1\u30d6\u30ed\u30d5\u30b9\u30af\u30ab\u30e0\u30c1\u30e3\u30c4\u30ad\u30fc\u590f\u6642\u9593", "PETST"}},
202.40 {"Asia/Karachi", PKT},
202.41 {"Asia/Kashgar", CTT},
202.42 - {"Asia/Katmandu", new String[] {"\u30cd\u30d1\u30fc\u30eb\u6642\u9593", "NPT",
202.43 - "\u30cd\u30d1\u30fc\u30eb\u590f\u6642\u9593", "NPST"}},
202.44 + {"Asia/Kathmandu", NPT},
202.45 + {"Asia/Katmandu", NPT},
202.46 {"Asia/Kolkata", IST},
202.47 {"Asia/Krasnoyarsk", new String[] {"\u30af\u30e9\u30b9\u30ce\u30e4\u30eb\u30b9\u30af\u6642\u9593", "KRAT",
202.48 "\u30af\u30e9\u30b9\u30ce\u30e4\u30eb\u30b9\u30af\u590f\u6642\u9593", "KRAST"}},
203.1 --- a/src/share/classes/sun/util/resources/TimeZoneNames_ko.java Thu Jan 29 21:46:48 2009 -0800
203.2 +++ b/src/share/classes/sun/util/resources/TimeZoneNames_ko.java Tue Feb 03 22:02:55 2009 -0800
203.3 @@ -141,6 +141,8 @@
203.4 "\ub9d0\ub808\uc774\uc2dc\uc544 \uc77c\uad11\uc808\uc57d\uc2dc\uac04", "MYST"};
203.5 String NORONHA[] = new String[] {"Fernando de Noronha \uc2dc\uac04", "FNT",
203.6 "Fernando de Noronha \uc77c\uad11\uc808\uc57d\uc2dc\uac04", "FNST"};
203.7 + String NPT[] = new String[] {"\ub124\ud314 \uc2dc\uac04", "NPT",
203.8 + "\ub124\ud314 \uc77c\uad11\uc808\uc57d\uc2dc\uac04", "NPST"};
203.9 String NST[] = new String[] {"\ub274\ud380\ub4e4\ub79c\ub4dc \ud45c\uc900\uc2dc", "NST",
203.10 "\ub274\ud380\ub4e4\ub79c\ub4dc \uc77c\uad11\uc808\uc57d\uc2dc\uac04", "NDT"};
203.11 String NZST[] = new String[] {"\ub274\uc9c8\ub79c\ub4dc \ud45c\uc900\uc2dc", "NZST",
203.12 @@ -151,6 +153,8 @@
203.13 "\ud30c\ud0a4\uc2a4\ud0c4 \uc77c\uad11\uc808\uc57d\uc2dc\uac04", "PKST"};
203.14 String PST[] = new String[] {"\ud0dc\ud3c9\uc591 \ud45c\uc900\uc2dc", "PST",
203.15 "\ud0dc\ud3c9\uc591 \uc77c\uad11\uc808\uc57d\uc2dc\uac04", "PDT"};
203.16 + String RST[] = new String[] {"\ub3d9\ubd80 \ud45c\uc900\uc2dc", "EST",
203.17 + "\uc911\ubd80 \uc77c\uad11\uc808\uc57d\uc2dc\uac04", "CDT"};
203.18 String SAST[] = new String[] {"\ub0a8\uc544\ud504\ub9ac\uce74 \ud45c\uc900\uc2dc", "SAST",
203.19 "\ub0a8\uc544\ud504\ub9ac\uce74 \uc77c\uad11\uc808\uc57d\uc2dc\uac04", "SAST"};
203.20 String SBT[] = new String[] {"\uc194\ub85c\ubaac \uad70\ub3c4 \uc2dc\uac04", "SBT",
203.21 @@ -290,6 +294,7 @@
203.22 {"America/Argentina/La_Rioja", AGT},
203.23 {"America/Argentina/Mendoza", AGT},
203.24 {"America/Argentina/Rio_Gallegos", AGT},
203.25 + {"America/Argentina/Salta", AGT},
203.26 {"America/Argentina/San_Juan", AGT},
203.27 {"America/Argentina/San_Luis", AGT},
203.28 {"America/Argentina/Tucuman", AGT},
203.29 @@ -407,7 +412,7 @@
203.30 {"America/Rankin_Inlet", CST},
203.31 {"America/Recife", BRT},
203.32 {"America/Regina", CST},
203.33 - {"America/Resolute", EST},
203.34 + {"America/Resolute", RST},
203.35 {"America/Rio_Branco", AMT},
203.36 {"America/Rosario", AGT},
203.37 {"America/Santarem", BRT},
203.38 @@ -505,8 +510,8 @@
203.39 "\ud398\ud2b8\ub85c\ud30c\ube14\ub85c\ud504\uc2a4\ud06c-\uce84\ucc28\uce20\ud0a4 \uc77c\uad11\uc808\uc57d\uc2dc\uac04", "PETST"}},
203.40 {"Asia/Karachi", PKT},
203.41 {"Asia/Kashgar", CTT},
203.42 - {"Asia/Katmandu", new String[] {"\ub124\ud314 \uc2dc\uac04", "NPT",
203.43 - "\ub124\ud314 \uc77c\uad11\uc808\uc57d\uc2dc\uac04", "NPST"}},
203.44 + {"Asia/Kathmandu", NPT},
203.45 + {"Asia/Katmandu", NPT},
203.46 {"Asia/Kolkata", IST},
203.47 {"Asia/Krasnoyarsk", new String[] {"\ud06c\ub77c\uc2a4\ub178\uc57c\ub974\uc2a4\ud06c \uc2dc\uac04", "KRAT",
203.48 "\ud06c\ub77c\uc2a4\ub178\uc57c\ub974\uc2a4\ud06c \uc77c\uad11\uc808\uc57d\uc2dc\uac04", "KRAST"}},
204.1 --- a/src/share/classes/sun/util/resources/TimeZoneNames_sv.java Thu Jan 29 21:46:48 2009 -0800
204.2 +++ b/src/share/classes/sun/util/resources/TimeZoneNames_sv.java Tue Feb 03 22:02:55 2009 -0800
204.3 @@ -141,6 +141,8 @@
204.4 "Malaysia, sommartid", "MYST"};
204.5 String NORONHA[] = new String[] {"Fernando de Noronha, normaltid", "FNT",
204.6 "Fernando de Noronha, sommartid", "FNST"};
204.7 + String NPT[] = new String[] {"Nepal, normaltid", "NPT",
204.8 + "Nepal, sommartid", "NPST"};
204.9 String NST[] = new String[] {"Newfoundland, normaltid", "NST",
204.10 "Newfoundland, sommartid", "NDT"};
204.11 String NZST[] = new String[] {"Nya Zeeland, normaltid", "NZST",
204.12 @@ -151,6 +153,8 @@
204.13 "Pakistan, sommartid", "PKST"};
204.14 String PST[] = new String[] {"Stilla havet, normaltid", "PST",
204.15 "Stilla havet, sommartid", "PDT"};
204.16 + String RST[] = new String[] {"Eastern, normaltid", "EST",
204.17 + "Central sommartid", "CDT"};
204.18 String SAST[] = new String[] {"Sydafrika, normaltid", "SAST",
204.19 "Sydafrika, sommartid", "SAST"};
204.20 String SBT[] = new String[] {"Salomon\u00f6arna, normaltid", "SBT",
204.21 @@ -290,6 +294,7 @@
204.22 {"America/Argentina/La_Rioja", AGT},
204.23 {"America/Argentina/Mendoza", AGT},
204.24 {"America/Argentina/Rio_Gallegos", AGT},
204.25 + {"America/Argentina/Salta", AGT},
204.26 {"America/Argentina/San_Juan", AGT},
204.27 {"America/Argentina/San_Luis", AGT},
204.28 {"America/Argentina/Tucuman", AGT},
204.29 @@ -407,7 +412,7 @@
204.30 {"America/Rankin_Inlet", CST},
204.31 {"America/Recife", BRT},
204.32 {"America/Regina", CST},
204.33 - {"America/Resolute", EST},
204.34 + {"America/Resolute", RST},
204.35 {"America/Rio_Branco", AMT},
204.36 {"America/Rosario", AGT},
204.37 {"America/Santarem", BRT},
204.38 @@ -505,8 +510,8 @@
204.39 "Petropavlovsk-Kamtjatka, sommartid", "PETST"}},
204.40 {"Asia/Karachi", PKT},
204.41 {"Asia/Kashgar", CTT},
204.42 - {"Asia/Katmandu", new String[] {"Nepal, normaltid", "NPT",
204.43 - "Nepal, sommartid", "NPST"}},
204.44 + {"Asia/Kathmandu", NPT},
204.45 + {"Asia/Katmandu", NPT},
204.46 {"Asia/Kolkata", IST},
204.47 {"Asia/Krasnoyarsk", new String[] {"Krasnojarsk, normaltid", "KRAT",
204.48 "Krasnojarsk, sommartid", "KRAST"}},
205.1 --- a/src/share/classes/sun/util/resources/TimeZoneNames_zh_CN.java Thu Jan 29 21:46:48 2009 -0800
205.2 +++ b/src/share/classes/sun/util/resources/TimeZoneNames_zh_CN.java Tue Feb 03 22:02:55 2009 -0800
205.3 @@ -141,6 +141,8 @@
205.4 "\u9a6c\u6765\u897f\u4e9a\u590f\u4ee4\u65f6", "MYST"};
205.5 String NORONHA[] = new String[] {"\u8d39\u5c14\u5357\u591a\u5fb7\u8bfa\u7f57\u5c3c\u4e9a\u65f6\u95f4", "FNT",
205.6 "\u8d39\u5c14\u5357\u591a\u5fb7\u8bfa\u7f57\u5c3c\u4e9a\u590f\u4ee4\u65f6", "FNST"};
205.7 + String NPT[] = new String[] {"\u5c3c\u6cca\u5c14\u65f6\u95f4", "NPT",
205.8 + "\u5c3c\u6cca\u5c14\u590f\u4ee4\u65f6", "NPST"};
205.9 String NST[] = new String[] {"\u7ebd\u82ac\u5170\u6807\u51c6\u65f6\u95f4", "NST",
205.10 "\u7ebd\u82ac\u5170\u590f\u4ee4\u65f6", "NDT"};
205.11 String NZST[] = new String[] {"\u65b0\u897f\u5170\u6807\u51c6\u65f6\u95f4", "NZST",
205.12 @@ -151,6 +153,8 @@
205.13 "\u5df4\u57fa\u65af\u5766\u590f\u4ee4\u65f6", "PKST"};
205.14 String PST[] = new String[] {"\u592a\u5e73\u6d0b\u6807\u51c6\u65f6\u95f4", "PST",
205.15 "\u592a\u5e73\u6d0b\u590f\u4ee4\u65f6", "PDT"};
205.16 + String RST[] = new String[] {"\u4e1c\u90e8\u6807\u51c6\u65f6\u95f4", "EST",
205.17 + "\u4e2d\u592e\u590f\u4ee4\u65f6", "CDT"};
205.18 String SAST[] = new String[] {"\u5357\u975e\u6807\u51c6\u65f6\u95f4", "SAST",
205.19 "\u5357\u975e\u590f\u4ee4\u65f6", "SAST"};
205.20 String SBT[] = new String[] {"\u6240\u7f57\u95e8\u7fa4\u5c9b\u65f6\u95f4", "SBT",
205.21 @@ -290,6 +294,7 @@
205.22 {"America/Argentina/La_Rioja", AGT},
205.23 {"America/Argentina/Mendoza", AGT},
205.24 {"America/Argentina/Rio_Gallegos", AGT},
205.25 + {"America/Argentina/Salta", AGT},
205.26 {"America/Argentina/San_Juan", AGT},
205.27 {"America/Argentina/San_Luis", AGT},
205.28 {"America/Argentina/Tucuman", AGT},
205.29 @@ -407,7 +412,7 @@
205.30 {"America/Rankin_Inlet", CST},
205.31 {"America/Recife", BRT},
205.32 {"America/Regina", CST},
205.33 - {"America/Resolute", EST},
205.34 + {"America/Resolute", RST},
205.35 {"America/Rio_Branco", AMT},
205.36 {"America/Rosario", AGT},
205.37 {"America/Santarem", BRT},
205.38 @@ -505,8 +510,8 @@
205.39 "\u5f7c\u5f97\u7f57\u5df4\u752b\u6d1b\u592b\u65af\u514b\u590f\u4ee4\u65f6", "PETST"}},
205.40 {"Asia/Karachi", PKT},
205.41 {"Asia/Kashgar", CTT},
205.42 - {"Asia/Katmandu", new String[] {"\u5c3c\u6cca\u5c14\u65f6\u95f4", "NPT",
205.43 - "\u5c3c\u6cca\u5c14\u590f\u4ee4\u65f6", "NPST"}},
205.44 + {"Asia/Kathmandu", NPT},
205.45 + {"Asia/Katmandu", NPT},
205.46 {"Asia/Kolkata", IST},
205.47 {"Asia/Krasnoyarsk", new String[] {"\u514b\u62c9\u65af\u8bfa\u4e9a\u5c14\u65af\u514b\u65f6\u95f4", "KRAT",
205.48 "\u514b\u62c9\u65af\u8bfa\u4e9a\u5c14\u65af\u514b\u590f\u4ee4\u65f6", "KRAST"}},
206.1 --- a/src/share/classes/sun/util/resources/TimeZoneNames_zh_TW.java Thu Jan 29 21:46:48 2009 -0800
206.2 +++ b/src/share/classes/sun/util/resources/TimeZoneNames_zh_TW.java Tue Feb 03 22:02:55 2009 -0800
206.3 @@ -141,6 +141,8 @@
206.4 "\u99ac\u4f86\u897f\u4e9e\u590f\u4ee4\u6642\u9593", "MYST"};
206.5 String NORONHA[] = new String[] {"\u8cbb\u723e\u5357\u591a-\u8fea\u8afe\u7f85\u5c3c\u4e9e\u6642\u9593", "FNT",
206.6 "\u8cbb\u723e\u5357\u591a-\u8fea\u8afe\u7f85\u5c3c\u4e9e\u590f\u4ee4\u6642\u9593", "FNST"};
206.7 + String NPT[] = new String[] {"\u5c3c\u6cca\u723e\u6642\u9593", "NPT",
206.8 + "\u5c3c\u6cca\u723e\u590f\u4ee4\u6642\u9593", "NPST"};
206.9 String NST[] = new String[] {"\u7d10\u82ac\u862d\u6a19\u6e96\u6642\u9593", "NST",
206.10 "\u7d10\u82ac\u862d\u65e5\u5149\u7bc0\u7d04\u6642\u9593", "NDT"};
206.11 String NZST[] = new String[] {"\u7d10\u897f\u862d\u6a19\u6e96\u6642\u9593", "NZST",
206.12 @@ -151,6 +153,8 @@
206.13 "\u5df4\u57fa\u65af\u5766\u590f\u4ee4\u6642\u9593", "PKST"};
206.14 String PST[] = new String[] {"\u592a\u5e73\u6d0b\u6a19\u6e96\u6642\u9593", "PST",
206.15 "\u592a\u5e73\u6d0b\u65e5\u5149\u7bc0\u7d04\u6642\u9593", "PDT"};
206.16 + String RST[] = new String[] {"\u6771\u65b9\u6a19\u6e96\u6642\u9593", "EST",
206.17 + "\u4e2d\u592e\u65e5\u5149\u7bc0\u7d04\u6642\u9593", "CDT"};
206.18 String SAST[] = new String[] {"\u5357\u975e\u6a19\u6e96\u6642\u9593", "SAST",
206.19 "\u5357\u975e\u590f\u4ee4\u6642\u9593", "SAST"};
206.20 String SBT[] = new String[] {"\u6240\u7f85\u9580\u7fa4\u5cf6\u6642\u9593", "SBT",
206.21 @@ -290,6 +294,7 @@
206.22 {"America/Argentina/La_Rioja", AGT},
206.23 {"America/Argentina/Mendoza", AGT},
206.24 {"America/Argentina/Rio_Gallegos", AGT},
206.25 + {"America/Argentina/Salta", AGT},
206.26 {"America/Argentina/San_Juan", AGT},
206.27 {"America/Argentina/San_Luis", AGT},
206.28 {"America/Argentina/Tucuman", AGT},
206.29 @@ -407,7 +412,7 @@
206.30 {"America/Rankin_Inlet", CST},
206.31 {"America/Recife", BRT},
206.32 {"America/Regina", CST},
206.33 - {"America/Resolute", EST},
206.34 + {"America/Resolute", RST},
206.35 {"America/Rio_Branco", AMT},
206.36 {"America/Rosario", AGT},
206.37 {"America/Santarem", BRT},
206.38 @@ -505,8 +510,8 @@
206.39 "Petropavlovsk-Kamchatski \u590f\u4ee4\u6642\u9593", "PETST"}},
206.40 {"Asia/Karachi", PKT},
206.41 {"Asia/Kashgar", CTT},
206.42 - {"Asia/Katmandu", new String[] {"\u5c3c\u6cca\u723e\u6642\u9593", "NPT",
206.43 - "\u5c3c\u6cca\u723e\u590f\u4ee4\u6642\u9593", "NPST"}},
206.44 + {"Asia/Kathmandu", NPT},
206.45 + {"Asia/Katmandu", NPT},
206.46 {"Asia/Kolkata", IST},
206.47 {"Asia/Krasnoyarsk", new String[] {"\u514b\u62c9\u65af\u8afe\u4e9e\u723e\u65af\u514b\u6642\u9593", "KRAT",
206.48 "\u514b\u62c9\u65af\u8afe\u4e9e\u723e\u65af\u514b\u590f\u4ee4\u6642\u9593", "KRAST"}},
207.1 Binary file src/share/lib/audio/soundbank.gm has changed
208.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
208.2 +++ b/test/java/beans/EventHandler/Test6788531.java Tue Feb 03 22:02:55 2009 -0800
208.3 @@ -0,0 +1,66 @@
208.4 +/*
208.5 + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
208.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
208.7 + *
208.8 + * This code is free software; you can redistribute it and/or modify it
208.9 + * under the terms of the GNU General Public License version 2 only, as
208.10 + * published by the Free Software Foundation.
208.11 + *
208.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
208.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
208.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
208.15 + * version 2 for more details (a copy is included in the LICENSE file that
208.16 + * accompanied this code).
208.17 + *
208.18 + * You should have received a copy of the GNU General Public License version
208.19 + * 2 along with this work; if not, write to the Free Software Foundation,
208.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
208.21 + *
208.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
208.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
208.24 + * have any questions.
208.25 + */
208.26 +
208.27 +/*
208.28 + * @test
208.29 + * @bug 6788531
208.30 + * @summary Tests public method lookup problem in EventHandler
208.31 + * @author Sergey Malenkov
208.32 + */
208.33 +
208.34 +import javax.swing.JButton;
208.35 +import java.awt.event.ActionListener;
208.36 +import java.beans.EventHandler;
208.37 +
208.38 +public class Test6788531 {
208.39 + public static void main(String[] args) throws Exception {
208.40 + JButton button = new JButton("hi");
208.41 + button.addActionListener(EventHandler.create(ActionListener.class, new Private(), "run"));
208.42 + button.addActionListener(EventHandler.create(ActionListener.class, new PrivateGeneric(), "run", "generic"));
208.43 + button.doClick();
208.44 + }
208.45 +
208.46 + public static class Public {
208.47 + public void run() {
208.48 + throw new Error("method is overridden");
208.49 + }
208.50 + }
208.51 +
208.52 + static class Private extends Public {
208.53 + public void run() {
208.54 + System.out.println("default");
208.55 + }
208.56 + }
208.57 +
208.58 + public static class PublicGeneric<T> {
208.59 + public void run(T object) {
208.60 + throw new Error("method is overridden");
208.61 + }
208.62 + }
208.63 +
208.64 + static class PrivateGeneric extends PublicGeneric<String> {
208.65 + public void run(String string) {
208.66 + System.out.println(string);
208.67 + }
208.68 + }
208.69 +}
209.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
209.2 +++ b/test/java/beans/PropertyEditor/TestEnumSubclass.java Tue Feb 03 22:02:55 2009 -0800
209.3 @@ -0,0 +1,50 @@
209.4 +/*
209.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
209.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
209.7 + *
209.8 + * This code is free software; you can redistribute it and/or modify it
209.9 + * under the terms of the GNU General Public License version 2 only, as
209.10 + * published by the Free Software Foundation.
209.11 + *
209.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
209.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
209.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
209.15 + * version 2 for more details (a copy is included in the LICENSE file that
209.16 + * accompanied this code).
209.17 + *
209.18 + * You should have received a copy of the GNU General Public License version
209.19 + * 2 along with this work; if not, write to the Free Software Foundation,
209.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
209.21 + *
209.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
209.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
209.24 + * have any questions.
209.25 + */
209.26 +
209.27 +/*
209.28 + * @test
209.29 + * @bug 6736248
209.30 + * @summary Tests PropertyEditor for value of subtype Enum with security manager
209.31 + * @author Sergey Malenkov
209.32 + */
209.33 +
209.34 +public class TestEnumSubclass {
209.35 + public static void main(String[] args) {
209.36 + System.setSecurityManager(new SecurityManager());
209.37 + new TestEditor(Operation.class);
209.38 + }
209.39 +
209.40 + public enum Operation {
209.41 + PLUS {
209.42 + public int run(int i, int j) {
209.43 + return i + j;
209.44 + }
209.45 + },
209.46 + MINUS {
209.47 + public int run(int i, int j) {
209.48 + return i - j;
209.49 + }
209.50 + };
209.51 + public abstract int run(int i, int j);
209.52 + }
209.53 +}
210.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
210.2 +++ b/test/java/beans/PropertyEditor/TestEnumSubclassJava.java Tue Feb 03 22:02:55 2009 -0800
210.3 @@ -0,0 +1,49 @@
210.4 +/*
210.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
210.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
210.7 + *
210.8 + * This code is free software; you can redistribute it and/or modify it
210.9 + * under the terms of the GNU General Public License version 2 only, as
210.10 + * published by the Free Software Foundation.
210.11 + *
210.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
210.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
210.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
210.15 + * version 2 for more details (a copy is included in the LICENSE file that
210.16 + * accompanied this code).
210.17 + *
210.18 + * You should have received a copy of the GNU General Public License version
210.19 + * 2 along with this work; if not, write to the Free Software Foundation,
210.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
210.21 + *
210.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
210.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
210.24 + * have any questions.
210.25 + */
210.26 +
210.27 +/*
210.28 + * @test
210.29 + * @bug 6736248
210.30 + * @summary Tests PropertyEditor for value of subtype Enum
210.31 + * @author Sergey Malenkov
210.32 + */
210.33 +
210.34 +public class TestEnumSubclassJava {
210.35 + public static void main(String[] args) {
210.36 + new TestEditor(Operation.class).testJava(Operation.PLUS);
210.37 + }
210.38 +
210.39 + public enum Operation {
210.40 + PLUS {
210.41 + public int run(int i, int j) {
210.42 + return i + j;
210.43 + }
210.44 + },
210.45 + MINUS {
210.46 + public int run(int i, int j) {
210.47 + return i - j;
210.48 + }
210.49 + };
210.50 + public abstract int run(int i, int j);
210.51 + }
210.52 +}
211.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
211.2 +++ b/test/java/beans/PropertyEditor/TestEnumSubclassNull.java Tue Feb 03 22:02:55 2009 -0800
211.3 @@ -0,0 +1,49 @@
211.4 +/*
211.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
211.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
211.7 + *
211.8 + * This code is free software; you can redistribute it and/or modify it
211.9 + * under the terms of the GNU General Public License version 2 only, as
211.10 + * published by the Free Software Foundation.
211.11 + *
211.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
211.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
211.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
211.15 + * version 2 for more details (a copy is included in the LICENSE file that
211.16 + * accompanied this code).
211.17 + *
211.18 + * You should have received a copy of the GNU General Public License version
211.19 + * 2 along with this work; if not, write to the Free Software Foundation,
211.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
211.21 + *
211.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
211.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
211.24 + * have any questions.
211.25 + */
211.26 +
211.27 +/*
211.28 + * @test
211.29 + * @bug 6736248
211.30 + * @summary Tests PropertyEditor for null value of subtype Enum
211.31 + * @author Sergey Malenkov
211.32 + */
211.33 +
211.34 +public class TestEnumSubclassNull {
211.35 + public static void main(String[] args) {
211.36 + new TestEditor(Operation.class).testJava(null);
211.37 + }
211.38 +
211.39 + public enum Operation {
211.40 + PLUS {
211.41 + public int run(int i, int j) {
211.42 + return i + j;
211.43 + }
211.44 + },
211.45 + MINUS {
211.46 + public int run(int i, int j) {
211.47 + return i - j;
211.48 + }
211.49 + };
211.50 + public abstract int run(int i, int j);
211.51 + }
211.52 +}
212.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
212.2 +++ b/test/java/beans/PropertyEditor/TestEnumSubclassValue.java Tue Feb 03 22:02:55 2009 -0800
212.3 @@ -0,0 +1,53 @@
212.4 +/*
212.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
212.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
212.7 + *
212.8 + * This code is free software; you can redistribute it and/or modify it
212.9 + * under the terms of the GNU General Public License version 2 only, as
212.10 + * published by the Free Software Foundation.
212.11 + *
212.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
212.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
212.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
212.15 + * version 2 for more details (a copy is included in the LICENSE file that
212.16 + * accompanied this code).
212.17 + *
212.18 + * You should have received a copy of the GNU General Public License version
212.19 + * 2 along with this work; if not, write to the Free Software Foundation,
212.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
212.21 + *
212.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
212.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
212.24 + * have any questions.
212.25 + */
212.26 +
212.27 +/*
212.28 + * @test
212.29 + * @bug 6736248
212.30 + * @summary Tests PropertyEditor for value of subtype Enum
212.31 + * @author Sergey Malenkov
212.32 + */
212.33 +
212.34 +public class TestEnumSubclassValue {
212.35 + public static void main(String[] args) {
212.36 + TestEditor test = new TestEditor(Operation.class);
212.37 + test.testValue(Operation.PLUS, "PLUS");
212.38 + test.testValue(null, null);
212.39 + test.testText("MINUS", Operation.MINUS);
212.40 + test.testText(null, null);
212.41 + }
212.42 +
212.43 + public enum Operation {
212.44 + PLUS {
212.45 + public int run(int i, int j) {
212.46 + return i + j;
212.47 + }
212.48 + },
212.49 + MINUS {
212.50 + public int run(int i, int j) {
212.51 + return i - j;
212.52 + }
212.53 + };
212.54 + public abstract int run(int i, int j);
212.55 + }
212.56 +}
213.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
213.2 +++ b/test/java/beans/Statement/Test6788531.java Tue Feb 03 22:02:55 2009 -0800
213.3 @@ -0,0 +1,62 @@
213.4 +/*
213.5 + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
213.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
213.7 + *
213.8 + * This code is free software; you can redistribute it and/or modify it
213.9 + * under the terms of the GNU General Public License version 2 only, as
213.10 + * published by the Free Software Foundation.
213.11 + *
213.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
213.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
213.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
213.15 + * version 2 for more details (a copy is included in the LICENSE file that
213.16 + * accompanied this code).
213.17 + *
213.18 + * You should have received a copy of the GNU General Public License version
213.19 + * 2 along with this work; if not, write to the Free Software Foundation,
213.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
213.21 + *
213.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
213.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
213.24 + * have any questions.
213.25 + */
213.26 +
213.27 +/*
213.28 + * @test
213.29 + * @bug 6788531
213.30 + * @summary Tests public method lookup problem in Statement
213.31 + * @author Sergey Malenkov
213.32 + */
213.33 +
213.34 +import java.beans.Statement;
213.35 +
213.36 +public class Test6788531 {
213.37 + public static void main(String[] args) throws Exception {
213.38 + new Statement(new Private(), "run", null).execute();
213.39 + new Statement(new PrivateGeneric(), "run", new Object[] {"generic"}).execute();
213.40 + }
213.41 +
213.42 + public static class Public {
213.43 + public void run() {
213.44 + throw new Error("method is overridden");
213.45 + }
213.46 + }
213.47 +
213.48 + static class Private extends Public {
213.49 + public void run() {
213.50 + System.out.println("default");
213.51 + }
213.52 + }
213.53 +
213.54 + public static class PublicGeneric<T> {
213.55 + public void run(T object) {
213.56 + throw new Error("method is overridden");
213.57 + }
213.58 + }
213.59 +
213.60 + static class PrivateGeneric extends PublicGeneric<String> {
213.61 + public void run(String string) {
213.62 + System.out.println(string);
213.63 + }
213.64 + }
213.65 +}
214.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
214.2 +++ b/test/java/beans/XMLDecoder/Test4864117.java Tue Feb 03 22:02:55 2009 -0800
214.3 @@ -0,0 +1,146 @@
214.4 +/*
214.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
214.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
214.7 + *
214.8 + * This code is free software; you can redistribute it and/or modify it
214.9 + * under the terms of the GNU General Public License version 2 only, as
214.10 + * published by the Free Software Foundation.
214.11 + *
214.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
214.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
214.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
214.15 + * version 2 for more details (a copy is included in the LICENSE file that
214.16 + * accompanied this code).
214.17 + *
214.18 + * You should have received a copy of the GNU General Public License version
214.19 + * 2 along with this work; if not, write to the Free Software Foundation,
214.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
214.21 + *
214.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
214.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
214.24 + * have any questions.
214.25 + */
214.26 +
214.27 +/*
214.28 + * @test
214.29 + * @bug 4864117
214.30 + * @summary Tests XMLDecoder within another DefaultHandler for SAX parser
214.31 + * @author Sergey Malenkov
214.32 + */
214.33 +
214.34 +import java.beans.XMLDecoder;
214.35 +import java.beans.ExceptionListener;
214.36 +
214.37 +import java.io.ByteArrayInputStream;
214.38 +import java.io.InputStream;
214.39 +import java.io.IOException;
214.40 +
214.41 +import javax.xml.parsers.ParserConfigurationException;
214.42 +import javax.xml.parsers.SAXParserFactory;
214.43 +
214.44 +import org.xml.sax.Attributes;
214.45 +import org.xml.sax.SAXException;
214.46 +import org.xml.sax.helpers.DefaultHandler;
214.47 +
214.48 +public final class Test4864117 extends DefaultHandler implements ExceptionListener {
214.49 + private static final String TEST = "test";
214.50 + private static final String DATA
214.51 + = "<test>\n"
214.52 + + " <void property=\"message\">\n"
214.53 + + " <string>Hello, world!</string>\n"
214.54 + + " </void>\n"
214.55 + + "</test>";
214.56 +
214.57 + public static void main(String[] args) {
214.58 + Test4864117 test = new Test4864117();
214.59 + InputStream input = new ByteArrayInputStream(DATA.getBytes());
214.60 + Exception error = null;
214.61 + try {
214.62 + SAXParserFactory.newInstance().newSAXParser().parse(input, test);
214.63 + }
214.64 + catch (ParserConfigurationException exception) {
214.65 + error = exception;
214.66 + }
214.67 + catch (SAXException exception) {
214.68 + error = exception.getException();
214.69 + if (error == null) {
214.70 + error = exception;
214.71 + }
214.72 + }
214.73 + catch (IOException exception) {
214.74 + error = exception;
214.75 + }
214.76 + if (error != null) {
214.77 + throw new Error("unexpected error", error);
214.78 + }
214.79 + test.print('?', test.getMessage());
214.80 + }
214.81 +
214.82 + private String message;
214.83 +
214.84 + public String getMessage() {
214.85 + if (this.message == null) {
214.86 + throw new Error("owner's method is not called");
214.87 + }
214.88 + return this.message;
214.89 + }
214.90 +
214.91 + public void setMessage(String message) {
214.92 + this.message = message;
214.93 + print(':', this.message);
214.94 + }
214.95 +
214.96 + // DefaultHandler implementation
214.97 +
214.98 + private DefaultHandler handler;
214.99 + private int depth;
214.100 +
214.101 + @Override
214.102 + public void startDocument() throws SAXException {
214.103 + this.handler = XMLDecoder.createHandler(this, this, null);
214.104 + this.handler.startDocument();
214.105 + }
214.106 +
214.107 + @Override
214.108 + public void endDocument() {
214.109 + this.handler = null;
214.110 + }
214.111 +
214.112 + @Override
214.113 + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
214.114 + print('>', qName);
214.115 + if (this.depth > 0) {
214.116 + this.handler.startElement(uri, localName, qName, attributes);
214.117 + } else if (!TEST.equals(qName)) {
214.118 + throw new SAXException("unexpected element name: " + qName);
214.119 + }
214.120 + this.depth++;
214.121 + }
214.122 +
214.123 + @Override
214.124 + public void endElement(String uri, String localName, String qName) throws SAXException {
214.125 + this.depth--;
214.126 + print('<', qName);
214.127 + if (this.depth > 0) {
214.128 + this.handler.endElement(uri, localName, qName);
214.129 + } else if (!TEST.equals(qName)) {
214.130 + throw new SAXException("unexpected element name: " + qName);
214.131 + }
214.132 + }
214.133 +
214.134 + @Override
214.135 + public void characters(char[] ch, int start, int length) throws SAXException {
214.136 + this.handler.characters(ch, start, length);
214.137 + }
214.138 +
214.139 + public void exceptionThrown(Exception exception) {
214.140 + throw new Error("unexpected exception", exception);
214.141 + }
214.142 +
214.143 + private void print(char ch, String name) {
214.144 + StringBuilder sb = new StringBuilder();
214.145 + for (int i = 0; i < this.depth; i++) sb.append(' ');
214.146 + sb.append(ch).append(' ').append(name);
214.147 + System.out.println(sb.toString());
214.148 + }
214.149 +}
215.1 --- a/test/java/beans/XMLDecoder/Test6341798.java Thu Jan 29 21:46:48 2009 -0800
215.2 +++ b/test/java/beans/XMLDecoder/Test6341798.java Tue Feb 03 22:02:55 2009 -0800
215.3 @@ -1,5 +1,5 @@
215.4 /*
215.5 - * Copyright 2005-2007 Sun Microsystems, Inc. All Rights Reserved.
215.6 + * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved.
215.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
215.8 *
215.9 * This code is free software; you can redistribute it and/or modify it
215.10 @@ -39,7 +39,7 @@
215.11
215.12 private static final String DATA
215.13 = "<java>\n"
215.14 - + " <object class=\"TestTurkishLocale$DataBean\">\n"
215.15 + + " <object class=\"Test6341798$DataBean\">\n"
215.16 + " <void property=\"illegal\">\n"
215.17 + " <boolean>true</boolean>\n"
215.18 + " </void>\n"
216.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
216.2 +++ b/test/java/beans/XMLDecoder/spec/AbstractTest.java Tue Feb 03 22:02:55 2009 -0800
216.3 @@ -0,0 +1,76 @@
216.4 +/*
216.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
216.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
216.7 + *
216.8 + * This code is free software; you can redistribute it and/or modify it
216.9 + * under the terms of the GNU General Public License version 2 only, as
216.10 + * published by the Free Software Foundation.
216.11 + *
216.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
216.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
216.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
216.15 + * version 2 for more details (a copy is included in the LICENSE file that
216.16 + * accompanied this code).
216.17 + *
216.18 + * You should have received a copy of the GNU General Public License version
216.19 + * 2 along with this work; if not, write to the Free Software Foundation,
216.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
216.21 + *
216.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
216.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
216.24 + * have any questions.
216.25 + */
216.26 +
216.27 +import java.beans.ExceptionListener;
216.28 +import java.beans.XMLDecoder;
216.29 +
216.30 +import java.io.ByteArrayInputStream;
216.31 +
216.32 +abstract class AbstractTest implements ExceptionListener {
216.33 + public void exceptionThrown(Exception exception) {
216.34 + throw new Error("unexpected exception", exception);
216.35 + }
216.36 +
216.37 + /**
216.38 + * Validates the XML decoder for XML archive
216.39 + * that defined in the public field of the subclass.
216.40 + *
216.41 + * @param decoder the initialized XML decoder
216.42 + * @throws Error if validation failed
216.43 + */
216.44 + protected abstract void validate(XMLDecoder decoder);
216.45 +
216.46 + /**
216.47 + * This is entry point to start testing.
216.48 + *
216.49 + * @param security use {@code true} to start
216.50 + * second pass in secure context
216.51 + */
216.52 + final void test(boolean security) {
216.53 + byte[] array = getFieldValue("XML").getBytes(); // NON-NLS: the field name
216.54 + ByteArrayInputStream input = new ByteArrayInputStream(array);
216.55 + XMLDecoder decoder = new XMLDecoder(input);
216.56 + decoder.setExceptionListener(this);
216.57 + validate(decoder);
216.58 + try {
216.59 + throw new Error("unexpected object" + decoder.readObject());
216.60 + } catch (ArrayIndexOutOfBoundsException exception) {
216.61 + // expected exception
216.62 + }
216.63 + decoder.close();
216.64 + if (security) {
216.65 + System.setSecurityManager(new SecurityManager());
216.66 + test(false);
216.67 + }
216.68 + }
216.69 +
216.70 + private String getFieldValue(String field) {
216.71 + try {
216.72 + return getClass().getField(field).get(this).toString();
216.73 + } catch (NoSuchFieldException exception) {
216.74 + throw new Error("unexpected exception", exception);
216.75 + } catch (IllegalAccessException exception) {
216.76 + throw new Error("unexpected exception", exception);
216.77 + }
216.78 + }
216.79 +}
217.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
217.2 +++ b/test/java/beans/XMLDecoder/spec/TestArray.java Tue Feb 03 22:02:55 2009 -0800
217.3 @@ -0,0 +1,86 @@
217.4 +/*
217.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
217.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
217.7 + *
217.8 + * This code is free software; you can redistribute it and/or modify it
217.9 + * under the terms of the GNU General Public License version 2 only, as
217.10 + * published by the Free Software Foundation.
217.11 + *
217.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
217.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
217.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
217.15 + * version 2 for more details (a copy is included in the LICENSE file that
217.16 + * accompanied this code).
217.17 + *
217.18 + * You should have received a copy of the GNU General Public License version
217.19 + * 2 along with this work; if not, write to the Free Software Foundation,
217.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
217.21 + *
217.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
217.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
217.24 + * have any questions.
217.25 + */
217.26 +
217.27 +/*
217.28 + * @test
217.29 + * @summary Tests <array> element
217.30 + * @author Sergey Malenkov
217.31 + */
217.32 +
217.33 +import java.beans.XMLDecoder;
217.34 +import java.lang.reflect.Array;
217.35 +
217.36 +public final class TestArray extends AbstractTest {
217.37 + public static final String XML
217.38 + = "<java>\n"
217.39 + + " <array class=\"java.lang.Number\">\n"
217.40 + + " <byte>-111</byte>\n"
217.41 + + " <long>1111</long>\n"
217.42 + + " </array>\n"
217.43 + + " <array length=\"3\">\n"
217.44 + + " <void index=\"1\">\n"
217.45 + + " <string>Hello, world!</string>\n"
217.46 + + " </void>\n"
217.47 + + " </array>\n"
217.48 + + "</java>";
217.49 +
217.50 + public static void main(String[] args) {
217.51 + new TestArray().test(true);
217.52 + }
217.53 +
217.54 + @Override
217.55 + protected void validate(XMLDecoder decoder) {
217.56 + Number[] numbers = getArray(Number.class, 2, decoder.readObject());
217.57 + if (!numbers[0].equals(Byte.valueOf("-111"))) { // NON-NLS: hardcoded in XML
217.58 + throw new Error("unexpected byte value");
217.59 + }
217.60 + if (!numbers[1].equals(Long.valueOf("1111"))) { // NON-NLS: hardcoded in XML
217.61 + throw new Error("unexpected long value");
217.62 + }
217.63 +
217.64 + Object[] objects = getArray(Object.class, 3, decoder.readObject());
217.65 + if (objects[0] != null) {
217.66 + throw new Error("unexpected first value");
217.67 + }
217.68 + if (!objects[1].equals("Hello, world!")) { // NON-NLS: hardcoded in XML
217.69 + throw new Error("unexpected string value");
217.70 + }
217.71 + if (objects[2] != null) {
217.72 + throw new Error("unexpected last value");
217.73 + }
217.74 + }
217.75 +
217.76 + private static <T> T[] getArray(Class<T> component, int length, Object object) {
217.77 + Class type = object.getClass();
217.78 + if (!type.isArray()) {
217.79 + throw new Error("array expected");
217.80 + }
217.81 + if (!type.getComponentType().equals(component)) {
217.82 + throw new Error("unexpected component type");
217.83 + }
217.84 + if (length != Array.getLength(object)) {
217.85 + throw new Error("unexpected array length");
217.86 + }
217.87 + return (T[]) object;
217.88 + }
217.89 +}
218.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
218.2 +++ b/test/java/beans/XMLDecoder/spec/TestBoolean.java Tue Feb 03 22:02:55 2009 -0800
218.3 @@ -0,0 +1,52 @@
218.4 +/*
218.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
218.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
218.7 + *
218.8 + * This code is free software; you can redistribute it and/or modify it
218.9 + * under the terms of the GNU General Public License version 2 only, as
218.10 + * published by the Free Software Foundation.
218.11 + *
218.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
218.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
218.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
218.15 + * version 2 for more details (a copy is included in the LICENSE file that
218.16 + * accompanied this code).
218.17 + *
218.18 + * You should have received a copy of the GNU General Public License version
218.19 + * 2 along with this work; if not, write to the Free Software Foundation,
218.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
218.21 + *
218.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
218.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
218.24 + * have any questions.
218.25 + */
218.26 +
218.27 +/*
218.28 + * @test
218.29 + * @summary Tests <boolean> element
218.30 + * @author Sergey Malenkov
218.31 + */
218.32 +
218.33 +import java.beans.XMLDecoder;
218.34 +
218.35 +public final class TestBoolean extends AbstractTest {
218.36 + public static final String XML
218.37 + = "<java>\n"
218.38 + + " <boolean>true</boolean>\n"
218.39 + + " <boolean>false</boolean>\n"
218.40 + + "</java>";
218.41 +
218.42 + public static void main(String[] args) {
218.43 + new TestBoolean().test(true);
218.44 + }
218.45 +
218.46 + @Override
218.47 + protected void validate(XMLDecoder decoder) {
218.48 + if (!Boolean.TRUE.equals(decoder.readObject())) {
218.49 + throw new Error("true expected");
218.50 + }
218.51 + if (!Boolean.FALSE.equals(decoder.readObject())) {
218.52 + throw new Error("false expected");
218.53 + }
218.54 + }
218.55 +}
219.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
219.2 +++ b/test/java/beans/XMLDecoder/spec/TestByte.java Tue Feb 03 22:02:55 2009 -0800
219.3 @@ -0,0 +1,56 @@
219.4 +/*
219.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
219.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
219.7 + *
219.8 + * This code is free software; you can redistribute it and/or modify it
219.9 + * under the terms of the GNU General Public License version 2 only, as
219.10 + * published by the Free Software Foundation.
219.11 + *
219.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
219.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
219.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
219.15 + * version 2 for more details (a copy is included in the LICENSE file that
219.16 + * accompanied this code).
219.17 + *
219.18 + * You should have received a copy of the GNU General Public License version
219.19 + * 2 along with this work; if not, write to the Free Software Foundation,
219.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
219.21 + *
219.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
219.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
219.24 + * have any questions.
219.25 + */
219.26 +
219.27 +/*
219.28 + * @test
219.29 + * @summary Tests <byte> element
219.30 + * @author Sergey Malenkov
219.31 + */
219.32 +
219.33 +import java.beans.XMLDecoder;
219.34 +
219.35 +public final class TestByte extends AbstractTest {
219.36 + public static final String XML
219.37 + = "<java>\n"
219.38 + + " <byte>0</byte>\n"
219.39 + + " <byte>127</byte>\n"
219.40 + + " <byte>-128</byte>\n"
219.41 + + "</java>";
219.42 +
219.43 + public static void main(String[] args) {
219.44 + new TestByte().test(true);
219.45 + }
219.46 +
219.47 + @Override
219.48 + protected void validate(XMLDecoder decoder) {
219.49 + validate((byte) 0, decoder.readObject());
219.50 + validate(Byte.MAX_VALUE, decoder.readObject());
219.51 + validate(Byte.MIN_VALUE, decoder.readObject());
219.52 + }
219.53 +
219.54 + private static void validate(byte value, Object object) {
219.55 + if (!object.equals(Byte.valueOf(value))) {
219.56 + throw new Error("byte " + value + " expected");
219.57 + }
219.58 + }
219.59 +}
220.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
220.2 +++ b/test/java/beans/XMLDecoder/spec/TestChar.java Tue Feb 03 22:02:55 2009 -0800
220.3 @@ -0,0 +1,52 @@
220.4 +/*
220.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
220.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
220.7 + *
220.8 + * This code is free software; you can redistribute it and/or modify it
220.9 + * under the terms of the GNU General Public License version 2 only, as
220.10 + * published by the Free Software Foundation.
220.11 + *
220.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
220.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
220.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
220.15 + * version 2 for more details (a copy is included in the LICENSE file that
220.16 + * accompanied this code).
220.17 + *
220.18 + * You should have received a copy of the GNU General Public License version
220.19 + * 2 along with this work; if not, write to the Free Software Foundation,
220.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
220.21 + *
220.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
220.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
220.24 + * have any questions.
220.25 + */
220.26 +
220.27 +/*
220.28 + * @test
220.29 + * @summary Tests <char> element
220.30 + * @author Sergey Malenkov
220.31 + */
220.32 +
220.33 +import java.beans.XMLDecoder;
220.34 +
220.35 +public final class TestChar extends AbstractTest {
220.36 + public static final String XML
220.37 + = "<java>\n"
220.38 + + " <char>X</char>\n"
220.39 + + " <char code=\"#20\"/>\n"
220.40 + + "</java>";
220.41 +
220.42 + public static void main(String[] args) {
220.43 + new TestChar().test(true);
220.44 + }
220.45 +
220.46 + @Override
220.47 + protected void validate(XMLDecoder decoder) {
220.48 + if (!decoder.readObject().equals(Character.valueOf('X'))) {
220.49 + throw new Error("unexpected character");
220.50 + }
220.51 + if (!decoder.readObject().equals(Character.valueOf((char) 0x20))) {
220.52 + throw new Error("unexpected character code");
220.53 + }
220.54 + }
220.55 +}
221.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
221.2 +++ b/test/java/beans/XMLDecoder/spec/TestClass.java Tue Feb 03 22:02:55 2009 -0800
221.3 @@ -0,0 +1,61 @@
221.4 +/*
221.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
221.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
221.7 + *
221.8 + * This code is free software; you can redistribute it and/or modify it
221.9 + * under the terms of the GNU General Public License version 2 only, as
221.10 + * published by the Free Software Foundation.
221.11 + *
221.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
221.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
221.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
221.15 + * version 2 for more details (a copy is included in the LICENSE file that
221.16 + * accompanied this code).
221.17 + *
221.18 + * You should have received a copy of the GNU General Public License version
221.19 + * 2 along with this work; if not, write to the Free Software Foundation,
221.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
221.21 + *
221.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
221.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
221.24 + * have any questions.
221.25 + */
221.26 +
221.27 +/*
221.28 + * @test
221.29 + * @summary Tests <class> element
221.30 + * @author Sergey Malenkov
221.31 + */
221.32 +
221.33 +import java.beans.XMLDecoder;
221.34 +
221.35 +public final class TestClass extends AbstractTest {
221.36 + public static final String PREFIX = "javax.swing.colorchooser.";
221.37 + public static final String INTERFACE = "ColorSelectionModel";
221.38 + public static final String PUBLIC_CLASS = "DefaultColorSelectionModel";
221.39 + public static final String PRIVATE_CLASS = "DiagramComponent";
221.40 + public static final String XML
221.41 + = "<java>\n"
221.42 + + " <class>" + PREFIX + INTERFACE + "</class>\n"
221.43 + + " <class>" + PREFIX + PUBLIC_CLASS + "</class>\n"
221.44 + + " <class>" + PREFIX + PRIVATE_CLASS + "</class>\n"
221.45 + + "</java>";
221.46 +
221.47 + public static void main(String[] args) {
221.48 + new TestClass().test(true);
221.49 + }
221.50 +
221.51 + @Override
221.52 + protected void validate(XMLDecoder decoder) {
221.53 + validate(PREFIX + INTERFACE, decoder.readObject());
221.54 + validate(PREFIX + PUBLIC_CLASS, decoder.readObject());
221.55 + validate(PREFIX + PRIVATE_CLASS, decoder.readObject());
221.56 + }
221.57 +
221.58 + private static void validate(String name, Object object) {
221.59 + Class type = (Class) object;
221.60 + if (!type.getName().equals(name)) {
221.61 + throw new Error(name + " expected");
221.62 + }
221.63 + }
221.64 +}
222.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
222.2 +++ b/test/java/beans/XMLDecoder/spec/TestDouble.java Tue Feb 03 22:02:55 2009 -0800
222.3 @@ -0,0 +1,58 @@
222.4 +/*
222.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
222.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
222.7 + *
222.8 + * This code is free software; you can redistribute it and/or modify it
222.9 + * under the terms of the GNU General Public License version 2 only, as
222.10 + * published by the Free Software Foundation.
222.11 + *
222.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
222.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
222.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
222.15 + * version 2 for more details (a copy is included in the LICENSE file that
222.16 + * accompanied this code).
222.17 + *
222.18 + * You should have received a copy of the GNU General Public License version
222.19 + * 2 along with this work; if not, write to the Free Software Foundation,
222.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
222.21 + *
222.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
222.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
222.24 + * have any questions.
222.25 + */
222.26 +
222.27 +/*
222.28 + * @test
222.29 + * @summary Tests <double> element
222.30 + * @author Sergey Malenkov
222.31 + */
222.32 +
222.33 +import java.beans.XMLDecoder;
222.34 +
222.35 +public final class TestDouble extends AbstractTest {
222.36 + public static final String XML
222.37 + = "<java>\n"
222.38 + + " <double>0</double>\n"
222.39 + + " <double>1000</double>\n"
222.40 + + " <double>-1.1e15</double>\n"
222.41 + + " <double>10.11e-123</double>\n"
222.42 + + "</java>";
222.43 +
222.44 + public static void main(String[] args) {
222.45 + new TestDouble().test(true);
222.46 + }
222.47 +
222.48 + @Override
222.49 + protected void validate(XMLDecoder decoder) {
222.50 + validate(0.0, decoder.readObject());
222.51 + validate(1000.0, decoder.readObject());
222.52 + validate(-1.1e15, decoder.readObject());
222.53 + validate(10.11e-123, decoder.readObject());
222.54 + }
222.55 +
222.56 + private static void validate(double value, Object object) {
222.57 + if (!object.equals(Double.valueOf(value))) {
222.58 + throw new Error("double " + value + " expected");
222.59 + }
222.60 + }
222.61 +}
223.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
223.2 +++ b/test/java/beans/XMLDecoder/spec/TestFalse.java Tue Feb 03 22:02:55 2009 -0800
223.3 @@ -0,0 +1,48 @@
223.4 +/*
223.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
223.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
223.7 + *
223.8 + * This code is free software; you can redistribute it and/or modify it
223.9 + * under the terms of the GNU General Public License version 2 only, as
223.10 + * published by the Free Software Foundation.
223.11 + *
223.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
223.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
223.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
223.15 + * version 2 for more details (a copy is included in the LICENSE file that
223.16 + * accompanied this code).
223.17 + *
223.18 + * You should have received a copy of the GNU General Public License version
223.19 + * 2 along with this work; if not, write to the Free Software Foundation,
223.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
223.21 + *
223.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
223.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
223.24 + * have any questions.
223.25 + */
223.26 +
223.27 +/*
223.28 + * @test
223.29 + * @summary Tests <false> element
223.30 + * @author Sergey Malenkov
223.31 + */
223.32 +
223.33 +import java.beans.XMLDecoder;
223.34 +
223.35 +public final class TestFalse extends AbstractTest {
223.36 + public static final String XML
223.37 + = "<java>\n"
223.38 + + " <false/>\n"
223.39 + + "</java>";
223.40 +
223.41 + public static void main(String[] args) {
223.42 + new TestFalse().test(true);
223.43 + }
223.44 +
223.45 + @Override
223.46 + protected void validate(XMLDecoder decoder) {
223.47 + if (!Boolean.FALSE.equals(decoder.readObject())) {
223.48 + throw new Error("false expected");
223.49 + }
223.50 + }
223.51 +}
224.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
224.2 +++ b/test/java/beans/XMLDecoder/spec/TestField.java Tue Feb 03 22:02:55 2009 -0800
224.3 @@ -0,0 +1,74 @@
224.4 +/*
224.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
224.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
224.7 + *
224.8 + * This code is free software; you can redistribute it and/or modify it
224.9 + * under the terms of the GNU General Public License version 2 only, as
224.10 + * published by the Free Software Foundation.
224.11 + *
224.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
224.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
224.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
224.15 + * version 2 for more details (a copy is included in the LICENSE file that
224.16 + * accompanied this code).
224.17 + *
224.18 + * You should have received a copy of the GNU General Public License version
224.19 + * 2 along with this work; if not, write to the Free Software Foundation,
224.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
224.21 + *
224.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
224.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
224.24 + * have any questions.
224.25 + */
224.26 +
224.27 +/*
224.28 + * @test
224.29 + * @summary Tests <field> element
224.30 + * @author Sergey Malenkov
224.31 + */
224.32 +
224.33 +import java.beans.XMLDecoder;
224.34 +
224.35 +public final class TestField extends AbstractTest {
224.36 + public static final String XML
224.37 + = "<java>\n"
224.38 + + " <field name=\"FIELD\" class=\"TestField\"/>\n"
224.39 + + " <field name=\"FIELD\" class=\"TestField\">\n"
224.40 + + " <string>static postfix</string>\n"
224.41 + + " </field>\n"
224.42 + + " <field name=\"FIELD\" class=\"TestField\"/>\n"
224.43 + + " <property name=\"owner\">\n"
224.44 + + " <field id=\"prefix\" name=\"field\"/>\n"
224.45 + + " <field name=\"field\">\n"
224.46 + + " <string>postfix</string>\n"
224.47 + + " </field>\n"
224.48 + + " <field id=\"postfix\" name=\"field\"/>\n"
224.49 + + " </property>\n"
224.50 + + " <var idref=\"prefix\"/>\n"
224.51 + + " <var idref=\"postfix\"/>\n"
224.52 + + "</java>";
224.53 +
224.54 + public static void main(String[] args) {
224.55 + new TestField().test(true);
224.56 + }
224.57 +
224.58 + public static String FIELD;
224.59 + public String field;
224.60 +
224.61 + @Override
224.62 + protected void validate(XMLDecoder decoder) {
224.63 + FIELD = "static prefix";
224.64 + field = "prefix";
224.65 + decoder.setOwner(this);
224.66 + validate(decoder, "static prefix");
224.67 + validate(decoder, "static postfix");
224.68 + validate(decoder, "prefix");
224.69 + validate(decoder, "postfix");
224.70 + }
224.71 +
224.72 + private static void validate(XMLDecoder decoder, String name) {
224.73 + if (!decoder.readObject().equals(name)) {
224.74 + throw new Error(name + " expected");
224.75 + }
224.76 + }
224.77 +}
225.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
225.2 +++ b/test/java/beans/XMLDecoder/spec/TestFloat.java Tue Feb 03 22:02:55 2009 -0800
225.3 @@ -0,0 +1,58 @@
225.4 +/*
225.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
225.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
225.7 + *
225.8 + * This code is free software; you can redistribute it and/or modify it
225.9 + * under the terms of the GNU General Public License version 2 only, as
225.10 + * published by the Free Software Foundation.
225.11 + *
225.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
225.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
225.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
225.15 + * version 2 for more details (a copy is included in the LICENSE file that
225.16 + * accompanied this code).
225.17 + *
225.18 + * You should have received a copy of the GNU General Public License version
225.19 + * 2 along with this work; if not, write to the Free Software Foundation,
225.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
225.21 + *
225.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
225.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
225.24 + * have any questions.
225.25 + */
225.26 +
225.27 +/*
225.28 + * @test
225.29 + * @summary Tests <float> element
225.30 + * @author Sergey Malenkov
225.31 + */
225.32 +
225.33 +import java.beans.XMLDecoder;
225.34 +
225.35 +public final class TestFloat extends AbstractTest {
225.36 + public static final String XML
225.37 + = "<java>\n"
225.38 + + " <float>0</float>\n"
225.39 + + " <float>100</float>\n"
225.40 + + " <float>-1e15</float>\n"
225.41 + + " <float>100e-20</float>\n"
225.42 + + "</java>";
225.43 +
225.44 + public static void main(String[] args) {
225.45 + new TestFloat().test(true);
225.46 + }
225.47 +
225.48 + @Override
225.49 + protected void validate(XMLDecoder decoder) {
225.50 + validate(0.0f, decoder.readObject());
225.51 + validate(100.0f, decoder.readObject());
225.52 + validate(-1e15f, decoder.readObject());
225.53 + validate(100e-20f, decoder.readObject());
225.54 + }
225.55 +
225.56 + private static void validate(float value, Object object) {
225.57 + if (!object.equals(Float.valueOf(value))) {
225.58 + throw new Error("float " + value + " expected");
225.59 + }
225.60 + }
225.61 +}
226.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
226.2 +++ b/test/java/beans/XMLDecoder/spec/TestInt.java Tue Feb 03 22:02:55 2009 -0800
226.3 @@ -0,0 +1,64 @@
226.4 +/*
226.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
226.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
226.7 + *
226.8 + * This code is free software; you can redistribute it and/or modify it
226.9 + * under the terms of the GNU General Public License version 2 only, as
226.10 + * published by the Free Software Foundation.
226.11 + *
226.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
226.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
226.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
226.15 + * version 2 for more details (a copy is included in the LICENSE file that
226.16 + * accompanied this code).
226.17 + *
226.18 + * You should have received a copy of the GNU General Public License version
226.19 + * 2 along with this work; if not, write to the Free Software Foundation,
226.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
226.21 + *
226.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
226.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
226.24 + * have any questions.
226.25 + */
226.26 +
226.27 +/*
226.28 + * @test
226.29 + * @summary Tests <int> element
226.30 + * @author Sergey Malenkov
226.31 + */
226.32 +
226.33 +import java.beans.XMLDecoder;
226.34 +
226.35 +public final class TestInt extends AbstractTest {
226.36 + public static final String XML
226.37 + = "<java>\n"
226.38 + + " <int>0</int>\n"
226.39 + + " <int>127</int>\n"
226.40 + + " <int>-128</int>\n"
226.41 + + " <int>32767</int>\n"
226.42 + + " <int>-32768</int>\n"
226.43 + + " <int>2147483647</int>\n"
226.44 + + " <int>-2147483648</int>\n"
226.45 + + "</java>";
226.46 +
226.47 + public static void main(String[] args) {
226.48 + new TestInt().test(true);
226.49 + }
226.50 +
226.51 + @Override
226.52 + protected void validate(XMLDecoder decoder) {
226.53 + validate(0, decoder.readObject());
226.54 + validate((int) Byte.MAX_VALUE, decoder.readObject());
226.55 + validate((int) Byte.MIN_VALUE, decoder.readObject());
226.56 + validate((int) Short.MAX_VALUE, decoder.readObject());
226.57 + validate((int) Short.MIN_VALUE, decoder.readObject());
226.58 + validate(Integer.MAX_VALUE, decoder.readObject());
226.59 + validate(Integer.MIN_VALUE, decoder.readObject());
226.60 + }
226.61 +
226.62 + private static void validate(int value, Object object) {
226.63 + if (!object.equals(Integer.valueOf(value))) {
226.64 + throw new Error("int " + value + " expected");
226.65 + }
226.66 + }
226.67 +}
227.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
227.2 +++ b/test/java/beans/XMLDecoder/spec/TestJava.java Tue Feb 03 22:02:55 2009 -0800
227.3 @@ -0,0 +1,63 @@
227.4 +/*
227.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
227.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
227.7 + *
227.8 + * This code is free software; you can redistribute it and/or modify it
227.9 + * under the terms of the GNU General Public License version 2 only, as
227.10 + * published by the Free Software Foundation.
227.11 + *
227.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
227.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
227.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
227.15 + * version 2 for more details (a copy is included in the LICENSE file that
227.16 + * accompanied this code).
227.17 + *
227.18 + * You should have received a copy of the GNU General Public License version
227.19 + * 2 along with this work; if not, write to the Free Software Foundation,
227.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
227.21 + *
227.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
227.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
227.24 + * have any questions.
227.25 + */
227.26 +
227.27 +/*
227.28 + * @test
227.29 + * @summary Tests <java> element
227.30 + * @author Sergey Malenkov
227.31 + */
227.32 +
227.33 +import java.beans.XMLDecoder;
227.34 +
227.35 +public final class TestJava extends AbstractTest {
227.36 + public static final String XML
227.37 + = "<java>\n"
227.38 + + " <void id=\"owner\" method=\"getOwner\">\n"
227.39 + + " <void method=\"init\">\n"
227.40 + + " <string>Hello, world!</string>\n"
227.41 + + " </void>\n"
227.42 + + " </void>\n"
227.43 + + " <object idref=\"owner\"/>\n"
227.44 + + "</java>";
227.45 +
227.46 + public static void main(String[] args) {
227.47 + new TestJava().test(true);
227.48 + }
227.49 +
227.50 + private String message;
227.51 +
227.52 + public void init(String message) {
227.53 + this.message = message;
227.54 + }
227.55 +
227.56 + @Override
227.57 + protected void validate(XMLDecoder decoder) {
227.58 + decoder.setOwner(this);
227.59 + if (this != decoder.readObject()) {
227.60 + throw new Error("owner should be the same");
227.61 + }
227.62 + if (this.message == null) {
227.63 + throw new Error("owner's method is not called");
227.64 + }
227.65 + }
227.66 +}
228.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
228.2 +++ b/test/java/beans/XMLDecoder/spec/TestLong.java Tue Feb 03 22:02:55 2009 -0800
228.3 @@ -0,0 +1,68 @@
228.4 +/*
228.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
228.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
228.7 + *
228.8 + * This code is free software; you can redistribute it and/or modify it
228.9 + * under the terms of the GNU General Public License version 2 only, as
228.10 + * published by the Free Software Foundation.
228.11 + *
228.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
228.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
228.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
228.15 + * version 2 for more details (a copy is included in the LICENSE file that
228.16 + * accompanied this code).
228.17 + *
228.18 + * You should have received a copy of the GNU General Public License version
228.19 + * 2 along with this work; if not, write to the Free Software Foundation,
228.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
228.21 + *
228.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
228.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
228.24 + * have any questions.
228.25 + */
228.26 +
228.27 +/*
228.28 + * @test
228.29 + * @summary Tests <long> element
228.30 + * @author Sergey Malenkov
228.31 + */
228.32 +
228.33 +import java.beans.XMLDecoder;
228.34 +
228.35 +public final class TestLong extends AbstractTest {
228.36 + public static final String XML
228.37 + = "<java>\n"
228.38 + + " <long>0</long>\n"
228.39 + + " <long>127</long>\n"
228.40 + + " <long>-128</long>\n"
228.41 + + " <long>32767</long>\n"
228.42 + + " <long>-32768</long>\n"
228.43 + + " <long>2147483647</long>\n"
228.44 + + " <long>-2147483648</long>\n"
228.45 + + " <long>9223372036854775807</long>\n"
228.46 + + " <long>-9223372036854775808</long>\n"
228.47 + + "</java>";
228.48 +
228.49 + public static void main(String[] args) {
228.50 + new TestLong().test(true);
228.51 + }
228.52 +
228.53 + @Override
228.54 + protected void validate(XMLDecoder decoder) {
228.55 + validate(0L, decoder.readObject());
228.56 + validate((long) Byte.MAX_VALUE, decoder.readObject());
228.57 + validate((long) Byte.MIN_VALUE, decoder.readObject());
228.58 + validate((long) Short.MAX_VALUE, decoder.readObject());
228.59 + validate((long) Short.MIN_VALUE, decoder.readObject());
228.60 + validate((long) Integer.MAX_VALUE, decoder.readObject());
228.61 + validate((long) Integer.MIN_VALUE, decoder.readObject());
228.62 + validate(Long.MAX_VALUE, decoder.readObject());
228.63 + validate(Long.MIN_VALUE, decoder.readObject());
228.64 + }
228.65 +
228.66 + private static void validate(long value, Object object) {
228.67 + if (!object.equals(Long.valueOf(value))) {
228.68 + throw new Error("long " + value + " expected");
228.69 + }
228.70 + }
228.71 +}
229.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
229.2 +++ b/test/java/beans/XMLDecoder/spec/TestMethod.java Tue Feb 03 22:02:55 2009 -0800
229.3 @@ -0,0 +1,178 @@
229.4 +/*
229.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
229.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
229.7 + *
229.8 + * This code is free software; you can redistribute it and/or modify it
229.9 + * under the terms of the GNU General Public License version 2 only, as
229.10 + * published by the Free Software Foundation.
229.11 + *
229.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
229.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
229.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
229.15 + * version 2 for more details (a copy is included in the LICENSE file that
229.16 + * accompanied this code).
229.17 + *
229.18 + * You should have received a copy of the GNU General Public License version
229.19 + * 2 along with this work; if not, write to the Free Software Foundation,
229.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
229.21 + *
229.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
229.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
229.24 + * have any questions.
229.25 + */
229.26 +
229.27 +/*
229.28 + * @test
229.29 + * @summary Tests <method> element
229.30 + * @author Sergey Malenkov
229.31 + */
229.32 +
229.33 +import java.beans.XMLDecoder;
229.34 +
229.35 +public final class TestMethod extends AbstractTest {
229.36 + public static final String XML
229.37 + = "<java>\n"
229.38 + + " <new class=\"TestMethod$A\">\n"
229.39 + + " <method name=\"m\">\n"
229.40 + + " <new class=\"TestMethod$Y\"/>\n"
229.41 + + " <new class=\"TestMethod$Y\"/>\n"
229.42 + + " </method>\n"
229.43 + + " </new>\n"
229.44 + + " <new class=\"TestMethod$B\">\n"
229.45 + + " <method name=\"m\">\n"
229.46 + + " <new class=\"TestMethod$Y\"/>\n"
229.47 + + " <new class=\"TestMethod$Y\"/>\n"
229.48 + + " </method>\n"
229.49 + + " </new>\n"
229.50 + + " <new class=\"TestMethod$C\">\n"
229.51 + + " <method name=\"m\">\n"
229.52 + + " <new class=\"TestMethod$Z\"/>\n"
229.53 + + " <new class=\"TestMethod$Z\"/>\n"
229.54 + + " </method>\n"
229.55 + + " </new>\n"
229.56 + + " <new class=\"TestMethod$D\">\n"
229.57 + + " <method name=\"m\">\n"
229.58 + + " <new class=\"TestMethod$Z\"/>\n"
229.59 + + " <new class=\"TestMethod$Z\"/>\n"
229.60 + + " </method>\n"
229.61 + + " </new>\n"
229.62 + + " <new class=\"TestMethod$E\">\n"
229.63 + + " <method name=\"m\">\n"
229.64 + + " <new class=\"TestMethod$Z\"/>\n"
229.65 + + " <new class=\"TestMethod$Z\"/>\n"
229.66 + + " </method>\n"
229.67 + + " </new>\n"
229.68 + + "</java>";
229.69 +
229.70 + public static void main(String[] args) {
229.71 + new TestMethod().test(true);
229.72 + }
229.73 +
229.74 + private NoSuchMethodException exception;
229.75 +
229.76 + @Override
229.77 + public void exceptionThrown(Exception exception) {
229.78 + if (this.exception != null) {
229.79 + // only one exception allowed
229.80 + super.exceptionThrown(exception);
229.81 + } else if (exception instanceof NoSuchMethodException) {
229.82 + // expected exception: ambiguous methods are found
229.83 + this.exception = (NoSuchMethodException) exception;
229.84 + } else {
229.85 + super.exceptionThrown(exception);
229.86 + }
229.87 + }
229.88 +
229.89 + @Override
229.90 + protected void validate(XMLDecoder decoder) {
229.91 + this.exception = null;
229.92 + validate(decoder, A.class);
229.93 + validate(decoder, B.class);
229.94 + validate(decoder, C.class);
229.95 + validate(decoder, D.class);
229.96 + validate(decoder, E.class);
229.97 + if (this.exception == null) {
229.98 + throw new Error("NoSuchMethodException expected");
229.99 + }
229.100 + }
229.101 +
229.102 + private static void validate(XMLDecoder decoder, Class type) {
229.103 + if (!type.equals(decoder.readObject().getClass())) {
229.104 + throw new Error("unexpected class");
229.105 + }
229.106 + }
229.107 +
229.108 + /**
229.109 + * All ambiguous method declarations should fail.
229.110 + */
229.111 + public static class A {
229.112 + public void m(X x1, X x2) {
229.113 + throw new Error("A.m(X,X) should not be called");
229.114 + }
229.115 +
229.116 + public void m(X x1, Y y2) {
229.117 + throw new Error("A.m(X,Y) should not be called");
229.118 + }
229.119 +
229.120 + public void m(Y y1, X x2) {
229.121 + throw new Error("A.m(Y,X) should not be called");
229.122 + }
229.123 + }
229.124 +
229.125 + /**
229.126 + * The most specific method in this case would be the second declaration.
229.127 + */
229.128 + public static class B {
229.129 + public void m(X x1, X x2) {
229.130 + throw new Error("B.m(X,X) should not be called");
229.131 + }
229.132 +
229.133 + public void m(X x1, Y y2) {
229.134 + // expected: B.m(X,Y) should be called
229.135 + }
229.136 + }
229.137 +
229.138 + /**
229.139 + * The most specific method in this case would be the first declaration.
229.140 + */
229.141 + public static class C {
229.142 + public void m(Y y1, Y y2) {
229.143 + // expected: C.m(Y,Y) should be called
229.144 + }
229.145 +
229.146 + public void m(X x1, X x2) {
229.147 + throw new Error("C.m(X,X) should not be called");
229.148 + }
229.149 + }
229.150 +
229.151 + /**
229.152 + * Same as the previous case but flip methods.
229.153 + */
229.154 + public static class D {
229.155 + public void m(X x1, X x2) {
229.156 + throw new Error("D.m(X,X) should not be called");
229.157 + }
229.158 +
229.159 + public void m(Y y1, Y y2) {
229.160 + // expected: D.m(Y,Y) should be called
229.161 + }
229.162 + }
229.163 +
229.164 + /**
229.165 + * The method should be called with (Z,Z).
229.166 + */
229.167 + public static class E {
229.168 + public void m(X x1, X x2) {
229.169 + // expected: E.m(X,X) should be called
229.170 + }
229.171 + }
229.172 +
229.173 + public static class X {
229.174 + }
229.175 +
229.176 + public static class Y extends X {
229.177 + }
229.178 +
229.179 + public static class Z extends Y {
229.180 + }
229.181 +}
230.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
230.2 +++ b/test/java/beans/XMLDecoder/spec/TestNew.java Tue Feb 03 22:02:55 2009 -0800
230.3 @@ -0,0 +1,90 @@
230.4 +/*
230.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
230.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
230.7 + *
230.8 + * This code is free software; you can redistribute it and/or modify it
230.9 + * under the terms of the GNU General Public License version 2 only, as
230.10 + * published by the Free Software Foundation.
230.11 + *
230.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
230.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
230.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
230.15 + * version 2 for more details (a copy is included in the LICENSE file that
230.16 + * accompanied this code).
230.17 + *
230.18 + * You should have received a copy of the GNU General Public License version
230.19 + * 2 along with this work; if not, write to the Free Software Foundation,
230.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
230.21 + *
230.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
230.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
230.24 + * have any questions.
230.25 + */
230.26 +
230.27 +/*
230.28 + * @test
230.29 + * @summary Tests <new> element
230.30 + * @author Sergey Malenkov
230.31 + */
230.32 +
230.33 +import java.beans.XMLDecoder;
230.34 +import java.util.ArrayList;
230.35 +import java.util.List;
230.36 +
230.37 +public final class TestNew extends AbstractTest {
230.38 + public static final String XML
230.39 + = "<java>\n"
230.40 + + " <new class=\"TestNew\"/>\n"
230.41 + + " <new class=\"TestNew\">\n"
230.42 + + " <null/>\n"
230.43 + + " </new>\n"
230.44 + + " <new class=\"TestNew\">\n"
230.45 + + " <string>single</string>\n"
230.46 + + " </new>\n"
230.47 + + " <new class=\"TestNew\">\n"
230.48 + + " <string>first</string>\n"
230.49 + + " <string>second</string>\n"
230.50 + + " <string>third</string>\n"
230.51 + + " </new>\n"
230.52 + + "</java>";
230.53 +
230.54 + public static void main(String[] args) {
230.55 + new TestNew().test(true);
230.56 + }
230.57 +
230.58 + private List<String> list;
230.59 +
230.60 + public TestNew(String...messages) {
230.61 + if (messages != null) {
230.62 + this.list = new ArrayList<String>();
230.63 + for (String message : messages) {
230.64 + this.list.add(message);
230.65 + }
230.66 + }
230.67 + }
230.68 +
230.69 + @Override
230.70 + public boolean equals(Object object) {
230.71 + if (object instanceof TestNew) {
230.72 + TestNew test = (TestNew) object;
230.73 + return (test.list == null)
230.74 + ? this.list == null
230.75 + : test.list.equals(this.list);
230.76 + }
230.77 + return false;
230.78 + }
230.79 +
230.80 + @Override
230.81 + protected void validate(XMLDecoder decoder) {
230.82 + validate(decoder.readObject());
230.83 + validate(decoder.readObject(), null);
230.84 + validate(decoder.readObject(), "single");
230.85 + validate(decoder.readObject(), "first", "second", "third");
230.86 + }
230.87 +
230.88 + private static void validate(Object object, String...messages) {
230.89 + if (!object.equals(new TestNew(messages))) {
230.90 + throw new Error("expected object");
230.91 + }
230.92 + }
230.93 +}
231.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
231.2 +++ b/test/java/beans/XMLDecoder/spec/TestNull.java Tue Feb 03 22:02:55 2009 -0800
231.3 @@ -0,0 +1,48 @@
231.4 +/*
231.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
231.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
231.7 + *
231.8 + * This code is free software; you can redistribute it and/or modify it
231.9 + * under the terms of the GNU General Public License version 2 only, as
231.10 + * published by the Free Software Foundation.
231.11 + *
231.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
231.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
231.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
231.15 + * version 2 for more details (a copy is included in the LICENSE file that
231.16 + * accompanied this code).
231.17 + *
231.18 + * You should have received a copy of the GNU General Public License version
231.19 + * 2 along with this work; if not, write to the Free Software Foundation,
231.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
231.21 + *
231.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
231.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
231.24 + * have any questions.
231.25 + */
231.26 +
231.27 +/*
231.28 + * @test
231.29 + * @summary Tests <null> element
231.30 + * @author Sergey Malenkov
231.31 + */
231.32 +
231.33 +import java.beans.XMLDecoder;
231.34 +
231.35 +public final class TestNull extends AbstractTest {
231.36 + public static final String XML
231.37 + = "<java>\n"
231.38 + + " <null/>\n"
231.39 + + "</java>";
231.40 +
231.41 + public static void main(String[] args) {
231.42 + new TestNull().test(true);
231.43 + }
231.44 +
231.45 + @Override
231.46 + protected void validate(XMLDecoder decoder) {
231.47 + if (null != decoder.readObject()) {
231.48 + throw new Error("null value expected");
231.49 + }
231.50 + }
231.51 +}
232.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
232.2 +++ b/test/java/beans/XMLDecoder/spec/TestObject.java Tue Feb 03 22:02:55 2009 -0800
232.3 @@ -0,0 +1,84 @@
232.4 +/*
232.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
232.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
232.7 + *
232.8 + * This code is free software; you can redistribute it and/or modify it
232.9 + * under the terms of the GNU General Public License version 2 only, as
232.10 + * published by the Free Software Foundation.
232.11 + *
232.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
232.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
232.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
232.15 + * version 2 for more details (a copy is included in the LICENSE file that
232.16 + * accompanied this code).
232.17 + *
232.18 + * You should have received a copy of the GNU General Public License version
232.19 + * 2 along with this work; if not, write to the Free Software Foundation,
232.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
232.21 + *
232.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
232.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
232.24 + * have any questions.
232.25 + */
232.26 +
232.27 +/*
232.28 + * @test
232.29 + * @summary Tests <object> element
232.30 + * @author Sergey Malenkov
232.31 + */
232.32 +
232.33 +import java.beans.XMLDecoder;
232.34 +import javax.swing.JButton;
232.35 +import javax.swing.JLabel;
232.36 +import javax.swing.JPanel;
232.37 +import javax.swing.SwingConstants;
232.38 +
232.39 +public final class TestObject extends AbstractTest {
232.40 + public static final String XML // TODO
232.41 + = "<java>\n"
232.42 + + " <object class=\"javax.swing.JPanel\">\n"
232.43 + + " <void method=\"add\">\n"
232.44 + + " <object id=\"button\" class=\"javax.swing.JButton\">\n"
232.45 + + " <string>button</string>\n"
232.46 + + " <void property=\"verticalAlignment\">\n"
232.47 + + " <object field=\"CENTER\" class=\"javax.swing.SwingConstants\"/>\n"
232.48 + + " </void>\n"
232.49 + + " </object>\n"
232.50 + + " </void>\n"
232.51 + + " <void method=\"add\">\n"
232.52 + + " <object class=\"javax.swing.JLabel\">\n"
232.53 + + " <string>label</string>\n"
232.54 + + " <void property=\"labelFor\">\n"
232.55 + + " <object idref=\"button\"/>\n"
232.56 + + " </void>\n"
232.57 + + " </object>\n"
232.58 + + " </void>\n"
232.59 + + " </object>\n"
232.60 + + "</java>";
232.61 +
232.62 + public static void main(String[] args) {
232.63 + new TestObject().test(true);
232.64 + }
232.65 +
232.66 + @Override
232.67 + protected void validate(XMLDecoder decoder) {
232.68 + JPanel panel = (JPanel) decoder.readObject();
232.69 + if (2 != panel.getComponents().length) {
232.70 + throw new Error("unexpected component count");
232.71 + }
232.72 + JButton button = (JButton) panel.getComponents()[0];
232.73 + if (!button.getText().equals("button")) { // NON-NLS: hardcoded in XML
232.74 + throw new Error("unexpected button text");
232.75 + }
232.76 + if (SwingConstants.CENTER != button.getVerticalAlignment()) {
232.77 + throw new Error("unexpected vertical alignment");
232.78 + }
232.79 + JLabel label = (JLabel) panel.getComponents()[1];
232.80 + if (!label.getText().equals("label")) { // NON-NLS: hardcoded in XML
232.81 + throw new Error("unexpected label text");
232.82 + }
232.83 + if (button != label.getLabelFor()) {
232.84 + throw new Error("unexpected component");
232.85 + }
232.86 + }
232.87 +}
233.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
233.2 +++ b/test/java/beans/XMLDecoder/spec/TestProperty.java Tue Feb 03 22:02:55 2009 -0800
233.3 @@ -0,0 +1,88 @@
233.4 +/*
233.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
233.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
233.7 + *
233.8 + * This code is free software; you can redistribute it and/or modify it
233.9 + * under the terms of the GNU General Public License version 2 only, as
233.10 + * published by the Free Software Foundation.
233.11 + *
233.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
233.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
233.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
233.15 + * version 2 for more details (a copy is included in the LICENSE file that
233.16 + * accompanied this code).
233.17 + *
233.18 + * You should have received a copy of the GNU General Public License version
233.19 + * 2 along with this work; if not, write to the Free Software Foundation,
233.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
233.21 + *
233.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
233.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
233.24 + * have any questions.
233.25 + */
233.26 +
233.27 +/*
233.28 + * @test
233.29 + * @summary Tests <property> element
233.30 + * @author Sergey Malenkov
233.31 + */
233.32 +
233.33 +import java.beans.XMLDecoder;
233.34 +
233.35 +public final class TestProperty extends AbstractTest {
233.36 + public static final String XML
233.37 + = "<java>\n"
233.38 + + " <property name=\"owner\">\n"
233.39 + + " <property name=\"message\">\n"
233.40 + + " <string>message</string>\n"
233.41 + + " </property>\n"
233.42 + + " <property id=\"message\" name=\"message\"/>\n"
233.43 + + " <property name=\"indexed\" index=\"1\">\n"
233.44 + + " <string>indexed</string>\n"
233.45 + + " </property>\n"
233.46 + + " <property id=\"indexed\" name=\"indexed\" index=\"1\"/>\n"
233.47 + + " </property>\n"
233.48 + + " <var idref=\"message\"/>\n"
233.49 + + " <var idref=\"indexed\"/>\n"
233.50 + + "</java>";
233.51 +
233.52 + public static void main(String[] args) {
233.53 + new TestProperty().test(true);
233.54 + }
233.55 +
233.56 + private int index;
233.57 + private String message;
233.58 +
233.59 + public String getMessage() {
233.60 + return this.message;
233.61 + }
233.62 +
233.63 + public void setMessage(String message) {
233.64 + this.message = message;
233.65 + }
233.66 +
233.67 + public String getIndexed(int index) {
233.68 + if (this.index != index) {
233.69 + throw new Error("unexpected index");
233.70 + }
233.71 + return this.message;
233.72 + }
233.73 +
233.74 + public void setIndexed(int index, String message) {
233.75 + this.index = index;
233.76 + this.message = message;
233.77 + }
233.78 +
233.79 + @Override
233.80 + protected void validate(XMLDecoder decoder) {
233.81 + decoder.setOwner(this);
233.82 + validate(decoder, "message");
233.83 + validate(decoder, "indexed");
233.84 + }
233.85 +
233.86 + private static void validate(XMLDecoder decoder, String name) {
233.87 + if (!decoder.readObject().equals(name)) {
233.88 + throw new Error(name + " expected");
233.89 + }
233.90 + }
233.91 +}
234.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
234.2 +++ b/test/java/beans/XMLDecoder/spec/TestShort.java Tue Feb 03 22:02:55 2009 -0800
234.3 @@ -0,0 +1,60 @@
234.4 +/*
234.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
234.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
234.7 + *
234.8 + * This code is free software; you can redistribute it and/or modify it
234.9 + * under the terms of the GNU General Public License version 2 only, as
234.10 + * published by the Free Software Foundation.
234.11 + *
234.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
234.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
234.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
234.15 + * version 2 for more details (a copy is included in the LICENSE file that
234.16 + * accompanied this code).
234.17 + *
234.18 + * You should have received a copy of the GNU General Public License version
234.19 + * 2 along with this work; if not, write to the Free Software Foundation,
234.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
234.21 + *
234.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
234.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
234.24 + * have any questions.
234.25 + */
234.26 +
234.27 +/*
234.28 + * @test
234.29 + * @summary Tests <short> element
234.30 + * @author Sergey Malenkov
234.31 + */
234.32 +
234.33 +import java.beans.XMLDecoder;
234.34 +
234.35 +public final class TestShort extends AbstractTest {
234.36 + public static final String XML
234.37 + = "<java>\n"
234.38 + + " <short>0</short>\n"
234.39 + + " <short>127</short>\n"
234.40 + + " <short>-128</short>\n"
234.41 + + " <short>32767</short>\n"
234.42 + + " <short>-32768</short>\n"
234.43 + + "</java>";
234.44 +
234.45 + public static void main(String[] args) {
234.46 + new TestShort().test(true);
234.47 + }
234.48 +
234.49 + @Override
234.50 + protected void validate(XMLDecoder decoder) {
234.51 + validate((short) 0, decoder.readObject());
234.52 + validate((short) Byte.MAX_VALUE, decoder.readObject());
234.53 + validate((short) Byte.MIN_VALUE, decoder.readObject());
234.54 + validate(Short.MAX_VALUE, decoder.readObject());
234.55 + validate(Short.MIN_VALUE, decoder.readObject());
234.56 + }
234.57 +
234.58 + private static void validate(short value, Object object) {
234.59 + if (!object.equals(Short.valueOf(value))) {
234.60 + throw new Error("short " + value + " expected");
234.61 + }
234.62 + }
234.63 +}
235.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
235.2 +++ b/test/java/beans/XMLDecoder/spec/TestString.java Tue Feb 03 22:02:55 2009 -0800
235.3 @@ -0,0 +1,60 @@
235.4 +/*
235.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
235.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
235.7 + *
235.8 + * This code is free software; you can redistribute it and/or modify it
235.9 + * under the terms of the GNU General Public License version 2 only, as
235.10 + * published by the Free Software Foundation.
235.11 + *
235.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
235.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
235.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
235.15 + * version 2 for more details (a copy is included in the LICENSE file that
235.16 + * accompanied this code).
235.17 + *
235.18 + * You should have received a copy of the GNU General Public License version
235.19 + * 2 along with this work; if not, write to the Free Software Foundation,
235.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
235.21 + *
235.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
235.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
235.24 + * have any questions.
235.25 + */
235.26 +
235.27 +/*
235.28 + * @test
235.29 + * @summary Tests <string> element
235.30 + * @author Sergey Malenkov
235.31 + */
235.32 +
235.33 +import java.beans.XMLDecoder;
235.34 +
235.35 +public final class TestString extends AbstractTest {
235.36 + public static final String PREFIX = " prefix ";
235.37 + public static final String POSTFIX = " postfix ";
235.38 + public static final String XML
235.39 + = "<java>\n"
235.40 + + " <string>" + PREFIX + "</string>\n"
235.41 + + " <string>" + POSTFIX + "</string>\n"
235.42 + + " <string>" + PREFIX + POSTFIX + "</string>\n"
235.43 + + " <string>" + PREFIX + "<char code=\"0\"/>" + POSTFIX + "</string>\n"
235.44 + + "</java>";
235.45 +
235.46 + public static void main(String[] args) {
235.47 + new TestString().test(true);
235.48 + }
235.49 +
235.50 + @Override
235.51 + protected void validate(XMLDecoder decoder) {
235.52 + validate(PREFIX, decoder.readObject());
235.53 + validate(POSTFIX, decoder.readObject());
235.54 + validate(PREFIX + POSTFIX, decoder.readObject());
235.55 + validate(PREFIX + '\u0000' + POSTFIX, decoder.readObject());
235.56 + }
235.57 +
235.58 + private static void validate(String name, Object object) {
235.59 + if (!object.equals(name)) {
235.60 + throw new Error(name + " expected");
235.61 + }
235.62 + }
235.63 +}
236.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
236.2 +++ b/test/java/beans/XMLDecoder/spec/TestTrue.java Tue Feb 03 22:02:55 2009 -0800
236.3 @@ -0,0 +1,48 @@
236.4 +/*
236.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
236.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
236.7 + *
236.8 + * This code is free software; you can redistribute it and/or modify it
236.9 + * under the terms of the GNU General Public License version 2 only, as
236.10 + * published by the Free Software Foundation.
236.11 + *
236.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
236.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
236.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
236.15 + * version 2 for more details (a copy is included in the LICENSE file that
236.16 + * accompanied this code).
236.17 + *
236.18 + * You should have received a copy of the GNU General Public License version
236.19 + * 2 along with this work; if not, write to the Free Software Foundation,
236.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
236.21 + *
236.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
236.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
236.24 + * have any questions.
236.25 + */
236.26 +
236.27 +/*
236.28 + * @test
236.29 + * @summary Tests <true> element
236.30 + * @author Sergey Malenkov
236.31 + */
236.32 +
236.33 +import java.beans.XMLDecoder;
236.34 +
236.35 +public final class TestTrue extends AbstractTest {
236.36 + public static final String XML
236.37 + = "<java>\n"
236.38 + + " <true/>\n"
236.39 + + "</java>";
236.40 +
236.41 + public static void main(String[] args) {
236.42 + new TestTrue().test(true);
236.43 + }
236.44 +
236.45 + @Override
236.46 + protected void validate(XMLDecoder decoder) {
236.47 + if (!Boolean.TRUE.equals(decoder.readObject())) {
236.48 + throw new Error("true expected");
236.49 + }
236.50 + }
236.51 +}
237.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
237.2 +++ b/test/java/beans/XMLDecoder/spec/TestVar.java Tue Feb 03 22:02:55 2009 -0800
237.3 @@ -0,0 +1,54 @@
237.4 +/*
237.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
237.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
237.7 + *
237.8 + * This code is free software; you can redistribute it and/or modify it
237.9 + * under the terms of the GNU General Public License version 2 only, as
237.10 + * published by the Free Software Foundation.
237.11 + *
237.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
237.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
237.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
237.15 + * version 2 for more details (a copy is included in the LICENSE file that
237.16 + * accompanied this code).
237.17 + *
237.18 + * You should have received a copy of the GNU General Public License version
237.19 + * 2 along with this work; if not, write to the Free Software Foundation,
237.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
237.21 + *
237.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
237.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
237.24 + * have any questions.
237.25 + */
237.26 +
237.27 +/*
237.28 + * @test
237.29 + * @summary Tests <var> element
237.30 + * @author Sergey Malenkov
237.31 + */
237.32 +
237.33 +import java.beans.XMLDecoder;
237.34 +
237.35 +public final class TestVar extends AbstractTest {
237.36 + public static final String XML
237.37 + = "<java id=\"decoder\">\n"
237.38 + + " <var idref=\"decoder\"/>\n"
237.39 + + " <var id=\"another\" idref=\"decoder\"/>\n"
237.40 + + " <var idref=\"another\"/>\n"
237.41 + + " <var id=\"decoder\" idref=\"another\"/>\n"
237.42 + + " <var idref=\"decoder\"/>\n"
237.43 + + "</java>";
237.44 +
237.45 + public static void main(String[] args) {
237.46 + new TestVar().test(true);
237.47 + }
237.48 +
237.49 + @Override
237.50 + protected void validate(XMLDecoder decoder) {
237.51 + for (int i = 0; i < 3; i++) {
237.52 + if (decoder != decoder.readObject()) {
237.53 + throw new Error("decoder instance expected");
237.54 + }
237.55 + }
237.56 + }
237.57 +}
238.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
238.2 +++ b/test/java/text/Bidi/BidiBug.java Tue Feb 03 22:02:55 2009 -0800
238.3 @@ -0,0 +1,41 @@
238.4 +/*
238.5 + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
238.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
238.7 + *
238.8 + * This code is free software; you can redistribute it and/or modify it
238.9 + * under the terms of the GNU General Public License version 2 only, as
238.10 + * published by the Free Software Foundation.
238.11 + *
238.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
238.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
238.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
238.15 + * version 2 for more details (a copy is included in the LICENSE file that
238.16 + * accompanied this code).
238.17 + *
238.18 + * You should have received a copy of the GNU General Public License version
238.19 + * 2 along with this work; if not, write to the Free Software Foundation,
238.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
238.21 + *
238.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
238.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
238.24 + * have any questions.
238.25 + */
238.26 +
238.27 +/*
238.28 + * @test
238.29 + * @bug 4827312
238.30 + * @summary verify that argument validity check is not fooled by overflow
238.31 + */
238.32 +public class BidiBug {
238.33 + public static void main(String[] args) {
238.34 + try {
238.35 + byte buff[] = new byte[3000];
238.36 + java.text.Bidi bidi = new java.text.Bidi(new char[20],10,buff,Integer.MAX_VALUE-3,4,1);
238.37 + }
238.38 + catch (IllegalArgumentException e) {
238.39 + System.out.println(e);
238.40 + return; // success
238.41 + }
238.42 + throw new RuntimeException("didn't throw error, though we didn't crash either");
238.43 + }
238.44 +}
239.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
239.2 +++ b/test/java/text/Bidi/BidiEmbeddingTest.java Tue Feb 03 22:02:55 2009 -0800
239.3 @@ -0,0 +1,132 @@
239.4 +/*
239.5 + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
239.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
239.7 + *
239.8 + * This code is free software; you can redistribute it and/or modify it
239.9 + * under the terms of the GNU General Public License version 2 only, as
239.10 + * published by the Free Software Foundation.
239.11 + *
239.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
239.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
239.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
239.15 + * version 2 for more details (a copy is included in the LICENSE file that
239.16 + * accompanied this code).
239.17 + *
239.18 + * You should have received a copy of the GNU General Public License version
239.19 + * 2 along with this work; if not, write to the Free Software Foundation,
239.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
239.21 + *
239.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
239.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
239.24 + * have any questions.
239.25 + */
239.26 +
239.27 +/*
239.28 + * @test
239.29 + * @bug 4396492 4396496 4778510
239.30 + * @summary verify that the embedding values processed by the bidi code use negative values to
239.31 + * indicate overrides, rather than using bit 7. Also tests Bidi without loading awt classes to
239.32 + * confirm that Bidi can be used without awt. Verify that embedding level 0 is properly mapped
239.33 + * to the base embedding level.
239.34 + */
239.35 +
239.36 +import java.awt.Color;
239.37 +import java.awt.Frame;
239.38 +import java.awt.font.TextAttribute;
239.39 +import java.text.AttributedString;
239.40 +import java.text.Bidi;
239.41 +
239.42 +public class BidiEmbeddingTest {
239.43 + public static void main(String[] args) {
239.44 + // to regress embedding test against old fix, call with an arg. A window will pop
239.45 + // up causing awt lib to be loaded so the vm won't die with the unsatisfied link error.
239.46 + if (args.length > 0) {
239.47 + Frame f = new Frame();
239.48 + f.setSize(300, 300);
239.49 + f.setBackground(Color.white);
239.50 + f.show();
239.51 + }
239.52 +
239.53 + test1();
239.54 + test2();
239.55 + }
239.56 +
239.57 + static void test1() {
239.58 + String target = "BACK WARDS";
239.59 + String str = "If this text is >" + target + "< the test passed.";
239.60 + int start = str.indexOf(target);
239.61 + int limit = start + target.length();
239.62 +
239.63 + System.out.println("start: " + start + " limit: " + limit);
239.64 +
239.65 + AttributedString astr = new AttributedString(str);
239.66 + astr.addAttribute(TextAttribute.BIDI_EMBEDDING,
239.67 + new Integer(-1),
239.68 + start,
239.69 + limit);
239.70 +
239.71 + Bidi bidi = new Bidi(astr.getIterator());
239.72 +
239.73 + for (int i = 0; i < bidi.getRunCount(); ++i) {
239.74 + System.out.println("run " + i +
239.75 + " from " + bidi.getRunStart(i) +
239.76 + " to " + bidi.getRunLimit(i) +
239.77 + " at level " + bidi.getRunLevel(i));
239.78 + }
239.79 +
239.80 + System.out.println(bidi);
239.81 +
239.82 + byte[] embs = new byte[str.length() + 3];
239.83 + for (int i = start + 1; i < limit + 1; ++i) {
239.84 + embs[i] = -1;
239.85 + }
239.86 +
239.87 + Bidi bidi2 = new Bidi(str.toCharArray(), 0, embs, 1, str.length(), Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
239.88 + for (int i = 0; i < bidi2.getRunCount(); ++i) {
239.89 + System.out.println("run " + i +
239.90 + " from " + bidi2.getRunStart(i) +
239.91 + " to " + bidi2.getRunLimit(i) +
239.92 + " at level " + bidi2.getRunLevel(i));
239.93 + }
239.94 +
239.95 + System.out.println(bidi2);
239.96 +
239.97 + if (bidi.getRunCount() != 3 || bidi2.getRunCount() != 3) {
239.98 + throw new Error("Bidi run count incorrect");
239.99 + }
239.100 + }
239.101 +
239.102 + // make sure BIDI_EMBEDDING values of 0 are mapped to base run direction, instead of flagging an error.
239.103 + static void test2() {
239.104 + String target = "BACK WARDS";
239.105 + String str = "If this text is >" + target + "< the test passed.";
239.106 + int length = str.length();
239.107 + int start = str.indexOf(target);
239.108 + int limit = start + target.length();
239.109 +
239.110 + System.out.println("start: " + start + " limit: " + limit);
239.111 +
239.112 + AttributedString astr = new AttributedString(str);
239.113 + astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
239.114 +
239.115 + astr.addAttribute(TextAttribute.BIDI_EMBEDDING,
239.116 + new Integer(-3),
239.117 + start,
239.118 + limit);
239.119 +
239.120 + Bidi bidi = new Bidi(astr.getIterator());
239.121 +
239.122 + for (int i = 0; i < bidi.getRunCount(); ++i) {
239.123 + System.out.println("run " + i +
239.124 + " from " + bidi.getRunStart(i) +
239.125 + " to " + bidi.getRunLimit(i) +
239.126 + " at level " + bidi.getRunLevel(i));
239.127 + }
239.128 +
239.129 + System.out.println(bidi);
239.130 +
239.131 + if (bidi.getRunCount() != 6) { // runs of spaces and angles at embedding bound,s and final period, each get level 1
239.132 + throw new Error("Bidi embedding processing failed");
239.133 + }
239.134 + }
239.135 +}
240.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
240.2 +++ b/test/java/text/Bidi/BidiSurrogateTest.java Tue Feb 03 22:02:55 2009 -0800
240.3 @@ -0,0 +1,103 @@
240.4 +/*
240.5 + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
240.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
240.7 + *
240.8 + * This code is free software; you can redistribute it and/or modify it
240.9 + * under the terms of the GNU General Public License version 2 only, as
240.10 + * published by the Free Software Foundation.
240.11 + *
240.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
240.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
240.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
240.15 + * version 2 for more details (a copy is included in the LICENSE file that
240.16 + * accompanied this code).
240.17 + *
240.18 + * You should have received a copy of the GNU General Public License version
240.19 + * 2 along with this work; if not, write to the Free Software Foundation,
240.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
240.21 + *
240.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
240.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
240.24 + * have any questions.
240.25 + */
240.26 +
240.27 +/*
240.28 + * @test
240.29 + * @bug 4888843
240.30 + * @summary verify that surrogate pairs representing codepoints with R or AL directionality
240.31 + * and correctly recognized and reordered.
240.32 + */
240.33 +
240.34 +import java.text.Bidi;
240.35 +
240.36 +public class BidiSurrogateTest {
240.37 + private static final String RTLS = new String(Character.toChars(0x10800)); // surrogate code point with R directionality
240.38 + private static final String LTRS = new String(Character.toChars(0x107ff)); // surrogate code point with L directionality
240.39 + private static final String LRE = "\u202a";
240.40 + private static final String RLE = "\u202b";
240.41 + private static final String PDF = "\u202c";
240.42 +
240.43 +
240.44 + public static void main(String[] args) {
240.45 + new BidiSurrogateTest().test();
240.46 + }
240.47 +
240.48 + void test() {
240.49 + test0();
240.50 + test1();
240.51 + }
240.52 +
240.53 + void test0() {
240.54 + // test unpaired surrogates - should have L directionality
240.55 + testRequiresBidi("\ud800", false); // unpaired lead surrogate
240.56 + testRequiresBidi("\udc00", false); // unpaired trail surrogate
240.57 + testRequiresBidi("\udc00\ud800", false); // out of order surrogates
240.58 + testRequiresBidi("a\udc00b\ud800c", false); // out of order surrogates split
240.59 + testRequiresBidi(LTRS, false); // supplementary with L
240.60 + testRequiresBidi(RTLS, true); // supplementary with R
240.61 + testRequiresBidi("a" + RTLS + "b", true); // R supplementary in LTR text
240.62 + testRequiresBidi(LTRS + RTLS, true); // R supplementary in LTR supplementary text
240.63 + testRequiresBidi(LRE, false); // LRE lone embedding
240.64 + testRequiresBidi(RLE, true); // RLE lone embedding
240.65 + testRequiresBidi(PDF, false); // PDF lone pop embedding
240.66 + }
240.67 +
240.68 + void testRequiresBidi(String string, boolean requiresBidi) {
240.69 + char[] text = string.toCharArray();
240.70 + if (Bidi.requiresBidi(text, 0, text.length) != requiresBidi) {
240.71 + throw new RuntimeException("testRequiresBidi failed with '" + string + "', " + requiresBidi);
240.72 + }
240.73 + }
240.74 +
240.75 + void test1() {
240.76 + // test that strings with surrogate runs process surrogate directionality ok
240.77 + testBidi("This is a string with " + LTRS + " in it.", false);
240.78 + testBidi("This is a string with \ud800 in it.", false);
240.79 + testBidi("This is a string with \u0640 in it.", 22, 1);
240.80 + testBidi(RTLS, true);
240.81 + testBidi("This is a string with " + RTLS + RTLS + RTLS + " in it.", 22, 6);
240.82 + }
240.83 +
240.84 + void testBidi(String string, boolean directionIsRTL) {
240.85 + Bidi bidi = new Bidi(string, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
240.86 + if (bidi.isMixed()) {
240.87 + throw new RuntimeException("bidi is mixed");
240.88 + }
240.89 + if (bidi.isRightToLeft() != directionIsRTL) {
240.90 + throw new RuntimeException("bidi is not " + (directionIsRTL ? "rtl" : "ltr"));
240.91 + }
240.92 + }
240.93 +
240.94 + void testBidi(String string, int rtlstart, int rtllength) {
240.95 + Bidi bidi = new Bidi(string, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
240.96 + for (int i = 0; i < bidi.getRunCount(); ++i) {
240.97 + if ((bidi.getRunLevel(i) & 1) != 0) {
240.98 + if (bidi.getRunStart(i) != rtlstart ||
240.99 + bidi.getRunLimit(i) != rtlstart + rtllength) {
240.100 + throw new RuntimeException("first rtl run didn't match " + rtlstart + ", " + rtllength);
240.101 + }
240.102 + break;
240.103 + }
240.104 + }
240.105 + }
240.106 +}
241.1 --- a/test/java/text/Format/DateFormat/Bug4823811.java Thu Jan 29 21:46:48 2009 -0800
241.2 +++ b/test/java/text/Format/DateFormat/Bug4823811.java Tue Feb 03 22:02:55 2009 -0800
241.3 @@ -25,6 +25,7 @@
241.4 * @test
241.5 * @bug 4823811
241.6 * @summary Confirm that text which includes numbers with a trailing minus sign is parsed correctly.
241.7 + * @run main/othervm -Duser.timezone=GMT+09:00 Bug4823811
241.8 */
241.9
241.10 import java.text.*;
242.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
242.2 +++ b/test/java/text/Format/DateFormat/Bug6683975.java Tue Feb 03 22:02:55 2009 -0800
242.3 @@ -0,0 +1,114 @@
242.4 +/*
242.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
242.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
242.7 + *
242.8 + * This code is free software; you can redistribute it and/or modify it
242.9 + * under the terms of the GNU General Public License version 2 only, as
242.10 + * published by the Free Software Foundation.
242.11 + *
242.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
242.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
242.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
242.15 + * version 2 for more details (a copy is included in the LICENSE file that
242.16 + * accompanied this code).
242.17 + *
242.18 + * You should have received a copy of the GNU General Public License version
242.19 + * 2 along with this work; if not, write to the Free Software Foundation,
242.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
242.21 + *
242.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
242.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
242.24 + * have any questions.
242.25 + */
242.26 +
242.27 +/**
242.28 + * @test
242.29 + * @bug 6683975
242.30 + * @summary Make sure that date is formatted correctlyin th locale.
242.31 + */
242.32 +import java.text.*;
242.33 +import java.util.*;
242.34 +
242.35 +public class Bug6683975 {
242.36 +
242.37 + private static boolean err = false;
242.38 +
242.39 + private static Locale th = new Locale("th", "");
242.40 + private static Locale th_TH = new Locale("th", "TH");
242.41 + private static String expected_th[] = {
242.42 + "\u0e27\u0e31\u0e19\u0e2d\u0e31\u0e07\u0e04\u0e32\u0e23\u0e17\u0e35\u0e48 30 \u0e01\u0e31\u0e19\u0e22\u0e32\u0e22\u0e19 \u0e04.\u0e28. 2008, 8 \u0e19\u0e32\u0e2c\u0e34\u0e01\u0e32 0 \u0e19\u0e32\u0e17\u0e35 00 \u0e27\u0e34\u0e19\u0e32\u0e17\u0e35", // 0: FULL
242.43 + "30 \u0e01\u0e31\u0e19\u0e22\u0e32\u0e22\u0e19 2008, 8 \u0e19\u0e32\u0e2c\u0e34\u0e01\u0e32 0 \u0e19\u0e32\u0e17\u0e35", // 1: LONG
242.44 + "30 \u0e01.\u0e22. 2008, 8:00:00", // 2: MEDIUM
242.45 + "30/9/2008, 8:00 \u0e19.", // 3: SHORT
242.46 + };
242.47 + private static String expected_th_TH[] = {
242.48 + "\u0e27\u0e31\u0e19\u0e2d\u0e31\u0e07\u0e04\u0e32\u0e23\u0e17\u0e35\u0e48 30 \u0e01\u0e31\u0e19\u0e22\u0e32\u0e22\u0e19 \u0e1e.\u0e28. 2551, 8 \u0e19\u0e32\u0e2c\u0e34\u0e01\u0e32 0 \u0e19\u0e32\u0e17\u0e35 00 \u0e27\u0e34\u0e19\u0e32\u0e17\u0e35", // 0: FULL
242.49 + "30 \u0e01\u0e31\u0e19\u0e22\u0e32\u0e22\u0e19 2551, 8 \u0e19\u0e32\u0e2c\u0e34\u0e01\u0e32 0 \u0e19\u0e32\u0e17\u0e35", // 1: LONG
242.50 + "30 \u0e01.\u0e22. 2551, 8:00:00", // 2: MEDIUM
242.51 + "30/9/2551, 8:00 \u0e19." // 3: SHORT
242.52 + };
242.53 + private static String stylePattern[] = {
242.54 + "FULL", "LONG", "MEDIUM", "SHORT"
242.55 + };
242.56 +
242.57 + private static void test(int style) {
242.58 + DateFormat df_th = DateFormat.getDateTimeInstance(style, style, th);
242.59 + DateFormat df_th_TH = DateFormat.getDateTimeInstance(style, style, th_TH);
242.60 +
242.61 + String str_th = ((SimpleDateFormat)df_th).toPattern();
242.62 + String str_th_TH = ((SimpleDateFormat)df_th_TH).toPattern();
242.63 + if (!str_th.equals(str_th_TH)) {
242.64 + err = true;
242.65 + System.err.println("Error: Pattern for th locale should be the same as pattern for th_TH locale. (" + stylePattern[style] + ")");
242.66 + System.err.println("\tth: " + str_th);
242.67 + System.err.println("\tth_TH: " + str_th_TH);
242.68 + }
242.69 +
242.70 + Date date = new Date(2008-1900, Calendar.SEPTEMBER, 30, 8, 0, 0);
242.71 + str_th = df_th.format(date);
242.72 + if (!expected_th[style].equals(str_th)) {
242.73 + err = true;
242.74 + System.err.println("Error: Formatted date in th locale is incorrect in " + stylePattern[style] + " pattern.");
242.75 + System.err.println("\tExpected: " + expected_th[style]);
242.76 + System.err.println("\tGot: " + str_th);
242.77 + }
242.78 +
242.79 + str_th_TH = df_th_TH.format(date);
242.80 + if (!expected_th_TH[style].equals(str_th_TH)) {
242.81 + err = true;
242.82 + System.err.println("Error: Formatted date in th_TH locale is incorrect in " + stylePattern[style] + " pattern.");
242.83 + System.err.println("\tExpected: " + expected_th_TH[style]);
242.84 + System.err.println("\tGot: " + str_th_TH);
242.85 + }
242.86 + }
242.87 +
242.88 + public static void main(String[] args) {
242.89 + TimeZone timezone = TimeZone.getDefault();
242.90 + Locale locale = Locale.getDefault();
242.91 +
242.92 + TimeZone.setDefault(TimeZone.getTimeZone("US/Pacific"));
242.93 + Locale.setDefault(Locale.US);
242.94 +
242.95 + try {
242.96 + test(DateFormat.FULL);
242.97 + test(DateFormat.LONG);
242.98 + test(DateFormat.MEDIUM);
242.99 + test(DateFormat.SHORT);
242.100 + }
242.101 + catch (Exception e) {
242.102 + err = true;
242.103 + System.err.println("Unexpected exception was thrown: " + e);
242.104 + }
242.105 + finally {
242.106 + TimeZone.setDefault(timezone);
242.107 + Locale.setDefault(locale);
242.108 +
242.109 + if (err) {
242.110 + throw new RuntimeException("Failed.");
242.111 + } else {
242.112 + System.out.println("Passed.");
242.113 + }
242.114 + }
242.115 + }
242.116 +
242.117 +}
243.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
243.2 +++ b/test/java/util/Calendar/Bug6645263.java Tue Feb 03 22:02:55 2009 -0800
243.3 @@ -0,0 +1,47 @@
243.4 +/*
243.5 + * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
243.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
243.7 + *
243.8 + * This code is free software; you can redistribute it and/or modify it
243.9 + * under the terms of the GNU General Public License version 2 only, as
243.10 + * published by the Free Software Foundation.
243.11 + *
243.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
243.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
243.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
243.15 + * version 2 for more details (a copy is included in the LICENSE file that
243.16 + * accompanied this code).
243.17 + *
243.18 + * You should have received a copy of the GNU General Public License version
243.19 + * 2 along with this work; if not, write to the Free Software Foundation,
243.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
243.21 + *
243.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
243.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
243.24 + * have any questions.
243.25 + */
243.26 +/*
243.27 + * @test
243.28 + * @bug 6645263
243.29 + * @summary Test field normalization in non-lenient from the partially normalized state
243.30 + */
243.31 +
243.32 +import java.util.*;
243.33 +
243.34 +public class Bug6645263 {
243.35 + public static void main(String[] args) {
243.36 + Calendar cal = new GregorianCalendar(Locale.US);
243.37 + cal.setLenient(false);
243.38 + cal.set(Calendar.YEAR, 2007);
243.39 + cal.set(Calendar.MONTH, Calendar.NOVEMBER);
243.40 + cal.set(Calendar.WEEK_OF_MONTH, 4);
243.41 + cal.set(Calendar.DAY_OF_WEEK, 1);
243.42 + // Let cal calculate the time from the given fields
243.43 + cal.getTime();
243.44 +
243.45 + // Change DAY_OF_MONTH
243.46 + cal.set(Calendar.DAY_OF_MONTH, 1);
243.47 + // The following line shouldn't throw an IllegalArgumentException.
243.48 + cal.getTime();
243.49 + }
243.50 +}
244.1 --- a/test/java/util/Currency/ValidateISO4217.java Thu Jan 29 21:46:48 2009 -0800
244.2 +++ b/test/java/util/Currency/ValidateISO4217.java Tue Feb 03 22:02:55 2009 -0800
244.3 @@ -22,7 +22,7 @@
244.4 */
244.5 /*
244.6 * @test
244.7 - * @bug 4691089 4819436 4942982 5104960 6544471
244.8 + * @bug 4691089 4819436 4942982 5104960 6544471 6627549
244.9 * @summary Validate ISO 4217 data for Currency class.
244.10 */
244.11
244.12 @@ -86,6 +86,8 @@
244.13 {"JE", "GBP", "826", "2"}, // Jersey
244.14 {"GG", "GBP", "826", "2"}, // Guernsey
244.15 {"IM", "GBP", "826", "2"}, // Isle of Man
244.16 + {"BL", "EUR", "978", "2"}, // Saint Barthelemy
244.17 + {"MF", "EUR", "978", "2"}, // Saint Martin
244.18 };
244.19
244.20 /* Codes that are obsolete, do not have related country */
245.1 --- a/test/java/util/Locale/LocaleTest.java Thu Jan 29 21:46:48 2009 -0800
245.2 +++ b/test/java/util/Locale/LocaleTest.java Tue Feb 03 22:02:55 2009 -0800
245.3 @@ -24,7 +24,7 @@
245.4 * @test
245.5 * @bug 4052404 4052440 4084688 4092475 4101316 4105828 4107014 4107953 4110613
245.6 * 4118587 4118595 4122371 4126371 4126880 4135316 4135752 4139504 4139940 4143951
245.7 - * 4147315 4147317 4147552 4335196 4778440 5010672 6475525 6544471
245.8 + * 4147315 4147317 4147552 4335196 4778440 5010672 6475525 6544471 6627549 6786276
245.9 * @summary test Locales
245.10 */
245.11 /*
245.12 @@ -439,8 +439,8 @@
245.13 String[] spotCheck2 = { "US", "CA", "GB", "FR", "DE", "IT", "JP", "KR", "CN", "TW", "TH" };
245.14
245.15
245.16 - if (test.length != 245)
245.17 - errln("Expected getISOCountries to return 245 countries; it returned " + test.length);
245.18 + if (test.length != 246)
245.19 + errln("Expected getISOCountries to return 246 countries; it returned " + test.length);
245.20 else {
245.21 for (int i = 0; i < spotCheck2.length; i++) {
245.22 int j;
246.1 --- a/test/java/util/Locale/data/deflocale.sol10 Thu Jan 29 21:46:48 2009 -0800
246.2 +++ b/test/java/util/Locale/data/deflocale.sol10 Tue Feb 03 22:02:55 2009 -0800
246.3 @@ -1,7 +1,7 @@
246.4 Solaris 10 3/05 s10_74L2a SPARC
246.5 - Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
246.6 - Use is subject to license terms.
246.7 - Assembled 22 January 2005
246.8 +
246.9 + (copyright from `uname -a` goes here)
246.10 +
246.11 SunOS deltas4 5.10 Generic_118833-03 sun4u sparc SUNW,Sun-Blade-2500
246.12
246.13 OS Locale: C
247.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
247.2 +++ b/test/javax/sound/midi/Gervill/AudioFloatConverter/GetFormat.java Tue Feb 03 22:02:55 2009 -0800
247.3 @@ -0,0 +1,41 @@
247.4 +/*
247.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
247.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
247.7 + *
247.8 + * This code is free software; you can redistribute it and/or modify it
247.9 + * under the terms of the GNU General Public License version 2 only, as
247.10 + * published by the Free Software Foundation. Sun designates this
247.11 + * particular file as subject to the "Classpath" exception as provided
247.12 + * by Sun in the LICENSE file that accompanied this code.
247.13 + *
247.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
247.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
247.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
247.17 + * version 2 for more details (a copy is included in the LICENSE file that
247.18 + * accompanied this code).
247.19 + *
247.20 + * You should have received a copy of the GNU General Public License version
247.21 + * 2 along with this work; if not, write to the Free Software Foundation,
247.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
247.23 + *
247.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
247.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
247.26 + * have any questions.
247.27 + */
247.28 +
247.29 +/* @test
247.30 + @summary Test AudioFloatConverter getFormat method */
247.31 +
247.32 +import javax.sound.sampled.*;
247.33 +import com.sun.media.sound.*;
247.34 +
247.35 +public class GetFormat {
247.36 +
247.37 + public static void main(String[] args) throws Exception {
247.38 + AudioFormat frm = new AudioFormat(8000, 16, 1, true, false);
247.39 + AudioFloatConverter conv = AudioFloatConverter.getConverter(frm);
247.40 + if(!conv.getFormat().matches(frm))
247.41 + throw new RuntimeException("Incorrect audio format returned.");
247.42 + }
247.43 +
247.44 +}
248.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
248.2 +++ b/test/javax/sound/midi/Gervill/AudioFloatConverter/ToFloatArray.java Tue Feb 03 22:02:55 2009 -0800
248.3 @@ -0,0 +1,160 @@
248.4 +/*
248.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
248.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
248.7 + *
248.8 + * This code is free software; you can redistribute it and/or modify it
248.9 + * under the terms of the GNU General Public License version 2 only, as
248.10 + * published by the Free Software Foundation. Sun designates this
248.11 + * particular file as subject to the "Classpath" exception as provided
248.12 + * by Sun in the LICENSE file that accompanied this code.
248.13 + *
248.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
248.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
248.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
248.17 + * version 2 for more details (a copy is included in the LICENSE file that
248.18 + * accompanied this code).
248.19 + *
248.20 + * You should have received a copy of the GNU General Public License version
248.21 + * 2 along with this work; if not, write to the Free Software Foundation,
248.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
248.23 + *
248.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
248.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
248.26 + * have any questions.
248.27 + */
248.28 +
248.29 +/* @test
248.30 + @summary Test AudioFloatConverter toFloatArray method */
248.31 +
248.32 +import javax.sound.sampled.*;
248.33 +
248.34 +import com.sun.media.sound.*;
248.35 +
248.36 +public class ToFloatArray {
248.37 +
248.38 + public static void main(String[] args) throws Exception {
248.39 + float[] testarray = new float[1024];
248.40 + for (int i = 0; i < 1024; i++) {
248.41 + double ii = i / 1024.0;
248.42 + ii = ii * ii;
248.43 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
248.44 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
248.45 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
248.46 + testarray[i] *= 0.3;
248.47 + }
248.48 +
248.49 + // Check conversion using PCM_FLOAT
248.50 + for (int big = 0; big < 2; big+=1)
248.51 + for (int bits = 32; bits <= 64; bits+=32) {
248.52 + AudioFormat frm = new AudioFormat(
248.53 + AudioFloatConverter.PCM_FLOAT,
248.54 + 44100, bits, 1, bits/8,
248.55 + 44100, big==1);
248.56 + byte[] buff = new byte[testarray.length * frm.getFrameSize()];
248.57 + float[] testarray2 = new float[testarray.length];
248.58 + AudioFloatConverter conv = AudioFloatConverter.getConverter(frm);
248.59 + conv.toByteArray(testarray, buff);
248.60 + conv.toFloatArray(buff, testarray2);
248.61 + for (int i = 0; i < testarray2.length; i++) {
248.62 + if(Math.abs(testarray[i] - testarray2[i]) > 0.05)
248.63 + throw new RuntimeException("Conversion failed for " + frm +" , arrays not equal enough!\n");
248.64 + }
248.65 + }
248.66 +
248.67 + // Check conversion from float2byte and byte2float.
248.68 + for (int big = 0; big < 2; big+=1)
248.69 + for (int signed = 0; signed < 2; signed+=1)
248.70 + for (int bits = 6; bits <= 40; bits+=2) {
248.71 + AudioFormat frm = new AudioFormat(44100, bits, 1, signed==1, big==1);
248.72 + byte[] buff = new byte[testarray.length * frm.getFrameSize()];
248.73 + float[] testarray2 = new float[testarray.length];
248.74 + AudioFloatConverter conv = AudioFloatConverter.getConverter(frm);
248.75 + conv.toByteArray(testarray, buff);
248.76 + conv.toFloatArray(buff, testarray2);
248.77 + for (int i = 0; i < testarray2.length; i++) {
248.78 + if(Math.abs(testarray[i] - testarray2[i]) > 0.05)
248.79 + throw new RuntimeException("Conversion failed for " + frm +" , arrays not equal enough!\n");
248.80 + }
248.81 + }
248.82 +
248.83 + // Check big/little
248.84 + for (int big = 0; big < 2; big+=1)
248.85 + for (int signed = 0; signed < 2; signed+=1)
248.86 + for (int bits = 6; bits <= 40; bits+=2) {
248.87 + AudioFormat frm = new AudioFormat(44100, bits, 1, signed==1, big==1);
248.88 + byte[] buff = new byte[testarray.length * frm.getFrameSize()];
248.89 + AudioFloatConverter conv = AudioFloatConverter.getConverter(frm);
248.90 + conv.toByteArray(testarray, buff);
248.91 + byte[] buff2 = new byte[testarray.length * frm.getFrameSize()];
248.92 + int fs = frm.getFrameSize();
248.93 + for (int i = 0; i < buff2.length; i+=fs) {
248.94 + for (int j = 0; j < fs; j++) {
248.95 + buff2[i+(fs-j-1)] = buff[i+j];
248.96 + }
248.97 + }
248.98 + float[] testarray2 = new float[testarray.length];
248.99 + AudioFormat frm2 = new AudioFormat(44100, bits, 1, signed==1, big==0);
248.100 + AudioFloatConverter.getConverter(frm2).toFloatArray(buff2, testarray2);
248.101 + for (int i = 0; i < testarray2.length; i++) {
248.102 + if(Math.abs(testarray[i] - testarray2[i]) > 0.05)
248.103 + {
248.104 + throw new RuntimeException("Conversion failed for " + frm +" to " + frm2 + " , arrays not equal enough!\n");
248.105 + }
248.106 + }
248.107 + }
248.108 +
248.109 + // Check signed/unsigned
248.110 + for (int big = 0; big < 2; big+=1)
248.111 + for (int signed = 0; signed < 2; signed+=1)
248.112 + for (int bits = 6; bits <= 40; bits+=2) {
248.113 + AudioFormat frm = new AudioFormat(44100, bits, 1, signed==1, big==1);
248.114 + byte[] b = new byte[testarray.length * frm.getFrameSize()];
248.115 + AudioFloatConverter conv = AudioFloatConverter.getConverter(frm);
248.116 + conv.toByteArray(testarray, b);
248.117 + int fs = frm.getFrameSize();
248.118 + if(big==1)
248.119 + {
248.120 + for(int i=0; i < b.length; i+= fs )
248.121 + b[i] = (b[i] >= 0) ? (byte)(0x80 | b[i]) : (byte)(0x7F & b[i]);
248.122 + }
248.123 + else
248.124 + {
248.125 + for(int i=(0+fs-1); i < b.length; i+= fs )
248.126 + b[i] = (b[i] >= 0) ? (byte)(0x80 | b[i]) : (byte)(0x7F & b[i]);
248.127 + }
248.128 + float[] testarray2 = new float[testarray.length];
248.129 + AudioFormat frm2 = new AudioFormat(44100, bits, 1, signed==0, big==1);
248.130 + AudioFloatConverter.getConverter(frm2).toFloatArray(b, testarray2);
248.131 + for (int i = 0; i < testarray2.length; i++) {
248.132 + if(Math.abs(testarray[i] - testarray2[i]) > 0.05)
248.133 + {
248.134 + throw new RuntimeException("Conversion failed for " + frm +" to " + frm2 + " , arrays not equal enough!\n");
248.135 + }
248.136 + }
248.137 + }
248.138 +
248.139 + // Check if conversion 32->24, 24->16, 16->8 result in same float data
248.140 + AudioFormat frm = new AudioFormat(44100, 40, 1, true, true);
248.141 + byte[] b = new byte[testarray.length * frm.getFrameSize()];
248.142 + AudioFloatConverter.getConverter(frm).toByteArray(testarray, b);
248.143 + for (int bits = 6; bits <= 40; bits+=2) {
248.144 + AudioFormat frm2 = new AudioFormat(44100, bits, 1, true, true);
248.145 + byte[] b2 = new byte[testarray.length * frm2.getFrameSize()];
248.146 + int fs1 = frm.getFrameSize();
248.147 + int fs2 = frm2.getFrameSize();
248.148 + int ii = 0;
248.149 + for (int i = 0; i < b.length; i+=fs1)
248.150 + for (int j = 0; j < fs2; j++)
248.151 + b2[ii++] = b[i+j];
248.152 + float[] testarray2 = new float[testarray.length];
248.153 + AudioFloatConverter.getConverter(frm2).toFloatArray(b2, testarray2);
248.154 + for (int i = 0; i < testarray2.length; i++) {
248.155 + if(Math.abs(testarray[i] - testarray2[i]) > 0.05)
248.156 + {
248.157 + throw new RuntimeException("Conversion failed for " + frm +" to " + frm2 + " , arrays not equal enough!\n");
248.158 + }
248.159 + }
248.160 + }
248.161 + }
248.162 +
248.163 +}
249.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
249.2 +++ b/test/javax/sound/midi/Gervill/AudioFloatInputStream/Available.java Tue Feb 03 22:02:55 2009 -0800
249.3 @@ -0,0 +1,81 @@
249.4 +/*
249.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
249.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
249.7 + *
249.8 + * This code is free software; you can redistribute it and/or modify it
249.9 + * under the terms of the GNU General Public License version 2 only, as
249.10 + * published by the Free Software Foundation. Sun designates this
249.11 + * particular file as subject to the "Classpath" exception as provided
249.12 + * by Sun in the LICENSE file that accompanied this code.
249.13 + *
249.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
249.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
249.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
249.17 + * version 2 for more details (a copy is included in the LICENSE file that
249.18 + * accompanied this code).
249.19 + *
249.20 + * You should have received a copy of the GNU General Public License version
249.21 + * 2 along with this work; if not, write to the Free Software Foundation,
249.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
249.23 + *
249.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
249.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
249.26 + * have any questions.
249.27 + */
249.28 +
249.29 +/* @test
249.30 + @summary Test AudioFloatInputStream available method */
249.31 +
249.32 +import java.io.*;
249.33 +
249.34 +import javax.sound.sampled.*;
249.35 +
249.36 +import com.sun.media.sound.*;
249.37 +
249.38 +public class Available {
249.39 +
249.40 + static float[] test_float_array;
249.41 + static byte[] test_byte_array;
249.42 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
249.43 +
249.44 + static AudioFloatInputStream getStream1()
249.45 + {
249.46 + return AudioFloatInputStream.getInputStream(format, test_byte_array, 0, test_byte_array.length);
249.47 + }
249.48 +
249.49 + static AudioFloatInputStream getStream2()
249.50 + {
249.51 + AudioInputStream strm = new AudioInputStream(new ByteArrayInputStream(test_byte_array), format, 1024);
249.52 + return AudioFloatInputStream.getInputStream(strm);
249.53 + }
249.54 +
249.55 + static void setUp() throws Exception {
249.56 + test_float_array = new float[1024];
249.57 + test_byte_array = new byte[1024*format.getFrameSize()];
249.58 + for (int i = 0; i < 1024; i++) {
249.59 + double ii = i / 1024.0;
249.60 + ii = ii * ii;
249.61 + test_float_array[i] = (float)Math.sin(10*ii*2*Math.PI);
249.62 + test_float_array[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
249.63 + test_float_array[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
249.64 + test_float_array[i] *= 0.3;
249.65 + }
249.66 + AudioFloatConverter.getConverter(format).toByteArray(test_float_array, test_byte_array);
249.67 + }
249.68 +
249.69 + public static void main(String[] args) throws Exception {
249.70 + setUp();
249.71 + for (int i = 0; i < 2; i++) {
249.72 + AudioFloatInputStream stream = null;
249.73 + if(i == 0) stream = getStream1();
249.74 + if(i == 1) stream = getStream2();
249.75 + float[] buff = new float[512];
249.76 + if(stream.available() != 1024)
249.77 + throw new RuntimeException("stream.available return incorrect value.");
249.78 + stream.read(buff);
249.79 + if(stream.available() != 512)
249.80 + throw new RuntimeException("stream.available return incorrect value.");
249.81 + }
249.82 + }
249.83 +
249.84 +}
250.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
250.2 +++ b/test/javax/sound/midi/Gervill/AudioFloatInputStream/Close.java Tue Feb 03 22:02:55 2009 -0800
250.3 @@ -0,0 +1,72 @@
250.4 +/*
250.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
250.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
250.7 + *
250.8 + * This code is free software; you can redistribute it and/or modify it
250.9 + * under the terms of the GNU General Public License version 2 only, as
250.10 + * published by the Free Software Foundation. Sun designates this
250.11 + * particular file as subject to the "Classpath" exception as provided
250.12 + * by Sun in the LICENSE file that accompanied this code.
250.13 + *
250.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
250.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
250.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
250.17 + * version 2 for more details (a copy is included in the LICENSE file that
250.18 + * accompanied this code).
250.19 + *
250.20 + * You should have received a copy of the GNU General Public License version
250.21 + * 2 along with this work; if not, write to the Free Software Foundation,
250.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
250.23 + *
250.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
250.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
250.26 + * have any questions.
250.27 + */
250.28 +
250.29 +/* @test
250.30 + @summary Test AudioFloatInputStream close method */
250.31 +
250.32 +import java.io.*;
250.33 +
250.34 +import javax.sound.sampled.*;
250.35 +
250.36 +import com.sun.media.sound.*;
250.37 +
250.38 +public class Close {
250.39 +
250.40 + static float[] test_float_array;
250.41 + static byte[] test_byte_array;
250.42 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
250.43 +
250.44 + static AudioFloatInputStream getStream1()
250.45 + {
250.46 + return AudioFloatInputStream.getInputStream(format, test_byte_array, 0, test_byte_array.length);
250.47 + }
250.48 +
250.49 + static AudioFloatInputStream getStream2()
250.50 + {
250.51 + AudioInputStream strm = new AudioInputStream(new ByteArrayInputStream(test_byte_array), format, 1024);
250.52 + return AudioFloatInputStream.getInputStream(strm);
250.53 + }
250.54 +
250.55 + static void setUp() throws Exception {
250.56 + test_float_array = new float[1024];
250.57 + test_byte_array = new byte[1024*format.getFrameSize()];
250.58 + for (int i = 0; i < 1024; i++) {
250.59 + double ii = i / 1024.0;
250.60 + ii = ii * ii;
250.61 + test_float_array[i] = (float)Math.sin(10*ii*2*Math.PI);
250.62 + test_float_array[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
250.63 + test_float_array[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
250.64 + test_float_array[i] *= 0.3;
250.65 + }
250.66 + AudioFloatConverter.getConverter(format).toByteArray(test_float_array, test_byte_array);
250.67 + }
250.68 +
250.69 + public static void main(String[] args) throws Exception {
250.70 + setUp();
250.71 + getStream1().close();
250.72 + getStream2().close();
250.73 + }
250.74 +
250.75 +}
251.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
251.2 +++ b/test/javax/sound/midi/Gervill/AudioFloatInputStream/GetFormat.java Tue Feb 03 22:02:55 2009 -0800
251.3 @@ -0,0 +1,74 @@
251.4 +/*
251.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
251.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
251.7 + *
251.8 + * This code is free software; you can redistribute it and/or modify it
251.9 + * under the terms of the GNU General Public License version 2 only, as
251.10 + * published by the Free Software Foundation. Sun designates this
251.11 + * particular file as subject to the "Classpath" exception as provided
251.12 + * by Sun in the LICENSE file that accompanied this code.
251.13 + *
251.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
251.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
251.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
251.17 + * version 2 for more details (a copy is included in the LICENSE file that
251.18 + * accompanied this code).
251.19 + *
251.20 + * You should have received a copy of the GNU General Public License version
251.21 + * 2 along with this work; if not, write to the Free Software Foundation,
251.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
251.23 + *
251.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
251.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
251.26 + * have any questions.
251.27 + */
251.28 +
251.29 +/* @test
251.30 + @summary Test AudioFloatInputStream getFormat method */
251.31 +
251.32 +import java.io.*;
251.33 +
251.34 +import javax.sound.sampled.*;
251.35 +
251.36 +import com.sun.media.sound.*;
251.37 +
251.38 +public class GetFormat {
251.39 +
251.40 + static float[] test_float_array;
251.41 + static byte[] test_byte_array;
251.42 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
251.43 +
251.44 + static AudioFloatInputStream getStream1()
251.45 + {
251.46 + return AudioFloatInputStream.getInputStream(format, test_byte_array, 0, test_byte_array.length);
251.47 + }
251.48 +
251.49 + static AudioFloatInputStream getStream2()
251.50 + {
251.51 + AudioInputStream strm = new AudioInputStream(new ByteArrayInputStream(test_byte_array), format, 1024);
251.52 + return AudioFloatInputStream.getInputStream(strm);
251.53 + }
251.54 +
251.55 + static void setUp() throws Exception {
251.56 + test_float_array = new float[1024];
251.57 + test_byte_array = new byte[1024*format.getFrameSize()];
251.58 + for (int i = 0; i < 1024; i++) {
251.59 + double ii = i / 1024.0;
251.60 + ii = ii * ii;
251.61 + test_float_array[i] = (float)Math.sin(10*ii*2*Math.PI);
251.62 + test_float_array[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
251.63 + test_float_array[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
251.64 + test_float_array[i] *= 0.3;
251.65 + }
251.66 + AudioFloatConverter.getConverter(format).toByteArray(test_float_array, test_byte_array);
251.67 + }
251.68 +
251.69 + public static void main(String[] args) throws Exception {
251.70 + setUp();
251.71 + if(!getStream1().getFormat().matches(format))
251.72 + throw new RuntimeException("Incorrect audio format returned.");
251.73 + if(!getStream2().getFormat().matches(format))
251.74 + throw new RuntimeException("Incorrect audio format returned.");
251.75 + }
251.76 +
251.77 +}
252.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
252.2 +++ b/test/javax/sound/midi/Gervill/AudioFloatInputStream/GetFrameLength.java Tue Feb 03 22:02:55 2009 -0800
252.3 @@ -0,0 +1,74 @@
252.4 +/*
252.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
252.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
252.7 + *
252.8 + * This code is free software; you can redistribute it and/or modify it
252.9 + * under the terms of the GNU General Public License version 2 only, as
252.10 + * published by the Free Software Foundation. Sun designates this
252.11 + * particular file as subject to the "Classpath" exception as provided
252.12 + * by Sun in the LICENSE file that accompanied this code.
252.13 + *
252.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
252.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
252.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
252.17 + * version 2 for more details (a copy is included in the LICENSE file that
252.18 + * accompanied this code).
252.19 + *
252.20 + * You should have received a copy of the GNU General Public License version
252.21 + * 2 along with this work; if not, write to the Free Software Foundation,
252.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
252.23 + *
252.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
252.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
252.26 + * have any questions.
252.27 + */
252.28 +
252.29 +/* @test
252.30 + @summary Test AudioFloatInputStream getFrameLength method */
252.31 +
252.32 +import java.io.*;
252.33 +
252.34 +import javax.sound.sampled.*;
252.35 +
252.36 +import com.sun.media.sound.*;
252.37 +
252.38 +public class GetFrameLength {
252.39 +
252.40 + static float[] test_float_array;
252.41 + static byte[] test_byte_array;
252.42 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
252.43 +
252.44 + static AudioFloatInputStream getStream1()
252.45 + {
252.46 + return AudioFloatInputStream.getInputStream(format, test_byte_array, 0, test_byte_array.length);
252.47 + }
252.48 +
252.49 + static AudioFloatInputStream getStream2()
252.50 + {
252.51 + AudioInputStream strm = new AudioInputStream(new ByteArrayInputStream(test_byte_array), format, 1024);
252.52 + return AudioFloatInputStream.getInputStream(strm);
252.53 + }
252.54 +
252.55 + static void setUp() throws Exception {
252.56 + test_float_array = new float[1024];
252.57 + test_byte_array = new byte[1024*format.getFrameSize()];
252.58 + for (int i = 0; i < 1024; i++) {
252.59 + double ii = i / 1024.0;
252.60 + ii = ii * ii;
252.61 + test_float_array[i] = (float)Math.sin(10*ii*2*Math.PI);
252.62 + test_float_array[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
252.63 + test_float_array[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
252.64 + test_float_array[i] *= 0.3;
252.65 + }
252.66 + AudioFloatConverter.getConverter(format).toByteArray(test_float_array, test_byte_array);
252.67 + }
252.68 +
252.69 + public static void main(String[] args) throws Exception {
252.70 + setUp();
252.71 + if(getStream1().getFrameLength() != 1024L)
252.72 + throw new RuntimeException("Incorrect frame length returned.");
252.73 + if(getStream2().getFrameLength() != 1024L)
252.74 + throw new RuntimeException("Incorrect frame length returned.");
252.75 + }
252.76 +
252.77 +}
253.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
253.2 +++ b/test/javax/sound/midi/Gervill/AudioFloatInputStream/MarkSupported.java Tue Feb 03 22:02:55 2009 -0800
253.3 @@ -0,0 +1,74 @@
253.4 +/*
253.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
253.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
253.7 + *
253.8 + * This code is free software; you can redistribute it and/or modify it
253.9 + * under the terms of the GNU General Public License version 2 only, as
253.10 + * published by the Free Software Foundation. Sun designates this
253.11 + * particular file as subject to the "Classpath" exception as provided
253.12 + * by Sun in the LICENSE file that accompanied this code.
253.13 + *
253.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
253.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
253.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
253.17 + * version 2 for more details (a copy is included in the LICENSE file that
253.18 + * accompanied this code).
253.19 + *
253.20 + * You should have received a copy of the GNU General Public License version
253.21 + * 2 along with this work; if not, write to the Free Software Foundation,
253.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
253.23 + *
253.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
253.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
253.26 + * have any questions.
253.27 + */
253.28 +
253.29 +/* @test
253.30 + @summary Test AudioFloatInputStream markSupported method */
253.31 +
253.32 +import java.io.*;
253.33 +
253.34 +import javax.sound.sampled.*;
253.35 +
253.36 +import com.sun.media.sound.*;
253.37 +
253.38 +public class MarkSupported {
253.39 +
253.40 + static float[] test_float_array;
253.41 + static byte[] test_byte_array;
253.42 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
253.43 +
253.44 + static AudioFloatInputStream getStream1()
253.45 + {
253.46 + return AudioFloatInputStream.getInputStream(format, test_byte_array, 0, test_byte_array.length);
253.47 + }
253.48 +
253.49 + static AudioFloatInputStream getStream2()
253.50 + {
253.51 + AudioInputStream strm = new AudioInputStream(new ByteArrayInputStream(test_byte_array), format, 1024);
253.52 + return AudioFloatInputStream.getInputStream(strm);
253.53 + }
253.54 +
253.55 + static void setUp() throws Exception {
253.56 + test_float_array = new float[1024];
253.57 + test_byte_array = new byte[1024*format.getFrameSize()];
253.58 + for (int i = 0; i < 1024; i++) {
253.59 + double ii = i / 1024.0;
253.60 + ii = ii * ii;
253.61 + test_float_array[i] = (float)Math.sin(10*ii*2*Math.PI);
253.62 + test_float_array[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
253.63 + test_float_array[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
253.64 + test_float_array[i] *= 0.3;
253.65 + }
253.66 + AudioFloatConverter.getConverter(format).toByteArray(test_float_array, test_byte_array);
253.67 + }
253.68 +
253.69 + public static void main(String[] args) throws Exception {
253.70 + setUp();
253.71 + if(!getStream1().markSupported())
253.72 + throw new RuntimeException("Mark not supported.");
253.73 + if(!getStream2().markSupported())
253.74 + throw new RuntimeException("Mark not supported.");
253.75 + }
253.76 +
253.77 +}
254.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
254.2 +++ b/test/javax/sound/midi/Gervill/AudioFloatInputStream/Read.java Tue Feb 03 22:02:55 2009 -0800
254.3 @@ -0,0 +1,83 @@
254.4 +/*
254.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
254.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
254.7 + *
254.8 + * This code is free software; you can redistribute it and/or modify it
254.9 + * under the terms of the GNU General Public License version 2 only, as
254.10 + * published by the Free Software Foundation. Sun designates this
254.11 + * particular file as subject to the "Classpath" exception as provided
254.12 + * by Sun in the LICENSE file that accompanied this code.
254.13 + *
254.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
254.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
254.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
254.17 + * version 2 for more details (a copy is included in the LICENSE file that
254.18 + * accompanied this code).
254.19 + *
254.20 + * You should have received a copy of the GNU General Public License version
254.21 + * 2 along with this work; if not, write to the Free Software Foundation,
254.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
254.23 + *
254.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
254.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
254.26 + * have any questions.
254.27 + */
254.28 +
254.29 +/* @test
254.30 + @summary Test AudioFloatInputStream read method */
254.31 +
254.32 +import java.io.*;
254.33 +
254.34 +import javax.sound.sampled.*;
254.35 +
254.36 +import com.sun.media.sound.*;
254.37 +
254.38 +public class Read {
254.39 +
254.40 + static float[] test_float_array;
254.41 + static byte[] test_byte_array;
254.42 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
254.43 +
254.44 + static AudioFloatInputStream getStream1()
254.45 + {
254.46 + return AudioFloatInputStream.getInputStream(format, test_byte_array, 0, test_byte_array.length);
254.47 + }
254.48 +
254.49 + static AudioFloatInputStream getStream2()
254.50 + {
254.51 + AudioInputStream strm = new AudioInputStream(new ByteArrayInputStream(test_byte_array), format, 1024);
254.52 + return AudioFloatInputStream.getInputStream(strm);
254.53 + }
254.54 +
254.55 + static void setUp() throws Exception {
254.56 + test_float_array = new float[1024];
254.57 + test_byte_array = new byte[1024*format.getFrameSize()];
254.58 + for (int i = 0; i < 1024; i++) {
254.59 + double ii = i / 1024.0;
254.60 + ii = ii * ii;
254.61 + test_float_array[i] = (float)Math.sin(10*ii*2*Math.PI);
254.62 + test_float_array[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
254.63 + test_float_array[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
254.64 + test_float_array[i] *= 0.3;
254.65 + }
254.66 + AudioFloatConverter.getConverter(format).toByteArray(test_float_array, test_byte_array);
254.67 + }
254.68 +
254.69 + public static void main(String[] args) throws Exception {
254.70 + setUp();
254.71 +
254.72 + for (int i = 0; i < 2; i++) {
254.73 + AudioFloatInputStream stream = null;
254.74 + if(i == 0) stream = getStream1();
254.75 + if(i == 1) stream = getStream2();
254.76 + float v = 0;
254.77 + stream.skip(512);
254.78 + v = stream.read();
254.79 + if(!(Math.abs(v - test_float_array[512]) < 0.0001))
254.80 + {
254.81 + throw new RuntimeException("Read returned unexpected value.");
254.82 + }
254.83 + }
254.84 + }
254.85 +
254.86 +}
255.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
255.2 +++ b/test/javax/sound/midi/Gervill/AudioFloatInputStream/ReadFloatArray.java Tue Feb 03 22:02:55 2009 -0800
255.3 @@ -0,0 +1,81 @@
255.4 +/*
255.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
255.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
255.7 + *
255.8 + * This code is free software; you can redistribute it and/or modify it
255.9 + * under the terms of the GNU General Public License version 2 only, as
255.10 + * published by the Free Software Foundation. Sun designates this
255.11 + * particular file as subject to the "Classpath" exception as provided
255.12 + * by Sun in the LICENSE file that accompanied this code.
255.13 + *
255.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
255.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
255.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
255.17 + * version 2 for more details (a copy is included in the LICENSE file that
255.18 + * accompanied this code).
255.19 + *
255.20 + * You should have received a copy of the GNU General Public License version
255.21 + * 2 along with this work; if not, write to the Free Software Foundation,
255.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
255.23 + *
255.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
255.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
255.26 + * have any questions.
255.27 + */
255.28 +
255.29 +/* @test
255.30 + @summary Test AudioFloatInputStream read(float[]) method */
255.31 +
255.32 +import java.io.*;
255.33 +
255.34 +import javax.sound.sampled.*;
255.35 +
255.36 +import com.sun.media.sound.*;
255.37 +
255.38 +public class ReadFloatArray {
255.39 +
255.40 + static float[] test_float_array;
255.41 + static byte[] test_byte_array;
255.42 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
255.43 +
255.44 + static AudioFloatInputStream getStream1()
255.45 + {
255.46 + return AudioFloatInputStream.getInputStream(format, test_byte_array, 0, test_byte_array.length);
255.47 + }
255.48 +
255.49 + static AudioFloatInputStream getStream2()
255.50 + {
255.51 + AudioInputStream strm = new AudioInputStream(new ByteArrayInputStream(test_byte_array), format, 1024);
255.52 + return AudioFloatInputStream.getInputStream(strm);
255.53 + }
255.54 +
255.55 + static void setUp() throws Exception {
255.56 + test_float_array = new float[1024];
255.57 + test_byte_array = new byte[1024*format.getFrameSize()];
255.58 + for (int i = 0; i < 1024; i++) {
255.59 + double ii = i / 1024.0;
255.60 + ii = ii * ii;
255.61 + test_float_array[i] = (float)Math.sin(10*ii*2*Math.PI);
255.62 + test_float_array[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
255.63 + test_float_array[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
255.64 + test_float_array[i] *= 0.3;
255.65 + }
255.66 + AudioFloatConverter.getConverter(format).toByteArray(test_float_array, test_byte_array);
255.67 + }
255.68 +
255.69 + public static void main(String[] args) throws Exception {
255.70 + setUp();
255.71 +
255.72 + for (int i = 0; i < 2; i++) {
255.73 + AudioFloatInputStream stream = null;
255.74 + if(i == 0) stream = getStream1();
255.75 + if(i == 1) stream = getStream2();
255.76 + float[] buff = new float[1024];
255.77 + stream.read(buff);
255.78 + for (int j = 0; j < buff.length; j++)
255.79 + if(!(Math.abs(buff[j] - test_float_array[j]) < 0.0001))
255.80 + throw new RuntimeException("Incorrect data in buffer.");
255.81 + }
255.82 + }
255.83 +
255.84 +}
256.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
256.2 +++ b/test/javax/sound/midi/Gervill/AudioFloatInputStream/ReadFloatArrayIntInt.java Tue Feb 03 22:02:55 2009 -0800
256.3 @@ -0,0 +1,83 @@
256.4 +/*
256.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
256.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
256.7 + *
256.8 + * This code is free software; you can redistribute it and/or modify it
256.9 + * under the terms of the GNU General Public License version 2 only, as
256.10 + * published by the Free Software Foundation. Sun designates this
256.11 + * particular file as subject to the "Classpath" exception as provided
256.12 + * by Sun in the LICENSE file that accompanied this code.
256.13 + *
256.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
256.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
256.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
256.17 + * version 2 for more details (a copy is included in the LICENSE file that
256.18 + * accompanied this code).
256.19 + *
256.20 + * You should have received a copy of the GNU General Public License version
256.21 + * 2 along with this work; if not, write to the Free Software Foundation,
256.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
256.23 + *
256.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
256.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
256.26 + * have any questions.
256.27 + */
256.28 +
256.29 +/* @test
256.30 + @summary Test AudioFloatInputStream read(float[], int, int) method */
256.31 +
256.32 +import java.io.*;
256.33 +
256.34 +import javax.sound.sampled.*;
256.35 +
256.36 +import com.sun.media.sound.*;
256.37 +
256.38 +public class ReadFloatArrayIntInt {
256.39 +
256.40 + static float[] test_float_array;
256.41 + static byte[] test_byte_array;
256.42 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
256.43 +
256.44 + static AudioFloatInputStream getStream1()
256.45 + {
256.46 + return AudioFloatInputStream.getInputStream(format, test_byte_array, 0, test_byte_array.length);
256.47 + }
256.48 +
256.49 + static AudioFloatInputStream getStream2()
256.50 + {
256.51 + AudioInputStream strm = new AudioInputStream(new ByteArrayInputStream(test_byte_array), format, 1024);
256.52 + return AudioFloatInputStream.getInputStream(strm);
256.53 + }
256.54 +
256.55 + static void setUp() throws Exception {
256.56 + test_float_array = new float[1024];
256.57 + test_byte_array = new byte[1024*format.getFrameSize()];
256.58 + for (int i = 0; i < 1024; i++) {
256.59 + double ii = i / 1024.0;
256.60 + ii = ii * ii;
256.61 + test_float_array[i] = (float)Math.sin(10*ii*2*Math.PI);
256.62 + test_float_array[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
256.63 + test_float_array[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
256.64 + test_float_array[i] *= 0.3;
256.65 + }
256.66 + AudioFloatConverter.getConverter(format).toByteArray(test_float_array, test_byte_array);
256.67 + }
256.68 +
256.69 + public static void main(String[] args) throws Exception {
256.70 + setUp();
256.71 +
256.72 + for (int i = 0; i < 2; i++) {
256.73 + AudioFloatInputStream stream = null;
256.74 + if(i == 0) stream = getStream1();
256.75 + if(i == 1) stream = getStream2();
256.76 + float[] buff = new float[1024];
256.77 + stream.read(buff,0,512);
256.78 + stream.read(buff,512,512);
256.79 + for (int j = 0; j < buff.length; j++)
256.80 + if(!(Math.abs(buff[j] - test_float_array[j]) < 0.0001))
256.81 + throw new RuntimeException("Incorrect data in buffer.");
256.82 +
256.83 + }
256.84 + }
256.85 +
256.86 +}
257.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
257.2 +++ b/test/javax/sound/midi/Gervill/AudioFloatInputStream/Reset.java Tue Feb 03 22:02:55 2009 -0800
257.3 @@ -0,0 +1,87 @@
257.4 +/*
257.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
257.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
257.7 + *
257.8 + * This code is free software; you can redistribute it and/or modify it
257.9 + * under the terms of the GNU General Public License version 2 only, as
257.10 + * published by the Free Software Foundation. Sun designates this
257.11 + * particular file as subject to the "Classpath" exception as provided
257.12 + * by Sun in the LICENSE file that accompanied this code.
257.13 + *
257.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
257.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
257.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
257.17 + * version 2 for more details (a copy is included in the LICENSE file that
257.18 + * accompanied this code).
257.19 + *
257.20 + * You should have received a copy of the GNU General Public License version
257.21 + * 2 along with this work; if not, write to the Free Software Foundation,
257.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
257.23 + *
257.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
257.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
257.26 + * have any questions.
257.27 + */
257.28 +
257.29 +/* @test
257.30 + @summary Test AudioFloatInputStream reset method */
257.31 +
257.32 +import java.io.*;
257.33 +
257.34 +import javax.sound.sampled.*;
257.35 +
257.36 +import com.sun.media.sound.*;
257.37 +
257.38 +public class Reset {
257.39 +
257.40 + static float[] test_float_array;
257.41 + static byte[] test_byte_array;
257.42 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
257.43 +
257.44 + static AudioFloatInputStream getStream1()
257.45 + {
257.46 + return AudioFloatInputStream.getInputStream(format, test_byte_array, 0, test_byte_array.length);
257.47 + }
257.48 +
257.49 + static AudioFloatInputStream getStream2()
257.50 + {
257.51 + AudioInputStream strm = new AudioInputStream(new ByteArrayInputStream(test_byte_array), format, 1024);
257.52 + return AudioFloatInputStream.getInputStream(strm);
257.53 + }
257.54 +
257.55 + static void setUp() throws Exception {
257.56 + test_float_array = new float[1024];
257.57 + test_byte_array = new byte[1024*format.getFrameSize()];
257.58 + for (int i = 0; i < 1024; i++) {
257.59 + double ii = i / 1024.0;
257.60 + ii = ii * ii;
257.61 + test_float_array[i] = (float)Math.sin(10*ii*2*Math.PI);
257.62 + test_float_array[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
257.63 + test_float_array[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
257.64 + test_float_array[i] *= 0.3;
257.65 + }
257.66 + AudioFloatConverter.getConverter(format).toByteArray(test_float_array, test_byte_array);
257.67 + }
257.68 +
257.69 + public static void main(String[] args) throws Exception {
257.70 + setUp();
257.71 +
257.72 + for (int i = 0; i < 2; i++) {
257.73 + AudioFloatInputStream stream = null;
257.74 + if(i == 0) stream = getStream1();
257.75 + if(i == 1) stream = getStream2();
257.76 + float[] buff = new float[512];
257.77 + float[] buff2 = new float[512];
257.78 + stream.read(buff);
257.79 + stream.mark(512);
257.80 + stream.read(buff);
257.81 + stream.reset();
257.82 + stream.read(buff2);
257.83 + for (int j = 0; j < buff2.length; j++)
257.84 + if(!(Math.abs(buff[j] - buff2[j]) < 0.0001))
257.85 + throw new RuntimeException("Incorrect data in buffer.");
257.86 +
257.87 + }
257.88 + }
257.89 +
257.90 +}
258.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
258.2 +++ b/test/javax/sound/midi/Gervill/AudioFloatInputStream/Skip.java Tue Feb 03 22:02:55 2009 -0800
258.3 @@ -0,0 +1,83 @@
258.4 +/*
258.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
258.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
258.7 + *
258.8 + * This code is free software; you can redistribute it and/or modify it
258.9 + * under the terms of the GNU General Public License version 2 only, as
258.10 + * published by the Free Software Foundation. Sun designates this
258.11 + * particular file as subject to the "Classpath" exception as provided
258.12 + * by Sun in the LICENSE file that accompanied this code.
258.13 + *
258.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
258.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
258.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
258.17 + * version 2 for more details (a copy is included in the LICENSE file that
258.18 + * accompanied this code).
258.19 + *
258.20 + * You should have received a copy of the GNU General Public License version
258.21 + * 2 along with this work; if not, write to the Free Software Foundation,
258.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
258.23 + *
258.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
258.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
258.26 + * have any questions.
258.27 + */
258.28 +
258.29 +/* @test
258.30 + @summary Test AudioFloatInputStream skip method */
258.31 +
258.32 +import java.io.*;
258.33 +
258.34 +import javax.sound.sampled.*;
258.35 +
258.36 +import com.sun.media.sound.*;
258.37 +
258.38 +public class Skip {
258.39 +
258.40 + static float[] test_float_array;
258.41 + static byte[] test_byte_array;
258.42 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
258.43 +
258.44 + static AudioFloatInputStream getStream1()
258.45 + {
258.46 + return AudioFloatInputStream.getInputStream(format, test_byte_array, 0, test_byte_array.length);
258.47 + }
258.48 +
258.49 + static AudioFloatInputStream getStream2()
258.50 + {
258.51 + AudioInputStream strm = new AudioInputStream(new ByteArrayInputStream(test_byte_array), format, 1024);
258.52 + return AudioFloatInputStream.getInputStream(strm);
258.53 + }
258.54 +
258.55 + static void setUp() throws Exception {
258.56 + test_float_array = new float[1024];
258.57 + test_byte_array = new byte[1024*format.getFrameSize()];
258.58 + for (int i = 0; i < 1024; i++) {
258.59 + double ii = i / 1024.0;
258.60 + ii = ii * ii;
258.61 + test_float_array[i] = (float)Math.sin(10*ii*2*Math.PI);
258.62 + test_float_array[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
258.63 + test_float_array[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
258.64 + test_float_array[i] *= 0.3;
258.65 + }
258.66 + AudioFloatConverter.getConverter(format).toByteArray(test_float_array, test_byte_array);
258.67 + }
258.68 +
258.69 + public static void main(String[] args) throws Exception {
258.70 + setUp();
258.71 +
258.72 + for (int i = 0; i < 2; i++) {
258.73 + AudioFloatInputStream stream = null;
258.74 + if(i == 0) stream = getStream1();
258.75 + if(i == 1) stream = getStream2();
258.76 + float[] buff = new float[512];
258.77 + stream.skip(512);
258.78 + stream.read(buff);
258.79 + for (int j = 0; j < buff.length; j++)
258.80 + if(!(Math.abs(buff[j] - test_float_array[j+512]) < 0.0001))
258.81 + throw new RuntimeException("Incorrect data in buffer.");
258.82 +
258.83 + }
258.84 + }
258.85 +
258.86 +}
259.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
259.2 +++ b/test/javax/sound/midi/Gervill/DLSSoundbankReader/TestGetSoundbankFile.java Tue Feb 03 22:02:55 2009 -0800
259.3 @@ -0,0 +1,52 @@
259.4 +/*
259.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
259.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
259.7 + *
259.8 + * This code is free software; you can redistribute it and/or modify it
259.9 + * under the terms of the GNU General Public License version 2 only, as
259.10 + * published by the Free Software Foundation. Sun designates this
259.11 + * particular file as subject to the "Classpath" exception as provided
259.12 + * by Sun in the LICENSE file that accompanied this code.
259.13 + *
259.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
259.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
259.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
259.17 + * version 2 for more details (a copy is included in the LICENSE file that
259.18 + * accompanied this code).
259.19 + *
259.20 + * You should have received a copy of the GNU General Public License version
259.21 + * 2 along with this work; if not, write to the Free Software Foundation,
259.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
259.23 + *
259.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
259.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
259.26 + * have any questions.
259.27 + */
259.28 +
259.29 +/* @test
259.30 + @summary Test DLSSoundbankReader getSoundbank(File) method */
259.31 +
259.32 +import java.io.File;
259.33 +
259.34 +import javax.sound.midi.Patch;
259.35 +import javax.sound.midi.Soundbank;
259.36 +
259.37 +import com.sun.media.sound.DLSSoundbankReader;
259.38 +
259.39 +public class TestGetSoundbankFile {
259.40 +
259.41 + private static void assertTrue(boolean value) throws Exception
259.42 + {
259.43 + if(!value)
259.44 + throw new RuntimeException("assertTrue fails!");
259.45 + }
259.46 +
259.47 + public static void main(String[] args) throws Exception {
259.48 + File file = new File(System.getProperty("test.src", "."), "ding.dls");
259.49 + Soundbank dls = new DLSSoundbankReader().getSoundbank(file);
259.50 + assertTrue(dls.getInstruments().length == 1);
259.51 + Patch patch = dls.getInstruments()[0].getPatch();
259.52 + assertTrue(patch.getProgram() == 0);
259.53 + assertTrue(patch.getBank() == 0);
259.54 + }
259.55 +}
260.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
260.2 +++ b/test/javax/sound/midi/Gervill/DLSSoundbankReader/TestGetSoundbankInputStream.java Tue Feb 03 22:02:55 2009 -0800
260.3 @@ -0,0 +1,63 @@
260.4 +/*
260.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
260.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
260.7 + *
260.8 + * This code is free software; you can redistribute it and/or modify it
260.9 + * under the terms of the GNU General Public License version 2 only, as
260.10 + * published by the Free Software Foundation. Sun designates this
260.11 + * particular file as subject to the "Classpath" exception as provided
260.12 + * by Sun in the LICENSE file that accompanied this code.
260.13 + *
260.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
260.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
260.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
260.17 + * version 2 for more details (a copy is included in the LICENSE file that
260.18 + * accompanied this code).
260.19 + *
260.20 + * You should have received a copy of the GNU General Public License version
260.21 + * 2 along with this work; if not, write to the Free Software Foundation,
260.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
260.23 + *
260.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
260.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
260.26 + * have any questions.
260.27 + */
260.28 +
260.29 +/* @test
260.30 + @summary Test DLSSoundbankReader getSoundbank(InputStream) method */
260.31 +
260.32 +import java.io.BufferedInputStream;
260.33 +import java.io.File;
260.34 +import java.io.FileInputStream;
260.35 +
260.36 +import javax.sound.midi.Patch;
260.37 +import javax.sound.midi.Soundbank;
260.38 +
260.39 +import com.sun.media.sound.DLSSoundbankReader;
260.40 +
260.41 +public class TestGetSoundbankInputStream {
260.42 +
260.43 + private static void assertTrue(boolean value) throws Exception
260.44 + {
260.45 + if(!value)
260.46 + throw new RuntimeException("assertTrue fails!");
260.47 + }
260.48 +
260.49 + public static void main(String[] args) throws Exception {
260.50 + File file = new File(System.getProperty("test.src", "."), "ding.dls");
260.51 + FileInputStream fis = new FileInputStream(file);
260.52 + BufferedInputStream bis = new BufferedInputStream(fis);
260.53 + try
260.54 + {
260.55 + Soundbank dls = new DLSSoundbankReader().getSoundbank(bis);
260.56 + assertTrue(dls.getInstruments().length == 1);
260.57 + Patch patch = dls.getInstruments()[0].getPatch();
260.58 + assertTrue(patch.getProgram() == 0);
260.59 + assertTrue(patch.getBank() == 0);
260.60 + }
260.61 + finally
260.62 + {
260.63 + bis.close();
260.64 + }
260.65 + }
260.66 +}
261.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
261.2 +++ b/test/javax/sound/midi/Gervill/DLSSoundbankReader/TestGetSoundbankInputStream2.java Tue Feb 03 22:02:55 2009 -0800
261.3 @@ -0,0 +1,119 @@
261.4 +/*
261.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
261.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
261.7 + *
261.8 + * This code is free software; you can redistribute it and/or modify it
261.9 + * under the terms of the GNU General Public License version 2 only, as
261.10 + * published by the Free Software Foundation. Sun designates this
261.11 + * particular file as subject to the "Classpath" exception as provided
261.12 + * by Sun in the LICENSE file that accompanied this code.
261.13 + *
261.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
261.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
261.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
261.17 + * version 2 for more details (a copy is included in the LICENSE file that
261.18 + * accompanied this code).
261.19 + *
261.20 + * You should have received a copy of the GNU General Public License version
261.21 + * 2 along with this work; if not, write to the Free Software Foundation,
261.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
261.23 + *
261.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
261.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
261.26 + * have any questions.
261.27 + */
261.28 +
261.29 +/* @test
261.30 + @summary Test DLSSoundbankReader getSoundbank(InputStream) method using
261.31 + very bad InputStream which can only read 1 byte at time */
261.32 +
261.33 +import java.io.BufferedInputStream;
261.34 +import java.io.File;
261.35 +import java.io.FileInputStream;
261.36 +import java.io.IOException;
261.37 +import java.io.InputStream;
261.38 +
261.39 +import javax.sound.midi.Patch;
261.40 +import javax.sound.midi.Soundbank;
261.41 +
261.42 +import com.sun.media.sound.DLSSoundbankReader;
261.43 +
261.44 +public class TestGetSoundbankInputStream2 {
261.45 +
261.46 + private static class BadInputStream extends InputStream
261.47 + {
261.48 +
261.49 + InputStream is;
261.50 +
261.51 + public BadInputStream(InputStream is)
261.52 + {
261.53 + this.is = is;
261.54 + }
261.55 +
261.56 + public int read() throws IOException {
261.57 + return is.read();
261.58 + }
261.59 +
261.60 + public int read(byte[] b, int off, int len) throws IOException {
261.61 + if(len > 1) len = 1;
261.62 + return is.read(b, off, len);
261.63 + }
261.64 +
261.65 + public int read(byte[] b) throws IOException {
261.66 + return read(b, 0, b.length);
261.67 + }
261.68 +
261.69 + public long skip(long n) throws IOException {
261.70 + if(n > 1) n = 1;
261.71 + return is.skip(n);
261.72 + }
261.73 +
261.74 + public int available() throws IOException {
261.75 + int avail = is.available();
261.76 + if(avail > 1) avail = 1;
261.77 + return avail;
261.78 + }
261.79 +
261.80 + public void close() throws IOException {
261.81 + is.close();
261.82 + }
261.83 +
261.84 + public synchronized void mark(int readlimit) {
261.85 + is.mark(readlimit);
261.86 + }
261.87 +
261.88 + public boolean markSupported() {
261.89 + return is.markSupported();
261.90 + }
261.91 +
261.92 + public synchronized void reset() throws IOException {
261.93 + is.reset();
261.94 + }
261.95 +
261.96 + }
261.97 +
261.98 + private static void assertTrue(boolean value) throws Exception
261.99 + {
261.100 + if(!value)
261.101 + throw new RuntimeException("assertTrue fails!");
261.102 + }
261.103 +
261.104 + public static void main(String[] args) throws Exception {
261.105 + File file = new File(System.getProperty("test.src", "."), "ding.dls");
261.106 + FileInputStream fis = new FileInputStream(file);
261.107 + BufferedInputStream bis = new BufferedInputStream(fis);
261.108 + try
261.109 + {
261.110 + InputStream badis = new BadInputStream(bis);
261.111 + Soundbank dls = new DLSSoundbankReader().getSoundbank(badis);
261.112 + assertTrue(dls.getInstruments().length == 1);
261.113 + Patch patch = dls.getInstruments()[0].getPatch();
261.114 + assertTrue(patch.getProgram() == 0);
261.115 + assertTrue(patch.getBank() == 0);
261.116 + }
261.117 + finally
261.118 + {
261.119 + bis.close();
261.120 + }
261.121 + }
261.122 +}
262.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
262.2 +++ b/test/javax/sound/midi/Gervill/DLSSoundbankReader/TestGetSoundbankUrl.java Tue Feb 03 22:02:55 2009 -0800
262.3 @@ -0,0 +1,54 @@
262.4 +/*
262.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
262.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
262.7 + *
262.8 + * This code is free software; you can redistribute it and/or modify it
262.9 + * under the terms of the GNU General Public License version 2 only, as
262.10 + * published by the Free Software Foundation. Sun designates this
262.11 + * particular file as subject to the "Classpath" exception as provided
262.12 + * by Sun in the LICENSE file that accompanied this code.
262.13 + *
262.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
262.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
262.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
262.17 + * version 2 for more details (a copy is included in the LICENSE file that
262.18 + * accompanied this code).
262.19 + *
262.20 + * You should have received a copy of the GNU General Public License version
262.21 + * 2 along with this work; if not, write to the Free Software Foundation,
262.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
262.23 + *
262.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
262.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
262.26 + * have any questions.
262.27 + */
262.28 +
262.29 +/* @test
262.30 + @summary Test DLSSoundbankReader getSoundbank(File) method */
262.31 +
262.32 +import java.io.File;
262.33 +import java.net.URL;
262.34 +
262.35 +import javax.sound.midi.Patch;
262.36 +import javax.sound.midi.Soundbank;
262.37 +
262.38 +import com.sun.media.sound.DLSSoundbankReader;
262.39 +
262.40 +public class TestGetSoundbankUrl {
262.41 +
262.42 + private static void assertTrue(boolean value) throws Exception
262.43 + {
262.44 + if(!value)
262.45 + throw new RuntimeException("assertTrue fails!");
262.46 + }
262.47 +
262.48 + public static void main(String[] args) throws Exception {
262.49 + File file = new File(System.getProperty("test.src", "."), "ding.dls");
262.50 + URL url = file.toURI().toURL();
262.51 + Soundbank dls = new DLSSoundbankReader().getSoundbank(url);
262.52 + assertTrue(dls.getInstruments().length == 1);
262.53 + Patch patch = dls.getInstruments()[0].getPatch();
262.54 + assertTrue(patch.getProgram() == 0);
262.55 + assertTrue(patch.getBank() == 0);
262.56 + }
262.57 +}
263.1 Binary file test/javax/sound/midi/Gervill/DLSSoundbankReader/ding.dls has changed
264.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
264.2 +++ b/test/javax/sound/midi/Gervill/EmergencySoundbank/TestCreateSoundbank.java Tue Feb 03 22:02:55 2009 -0800
264.3 @@ -0,0 +1,59 @@
264.4 +/*
264.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
264.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
264.7 + *
264.8 + * This code is free software; you can redistribute it and/or modify it
264.9 + * under the terms of the GNU General Public License version 2 only, as
264.10 + * published by the Free Software Foundation. Sun designates this
264.11 + * particular file as subject to the "Classpath" exception as provided
264.12 + * by Sun in the LICENSE file that accompanied this code.
264.13 + *
264.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
264.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
264.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
264.17 + * version 2 for more details (a copy is included in the LICENSE file that
264.18 + * accompanied this code).
264.19 + *
264.20 + * You should have received a copy of the GNU General Public License version
264.21 + * 2 along with this work; if not, write to the Free Software Foundation,
264.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
264.23 + *
264.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
264.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
264.26 + * have any questions.
264.27 + */
264.28 +
264.29 +/* @test
264.30 + @summary Test EmergencySoundbank createSoundbank() method */
264.31 +
264.32 +import java.io.File;
264.33 +
264.34 +import javax.sound.midi.Instrument;
264.35 +import javax.sound.midi.Patch;
264.36 +import javax.sound.midi.Soundbank;
264.37 +
264.38 +import com.sun.media.sound.EmergencySoundbank;
264.39 +import com.sun.media.sound.ModelInstrument;
264.40 +import com.sun.media.sound.ModelPatch;
264.41 +
264.42 +public class TestCreateSoundbank {
264.43 +
264.44 + public static void main(String[] args) throws Exception {
264.45 +
264.46 + Soundbank soundbank = EmergencySoundbank.createSoundbank();
264.47 + for (int i = 0; i < 128; i++) {
264.48 + Patch patch = new ModelPatch(0, i, false);
264.49 + ModelInstrument ins = (ModelInstrument)soundbank.getInstrument(patch);
264.50 + if(ins == null)
264.51 + throw new Exception("Instrument " + i + " is missing!");
264.52 + if(ins.getPerformers().length == 0)
264.53 + throw new Exception("Instrument " + i + " doesn't have any performers!");
264.54 + }
264.55 + Patch patch = new ModelPatch(0, 0, true);
264.56 + ModelInstrument ins = (ModelInstrument)soundbank.getInstrument(patch);
264.57 + if(ins == null)
264.58 + throw new Exception("Drumkit instrument is missing!");
264.59 + if(ins.getPerformers().length == 0)
264.60 + throw new Exception("Drumkit instrument doesn't have any performers!");
264.61 + }
264.62 +}
265.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
265.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBuffer/GetInputStream.java Tue Feb 03 22:02:55 2009 -0800
265.3 @@ -0,0 +1,91 @@
265.4 +/*
265.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
265.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
265.7 + *
265.8 + * This code is free software; you can redistribute it and/or modify it
265.9 + * under the terms of the GNU General Public License version 2 only, as
265.10 + * published by the Free Software Foundation. Sun designates this
265.11 + * particular file as subject to the "Classpath" exception as provided
265.12 + * by Sun in the LICENSE file that accompanied this code.
265.13 + *
265.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
265.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
265.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
265.17 + * version 2 for more details (a copy is included in the LICENSE file that
265.18 + * accompanied this code).
265.19 + *
265.20 + * You should have received a copy of the GNU General Public License version
265.21 + * 2 along with this work; if not, write to the Free Software Foundation,
265.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
265.23 + *
265.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
265.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
265.26 + * have any questions.
265.27 + */
265.28 +
265.29 +/* @test
265.30 + @summary Test ModelByteBuffer getInputStream method */
265.31 +
265.32 +import java.io.File;
265.33 +import java.io.FileOutputStream;
265.34 +import java.io.IOException;
265.35 +
265.36 +import javax.sound.sampled.*;
265.37 +
265.38 +import com.sun.media.sound.*;
265.39 +
265.40 +public class GetInputStream {
265.41 +
265.42 + static float[] testarray;
265.43 + static byte[] test_byte_array;
265.44 + static File test_file;
265.45 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
265.46 +
265.47 + static void setUp() throws Exception {
265.48 + testarray = new float[1024];
265.49 + for (int i = 0; i < 1024; i++) {
265.50 + double ii = i / 1024.0;
265.51 + ii = ii * ii;
265.52 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
265.53 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
265.54 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
265.55 + testarray[i] *= 0.3;
265.56 + }
265.57 + test_byte_array = new byte[testarray.length*2];
265.58 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
265.59 + test_file = File.createTempFile("test", ".raw");
265.60 + FileOutputStream fos = new FileOutputStream(test_file);
265.61 + fos.write(test_byte_array);
265.62 + }
265.63 +
265.64 + static void tearDown() throws Exception {
265.65 + if(!test_file.delete())
265.66 + test_file.deleteOnExit();
265.67 + }
265.68 +
265.69 + public static void main(String[] args) throws Exception {
265.70 + try
265.71 + {
265.72 + setUp();
265.73 +
265.74 + for (int i = 0; i < 2; i++) {
265.75 + ModelByteBuffer buff;
265.76 + if(i == 0)
265.77 + buff = new ModelByteBuffer(test_file);
265.78 + else
265.79 + buff = new ModelByteBuffer(test_byte_array);
265.80 +
265.81 + byte[] b = new byte[test_byte_array.length];
265.82 + buff.getInputStream().read(b);
265.83 + for (int j = 0; j < b.length; j++)
265.84 + if(b[i] != test_byte_array[i])
265.85 + throw new RuntimeException("Byte array compare fails!");
265.86 + }
265.87 + }
265.88 + finally
265.89 + {
265.90 + tearDown();
265.91 + }
265.92 + }
265.93 +
265.94 +}
266.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
266.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBuffer/GetRoot.java Tue Feb 03 22:02:55 2009 -0800
266.3 @@ -0,0 +1,82 @@
266.4 +/*
266.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
266.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
266.7 + *
266.8 + * This code is free software; you can redistribute it and/or modify it
266.9 + * under the terms of the GNU General Public License version 2 only, as
266.10 + * published by the Free Software Foundation. Sun designates this
266.11 + * particular file as subject to the "Classpath" exception as provided
266.12 + * by Sun in the LICENSE file that accompanied this code.
266.13 + *
266.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
266.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
266.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
266.17 + * version 2 for more details (a copy is included in the LICENSE file that
266.18 + * accompanied this code).
266.19 + *
266.20 + * You should have received a copy of the GNU General Public License version
266.21 + * 2 along with this work; if not, write to the Free Software Foundation,
266.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
266.23 + *
266.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
266.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
266.26 + * have any questions.
266.27 + */
266.28 +
266.29 +/* @test
266.30 + @summary Test ModelByteBuffer getRoot method */
266.31 +
266.32 +import java.io.File;
266.33 +import java.io.FileOutputStream;
266.34 +
266.35 +import javax.sound.sampled.*;
266.36 +
266.37 +import com.sun.media.sound.*;
266.38 +
266.39 +public class GetRoot {
266.40 +
266.41 + static float[] testarray;
266.42 + static byte[] test_byte_array;
266.43 + static File test_file;
266.44 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
266.45 +
266.46 + static void setUp() throws Exception {
266.47 + testarray = new float[1024];
266.48 + for (int i = 0; i < 1024; i++) {
266.49 + double ii = i / 1024.0;
266.50 + ii = ii * ii;
266.51 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
266.52 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
266.53 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
266.54 + testarray[i] *= 0.3;
266.55 + }
266.56 + test_byte_array = new byte[testarray.length*2];
266.57 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
266.58 + test_file = File.createTempFile("test", ".raw");
266.59 + FileOutputStream fos = new FileOutputStream(test_file);
266.60 + fos.write(test_byte_array);
266.61 + }
266.62 +
266.63 + static void tearDown() throws Exception {
266.64 + if(!test_file.delete())
266.65 + test_file.deleteOnExit();
266.66 + }
266.67 +
266.68 + public static void main(String[] args) throws Exception {
266.69 + try
266.70 + {
266.71 + setUp();
266.72 +
266.73 + ModelByteBuffer buff = new ModelByteBuffer(test_file);
266.74 + ModelByteBuffer buff2 = buff.subbuffer(10, 10);
266.75 + ModelByteBuffer buff3 = buff2.subbuffer(2, 2);
266.76 + if(buff != buff3.getRoot())
266.77 + throw new RuntimeException("ModelByteBuffer doesn't return correct root!");
266.78 + }
266.79 + finally
266.80 + {
266.81 + tearDown();
266.82 + }
266.83 + }
266.84 +
266.85 +}
267.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
267.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBuffer/Load.java Tue Feb 03 22:02:55 2009 -0800
267.3 @@ -0,0 +1,89 @@
267.4 +/*
267.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
267.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
267.7 + *
267.8 + * This code is free software; you can redistribute it and/or modify it
267.9 + * under the terms of the GNU General Public License version 2 only, as
267.10 + * published by the Free Software Foundation. Sun designates this
267.11 + * particular file as subject to the "Classpath" exception as provided
267.12 + * by Sun in the LICENSE file that accompanied this code.
267.13 + *
267.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
267.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
267.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
267.17 + * version 2 for more details (a copy is included in the LICENSE file that
267.18 + * accompanied this code).
267.19 + *
267.20 + * You should have received a copy of the GNU General Public License version
267.21 + * 2 along with this work; if not, write to the Free Software Foundation,
267.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
267.23 + *
267.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
267.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
267.26 + * have any questions.
267.27 + */
267.28 +
267.29 +/* @test
267.30 + @summary Test ModelByteBuffer load method */
267.31 +
267.32 +import java.io.File;
267.33 +import java.io.FileOutputStream;
267.34 +import java.io.IOException;
267.35 +
267.36 +import javax.sound.sampled.*;
267.37 +
267.38 +import com.sun.media.sound.*;
267.39 +
267.40 +public class Load {
267.41 +
267.42 + static float[] testarray;
267.43 + static byte[] test_byte_array;
267.44 + static File test_file;
267.45 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
267.46 +
267.47 + static void setUp() throws Exception {
267.48 + testarray = new float[1024];
267.49 + for (int i = 0; i < 1024; i++) {
267.50 + double ii = i / 1024.0;
267.51 + ii = ii * ii;
267.52 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
267.53 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
267.54 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
267.55 + testarray[i] *= 0.3;
267.56 + }
267.57 + test_byte_array = new byte[testarray.length*2];
267.58 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
267.59 + test_file = File.createTempFile("test", ".raw");
267.60 + FileOutputStream fos = new FileOutputStream(test_file);
267.61 + fos.write(test_byte_array);
267.62 + }
267.63 +
267.64 + static void tearDown() throws Exception {
267.65 + if(!test_file.delete())
267.66 + test_file.deleteOnExit();
267.67 + }
267.68 +
267.69 + public static void main(String[] args) throws Exception {
267.70 + try
267.71 + {
267.72 + setUp();
267.73 +
267.74 + ModelByteBuffer buff = new ModelByteBuffer(test_file);
267.75 +
267.76 + buff.load();
267.77 + if(buff.array() == null)
267.78 + throw new RuntimeException("buf is null!");
267.79 + if(buff.array().length != test_byte_array.length)
267.80 + throw new RuntimeException("buff.array().length length is incorrect!");
267.81 + byte[] b = buff.array();
267.82 + for (int i = 0; i < b.length; i++)
267.83 + if(test_byte_array[i] != b[i])
267.84 + throw new RuntimeException("buff.array() incorrect!");
267.85 + }
267.86 + finally
267.87 + {
267.88 + tearDown();
267.89 + }
267.90 + }
267.91 +
267.92 +}
268.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
268.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBuffer/LoadAll.java Tue Feb 03 22:02:55 2009 -0800
268.3 @@ -0,0 +1,93 @@
268.4 +/*
268.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
268.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
268.7 + *
268.8 + * This code is free software; you can redistribute it and/or modify it
268.9 + * under the terms of the GNU General Public License version 2 only, as
268.10 + * published by the Free Software Foundation. Sun designates this
268.11 + * particular file as subject to the "Classpath" exception as provided
268.12 + * by Sun in the LICENSE file that accompanied this code.
268.13 + *
268.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
268.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
268.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
268.17 + * version 2 for more details (a copy is included in the LICENSE file that
268.18 + * accompanied this code).
268.19 + *
268.20 + * You should have received a copy of the GNU General Public License version
268.21 + * 2 along with this work; if not, write to the Free Software Foundation,
268.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
268.23 + *
268.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
268.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
268.26 + * have any questions.
268.27 + */
268.28 +
268.29 +/* @test
268.30 + @summary Test ModelByteBuffer loadAll method */
268.31 +
268.32 +import java.io.File;
268.33 +import java.io.FileOutputStream;
268.34 +import java.io.IOException;
268.35 +import java.util.ArrayList;
268.36 +import java.util.List;
268.37 +
268.38 +import javax.sound.sampled.*;
268.39 +
268.40 +import com.sun.media.sound.*;
268.41 +
268.42 +public class LoadAll {
268.43 +
268.44 + static float[] testarray;
268.45 + static byte[] test_byte_array;
268.46 + static File test_file;
268.47 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
268.48 +
268.49 + static void setUp() throws Exception {
268.50 + testarray = new float[1024];
268.51 + for (int i = 0; i < 1024; i++) {
268.52 + double ii = i / 1024.0;
268.53 + ii = ii * ii;
268.54 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
268.55 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
268.56 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
268.57 + testarray[i] *= 0.3;
268.58 + }
268.59 + test_byte_array = new byte[testarray.length*2];
268.60 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
268.61 + test_file = File.createTempFile("test", ".raw");
268.62 + FileOutputStream fos = new FileOutputStream(test_file);
268.63 + fos.write(test_byte_array);
268.64 + }
268.65 +
268.66 + static void tearDown() throws Exception {
268.67 + if(!test_file.delete())
268.68 + test_file.deleteOnExit();
268.69 + }
268.70 +
268.71 + public static void main(String[] args) throws Exception {
268.72 + try
268.73 + {
268.74 + setUp();
268.75 +
268.76 + ModelByteBuffer buff = new ModelByteBuffer(test_file);
268.77 + List<ModelByteBuffer> col = new ArrayList<ModelByteBuffer>();
268.78 + col.add(buff);
268.79 + ModelByteBuffer.loadAll(col);
268.80 + if(buff.array() == null)
268.81 + throw new RuntimeException("buf is null!");
268.82 + if(buff.array().length != test_byte_array.length)
268.83 + throw new RuntimeException("buff.array().length length is incorrect!");
268.84 + byte[] b = buff.array();
268.85 + for (int i = 0; i < b.length; i++)
268.86 + if(test_byte_array[i] != b[i])
268.87 + throw new RuntimeException("buff.array() incorrect!");
268.88 +
268.89 + }
268.90 + finally
268.91 + {
268.92 + tearDown();
268.93 + }
268.94 + }
268.95 +
268.96 +}
269.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
269.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBuffer/NewModelByteBufferByteArray.java Tue Feb 03 22:02:55 2009 -0800
269.3 @@ -0,0 +1,84 @@
269.4 +/*
269.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
269.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
269.7 + *
269.8 + * This code is free software; you can redistribute it and/or modify it
269.9 + * under the terms of the GNU General Public License version 2 only, as
269.10 + * published by the Free Software Foundation. Sun designates this
269.11 + * particular file as subject to the "Classpath" exception as provided
269.12 + * by Sun in the LICENSE file that accompanied this code.
269.13 + *
269.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
269.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
269.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
269.17 + * version 2 for more details (a copy is included in the LICENSE file that
269.18 + * accompanied this code).
269.19 + *
269.20 + * You should have received a copy of the GNU General Public License version
269.21 + * 2 along with this work; if not, write to the Free Software Foundation,
269.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
269.23 + *
269.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
269.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
269.26 + * have any questions.
269.27 + */
269.28 +
269.29 +/* @test
269.30 + @summary Test ModelByteBuffer(byte[]) constructor */
269.31 +
269.32 +import java.io.File;
269.33 +import java.io.FileOutputStream;
269.34 +
269.35 +import javax.sound.sampled.*;
269.36 +
269.37 +import com.sun.media.sound.*;
269.38 +
269.39 +public class NewModelByteBufferByteArray {
269.40 +
269.41 + static float[] testarray;
269.42 + static byte[] test_byte_array;
269.43 + static File test_file;
269.44 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
269.45 +
269.46 + static void setUp() throws Exception {
269.47 + testarray = new float[1024];
269.48 + for (int i = 0; i < 1024; i++) {
269.49 + double ii = i / 1024.0;
269.50 + ii = ii * ii;
269.51 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
269.52 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
269.53 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
269.54 + testarray[i] *= 0.3;
269.55 + }
269.56 + test_byte_array = new byte[testarray.length*2];
269.57 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
269.58 + test_file = File.createTempFile("test", ".raw");
269.59 + FileOutputStream fos = new FileOutputStream(test_file);
269.60 + fos.write(test_byte_array);
269.61 + }
269.62 +
269.63 + static void tearDown() throws Exception {
269.64 + if(!test_file.delete())
269.65 + test_file.deleteOnExit();
269.66 + }
269.67 +
269.68 + public static void main(String[] args) throws Exception {
269.69 + try
269.70 + {
269.71 + setUp();
269.72 +
269.73 + ModelByteBuffer buff = new ModelByteBuffer(test_byte_array);
269.74 + if(buff.array() != test_byte_array)
269.75 + throw new RuntimeException("buff.bytearray incorrect!");
269.76 + if(buff.capacity() != test_byte_array.length)
269.77 + throw new RuntimeException("buff.capacity() incorrect!");
269.78 + if(buff.arrayOffset() != 0)
269.79 + throw new RuntimeException("buff.arrayOffset not 0!");
269.80 + }
269.81 + finally
269.82 + {
269.83 + tearDown();
269.84 + }
269.85 + }
269.86 +
269.87 +}
270.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
270.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBuffer/NewModelByteBufferByteArrayIntInt.java Tue Feb 03 22:02:55 2009 -0800
270.3 @@ -0,0 +1,86 @@
270.4 +/*
270.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
270.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
270.7 + *
270.8 + * This code is free software; you can redistribute it and/or modify it
270.9 + * under the terms of the GNU General Public License version 2 only, as
270.10 + * published by the Free Software Foundation. Sun designates this
270.11 + * particular file as subject to the "Classpath" exception as provided
270.12 + * by Sun in the LICENSE file that accompanied this code.
270.13 + *
270.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
270.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
270.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
270.17 + * version 2 for more details (a copy is included in the LICENSE file that
270.18 + * accompanied this code).
270.19 + *
270.20 + * You should have received a copy of the GNU General Public License version
270.21 + * 2 along with this work; if not, write to the Free Software Foundation,
270.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
270.23 + *
270.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
270.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
270.26 + * have any questions.
270.27 + */
270.28 +
270.29 +/* @test
270.30 + @summary Test ModelByteBuffer(byte[],int,int) constructor */
270.31 +
270.32 +import java.io.File;
270.33 +import java.io.FileOutputStream;
270.34 +
270.35 +import javax.sound.sampled.*;
270.36 +
270.37 +import com.sun.media.sound.*;
270.38 +
270.39 +public class NewModelByteBufferByteArrayIntInt {
270.40 +
270.41 + static float[] testarray;
270.42 + static byte[] test_byte_array;
270.43 + static File test_file;
270.44 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
270.45 +
270.46 + static void setUp() throws Exception {
270.47 + testarray = new float[1024];
270.48 + for (int i = 0; i < 1024; i++) {
270.49 + double ii = i / 1024.0;
270.50 + ii = ii * ii;
270.51 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
270.52 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
270.53 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
270.54 + testarray[i] *= 0.3;
270.55 + }
270.56 + test_byte_array = new byte[testarray.length*2];
270.57 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
270.58 + test_file = File.createTempFile("test", ".raw");
270.59 + FileOutputStream fos = new FileOutputStream(test_file);
270.60 + fos.write(test_byte_array);
270.61 + }
270.62 +
270.63 + static void tearDown() throws Exception {
270.64 + if(!test_file.delete())
270.65 + test_file.deleteOnExit();
270.66 + }
270.67 +
270.68 + public static void main(String[] args) throws Exception {
270.69 + try
270.70 + {
270.71 + setUp();
270.72 +
270.73 + ModelByteBuffer buff = new ModelByteBuffer(test_byte_array,10,20);
270.74 + if(buff.array() != test_byte_array)
270.75 + throw new RuntimeException("buff.array() incorrect!");
270.76 + if(buff.capacity() != 20)
270.77 + throw new RuntimeException("buff.capacity() not 20!");
270.78 + if(buff.arrayOffset() != 10)
270.79 + throw new RuntimeException("buff.arrayOffset() not 10!");
270.80 + if(buff.getFile() != null)
270.81 + throw new RuntimeException("buff.getFile() not null!");
270.82 + }
270.83 + finally
270.84 + {
270.85 + tearDown();
270.86 + }
270.87 + }
270.88 +
270.89 +}
271.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
271.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBuffer/NewModelByteBufferFile.java Tue Feb 03 22:02:55 2009 -0800
271.3 @@ -0,0 +1,88 @@
271.4 +/*
271.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
271.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
271.7 + *
271.8 + * This code is free software; you can redistribute it and/or modify it
271.9 + * under the terms of the GNU General Public License version 2 only, as
271.10 + * published by the Free Software Foundation. Sun designates this
271.11 + * particular file as subject to the "Classpath" exception as provided
271.12 + * by Sun in the LICENSE file that accompanied this code.
271.13 + *
271.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
271.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
271.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
271.17 + * version 2 for more details (a copy is included in the LICENSE file that
271.18 + * accompanied this code).
271.19 + *
271.20 + * You should have received a copy of the GNU General Public License version
271.21 + * 2 along with this work; if not, write to the Free Software Foundation,
271.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
271.23 + *
271.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
271.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
271.26 + * have any questions.
271.27 + */
271.28 +
271.29 +/* @test
271.30 + @summary Test ModelByteBuffer(File) constructor */
271.31 +
271.32 +import java.io.File;
271.33 +import java.io.FileOutputStream;
271.34 +
271.35 +import javax.sound.sampled.*;
271.36 +
271.37 +import com.sun.media.sound.*;
271.38 +
271.39 +public class NewModelByteBufferFile {
271.40 +
271.41 + static float[] testarray;
271.42 + static byte[] test_byte_array;
271.43 + static File test_file;
271.44 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
271.45 +
271.46 + static void setUp() throws Exception {
271.47 + testarray = new float[1024];
271.48 + for (int i = 0; i < 1024; i++) {
271.49 + double ii = i / 1024.0;
271.50 + ii = ii * ii;
271.51 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
271.52 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
271.53 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
271.54 + testarray[i] *= 0.3;
271.55 + }
271.56 + test_byte_array = new byte[testarray.length*2];
271.57 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
271.58 + test_file = File.createTempFile("test", ".raw");
271.59 + FileOutputStream fos = new FileOutputStream(test_file);
271.60 + fos.write(test_byte_array);
271.61 + }
271.62 +
271.63 + static void tearDown() throws Exception {
271.64 + if(!test_file.delete())
271.65 + test_file.deleteOnExit();
271.66 + }
271.67 +
271.68 + public static void main(String[] args) throws Exception {
271.69 + try
271.70 + {
271.71 + setUp();
271.72 +
271.73 + ModelByteBuffer buff = new ModelByteBuffer(test_file);
271.74 + if(buff.array() != null)
271.75 + throw new RuntimeException("buff.array() not null!");
271.76 + if(buff.capacity() != test_file.length())
271.77 + throw new RuntimeException("buff.capacity() incorrect!");
271.78 + if(buff.arrayOffset() != 0)
271.79 + throw new RuntimeException("buff.arrayOffset() not 0!");
271.80 + if(buff.getFile() != test_file)
271.81 + throw new RuntimeException("buff.getFile() incorrect!");
271.82 + if(buff.getFilePointer() != 0)
271.83 + throw new RuntimeException("buff.getFilePointer() not 0!");
271.84 + }
271.85 + finally
271.86 + {
271.87 + tearDown();
271.88 + }
271.89 + }
271.90 +
271.91 +}
272.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
272.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBuffer/NewModelByteBufferFileLongLong.java Tue Feb 03 22:02:55 2009 -0800
272.3 @@ -0,0 +1,88 @@
272.4 +/*
272.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
272.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
272.7 + *
272.8 + * This code is free software; you can redistribute it and/or modify it
272.9 + * under the terms of the GNU General Public License version 2 only, as
272.10 + * published by the Free Software Foundation. Sun designates this
272.11 + * particular file as subject to the "Classpath" exception as provided
272.12 + * by Sun in the LICENSE file that accompanied this code.
272.13 + *
272.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
272.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
272.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
272.17 + * version 2 for more details (a copy is included in the LICENSE file that
272.18 + * accompanied this code).
272.19 + *
272.20 + * You should have received a copy of the GNU General Public License version
272.21 + * 2 along with this work; if not, write to the Free Software Foundation,
272.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
272.23 + *
272.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
272.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
272.26 + * have any questions.
272.27 + */
272.28 +
272.29 +/* @test
272.30 + @summary Test ModelByteBuffer(File,long,long) constructor */
272.31 +
272.32 +import java.io.File;
272.33 +import java.io.FileOutputStream;
272.34 +
272.35 +import javax.sound.sampled.*;
272.36 +
272.37 +import com.sun.media.sound.*;
272.38 +
272.39 +public class NewModelByteBufferFileLongLong {
272.40 +
272.41 + static float[] testarray;
272.42 + static byte[] test_byte_array;
272.43 + static File test_file;
272.44 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
272.45 +
272.46 + static void setUp() throws Exception {
272.47 + testarray = new float[1024];
272.48 + for (int i = 0; i < 1024; i++) {
272.49 + double ii = i / 1024.0;
272.50 + ii = ii * ii;
272.51 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
272.52 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
272.53 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
272.54 + testarray[i] *= 0.3;
272.55 + }
272.56 + test_byte_array = new byte[testarray.length*2];
272.57 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
272.58 + test_file = File.createTempFile("test", ".raw");
272.59 + FileOutputStream fos = new FileOutputStream(test_file);
272.60 + fos.write(test_byte_array);
272.61 + }
272.62 +
272.63 + static void tearDown() throws Exception {
272.64 + if(!test_file.delete())
272.65 + test_file.deleteOnExit();
272.66 + }
272.67 +
272.68 + public static void main(String[] args) throws Exception {
272.69 + try
272.70 + {
272.71 + setUp();
272.72 +
272.73 + ModelByteBuffer buff = new ModelByteBuffer(test_file,10,20);
272.74 + if(buff.array() != null)
272.75 + throw new RuntimeException("buff.array() not null!");
272.76 + if(buff.capacity() != 20)
272.77 + throw new RuntimeException("buff.capacity() not 20!");
272.78 + if(buff.arrayOffset() != 0)
272.79 + throw new RuntimeException("buff.arrayOffset() not 0!");
272.80 + if(buff.getFile() != test_file)
272.81 + throw new RuntimeException("buff.getFile incorrect!");
272.82 + if(buff.getFilePointer() != 10)
272.83 + throw new RuntimeException("buff.getFilePointer not 10!");
272.84 + }
272.85 + finally
272.86 + {
272.87 + tearDown();
272.88 + }
272.89 + }
272.90 +
272.91 +}
273.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
273.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/Available.java Tue Feb 03 22:02:55 2009 -0800
273.3 @@ -0,0 +1,107 @@
273.4 +/*
273.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
273.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
273.7 + *
273.8 + * This code is free software; you can redistribute it and/or modify it
273.9 + * under the terms of the GNU General Public License version 2 only, as
273.10 + * published by the Free Software Foundation. Sun designates this
273.11 + * particular file as subject to the "Classpath" exception as provided
273.12 + * by Sun in the LICENSE file that accompanied this code.
273.13 + *
273.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
273.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
273.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
273.17 + * version 2 for more details (a copy is included in the LICENSE file that
273.18 + * accompanied this code).
273.19 + *
273.20 + * You should have received a copy of the GNU General Public License version
273.21 + * 2 along with this work; if not, write to the Free Software Foundation,
273.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
273.23 + *
273.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
273.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
273.26 + * have any questions.
273.27 + */
273.28 +
273.29 +/* @test
273.30 + @summary Test ModelByteBuffer.RandomFileInputStream available() method */
273.31 +
273.32 +import java.io.File;
273.33 +import java.io.FileOutputStream;
273.34 +import java.io.IOException;
273.35 +import java.io.InputStream;
273.36 +
273.37 +import javax.sound.sampled.*;
273.38 +
273.39 +import com.sun.media.sound.*;
273.40 +
273.41 +public class Available {
273.42 +
273.43 + static float[] testarray;
273.44 + static byte[] test_byte_array;
273.45 + static File test_file;
273.46 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
273.47 +
273.48 + static void setUp() throws Exception {
273.49 + testarray = new float[1024];
273.50 + for (int i = 0; i < 1024; i++) {
273.51 + double ii = i / 1024.0;
273.52 + ii = ii * ii;
273.53 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
273.54 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
273.55 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
273.56 + testarray[i] *= 0.3;
273.57 + }
273.58 + test_byte_array = new byte[testarray.length*2];
273.59 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
273.60 + test_file = File.createTempFile("test", ".raw");
273.61 + FileOutputStream fos = new FileOutputStream(test_file);
273.62 + fos.write(test_byte_array);
273.63 + }
273.64 +
273.65 + static void tearDown() throws Exception {
273.66 + if(!test_file.delete())
273.67 + test_file.deleteOnExit();
273.68 + }
273.69 +
273.70 + public static void main(String[] args) throws Exception {
273.71 + try
273.72 + {
273.73 + setUp();
273.74 +
273.75 + for (int i = 0; i < 8; i++) {
273.76 + ModelByteBuffer buff;
273.77 + if(i % 2 == 0)
273.78 + buff = new ModelByteBuffer(test_file);
273.79 + else
273.80 + buff = new ModelByteBuffer(test_byte_array);
273.81 + if((i / 2) == 1)
273.82 + buff.subbuffer(5);
273.83 + if((i / 2) == 2)
273.84 + buff.subbuffer(5,500);
273.85 + if((i / 2) == 3)
273.86 + buff.subbuffer(5,600,true);
273.87 +
273.88 + long capacity = buff.capacity();
273.89 + InputStream is = buff.getInputStream();
273.90 + try
273.91 + {
273.92 + int ret = is.available();
273.93 + if(ret != capacity)
273.94 + throw new RuntimeException("is.available() return unexpected value!");
273.95 + }
273.96 + finally
273.97 + {
273.98 + is.close();
273.99 + }
273.100 + if(buff.capacity() != capacity)
273.101 + throw new RuntimeException("Capacity variable should not change!");
273.102 + }
273.103 + }
273.104 + finally
273.105 + {
273.106 + tearDown();
273.107 + }
273.108 + }
273.109 +
273.110 +}
274.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
274.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/Close.java Tue Feb 03 22:02:55 2009 -0800
274.3 @@ -0,0 +1,104 @@
274.4 +/*
274.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
274.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
274.7 + *
274.8 + * This code is free software; you can redistribute it and/or modify it
274.9 + * under the terms of the GNU General Public License version 2 only, as
274.10 + * published by the Free Software Foundation. Sun designates this
274.11 + * particular file as subject to the "Classpath" exception as provided
274.12 + * by Sun in the LICENSE file that accompanied this code.
274.13 + *
274.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
274.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
274.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
274.17 + * version 2 for more details (a copy is included in the LICENSE file that
274.18 + * accompanied this code).
274.19 + *
274.20 + * You should have received a copy of the GNU General Public License version
274.21 + * 2 along with this work; if not, write to the Free Software Foundation,
274.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
274.23 + *
274.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
274.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
274.26 + * have any questions.
274.27 + */
274.28 +
274.29 +/* @test
274.30 + @summary Test ModelByteBuffer.RandomFileInputStream close method */
274.31 +
274.32 +import java.io.File;
274.33 +import java.io.FileOutputStream;
274.34 +import java.io.IOException;
274.35 +import java.io.InputStream;
274.36 +
274.37 +import javax.sound.sampled.*;
274.38 +
274.39 +import com.sun.media.sound.*;
274.40 +
274.41 +public class Close {
274.42 +
274.43 + static float[] testarray;
274.44 + static byte[] test_byte_array;
274.45 + static File test_file;
274.46 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
274.47 +
274.48 + static void setUp() throws Exception {
274.49 + testarray = new float[1024];
274.50 + for (int i = 0; i < 1024; i++) {
274.51 + double ii = i / 1024.0;
274.52 + ii = ii * ii;
274.53 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
274.54 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
274.55 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
274.56 + testarray[i] *= 0.3;
274.57 + }
274.58 + test_byte_array = new byte[testarray.length*2];
274.59 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
274.60 + test_file = File.createTempFile("test", ".raw");
274.61 + FileOutputStream fos = new FileOutputStream(test_file);
274.62 + fos.write(test_byte_array);
274.63 + }
274.64 +
274.65 + static void tearDown() throws Exception {
274.66 + if(!test_file.delete())
274.67 + test_file.deleteOnExit();
274.68 + }
274.69 +
274.70 + public static void main(String[] args) throws Exception {
274.71 + try
274.72 + {
274.73 + setUp();
274.74 +
274.75 + for (int i = 0; i < 8; i++) {
274.76 + ModelByteBuffer buff;
274.77 + if(i % 2 == 0)
274.78 + buff = new ModelByteBuffer(test_file);
274.79 + else
274.80 + buff = new ModelByteBuffer(test_byte_array);
274.81 + if((i / 2) == 1)
274.82 + buff.subbuffer(5);
274.83 + if((i / 2) == 2)
274.84 + buff.subbuffer(5,500);
274.85 + if((i / 2) == 3)
274.86 + buff.subbuffer(5,600,true);
274.87 +
274.88 + long capacity = buff.capacity();
274.89 + InputStream is = buff.getInputStream();
274.90 + try
274.91 + {
274.92 + }
274.93 + finally
274.94 + {
274.95 + is.close();
274.96 + }
274.97 + if(buff.capacity() != capacity)
274.98 + throw new RuntimeException("Capacity variable should not change!");
274.99 + }
274.100 + }
274.101 + finally
274.102 + {
274.103 + tearDown();
274.104 + }
274.105 + }
274.106 +
274.107 +}
275.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
275.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/MarkReset.java Tue Feb 03 22:02:55 2009 -0800
275.3 @@ -0,0 +1,129 @@
275.4 +/*
275.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
275.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
275.7 + *
275.8 + * This code is free software; you can redistribute it and/or modify it
275.9 + * under the terms of the GNU General Public License version 2 only, as
275.10 + * published by the Free Software Foundation. Sun designates this
275.11 + * particular file as subject to the "Classpath" exception as provided
275.12 + * by Sun in the LICENSE file that accompanied this code.
275.13 + *
275.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
275.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
275.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
275.17 + * version 2 for more details (a copy is included in the LICENSE file that
275.18 + * accompanied this code).
275.19 + *
275.20 + * You should have received a copy of the GNU General Public License version
275.21 + * 2 along with this work; if not, write to the Free Software Foundation,
275.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
275.23 + *
275.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
275.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
275.26 + * have any questions.
275.27 + */
275.28 +
275.29 +/* @test
275.30 + @summary Test ModelByteBuffer.RandomFileInputStream mark and reset methods */
275.31 +
275.32 +import java.io.File;
275.33 +import java.io.FileOutputStream;
275.34 +import java.io.IOException;
275.35 +import java.io.InputStream;
275.36 +
275.37 +import javax.sound.sampled.*;
275.38 +
275.39 +import com.sun.media.sound.*;
275.40 +
275.41 +public class MarkReset {
275.42 +
275.43 + static float[] testarray;
275.44 + static byte[] test_byte_array;
275.45 + static File test_file;
275.46 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
275.47 +
275.48 + static void setUp() throws Exception {
275.49 + testarray = new float[1024];
275.50 + for (int i = 0; i < 1024; i++) {
275.51 + double ii = i / 1024.0;
275.52 + ii = ii * ii;
275.53 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
275.54 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
275.55 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
275.56 + testarray[i] *= 0.3;
275.57 + }
275.58 + test_byte_array = new byte[testarray.length*2];
275.59 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
275.60 + test_file = File.createTempFile("test", ".raw");
275.61 + FileOutputStream fos = new FileOutputStream(test_file);
275.62 + fos.write(test_byte_array);
275.63 + }
275.64 +
275.65 + static void tearDown() throws Exception {
275.66 + if(!test_file.delete())
275.67 + test_file.deleteOnExit();
275.68 + }
275.69 +
275.70 + public static void main(String[] args) throws Exception {
275.71 + try
275.72 + {
275.73 + setUp();
275.74 +
275.75 + for (int i = 0; i < 8; i++) {
275.76 + ModelByteBuffer buff;
275.77 + if(i % 2 == 0)
275.78 + buff = new ModelByteBuffer(test_file);
275.79 + else
275.80 + buff = new ModelByteBuffer(test_byte_array);
275.81 + if((i / 2) == 1)
275.82 + buff.subbuffer(5);
275.83 + if((i / 2) == 2)
275.84 + buff.subbuffer(5,500);
275.85 + if((i / 2) == 3)
275.86 + buff.subbuffer(5,600,true);
275.87 +
275.88 + long capacity = buff.capacity();
275.89 + InputStream is = buff.getInputStream();
275.90 + try
275.91 + {
275.92 + is.mark(1000);
275.93 + int ret = is.available();
275.94 + int a = is.read();
275.95 + is.skip(75);
275.96 + is.reset();
275.97 + if(is.available() != ret)
275.98 + throw new RuntimeException(
275.99 + "is.available() returns incorrect value ("
275.100 + + is.available() + "!="+(ret)+") !");
275.101 + int b = is.read();
275.102 + if(a != b)
275.103 + throw new RuntimeException(
275.104 + "is doesn't return same value after reset ("
275.105 + + a + "!="+b+") !");
275.106 +
275.107 + is.skip(15);
275.108 + ret = is.available();
275.109 + is.mark(1000);
275.110 + is.reset();
275.111 + if(is.available() != ret)
275.112 + throw new RuntimeException(
275.113 + "is.available() returns incorrect value ("
275.114 + + is.available() + "!="+(ret)+") !");
275.115 +
275.116 +
275.117 + }
275.118 + finally
275.119 + {
275.120 + is.close();
275.121 + }
275.122 + if(buff.capacity() != capacity)
275.123 + throw new RuntimeException("Capacity variable should not change!");
275.124 + }
275.125 + }
275.126 + finally
275.127 + {
275.128 + tearDown();
275.129 + }
275.130 + }
275.131 +
275.132 +}
276.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
276.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/MarkSupported.java Tue Feb 03 22:02:55 2009 -0800
276.3 @@ -0,0 +1,106 @@
276.4 +/*
276.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
276.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
276.7 + *
276.8 + * This code is free software; you can redistribute it and/or modify it
276.9 + * under the terms of the GNU General Public License version 2 only, as
276.10 + * published by the Free Software Foundation. Sun designates this
276.11 + * particular file as subject to the "Classpath" exception as provided
276.12 + * by Sun in the LICENSE file that accompanied this code.
276.13 + *
276.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
276.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
276.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
276.17 + * version 2 for more details (a copy is included in the LICENSE file that
276.18 + * accompanied this code).
276.19 + *
276.20 + * You should have received a copy of the GNU General Public License version
276.21 + * 2 along with this work; if not, write to the Free Software Foundation,
276.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
276.23 + *
276.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
276.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
276.26 + * have any questions.
276.27 + */
276.28 +
276.29 +/* @test
276.30 + @summary Test ModelByteBuffer.RandomFileInputStream markSupported() method */
276.31 +
276.32 +import java.io.File;
276.33 +import java.io.FileOutputStream;
276.34 +import java.io.IOException;
276.35 +import java.io.InputStream;
276.36 +
276.37 +import javax.sound.sampled.*;
276.38 +
276.39 +import com.sun.media.sound.*;
276.40 +
276.41 +public class MarkSupported {
276.42 +
276.43 + static float[] testarray;
276.44 + static byte[] test_byte_array;
276.45 + static File test_file;
276.46 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
276.47 +
276.48 + static void setUp() throws Exception {
276.49 + testarray = new float[1024];
276.50 + for (int i = 0; i < 1024; i++) {
276.51 + double ii = i / 1024.0;
276.52 + ii = ii * ii;
276.53 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
276.54 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
276.55 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
276.56 + testarray[i] *= 0.3;
276.57 + }
276.58 + test_byte_array = new byte[testarray.length*2];
276.59 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
276.60 + test_file = File.createTempFile("test", ".raw");
276.61 + FileOutputStream fos = new FileOutputStream(test_file);
276.62 + fos.write(test_byte_array);
276.63 + }
276.64 +
276.65 + static void tearDown() throws Exception {
276.66 + if(!test_file.delete())
276.67 + test_file.deleteOnExit();
276.68 + }
276.69 +
276.70 + public static void main(String[] args) throws Exception {
276.71 + try
276.72 + {
276.73 + setUp();
276.74 +
276.75 + for (int i = 0; i < 8; i++) {
276.76 + ModelByteBuffer buff;
276.77 + if(i % 2 == 0)
276.78 + buff = new ModelByteBuffer(test_file);
276.79 + else
276.80 + buff = new ModelByteBuffer(test_byte_array);
276.81 + if((i / 2) == 1)
276.82 + buff.subbuffer(5);
276.83 + if((i / 2) == 2)
276.84 + buff.subbuffer(5,500);
276.85 + if((i / 2) == 3)
276.86 + buff.subbuffer(5,600,true);
276.87 +
276.88 + long capacity = buff.capacity();
276.89 + InputStream is = buff.getInputStream();
276.90 + try
276.91 + {
276.92 + if(!is.markSupported())
276.93 + throw new RuntimeException("InputStream doesn't support mark/reset!");
276.94 + }
276.95 + finally
276.96 + {
276.97 + is.close();
276.98 + }
276.99 + if(buff.capacity() != capacity)
276.100 + throw new RuntimeException("Capacity variable should not change!");
276.101 + }
276.102 + }
276.103 + finally
276.104 + {
276.105 + tearDown();
276.106 + }
276.107 + }
276.108 +
276.109 +}
277.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
277.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/Read.java Tue Feb 03 22:02:55 2009 -0800
277.3 @@ -0,0 +1,117 @@
277.4 +/*
277.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
277.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
277.7 + *
277.8 + * This code is free software; you can redistribute it and/or modify it
277.9 + * under the terms of the GNU General Public License version 2 only, as
277.10 + * published by the Free Software Foundation. Sun designates this
277.11 + * particular file as subject to the "Classpath" exception as provided
277.12 + * by Sun in the LICENSE file that accompanied this code.
277.13 + *
277.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
277.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
277.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
277.17 + * version 2 for more details (a copy is included in the LICENSE file that
277.18 + * accompanied this code).
277.19 + *
277.20 + * You should have received a copy of the GNU General Public License version
277.21 + * 2 along with this work; if not, write to the Free Software Foundation,
277.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
277.23 + *
277.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
277.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
277.26 + * have any questions.
277.27 + */
277.28 +
277.29 +/* @test
277.30 + @summary Test ModelByteBuffer.RandomFileInputStream read() method */
277.31 +
277.32 +import java.io.File;
277.33 +import java.io.FileOutputStream;
277.34 +import java.io.IOException;
277.35 +import java.io.InputStream;
277.36 +
277.37 +import javax.sound.sampled.*;
277.38 +
277.39 +import com.sun.media.sound.*;
277.40 +
277.41 +public class Read {
277.42 +
277.43 + static float[] testarray;
277.44 + static byte[] test_byte_array;
277.45 + static File test_file;
277.46 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
277.47 +
277.48 + static void setUp() throws Exception {
277.49 + testarray = new float[1024];
277.50 + for (int i = 0; i < 1024; i++) {
277.51 + double ii = i / 1024.0;
277.52 + ii = ii * ii;
277.53 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
277.54 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
277.55 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
277.56 + testarray[i] *= 0.3;
277.57 + }
277.58 + test_byte_array = new byte[testarray.length*2];
277.59 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
277.60 + test_file = File.createTempFile("test", ".raw");
277.61 + FileOutputStream fos = new FileOutputStream(test_file);
277.62 + fos.write(test_byte_array);
277.63 + }
277.64 +
277.65 + static void tearDown() throws Exception {
277.66 + if(!test_file.delete())
277.67 + test_file.deleteOnExit();
277.68 + }
277.69 +
277.70 + public static void main(String[] args) throws Exception {
277.71 + try
277.72 + {
277.73 + setUp();
277.74 +
277.75 + for (int i = 0; i < 8; i++) {
277.76 + ModelByteBuffer buff;
277.77 + if(i % 2 == 0)
277.78 + buff = new ModelByteBuffer(test_file);
277.79 + else
277.80 + buff = new ModelByteBuffer(test_byte_array);
277.81 + if((i / 2) == 1)
277.82 + buff.subbuffer(5);
277.83 + if((i / 2) == 2)
277.84 + buff.subbuffer(5,500);
277.85 + if((i / 2) == 3)
277.86 + buff.subbuffer(5,600,true);
277.87 +
277.88 + long capacity = buff.capacity();
277.89 + InputStream is = buff.getInputStream();
277.90 + try
277.91 + {
277.92 + byte[] b = new byte[100];
277.93 + int ret = is.available();
277.94 + int n = is.read();
277.95 + if(n == -1)
277.96 + throw new RuntimeException("is.read shouldn't return -1!");
277.97 + if(is.available() != ret - 1)
277.98 + throw new RuntimeException(
277.99 + "is.available() returns incorrect value ("
277.100 + + is.available() + "!="+(ret - 1)+") !");
277.101 + is.skip(5000);
277.102 + if(is.read() != -1)
277.103 + throw new RuntimeException(
277.104 + "is.read() doesn't return -1!");
277.105 + }
277.106 + finally
277.107 + {
277.108 + is.close();
277.109 + }
277.110 + if(buff.capacity() != capacity)
277.111 + throw new RuntimeException("Capacity variable should not change!");
277.112 + }
277.113 + }
277.114 + finally
277.115 + {
277.116 + tearDown();
277.117 + }
277.118 + }
277.119 +
277.120 +}
278.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
278.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/ReadByte.java Tue Feb 03 22:02:55 2009 -0800
278.3 @@ -0,0 +1,118 @@
278.4 +/*
278.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
278.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
278.7 + *
278.8 + * This code is free software; you can redistribute it and/or modify it
278.9 + * under the terms of the GNU General Public License version 2 only, as
278.10 + * published by the Free Software Foundation. Sun designates this
278.11 + * particular file as subject to the "Classpath" exception as provided
278.12 + * by Sun in the LICENSE file that accompanied this code.
278.13 + *
278.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
278.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
278.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
278.17 + * version 2 for more details (a copy is included in the LICENSE file that
278.18 + * accompanied this code).
278.19 + *
278.20 + * You should have received a copy of the GNU General Public License version
278.21 + * 2 along with this work; if not, write to the Free Software Foundation,
278.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
278.23 + *
278.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
278.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
278.26 + * have any questions.
278.27 + */
278.28 +
278.29 +/* @test
278.30 + @summary Test ModelByteBuffer.RandomFileInputStream read(byte[]) method */
278.31 +
278.32 +import java.io.File;
278.33 +import java.io.FileOutputStream;
278.34 +import java.io.IOException;
278.35 +import java.io.InputStream;
278.36 +
278.37 +import javax.sound.sampled.*;
278.38 +
278.39 +import com.sun.media.sound.*;
278.40 +
278.41 +public class ReadByte {
278.42 +
278.43 + static float[] testarray;
278.44 + static byte[] test_byte_array;
278.45 + static File test_file;
278.46 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
278.47 +
278.48 + static void setUp() throws Exception {
278.49 + testarray = new float[1024];
278.50 + for (int i = 0; i < 1024; i++) {
278.51 + double ii = i / 1024.0;
278.52 + ii = ii * ii;
278.53 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
278.54 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
278.55 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
278.56 + testarray[i] *= 0.3;
278.57 + }
278.58 + test_byte_array = new byte[testarray.length*2];
278.59 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
278.60 + test_file = File.createTempFile("test", ".raw");
278.61 + FileOutputStream fos = new FileOutputStream(test_file);
278.62 + fos.write(test_byte_array);
278.63 + }
278.64 +
278.65 + static void tearDown() throws Exception {
278.66 + if(!test_file.delete())
278.67 + test_file.deleteOnExit();
278.68 + }
278.69 +
278.70 + public static void main(String[] args) throws Exception {
278.71 + try
278.72 + {
278.73 + setUp();
278.74 +
278.75 + for (int i = 0; i < 8; i++) {
278.76 + ModelByteBuffer buff;
278.77 + if(i % 2 == 0)
278.78 + buff = new ModelByteBuffer(test_file);
278.79 + else
278.80 + buff = new ModelByteBuffer(test_byte_array);
278.81 + if((i / 2) == 1)
278.82 + buff.subbuffer(5);
278.83 + if((i / 2) == 2)
278.84 + buff.subbuffer(5,500);
278.85 + if((i / 2) == 3)
278.86 + buff.subbuffer(5,600,true);
278.87 +
278.88 + long capacity = buff.capacity();
278.89 + InputStream is = buff.getInputStream();
278.90 + try
278.91 + {
278.92 + byte[] b = new byte[100];
278.93 + int ret = is.available();
278.94 + int n = is.read(b);
278.95 + if(n == -1)
278.96 + throw new RuntimeException("is.read shouldn't return -1!");
278.97 + if(is.available() != ret - n)
278.98 + throw new RuntimeException(
278.99 + "is.available() returns incorrect value ("
278.100 + + is.available() + "!="+(ret - n)+") !");
278.101 + is.skip(5000);
278.102 + if(is.read(b) != -1)
278.103 + throw new RuntimeException(
278.104 + "is.read() doesn't return -1!");
278.105 +
278.106 + }
278.107 + finally
278.108 + {
278.109 + is.close();
278.110 + }
278.111 + if(buff.capacity() != capacity)
278.112 + throw new RuntimeException("Capacity variable should not change!");
278.113 + }
278.114 + }
278.115 + finally
278.116 + {
278.117 + tearDown();
278.118 + }
278.119 + }
278.120 +
278.121 +}
279.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
279.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/ReadByteIntInt.java Tue Feb 03 22:02:55 2009 -0800
279.3 @@ -0,0 +1,118 @@
279.4 +/*
279.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
279.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
279.7 + *
279.8 + * This code is free software; you can redistribute it and/or modify it
279.9 + * under the terms of the GNU General Public License version 2 only, as
279.10 + * published by the Free Software Foundation. Sun designates this
279.11 + * particular file as subject to the "Classpath" exception as provided
279.12 + * by Sun in the LICENSE file that accompanied this code.
279.13 + *
279.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
279.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
279.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
279.17 + * version 2 for more details (a copy is included in the LICENSE file that
279.18 + * accompanied this code).
279.19 + *
279.20 + * You should have received a copy of the GNU General Public License version
279.21 + * 2 along with this work; if not, write to the Free Software Foundation,
279.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
279.23 + *
279.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
279.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
279.26 + * have any questions.
279.27 + */
279.28 +
279.29 +/* @test
279.30 + @summary Test ModelByteBuffer.RandomFileInputStream read(byte[], int, int) method */
279.31 +
279.32 +import java.io.File;
279.33 +import java.io.FileOutputStream;
279.34 +import java.io.IOException;
279.35 +import java.io.InputStream;
279.36 +
279.37 +import javax.sound.sampled.*;
279.38 +
279.39 +import com.sun.media.sound.*;
279.40 +
279.41 +public class ReadByteIntInt {
279.42 +
279.43 + static float[] testarray;
279.44 + static byte[] test_byte_array;
279.45 + static File test_file;
279.46 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
279.47 +
279.48 + static void setUp() throws Exception {
279.49 + testarray = new float[1024];
279.50 + for (int i = 0; i < 1024; i++) {
279.51 + double ii = i / 1024.0;
279.52 + ii = ii * ii;
279.53 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
279.54 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
279.55 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
279.56 + testarray[i] *= 0.3;
279.57 + }
279.58 + test_byte_array = new byte[testarray.length*2];
279.59 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
279.60 + test_file = File.createTempFile("test", ".raw");
279.61 + FileOutputStream fos = new FileOutputStream(test_file);
279.62 + fos.write(test_byte_array);
279.63 + }
279.64 +
279.65 + static void tearDown() throws Exception {
279.66 + if(!test_file.delete())
279.67 + test_file.deleteOnExit();
279.68 + }
279.69 +
279.70 + public static void main(String[] args) throws Exception {
279.71 + try
279.72 + {
279.73 + setUp();
279.74 +
279.75 + for (int i = 0; i < 8; i++) {
279.76 + ModelByteBuffer buff;
279.77 + if(i % 2 == 0)
279.78 + buff = new ModelByteBuffer(test_file);
279.79 + else
279.80 + buff = new ModelByteBuffer(test_byte_array);
279.81 + if((i / 2) == 1)
279.82 + buff.subbuffer(5);
279.83 + if((i / 2) == 2)
279.84 + buff.subbuffer(5,500);
279.85 + if((i / 2) == 3)
279.86 + buff.subbuffer(5,600,true);
279.87 +
279.88 + long capacity = buff.capacity();
279.89 + InputStream is = buff.getInputStream();
279.90 + try
279.91 + {
279.92 + byte[] b = new byte[100];
279.93 + int ret = is.available();
279.94 + int n = is.read(b, 7, 50);
279.95 + if(n == -1)
279.96 + throw new RuntimeException("is.read shouldn't return -1!");
279.97 + if(is.available() != ret - n)
279.98 + throw new RuntimeException(
279.99 + "is.available() returns incorrect value ("
279.100 + + is.available() + "!="+(ret - n)+") !");
279.101 + is.skip(5000);
279.102 + if(is.read(b, 7, 50) != -1)
279.103 + throw new RuntimeException(
279.104 + "is.read() doesn't return -1!");
279.105 +
279.106 + }
279.107 + finally
279.108 + {
279.109 + is.close();
279.110 + }
279.111 + if(buff.capacity() != capacity)
279.112 + throw new RuntimeException("Capacity variable should not change!");
279.113 + }
279.114 + }
279.115 + finally
279.116 + {
279.117 + tearDown();
279.118 + }
279.119 + }
279.120 +
279.121 +}
280.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
280.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/Skip.java Tue Feb 03 22:02:55 2009 -0800
280.3 @@ -0,0 +1,131 @@
280.4 +/*
280.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
280.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
280.7 + *
280.8 + * This code is free software; you can redistribute it and/or modify it
280.9 + * under the terms of the GNU General Public License version 2 only, as
280.10 + * published by the Free Software Foundation. Sun designates this
280.11 + * particular file as subject to the "Classpath" exception as provided
280.12 + * by Sun in the LICENSE file that accompanied this code.
280.13 + *
280.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
280.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
280.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
280.17 + * version 2 for more details (a copy is included in the LICENSE file that
280.18 + * accompanied this code).
280.19 + *
280.20 + * You should have received a copy of the GNU General Public License version
280.21 + * 2 along with this work; if not, write to the Free Software Foundation,
280.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
280.23 + *
280.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
280.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
280.26 + * have any questions.
280.27 + */
280.28 +
280.29 +/* @test
280.30 + @summary Test ModelByteBuffer.RandomFileInputStream skip(long) method */
280.31 +
280.32 +import java.io.File;
280.33 +import java.io.FileOutputStream;
280.34 +import java.io.IOException;
280.35 +import java.io.InputStream;
280.36 +
280.37 +import javax.sound.sampled.*;
280.38 +
280.39 +import com.sun.media.sound.*;
280.40 +
280.41 +public class Skip {
280.42 +
280.43 + static float[] testarray;
280.44 + static byte[] test_byte_array;
280.45 + static File test_file;
280.46 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
280.47 +
280.48 + static void setUp() throws Exception {
280.49 + testarray = new float[1024];
280.50 + for (int i = 0; i < 1024; i++) {
280.51 + double ii = i / 1024.0;
280.52 + ii = ii * ii;
280.53 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
280.54 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
280.55 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
280.56 + testarray[i] *= 0.3;
280.57 + }
280.58 + test_byte_array = new byte[testarray.length*2];
280.59 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
280.60 + test_file = File.createTempFile("test", ".raw");
280.61 + FileOutputStream fos = new FileOutputStream(test_file);
280.62 + fos.write(test_byte_array);
280.63 + }
280.64 +
280.65 + static void tearDown() throws Exception {
280.66 + if(!test_file.delete())
280.67 + test_file.deleteOnExit();
280.68 + }
280.69 +
280.70 + public static void main(String[] args) throws Exception {
280.71 + try
280.72 + {
280.73 + setUp();
280.74 +
280.75 + for (int i = 0; i < 8; i++) {
280.76 + ModelByteBuffer buff;
280.77 + if(i % 2 == 0)
280.78 + buff = new ModelByteBuffer(test_file);
280.79 + else
280.80 + buff = new ModelByteBuffer(test_byte_array);
280.81 + if((i / 2) == 1)
280.82 + buff.subbuffer(5);
280.83 + if((i / 2) == 2)
280.84 + buff.subbuffer(5,500);
280.85 + if((i / 2) == 3)
280.86 + buff.subbuffer(5,600,true);
280.87 +
280.88 + long capacity = buff.capacity();
280.89 + InputStream is = buff.getInputStream();
280.90 + try
280.91 + {
280.92 + int ret = is.available();
280.93 + long n = is.skip(75);
280.94 + if(n == -1)
280.95 + throw new RuntimeException("is.read shouldn't return -1!");
280.96 + if(is.available() != ret - n)
280.97 + throw new RuntimeException(
280.98 + "is.available() returns incorrect value ("
280.99 + + is.available() + "!="+(ret - n)+") !");
280.100 +
280.101 + ret = is.available();
280.102 + n = is.skip(-100);
280.103 + if(n != 0)
280.104 + throw new RuntimeException("is.skip(-100) shouldn't skip values!");
280.105 + if(is.available() != ret - n)
280.106 + throw new RuntimeException(
280.107 + "is.available() returns incorrect value ("
280.108 + + is.available() + "!="+(ret - n)+") !");
280.109 +
280.110 + ret = is.available();
280.111 + n = is.skip(5000);
280.112 + if(is.available() != ret - n)
280.113 + throw new RuntimeException(
280.114 + "is.available() returns incorrect value ("
280.115 + + is.available() + "!="+(ret - n)+") !");
280.116 + if(is.available() != 0)
280.117 + throw new RuntimeException(
280.118 + "is.available() returns incorrect value ("
280.119 + + is.available() + "!="+(0)+") !"); }
280.120 + finally
280.121 + {
280.122 + is.close();
280.123 + }
280.124 + if(buff.capacity() != capacity)
280.125 + throw new RuntimeException("Capacity variable should not change!");
280.126 + }
280.127 + }
280.128 + finally
280.129 + {
280.130 + tearDown();
280.131 + }
280.132 + }
280.133 +
280.134 +}
281.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
281.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBuffer/SubbufferLong.java Tue Feb 03 22:02:55 2009 -0800
281.3 @@ -0,0 +1,92 @@
281.4 +/*
281.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
281.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
281.7 + *
281.8 + * This code is free software; you can redistribute it and/or modify it
281.9 + * under the terms of the GNU General Public License version 2 only, as
281.10 + * published by the Free Software Foundation. Sun designates this
281.11 + * particular file as subject to the "Classpath" exception as provided
281.12 + * by Sun in the LICENSE file that accompanied this code.
281.13 + *
281.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
281.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
281.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
281.17 + * version 2 for more details (a copy is included in the LICENSE file that
281.18 + * accompanied this code).
281.19 + *
281.20 + * You should have received a copy of the GNU General Public License version
281.21 + * 2 along with this work; if not, write to the Free Software Foundation,
281.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
281.23 + *
281.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
281.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
281.26 + * have any questions.
281.27 + */
281.28 +
281.29 +/* @test
281.30 + @summary Test ModelByteBuffer subbuffer(long) method */
281.31 +
281.32 +import java.io.File;
281.33 +import java.io.FileOutputStream;
281.34 +
281.35 +import javax.sound.sampled.*;
281.36 +
281.37 +import com.sun.media.sound.*;
281.38 +
281.39 +public class SubbufferLong {
281.40 +
281.41 + static float[] testarray;
281.42 + static byte[] test_byte_array;
281.43 + static File test_file;
281.44 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
281.45 +
281.46 + static void setUp() throws Exception {
281.47 + testarray = new float[1024];
281.48 + for (int i = 0; i < 1024; i++) {
281.49 + double ii = i / 1024.0;
281.50 + ii = ii * ii;
281.51 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
281.52 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
281.53 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
281.54 + testarray[i] *= 0.3;
281.55 + }
281.56 + test_byte_array = new byte[testarray.length*2];
281.57 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
281.58 + test_file = File.createTempFile("test", ".raw");
281.59 + FileOutputStream fos = new FileOutputStream(test_file);
281.60 + fos.write(test_byte_array);
281.61 + }
281.62 +
281.63 + static void tearDown() throws Exception {
281.64 + if(!test_file.delete())
281.65 + test_file.deleteOnExit();
281.66 + }
281.67 +
281.68 + public static void main(String[] args) throws Exception {
281.69 + try
281.70 + {
281.71 + setUp();
281.72 +
281.73 + for (int i = 0; i < 2; i++) {
281.74 + ModelByteBuffer buff;
281.75 + if(i == 0)
281.76 + buff = new ModelByteBuffer(test_file);
281.77 + else
281.78 + buff = new ModelByteBuffer(test_byte_array);
281.79 +
281.80 + ModelByteBuffer buff2 = buff.subbuffer(10);
281.81 + if(buff2.getFilePointer() != buff.getFilePointer())
281.82 + throw new RuntimeException("buff2.getFilePointer() incorreect!");
281.83 + if(buff2.arrayOffset() != 10)
281.84 + throw new RuntimeException("buff2.arrayOffset() not 10!");
281.85 + if(buff2.capacity() != buff.capacity()-10)
281.86 + throw new RuntimeException("buff2.capacity() not correct!");
281.87 + }
281.88 + }
281.89 + finally
281.90 + {
281.91 + tearDown();
281.92 + }
281.93 + }
281.94 +
281.95 +}
282.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
282.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBuffer/SubbufferLongLong.java Tue Feb 03 22:02:55 2009 -0800
282.3 @@ -0,0 +1,92 @@
282.4 +/*
282.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
282.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
282.7 + *
282.8 + * This code is free software; you can redistribute it and/or modify it
282.9 + * under the terms of the GNU General Public License version 2 only, as
282.10 + * published by the Free Software Foundation. Sun designates this
282.11 + * particular file as subject to the "Classpath" exception as provided
282.12 + * by Sun in the LICENSE file that accompanied this code.
282.13 + *
282.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
282.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
282.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
282.17 + * version 2 for more details (a copy is included in the LICENSE file that
282.18 + * accompanied this code).
282.19 + *
282.20 + * You should have received a copy of the GNU General Public License version
282.21 + * 2 along with this work; if not, write to the Free Software Foundation,
282.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
282.23 + *
282.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
282.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
282.26 + * have any questions.
282.27 + */
282.28 +
282.29 +/* @test
282.30 + @summary Test ModelByteBuffer subbuffer(long,long) method */
282.31 +
282.32 +import java.io.File;
282.33 +import java.io.FileOutputStream;
282.34 +
282.35 +import javax.sound.sampled.*;
282.36 +
282.37 +import com.sun.media.sound.*;
282.38 +
282.39 +public class SubbufferLongLong {
282.40 +
282.41 + static float[] testarray;
282.42 + static byte[] test_byte_array;
282.43 + static File test_file;
282.44 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
282.45 +
282.46 + static void setUp() throws Exception {
282.47 + testarray = new float[1024];
282.48 + for (int i = 0; i < 1024; i++) {
282.49 + double ii = i / 1024.0;
282.50 + ii = ii * ii;
282.51 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
282.52 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
282.53 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
282.54 + testarray[i] *= 0.3;
282.55 + }
282.56 + test_byte_array = new byte[testarray.length*2];
282.57 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
282.58 + test_file = File.createTempFile("test", ".raw");
282.59 + FileOutputStream fos = new FileOutputStream(test_file);
282.60 + fos.write(test_byte_array);
282.61 + }
282.62 +
282.63 + static void tearDown() throws Exception {
282.64 + if(!test_file.delete())
282.65 + test_file.deleteOnExit();
282.66 + }
282.67 +
282.68 + public static void main(String[] args) throws Exception {
282.69 + try
282.70 + {
282.71 + setUp();
282.72 +
282.73 + for (int i = 0; i < 2; i++) {
282.74 + ModelByteBuffer buff;
282.75 + if(i == 0)
282.76 + buff = new ModelByteBuffer(test_file);
282.77 + else
282.78 + buff = new ModelByteBuffer(test_byte_array);
282.79 +
282.80 + ModelByteBuffer buff2 = buff.subbuffer(10,21);
282.81 + if(buff2.getFilePointer() != buff.getFilePointer())
282.82 + throw new RuntimeException("buff2.getFilePointer() incorrect!");
282.83 + if(buff2.arrayOffset() != 10)
282.84 + throw new RuntimeException("buff2.arrayOffset() not 10!");
282.85 + if(buff2.capacity() != 11)
282.86 + throw new RuntimeException("buff2.capacity() not 11!");
282.87 + }
282.88 + }
282.89 + finally
282.90 + {
282.91 + tearDown();
282.92 + }
282.93 + }
282.94 +
282.95 +}
283.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
283.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBuffer/SubbufferLongLongBoolean.java Tue Feb 03 22:02:55 2009 -0800
283.3 @@ -0,0 +1,98 @@
283.4 +/*
283.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
283.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
283.7 + *
283.8 + * This code is free software; you can redistribute it and/or modify it
283.9 + * under the terms of the GNU General Public License version 2 only, as
283.10 + * published by the Free Software Foundation. Sun designates this
283.11 + * particular file as subject to the "Classpath" exception as provided
283.12 + * by Sun in the LICENSE file that accompanied this code.
283.13 + *
283.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
283.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
283.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
283.17 + * version 2 for more details (a copy is included in the LICENSE file that
283.18 + * accompanied this code).
283.19 + *
283.20 + * You should have received a copy of the GNU General Public License version
283.21 + * 2 along with this work; if not, write to the Free Software Foundation,
283.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
283.23 + *
283.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
283.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
283.26 + * have any questions.
283.27 + */
283.28 +
283.29 +/* @test
283.30 + @summary Test ModelByteBuffer subbuffer(long,long,boolean) method */
283.31 +
283.32 +import java.io.File;
283.33 +import java.io.FileOutputStream;
283.34 +
283.35 +import javax.sound.sampled.*;
283.36 +
283.37 +import com.sun.media.sound.*;
283.38 +
283.39 +public class SubbufferLongLongBoolean {
283.40 +
283.41 + static float[] testarray;
283.42 + static byte[] test_byte_array;
283.43 + static File test_file;
283.44 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
283.45 +
283.46 + static void setUp() throws Exception {
283.47 + testarray = new float[1024];
283.48 + for (int i = 0; i < 1024; i++) {
283.49 + double ii = i / 1024.0;
283.50 + ii = ii * ii;
283.51 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
283.52 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
283.53 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
283.54 + testarray[i] *= 0.3;
283.55 + }
283.56 + test_byte_array = new byte[testarray.length*2];
283.57 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
283.58 + test_file = File.createTempFile("test", ".raw");
283.59 + FileOutputStream fos = new FileOutputStream(test_file);
283.60 + fos.write(test_byte_array);
283.61 + }
283.62 +
283.63 + static void tearDown() throws Exception {
283.64 + if(!test_file.delete())
283.65 + test_file.deleteOnExit();
283.66 + }
283.67 +
283.68 + public static void main(String[] args) throws Exception {
283.69 + try
283.70 + {
283.71 + setUp();
283.72 +
283.73 + for (int i = 0; i < 2; i++) {
283.74 + ModelByteBuffer buff;
283.75 + if(i == 0)
283.76 + buff = new ModelByteBuffer(test_file);
283.77 + else
283.78 + buff = new ModelByteBuffer(test_byte_array);
283.79 +
283.80 + ModelByteBuffer buff2 = buff.subbuffer(10,21,true);
283.81 + if(buff2.getRoot() != buff2);
283.82 + if(buff2.capacity() != 11);
283.83 + if(i == 0)
283.84 + {
283.85 + if(buff2.getFilePointer() != buff.getFilePointer()+10)
283.86 + throw new RuntimeException("buff2.getFilePointer() incorrect!");
283.87 + }
283.88 + else
283.89 + {
283.90 + if(buff2.arrayOffset() != 10)
283.91 + throw new RuntimeException("buff2.arrayOffset() not 10!");
283.92 + }
283.93 + }
283.94 + }
283.95 + finally
283.96 + {
283.97 + tearDown();
283.98 + }
283.99 + }
283.100 +
283.101 +}
284.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
284.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBuffer/Unload.java Tue Feb 03 22:02:55 2009 -0800
284.3 @@ -0,0 +1,83 @@
284.4 +/*
284.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
284.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
284.7 + *
284.8 + * This code is free software; you can redistribute it and/or modify it
284.9 + * under the terms of the GNU General Public License version 2 only, as
284.10 + * published by the Free Software Foundation. Sun designates this
284.11 + * particular file as subject to the "Classpath" exception as provided
284.12 + * by Sun in the LICENSE file that accompanied this code.
284.13 + *
284.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
284.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
284.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
284.17 + * version 2 for more details (a copy is included in the LICENSE file that
284.18 + * accompanied this code).
284.19 + *
284.20 + * You should have received a copy of the GNU General Public License version
284.21 + * 2 along with this work; if not, write to the Free Software Foundation,
284.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
284.23 + *
284.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
284.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
284.26 + * have any questions.
284.27 + */
284.28 +
284.29 +/* @test
284.30 + @summary Test ModelByteBuffer unload method */
284.31 +
284.32 +import java.io.File;
284.33 +import java.io.FileOutputStream;
284.34 +import java.io.IOException;
284.35 +
284.36 +import javax.sound.sampled.*;
284.37 +
284.38 +import com.sun.media.sound.*;
284.39 +
284.40 +public class Unload {
284.41 +
284.42 + static float[] testarray;
284.43 + static byte[] test_byte_array;
284.44 + static File test_file;
284.45 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
284.46 +
284.47 + static void setUp() throws Exception {
284.48 + testarray = new float[1024];
284.49 + for (int i = 0; i < 1024; i++) {
284.50 + double ii = i / 1024.0;
284.51 + ii = ii * ii;
284.52 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
284.53 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
284.54 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
284.55 + testarray[i] *= 0.3;
284.56 + }
284.57 + test_byte_array = new byte[testarray.length*2];
284.58 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
284.59 + test_file = File.createTempFile("test", ".raw");
284.60 + FileOutputStream fos = new FileOutputStream(test_file);
284.61 + fos.write(test_byte_array);
284.62 + }
284.63 +
284.64 + static void tearDown() throws Exception {
284.65 + if(!test_file.delete())
284.66 + test_file.deleteOnExit();
284.67 + }
284.68 +
284.69 + public static void main(String[] args) throws Exception {
284.70 + try
284.71 + {
284.72 + setUp();
284.73 +
284.74 + ModelByteBuffer buff = new ModelByteBuffer(test_file);
284.75 + buff.load();
284.76 + buff.unload();
284.77 + if(buff.array() != null)
284.78 + throw new RuntimeException("buff.array() not null!");
284.79 + }
284.80 + finally
284.81 + {
284.82 + tearDown();
284.83 + }
284.84 + }
284.85 +
284.86 +}
285.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
285.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBuffer/WriteTo.java Tue Feb 03 22:02:55 2009 -0800
285.3 @@ -0,0 +1,92 @@
285.4 +/*
285.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
285.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
285.7 + *
285.8 + * This code is free software; you can redistribute it and/or modify it
285.9 + * under the terms of the GNU General Public License version 2 only, as
285.10 + * published by the Free Software Foundation. Sun designates this
285.11 + * particular file as subject to the "Classpath" exception as provided
285.12 + * by Sun in the LICENSE file that accompanied this code.
285.13 + *
285.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
285.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
285.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
285.17 + * version 2 for more details (a copy is included in the LICENSE file that
285.18 + * accompanied this code).
285.19 + *
285.20 + * You should have received a copy of the GNU General Public License version
285.21 + * 2 along with this work; if not, write to the Free Software Foundation,
285.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
285.23 + *
285.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
285.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
285.26 + * have any questions.
285.27 + */
285.28 +
285.29 +/* @test
285.30 + @summary Test ModelByteBuffer writeTo method */
285.31 +
285.32 +import java.io.ByteArrayOutputStream;
285.33 +import java.io.File;
285.34 +import java.io.FileOutputStream;
285.35 +import java.io.IOException;
285.36 +
285.37 +import javax.sound.sampled.*;
285.38 +
285.39 +import com.sun.media.sound.*;
285.40 +
285.41 +public class WriteTo {
285.42 +
285.43 + static float[] testarray;
285.44 + static byte[] test_byte_array;
285.45 + static File test_file;
285.46 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
285.47 +
285.48 + static void setUp() throws Exception {
285.49 + testarray = new float[1024];
285.50 + for (int i = 0; i < 1024; i++) {
285.51 + double ii = i / 1024.0;
285.52 + ii = ii * ii;
285.53 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
285.54 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
285.55 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
285.56 + testarray[i] *= 0.3;
285.57 + }
285.58 + test_byte_array = new byte[testarray.length*2];
285.59 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
285.60 + test_file = File.createTempFile("test", ".raw");
285.61 + FileOutputStream fos = new FileOutputStream(test_file);
285.62 + fos.write(test_byte_array);
285.63 + }
285.64 +
285.65 + static void tearDown() throws Exception {
285.66 + if(!test_file.delete())
285.67 + test_file.deleteOnExit();
285.68 + }
285.69 +
285.70 + public static void main(String[] args) throws Exception {
285.71 + try
285.72 + {
285.73 + setUp();
285.74 +
285.75 + for (int i = 0; i < 2; i++) {
285.76 + ModelByteBuffer buff;
285.77 + ByteArrayOutputStream baos = new ByteArrayOutputStream();
285.78 + if(i == 0)
285.79 + buff = new ModelByteBuffer(test_file);
285.80 + else
285.81 + buff = new ModelByteBuffer(test_byte_array);
285.82 + buff.writeTo(baos);
285.83 + byte[] b = baos.toByteArray();
285.84 + for (int j = 0; j < b.length; j++)
285.85 + if(b[i] != test_byte_array[i])
285.86 + throw new RuntimeException("baos.toByteArray() incorrect!");
285.87 + }
285.88 + }
285.89 + finally
285.90 + {
285.91 + tearDown();
285.92 + }
285.93 + }
285.94 +
285.95 +}
286.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
286.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBufferWavetable/GetAttenuation.java Tue Feb 03 22:02:55 2009 -0800
286.3 @@ -0,0 +1,97 @@
286.4 +/*
286.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
286.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
286.7 + *
286.8 + * This code is free software; you can redistribute it and/or modify it
286.9 + * under the terms of the GNU General Public License version 2 only, as
286.10 + * published by the Free Software Foundation. Sun designates this
286.11 + * particular file as subject to the "Classpath" exception as provided
286.12 + * by Sun in the LICENSE file that accompanied this code.
286.13 + *
286.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
286.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
286.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
286.17 + * version 2 for more details (a copy is included in the LICENSE file that
286.18 + * accompanied this code).
286.19 + *
286.20 + * You should have received a copy of the GNU General Public License version
286.21 + * 2 along with this work; if not, write to the Free Software Foundation,
286.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
286.23 + *
286.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
286.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
286.26 + * have any questions.
286.27 + */
286.28 +
286.29 +/* @test
286.30 + @summary Test ModelByteBufferWavetable getAttenuation method */
286.31 +
286.32 +import java.io.ByteArrayOutputStream;
286.33 +
286.34 +import javax.sound.sampled.*;
286.35 +
286.36 +import com.sun.media.sound.*;
286.37 +
286.38 +public class GetAttenuation {
286.39 +
286.40 + static float[] testarray;
286.41 + static byte[] test_byte_array;
286.42 + static byte[] test_byte_array_8ext;
286.43 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
286.44 + static AudioFormat format24 = new AudioFormat(44100, 24, 1, true, false);
286.45 + static ModelByteBuffer buffer;
286.46 + static ModelByteBuffer buffer_wave;
286.47 + static ModelByteBuffer buffer8;
286.48 + static ModelByteBuffer buffer16_8;
286.49 + static ModelByteBuffer buffer24;
286.50 +
286.51 + static void setUp() throws Exception {
286.52 + testarray = new float[1024];
286.53 + for (int i = 0; i < 1024; i++) {
286.54 + double ii = i / 1024.0;
286.55 + ii = ii * ii;
286.56 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
286.57 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
286.58 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
286.59 + testarray[i] *= 0.3;
286.60 + }
286.61 + test_byte_array = new byte[testarray.length*2];
286.62 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
286.63 + buffer = new ModelByteBuffer(test_byte_array);
286.64 +
286.65 + byte[] test_byte_array2 = new byte[testarray.length*3];
286.66 + buffer24 = new ModelByteBuffer(test_byte_array2);
286.67 + test_byte_array_8ext = new byte[testarray.length];
286.68 + byte[] test_byte_array_8_16 = new byte[testarray.length*2];
286.69 + AudioFloatConverter.getConverter(format24).toByteArray(testarray, test_byte_array2);
286.70 + int ix = 0;
286.71 + int x = 0;
286.72 + for (int i = 0; i < test_byte_array_8ext.length; i++) {
286.73 + test_byte_array_8ext[i] = test_byte_array2[ix++];
286.74 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
286.75 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
286.76 + }
286.77 + buffer16_8 = new ModelByteBuffer(test_byte_array_8_16);
286.78 + buffer8 = new ModelByteBuffer(test_byte_array_8ext);
286.79 +
286.80 + AudioInputStream ais = new AudioInputStream(buffer.getInputStream(), format, testarray.length);
286.81 + ByteArrayOutputStream baos = new ByteArrayOutputStream();
286.82 + AudioSystem.write(ais, AudioFileFormat.Type.WAVE, baos);
286.83 + buffer_wave = new ModelByteBuffer(baos.toByteArray());
286.84 + }
286.85 +
286.86 + public static void main(String[] args) throws Exception {
286.87 +
286.88 + setUp();
286.89 +
286.90 + ModelByteBufferWavetable wavetable = new ModelByteBufferWavetable(buffer,format);
286.91 + wavetable.setAttenuation(10f);
286.92 + if(wavetable.getAttenuation() != 10f)
286.93 + throw new RuntimeException("wavetable.getAttenuation() not 10!");
286.94 + wavetable.setAttenuation(20f);
286.95 + if(wavetable.getAttenuation() != 20f)
286.96 + throw new RuntimeException("wavetable.getAttenuation() not 20!");
286.97 +
286.98 + }
286.99 +
286.100 +}
287.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
287.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBufferWavetable/GetChannels.java Tue Feb 03 22:02:55 2009 -0800
287.3 @@ -0,0 +1,97 @@
287.4 +/*
287.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
287.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
287.7 + *
287.8 + * This code is free software; you can redistribute it and/or modify it
287.9 + * under the terms of the GNU General Public License version 2 only, as
287.10 + * published by the Free Software Foundation. Sun designates this
287.11 + * particular file as subject to the "Classpath" exception as provided
287.12 + * by Sun in the LICENSE file that accompanied this code.
287.13 + *
287.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
287.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
287.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
287.17 + * version 2 for more details (a copy is included in the LICENSE file that
287.18 + * accompanied this code).
287.19 + *
287.20 + * You should have received a copy of the GNU General Public License version
287.21 + * 2 along with this work; if not, write to the Free Software Foundation,
287.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
287.23 + *
287.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
287.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
287.26 + * have any questions.
287.27 + */
287.28 +
287.29 +/* @test
287.30 + @summary Test ModelByteBufferWavetable getChannels method */
287.31 +
287.32 +import java.io.ByteArrayOutputStream;
287.33 +
287.34 +import javax.sound.sampled.*;
287.35 +
287.36 +import com.sun.media.sound.*;
287.37 +
287.38 +public class GetChannels {
287.39 +
287.40 + static float[] testarray;
287.41 + static byte[] test_byte_array;
287.42 + static byte[] test_byte_array_8ext;
287.43 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
287.44 + static AudioFormat format24 = new AudioFormat(44100, 24, 1, true, false);
287.45 + static ModelByteBuffer buffer;
287.46 + static ModelByteBuffer buffer_wave;
287.47 + static ModelByteBuffer buffer8;
287.48 + static ModelByteBuffer buffer16_8;
287.49 + static ModelByteBuffer buffer24;
287.50 +
287.51 + static void setUp() throws Exception {
287.52 + testarray = new float[1024];
287.53 + for (int i = 0; i < 1024; i++) {
287.54 + double ii = i / 1024.0;
287.55 + ii = ii * ii;
287.56 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
287.57 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
287.58 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
287.59 + testarray[i] *= 0.3;
287.60 + }
287.61 + test_byte_array = new byte[testarray.length*2];
287.62 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
287.63 + buffer = new ModelByteBuffer(test_byte_array);
287.64 +
287.65 + byte[] test_byte_array2 = new byte[testarray.length*3];
287.66 + buffer24 = new ModelByteBuffer(test_byte_array2);
287.67 + test_byte_array_8ext = new byte[testarray.length];
287.68 + byte[] test_byte_array_8_16 = new byte[testarray.length*2];
287.69 + AudioFloatConverter.getConverter(format24).toByteArray(testarray, test_byte_array2);
287.70 + int ix = 0;
287.71 + int x = 0;
287.72 + for (int i = 0; i < test_byte_array_8ext.length; i++) {
287.73 + test_byte_array_8ext[i] = test_byte_array2[ix++];
287.74 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
287.75 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
287.76 + }
287.77 + buffer16_8 = new ModelByteBuffer(test_byte_array_8_16);
287.78 + buffer8 = new ModelByteBuffer(test_byte_array_8ext);
287.79 +
287.80 + AudioInputStream ais = new AudioInputStream(buffer.getInputStream(), format, testarray.length);
287.81 + ByteArrayOutputStream baos = new ByteArrayOutputStream();
287.82 + AudioSystem.write(ais, AudioFileFormat.Type.WAVE, baos);
287.83 + buffer_wave = new ModelByteBuffer(baos.toByteArray());
287.84 + }
287.85 +
287.86 + public static void main(String[] args) throws Exception {
287.87 +
287.88 + setUp();
287.89 +
287.90 + AudioFormat format1 = new AudioFormat(44100, 16, 1, true, false);
287.91 + AudioFormat format2 = new AudioFormat(44100, 16, 2, true, false);
287.92 + ModelByteBufferWavetable wavetable = new ModelByteBufferWavetable(buffer,format1,10f);
287.93 + if(wavetable.getChannels() != 1)
287.94 + throw new RuntimeException("wavetable.getChannels() not 1!");
287.95 + wavetable = new ModelByteBufferWavetable(buffer,format2,10f);
287.96 + if(wavetable.getChannels() != 2)
287.97 + throw new RuntimeException("wavetable.getChannels() not 2!");
287.98 + }
287.99 +
287.100 +}
288.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
288.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBufferWavetable/GetLoopLength.java Tue Feb 03 22:02:55 2009 -0800
288.3 @@ -0,0 +1,96 @@
288.4 +/*
288.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
288.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
288.7 + *
288.8 + * This code is free software; you can redistribute it and/or modify it
288.9 + * under the terms of the GNU General Public License version 2 only, as
288.10 + * published by the Free Software Foundation. Sun designates this
288.11 + * particular file as subject to the "Classpath" exception as provided
288.12 + * by Sun in the LICENSE file that accompanied this code.
288.13 + *
288.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
288.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
288.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
288.17 + * version 2 for more details (a copy is included in the LICENSE file that
288.18 + * accompanied this code).
288.19 + *
288.20 + * You should have received a copy of the GNU General Public License version
288.21 + * 2 along with this work; if not, write to the Free Software Foundation,
288.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
288.23 + *
288.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
288.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
288.26 + * have any questions.
288.27 + */
288.28 +
288.29 +/* @test
288.30 + @summary Test ModelByteBufferWavetable getLoopLength method */
288.31 +
288.32 +import java.io.ByteArrayOutputStream;
288.33 +
288.34 +import javax.sound.sampled.*;
288.35 +
288.36 +import com.sun.media.sound.*;
288.37 +
288.38 +public class GetLoopLength {
288.39 +
288.40 + static float[] testarray;
288.41 + static byte[] test_byte_array;
288.42 + static byte[] test_byte_array_8ext;
288.43 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
288.44 + static AudioFormat format24 = new AudioFormat(44100, 24, 1, true, false);
288.45 + static ModelByteBuffer buffer;
288.46 + static ModelByteBuffer buffer_wave;
288.47 + static ModelByteBuffer buffer8;
288.48 + static ModelByteBuffer buffer16_8;
288.49 + static ModelByteBuffer buffer24;
288.50 +
288.51 + static void setUp() throws Exception {
288.52 + testarray = new float[1024];
288.53 + for (int i = 0; i < 1024; i++) {
288.54 + double ii = i / 1024.0;
288.55 + ii = ii * ii;
288.56 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
288.57 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
288.58 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
288.59 + testarray[i] *= 0.3;
288.60 + }
288.61 + test_byte_array = new byte[testarray.length*2];
288.62 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
288.63 + buffer = new ModelByteBuffer(test_byte_array);
288.64 +
288.65 + byte[] test_byte_array2 = new byte[testarray.length*3];
288.66 + buffer24 = new ModelByteBuffer(test_byte_array2);
288.67 + test_byte_array_8ext = new byte[testarray.length];
288.68 + byte[] test_byte_array_8_16 = new byte[testarray.length*2];
288.69 + AudioFloatConverter.getConverter(format24).toByteArray(testarray, test_byte_array2);
288.70 + int ix = 0;
288.71 + int x = 0;
288.72 + for (int i = 0; i < test_byte_array_8ext.length; i++) {
288.73 + test_byte_array_8ext[i] = test_byte_array2[ix++];
288.74 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
288.75 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
288.76 + }
288.77 + buffer16_8 = new ModelByteBuffer(test_byte_array_8_16);
288.78 + buffer8 = new ModelByteBuffer(test_byte_array_8ext);
288.79 +
288.80 + AudioInputStream ais = new AudioInputStream(buffer.getInputStream(), format, testarray.length);
288.81 + ByteArrayOutputStream baos = new ByteArrayOutputStream();
288.82 + AudioSystem.write(ais, AudioFileFormat.Type.WAVE, baos);
288.83 + buffer_wave = new ModelByteBuffer(baos.toByteArray());
288.84 + }
288.85 +
288.86 + public static void main(String[] args) throws Exception {
288.87 +
288.88 + setUp();
288.89 +
288.90 + ModelByteBufferWavetable wavetable = new ModelByteBufferWavetable(buffer,format);
288.91 + wavetable.setLoopLength(10f);
288.92 + if(wavetable.getLoopLength() != 10f)
288.93 + throw new RuntimeException("wavetable.getLoopLength() not 10!");
288.94 + wavetable.setLoopLength(20f);
288.95 + if(wavetable.getLoopLength() != 20f)
288.96 + throw new RuntimeException("wavetable.getLoopLength() not 20!");
288.97 + }
288.98 +
288.99 +}
289.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
289.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBufferWavetable/GetLoopStart.java Tue Feb 03 22:02:55 2009 -0800
289.3 @@ -0,0 +1,96 @@
289.4 +/*
289.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
289.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
289.7 + *
289.8 + * This code is free software; you can redistribute it and/or modify it
289.9 + * under the terms of the GNU General Public License version 2 only, as
289.10 + * published by the Free Software Foundation. Sun designates this
289.11 + * particular file as subject to the "Classpath" exception as provided
289.12 + * by Sun in the LICENSE file that accompanied this code.
289.13 + *
289.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
289.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
289.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
289.17 + * version 2 for more details (a copy is included in the LICENSE file that
289.18 + * accompanied this code).
289.19 + *
289.20 + * You should have received a copy of the GNU General Public License version
289.21 + * 2 along with this work; if not, write to the Free Software Foundation,
289.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
289.23 + *
289.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
289.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
289.26 + * have any questions.
289.27 + */
289.28 +
289.29 +/* @test
289.30 + @summary Test ModelByteBufferWavetable getLoopStart method */
289.31 +
289.32 +import java.io.ByteArrayOutputStream;
289.33 +
289.34 +import javax.sound.sampled.*;
289.35 +
289.36 +import com.sun.media.sound.*;
289.37 +
289.38 +public class GetLoopStart {
289.39 +
289.40 + static float[] testarray;
289.41 + static byte[] test_byte_array;
289.42 + static byte[] test_byte_array_8ext;
289.43 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
289.44 + static AudioFormat format24 = new AudioFormat(44100, 24, 1, true, false);
289.45 + static ModelByteBuffer buffer;
289.46 + static ModelByteBuffer buffer_wave;
289.47 + static ModelByteBuffer buffer8;
289.48 + static ModelByteBuffer buffer16_8;
289.49 + static ModelByteBuffer buffer24;
289.50 +
289.51 + static void setUp() throws Exception {
289.52 + testarray = new float[1024];
289.53 + for (int i = 0; i < 1024; i++) {
289.54 + double ii = i / 1024.0;
289.55 + ii = ii * ii;
289.56 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
289.57 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
289.58 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
289.59 + testarray[i] *= 0.3;
289.60 + }
289.61 + test_byte_array = new byte[testarray.length*2];
289.62 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
289.63 + buffer = new ModelByteBuffer(test_byte_array);
289.64 +
289.65 + byte[] test_byte_array2 = new byte[testarray.length*3];
289.66 + buffer24 = new ModelByteBuffer(test_byte_array2);
289.67 + test_byte_array_8ext = new byte[testarray.length];
289.68 + byte[] test_byte_array_8_16 = new byte[testarray.length*2];
289.69 + AudioFloatConverter.getConverter(format24).toByteArray(testarray, test_byte_array2);
289.70 + int ix = 0;
289.71 + int x = 0;
289.72 + for (int i = 0; i < test_byte_array_8ext.length; i++) {
289.73 + test_byte_array_8ext[i] = test_byte_array2[ix++];
289.74 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
289.75 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
289.76 + }
289.77 + buffer16_8 = new ModelByteBuffer(test_byte_array_8_16);
289.78 + buffer8 = new ModelByteBuffer(test_byte_array_8ext);
289.79 +
289.80 + AudioInputStream ais = new AudioInputStream(buffer.getInputStream(), format, testarray.length);
289.81 + ByteArrayOutputStream baos = new ByteArrayOutputStream();
289.82 + AudioSystem.write(ais, AudioFileFormat.Type.WAVE, baos);
289.83 + buffer_wave = new ModelByteBuffer(baos.toByteArray());
289.84 + }
289.85 +
289.86 + public static void main(String[] args) throws Exception {
289.87 +
289.88 + setUp();
289.89 +
289.90 + ModelByteBufferWavetable wavetable = new ModelByteBufferWavetable(buffer,format);
289.91 + wavetable.setLoopStart(10f);
289.92 + if(wavetable.getLoopStart() != 10f)
289.93 + throw new RuntimeException("wavetable.getLoopStart() not 10!");
289.94 + wavetable.setLoopStart(20f);
289.95 + if(wavetable.getLoopStart() != 20f)
289.96 + throw new RuntimeException("wavetable.getLoopStart() not 20!");
289.97 + }
289.98 +
289.99 +}
290.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
290.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBufferWavetable/GetPitchCorrection.java Tue Feb 03 22:02:55 2009 -0800
290.3 @@ -0,0 +1,97 @@
290.4 +/*
290.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
290.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
290.7 + *
290.8 + * This code is free software; you can redistribute it and/or modify it
290.9 + * under the terms of the GNU General Public License version 2 only, as
290.10 + * published by the Free Software Foundation. Sun designates this
290.11 + * particular file as subject to the "Classpath" exception as provided
290.12 + * by Sun in the LICENSE file that accompanied this code.
290.13 + *
290.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
290.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
290.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
290.17 + * version 2 for more details (a copy is included in the LICENSE file that
290.18 + * accompanied this code).
290.19 + *
290.20 + * You should have received a copy of the GNU General Public License version
290.21 + * 2 along with this work; if not, write to the Free Software Foundation,
290.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
290.23 + *
290.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
290.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
290.26 + * have any questions.
290.27 + */
290.28 +
290.29 +/* @test
290.30 + @summary Test ModelByteBufferWavetable getPitchCorrect method */
290.31 +
290.32 +import java.io.ByteArrayOutputStream;
290.33 +
290.34 +import javax.sound.sampled.*;
290.35 +
290.36 +import com.sun.media.sound.*;
290.37 +
290.38 +public class GetPitchCorrection {
290.39 +
290.40 + static float[] testarray;
290.41 + static byte[] test_byte_array;
290.42 + static byte[] test_byte_array_8ext;
290.43 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
290.44 + static AudioFormat format24 = new AudioFormat(44100, 24, 1, true, false);
290.45 + static ModelByteBuffer buffer;
290.46 + static ModelByteBuffer buffer_wave;
290.47 + static ModelByteBuffer buffer8;
290.48 + static ModelByteBuffer buffer16_8;
290.49 + static ModelByteBuffer buffer24;
290.50 +
290.51 + static void setUp() throws Exception {
290.52 + testarray = new float[1024];
290.53 + for (int i = 0; i < 1024; i++) {
290.54 + double ii = i / 1024.0;
290.55 + ii = ii * ii;
290.56 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
290.57 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
290.58 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
290.59 + testarray[i] *= 0.3;
290.60 + }
290.61 + test_byte_array = new byte[testarray.length*2];
290.62 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
290.63 + buffer = new ModelByteBuffer(test_byte_array);
290.64 +
290.65 + byte[] test_byte_array2 = new byte[testarray.length*3];
290.66 + buffer24 = new ModelByteBuffer(test_byte_array2);
290.67 + test_byte_array_8ext = new byte[testarray.length];
290.68 + byte[] test_byte_array_8_16 = new byte[testarray.length*2];
290.69 + AudioFloatConverter.getConverter(format24).toByteArray(testarray, test_byte_array2);
290.70 + int ix = 0;
290.71 + int x = 0;
290.72 + for (int i = 0; i < test_byte_array_8ext.length; i++) {
290.73 + test_byte_array_8ext[i] = test_byte_array2[ix++];
290.74 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
290.75 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
290.76 + }
290.77 + buffer16_8 = new ModelByteBuffer(test_byte_array_8_16);
290.78 + buffer8 = new ModelByteBuffer(test_byte_array_8ext);
290.79 +
290.80 + AudioInputStream ais = new AudioInputStream(buffer.getInputStream(), format, testarray.length);
290.81 + ByteArrayOutputStream baos = new ByteArrayOutputStream();
290.82 + AudioSystem.write(ais, AudioFileFormat.Type.WAVE, baos);
290.83 + buffer_wave = new ModelByteBuffer(baos.toByteArray());
290.84 + }
290.85 +
290.86 + public static void main(String[] args) throws Exception {
290.87 +
290.88 + setUp();
290.89 +
290.90 + ModelByteBufferWavetable wavetable = new ModelByteBufferWavetable(buffer,format);
290.91 + wavetable.setPitchcorrection(10f);
290.92 + if(wavetable.getPitchcorrection() != 10f)
290.93 + throw new RuntimeException("wavetable.getPitchcorrection() not 10!");
290.94 + wavetable.setPitchcorrection(20f);
290.95 + if(wavetable.getPitchcorrection() != 20f)
290.96 + throw new RuntimeException("wavetable.getPitchcorrection() not 20!");
290.97 +
290.98 + }
290.99 +
290.100 +}
291.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
291.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBufferWavetable/NewModelByteBufferWavetableModelByteBuffer.java Tue Feb 03 22:02:55 2009 -0800
291.3 @@ -0,0 +1,94 @@
291.4 +/*
291.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
291.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
291.7 + *
291.8 + * This code is free software; you can redistribute it and/or modify it
291.9 + * under the terms of the GNU General Public License version 2 only, as
291.10 + * published by the Free Software Foundation. Sun designates this
291.11 + * particular file as subject to the "Classpath" exception as provided
291.12 + * by Sun in the LICENSE file that accompanied this code.
291.13 + *
291.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
291.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
291.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
291.17 + * version 2 for more details (a copy is included in the LICENSE file that
291.18 + * accompanied this code).
291.19 + *
291.20 + * You should have received a copy of the GNU General Public License version
291.21 + * 2 along with this work; if not, write to the Free Software Foundation,
291.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
291.23 + *
291.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
291.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
291.26 + * have any questions.
291.27 + */
291.28 +
291.29 +/* @test
291.30 + @summary Test ModelByteBufferWavetable(ModelByteBuffer) method */
291.31 +
291.32 +import java.io.ByteArrayOutputStream;
291.33 +
291.34 +import javax.sound.sampled.*;
291.35 +
291.36 +import com.sun.media.sound.*;
291.37 +
291.38 +public class NewModelByteBufferWavetableModelByteBuffer {
291.39 +
291.40 + static float[] testarray;
291.41 + static byte[] test_byte_array;
291.42 + static byte[] test_byte_array_8ext;
291.43 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
291.44 + static AudioFormat format24 = new AudioFormat(44100, 24, 1, true, false);
291.45 + static ModelByteBuffer buffer;
291.46 + static ModelByteBuffer buffer_wave;
291.47 + static ModelByteBuffer buffer8;
291.48 + static ModelByteBuffer buffer16_8;
291.49 + static ModelByteBuffer buffer24;
291.50 +
291.51 + static void setUp() throws Exception {
291.52 + testarray = new float[1024];
291.53 + for (int i = 0; i < 1024; i++) {
291.54 + double ii = i / 1024.0;
291.55 + ii = ii * ii;
291.56 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
291.57 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
291.58 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
291.59 + testarray[i] *= 0.3;
291.60 + }
291.61 + test_byte_array = new byte[testarray.length*2];
291.62 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
291.63 + buffer = new ModelByteBuffer(test_byte_array);
291.64 +
291.65 + byte[] test_byte_array2 = new byte[testarray.length*3];
291.66 + buffer24 = new ModelByteBuffer(test_byte_array2);
291.67 + test_byte_array_8ext = new byte[testarray.length];
291.68 + byte[] test_byte_array_8_16 = new byte[testarray.length*2];
291.69 + AudioFloatConverter.getConverter(format24).toByteArray(testarray, test_byte_array2);
291.70 + int ix = 0;
291.71 + int x = 0;
291.72 + for (int i = 0; i < test_byte_array_8ext.length; i++) {
291.73 + test_byte_array_8ext[i] = test_byte_array2[ix++];
291.74 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
291.75 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
291.76 + }
291.77 + buffer16_8 = new ModelByteBuffer(test_byte_array_8_16);
291.78 + buffer8 = new ModelByteBuffer(test_byte_array_8ext);
291.79 +
291.80 + AudioInputStream ais = new AudioInputStream(buffer.getInputStream(), format, testarray.length);
291.81 + ByteArrayOutputStream baos = new ByteArrayOutputStream();
291.82 + AudioSystem.write(ais, AudioFileFormat.Type.WAVE, baos);
291.83 + buffer_wave = new ModelByteBuffer(baos.toByteArray());
291.84 + }
291.85 +
291.86 + public static void main(String[] args) throws Exception {
291.87 +
291.88 + setUp();
291.89 +
291.90 + ModelByteBufferWavetable wavetable = new ModelByteBufferWavetable(buffer_wave);
291.91 + if(wavetable.getBuffer() != buffer_wave)
291.92 + throw new RuntimeException("wavetable.getBuffer() incorrect!");
291.93 + if(!wavetable.getFormat().matches(format))
291.94 + throw new RuntimeException("wavetable.getFormat() incorrect!");
291.95 + }
291.96 +
291.97 +}
292.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
292.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBufferWavetable/NewModelByteBufferWavetableModelByteBufferAudioFormat.java Tue Feb 03 22:02:55 2009 -0800
292.3 @@ -0,0 +1,94 @@
292.4 +/*
292.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
292.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
292.7 + *
292.8 + * This code is free software; you can redistribute it and/or modify it
292.9 + * under the terms of the GNU General Public License version 2 only, as
292.10 + * published by the Free Software Foundation. Sun designates this
292.11 + * particular file as subject to the "Classpath" exception as provided
292.12 + * by Sun in the LICENSE file that accompanied this code.
292.13 + *
292.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
292.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
292.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
292.17 + * version 2 for more details (a copy is included in the LICENSE file that
292.18 + * accompanied this code).
292.19 + *
292.20 + * You should have received a copy of the GNU General Public License version
292.21 + * 2 along with this work; if not, write to the Free Software Foundation,
292.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
292.23 + *
292.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
292.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
292.26 + * have any questions.
292.27 + */
292.28 +
292.29 +/* @test
292.30 + @summary Test ModelByteBufferWavetable(ModelByteBuffer, AudioFormat) method */
292.31 +
292.32 +import java.io.ByteArrayOutputStream;
292.33 +
292.34 +import javax.sound.sampled.*;
292.35 +
292.36 +import com.sun.media.sound.*;
292.37 +
292.38 +public class NewModelByteBufferWavetableModelByteBufferAudioFormat {
292.39 +
292.40 + static float[] testarray;
292.41 + static byte[] test_byte_array;
292.42 + static byte[] test_byte_array_8ext;
292.43 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
292.44 + static AudioFormat format24 = new AudioFormat(44100, 24, 1, true, false);
292.45 + static ModelByteBuffer buffer;
292.46 + static ModelByteBuffer buffer_wave;
292.47 + static ModelByteBuffer buffer8;
292.48 + static ModelByteBuffer buffer16_8;
292.49 + static ModelByteBuffer buffer24;
292.50 +
292.51 + static void setUp() throws Exception {
292.52 + testarray = new float[1024];
292.53 + for (int i = 0; i < 1024; i++) {
292.54 + double ii = i / 1024.0;
292.55 + ii = ii * ii;
292.56 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
292.57 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
292.58 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
292.59 + testarray[i] *= 0.3;
292.60 + }
292.61 + test_byte_array = new byte[testarray.length*2];
292.62 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
292.63 + buffer = new ModelByteBuffer(test_byte_array);
292.64 +
292.65 + byte[] test_byte_array2 = new byte[testarray.length*3];
292.66 + buffer24 = new ModelByteBuffer(test_byte_array2);
292.67 + test_byte_array_8ext = new byte[testarray.length];
292.68 + byte[] test_byte_array_8_16 = new byte[testarray.length*2];
292.69 + AudioFloatConverter.getConverter(format24).toByteArray(testarray, test_byte_array2);
292.70 + int ix = 0;
292.71 + int x = 0;
292.72 + for (int i = 0; i < test_byte_array_8ext.length; i++) {
292.73 + test_byte_array_8ext[i] = test_byte_array2[ix++];
292.74 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
292.75 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
292.76 + }
292.77 + buffer16_8 = new ModelByteBuffer(test_byte_array_8_16);
292.78 + buffer8 = new ModelByteBuffer(test_byte_array_8ext);
292.79 +
292.80 + AudioInputStream ais = new AudioInputStream(buffer.getInputStream(), format, testarray.length);
292.81 + ByteArrayOutputStream baos = new ByteArrayOutputStream();
292.82 + AudioSystem.write(ais, AudioFileFormat.Type.WAVE, baos);
292.83 + buffer_wave = new ModelByteBuffer(baos.toByteArray());
292.84 + }
292.85 +
292.86 + public static void main(String[] args) throws Exception {
292.87 +
292.88 + setUp();
292.89 +
292.90 + ModelByteBufferWavetable wavetable = new ModelByteBufferWavetable(buffer,format);
292.91 + if(wavetable.getBuffer() != buffer)
292.92 + throw new RuntimeException("wavetable.getBuffer() incorrect!");
292.93 + if(wavetable.getFormat() != format)
292.94 + throw new RuntimeException("wavetable.getFormat() incorrect!");
292.95 + }
292.96 +
292.97 +}
293.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
293.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBufferWavetable/NewModelByteBufferWavetableModelByteBufferAudioFormatFloat.java Tue Feb 03 22:02:55 2009 -0800
293.3 @@ -0,0 +1,94 @@
293.4 +/*
293.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
293.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
293.7 + *
293.8 + * This code is free software; you can redistribute it and/or modify it
293.9 + * under the terms of the GNU General Public License version 2 only, as
293.10 + * published by the Free Software Foundation. Sun designates this
293.11 + * particular file as subject to the "Classpath" exception as provided
293.12 + * by Sun in the LICENSE file that accompanied this code.
293.13 + *
293.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
293.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
293.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
293.17 + * version 2 for more details (a copy is included in the LICENSE file that
293.18 + * accompanied this code).
293.19 + *
293.20 + * You should have received a copy of the GNU General Public License version
293.21 + * 2 along with this work; if not, write to the Free Software Foundation,
293.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
293.23 + *
293.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
293.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
293.26 + * have any questions.
293.27 + */
293.28 +
293.29 +/* @test
293.30 + @summary Test ModelByteBufferWavetable(ModelByteBuffer, AudioFormat) method */
293.31 +
293.32 +import java.io.ByteArrayOutputStream;
293.33 +
293.34 +import javax.sound.sampled.*;
293.35 +
293.36 +import com.sun.media.sound.*;
293.37 +
293.38 +public class NewModelByteBufferWavetableModelByteBufferAudioFormatFloat {
293.39 +
293.40 + static float[] testarray;
293.41 + static byte[] test_byte_array;
293.42 + static byte[] test_byte_array_8ext;
293.43 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
293.44 + static AudioFormat format24 = new AudioFormat(44100, 24, 1, true, false);
293.45 + static ModelByteBuffer buffer;
293.46 + static ModelByteBuffer buffer_wave;
293.47 + static ModelByteBuffer buffer8;
293.48 + static ModelByteBuffer buffer16_8;
293.49 + static ModelByteBuffer buffer24;
293.50 +
293.51 + static void setUp() throws Exception {
293.52 + testarray = new float[1024];
293.53 + for (int i = 0; i < 1024; i++) {
293.54 + double ii = i / 1024.0;
293.55 + ii = ii * ii;
293.56 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
293.57 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
293.58 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
293.59 + testarray[i] *= 0.3;
293.60 + }
293.61 + test_byte_array = new byte[testarray.length*2];
293.62 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
293.63 + buffer = new ModelByteBuffer(test_byte_array);
293.64 +
293.65 + byte[] test_byte_array2 = new byte[testarray.length*3];
293.66 + buffer24 = new ModelByteBuffer(test_byte_array2);
293.67 + test_byte_array_8ext = new byte[testarray.length];
293.68 + byte[] test_byte_array_8_16 = new byte[testarray.length*2];
293.69 + AudioFloatConverter.getConverter(format24).toByteArray(testarray, test_byte_array2);
293.70 + int ix = 0;
293.71 + int x = 0;
293.72 + for (int i = 0; i < test_byte_array_8ext.length; i++) {
293.73 + test_byte_array_8ext[i] = test_byte_array2[ix++];
293.74 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
293.75 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
293.76 + }
293.77 + buffer16_8 = new ModelByteBuffer(test_byte_array_8_16);
293.78 + buffer8 = new ModelByteBuffer(test_byte_array_8ext);
293.79 +
293.80 + AudioInputStream ais = new AudioInputStream(buffer.getInputStream(), format, testarray.length);
293.81 + ByteArrayOutputStream baos = new ByteArrayOutputStream();
293.82 + AudioSystem.write(ais, AudioFileFormat.Type.WAVE, baos);
293.83 + buffer_wave = new ModelByteBuffer(baos.toByteArray());
293.84 + }
293.85 +
293.86 + public static void main(String[] args) throws Exception {
293.87 +
293.88 + setUp();
293.89 +
293.90 + ModelByteBufferWavetable wavetable = new ModelByteBufferWavetable(buffer,format);
293.91 + if(wavetable.getBuffer() != buffer)
293.92 + throw new RuntimeException("wavetable.getBuffer() incorrect!");
293.93 + if(!wavetable.getFormat().matches(format))
293.94 + throw new RuntimeException("wavetable.getFormat() incorrect!");
293.95 + }
293.96 +
293.97 +}
294.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
294.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBufferWavetable/NewModelByteBufferWavetableModelByteBufferFloat.java Tue Feb 03 22:02:55 2009 -0800
294.3 @@ -0,0 +1,96 @@
294.4 +/*
294.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
294.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
294.7 + *
294.8 + * This code is free software; you can redistribute it and/or modify it
294.9 + * under the terms of the GNU General Public License version 2 only, as
294.10 + * published by the Free Software Foundation. Sun designates this
294.11 + * particular file as subject to the "Classpath" exception as provided
294.12 + * by Sun in the LICENSE file that accompanied this code.
294.13 + *
294.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
294.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
294.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
294.17 + * version 2 for more details (a copy is included in the LICENSE file that
294.18 + * accompanied this code).
294.19 + *
294.20 + * You should have received a copy of the GNU General Public License version
294.21 + * 2 along with this work; if not, write to the Free Software Foundation,
294.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
294.23 + *
294.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
294.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
294.26 + * have any questions.
294.27 + */
294.28 +
294.29 +/* @test
294.30 + @summary Test ModelByteBufferWavetable(ModelByteBuffer, AudioFormat, float) method */
294.31 +
294.32 +import java.io.ByteArrayOutputStream;
294.33 +
294.34 +import javax.sound.sampled.*;
294.35 +
294.36 +import com.sun.media.sound.*;
294.37 +
294.38 +public class NewModelByteBufferWavetableModelByteBufferFloat {
294.39 +
294.40 + static float[] testarray;
294.41 + static byte[] test_byte_array;
294.42 + static byte[] test_byte_array_8ext;
294.43 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
294.44 + static AudioFormat format24 = new AudioFormat(44100, 24, 1, true, false);
294.45 + static ModelByteBuffer buffer;
294.46 + static ModelByteBuffer buffer_wave;
294.47 + static ModelByteBuffer buffer8;
294.48 + static ModelByteBuffer buffer16_8;
294.49 + static ModelByteBuffer buffer24;
294.50 +
294.51 + static void setUp() throws Exception {
294.52 + testarray = new float[1024];
294.53 + for (int i = 0; i < 1024; i++) {
294.54 + double ii = i / 1024.0;
294.55 + ii = ii * ii;
294.56 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
294.57 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
294.58 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
294.59 + testarray[i] *= 0.3;
294.60 + }
294.61 + test_byte_array = new byte[testarray.length*2];
294.62 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
294.63 + buffer = new ModelByteBuffer(test_byte_array);
294.64 +
294.65 + byte[] test_byte_array2 = new byte[testarray.length*3];
294.66 + buffer24 = new ModelByteBuffer(test_byte_array2);
294.67 + test_byte_array_8ext = new byte[testarray.length];
294.68 + byte[] test_byte_array_8_16 = new byte[testarray.length*2];
294.69 + AudioFloatConverter.getConverter(format24).toByteArray(testarray, test_byte_array2);
294.70 + int ix = 0;
294.71 + int x = 0;
294.72 + for (int i = 0; i < test_byte_array_8ext.length; i++) {
294.73 + test_byte_array_8ext[i] = test_byte_array2[ix++];
294.74 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
294.75 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
294.76 + }
294.77 + buffer16_8 = new ModelByteBuffer(test_byte_array_8_16);
294.78 + buffer8 = new ModelByteBuffer(test_byte_array_8ext);
294.79 +
294.80 + AudioInputStream ais = new AudioInputStream(buffer.getInputStream(), format, testarray.length);
294.81 + ByteArrayOutputStream baos = new ByteArrayOutputStream();
294.82 + AudioSystem.write(ais, AudioFileFormat.Type.WAVE, baos);
294.83 + buffer_wave = new ModelByteBuffer(baos.toByteArray());
294.84 + }
294.85 +
294.86 + public static void main(String[] args) throws Exception {
294.87 +
294.88 + setUp();
294.89 +
294.90 + ModelByteBufferWavetable wavetable = new ModelByteBufferWavetable(buffer,format,10f);
294.91 + if(wavetable.getBuffer() != buffer)
294.92 + throw new RuntimeException("wavetable.getBuffer() incorrect!");
294.93 + if(!wavetable.getFormat().matches(format))
294.94 + throw new RuntimeException("wavetable.getFormat() incorrect!");
294.95 + if(wavetable.getPitchcorrection() != 10f)
294.96 + throw new RuntimeException("wavetable.getPitchcorrection() not 10!");
294.97 + }
294.98 +
294.99 +}
295.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
295.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBufferWavetable/Open.java Tue Feb 03 22:02:55 2009 -0800
295.3 @@ -0,0 +1,92 @@
295.4 +/*
295.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
295.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
295.7 + *
295.8 + * This code is free software; you can redistribute it and/or modify it
295.9 + * under the terms of the GNU General Public License version 2 only, as
295.10 + * published by the Free Software Foundation. Sun designates this
295.11 + * particular file as subject to the "Classpath" exception as provided
295.12 + * by Sun in the LICENSE file that accompanied this code.
295.13 + *
295.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
295.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
295.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
295.17 + * version 2 for more details (a copy is included in the LICENSE file that
295.18 + * accompanied this code).
295.19 + *
295.20 + * You should have received a copy of the GNU General Public License version
295.21 + * 2 along with this work; if not, write to the Free Software Foundation,
295.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
295.23 + *
295.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
295.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
295.26 + * have any questions.
295.27 + */
295.28 +
295.29 +/* @test
295.30 + @summary Test ModelByteBufferWavetable open method */
295.31 +
295.32 +import java.io.ByteArrayOutputStream;
295.33 +
295.34 +import javax.sound.sampled.*;
295.35 +
295.36 +import com.sun.media.sound.*;
295.37 +
295.38 +public class Open {
295.39 +
295.40 + static float[] testarray;
295.41 + static byte[] test_byte_array;
295.42 + static byte[] test_byte_array_8ext;
295.43 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
295.44 + static AudioFormat format24 = new AudioFormat(44100, 24, 1, true, false);
295.45 + static ModelByteBuffer buffer;
295.46 + static ModelByteBuffer buffer_wave;
295.47 + static ModelByteBuffer buffer8;
295.48 + static ModelByteBuffer buffer16_8;
295.49 + static ModelByteBuffer buffer24;
295.50 +
295.51 + static void setUp() throws Exception {
295.52 + testarray = new float[1024];
295.53 + for (int i = 0; i < 1024; i++) {
295.54 + double ii = i / 1024.0;
295.55 + ii = ii * ii;
295.56 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
295.57 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
295.58 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
295.59 + testarray[i] *= 0.3;
295.60 + }
295.61 + test_byte_array = new byte[testarray.length*2];
295.62 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
295.63 + buffer = new ModelByteBuffer(test_byte_array);
295.64 +
295.65 + byte[] test_byte_array2 = new byte[testarray.length*3];
295.66 + buffer24 = new ModelByteBuffer(test_byte_array2);
295.67 + test_byte_array_8ext = new byte[testarray.length];
295.68 + byte[] test_byte_array_8_16 = new byte[testarray.length*2];
295.69 + AudioFloatConverter.getConverter(format24).toByteArray(testarray, test_byte_array2);
295.70 + int ix = 0;
295.71 + int x = 0;
295.72 + for (int i = 0; i < test_byte_array_8ext.length; i++) {
295.73 + test_byte_array_8ext[i] = test_byte_array2[ix++];
295.74 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
295.75 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
295.76 + }
295.77 + buffer16_8 = new ModelByteBuffer(test_byte_array_8_16);
295.78 + buffer8 = new ModelByteBuffer(test_byte_array_8ext);
295.79 +
295.80 + AudioInputStream ais = new AudioInputStream(buffer.getInputStream(), format, testarray.length);
295.81 + ByteArrayOutputStream baos = new ByteArrayOutputStream();
295.82 + AudioSystem.write(ais, AudioFileFormat.Type.WAVE, baos);
295.83 + buffer_wave = new ModelByteBuffer(baos.toByteArray());
295.84 + }
295.85 +
295.86 + public static void main(String[] args) throws Exception {
295.87 +
295.88 + setUp();
295.89 +
295.90 + ModelByteBufferWavetable wavetable = new ModelByteBufferWavetable(buffer,format);
295.91 + if(wavetable.open(44100) != null)
295.92 + throw new RuntimeException("wavetable.open(44100) doesn't return null!");
295.93 + }
295.94 +
295.95 +}
296.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
296.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBufferWavetable/Set8BitExtensionBuffer.java Tue Feb 03 22:02:55 2009 -0800
296.3 @@ -0,0 +1,119 @@
296.4 +/*
296.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
296.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
296.7 + *
296.8 + * This code is free software; you can redistribute it and/or modify it
296.9 + * under the terms of the GNU General Public License version 2 only, as
296.10 + * published by the Free Software Foundation. Sun designates this
296.11 + * particular file as subject to the "Classpath" exception as provided
296.12 + * by Sun in the LICENSE file that accompanied this code.
296.13 + *
296.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
296.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
296.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
296.17 + * version 2 for more details (a copy is included in the LICENSE file that
296.18 + * accompanied this code).
296.19 + *
296.20 + * You should have received a copy of the GNU General Public License version
296.21 + * 2 along with this work; if not, write to the Free Software Foundation,
296.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
296.23 + *
296.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
296.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
296.26 + * have any questions.
296.27 + */
296.28 +
296.29 +/* @test
296.30 + @summary Test ModelByteBufferWavetable set8BitExtensionBuffer method */
296.31 +
296.32 +import java.io.ByteArrayOutputStream;
296.33 +
296.34 +import javax.sound.sampled.*;
296.35 +
296.36 +import com.sun.media.sound.*;
296.37 +
296.38 +public class Set8BitExtensionBuffer {
296.39 +
296.40 + static float[] testarray;
296.41 + static byte[] test_byte_array;
296.42 + static byte[] test_byte_array_8ext;
296.43 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
296.44 + static AudioFormat format24 = new AudioFormat(44100, 24, 1, true, false);
296.45 + static ModelByteBuffer buffer;
296.46 + static ModelByteBuffer buffer_wave;
296.47 + static ModelByteBuffer buffer8;
296.48 + static ModelByteBuffer buffer16_8;
296.49 + static ModelByteBuffer buffer24;
296.50 +
296.51 + static void setUp() throws Exception {
296.52 + testarray = new float[1024];
296.53 + for (int i = 0; i < 1024; i++) {
296.54 + double ii = i / 1024.0;
296.55 + ii = ii * ii;
296.56 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
296.57 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
296.58 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
296.59 + testarray[i] *= 0.3;
296.60 + }
296.61 + test_byte_array = new byte[testarray.length*2];
296.62 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
296.63 + buffer = new ModelByteBuffer(test_byte_array);
296.64 +
296.65 + byte[] test_byte_array2 = new byte[testarray.length*3];
296.66 + buffer24 = new ModelByteBuffer(test_byte_array2);
296.67 + test_byte_array_8ext = new byte[testarray.length];
296.68 + byte[] test_byte_array_8_16 = new byte[testarray.length*2];
296.69 + AudioFloatConverter.getConverter(format24).toByteArray(testarray, test_byte_array2);
296.70 + int ix = 0;
296.71 + int x = 0;
296.72 + for (int i = 0; i < test_byte_array_8ext.length; i++) {
296.73 + test_byte_array_8ext[i] = test_byte_array2[ix++];
296.74 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
296.75 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
296.76 + }
296.77 + buffer16_8 = new ModelByteBuffer(test_byte_array_8_16);
296.78 + buffer8 = new ModelByteBuffer(test_byte_array_8ext);
296.79 +
296.80 + AudioInputStream ais = new AudioInputStream(buffer.getInputStream(), format, testarray.length);
296.81 + ByteArrayOutputStream baos = new ByteArrayOutputStream();
296.82 + AudioSystem.write(ais, AudioFileFormat.Type.WAVE, baos);
296.83 + buffer_wave = new ModelByteBuffer(baos.toByteArray());
296.84 + }
296.85 +
296.86 + static float compare(float[] a, float[] b)
296.87 + {
296.88 + float ac_error = 0;
296.89 + int counter = 0;
296.90 + for (int i = 0; i < a.length; i++) {
296.91 + ac_error += Math.abs(a[i] - b[i]);
296.92 + counter++;
296.93 + }
296.94 + return ac_error / ((float)counter);
296.95 +
296.96 + }
296.97 +
296.98 + public static void main(String[] args) throws Exception {
296.99 +
296.100 + setUp();
296.101 +
296.102 + ModelByteBufferWavetable wavetable = new ModelByteBufferWavetable(buffer16_8,format,10f);
296.103 + float[] f1 = new float[testarray.length];
296.104 + float[] f2 = new float[testarray.length];
296.105 + wavetable.openStream().read(f1);
296.106 + wavetable.set8BitExtensionBuffer(buffer8);
296.107 + if(wavetable.get8BitExtensionBuffer() != buffer8)
296.108 + throw new RuntimeException("wavetable.get8BitExtensionBuffer() incorrect!");
296.109 + wavetable.openStream().read(f2);
296.110 + // f2 should have more accurity than f1,
296.111 + // about 256 times more, or 8 bits
296.112 + float spec1 = compare(f1, testarray);
296.113 + float spec2 = compare(f2, testarray);
296.114 + if((spec1/spec2) <= 200)
296.115 + throw new RuntimeException("(spec1/spec2) <= 200!");
296.116 +
296.117 +
296.118 + }
296.119 +
296.120 +
296.121 +
296.122 +}
297.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
297.2 +++ b/test/javax/sound/midi/Gervill/ModelByteBufferWavetable/SetLoopType.java Tue Feb 03 22:02:55 2009 -0800
297.3 @@ -0,0 +1,96 @@
297.4 +/*
297.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
297.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
297.7 + *
297.8 + * This code is free software; you can redistribute it and/or modify it
297.9 + * under the terms of the GNU General Public License version 2 only, as
297.10 + * published by the Free Software Foundation. Sun designates this
297.11 + * particular file as subject to the "Classpath" exception as provided
297.12 + * by Sun in the LICENSE file that accompanied this code.
297.13 + *
297.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
297.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
297.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
297.17 + * version 2 for more details (a copy is included in the LICENSE file that
297.18 + * accompanied this code).
297.19 + *
297.20 + * You should have received a copy of the GNU General Public License version
297.21 + * 2 along with this work; if not, write to the Free Software Foundation,
297.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
297.23 + *
297.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
297.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
297.26 + * have any questions.
297.27 + */
297.28 +
297.29 +/* @test
297.30 + @summary Test ModelByteBufferWavetable SetLoopType method */
297.31 +
297.32 +import java.io.ByteArrayOutputStream;
297.33 +
297.34 +import javax.sound.sampled.*;
297.35 +
297.36 +import com.sun.media.sound.*;
297.37 +
297.38 +public class SetLoopType {
297.39 +
297.40 + static float[] testarray;
297.41 + static byte[] test_byte_array;
297.42 + static byte[] test_byte_array_8ext;
297.43 + static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
297.44 + static AudioFormat format24 = new AudioFormat(44100, 24, 1, true, false);
297.45 + static ModelByteBuffer buffer;
297.46 + static ModelByteBuffer buffer_wave;
297.47 + static ModelByteBuffer buffer8;
297.48 + static ModelByteBuffer buffer16_8;
297.49 + static ModelByteBuffer buffer24;
297.50 +
297.51 + static void setUp() throws Exception {
297.52 + testarray = new float[1024];
297.53 + for (int i = 0; i < 1024; i++) {
297.54 + double ii = i / 1024.0;
297.55 + ii = ii * ii;
297.56 + testarray[i] = (float)Math.sin(10*ii*2*Math.PI);
297.57 + testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);
297.58 + testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);
297.59 + testarray[i] *= 0.3;
297.60 + }
297.61 + test_byte_array = new byte[testarray.length*2];
297.62 + AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
297.63 + buffer = new ModelByteBuffer(test_byte_array);
297.64 +
297.65 + byte[] test_byte_array2 = new byte[testarray.length*3];
297.66 + buffer24 = new ModelByteBuffer(test_byte_array2);
297.67 + test_byte_array_8ext = new byte[testarray.length];
297.68 + byte[] test_byte_array_8_16 = new byte[testarray.length*2];
297.69 + AudioFloatConverter.getConverter(format24).toByteArray(testarray, test_byte_array2);
297.70 + int ix = 0;
297.71 + int x = 0;
297.72 + for (int i = 0; i < test_byte_array_8ext.length; i++) {
297.73 + test_byte_array_8ext[i] = test_byte_array2[ix++];
297.74 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
297.75 + test_byte_array_8_16[x++] = test_byte_array2[ix++];
297.76 + }
297.77 + buffer16_8 = new ModelByteBuffer(test_byte_array_8_16);
297.78 + buffer8 = new ModelByteBuffer(test_byte_array_8ext);
297.79 +
297.80 + AudioInputStream ais = new AudioInputStream(buffer.getInputStream(), format, testarray.length);
297.81 + ByteArrayOutputStream baos = new ByteArrayOutputStream();
297.82 + AudioSystem.write(ais, AudioFileFormat.Type.WAVE, baos);
297.83 + buffer_wave = new ModelByteBuffer(baos.toByteArray());
297.84 + }
297.85 +
297.86 + public static void main(String[] args) throws Exception {
297.87 +
297.88 + setUp();
297.89 +
297.90 + ModelByteBufferWavetable wavetable = new ModelByteBufferWavetable(buffer,format);
297.91 + wavetable.setLoopType(1);
297.92 + if(wavetable.getLoopType() != 1)
297.93 + throw new RuntimeException("wavetable.getLoopType() not 1!");
297.94 + wavetable.setLoopType(2);
297.95 + if(wavetable.getLoopType() != 2)
297.96 + throw new RuntimeException("wavetable.getLoopType() not 2!");
297.97 + }
297.98 +
297.99 +}
298.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
298.2 +++ b/test/javax/sound/midi/Gervill/ModelDestination/NewModelDestination.java Tue Feb 03 22:02:55 2009 -0800
298.3 @@ -0,0 +1,46 @@
298.4 +/*
298.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
298.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
298.7 + *
298.8 + * This code is free software; you can redistribute it and/or modify it
298.9 + * under the terms of the GNU General Public License version 2 only, as
298.10 + * published by the Free Software Foundation. Sun designates this
298.11 + * particular file as subject to the "Classpath" exception as provided
298.12 + * by Sun in the LICENSE file that accompanied this code.
298.13 + *
298.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
298.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
298.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
298.17 + * version 2 for more details (a copy is included in the LICENSE file that
298.18 + * accompanied this code).
298.19 + *
298.20 + * You should have received a copy of the GNU General Public License version
298.21 + * 2 along with this work; if not, write to the Free Software Foundation,
298.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
298.23 + *
298.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
298.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
298.26 + * have any questions.
298.27 + */
298.28 +
298.29 +/* @test
298.30 + @summary Test ModelDestination constructor */
298.31 +
298.32 +import java.io.File;
298.33 +import java.io.FileOutputStream;
298.34 +import java.io.IOException;
298.35 +
298.36 +import javax.sound.sampled.*;
298.37 +
298.38 +import com.sun.media.sound.*;
298.39 +
298.40 +public class NewModelDestination {
298.41 +
298.42 + public static void main(String[] args) throws Exception {
298.43 + ModelDestination dest = new ModelDestination();
298.44 + if(dest.getIdentifier() != ModelDestination.DESTINATION_NONE)
298.45 + throw new RuntimeException("dest.getIdentifier() is not equals ModelDestination.DESTINATION_NONE!");
298.46 + if(!(dest.getTransform() instanceof ModelStandardTransform))
298.47 + throw new RuntimeException("dest.getTransform() is not instancoef ModelStandardTransform!");
298.48 + }
298.49 +}
299.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
299.2 +++ b/test/javax/sound/midi/Gervill/ModelDestination/NewModelDestinationModelIdentifier.java Tue Feb 03 22:02:55 2009 -0800
299.3 @@ -0,0 +1,46 @@
299.4 +/*
299.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
299.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
299.7 + *
299.8 + * This code is free software; you can redistribute it and/or modify it
299.9 + * under the terms of the GNU General Public License version 2 only, as
299.10 + * published by the Free Software Foundation. Sun designates this
299.11 + * particular file as subject to the "Classpath" exception as provided
299.12 + * by Sun in the LICENSE file that accompanied this code.
299.13 + *
299.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
299.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
299.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
299.17 + * version 2 for more details (a copy is included in the LICENSE file that
299.18 + * accompanied this code).
299.19 + *
299.20 + * You should have received a copy of the GNU General Public License version
299.21 + * 2 along with this work; if not, write to the Free Software Foundation,
299.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
299.23 + *
299.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
299.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
299.26 + * have any questions.
299.27 + */
299.28 +
299.29 +/* @test
299.30 + @summary Test ModelDestination(ModelIdentifier) constructor */
299.31 +
299.32 +import java.io.File;
299.33 +import java.io.FileOutputStream;
299.34 +import java.io.IOException;
299.35 +
299.36 +import javax.sound.sampled.*;
299.37 +
299.38 +import com.sun.media.sound.*;
299.39 +
299.40 +public class NewModelDestinationModelIdentifier {
299.41 +
299.42 + public static void main(String[] args) throws Exception {
299.43 + ModelDestination dest = new ModelDestination(ModelDestination.DESTINATION_EG1_ATTACK);
299.44 + if(dest.getIdentifier() != ModelDestination.DESTINATION_EG1_ATTACK)
299.45 + throw new RuntimeException("dest.getIdentifier() is not equals ModelDestination.DESTINATION_EG1_ATTACK!");
299.46 + if(!(dest.getTransform() instanceof ModelStandardTransform))
299.47 + throw new RuntimeException("dest.getTransform() is not instancoef ModelStandardTransform!");
299.48 + }
299.49 +}
300.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
300.2 +++ b/test/javax/sound/midi/Gervill/ModelDestination/SetIdentifier.java Tue Feb 03 22:02:55 2009 -0800
300.3 @@ -0,0 +1,45 @@
300.4 +/*
300.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
300.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
300.7 + *
300.8 + * This code is free software; you can redistribute it and/or modify it
300.9 + * under the terms of the GNU General Public License version 2 only, as
300.10 + * published by the Free Software Foundation. Sun designates this
300.11 + * particular file as subject to the "Classpath" exception as provided
300.12 + * by Sun in the LICENSE file that accompanied this code.
300.13 + *
300.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
300.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
300.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
300.17 + * version 2 for more details (a copy is included in the LICENSE file that
300.18 + * accompanied this code).
300.19 + *
300.20 + * You should have received a copy of the GNU General Public License version
300.21 + * 2 along with this work; if not, write to the Free Software Foundation,
300.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
300.23 + *
300.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
300.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
300.26 + * have any questions.
300.27 + */
300.28 +
300.29 +/* @test
300.30 + @summary Test ModelByteBufferWavetable setIdentifier(ModelIdentifier) method */
300.31 +
300.32 +import java.io.File;
300.33 +import java.io.FileOutputStream;
300.34 +import java.io.IOException;
300.35 +
300.36 +import javax.sound.sampled.*;
300.37 +
300.38 +import com.sun.media.sound.*;
300.39 +
300.40 +public class SetIdentifier {
300.41 +
300.42 + public static void main(String[] args) throws Exception {
300.43 + ModelDestination dest = new ModelDestination();
300.44 + dest.setIdentifier(ModelDestination.DESTINATION_EG1_ATTACK);
300.45 + if(dest.getIdentifier() != ModelDestination.DESTINATION_EG1_ATTACK)
300.46 + throw new RuntimeException("dest.getIdentifier() is not equals ModelDestination.DESTINATION_EG1_ATTACK!");
300.47 + }
300.48 +}
301.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
301.2 +++ b/test/javax/sound/midi/Gervill/ModelDestination/SetTransform.java Tue Feb 03 22:02:55 2009 -0800
301.3 @@ -0,0 +1,46 @@
301.4 +/*
301.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
301.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
301.7 + *
301.8 + * This code is free software; you can redistribute it and/or modify it
301.9 + * under the terms of the GNU General Public License version 2 only, as
301.10 + * published by the Free Software Foundation. Sun designates this
301.11 + * particular file as subject to the "Classpath" exception as provided
301.12 + * by Sun in the LICENSE file that accompanied this code.
301.13 + *
301.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
301.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
301.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
301.17 + * version 2 for more details (a copy is included in the LICENSE file that
301.18 + * accompanied this code).
301.19 + *
301.20 + * You should have received a copy of the GNU General Public License version
301.21 + * 2 along with this work; if not, write to the Free Software Foundation,
301.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
301.23 + *
301.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
301.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
301.26 + * have any questions.
301.27 + */
301.28 +
301.29 +/* @test
301.30 + @summary Test ModelByteBufferWavetable setTransform(ModelTransform) method */
301.31 +
301.32 +import java.io.File;
301.33 +import java.io.FileOutputStream;
301.34 +import java.io.IOException;
301.35 +
301.36 +import javax.sound.sampled.*;
301.37 +
301.38 +import com.sun.media.sound.*;
301.39 +
301.40 +public class SetTransform{
301.41 +
301.42 + public static void main(String[] args) throws Exception {
301.43 + ModelDestination dest = new ModelDestination();
301.44 + ModelStandardTransform newtransform = new ModelStandardTransform();
301.45 + dest.setTransform(newtransform);
301.46 + if(dest.getTransform() != newtransform)
301.47 + throw new RuntimeException("dest.getTransform() is incorrect!");
301.48 + }
301.49 +}
302.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
302.2 +++ b/test/javax/sound/midi/Gervill/ModelIdentifier/EqualsObject.java Tue Feb 03 22:02:55 2009 -0800
302.3 @@ -0,0 +1,54 @@
302.4 +/*
302.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
302.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
302.7 + *
302.8 + * This code is free software; you can redistribute it and/or modify it
302.9 + * under the terms of the GNU General Public License version 2 only, as
302.10 + * published by the Free Software Foundation. Sun designates this
302.11 + * particular file as subject to the "Classpath" exception as provided
302.12 + * by Sun in the LICENSE file that accompanied this code.
302.13 + *
302.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
302.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
302.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
302.17 + * version 2 for more details (a copy is included in the LICENSE file that
302.18 + * accompanied this code).
302.19 + *
302.20 + * You should have received a copy of the GNU General Public License version
302.21 + * 2 along with this work; if not, write to the Free Software Foundation,
302.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
302.23 + *
302.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
302.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
302.26 + * have any questions.
302.27 + */
302.28 +
302.29 +/* @test
302.30 + @summary Test ModelIdentifier equals method */
302.31 +
302.32 +import java.io.File;
302.33 +import java.io.FileOutputStream;
302.34 +import java.io.IOException;
302.35 +
302.36 +import javax.sound.sampled.*;
302.37 +
302.38 +import com.sun.media.sound.*;
302.39 +
302.40 +public class EqualsObject {
302.41 +
302.42 + public static void main(String[] args) throws Exception {
302.43 + ModelIdentifier id = new ModelIdentifier("test","a",1);
302.44 + ModelIdentifier id2 = new ModelIdentifier("test","a",1);
302.45 + ModelIdentifier id3 = new ModelIdentifier("test","a",2);
302.46 + ModelIdentifier id4 = new ModelIdentifier("test","b",1);
302.47 + ModelIdentifier id5 = new ModelIdentifier("hello","a",1);
302.48 + if(!id.equals(id2))
302.49 + throw new RuntimeException("Compare failed!");
302.50 + if(id.equals(id3))
302.51 + throw new RuntimeException("Compare failed!");
302.52 + if(id.equals(id4))
302.53 + throw new RuntimeException("Compare failed!");
302.54 + if(id.equals(id5))
302.55 + throw new RuntimeException("Compare failed!");
302.56 + }
302.57 +}
303.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
303.2 +++ b/test/javax/sound/midi/Gervill/ModelIdentifier/NewModelIdentifierString.java Tue Feb 03 22:02:55 2009 -0800
303.3 @@ -0,0 +1,48 @@
303.4 +/*
303.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
303.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
303.7 + *
303.8 + * This code is free software; you can redistribute it and/or modify it
303.9 + * under the terms of the GNU General Public License version 2 only, as
303.10 + * published by the Free Software Foundation. Sun designates this
303.11 + * particular file as subject to the "Classpath" exception as provided
303.12 + * by Sun in the LICENSE file that accompanied this code.
303.13 + *
303.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
303.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
303.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
303.17 + * version 2 for more details (a copy is included in the LICENSE file that
303.18 + * accompanied this code).
303.19 + *
303.20 + * You should have received a copy of the GNU General Public License version
303.21 + * 2 along with this work; if not, write to the Free Software Foundation,
303.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
303.23 + *
303.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
303.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
303.26 + * have any questions.
303.27 + */
303.28 +
303.29 +/* @test
303.30 + @summary Test ModelIdentifier(String) constructor */
303.31 +
303.32 +import java.io.File;
303.33 +import java.io.FileOutputStream;
303.34 +import java.io.IOException;
303.35 +
303.36 +import javax.sound.sampled.*;
303.37 +
303.38 +import com.sun.media.sound.*;
303.39 +
303.40 +public class NewModelIdentifierString {
303.41 +
303.42 + public static void main(String[] args) throws Exception {
303.43 + ModelIdentifier id = new ModelIdentifier("test");
303.44 + if(!id.getObject().equals("test"))
303.45 + throw new RuntimeException("id.getObject() doesn't return \"test\"!");
303.46 + if(id.getVariable() != null)
303.47 + throw new RuntimeException("id.getVariable() doesn't return null!");
303.48 + if(id.getInstance() != 0)
303.49 + throw new RuntimeException("id.getInstance() doesn't return 0!");
303.50 + }
303.51 +}
304.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
304.2 +++ b/test/javax/sound/midi/Gervill/ModelIdentifier/NewModelIdentifierStringInt.java Tue Feb 03 22:02:55 2009 -0800
304.3 @@ -0,0 +1,48 @@
304.4 +/*
304.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
304.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
304.7 + *
304.8 + * This code is free software; you can redistribute it and/or modify it
304.9 + * under the terms of the GNU General Public License version 2 only, as
304.10 + * published by the Free Software Foundation. Sun designates this
304.11 + * particular file as subject to the "Classpath" exception as provided
304.12 + * by Sun in the LICENSE file that accompanied this code.
304.13 + *
304.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
304.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
304.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
304.17 + * version 2 for more details (a copy is included in the LICENSE file that
304.18 + * accompanied this code).
304.19 + *
304.20 + * You should have received a copy of the GNU General Public License version
304.21 + * 2 along with this work; if not, write to the Free Software Foundation,
304.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
304.23 + *
304.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
304.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
304.26 + * have any questions.
304.27 + */
304.28 +
304.29 +/* @test
304.30 + @summary Test ModelIdentifier(String, integer) constructor */
304.31 +
304.32 +import java.io.File;
304.33 +import java.io.FileOutputStream;
304.34 +import java.io.IOException;
304.35 +
304.36 +import javax.sound.sampled.*;
304.37 +
304.38 +import com.sun.media.sound.*;
304.39 +
304.40 +public class NewModelIdentifierStringInt {
304.41 +
304.42 + public static void main(String[] args) throws Exception {
304.43 + ModelIdentifier id = new ModelIdentifier("test",1);
304.44 + if(!id.getObject().equals("test"))
304.45 + throw new RuntimeException("id.getObject() doesn't return \"test\"!");
304.46 + if(id.getVariable() != null)
304.47 + throw new RuntimeException("id.getVariable() doesn't return null!");
304.48 + if(id.getInstance() != 1)
304.49 + throw new RuntimeException("id.getInstance() doesn't return 1!");
304.50 + }
304.51 +}
305.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
305.2 +++ b/test/javax/sound/midi/Gervill/ModelIdentifier/NewModelIdentifierStringString.java Tue Feb 03 22:02:55 2009 -0800
305.3 @@ -0,0 +1,48 @@
305.4 +/*
305.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
305.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
305.7 + *
305.8 + * This code is free software; you can redistribute it and/or modify it
305.9 + * under the terms of the GNU General Public License version 2 only, as
305.10 + * published by the Free Software Foundation. Sun designates this
305.11 + * particular file as subject to the "Classpath" exception as provided
305.12 + * by Sun in the LICENSE file that accompanied this code.
305.13 + *
305.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
305.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
305.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
305.17 + * version 2 for more details (a copy is included in the LICENSE file that
305.18 + * accompanied this code).
305.19 + *
305.20 + * You should have received a copy of the GNU General Public License version
305.21 + * 2 along with this work; if not, write to the Free Software Foundation,
305.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
305.23 + *
305.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
305.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
305.26 + * have any questions.
305.27 + */
305.28 +
305.29 +/* @test
305.30 + @summary Test ModelIdentifier(String,String) constructor */
305.31 +
305.32 +import java.io.File;
305.33 +import java.io.FileOutputStream;
305.34 +import java.io.IOException;
305.35 +
305.36 +import javax.sound.sampled.*;
305.37 +
305.38 +import com.sun.media.sound.*;
305.39 +
305.40 +public class NewModelIdentifierStringString {
305.41 +
305.42 + public static void main(String[] args) throws Exception {
305.43 + ModelIdentifier id = new ModelIdentifier("test","a");
305.44 + if(!id.getObject().equals("test"))
305.45 + throw new RuntimeException("id.getObject() doesn't return \"test\"!");
305.46 + if(!id.getVariable().equals("a"))
305.47 + throw new RuntimeException("id.getVariable() doesn't return \"a\"!");
305.48 + if(id.getInstance() != 0)
305.49 + throw new RuntimeException("id.getInstance() doesn't return 0!");
305.50 + }
305.51 +}
306.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
306.2 +++ b/test/javax/sound/midi/Gervill/ModelIdentifier/NewModelIdentifierStringStringInt.java Tue Feb 03 22:02:55 2009 -0800
306.3 @@ -0,0 +1,48 @@
306.4 +/*
306.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
306.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
306.7 + *
306.8 + * This code is free software; you can redistribute it and/or modify it
306.9 + * under the terms of the GNU General Public License version 2 only, as
306.10 + * published by the Free Software Foundation. Sun designates this
306.11 + * particular file as subject to the "Classpath" exception as provided
306.12 + * by Sun in the LICENSE file that accompanied this code.
306.13 + *
306.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
306.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
306.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
306.17 + * version 2 for more details (a copy is included in the LICENSE file that
306.18 + * accompanied this code).
306.19 + *
306.20 + * You should have received a copy of the GNU General Public License version
306.21 + * 2 along with this work; if not, write to the Free Software Foundation,
306.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
306.23 + *
306.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
306.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
306.26 + * have any questions.
306.27 + */
306.28 +
306.29 +/* @test
306.30 + @summary Test ModelIdentifier(String,String,int) constructor */
306.31 +
306.32 +import java.io.File;
306.33 +import java.io.FileOutputStream;
306.34 +import java.io.IOException;
306.35 +
306.36 +import javax.sound.sampled.*;
306.37 +
306.38 +import com.sun.media.sound.*;
306.39 +
306.40 +public class NewModelIdentifierStringStringInt {
306.41 +
306.42 + public static void main(String[] args) throws Exception {
306.43 + ModelIdentifier id = new ModelIdentifier("test","a",1);;
306.44 + if(!id.getObject().equals("test"))
306.45 + throw new RuntimeException("id.getObject() doesn't return \"test\"!");
306.46 + if(!id.getVariable().equals("a"))
306.47 + throw new RuntimeException("id.getVariable() doesn't return \"a\"!");
306.48 + if(id.getInstance() != 1)
306.49 + throw new RuntimeException("id.getInstance() doesn't return 1!");
306.50 + }
306.51 +}
307.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
307.2 +++ b/test/javax/sound/midi/Gervill/ModelIdentifier/SetInstance.java Tue Feb 03 22:02:55 2009 -0800
307.3 @@ -0,0 +1,45 @@
307.4 +/*
307.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
307.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
307.7 + *
307.8 + * This code is free software; you can redistribute it and/or modify it
307.9 + * under the terms of the GNU General Public License version 2 only, as
307.10 + * published by the Free Software Foundation. Sun designates this
307.11 + * particular file as subject to the "Classpath" exception as provided
307.12 + * by Sun in the LICENSE file that accompanied this code.
307.13 + *
307.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
307.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
307.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
307.17 + * version 2 for more details (a copy is included in the LICENSE file that
307.18 + * accompanied this code).
307.19 + *
307.20 + * You should have received a copy of the GNU General Public License version
307.21 + * 2 along with this work; if not, write to the Free Software Foundation,
307.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
307.23 + *
307.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
307.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
307.26 + * have any questions.
307.27 + */
307.28 +
307.29 +/* @test
307.30 + @summary Test ModelIdentifier setInstance method */
307.31 +
307.32 +import java.io.File;
307.33 +import java.io.FileOutputStream;
307.34 +import java.io.IOException;
307.35 +
307.36 +import javax.sound.sampled.*;
307.37 +
307.38 +import com.sun.media.sound.*;
307.39 +
307.40 +public class SetInstance {
307.41 +
307.42 + public static void main(String[] args) throws Exception {
307.43 + ModelIdentifier id = new ModelIdentifier("test","a",1);
307.44 + id.setInstance(2);
307.45 + if(id.getInstance() != 2)
307.46 + throw new RuntimeException("id.getInstance() doesn't return 2!");
307.47 + }
307.48 +}
308.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
308.2 +++ b/test/javax/sound/midi/Gervill/ModelIdentifier/SetObject.java Tue Feb 03 22:02:55 2009 -0800
308.3 @@ -0,0 +1,45 @@
308.4 +/*
308.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
308.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
308.7 + *
308.8 + * This code is free software; you can redistribute it and/or modify it
308.9 + * under the terms of the GNU General Public License version 2 only, as
308.10 + * published by the Free Software Foundation. Sun designates this
308.11 + * particular file as subject to the "Classpath" exception as provided
308.12 + * by Sun in the LICENSE file that accompanied this code.
308.13 + *
308.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
308.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
308.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
308.17 + * version 2 for more details (a copy is included in the LICENSE file that
308.18 + * accompanied this code).
308.19 + *
308.20 + * You should have received a copy of the GNU General Public License version
308.21 + * 2 along with this work; if not, write to the Free Software Foundation,
308.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
308.23 + *
308.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
308.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
308.26 + * have any questions.
308.27 + */
308.28 +
308.29 +/* @test
308.30 + @summary Test ModelIdentifier setObject method */
308.31 +
308.32 +import java.io.File;
308.33 +import java.io.FileOutputStream;
308.34 +import java.io.IOException;
308.35 +
308.36 +import javax.sound.sampled.*;
308.37 +
308.38 +import com.sun.media.sound.*;
308.39 +
308.40 +public class SetObject {
308.41 +
308.42 + public static void main(String[] args) throws Exception {
308.43 + ModelIdentifier id = new ModelIdentifier("test","a",1);
308.44 + id.setObject("hello");
308.45 + if(!id.getObject().equals("hello"))
308.46 + throw new RuntimeException("id.getObject() does't return \"hello\"!");
308.47 + }
308.48 +}
309.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
309.2 +++ b/test/javax/sound/midi/Gervill/ModelIdentifier/SetVariable.java Tue Feb 03 22:02:55 2009 -0800
309.3 @@ -0,0 +1,45 @@
309.4 +/*
309.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
309.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
309.7 + *
309.8 + * This code is free software; you can redistribute it and/or modify it
309.9 + * under the terms of the GNU General Public License version 2 only, as
309.10 + * published by the Free Software Foundation. Sun designates this
309.11 + * particular file as subject to the "Classpath" exception as provided
309.12 + * by Sun in the LICENSE file that accompanied this code.
309.13 + *
309.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
309.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
309.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
309.17 + * version 2 for more details (a copy is included in the LICENSE file that
309.18 + * accompanied this code).
309.19 + *
309.20 + * You should have received a copy of the GNU General Public License version
309.21 + * 2 along with this work; if not, write to the Free Software Foundation,
309.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
309.23 + *
309.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
309.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
309.26 + * have any questions.
309.27 + */
309.28 +
309.29 +/* @test
309.30 + @summary Test ModelIdentifier setVariable method */
309.31 +
309.32 +import java.io.File;
309.33 +import java.io.FileOutputStream;
309.34 +import java.io.IOException;
309.35 +
309.36 +import javax.sound.sampled.*;
309.37 +
309.38 +import com.sun.media.sound.*;
309.39 +
309.40 +public class SetVariable {
309.41 +
309.42 + public static void main(String[] args) throws Exception {
309.43 + ModelIdentifier id = new ModelIdentifier("test","a",1);
309.44 + id.setVariable("b");
309.45 + if(!id.getVariable().equals("b"))
309.46 + throw new RuntimeException("id.getVariable() does't return \"b\"!");
309.47 + }
309.48 +}
310.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
310.2 +++ b/test/javax/sound/midi/Gervill/ModelPerformer/GetOscillators.java Tue Feb 03 22:02:55 2009 -0800
310.3 @@ -0,0 +1,44 @@
310.4 +/*
310.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
310.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
310.7 + *
310.8 + * This code is free software; you can redistribute it and/or modify it
310.9 + * under the terms of the GNU General Public License version 2 only, as
310.10 + * published by the Free Software Foundation. Sun designates this
310.11 + * particular file as subject to the "Classpath" exception as provided
310.12 + * by Sun in the LICENSE file that accompanied this code.
310.13 + *
310.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
310.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
310.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
310.17 + * version 2 for more details (a copy is included in the LICENSE file that
310.18 + * accompanied this code).
310.19 + *
310.20 + * You should have received a copy of the GNU General Public License version
310.21 + * 2 along with this work; if not, write to the Free Software Foundation,
310.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
310.23 + *
310.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
310.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
310.26 + * have any questions.
310.27 + */
310.28 +
310.29 +/* @test
310.30 + @summary Test ModelPerformer getOscillators method */
310.31 +
310.32 +import java.io.File;
310.33 +import java.io.FileOutputStream;
310.34 +import java.io.IOException;
310.35 +
310.36 +import javax.sound.sampled.*;
310.37 +
310.38 +import com.sun.media.sound.*;
310.39 +
310.40 +public class GetOscillators {
310.41 +
310.42 + public static void main(String[] args) throws Exception {
310.43 + ModelPerformer performer = new ModelPerformer();
310.44 + if(performer.getOscillators() == null)
310.45 + throw new RuntimeException("performer.getOscillators() returned null!");
310.46 + }
310.47 +}
311.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
311.2 +++ b/test/javax/sound/midi/Gervill/ModelPerformer/SetConnectionBlocks.java Tue Feb 03 22:02:55 2009 -0800
311.3 @@ -0,0 +1,48 @@
311.4 +/*
311.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
311.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
311.7 + *
311.8 + * This code is free software; you can redistribute it and/or modify it
311.9 + * under the terms of the GNU General Public License version 2 only, as
311.10 + * published by the Free Software Foundation. Sun designates this
311.11 + * particular file as subject to the "Classpath" exception as provided
311.12 + * by Sun in the LICENSE file that accompanied this code.
311.13 + *
311.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
311.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
311.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
311.17 + * version 2 for more details (a copy is included in the LICENSE file that
311.18 + * accompanied this code).
311.19 + *
311.20 + * You should have received a copy of the GNU General Public License version
311.21 + * 2 along with this work; if not, write to the Free Software Foundation,
311.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
311.23 + *
311.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
311.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
311.26 + * have any questions.
311.27 + */
311.28 +
311.29 +/* @test
311.30 + @summary Test ModelPerformer setConnectionBlocks method */
311.31 +
311.32 +import java.io.File;
311.33 +import java.io.FileOutputStream;
311.34 +import java.io.IOException;
311.35 +import java.util.ArrayList;
311.36 +import java.util.List;
311.37 +
311.38 +import javax.sound.sampled.*;
311.39 +
311.40 +import com.sun.media.sound.*;
311.41 +
311.42 +public class SetConnectionBlocks {
311.43 +
311.44 + public static void main(String[] args) throws Exception {
311.45 + ModelPerformer performer = new ModelPerformer();
311.46 + List<ModelConnectionBlock> newlist = new ArrayList<ModelConnectionBlock>();
311.47 + performer.setConnectionBlocks(newlist);
311.48 + if(performer.getConnectionBlocks() != newlist)
311.49 + throw new RuntimeException("performer.getConnectionBlocks() returned incorrect data!");
311.50 + }
311.51 +}
312.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
312.2 +++ b/test/javax/sound/midi/Gervill/ModelPerformer/SetDefaultConnectionsEnabled.java Tue Feb 03 22:02:55 2009 -0800
312.3 @@ -0,0 +1,49 @@
312.4 +/*
312.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
312.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
312.7 + *
312.8 + * This code is free software; you can redistribute it and/or modify it
312.9 + * under the terms of the GNU General Public License version 2 only, as
312.10 + * published by the Free Software Foundation. Sun designates this
312.11 + * particular file as subject to the "Classpath" exception as provided
312.12 + * by Sun in the LICENSE file that accompanied this code.
312.13 + *
312.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
312.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
312.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
312.17 + * version 2 for more details (a copy is included in the LICENSE file that
312.18 + * accompanied this code).
312.19 + *
312.20 + * You should have received a copy of the GNU General Public License version
312.21 + * 2 along with this work; if not, write to the Free Software Foundation,
312.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
312.23 + *
312.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
312.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
312.26 + * have any questions.
312.27 + */
312.28 +
312.29 +/* @test
312.30 + @summary Test ModelPerformer setDefaultConnectionsEnabled method */
312.31 +
312.32 +import java.io.File;
312.33 +import java.io.FileOutputStream;
312.34 +import java.io.IOException;
312.35 +
312.36 +import javax.sound.sampled.*;
312.37 +
312.38 +import com.sun.media.sound.*;
312.39 +
312.40 +public class SetDefaultConnectionsEnabled {
312.41 +
312.42 + public static void main(String[] args) throws Exception {
312.43 + ModelPerformer performer = new ModelPerformer();
312.44 + performer.setDefaultConnectionsEnabled(true);
312.45 + if(performer.isDefaultConnectionsEnabled() != true)
312.46 + throw new RuntimeException("performer.isAddDefaultConnectionsEnabled() didn't return true!");
312.47 + performer.setDefaultConnectionsEnabled(false);
312.48 + if(performer.isDefaultConnectionsEnabled() != false)
312.49 + throw new RuntimeException("performer.isAddDefaultConnectionsEnabled() didn't return false!");
312.50 +
312.51 + }
312.52 +}
313.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
313.2 +++ b/test/javax/sound/midi/Gervill/ModelPerformer/SetExclusiveClass.java Tue Feb 03 22:02:55 2009 -0800
313.3 @@ -0,0 +1,45 @@
313.4 +/*
313.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
313.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
313.7 + *
313.8 + * This code is free software; you can redistribute it and/or modify it
313.9 + * under the terms of the GNU General Public License version 2 only, as
313.10 + * published by the Free Software Foundation. Sun designates this
313.11 + * particular file as subject to the "Classpath" exception as provided
313.12 + * by Sun in the LICENSE file that accompanied this code.
313.13 + *
313.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
313.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
313.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
313.17 + * version 2 for more details (a copy is included in the LICENSE file that
313.18 + * accompanied this code).
313.19 + *
313.20 + * You should have received a copy of the GNU General Public License version
313.21 + * 2 along with this work; if not, write to the Free Software Foundation,
313.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
313.23 + *
313.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
313.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
313.26 + * have any questions.
313.27 + */
313.28 +
313.29 +/* @test
313.30 + @summary Test ModelPerformer setExclusiveClass method */
313.31 +
313.32 +import java.io.File;
313.33 +import java.io.FileOutputStream;
313.34 +import java.io.IOException;
313.35 +
313.36 +import javax.sound.sampled.*;
313.37 +
313.38 +import com.sun.media.sound.*;
313.39 +
313.40 +public class SetExclusiveClass {
313.41 +
313.42 + public static void main(String[] args) throws Exception {
313.43 + ModelPerformer performer = new ModelPerformer();
313.44 + performer.setExclusiveClass(10);
313.45 + if(performer.getExclusiveClass() != 10)
313.46 + throw new RuntimeException("performer.getExclusiveClass() didn't return 10!");
313.47 + }
313.48 +}
314.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
314.2 +++ b/test/javax/sound/midi/Gervill/ModelPerformer/SetKeyFrom.java Tue Feb 03 22:02:55 2009 -0800
314.3 @@ -0,0 +1,45 @@
314.4 +/*
314.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
314.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
314.7 + *
314.8 + * This code is free software; you can redistribute it and/or modify it
314.9 + * under the terms of the GNU General Public License version 2 only, as
314.10 + * published by the Free Software Foundation. Sun designates this
314.11 + * particular file as subject to the "Classpath" exception as provided
314.12 + * by Sun in the LICENSE file that accompanied this code.
314.13 + *
314.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
314.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
314.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
314.17 + * version 2 for more details (a copy is included in the LICENSE file that
314.18 + * accompanied this code).
314.19 + *
314.20 + * You should have received a copy of the GNU General Public License version
314.21 + * 2 along with this work; if not, write to the Free Software Foundation,
314.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
314.23 + *
314.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
314.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
314.26 + * have any questions.
314.27 + */
314.28 +
314.29 +/* @test
314.30 + @summary Test ModelPerformer setKeyFrom method */
314.31 +
314.32 +import java.io.File;
314.33 +import java.io.FileOutputStream;
314.34 +import java.io.IOException;
314.35 +
314.36 +import javax.sound.sampled.*;
314.37 +
314.38 +import com.sun.media.sound.*;
314.39 +
314.40 +public class SetKeyFrom {
314.41 +
314.42 + public static void main(String[] args) throws Exception {
314.43 + ModelPerformer performer = new ModelPerformer();
314.44 + performer.setKeyFrom(10);
314.45 + if(performer.getKeyFrom() != 10)
314.46 + throw new RuntimeException("performer.getKeyFrom() didn't return 10!");
314.47 + }
314.48 +}
315.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
315.2 +++ b/test/javax/sound/midi/Gervill/ModelPerformer/SetKeyTo.java Tue Feb 03 22:02:55 2009 -0800
315.3 @@ -0,0 +1,45 @@
315.4 +/*
315.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
315.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
315.7 + *
315.8 + * This code is free software; you can redistribute it and/or modify it
315.9 + * under the terms of the GNU General Public License version 2 only, as
315.10 + * published by the Free Software Foundation. Sun designates this
315.11 + * particular file as subject to the "Classpath" exception as provided
315.12 + * by Sun in the LICENSE file that accompanied this code.
315.13 + *
315.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
315.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
315.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
315.17 + * version 2 for more details (a copy is included in the LICENSE file that
315.18 + * accompanied this code).
315.19 + *
315.20 + * You should have received a copy of the GNU General Public License version
315.21 + * 2 along with this work; if not, write to the Free Software Foundation,
315.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
315.23 + *
315.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
315.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
315.26 + * have any questions.
315.27 + */
315.28 +
315.29 +/* @test
315.30 + @summary Test ModelPerformer setKeyTo method */
315.31 +
315.32 +import java.io.File;
315.33 +import java.io.FileOutputStream;
315.34 +import java.io.IOException;
315.35 +
315.36 +import javax.sound.sampled.*;
315.37 +
315.38 +import com.sun.media.sound.*;
315.39 +
315.40 +public class SetKeyTo {
315.41 +
315.42 + public static void main(String[] args) throws Exception {
315.43 + ModelPerformer performer = new ModelPerformer();
315.44 + performer.setKeyTo(10);
315.45 + if(performer.getKeyTo() != 10)
315.46 + throw new RuntimeException("performer.getKeyTo() didn't return 10!");
315.47 + }
315.48 +}
316.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
316.2 +++ b/test/javax/sound/midi/Gervill/ModelPerformer/SetName.java Tue Feb 03 22:02:55 2009 -0800
316.3 @@ -0,0 +1,45 @@
316.4 +/*
316.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
316.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
316.7 + *
316.8 + * This code is free software; you can redistribute it and/or modify it
316.9 + * under the terms of the GNU General Public License version 2 only, as
316.10 + * published by the Free Software Foundation. Sun designates this
316.11 + * particular file as subject to the "Classpath" exception as provided
316.12 + * by Sun in the LICENSE file that accompanied this code.
316.13 + *
316.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
316.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
316.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
316.17 + * version 2 for more details (a copy is included in the LICENSE file that
316.18 + * accompanied this code).
316.19 + *
316.20 + * You should have received a copy of the GNU General Public License version
316.21 + * 2 along with this work; if not, write to the Free Software Foundation,
316.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
316.23 + *
316.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
316.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
316.26 + * have any questions.
316.27 + */
316.28 +
316.29 +/* @test
316.30 + @summary Test ModelPerformer setName method */
316.31 +
316.32 +import java.io.File;
316.33 +import java.io.FileOutputStream;
316.34 +import java.io.IOException;
316.35 +
316.36 +import javax.sound.sampled.*;
316.37 +
316.38 +import com.sun.media.sound.*;
316.39 +
316.40 +public class SetName {
316.41 +
316.42 + public static void main(String[] args) throws Exception {
316.43 + ModelPerformer performer = new ModelPerformer();
316.44 + performer.setName("hello");
316.45 + if(!performer.getName().equals("hello"))
316.46 + throw new RuntimeException("performer.getName() didn't return \"hello\"!");
316.47 + }
316.48 +}
317.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
317.2 +++ b/test/javax/sound/midi/Gervill/ModelPerformer/SetSelfNonExclusive.java Tue Feb 03 22:02:55 2009 -0800
317.3 @@ -0,0 +1,48 @@
317.4 +/*
317.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
317.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
317.7 + *
317.8 + * This code is free software; you can redistribute it and/or modify it
317.9 + * under the terms of the GNU General Public License version 2 only, as
317.10 + * published by the Free Software Foundation. Sun designates this
317.11 + * particular file as subject to the "Classpath" exception as provided
317.12 + * by Sun in the LICENSE file that accompanied this code.
317.13 + *
317.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
317.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
317.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
317.17 + * version 2 for more details (a copy is included in the LICENSE file that
317.18 + * accompanied this code).
317.19 + *
317.20 + * You should have received a copy of the GNU General Public License version
317.21 + * 2 along with this work; if not, write to the Free Software Foundation,
317.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
317.23 + *
317.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
317.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
317.26 + * have any questions.
317.27 + */
317.28 +
317.29 +/* @test
317.30 + @summary Test ModelPerformer setSelfNonExclusive method */
317.31 +
317.32 +import java.io.File;
317.33 +import java.io.FileOutputStream;
317.34 +import java.io.IOException;
317.35 +
317.36 +import javax.sound.sampled.*;
317.37 +
317.38 +import com.sun.media.sound.*;
317.39 +
317.40 +public class SetSelfNonExclusive {
317.41 +
317.42 + public static void main(String[] args) throws Exception {
317.43 + ModelPerformer performer = new ModelPerformer();
317.44 + performer.setSelfNonExclusive(true);
317.45 + if(performer.isSelfNonExclusive() != true)
317.46 + throw new RuntimeException("performer.isSelfNonExclusive() didn't return true!");
317.47 + performer.setSelfNonExclusive(false);
317.48 + if(performer.isSelfNonExclusive() != false)
317.49 + throw new RuntimeException("performer.isSelfNonExclusive() didn't return false!");
317.50 + }
317.51 +}
318.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
318.2 +++ b/test/javax/sound/midi/Gervill/ModelPerformer/SetVelFrom.java Tue Feb 03 22:02:55 2009 -0800
318.3 @@ -0,0 +1,45 @@
318.4 +/*
318.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
318.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
318.7 + *
318.8 + * This code is free software; you can redistribute it and/or modify it
318.9 + * under the terms of the GNU General Public License version 2 only, as
318.10 + * published by the Free Software Foundation. Sun designates this
318.11 + * particular file as subject to the "Classpath" exception as provided
318.12 + * by Sun in the LICENSE file that accompanied this code.
318.13 + *
318.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
318.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
318.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
318.17 + * version 2 for more details (a copy is included in the LICENSE file that
318.18 + * accompanied this code).
318.19 + *
318.20 + * You should have received a copy of the GNU General Public License version
318.21 + * 2 along with this work; if not, write to the Free Software Foundation,
318.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
318.23 + *
318.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
318.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
318.26 + * have any questions.
318.27 + */
318.28 +
318.29 +/* @test
318.30 + @summary Test ModelPerformer setVelFrom method */
318.31 +
318.32 +import java.io.File;
318.33 +import java.io.FileOutputStream;
318.34 +import java.io.IOException;
318.35 +
318.36 +import javax.sound.sampled.*;
318.37 +
318.38 +import com.sun.media.sound.*;
318.39 +
318.40 +public class SetVelFrom {
318.41 +
318.42 + public static void main(String[] args) throws Exception {
318.43 + ModelPerformer performer = new ModelPerformer();
318.44 + performer.setVelFrom(10);
318.45 + if(performer.getVelFrom() != 10)
318.46 + throw new RuntimeException("performer.getVelFrom() didn't return 10!");
318.47 + }
318.48 +}
319.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
319.2 +++ b/test/javax/sound/midi/Gervill/ModelPerformer/SetVelTo.java Tue Feb 03 22:02:55 2009 -0800
319.3 @@ -0,0 +1,45 @@
319.4 +/*
319.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
319.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
319.7 + *
319.8 + * This code is free software; you can redistribute it and/or modify it
319.9 + * under the terms of the GNU General Public License version 2 only, as
319.10 + * published by the Free Software Foundation. Sun designates this
319.11 + * particular file as subject to the "Classpath" exception as provided
319.12 + * by Sun in the LICENSE file that accompanied this code.
319.13 + *
319.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
319.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
319.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
319.17 + * version 2 for more details (a copy is included in the LICENSE file that
319.18 + * accompanied this code).
319.19 + *
319.20 + * You should have received a copy of the GNU General Public License version
319.21 + * 2 along with this work; if not, write to the Free Software Foundation,
319.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
319.23 + *
319.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
319.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
319.26 + * have any questions.
319.27 + */
319.28 +
319.29 +/* @test
319.30 + @summary Test ModelPerformer setVelTo method */
319.31 +
319.32 +import java.io.File;
319.33 +import java.io.FileOutputStream;
319.34 +import java.io.IOException;
319.35 +
319.36 +import javax.sound.sampled.*;
319.37 +
319.38 +import com.sun.media.sound.*;
319.39 +
319.40 +public class SetVelTo {
319.41 +
319.42 + public static void main(String[] args) throws Exception {
319.43 + ModelPerformer performer = new ModelPerformer();
319.44 + performer.setVelTo(10);
319.45 + if(performer.getVelTo() != 10)
319.46 + throw new RuntimeException("performer.getVelTo() didn't return 10!");
319.47 + }
319.48 +}
320.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
320.2 +++ b/test/javax/sound/midi/Gervill/ModelSource/NewModelSource.java Tue Feb 03 22:02:55 2009 -0800
320.3 @@ -0,0 +1,48 @@
320.4 +/*
320.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
320.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
320.7 + *
320.8 + * This code is free software; you can redistribute it and/or modify it
320.9 + * under the terms of the GNU General Public License version 2 only, as
320.10 + * published by the Free Software Foundation. Sun designates this
320.11 + * particular file as subject to the "Classpath" exception as provided
320.12 + * by Sun in the LICENSE file that accompanied this code.
320.13 + *
320.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
320.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
320.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
320.17 + * version 2 for more details (a copy is included in the LICENSE file that
320.18 + * accompanied this code).
320.19 + *
320.20 + * You should have received a copy of the GNU General Public License version
320.21 + * 2 along with this work; if not, write to the Free Software Foundation,
320.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
320.23 + *
320.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
320.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
320.26 + * have any questions.
320.27 + */
320.28 +
320.29 +/* @test
320.30 + @summary Test ModelSource() constructor */
320.31 +
320.32 +import java.io.File;
320.33 +import java.io.FileOutputStream;
320.34 +import java.io.IOException;
320.35 +
320.36 +import javax.sound.sampled.*;
320.37 +
320.38 +import com.sun.media.sound.*;
320.39 +
320.40 +public class NewModelSource {
320.41 +
320.42 + public static void main(String[] args) throws Exception {
320.43 + ModelSource src = new ModelSource();
320.44 + if(src.getIdentifier() != ModelSource.SOURCE_NONE)
320.45 + throw new RuntimeException("src.getIdentifier() doesn't return ModelSource.SOURCE_NONE!");
320.46 + if(!(src.getTransform() instanceof ModelStandardTransform))
320.47 + throw new RuntimeException("src.getTransform() doesn't return object which is instance of ModelStandardTransform!");
320.48 +
320.49 +
320.50 + }
320.51 +}
321.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
321.2 +++ b/test/javax/sound/midi/Gervill/ModelSource/NewModelSourceModelIdentifier.java Tue Feb 03 22:02:55 2009 -0800
321.3 @@ -0,0 +1,46 @@
321.4 +/*
321.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
321.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
321.7 + *
321.8 + * This code is free software; you can redistribute it and/or modify it
321.9 + * under the terms of the GNU General Public License version 2 only, as
321.10 + * published by the Free Software Foundation. Sun designates this
321.11 + * particular file as subject to the "Classpath" exception as provided
321.12 + * by Sun in the LICENSE file that accompanied this code.
321.13 + *
321.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
321.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
321.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
321.17 + * version 2 for more details (a copy is included in the LICENSE file that
321.18 + * accompanied this code).
321.19 + *
321.20 + * You should have received a copy of the GNU General Public License version
321.21 + * 2 along with this work; if not, write to the Free Software Foundation,
321.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
321.23 + *
321.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
321.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
321.26 + * have any questions.
321.27 + */
321.28 +
321.29 +/* @test
321.30 + @summary Test ModelSource(ModelIdentifier) constructor */
321.31 +
321.32 +import java.io.File;
321.33 +import java.io.FileOutputStream;
321.34 +import java.io.IOException;
321.35 +
321.36 +import javax.sound.sampled.*;
321.37 +
321.38 +import com.sun.media.sound.*;
321.39 +
321.40 +public class NewModelSourceModelIdentifier {
321.41 +
321.42 + public static void main(String[] args) throws Exception {
321.43 + ModelSource src = new ModelSource(ModelSource.SOURCE_NOTEON_KEYNUMBER);
321.44 + if(src.getIdentifier() != ModelSource.SOURCE_NOTEON_KEYNUMBER)
321.45 + throw new RuntimeException("src.getIdentifier() doesn't return ModelSource.SOURCE_NOTEON_KEYNUMBER!");
321.46 + if(!(src.getTransform() instanceof ModelStandardTransform))
321.47 + throw new RuntimeException("src.getTransform() doesn't return object which is instance of ModelStandardTransform!");
321.48 + }
321.49 +}
322.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
322.2 +++ b/test/javax/sound/midi/Gervill/ModelSource/NewModelSourceModelIdentifierBoolean.java Tue Feb 03 22:02:55 2009 -0800
322.3 @@ -0,0 +1,49 @@
322.4 +/*
322.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
322.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
322.7 + *
322.8 + * This code is free software; you can redistribute it and/or modify it
322.9 + * under the terms of the GNU General Public License version 2 only, as
322.10 + * published by the Free Software Foundation. Sun designates this
322.11 + * particular file as subject to the "Classpath" exception as provided
322.12 + * by Sun in the LICENSE file that accompanied this code.
322.13 + *
322.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
322.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
322.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
322.17 + * version 2 for more details (a copy is included in the LICENSE file that
322.18 + * accompanied this code).
322.19 + *
322.20 + * You should have received a copy of the GNU General Public License version
322.21 + * 2 along with this work; if not, write to the Free Software Foundation,
322.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
322.23 + *
322.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
322.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
322.26 + * have any questions.
322.27 + */
322.28 +
322.29 +/* @test
322.30 + @summary Test ModelSource(ModelIdentifier,boolean) constructor */
322.31 +
322.32 +import java.io.File;
322.33 +import java.io.FileOutputStream;
322.34 +import java.io.IOException;
322.35 +
322.36 +import javax.sound.sampled.*;
322.37 +
322.38 +import com.sun.media.sound.*;
322.39 +
322.40 +public class NewModelSourceModelIdentifierBoolean {
322.41 +
322.42 + public static void main(String[] args) throws Exception {
322.43 + ModelSource src = new ModelSource(ModelSource.SOURCE_NOTEON_KEYNUMBER,ModelStandardTransform.DIRECTION_MAX2MIN);
322.44 + if(src.getIdentifier() != ModelSource.SOURCE_NOTEON_KEYNUMBER)
322.45 + throw new RuntimeException("src.getIdentifier() doesn't return ModelSource.SOURCE_NOTEON_KEYNUMBER!");
322.46 + if(!(src.getTransform() instanceof ModelStandardTransform))
322.47 + throw new RuntimeException("src.getTransform() doesn't return object which is instance of ModelStandardTransform!");
322.48 + ModelStandardTransform trans = (ModelStandardTransform)src.getTransform();
322.49 + if(trans.getDirection() != ModelStandardTransform.DIRECTION_MAX2MIN)
322.50 + throw new RuntimeException("trans.getDirection() doesn't return ModelStandardTransform.DIRECTION_MAX2MIN!");
322.51 + }
322.52 +}
323.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
323.2 +++ b/test/javax/sound/midi/Gervill/ModelSource/NewModelSourceModelIdentifierBooleanBoolean.java Tue Feb 03 22:02:55 2009 -0800
323.3 @@ -0,0 +1,51 @@
323.4 +/*
323.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
323.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
323.7 + *
323.8 + * This code is free software; you can redistribute it and/or modify it
323.9 + * under the terms of the GNU General Public License version 2 only, as
323.10 + * published by the Free Software Foundation. Sun designates this
323.11 + * particular file as subject to the "Classpath" exception as provided
323.12 + * by Sun in the LICENSE file that accompanied this code.
323.13 + *
323.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
323.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
323.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
323.17 + * version 2 for more details (a copy is included in the LICENSE file that
323.18 + * accompanied this code).
323.19 + *
323.20 + * You should have received a copy of the GNU General Public License version
323.21 + * 2 along with this work; if not, write to the Free Software Foundation,
323.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
323.23 + *
323.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
323.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
323.26 + * have any questions.
323.27 + */
323.28 +
323.29 +/* @test
323.30 + @summary Test ModelSource(ModelIdentifier,boolean,boolean) constructor */
323.31 +
323.32 +import java.io.File;
323.33 +import java.io.FileOutputStream;
323.34 +import java.io.IOException;
323.35 +
323.36 +import javax.sound.sampled.*;
323.37 +
323.38 +import com.sun.media.sound.*;
323.39 +
323.40 +public class NewModelSourceModelIdentifierBooleanBoolean {
323.41 +
323.42 + public static void main(String[] args) throws Exception {
323.43 + ModelSource src = new ModelSource(ModelSource.SOURCE_NOTEON_KEYNUMBER,ModelStandardTransform.DIRECTION_MAX2MIN,ModelStandardTransform.POLARITY_BIPOLAR);
323.44 + if(src.getIdentifier() != ModelSource.SOURCE_NOTEON_KEYNUMBER)
323.45 + throw new RuntimeException("src.getIdentifier() doesn't return ModelSource.SOURCE_NOTEON_KEYNUMBER!");
323.46 + if(!(src.getTransform() instanceof ModelStandardTransform))
323.47 + throw new RuntimeException("src.getTransform() doesn't return object which is instance of ModelStandardTransform!");
323.48 + ModelStandardTransform trans = (ModelStandardTransform)src.getTransform();
323.49 + if(trans.getDirection() != ModelStandardTransform.DIRECTION_MAX2MIN)
323.50 + throw new RuntimeException("trans.getDirection() doesn't return ModelStandardTransform.DIRECTION_MAX2MIN!");
323.51 + if(trans.getPolarity() != ModelStandardTransform.POLARITY_BIPOLAR)
323.52 + throw new RuntimeException("trans.getPolarity() doesn't return ModelStandardTransform.POLARITY_BIPOLAR!");
323.53 + }
323.54 +}
324.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
324.2 +++ b/test/javax/sound/midi/Gervill/ModelSource/NewModelSourceModelIdentifierBooleanBooleanInt.java Tue Feb 03 22:02:55 2009 -0800
324.3 @@ -0,0 +1,56 @@
324.4 +/*
324.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
324.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
324.7 + *
324.8 + * This code is free software; you can redistribute it and/or modify it
324.9 + * under the terms of the GNU General Public License version 2 only, as
324.10 + * published by the Free Software Foundation. Sun designates this
324.11 + * particular file as subject to the "Classpath" exception as provided
324.12 + * by Sun in the LICENSE file that accompanied this code.
324.13 + *
324.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
324.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
324.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
324.17 + * version 2 for more details (a copy is included in the LICENSE file that
324.18 + * accompanied this code).
324.19 + *
324.20 + * You should have received a copy of the GNU General Public License version
324.21 + * 2 along with this work; if not, write to the Free Software Foundation,
324.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
324.23 + *
324.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
324.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
324.26 + * have any questions.
324.27 + */
324.28 +
324.29 +/* @test
324.30 + @summary Test ModelSource(ModelIdentifier,boolean,boolean,int) constructor */
324.31 +
324.32 +import java.io.File;
324.33 +import java.io.FileOutputStream;
324.34 +import java.io.IOException;
324.35 +
324.36 +import javax.sound.sampled.*;
324.37 +
324.38 +import com.sun.media.sound.*;
324.39 +
324.40 +public class NewModelSourceModelIdentifierBooleanBooleanInt {
324.41 +
324.42 + public static void main(String[] args) throws Exception {
324.43 + ModelSource src = new ModelSource(ModelSource.SOURCE_NOTEON_KEYNUMBER,
324.44 + ModelStandardTransform.DIRECTION_MAX2MIN,
324.45 + ModelStandardTransform.POLARITY_BIPOLAR,
324.46 + ModelStandardTransform.TRANSFORM_CONCAVE);
324.47 + if(src.getIdentifier() != ModelSource.SOURCE_NOTEON_KEYNUMBER)
324.48 + throw new RuntimeException("src.getIdentifier() doesn't return ModelSource.SOURCE_NOTEON_KEYNUMBER!");
324.49 + if(!(src.getTransform() instanceof ModelStandardTransform))
324.50 + throw new RuntimeException("src.getTransform() doesn't return object which is instance of ModelStandardTransform!");
324.51 + ModelStandardTransform trans = (ModelStandardTransform)src.getTransform();
324.52 + if(trans.getDirection() != ModelStandardTransform.DIRECTION_MAX2MIN)
324.53 + throw new RuntimeException("trans.getDirection() doesn't return ModelStandardTransform.DIRECTION_MAX2MIN!");
324.54 + if(trans.getPolarity() != ModelStandardTransform.POLARITY_BIPOLAR)
324.55 + throw new RuntimeException("trans.getPolarity() doesn't return ModelStandardTransform.POLARITY_BIPOLAR!");
324.56 + if(trans.getTransform() != ModelStandardTransform.TRANSFORM_CONCAVE)
324.57 + throw new RuntimeException("trans.getTransform() doesn't return ModelStandardTransform.TRANSFORM_CONCAVE!");
324.58 + }
324.59 +}
325.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
325.2 +++ b/test/javax/sound/midi/Gervill/ModelSource/NewModelSourceModelIdentifierModelTransform.java Tue Feb 03 22:02:55 2009 -0800
325.3 @@ -0,0 +1,47 @@
325.4 +/*
325.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
325.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325.7 + *
325.8 + * This code is free software; you can redistribute it and/or modify it
325.9 + * under the terms of the GNU General Public License version 2 only, as
325.10 + * published by the Free Software Foundation. Sun designates this
325.11 + * particular file as subject to the "Classpath" exception as provided
325.12 + * by Sun in the LICENSE file that accompanied this code.
325.13 + *
325.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
325.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325.17 + * version 2 for more details (a copy is included in the LICENSE file that
325.18 + * accompanied this code).
325.19 + *
325.20 + * You should have received a copy of the GNU General Public License version
325.21 + * 2 along with this work; if not, write to the Free Software Foundation,
325.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325.23 + *
325.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
325.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
325.26 + * have any questions.
325.27 + */
325.28 +
325.29 +/* @test
325.30 + @summary Test ModelSource(ModelIdentifier,ModelTransform) constructor */
325.31 +
325.32 +import java.io.File;
325.33 +import java.io.FileOutputStream;
325.34 +import java.io.IOException;
325.35 +
325.36 +import javax.sound.sampled.*;
325.37 +
325.38 +import com.sun.media.sound.*;
325.39 +
325.40 +public class NewModelSourceModelIdentifierModelTransform {
325.41 +
325.42 + public static void main(String[] args) throws Exception {
325.43 + ModelStandardTransform trans = new ModelStandardTransform();
325.44 + ModelSource src = new ModelSource(ModelSource.SOURCE_NOTEON_KEYNUMBER, trans);
325.45 + if(src.getIdentifier() != ModelSource.SOURCE_NOTEON_KEYNUMBER)
325.46 + throw new RuntimeException("src.getIdentifier() doesn't return ModelSource.SOURCE_NOTEON_KEYNUMBER!");
325.47 + if(src.getTransform() != trans)
325.48 + throw new RuntimeException("src.getTransform() doesn't return trans!");
325.49 + }
325.50 +}
326.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
326.2 +++ b/test/javax/sound/midi/Gervill/ModelSource/SetIdentifier.java Tue Feb 03 22:02:55 2009 -0800
326.3 @@ -0,0 +1,45 @@
326.4 +/*
326.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
326.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
326.7 + *
326.8 + * This code is free software; you can redistribute it and/or modify it
326.9 + * under the terms of the GNU General Public License version 2 only, as
326.10 + * published by the Free Software Foundation. Sun designates this
326.11 + * particular file as subject to the "Classpath" exception as provided
326.12 + * by Sun in the LICENSE file that accompanied this code.
326.13 + *
326.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
326.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
326.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
326.17 + * version 2 for more details (a copy is included in the LICENSE file that
326.18 + * accompanied this code).
326.19 + *
326.20 + * You should have received a copy of the GNU General Public License version
326.21 + * 2 along with this work; if not, write to the Free Software Foundation,
326.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
326.23 + *
326.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
326.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
326.26 + * have any questions.
326.27 + */
326.28 +
326.29 +/* @test
326.30 + @summary Test ModelSource setIdentifier method */
326.31 +
326.32 +import java.io.File;
326.33 +import java.io.FileOutputStream;
326.34 +import java.io.IOException;
326.35 +
326.36 +import javax.sound.sampled.*;
326.37 +
326.38 +import com.sun.media.sound.*;
326.39 +
326.40 +public class SetIdentifier {
326.41 +
326.42 + public static void main(String[] args) throws Exception {
326.43 + ModelSource src = new ModelSource();
326.44 + src.setIdentifier(ModelSource.SOURCE_NOTEON_KEYNUMBER);
326.45 + if(src.getIdentifier() != ModelSource.SOURCE_NOTEON_KEYNUMBER)
326.46 + throw new RuntimeException("src.getIdentifier() doesn't return ModelSource.SOURCE_NOTEON_KEYNUMBER!");
326.47 + }
326.48 +}
327.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
327.2 +++ b/test/javax/sound/midi/Gervill/ModelSource/SetTransform.java Tue Feb 03 22:02:55 2009 -0800
327.3 @@ -0,0 +1,46 @@
327.4 +/*
327.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
327.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
327.7 + *
327.8 + * This code is free software; you can redistribute it and/or modify it
327.9 + * under the terms of the GNU General Public License version 2 only, as
327.10 + * published by the Free Software Foundation. Sun designates this
327.11 + * particular file as subject to the "Classpath" exception as provided
327.12 + * by Sun in the LICENSE file that accompanied this code.
327.13 + *
327.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
327.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
327.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
327.17 + * version 2 for more details (a copy is included in the LICENSE file that
327.18 + * accompanied this code).
327.19 + *
327.20 + * You should have received a copy of the GNU General Public License version
327.21 + * 2 along with this work; if not, write to the Free Software Foundation,
327.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
327.23 + *
327.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
327.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
327.26 + * have any questions.
327.27 + */
327.28 +
327.29 +/* @test
327.30 + @summary Test ModelSource setTransform method */
327.31 +
327.32 +import java.io.File;
327.33 +import java.io.FileOutputStream;
327.34 +import java.io.IOException;
327.35 +
327.36 +import javax.sound.sampled.*;
327.37 +
327.38 +import com.sun.media.sound.*;
327.39 +
327.40 +public class SetTransform {
327.41 +
327.42 + public static void main(String[] args) throws Exception {
327.43 + ModelSource src = new ModelSource();
327.44 + ModelStandardTransform trans = new ModelStandardTransform();
327.45 + src.setTransform(trans);
327.46 + if(src.getTransform() != trans)
327.47 + throw new RuntimeException("src.getTransform() doesn't return trans!");
327.48 + }
327.49 +}
328.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
328.2 +++ b/test/javax/sound/midi/Gervill/ModelStandardTransform/NewModelStandardTransform.java Tue Feb 03 22:02:55 2009 -0800
328.3 @@ -0,0 +1,48 @@
328.4 +/*
328.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
328.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
328.7 + *
328.8 + * This code is free software; you can redistribute it and/or modify it
328.9 + * under the terms of the GNU General Public License version 2 only, as
328.10 + * published by the Free Software Foundation. Sun designates this
328.11 + * particular file as subject to the "Classpath" exception as provided
328.12 + * by Sun in the LICENSE file that accompanied this code.
328.13 + *
328.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
328.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
328.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
328.17 + * version 2 for more details (a copy is included in the LICENSE file that
328.18 + * accompanied this code).
328.19 + *
328.20 + * You should have received a copy of the GNU General Public License version
328.21 + * 2 along with this work; if not, write to the Free Software Foundation,
328.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
328.23 + *
328.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
328.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
328.26 + * have any questions.
328.27 + */
328.28 +
328.29 +/* @test
328.30 + @summary Test ModelStandardTransform constructor */
328.31 +
328.32 +import java.io.File;
328.33 +import java.io.FileOutputStream;
328.34 +import java.io.IOException;
328.35 +
328.36 +import javax.sound.sampled.*;
328.37 +
328.38 +import com.sun.media.sound.*;
328.39 +
328.40 +public class NewModelStandardTransform {
328.41 +
328.42 + public static void main(String[] args) throws Exception {
328.43 + ModelStandardTransform transform = new ModelStandardTransform();
328.44 + if(transform.getDirection() != ModelStandardTransform.DIRECTION_MIN2MAX)
328.45 + throw new RuntimeException("transform.getDirection() doesn't return ModelStandardTransform.DIRECTION_MIN2MAX!");
328.46 + if(transform.getPolarity() != ModelStandardTransform.POLARITY_UNIPOLAR)
328.47 + throw new RuntimeException("transform.getPolarity() doesn't return ModelStandardTransform.POLARITY_UNIPOLAR!");
328.48 + if(transform.getTransform() != ModelStandardTransform.TRANSFORM_LINEAR)
328.49 + throw new RuntimeException("transform.getTransform() doesn't return ModelStandardTransform.TRANSFORM_LINEAR!");
328.50 + }
328.51 +}
329.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
329.2 +++ b/test/javax/sound/midi/Gervill/ModelStandardTransform/NewModelStandardTransformBoolean.java Tue Feb 03 22:02:55 2009 -0800
329.3 @@ -0,0 +1,48 @@
329.4 +/*
329.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
329.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
329.7 + *
329.8 + * This code is free software; you can redistribute it and/or modify it
329.9 + * under the terms of the GNU General Public License version 2 only, as
329.10 + * published by the Free Software Foundation. Sun designates this
329.11 + * particular file as subject to the "Classpath" exception as provided
329.12 + * by Sun in the LICENSE file that accompanied this code.
329.13 + *
329.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
329.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
329.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
329.17 + * version 2 for more details (a copy is included in the LICENSE file that
329.18 + * accompanied this code).
329.19 + *
329.20 + * You should have received a copy of the GNU General Public License version
329.21 + * 2 along with this work; if not, write to the Free Software Foundation,
329.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
329.23 + *
329.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
329.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
329.26 + * have any questions.
329.27 + */
329.28 +
329.29 +/* @test
329.30 + @summary Test ModelStandardTransform(boolean) constructor */
329.31 +
329.32 +import java.io.File;
329.33 +import java.io.FileOutputStream;
329.34 +import java.io.IOException;
329.35 +
329.36 +import javax.sound.sampled.*;
329.37 +
329.38 +import com.sun.media.sound.*;
329.39 +
329.40 +public class NewModelStandardTransformBoolean {
329.41 +
329.42 + public static void main(String[] args) throws Exception {
329.43 + ModelStandardTransform transform = new ModelStandardTransform(ModelStandardTransform.DIRECTION_MAX2MIN);
329.44 + if(transform.getDirection() != ModelStandardTransform.DIRECTION_MAX2MIN)
329.45 + throw new RuntimeException("transform.getDirection() doesn't return ModelStandardTransform.DIRECTION_MAX2MIN!");
329.46 + if(transform.getPolarity() != ModelStandardTransform.POLARITY_UNIPOLAR)
329.47 + throw new RuntimeException("transform.getPolarity() doesn't return ModelStandardTransform.POLARITY_UNIPOLAR!");
329.48 + if(transform.getTransform() != ModelStandardTransform.TRANSFORM_LINEAR)
329.49 + throw new RuntimeException("transform.getTransform() doesn't return ModelStandardTransform.TRANSFORM_LINEAR!");
329.50 + }
329.51 +}
330.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
330.2 +++ b/test/javax/sound/midi/Gervill/ModelStandardTransform/NewModelStandardTransformBooleanBoolean.java Tue Feb 03 22:02:55 2009 -0800
330.3 @@ -0,0 +1,50 @@
330.4 +/*
330.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
330.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
330.7 + *
330.8 + * This code is free software; you can redistribute it and/or modify it
330.9 + * under the terms of the GNU General Public License version 2 only, as
330.10 + * published by the Free Software Foundation. Sun designates this
330.11 + * particular file as subject to the "Classpath" exception as provided
330.12 + * by Sun in the LICENSE file that accompanied this code.
330.13 + *
330.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
330.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
330.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
330.17 + * version 2 for more details (a copy is included in the LICENSE file that
330.18 + * accompanied this code).
330.19 + *
330.20 + * You should have received a copy of the GNU General Public License version
330.21 + * 2 along with this work; if not, write to the Free Software Foundation,
330.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
330.23 + *
330.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
330.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
330.26 + * have any questions.
330.27 + */
330.28 +
330.29 +/* @test
330.30 + @summary Test ModelStandardTransform(boolean,boolean) constructor */
330.31 +
330.32 +import java.io.File;
330.33 +import java.io.FileOutputStream;
330.34 +import java.io.IOException;
330.35 +
330.36 +import javax.sound.sampled.*;
330.37 +
330.38 +import com.sun.media.sound.*;
330.39 +
330.40 +public class NewModelStandardTransformBooleanBoolean {
330.41 +
330.42 + public static void main(String[] args) throws Exception {
330.43 + ModelStandardTransform transform = new ModelStandardTransform(
330.44 + ModelStandardTransform.DIRECTION_MAX2MIN,
330.45 + ModelStandardTransform.POLARITY_BIPOLAR);
330.46 + if(transform.getDirection() != ModelStandardTransform.DIRECTION_MAX2MIN)
330.47 + throw new RuntimeException("transform.getDirection() doesn't return ModelStandardTransform.DIRECTION_MAX2MIN!");
330.48 + if(transform.getPolarity() != ModelStandardTransform.POLARITY_BIPOLAR)
330.49 + throw new RuntimeException("transform.getPolarity() doesn't return ModelStandardTransform.POLARITY_BIPOLAR!");
330.50 + if(transform.getTransform() != ModelStandardTransform.TRANSFORM_LINEAR)
330.51 + throw new RuntimeException("transform.getTransform() doesn't return ModelStandardTransform.TRANSFORM_LINEAR!");
330.52 + }
330.53 +}
331.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
331.2 +++ b/test/javax/sound/midi/Gervill/ModelStandardTransform/NewModelStandardTransformBooleanBooleanInt.java Tue Feb 03 22:02:55 2009 -0800
331.3 @@ -0,0 +1,51 @@
331.4 +/*
331.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
331.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
331.7 + *
331.8 + * This code is free software; you can redistribute it and/or modify it
331.9 + * under the terms of the GNU General Public License version 2 only, as
331.10 + * published by the Free Software Foundation. Sun designates this
331.11 + * particular file as subject to the "Classpath" exception as provided
331.12 + * by Sun in the LICENSE file that accompanied this code.
331.13 + *
331.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
331.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
331.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
331.17 + * version 2 for more details (a copy is included in the LICENSE file that
331.18 + * accompanied this code).
331.19 + *
331.20 + * You should have received a copy of the GNU General Public License version
331.21 + * 2 along with this work; if not, write to the Free Software Foundation,
331.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
331.23 + *
331.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
331.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
331.26 + * have any questions.
331.27 + */
331.28 +
331.29 +/* @test
331.30 + @summary Test ModelStandardTransform(boolean,boolean,int) constructor */
331.31 +
331.32 +import java.io.File;
331.33 +import java.io.FileOutputStream;
331.34 +import java.io.IOException;
331.35 +
331.36 +import javax.sound.sampled.*;
331.37 +
331.38 +import com.sun.media.sound.*;
331.39 +
331.40 +public class NewModelStandardTransformBooleanBooleanInt {
331.41 +
331.42 + public static void main(String[] args) throws Exception {
331.43 + ModelStandardTransform transform = new ModelStandardTransform(
331.44 + ModelStandardTransform.DIRECTION_MAX2MIN,
331.45 + ModelStandardTransform.POLARITY_BIPOLAR,
331.46 + ModelStandardTransform.TRANSFORM_CONVEX);
331.47 + if(transform.getDirection() != ModelStandardTransform.DIRECTION_MAX2MIN)
331.48 + throw new RuntimeException("transform.getDirection() doesn't return ModelStandardTransform.DIRECTION_MAX2MIN!");
331.49 + if(transform.getPolarity() != ModelStandardTransform.POLARITY_BIPOLAR)
331.50 + throw new RuntimeException("transform.getPolarity() doesn't return ModelStandardTransform.POLARITY_BIPOLAR!");
331.51 + if(transform.getTransform() != ModelStandardTransform.TRANSFORM_CONVEX)
331.52 + throw new RuntimeException("transform.getTransform() doesn't return ModelStandardTransform.TRANSFORM_CONVEX!");
331.53 + }
331.54 +}
332.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
332.2 +++ b/test/javax/sound/midi/Gervill/ModelStandardTransform/SetDirection.java Tue Feb 03 22:02:55 2009 -0800
332.3 @@ -0,0 +1,45 @@
332.4 +/*
332.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
332.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
332.7 + *
332.8 + * This code is free software; you can redistribute it and/or modify it
332.9 + * under the terms of the GNU General Public License version 2 only, as
332.10 + * published by the Free Software Foundation. Sun designates this
332.11 + * particular file as subject to the "Classpath" exception as provided
332.12 + * by Sun in the LICENSE file that accompanied this code.
332.13 + *
332.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
332.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
332.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
332.17 + * version 2 for more details (a copy is included in the LICENSE file that
332.18 + * accompanied this code).
332.19 + *
332.20 + * You should have received a copy of the GNU General Public License version
332.21 + * 2 along with this work; if not, write to the Free Software Foundation,
332.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
332.23 + *
332.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
332.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
332.26 + * have any questions.
332.27 + */
332.28 +
332.29 +/* @test
332.30 + @summary Test ModelStandardTransform setDirection method */
332.31 +
332.32 +import java.io.File;
332.33 +import java.io.FileOutputStream;
332.34 +import java.io.IOException;
332.35 +
332.36 +import javax.sound.sampled.*;
332.37 +
332.38 +import com.sun.media.sound.*;
332.39 +
332.40 +public class SetDirection {
332.41 +
332.42 + public static void main(String[] args) throws Exception {
332.43 + ModelStandardTransform transform = new ModelStandardTransform();
332.44 + transform.setDirection(ModelStandardTransform.DIRECTION_MAX2MIN);
332.45 + if(transform.getDirection() != ModelStandardTransform.DIRECTION_MAX2MIN)
332.46 + throw new RuntimeException("transform.getDirection() doesn't return ModelStandardTransform.DIRECTION_MAX2MIN!");
332.47 + }
332.48 +}
333.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
333.2 +++ b/test/javax/sound/midi/Gervill/ModelStandardTransform/SetPolarity.java Tue Feb 03 22:02:55 2009 -0800
333.3 @@ -0,0 +1,45 @@
333.4 +/*
333.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
333.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
333.7 + *
333.8 + * This code is free software; you can redistribute it and/or modify it
333.9 + * under the terms of the GNU General Public License version 2 only, as
333.10 + * published by the Free Software Foundation. Sun designates this
333.11 + * particular file as subject to the "Classpath" exception as provided
333.12 + * by Sun in the LICENSE file that accompanied this code.
333.13 + *
333.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
333.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
333.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
333.17 + * version 2 for more details (a copy is included in the LICENSE file that
333.18 + * accompanied this code).
333.19 + *
333.20 + * You should have received a copy of the GNU General Public License version
333.21 + * 2 along with this work; if not, write to the Free Software Foundation,
333.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
333.23 + *
333.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
333.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
333.26 + * have any questions.
333.27 + */
333.28 +
333.29 +/* @test
333.30 + @summary Test ModelStandardTransform setPolarity method */
333.31 +
333.32 +import java.io.File;
333.33 +import java.io.FileOutputStream;
333.34 +import java.io.IOException;
333.35 +
333.36 +import javax.sound.sampled.*;
333.37 +
333.38 +import com.sun.media.sound.*;
333.39 +
333.40 +public class SetPolarity {
333.41 +
333.42 + public static void main(String[] args) throws Exception {
333.43 + ModelStandardTransform transform = new ModelStandardTransform();
333.44 + transform.setPolarity(ModelStandardTransform.POLARITY_BIPOLAR);
333.45 + if(transform.getPolarity() != ModelStandardTransform.POLARITY_BIPOLAR)
333.46 + throw new RuntimeException("transform.getPolarity() doesn't return ModelStandardTransform.POLARITY_BIPOLAR!");
333.47 + }
333.48 +}
334.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
334.2 +++ b/test/javax/sound/midi/Gervill/ModelStandardTransform/SetTransform.java Tue Feb 03 22:02:55 2009 -0800
334.3 @@ -0,0 +1,74 @@
334.4 +/*
334.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
334.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
334.7 + *
334.8 + * This code is free software; you can redistribute it and/or modify it
334.9 + * under the terms of the GNU General Public License version 2 only, as
334.10 + * published by the Free Software Foundation. Sun designates this
334.11 + * particular file as subject to the "Classpath" exception as provided
334.12 + * by Sun in the LICENSE file that accompanied this code.
334.13 + *
334.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
334.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
334.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
334.17 + * version 2 for more details (a copy is included in the LICENSE file that
334.18 + * accompanied this code).
334.19 + *
334.20 + * You should have received a copy of the GNU General Public License version
334.21 + * 2 along with this work; if not, write to the Free Software Foundation,
334.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
334.23 + *
334.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
334.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
334.26 + * have any questions.
334.27 + */
334.28 +
334.29 +/* @test
334.30 + @summary Test ModelStandardTransform setTransform method */
334.31 +
334.32 +import java.io.File;
334.33 +import java.io.FileOutputStream;
334.34 +import java.io.IOException;
334.35 +
334.36 +import javax.sound.sampled.*;
334.37 +
334.38 +import com.sun.media.sound.*;
334.39 +
334.40 +public class SetTransform {
334.41 +
334.42 +
334.43 + private static boolean checkLinearity(ModelStandardTransform transform)
334.44 + {
334.45 + double lastx = 0;
334.46 + for (int p = 0; p < 2; p++)
334.47 + for (int d = 0; d < 2; d++)
334.48 + for (double i = 0; i < 1.0; i+=0.001) {
334.49 + if(p == 0)
334.50 + transform.setPolarity(ModelStandardTransform.POLARITY_UNIPOLAR);
334.51 + else
334.52 + transform.setPolarity(ModelStandardTransform.POLARITY_BIPOLAR);
334.53 + if(d == 0)
334.54 + transform.setDirection(ModelStandardTransform.DIRECTION_MIN2MAX);
334.55 + else
334.56 + transform.setDirection(ModelStandardTransform.DIRECTION_MAX2MIN);
334.57 + double x = transform.transform(i);
334.58 + if(i == 0)
334.59 + lastx = x;
334.60 + else
334.61 + {
334.62 + if(lastx - x > 0.2) return false;
334.63 + lastx = x;
334.64 + }
334.65 + }
334.66 + return true;
334.67 + }
334.68 +
334.69 +
334.70 + public static void main(String[] args) throws Exception {
334.71 + ModelStandardTransform transform = new ModelStandardTransform();
334.72 + transform.setTransform(ModelStandardTransform.TRANSFORM_CONVEX);
334.73 + if(transform.getTransform() != ModelStandardTransform.TRANSFORM_CONVEX)
334.74 + throw new RuntimeException("transform.getTransform() doesn't return ModelStandardTransform.TRANSFORM_CONVEX!");
334.75 +
334.76 + }
334.77 +}
335.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
335.2 +++ b/test/javax/sound/midi/Gervill/ModelStandardTransform/TransformAbsolute.java Tue Feb 03 22:02:55 2009 -0800
335.3 @@ -0,0 +1,73 @@
335.4 +/*
335.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
335.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
335.7 + *
335.8 + * This code is free software; you can redistribute it and/or modify it
335.9 + * under the terms of the GNU General Public License version 2 only, as
335.10 + * published by the Free Software Foundation. Sun designates this
335.11 + * particular file as subject to the "Classpath" exception as provided
335.12 + * by Sun in the LICENSE file that accompanied this code.
335.13 + *
335.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
335.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
335.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
335.17 + * version 2 for more details (a copy is included in the LICENSE file that
335.18 + * accompanied this code).
335.19 + *
335.20 + * You should have received a copy of the GNU General Public License version
335.21 + * 2 along with this work; if not, write to the Free Software Foundation,
335.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
335.23 + *
335.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
335.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
335.26 + * have any questions.
335.27 + */
335.28 +
335.29 +/* @test
335.30 + @summary Test ModelStandardTransform transform method */
335.31 +
335.32 +import com.sun.media.sound.ModelStandardTransform;
335.33 +
335.34 +public class TransformAbsolute {
335.35 +
335.36 + private static boolean checkLinearity(ModelStandardTransform transform)
335.37 + {
335.38 + double lastx = 0;
335.39 + for (int p = 0; p < 2; p++)
335.40 + for (int d = 0; d < 2; d++)
335.41 + for (double i = 0; i < 1.0; i+=0.001) {
335.42 + if(p == 0)
335.43 + transform.setPolarity(ModelStandardTransform.POLARITY_UNIPOLAR);
335.44 + else
335.45 + transform.setPolarity(ModelStandardTransform.POLARITY_BIPOLAR);
335.46 + if(d == 0)
335.47 + transform.setDirection(ModelStandardTransform.DIRECTION_MIN2MAX);
335.48 + else
335.49 + transform.setDirection(ModelStandardTransform.DIRECTION_MAX2MIN);
335.50 + double x = transform.transform(i);
335.51 + if(i == 0)
335.52 + lastx = x;
335.53 + else
335.54 + {
335.55 + if(lastx - x > 0.2) return false;
335.56 + lastx = x;
335.57 + }
335.58 + }
335.59 + return true;
335.60 + }
335.61 +
335.62 + private static void assertTrue(boolean value) throws Exception
335.63 + {
335.64 + if(!value)
335.65 + throw new RuntimeException("assertTrue fails!");
335.66 +
335.67 + }
335.68 +
335.69 + public static void main(String[] args) throws Exception {
335.70 + ModelStandardTransform transform = new ModelStandardTransform();
335.71 + transform.setTransform(ModelStandardTransform.TRANSFORM_ABSOLUTE);
335.72 + assertTrue(Math.abs(transform.transform(0.2f) - 0.2f) < 0.0001f);
335.73 + assertTrue(Math.abs(transform.transform(-0.8f) - 0.8f) < 0.0001f);
335.74 + assertTrue(checkLinearity(transform));
335.75 + }
335.76 +}
336.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
336.2 +++ b/test/javax/sound/midi/Gervill/ModelStandardTransform/TransformConcave.java Tue Feb 03 22:02:55 2009 -0800
336.3 @@ -0,0 +1,98 @@
336.4 +/*
336.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
336.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
336.7 + *
336.8 + * This code is free software; you can redistribute it and/or modify it
336.9 + * under the terms of the GNU General Public License version 2 only, as
336.10 + * published by the Free Software Foundation. Sun designates this
336.11 + * particular file as subject to the "Classpath" exception as provided
336.12 + * by Sun in the LICENSE file that accompanied this code.
336.13 + *
336.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
336.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
336.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
336.17 + * version 2 for more details (a copy is included in the LICENSE file that
336.18 + * accompanied this code).
336.19 + *
336.20 + * You should have received a copy of the GNU General Public License version
336.21 + * 2 along with this work; if not, write to the Free Software Foundation,
336.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
336.23 + *
336.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
336.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
336.26 + * have any questions.
336.27 + */
336.28 +
336.29 +/* @test
336.30 + @summary Test ModelStandardTransform transform method */
336.31 +
336.32 +import com.sun.media.sound.ModelStandardTransform;
336.33 +
336.34 +public class TransformConcave {
336.35 +
336.36 + private static boolean checkLinearity(ModelStandardTransform transform)
336.37 + {
336.38 + double lastx = 0;
336.39 + for (int p = 0; p < 2; p++)
336.40 + for (int d = 0; d < 2; d++)
336.41 + for (double i = 0; i < 1.0; i+=0.001) {
336.42 + if(p == 0)
336.43 + transform.setPolarity(ModelStandardTransform.POLARITY_UNIPOLAR);
336.44 + else
336.45 + transform.setPolarity(ModelStandardTransform.POLARITY_BIPOLAR);
336.46 + if(d == 0)
336.47 + transform.setDirection(ModelStandardTransform.DIRECTION_MIN2MAX);
336.48 + else
336.49 + transform.setDirection(ModelStandardTransform.DIRECTION_MAX2MIN);
336.50 + double x = transform.transform(i);
336.51 + if(i == 0)
336.52 + lastx = x;
336.53 + else
336.54 + {
336.55 + if(lastx - x > 0.2) return false;
336.56 + lastx = x;
336.57 + }
336.58 + }
336.59 + return true;
336.60 + }
336.61 +
336.62 + private static void assertTrue(boolean value) throws Exception
336.63 + {
336.64 + if(!value)
336.65 + throw new RuntimeException("assertTrue fails!");
336.66 + }
336.67 +
336.68 + public static void main(String[] args) throws Exception {
336.69 + ModelStandardTransform transform = new ModelStandardTransform();
336.70 + transform.setTransform(ModelStandardTransform.TRANSFORM_CONCAVE);
336.71 + assertTrue(checkLinearity(transform));
336.72 +
336.73 + transform.setDirection(ModelStandardTransform.DIRECTION_MIN2MAX);
336.74 + transform.setPolarity(ModelStandardTransform.POLARITY_UNIPOLAR);
336.75 + assertTrue(Math.abs(transform.transform(0.0f) - 0.0f) < 0.0001f);
336.76 + assertTrue(transform.transform(0.5f) < 0.5f);
336.77 + assertTrue(Math.abs(transform.transform(1.0f) - 1.0f) < 0.0001f);
336.78 +
336.79 + transform.setDirection(ModelStandardTransform.DIRECTION_MAX2MIN);
336.80 + transform.setPolarity(ModelStandardTransform.POLARITY_UNIPOLAR);
336.81 + assertTrue(Math.abs(transform.transform(1.0f) - 0.0f) < 0.0001f);
336.82 + assertTrue(transform.transform(0.5f) < 0.5f);
336.83 + assertTrue(Math.abs(transform.transform(0.0f) - 1.0f) < 0.0001f);
336.84 +
336.85 + transform.setDirection(ModelStandardTransform.DIRECTION_MIN2MAX);
336.86 + transform.setPolarity(ModelStandardTransform.POLARITY_BIPOLAR);
336.87 + assertTrue(Math.abs(transform.transform(0.0f) + 1.0f) < 0.0001f);
336.88 + assertTrue(transform.transform(0.25f) > -0.5f);
336.89 + assertTrue(Math.abs(transform.transform(0.5f) - 0.0f) < 0.0001f);
336.90 + assertTrue(transform.transform(0.75f) < 0.5f);
336.91 + assertTrue(Math.abs(transform.transform(1.0f) - 1.0f) < 0.0001f);
336.92 +
336.93 + transform.setDirection(ModelStandardTransform.DIRECTION_MAX2MIN);
336.94 + transform.setPolarity(ModelStandardTransform.POLARITY_BIPOLAR);
336.95 + assertTrue(Math.abs(transform.transform(1.0f) + 1.0f) < 0.0001f);
336.96 + assertTrue(transform.transform(0.75f) > -0.5f);
336.97 + assertTrue(Math.abs(transform.transform(0.50f) - 0.0f) < 0.0001f);
336.98 + assertTrue(transform.transform(0.25f) < 0.5f);
336.99 + assertTrue(Math.abs(transform.transform(0.0f) - 1.0f) < 0.0001f);
336.100 + }
336.101 +}
337.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
337.2 +++ b/test/javax/sound/midi/Gervill/ModelStandardTransform/TransformConvex.java Tue Feb 03 22:02:55 2009 -0800
337.3 @@ -0,0 +1,98 @@
337.4 +/*
337.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
337.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
337.7 + *
337.8 + * This code is free software; you can redistribute it and/or modify it
337.9 + * under the terms of the GNU General Public License version 2 only, as
337.10 + * published by the Free Software Foundation. Sun designates this
337.11 + * particular file as subject to the "Classpath" exception as provided
337.12 + * by Sun in the LICENSE file that accompanied this code.
337.13 + *
337.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
337.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
337.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
337.17 + * version 2 for more details (a copy is included in the LICENSE file that
337.18 + * accompanied this code).
337.19 + *
337.20 + * You should have received a copy of the GNU General Public License version
337.21 + * 2 along with this work; if not, write to the Free Software Foundation,
337.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
337.23 + *
337.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
337.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
337.26 + * have any questions.
337.27 + */
337.28 +
337.29 +/* @test
337.30 + @summary Test ModelStandardTransform transform method */
337.31 +
337.32 +import com.sun.media.sound.ModelStandardTransform;
337.33 +
337.34 +public class TransformConvex {
337.35 +
337.36 + private static boolean checkLinearity(ModelStandardTransform transform)
337.37 + {
337.38 + double lastx = 0;
337.39 + for (int p = 0; p < 2; p++)
337.40 + for (int d = 0; d < 2; d++)
337.41 + for (double i = 0; i < 1.0; i+=0.001) {
337.42 + if(p == 0)
337.43 + transform.setPolarity(ModelStandardTransform.POLARITY_UNIPOLAR);
337.44 + else
337.45 + transform.setPolarity(ModelStandardTransform.POLARITY_BIPOLAR);
337.46 + if(d == 0)
337.47 + transform.setDirection(ModelStandardTransform.DIRECTION_MIN2MAX);
337.48 + else
337.49 + transform.setDirection(ModelStandardTransform.DIRECTION_MAX2MIN);
337.50 + double x = transform.transform(i);
337.51 + if(i == 0)
337.52 + lastx = x;
337.53 + else
337.54 + {
337.55 + if(lastx - x > 0.2) return false;
337.56 + lastx = x;
337.57 + }
337.58 + }
337.59 + return true;
337.60 + }
337.61 +
337.62 + private static void assertTrue(boolean value) throws Exception
337.63 + {
337.64 + if(!value)
337.65 + throw new RuntimeException("assertTrue fails!");
337.66 + }
337.67 +
337.68 + public static void main(String[] args) throws Exception {
337.69 + ModelStandardTransform transform = new ModelStandardTransform();
337.70 + transform.setTransform(ModelStandardTransform.TRANSFORM_CONVEX);
337.71 + assertTrue(checkLinearity(transform));
337.72 +
337.73 + transform.setDirection(ModelStandardTransform.DIRECTION_MIN2MAX);
337.74 + transform.setPolarity(ModelStandardTransform.POLARITY_UNIPOLAR);
337.75 + assertTrue(Math.abs(transform.transform(0.0f) - 0.0f) < 0.0001f);
337.76 + assertTrue(transform.transform(0.5f) > 0.5f);
337.77 + assertTrue(Math.abs(transform.transform(1.0f) - 1.0f) < 0.0001f);
337.78 +
337.79 + transform.setDirection(ModelStandardTransform.DIRECTION_MAX2MIN);
337.80 + transform.setPolarity(ModelStandardTransform.POLARITY_UNIPOLAR);
337.81 + assertTrue(Math.abs(transform.transform(1.0f) - 0.0f) < 0.0001f);
337.82 + assertTrue(transform.transform(0.5f) > 0.5f);
337.83 + assertTrue(Math.abs(transform.transform(0.0f) - 1.0f) < 0.0001f);
337.84 +
337.85 + transform.setDirection(ModelStandardTransform.DIRECTION_MIN2MAX);
337.86 + transform.setPolarity(ModelStandardTransform.POLARITY_BIPOLAR);
337.87 + assertTrue(Math.abs(transform.transform(0.0f) + 1.0f) < 0.0001f);
337.88 + assertTrue(transform.transform(0.25f) < -0.5f);
337.89 + assertTrue(Math.abs(transform.transform(0.5f) - 0.0f) < 0.0001f);
337.90 + assertTrue(transform.transform(0.75f) > 0.5f);
337.91 + assertTrue(Math.abs(transform.transform(1.0f) - 1.0f) < 0.0001f);
337.92 +
337.93 + transform.setDirection(ModelStandardTransform.DIRECTION_MAX2MIN);
337.94 + transform.setPolarity(ModelStandardTransform.POLARITY_BIPOLAR);
337.95 + assertTrue(Math.abs(transform.transform(1.0f) + 1.0f) < 0.0001f);
337.96 + assertTrue(transform.transform(0.75f) < -0.5f);
337.97 + assertTrue(Math.abs(transform.transform(0.50f) - 0.0f) < 0.0001f);
337.98 + assertTrue(transform.transform(0.25f) > 0.5f);
337.99 + assertTrue(Math.abs(transform.transform(0.0f) - 1.0f) < 0.0001f);
337.100 + }
337.101 +}
338.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
338.2 +++ b/test/javax/sound/midi/Gervill/ModelStandardTransform/TransformLinear.java Tue Feb 03 22:02:55 2009 -0800
338.3 @@ -0,0 +1,90 @@
338.4 +/*
338.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
338.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
338.7 + *
338.8 + * This code is free software; you can redistribute it and/or modify it
338.9 + * under the terms of the GNU General Public License version 2 only, as
338.10 + * published by the Free Software Foundation. Sun designates this
338.11 + * particular file as subject to the "Classpath" exception as provided
338.12 + * by Sun in the LICENSE file that accompanied this code.
338.13 + *
338.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
338.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
338.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
338.17 + * version 2 for more details (a copy is included in the LICENSE file that
338.18 + * accompanied this code).
338.19 + *
338.20 + * You should have received a copy of the GNU General Public License version
338.21 + * 2 along with this work; if not, write to the Free Software Foundation,
338.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
338.23 + *
338.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
338.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
338.26 + * have any questions.
338.27 + */
338.28 +
338.29 +/* @test
338.30 + @summary Test ModelStandardTransform transform method */
338.31 +
338.32 +import com.sun.media.sound.ModelStandardTransform;
338.33 +
338.34 +public class TransformLinear {
338.35 +
338.36 + private static boolean checkLinearity(ModelStandardTransform transform)
338.37 + {
338.38 + double lastx = 0;
338.39 + for (int p = 0; p < 2; p++)
338.40 + for (int d = 0; d < 2; d++)
338.41 + for (double i = 0; i < 1.0; i+=0.001) {
338.42 + if(p == 0)
338.43 + transform.setPolarity(ModelStandardTransform.POLARITY_UNIPOLAR);
338.44 + else
338.45 + transform.setPolarity(ModelStandardTransform.POLARITY_BIPOLAR);
338.46 + if(d == 0)
338.47 + transform.setDirection(ModelStandardTransform.DIRECTION_MIN2MAX);
338.48 + else
338.49 + transform.setDirection(ModelStandardTransform.DIRECTION_MAX2MIN);
338.50 + double x = transform.transform(i);
338.51 + if(i == 0)
338.52 + lastx = x;
338.53 + else
338.54 + {
338.55 + if(lastx - x > 0.2) return false;
338.56 + lastx = x;
338.57 + }
338.58 + }
338.59 + return true;
338.60 + }
338.61 +
338.62 + private static void assertTrue(boolean value) throws Exception
338.63 + {
338.64 + if(!value)
338.65 + throw new RuntimeException("assertTrue fails!");
338.66 + }
338.67 +
338.68 + public static void main(String[] args) throws Exception {
338.69 + ModelStandardTransform transform = new ModelStandardTransform();
338.70 + transform.setTransform(ModelStandardTransform.TRANSFORM_LINEAR);
338.71 + assertTrue(checkLinearity(transform));
338.72 +
338.73 + transform.setDirection(ModelStandardTransform.DIRECTION_MIN2MAX);
338.74 + transform.setPolarity(ModelStandardTransform.POLARITY_UNIPOLAR);
338.75 + assertTrue(Math.abs(transform.transform(0.2f) - 0.2f) < 0.0001f);
338.76 + assertTrue(Math.abs(transform.transform(0.8f) - 0.8f) < 0.0001f);
338.77 +
338.78 + transform.setDirection(ModelStandardTransform.DIRECTION_MAX2MIN);
338.79 + transform.setPolarity(ModelStandardTransform.POLARITY_UNIPOLAR);
338.80 + assertTrue(Math.abs(transform.transform(0.2f) - 0.8f) < 0.0001f);
338.81 + assertTrue(Math.abs(transform.transform(0.8f) - 0.2f) < 0.0001f);
338.82 +
338.83 + transform.setDirection(ModelStandardTransform.DIRECTION_MIN2MAX);
338.84 + transform.setPolarity(ModelStandardTransform.POLARITY_BIPOLAR);
338.85 + assertTrue(Math.abs(transform.transform(0.2f) - (-0.6f)) < 0.0001f);
338.86 + assertTrue(Math.abs(transform.transform(0.8f) - (0.6f)) < 0.0001f);
338.87 +
338.88 + transform.setDirection(ModelStandardTransform.DIRECTION_MAX2MIN);
338.89 + transform.setPolarity(ModelStandardTransform.POLARITY_BIPOLAR);
338.90 + assertTrue(Math.abs(transform.transform(0.2f) - (0.6f)) < 0.0001f);
338.91 + assertTrue(Math.abs(transform.transform(0.8f) - (-0.6f)) < 0.0001f);
338.92 + }
338.93 +}
339.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
339.2 +++ b/test/javax/sound/midi/Gervill/ModelStandardTransform/TransformSwitch.java Tue Feb 03 22:02:55 2009 -0800
339.3 @@ -0,0 +1,63 @@
339.4 +/*
339.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
339.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
339.7 + *
339.8 + * This code is free software; you can redistribute it and/or modify it
339.9 + * under the terms of the GNU General Public License version 2 only, as
339.10 + * published by the Free Software Foundation. Sun designates this
339.11 + * particular file as subject to the "Classpath" exception as provided
339.12 + * by Sun in the LICENSE file that accompanied this code.
339.13 + *
339.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
339.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
339.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
339.17 + * version 2 for more details (a copy is included in the LICENSE file that
339.18 + * accompanied this code).
339.19 + *
339.20 + * You should have received a copy of the GNU General Public License version
339.21 + * 2 along with this work; if not, write to the Free Software Foundation,
339.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
339.23 + *
339.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
339.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
339.26 + * have any questions.
339.27 + */
339.28 +
339.29 +/* @test
339.30 + @summary Test ModelStandardTransform transform method */
339.31 +
339.32 +import com.sun.media.sound.ModelStandardTransform;
339.33 +
339.34 +public class TransformSwitch {
339.35 +
339.36 + private static void assertTrue(boolean value) throws Exception
339.37 + {
339.38 + if(!value)
339.39 + throw new RuntimeException("assertTrue fails!");
339.40 + }
339.41 +
339.42 + public static void main(String[] args) throws Exception {
339.43 + ModelStandardTransform transform = new ModelStandardTransform();
339.44 + transform.setTransform(ModelStandardTransform.TRANSFORM_SWITCH);
339.45 +
339.46 + transform.setDirection(ModelStandardTransform.DIRECTION_MIN2MAX);
339.47 + transform.setPolarity(ModelStandardTransform.POLARITY_UNIPOLAR);
339.48 + assertTrue(Math.abs(transform.transform(0.2f) - 0.0f) < 0.0001f);
339.49 + assertTrue(Math.abs(transform.transform(0.8f) - 1.0f) < 0.0001f);
339.50 +
339.51 + transform.setDirection(ModelStandardTransform.DIRECTION_MAX2MIN);
339.52 + transform.setPolarity(ModelStandardTransform.POLARITY_UNIPOLAR);
339.53 + assertTrue(Math.abs(transform.transform(0.2f) - 1.0f) < 0.0001f);
339.54 + assertTrue(Math.abs(transform.transform(0.8f) - 0.0f) < 0.0001f);
339.55 +
339.56 + transform.setDirection(ModelStandardTransform.DIRECTION_MIN2MAX);
339.57 + transform.setPolarity(ModelStandardTransform.POLARITY_BIPOLAR);
339.58 + assertTrue(Math.abs(transform.transform(0.2f) + 1.0f) < 0.0001f);
339.59 + assertTrue(Math.abs(transform.transform(0.8f) - 1.0f) < 0.0001f);
339.60 +
339.61 + transform.setDirection(ModelStandardTransform.DIRECTION_MAX2MIN);
339.62 + transform.setPolarity(ModelStandardTransform.POLARITY_BIPOLAR);
339.63 + assertTrue(Math.abs(transform.transform(0.2f) - 1.0f) < 0.0001f);
339.64 + assertTrue(Math.abs(transform.transform(0.8f) + 1.0f) < 0.0001f);
339.65 + }
339.66 +}
340.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
340.2 +++ b/test/javax/sound/midi/Gervill/RiffReaderWriter/Available.java Tue Feb 03 22:02:55 2009 -0800
340.3 @@ -0,0 +1,78 @@
340.4 +/*
340.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
340.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
340.7 + *
340.8 + * This code is free software; you can redistribute it and/or modify it
340.9 + * under the terms of the GNU General Public License version 2 only, as
340.10 + * published by the Free Software Foundation. Sun designates this
340.11 + * particular file as subject to the "Classpath" exception as provided
340.12 + * by Sun in the LICENSE file that accompanied this code.
340.13 + *
340.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
340.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
340.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
340.17 + * version 2 for more details (a copy is included in the LICENSE file that
340.18 + * accompanied this code).
340.19 + *
340.20 + * You should have received a copy of the GNU General Public License version
340.21 + * 2 along with this work; if not, write to the Free Software Foundation,
340.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
340.23 + *
340.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
340.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
340.26 + * have any questions.
340.27 + */
340.28 +
340.29 +/* @test
340.30 + @summary Test RiffReader available method */
340.31 +
340.32 +import java.io.File;
340.33 +import java.io.FileInputStream;
340.34 +
340.35 +import javax.sound.sampled.*;
340.36 +
340.37 +import com.sun.media.sound.*;
340.38 +
340.39 +public class Available {
340.40 +
340.41 + private static void assertEquals(Object a, Object b) throws Exception
340.42 + {
340.43 + if(!a.equals(b))
340.44 + throw new RuntimeException("assertEquals fails!");
340.45 + }
340.46 +
340.47 + public static void main(String[] args) throws Exception {
340.48 + RIFFWriter writer = null;
340.49 + RIFFReader reader = null;
340.50 + File tempfile = File.createTempFile("test",".riff");
340.51 + try
340.52 + {
340.53 + writer = new RIFFWriter(tempfile, "TEST");
340.54 + RIFFWriter chunk = writer.writeChunk("TSCH");
340.55 + chunk.writeByte(10);
340.56 + writer.close();
340.57 + writer = null;
340.58 + FileInputStream fis = new FileInputStream(tempfile);
340.59 + reader = new RIFFReader(fis);
340.60 + RIFFReader readchunk = reader.nextChunk();
340.61 + int avail = readchunk.available();
340.62 + readchunk.readByte();
340.63 + assertEquals(avail - 1,readchunk.available());
340.64 + fis.close();
340.65 + reader = null;
340.66 +
340.67 +
340.68 + }
340.69 + finally
340.70 + {
340.71 + if(writer != null)
340.72 + writer.close();
340.73 + if(reader != null)
340.74 + reader.close();
340.75 +
340.76 + if(tempfile.exists())
340.77 + if(!tempfile.delete())
340.78 + tempfile.deleteOnExit();
340.79 + }
340.80 + }
340.81 +}
341.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
341.2 +++ b/test/javax/sound/midi/Gervill/RiffReaderWriter/Close.java Tue Feb 03 22:02:55 2009 -0800
341.3 @@ -0,0 +1,72 @@
341.4 +/*
341.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
341.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
341.7 + *
341.8 + * This code is free software; you can redistribute it and/or modify it
341.9 + * under the terms of the GNU General Public License version 2 only, as
341.10 + * published by the Free Software Foundation. Sun designates this
341.11 + * particular file as subject to the "Classpath" exception as provided
341.12 + * by Sun in the LICENSE file that accompanied this code.
341.13 + *
341.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
341.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
341.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
341.17 + * version 2 for more details (a copy is included in the LICENSE file that
341.18 + * accompanied this code).
341.19 + *
341.20 + * You should have received a copy of the GNU General Public License version
341.21 + * 2 along with this work; if not, write to the Free Software Foundation,
341.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
341.23 + *
341.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
341.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
341.26 + * have any questions.
341.27 + */
341.28 +
341.29 +/* @test
341.30 + @summary Test RiffReader close method */
341.31 +
341.32 +import java.io.File;
341.33 +import java.io.FileInputStream;
341.34 +
341.35 +import javax.sound.sampled.*;
341.36 +
341.37 +import com.sun.media.sound.*;
341.38 +
341.39 +public class Close {
341.40 +
341.41 + private static void assertEquals(Object a, Object b) throws Exception
341.42 + {
341.43 + if(!a.equals(b))
341.44 + throw new RuntimeException("assertEquals fails!");
341.45 + }
341.46 +
341.47 + public static void main(String[] args) throws Exception {
341.48 + RIFFWriter writer = null;
341.49 + RIFFReader reader = null;
341.50 + File tempfile = File.createTempFile("test",".riff");
341.51 + try
341.52 + {
341.53 + writer = new RIFFWriter(tempfile, "TEST");
341.54 + writer.close();
341.55 + writer = null;
341.56 + FileInputStream fis = new FileInputStream(tempfile);
341.57 + reader = new RIFFReader(fis);
341.58 + reader.close();
341.59 + reader = null;
341.60 +
341.61 +
341.62 + }
341.63 + finally
341.64 + {
341.65 + if(writer != null)
341.66 + writer.close();
341.67 + if(reader != null)
341.68 + reader.close();
341.69 +
341.70 + if(tempfile.exists())
341.71 + if(!tempfile.delete())
341.72 + tempfile.deleteOnExit();
341.73 + }
341.74 + }
341.75 +}
342.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
342.2 +++ b/test/javax/sound/midi/Gervill/RiffReaderWriter/GetFilePointer.java Tue Feb 03 22:02:55 2009 -0800
342.3 @@ -0,0 +1,78 @@
342.4 +/*
342.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
342.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
342.7 + *
342.8 + * This code is free software; you can redistribute it and/or modify it
342.9 + * under the terms of the GNU General Public License version 2 only, as
342.10 + * published by the Free Software Foundation. Sun designates this
342.11 + * particular file as subject to the "Classpath" exception as provided
342.12 + * by Sun in the LICENSE file that accompanied this code.
342.13 + *
342.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
342.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
342.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
342.17 + * version 2 for more details (a copy is included in the LICENSE file that
342.18 + * accompanied this code).
342.19 + *
342.20 + * You should have received a copy of the GNU General Public License version
342.21 + * 2 along with this work; if not, write to the Free Software Foundation,
342.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
342.23 + *
342.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
342.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
342.26 + * have any questions.
342.27 + */
342.28 +
342.29 +/* @test
342.30 + @summary Test RiffReader getFilePointer method */
342.31 +
342.32 +import java.io.File;
342.33 +import java.io.FileInputStream;
342.34 +
342.35 +import javax.sound.sampled.*;
342.36 +
342.37 +import com.sun.media.sound.*;
342.38 +
342.39 +public class GetFilePointer {
342.40 +
342.41 + private static void assertEquals(Object a, Object b) throws Exception
342.42 + {
342.43 + if(!a.equals(b))
342.44 + throw new RuntimeException("assertEquals fails!");
342.45 + }
342.46 +
342.47 + public static void main(String[] args) throws Exception {
342.48 + RIFFWriter writer = null;
342.49 + RIFFReader reader = null;
342.50 + File tempfile = File.createTempFile("test",".riff");
342.51 + try
342.52 + {
342.53 + writer = new RIFFWriter(tempfile, "TEST");
342.54 + RIFFWriter chunk = writer.writeChunk("TSCH");
342.55 + chunk.writeByte(10);
342.56 + writer.close();
342.57 + writer = null;
342.58 + FileInputStream fis = new FileInputStream(tempfile);
342.59 + reader = new RIFFReader(fis);
342.60 + RIFFReader readchunk = reader.nextChunk();
342.61 + long p = readchunk.getFilePointer();
342.62 + readchunk.readByte();
342.63 + assertEquals(p+1,readchunk.getFilePointer());
342.64 + fis.close();
342.65 + reader = null;
342.66 +
342.67 +
342.68 + }
342.69 + finally
342.70 + {
342.71 + if(writer != null)
342.72 + writer.close();
342.73 + if(reader != null)
342.74 + reader.close();
342.75 +
342.76 + if(tempfile.exists())
342.77 + if(!tempfile.delete())
342.78 + tempfile.deleteOnExit();
342.79 + }
342.80 + }
342.81 +}
343.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
343.2 +++ b/test/javax/sound/midi/Gervill/RiffReaderWriter/GetSize.java Tue Feb 03 22:02:55 2009 -0800
343.3 @@ -0,0 +1,77 @@
343.4 +/*
343.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
343.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
343.7 + *
343.8 + * This code is free software; you can redistribute it and/or modify it
343.9 + * under the terms of the GNU General Public License version 2 only, as
343.10 + * published by the Free Software Foundation. Sun designates this
343.11 + * particular file as subject to the "Classpath" exception as provided
343.12 + * by Sun in the LICENSE file that accompanied this code.
343.13 + *
343.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
343.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
343.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
343.17 + * version 2 for more details (a copy is included in the LICENSE file that
343.18 + * accompanied this code).
343.19 + *
343.20 + * You should have received a copy of the GNU General Public License version
343.21 + * 2 along with this work; if not, write to the Free Software Foundation,
343.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
343.23 + *
343.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
343.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
343.26 + * have any questions.
343.27 + */
343.28 +
343.29 +/* @test
343.30 + @summary Test RiffReader getSize method */
343.31 +
343.32 +import java.io.File;
343.33 +import java.io.FileInputStream;
343.34 +
343.35 +import javax.sound.sampled.*;
343.36 +
343.37 +import com.sun.media.sound.*;
343.38 +
343.39 +public class GetSize {
343.40 +
343.41 + private static void assertEquals(Object a, Object b) throws Exception
343.42 + {
343.43 + if(!a.equals(b))
343.44 + throw new RuntimeException("assertEquals fails!");
343.45 + }
343.46 +
343.47 + public static void main(String[] args) throws Exception {
343.48 + RIFFWriter writer = null;
343.49 + RIFFReader reader = null;
343.50 + File tempfile = File.createTempFile("test",".riff");
343.51 + try
343.52 + {
343.53 + writer = new RIFFWriter(tempfile, "TEST");
343.54 + RIFFWriter chunk = writer.writeChunk("TSCH");
343.55 + chunk.writeByte(10);
343.56 + writer.close();
343.57 + writer = null;
343.58 + FileInputStream fis = new FileInputStream(tempfile);
343.59 + reader = new RIFFReader(fis);
343.60 + RIFFReader readchunk = reader.nextChunk();
343.61 + assertEquals(readchunk.getSize(), (long)readchunk.available());
343.62 + readchunk.readByte();
343.63 + fis.close();
343.64 + reader = null;
343.65 +
343.66 +
343.67 + }
343.68 + finally
343.69 + {
343.70 + if(writer != null)
343.71 + writer.close();
343.72 + if(reader != null)
343.73 + reader.close();
343.74 +
343.75 + if(tempfile.exists())
343.76 + if(!tempfile.delete())
343.77 + tempfile.deleteOnExit();
343.78 + }
343.79 + }
343.80 +}
344.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
344.2 +++ b/test/javax/sound/midi/Gervill/RiffReaderWriter/HasNextChunk.java Tue Feb 03 22:02:55 2009 -0800
344.3 @@ -0,0 +1,85 @@
344.4 +/*
344.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
344.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
344.7 + *
344.8 + * This code is free software; you can redistribute it and/or modify it
344.9 + * under the terms of the GNU General Public License version 2 only, as
344.10 + * published by the Free Software Foundation. Sun designates this
344.11 + * particular file as subject to the "Classpath" exception as provided
344.12 + * by Sun in the LICENSE file that accompanied this code.
344.13 + *
344.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
344.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
344.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
344.17 + * version 2 for more details (a copy is included in the LICENSE file that
344.18 + * accompanied this code).
344.19 + *
344.20 + * You should have received a copy of the GNU General Public License version
344.21 + * 2 along with this work; if not, write to the Free Software Foundation,
344.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
344.23 + *
344.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
344.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
344.26 + * have any questions.
344.27 + */
344.28 +
344.29 +/* @test
344.30 + @summary Test RiffReader hasNextChunk method */
344.31 +
344.32 +import java.io.File;
344.33 +import java.io.FileInputStream;
344.34 +
344.35 +import javax.sound.sampled.*;
344.36 +
344.37 +import com.sun.media.sound.*;
344.38 +
344.39 +public class HasNextChunk {
344.40 +
344.41 + private static void assertEquals(Object a, Object b) throws Exception
344.42 + {
344.43 + if(!a.equals(b))
344.44 + throw new RuntimeException("assertEquals fails!");
344.45 + }
344.46 +
344.47 + private static void assertTrue(boolean a) throws Exception
344.48 + {
344.49 + if(!a)
344.50 + throw new RuntimeException("assertEquals fails!");
344.51 + }
344.52 +
344.53 + public static void main(String[] args) throws Exception {
344.54 + RIFFWriter writer = null;
344.55 + RIFFReader reader = null;
344.56 + File tempfile = File.createTempFile("test",".riff");
344.57 + try
344.58 + {
344.59 + writer = new RIFFWriter(tempfile, "TEST");
344.60 + RIFFWriter chunk = writer.writeChunk("TSCH");
344.61 + chunk.writeByte(10);
344.62 + writer.close();
344.63 + writer = null;
344.64 + FileInputStream fis = new FileInputStream(tempfile);
344.65 + reader = new RIFFReader(fis);
344.66 + assertTrue(reader.hasNextChunk());
344.67 + RIFFReader readchunk = reader.nextChunk();
344.68 + readchunk.readByte();
344.69 + readchunk.close();
344.70 + assertTrue(!reader.hasNextChunk());
344.71 + fis.close();
344.72 + reader = null;
344.73 +
344.74 +
344.75 + }
344.76 + finally
344.77 + {
344.78 + if(writer != null)
344.79 + writer.close();
344.80 + if(reader != null)
344.81 + reader.close();
344.82 +
344.83 + if(tempfile.exists())
344.84 + if(!tempfile.delete())
344.85 + tempfile.deleteOnExit();
344.86 + }
344.87 + }
344.88 +}
345.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
345.2 +++ b/test/javax/sound/midi/Gervill/RiffReaderWriter/Read.java Tue Feb 03 22:02:55 2009 -0800
345.3 @@ -0,0 +1,79 @@
345.4 +/*
345.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
345.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
345.7 + *
345.8 + * This code is free software; you can redistribute it and/or modify it
345.9 + * under the terms of the GNU General Public License version 2 only, as
345.10 + * published by the Free Software Foundation. Sun designates this
345.11 + * particular file as subject to the "Classpath" exception as provided
345.12 + * by Sun in the LICENSE file that accompanied this code.
345.13 + *
345.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
345.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
345.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
345.17 + * version 2 for more details (a copy is included in the LICENSE file that
345.18 + * accompanied this code).
345.19 + *
345.20 + * You should have received a copy of the GNU General Public License version
345.21 + * 2 along with this work; if not, write to the Free Software Foundation,
345.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
345.23 + *
345.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
345.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
345.26 + * have any questions.
345.27 + */
345.28 +
345.29 +/* @test
345.30 + @summary Test RiffReader read method */
345.31 +
345.32 +import java.io.File;
345.33 +import java.io.FileInputStream;
345.34 +
345.35 +import javax.sound.sampled.*;
345.36 +
345.37 +import com.sun.media.sound.*;
345.38 +
345.39 +public class Read {
345.40 +
345.41 + private static void assertEquals(Object a, Object b) throws Exception
345.42 + {
345.43 + if(!a.equals(b))
345.44 + throw new RuntimeException("assertEquals fails!");
345.45 + }
345.46 +
345.47 + public static void main(String[] args) throws Exception {
345.48 + RIFFWriter writer = null;
345.49 + RIFFReader reader = null;
345.50 + File tempfile = File.createTempFile("test",".riff");
345.51 + try
345.52 + {
345.53 +
345.54 + writer = new RIFFWriter(tempfile, "TEST");
345.55 + RIFFWriter chunk = writer.writeChunk("TSCH");
345.56 + chunk.write((byte)33);
345.57 + writer.close();
345.58 + writer = null;
345.59 + FileInputStream fis = new FileInputStream(tempfile);
345.60 + reader = new RIFFReader(fis);
345.61 + assertEquals(reader.getFormat(), "RIFF");
345.62 + assertEquals(reader.getType(), "TEST");
345.63 + RIFFReader readchunk = reader.nextChunk();
345.64 + assertEquals(readchunk.getFormat(), "TSCH");
345.65 + assertEquals(readchunk.read(), 33);
345.66 + fis.close();
345.67 + reader = null;
345.68 +
345.69 + }
345.70 + finally
345.71 + {
345.72 + if(writer != null)
345.73 + writer.close();
345.74 + if(reader != null)
345.75 + reader.close();
345.76 +
345.77 + if(tempfile.exists())
345.78 + if(!tempfile.delete())
345.79 + tempfile.deleteOnExit();
345.80 + }
345.81 + }
345.82 +}
346.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
346.2 +++ b/test/javax/sound/midi/Gervill/RiffReaderWriter/ReadByte.java Tue Feb 03 22:02:55 2009 -0800
346.3 @@ -0,0 +1,79 @@
346.4 +/*
346.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
346.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
346.7 + *
346.8 + * This code is free software; you can redistribute it and/or modify it
346.9 + * under the terms of the GNU General Public License version 2 only, as
346.10 + * published by the Free Software Foundation. Sun designates this
346.11 + * particular file as subject to the "Classpath" exception as provided
346.12 + * by Sun in the LICENSE file that accompanied this code.
346.13 + *
346.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
346.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
346.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
346.17 + * version 2 for more details (a copy is included in the LICENSE file that
346.18 + * accompanied this code).
346.19 + *
346.20 + * You should have received a copy of the GNU General Public License version
346.21 + * 2 along with this work; if not, write to the Free Software Foundation,
346.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
346.23 + *
346.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
346.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
346.26 + * have any questions.
346.27 + */
346.28 +
346.29 +/* @test
346.30 + @summary Test RiffReader read(byte) method */
346.31 +
346.32 +import java.io.File;
346.33 +import java.io.FileInputStream;
346.34 +
346.35 +import javax.sound.sampled.*;
346.36 +
346.37 +import com.sun.media.sound.*;
346.38 +
346.39 +public class ReadByte {
346.40 +
346.41 + private static void assertEquals(Object a, Object b) throws Exception
346.42 + {
346.43 + if(!a.equals(b))
346.44 + throw new RuntimeException("assertEquals fails!");
346.45 + }
346.46 +
346.47 + public static void main(String[] args) throws Exception {
346.48 + RIFFWriter writer = null;
346.49 + RIFFReader reader = null;
346.50 + File tempfile = File.createTempFile("test",".riff");
346.51 + try
346.52 + {
346.53 +
346.54 + writer = new RIFFWriter(tempfile, "TEST");
346.55 + RIFFWriter chunk = writer.writeChunk("TSCH");
346.56 + chunk.writeByte((byte)33);
346.57 + writer.close();
346.58 + writer = null;
346.59 + FileInputStream fis = new FileInputStream(tempfile);
346.60 + reader = new RIFFReader(fis);
346.61 + assertEquals(reader.getFormat(), "RIFF");
346.62 + assertEquals(reader.getType(), "TEST");
346.63 + RIFFReader readchunk = reader.nextChunk();
346.64 + assertEquals(readchunk.getFormat(), "TSCH");
346.65 + assertEquals((int)reader.readByte(), 33);
346.66 + fis.close();
346.67 + reader = null;
346.68 +
346.69 + }
346.70 + finally
346.71 + {
346.72 + if(writer != null)
346.73 + writer.close();
346.74 + if(reader != null)
346.75 + reader.close();
346.76 +
346.77 + if(tempfile.exists())
346.78 + if(!tempfile.delete())
346.79 + tempfile.deleteOnExit();
346.80 + }
346.81 + }
346.82 +}
347.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
347.2 +++ b/test/javax/sound/midi/Gervill/RiffReaderWriter/ReadByteArrayIntInt.java Tue Feb 03 22:02:55 2009 -0800
347.3 @@ -0,0 +1,81 @@
347.4 +/*
347.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
347.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
347.7 + *
347.8 + * This code is free software; you can redistribute it and/or modify it
347.9 + * under the terms of the GNU General Public License version 2 only, as
347.10 + * published by the Free Software Foundation. Sun designates this
347.11 + * particular file as subject to the "Classpath" exception as provided
347.12 + * by Sun in the LICENSE file that accompanied this code.
347.13 + *
347.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
347.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
347.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
347.17 + * version 2 for more details (a copy is included in the LICENSE file that
347.18 + * accompanied this code).
347.19 + *
347.20 + * You should have received a copy of the GNU General Public License version
347.21 + * 2 along with this work; if not, write to the Free Software Foundation,
347.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
347.23 + *
347.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
347.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
347.26 + * have any questions.
347.27 + */
347.28 +
347.29 +/* @test
347.30 + @summary Test RiffReader read(byte[], int, int) method */
347.31 +
347.32 +import java.io.File;
347.33 +import java.io.FileInputStream;
347.34 +
347.35 +import javax.sound.sampled.*;
347.36 +
347.37 +import com.sun.media.sound.*;
347.38 +
347.39 +public class ReadByteArrayIntInt {
347.40 +
347.41 + private static void assertEquals(Object a, Object b) throws Exception
347.42 + {
347.43 + if(!a.equals(b))
347.44 + throw new RuntimeException("assertEquals fails!");
347.45 + }
347.46 +
347.47 + public static void main(String[] args) throws Exception {
347.48 + RIFFWriter writer = null;
347.49 + RIFFReader reader = null;
347.50 + File tempfile = File.createTempFile("test",".riff");
347.51 + try
347.52 + {
347.53 + writer = new RIFFWriter(tempfile, "TEST");
347.54 + RIFFWriter chunk = writer.writeChunk("TSCH");
347.55 + chunk.write(new byte[] {1,2,3});
347.56 + writer.close();
347.57 + writer = null;
347.58 + FileInputStream fis = new FileInputStream(tempfile);
347.59 + reader = new RIFFReader(fis);
347.60 + assertEquals(reader.getFormat(), "RIFF");
347.61 + assertEquals(reader.getType(), "TEST");
347.62 + RIFFReader readchunk = reader.nextChunk();
347.63 + assertEquals(readchunk.getFormat(), "TSCH");
347.64 + assertEquals(readchunk.read(), 1);
347.65 + assertEquals(readchunk.read(), 2);
347.66 + assertEquals(readchunk.read(), 3);
347.67 + fis.close();
347.68 + reader = null;
347.69 +
347.70 +
347.71 + }
347.72 + finally
347.73 + {
347.74 + if(writer != null)
347.75 + writer.close();
347.76 + if(reader != null)
347.77 + reader.close();
347.78 +
347.79 + if(tempfile.exists())
347.80 + if(!tempfile.delete())
347.81 + tempfile.deleteOnExit();
347.82 + }
347.83 + }
347.84 +}
348.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
348.2 +++ b/test/javax/sound/midi/Gervill/RiffReaderWriter/ReadInt.java Tue Feb 03 22:02:55 2009 -0800
348.3 @@ -0,0 +1,79 @@
348.4 +/*
348.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
348.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
348.7 + *
348.8 + * This code is free software; you can redistribute it and/or modify it
348.9 + * under the terms of the GNU General Public License version 2 only, as
348.10 + * published by the Free Software Foundation. Sun designates this
348.11 + * particular file as subject to the "Classpath" exception as provided
348.12 + * by Sun in the LICENSE file that accompanied this code.
348.13 + *
348.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
348.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
348.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
348.17 + * version 2 for more details (a copy is included in the LICENSE file that
348.18 + * accompanied this code).
348.19 + *
348.20 + * You should have received a copy of the GNU General Public License version
348.21 + * 2 along with this work; if not, write to the Free Software Foundation,
348.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
348.23 + *
348.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
348.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
348.26 + * have any questions.
348.27 + */
348.28 +
348.29 +/* @test
348.30 + @summary Test RiffReader readInt method */
348.31 +
348.32 +import java.io.File;
348.33 +import java.io.FileInputStream;
348.34 +
348.35 +import javax.sound.sampled.*;
348.36 +
348.37 +import com.sun.media.sound.*;
348.38 +
348.39 +public class ReadInt {
348.40 +
348.41 + private static void assertEquals(Object a, Object b) throws Exception
348.42 + {
348.43 + if(!a.equals(b))
348.44 + throw new RuntimeException("assertEquals fails!");
348.45 + }
348.46 +
348.47 + public static void main(String[] args) throws Exception {
348.48 + RIFFWriter writer = null;
348.49 + RIFFReader reader = null;
348.50 + File tempfile = File.createTempFile("test",".riff");
348.51 + try
348.52 + {
348.53 + writer = new RIFFWriter(tempfile, "TEST");
348.54 + RIFFWriter chunk = writer.writeChunk("TSCH");
348.55 + chunk.writeInt(133);
348.56 + writer.close();
348.57 + writer = null;
348.58 + FileInputStream fis = new FileInputStream(tempfile);
348.59 + reader = new RIFFReader(fis);
348.60 + assertEquals(reader.getFormat(), "RIFF");
348.61 + assertEquals(reader.getType(), "TEST");
348.62 + RIFFReader readchunk = reader.nextChunk();
348.63 + assertEquals(readchunk.getFormat(), "TSCH");
348.64 + assertEquals(reader.readInt(), 133);
348.65 + fis.close();
348.66 + reader = null;
348.67 +
348.68 +
348.69 + }
348.70 + finally
348.71 + {
348.72 + if(writer != null)
348.73 + writer.close();
348.74 + if(reader != null)
348.75 + reader.close();
348.76 +
348.77 + if(tempfile.exists())
348.78 + if(!tempfile.delete())
348.79 + tempfile.deleteOnExit();
348.80 + }
348.81 + }
348.82 +}
349.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
349.2 +++ b/test/javax/sound/midi/Gervill/RiffReaderWriter/ReadLong.java Tue Feb 03 22:02:55 2009 -0800
349.3 @@ -0,0 +1,79 @@
349.4 +/*
349.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
349.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
349.7 + *
349.8 + * This code is free software; you can redistribute it and/or modify it
349.9 + * under the terms of the GNU General Public License version 2 only, as
349.10 + * published by the Free Software Foundation. Sun designates this
349.11 + * particular file as subject to the "Classpath" exception as provided
349.12 + * by Sun in the LICENSE file that accompanied this code.
349.13 + *
349.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
349.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
349.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
349.17 + * version 2 for more details (a copy is included in the LICENSE file that
349.18 + * accompanied this code).
349.19 + *
349.20 + * You should have received a copy of the GNU General Public License version
349.21 + * 2 along with this work; if not, write to the Free Software Foundation,
349.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
349.23 + *
349.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
349.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
349.26 + * have any questions.
349.27 + */
349.28 +
349.29 +/* @test
349.30 + @summary Test RiffReader readLong method */
349.31 +
349.32 +import java.io.File;
349.33 +import java.io.FileInputStream;
349.34 +
349.35 +import javax.sound.sampled.*;
349.36 +
349.37 +import com.sun.media.sound.*;
349.38 +
349.39 +public class ReadLong {
349.40 +
349.41 + private static void assertEquals(Object a, Object b) throws Exception
349.42 + {
349.43 + if(!a.equals(b))
349.44 + throw new RuntimeException("assertEquals fails!");
349.45 + }
349.46 +
349.47 + public static void main(String[] args) throws Exception {
349.48 + RIFFWriter writer = null;
349.49 + RIFFReader reader = null;
349.50 + File tempfile = File.createTempFile("test",".riff");
349.51 + try
349.52 + {
349.53 + writer = new RIFFWriter(tempfile, "TEST");
349.54 + RIFFWriter chunk = writer.writeChunk("TSCH");
349.55 + chunk.writeLong(133L);
349.56 + writer.close();
349.57 + writer = null;
349.58 + FileInputStream fis = new FileInputStream(tempfile);
349.59 + reader = new RIFFReader(fis);
349.60 + assertEquals(reader.getFormat(), "RIFF");
349.61 + assertEquals(reader.getType(), "TEST");
349.62 + RIFFReader readchunk = reader.nextChunk();
349.63 + assertEquals(readchunk.getFormat(), "TSCH");
349.64 + assertEquals(reader.readLong(), 133L);
349.65 + fis.close();
349.66 + reader = null;
349.67 +
349.68 +
349.69 + }
349.70 + finally
349.71 + {
349.72 + if(writer != null)
349.73 + writer.close();
349.74 + if(reader != null)
349.75 + reader.close();
349.76 +
349.77 + if(tempfile.exists())
349.78 + if(!tempfile.delete())
349.79 + tempfile.deleteOnExit();
349.80 + }
349.81 + }
349.82 +}
350.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
350.2 +++ b/test/javax/sound/midi/Gervill/RiffReaderWriter/ReadShort.java Tue Feb 03 22:02:55 2009 -0800
350.3 @@ -0,0 +1,79 @@
350.4 +/*
350.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
350.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
350.7 + *
350.8 + * This code is free software; you can redistribute it and/or modify it
350.9 + * under the terms of the GNU General Public License version 2 only, as
350.10 + * published by the Free Software Foundation. Sun designates this
350.11 + * particular file as subject to the "Classpath" exception as provided
350.12 + * by Sun in the LICENSE file that accompanied this code.
350.13 + *
350.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
350.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
350.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
350.17 + * version 2 for more details (a copy is included in the LICENSE file that
350.18 + * accompanied this code).
350.19 + *
350.20 + * You should have received a copy of the GNU General Public License version
350.21 + * 2 along with this work; if not, write to the Free Software Foundation,
350.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
350.23 + *
350.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
350.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
350.26 + * have any questions.
350.27 + */
350.28 +
350.29 +/* @test
350.30 + @summary Test RiffReader readShort method */
350.31 +
350.32 +import java.io.File;
350.33 +import java.io.FileInputStream;
350.34 +
350.35 +import javax.sound.sampled.*;
350.36 +
350.37 +import com.sun.media.sound.*;
350.38 +
350.39 +public class ReadShort {
350.40 +
350.41 + private static void assertEquals(Object a, Object b) throws Exception
350.42 + {
350.43 + if(!a.equals(b))
350.44 + throw new RuntimeException("assertEquals fails!");
350.45 + }
350.46 +
350.47 + public static void main(String[] args) throws Exception {
350.48 + RIFFWriter writer = null;
350.49 + RIFFReader reader = null;
350.50 + File tempfile = File.createTempFile("test",".riff");
350.51 + try
350.52 + {
350.53 + writer = new RIFFWriter(tempfile, "TEST");
350.54 + RIFFWriter chunk = writer.writeChunk("TSCH");
350.55 + chunk.writeShort((short)133);
350.56 + writer.close();
350.57 + writer = null;
350.58 + FileInputStream fis = new FileInputStream(tempfile);
350.59 + reader = new RIFFReader(fis);
350.60 + assertEquals(reader.getFormat(), "RIFF");
350.61 + assertEquals(reader.getType(), "TEST");
350.62 + RIFFReader readchunk = reader.nextChunk();
350.63 + assertEquals(readchunk.getFormat(), "TSCH");
350.64 + assertEquals(reader.readShort(), (short)133);
350.65 + fis.close();
350.66 + reader = null;
350.67 +
350.68 +
350.69 + }
350.70 + finally
350.71 + {
350.72 + if(writer != null)
350.73 + writer.close();
350.74 + if(reader != null)
350.75 + reader.close();
350.76 +
350.77 + if(tempfile.exists())
350.78 + if(!tempfile.delete())
350.79 + tempfile.deleteOnExit();
350.80 + }
350.81 + }
350.82 +}
351.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
351.2 +++ b/test/javax/sound/midi/Gervill/RiffReaderWriter/ReadString.java Tue Feb 03 22:02:55 2009 -0800
351.3 @@ -0,0 +1,79 @@
351.4 +/*
351.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
351.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
351.7 + *
351.8 + * This code is free software; you can redistribute it and/or modify it
351.9 + * under the terms of the GNU General Public License version 2 only, as
351.10 + * published by the Free Software Foundation. Sun designates this
351.11 + * particular file as subject to the "Classpath" exception as provided
351.12 + * by Sun in the LICENSE file that accompanied this code.
351.13 + *
351.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
351.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
351.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
351.17 + * version 2 for more details (a copy is included in the LICENSE file that
351.18 + * accompanied this code).
351.19 + *
351.20 + * You should have received a copy of the GNU General Public License version
351.21 + * 2 along with this work; if not, write to the Free Software Foundation,
351.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
351.23 + *
351.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
351.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
351.26 + * have any questions.
351.27 + */
351.28 +
351.29 +/* @test
351.30 + @summary Test RiffReader readString method */
351.31 +
351.32 +import java.io.File;
351.33 +import java.io.FileInputStream;
351.34 +
351.35 +import javax.sound.sampled.*;
351.36 +
351.37 +import com.sun.media.sound.*;
351.38 +
351.39 +public class ReadString {
351.40 +
351.41 + private static void assertEquals(Object a, Object b) throws Exception
351.42 + {
351.43 + if(!a.equals(b))
351.44 + throw new RuntimeException("assertEquals fails!");
351.45 + }
351.46 +
351.47 + public static void main(String[] args) throws Exception {
351.48 + RIFFWriter writer = null;
351.49 + RIFFReader reader = null;
351.50 + File tempfile = File.createTempFile("test",".riff");
351.51 + try
351.52 + {
351.53 + writer = new RIFFWriter(tempfile, "TEST");
351.54 + RIFFWriter chunk = writer.writeChunk("TSCH");
351.55 + chunk.writeString("HELLO",5);
351.56 + writer.close();
351.57 + writer = null;
351.58 + FileInputStream fis = new FileInputStream(tempfile);
351.59 + reader = new RIFFReader(fis);
351.60 + assertEquals(reader.getFormat(), "RIFF");
351.61 + assertEquals(reader.getType(), "TEST");
351.62 + RIFFReader readchunk = reader.nextChunk();
351.63 + assertEquals(readchunk.getFormat(), "TSCH");
351.64 + assertEquals(reader.readString(5), "HELLO");
351.65 + fis.close();
351.66 + reader = null;
351.67 +
351.68 +
351.69 + }
351.70 + finally
351.71 + {
351.72 + if(writer != null)
351.73 + writer.close();
351.74 + if(reader != null)
351.75 + reader.close();
351.76 +
351.77 + if(tempfile.exists())
351.78 + if(!tempfile.delete())
351.79 + tempfile.deleteOnExit();
351.80 + }
351.81 + }
351.82 +}
352.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
352.2 +++ b/test/javax/sound/midi/Gervill/RiffReaderWriter/ReadUnsignedByte.java Tue Feb 03 22:02:55 2009 -0800
352.3 @@ -0,0 +1,79 @@
352.4 +/*
352.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
352.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
352.7 + *
352.8 + * This code is free software; you can redistribute it and/or modify it
352.9 + * under the terms of the GNU General Public License version 2 only, as
352.10 + * published by the Free Software Foundation. Sun designates this
352.11 + * particular file as subject to the "Classpath" exception as provided
352.12 + * by Sun in the LICENSE file that accompanied this code.
352.13 + *
352.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
352.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
352.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
352.17 + * version 2 for more details (a copy is included in the LICENSE file that
352.18 + * accompanied this code).
352.19 + *
352.20 + * You should have received a copy of the GNU General Public License version
352.21 + * 2 along with this work; if not, write to the Free Software Foundation,
352.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
352.23 + *
352.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
352.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
352.26 + * have any questions.
352.27 + */
352.28 +
352.29 +/* @test
352.30 + @summary Test RiffReader readUnsignedByte method */
352.31 +
352.32 +import java.io.File;
352.33 +import java.io.FileInputStream;
352.34 +
352.35 +import javax.sound.sampled.*;
352.36 +
352.37 +import com.sun.media.sound.*;
352.38 +
352.39 +public class ReadUnsignedByte {
352.40 +
352.41 + private static void assertEquals(Object a, Object b) throws Exception
352.42 + {
352.43 + if(!a.equals(b))
352.44 + throw new RuntimeException("assertEquals fails!");
352.45 + }
352.46 +
352.47 + public static void main(String[] args) throws Exception {
352.48 + RIFFWriter writer = null;
352.49 + RIFFReader reader = null;
352.50 + File tempfile = File.createTempFile("test",".riff");
352.51 + try
352.52 + {
352.53 + writer = new RIFFWriter(tempfile, "TEST");
352.54 + RIFFWriter chunk = writer.writeChunk("TSCH");
352.55 + chunk.writeUnsignedByte(77);
352.56 + writer.close();
352.57 + writer = null;
352.58 + FileInputStream fis = new FileInputStream(tempfile);
352.59 + reader = new RIFFReader(fis);
352.60 + assertEquals(reader.getFormat(), "RIFF");
352.61 + assertEquals(reader.getType(), "TEST");
352.62 + RIFFReader readchunk = reader.nextChunk();
352.63 + assertEquals(readchunk.getFormat(), "TSCH");
352.64 + assertEquals(reader.readUnsignedByte(), 77);
352.65 + fis.close();
352.66 + reader = null;
352.67 +
352.68 +
352.69 + }
352.70 + finally
352.71 + {
352.72 + if(writer != null)
352.73 + writer.close();
352.74 + if(reader != null)
352.75 + reader.close();
352.76 +
352.77 + if(tempfile.exists())
352.78 + if(!tempfile.delete())
352.79 + tempfile.deleteOnExit();
352.80 + }
352.81 + }
352.82 +}
353.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
353.2 +++ b/test/javax/sound/midi/Gervill/RiffReaderWriter/ReadUnsignedInt.java Tue Feb 03 22:02:55 2009 -0800
353.3 @@ -0,0 +1,79 @@
353.4 +/*
353.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
353.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
353.7 + *
353.8 + * This code is free software; you can redistribute it and/or modify it
353.9 + * under the terms of the GNU General Public License version 2 only, as
353.10 + * published by the Free Software Foundation. Sun designates this
353.11 + * particular file as subject to the "Classpath" exception as provided
353.12 + * by Sun in the LICENSE file that accompanied this code.
353.13 + *
353.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
353.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
353.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
353.17 + * version 2 for more details (a copy is included in the LICENSE file that
353.18 + * accompanied this code).
353.19 + *
353.20 + * You should have received a copy of the GNU General Public License version
353.21 + * 2 along with this work; if not, write to the Free Software Foundation,
353.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
353.23 + *
353.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
353.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
353.26 + * have any questions.
353.27 + */
353.28 +
353.29 +/* @test
353.30 + @summary Test RiffReader readUnsignedInt method */
353.31 +
353.32 +import java.io.File;
353.33 +import java.io.FileInputStream;
353.34 +
353.35 +import javax.sound.sampled.*;
353.36 +
353.37 +import com.sun.media.sound.*;
353.38 +
353.39 +public class ReadUnsignedInt {
353.40 +
353.41 + private static void assertEquals(Object a, Object b) throws Exception
353.42 + {
353.43 + if(!a.equals(b))
353.44 + throw new RuntimeException("assertEquals fails!");
353.45 + }
353.46 +
353.47 + public static void main(String[] args) throws Exception {
353.48 + RIFFWriter writer = null;
353.49 + RIFFReader reader = null;
353.50 + File tempfile = File.createTempFile("test",".riff");
353.51 + try
353.52 + {
353.53 + writer = new RIFFWriter(tempfile, "TEST");
353.54 + RIFFWriter chunk = writer.writeChunk("TSCH");
353.55 + chunk.writeUnsignedInt(55377);
353.56 + writer.close();
353.57 + writer = null;
353.58 + FileInputStream fis = new FileInputStream(tempfile);
353.59 + reader = new RIFFReader(fis);
353.60 + assertEquals(reader.getFormat(), "RIFF");
353.61 + assertEquals(reader.getType(), "TEST");
353.62 + RIFFReader readchunk = reader.nextChunk();
353.63 + assertEquals(readchunk.getFormat(), "TSCH");
353.64 + assertEquals(reader.readUnsignedInt(), 55377L);
353.65 + fis.close();
353.66 + reader = null;
353.67 +
353.68 +
353.69 + }
353.70 + finally
353.71 + {
353.72 + if(writer != null)
353.73 + writer.close();
353.74 + if(reader != null)
353.75 + reader.close();
353.76 +
353.77 + if(tempfile.exists())
353.78 + if(!tempfile.delete())
353.79 + tempfile.deleteOnExit();
353.80 + }
353.81 + }
353.82 +}
354.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
354.2 +++ b/test/javax/sound/midi/Gervill/RiffReaderWriter/ReadUnsignedShort.java Tue Feb 03 22:02:55 2009 -0800
354.3 @@ -0,0 +1,79 @@
354.4 +/*
354.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
354.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
354.7 + *
354.8 + * This code is free software; you can redistribute it and/or modify it
354.9 + * under the terms of the GNU General Public License version 2 only, as
354.10 + * published by the Free Software Foundation. Sun designates this
354.11 + * particular file as subject to the "Classpath" exception as provided
354.12 + * by Sun in the LICENSE file that accompanied this code.
354.13 + *
354.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
354.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
354.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
354.17 + * version 2 for more details (a copy is included in the LICENSE file that
354.18 + * accompanied this code).
354.19 + *
354.20 + * You should have received a copy of the GNU General Public License version
354.21 + * 2 along with this work; if not, write to the Free Software Foundation,
354.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
354.23 + *
354.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
354.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
354.26 + * have any questions.
354.27 + */
354.28 +
354.29 +/* @test
354.30 + @summary Test RiffReader readUnsignedShort method */
354.31 +
354.32 +import java.io.File;
354.33 +import java.io.FileInputStream;
354.34 +
354.35 +import javax.sound.sampled.*;
354.36 +
354.37 +import com.sun.media.sound.*;
354.38 +
354.39 +public class ReadUnsignedShort {
354.40 +
354.41 + private static void assertEquals(Object a, Object b) throws Exception
354.42 + {
354.43 + if(!a.equals(b))
354.44 + throw new RuntimeException("assertEquals fails!");
354.45 + }
354.46 +
354.47 + public static void main(String[] args) throws Exception {
354.48 + RIFFWriter writer = null;
354.49 + RIFFReader reader = null;
354.50 + File tempfile = File.createTempFile("test",".riff");
354.51 + try
354.52 + {
354.53 + writer = new RIFFWriter(tempfile, "TEST");
354.54 + RIFFWriter chunk = writer.writeChunk("TSCH");
354.55 + chunk.writeUnsignedShort(377);
354.56 + writer.close();
354.57 + writer = null;
354.58 + FileInputStream fis = new FileInputStream(tempfile);
354.59 + reader = new RIFFReader(fis);
354.60 + assertEquals(reader.getFormat(), "RIFF");
354.61 + assertEquals(reader.getType(), "TEST");
354.62 + RIFFReader readchunk = reader.nextChunk();
354.63 + assertEquals(readchunk.getFormat(), "TSCH");
354.64 + assertEquals(reader.readUnsignedShort(), 377);
354.65 + fis.close();
354.66 + reader = null;
354.67 +
354.68 +
354.69 + }
354.70 + finally
354.71 + {
354.72 + if(writer != null)
354.73 + writer.close();
354.74 + if(reader != null)
354.75 + reader.close();
354.76 +
354.77 + if(tempfile.exists())
354.78 + if(!tempfile.delete())
354.79 + tempfile.deleteOnExit();
354.80 + }
354.81 + }
354.82 +}
355.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
355.2 +++ b/test/javax/sound/midi/Gervill/RiffReaderWriter/Skip.java Tue Feb 03 22:02:55 2009 -0800
355.3 @@ -0,0 +1,78 @@
355.4 +/*
355.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
355.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
355.7 + *
355.8 + * This code is free software; you can redistribute it and/or modify it
355.9 + * under the terms of the GNU General Public License version 2 only, as
355.10 + * published by the Free Software Foundation. Sun designates this
355.11 + * particular file as subject to the "Classpath" exception as provided
355.12 + * by Sun in the LICENSE file that accompanied this code.
355.13 + *
355.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
355.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
355.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
355.17 + * version 2 for more details (a copy is included in the LICENSE file that
355.18 + * accompanied this code).
355.19 + *
355.20 + * You should have received a copy of the GNU General Public License version
355.21 + * 2 along with this work; if not, write to the Free Software Foundation,
355.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
355.23 + *
355.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
355.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
355.26 + * have any questions.
355.27 + */
355.28 +
355.29 +/* @test
355.30 + @summary Test RiffReader skip method */
355.31 +
355.32 +import java.io.File;
355.33 +import java.io.FileInputStream;
355.34 +
355.35 +import javax.sound.sampled.*;
355.36 +
355.37 +import com.sun.media.sound.*;
355.38 +
355.39 +public class Skip {
355.40 +
355.41 + private static void assertEquals(Object a, Object b) throws Exception
355.42 + {
355.43 + if(!a.equals(b))
355.44 + throw new RuntimeException("assertEquals fails!");
355.45 + }
355.46 +
355.47 + public static void main(String[] args) throws Exception {
355.48 + RIFFWriter writer = null;
355.49 + RIFFReader reader = null;
355.50 + File tempfile = File.createTempFile("test",".riff");
355.51 + try
355.52 + {
355.53 + writer = new RIFFWriter(tempfile, "TEST");
355.54 + RIFFWriter chunk = writer.writeChunk("TSCH");
355.55 + chunk.write((byte)33);
355.56 + chunk.write((byte)44);
355.57 + writer.close();
355.58 + writer = null;
355.59 + FileInputStream fis = new FileInputStream(tempfile);
355.60 + reader = new RIFFReader(fis);
355.61 + RIFFReader readchunk = reader.nextChunk();
355.62 + reader.skip(1);
355.63 + assertEquals(readchunk.read(), 44);
355.64 + fis.close();
355.65 + reader = null;
355.66 +
355.67 +
355.68 + }
355.69 + finally
355.70 + {
355.71 + if(writer != null)
355.72 + writer.close();
355.73 + if(reader != null)
355.74 + reader.close();
355.75 +
355.76 + if(tempfile.exists())
355.77 + if(!tempfile.delete())
355.78 + tempfile.deleteOnExit();
355.79 + }
355.80 + }
355.81 +}
356.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
356.2 +++ b/test/javax/sound/midi/Gervill/RiffReaderWriter/WriteOutputStream.java Tue Feb 03 22:02:55 2009 -0800
356.3 @@ -0,0 +1,81 @@
356.4 +/*
356.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
356.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
356.7 + *
356.8 + * This code is free software; you can redistribute it and/or modify it
356.9 + * under the terms of the GNU General Public License version 2 only, as
356.10 + * published by the Free Software Foundation. Sun designates this
356.11 + * particular file as subject to the "Classpath" exception as provided
356.12 + * by Sun in the LICENSE file that accompanied this code.
356.13 + *
356.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
356.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
356.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
356.17 + * version 2 for more details (a copy is included in the LICENSE file that
356.18 + * accompanied this code).
356.19 + *
356.20 + * You should have received a copy of the GNU General Public License version
356.21 + * 2 along with this work; if not, write to the Free Software Foundation,
356.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
356.23 + *
356.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
356.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
356.26 + * have any questions.
356.27 + */
356.28 +
356.29 +/* @test
356.30 + @summary Test RiffWriter(OutputStream) constructor */
356.31 +
356.32 +import java.io.ByteArrayInputStream;
356.33 +import java.io.ByteArrayOutputStream;
356.34 +import java.io.File;
356.35 +
356.36 +import javax.sound.sampled.*;
356.37 +
356.38 +import com.sun.media.sound.*;
356.39 +
356.40 +public class WriteOutputStream {
356.41 +
356.42 + private static void assertEquals(Object a, Object b) throws Exception
356.43 + {
356.44 + if(!a.equals(b))
356.45 + throw new RuntimeException("assertEquals fails!");
356.46 + }
356.47 +
356.48 + public static void main(String[] args) throws Exception {
356.49 + RIFFWriter writer = null;
356.50 + RIFFReader reader = null;
356.51 + File tempfile = File.createTempFile("test",".riff");
356.52 + try
356.53 + {
356.54 + ByteArrayOutputStream baos = new ByteArrayOutputStream();
356.55 + writer = new RIFFWriter(baos, "TEST");
356.56 + RIFFWriter chunk = writer.writeChunk("TSCH");
356.57 + chunk.write((byte)33);
356.58 + writer.close();
356.59 + writer = null;
356.60 + ByteArrayInputStream fis = new ByteArrayInputStream(baos.toByteArray());
356.61 + reader = new RIFFReader(fis);
356.62 + assertEquals(reader.getFormat(), "RIFF");
356.63 + assertEquals(reader.getType(), "TEST");
356.64 + RIFFReader readchunk = reader.nextChunk();
356.65 + assertEquals(readchunk.getFormat(), "TSCH");
356.66 + assertEquals(readchunk.read(), 33);
356.67 + fis.close();
356.68 + reader = null;
356.69 +
356.70 +
356.71 + }
356.72 + finally
356.73 + {
356.74 + if(writer != null)
356.75 + writer.close();
356.76 + if(reader != null)
356.77 + reader.close();
356.78 +
356.79 + if(tempfile.exists())
356.80 + if(!tempfile.delete())
356.81 + tempfile.deleteOnExit();
356.82 + }
356.83 + }
356.84 +}
357.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
357.2 +++ b/test/javax/sound/midi/Gervill/SF2SoundbankReader/TestGetSoundbankFile.java Tue Feb 03 22:02:55 2009 -0800
357.3 @@ -0,0 +1,52 @@
357.4 +/*
357.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
357.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
357.7 + *
357.8 + * This code is free software; you can redistribute it and/or modify it
357.9 + * under the terms of the GNU General Public License version 2 only, as
357.10 + * published by the Free Software Foundation. Sun designates this
357.11 + * particular file as subject to the "Classpath" exception as provided
357.12 + * by Sun in the LICENSE file that accompanied this code.
357.13 + *
357.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
357.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
357.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
357.17 + * version 2 for more details (a copy is included in the LICENSE file that
357.18 + * accompanied this code).
357.19 + *
357.20 + * You should have received a copy of the GNU General Public License version
357.21 + * 2 along with this work; if not, write to the Free Software Foundation,
357.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
357.23 + *
357.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
357.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
357.26 + * have any questions.
357.27 + */
357.28 +
357.29 +/* @test
357.30 + @summary Test SF2SoundbankReader getSoundbank(File) method */
357.31 +
357.32 +import java.io.File;
357.33 +
357.34 +import javax.sound.midi.Patch;
357.35 +import javax.sound.midi.Soundbank;
357.36 +
357.37 +import com.sun.media.sound.SF2SoundbankReader;
357.38 +
357.39 +public class TestGetSoundbankFile {
357.40 +
357.41 + private static void assertTrue(boolean value) throws Exception
357.42 + {
357.43 + if(!value)
357.44 + throw new RuntimeException("assertTrue fails!");
357.45 + }
357.46 +
357.47 + public static void main(String[] args) throws Exception {
357.48 + File file = new File(System.getProperty("test.src", "."), "ding.sf2");
357.49 + Soundbank sf2 = new SF2SoundbankReader().getSoundbank(file);
357.50 + assertTrue(sf2.getInstruments().length == 1);
357.51 + Patch patch = sf2.getInstruments()[0].getPatch();
357.52 + assertTrue(patch.getProgram() == 0);
357.53 + assertTrue(patch.getBank() == 0);
357.54 + }
357.55 +}
358.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
358.2 +++ b/test/javax/sound/midi/Gervill/SF2SoundbankReader/TestGetSoundbankInputStream.java Tue Feb 03 22:02:55 2009 -0800
358.3 @@ -0,0 +1,63 @@
358.4 +/*
358.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
358.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
358.7 + *
358.8 + * This code is free software; you can redistribute it and/or modify it
358.9 + * under the terms of the GNU General Public License version 2 only, as
358.10 + * published by the Free Software Foundation. Sun designates this
358.11 + * particular file as subject to the "Classpath" exception as provided
358.12 + * by Sun in the LICENSE file that accompanied this code.
358.13 + *
358.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
358.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
358.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
358.17 + * version 2 for more details (a copy is included in the LICENSE file that
358.18 + * accompanied this code).
358.19 + *
358.20 + * You should have received a copy of the GNU General Public License version
358.21 + * 2 along with this work; if not, write to the Free Software Foundation,
358.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
358.23 + *
358.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
358.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
358.26 + * have any questions.
358.27 + */
358.28 +
358.29 +/* @test
358.30 + @summary Test SF2SoundbankReader getSoundbank(InputStream) method */
358.31 +
358.32 +import java.io.BufferedInputStream;
358.33 +import java.io.File;
358.34 +import java.io.FileInputStream;
358.35 +
358.36 +import javax.sound.midi.Patch;
358.37 +import javax.sound.midi.Soundbank;
358.38 +
358.39 +import com.sun.media.sound.SF2SoundbankReader;
358.40 +
358.41 +public class TestGetSoundbankInputStream {
358.42 +
358.43 + private static void assertTrue(boolean value) throws Exception
358.44 + {
358.45 + if(!value)
358.46 + throw new RuntimeException("assertTrue fails!");
358.47 + }
358.48 +
358.49 + public static void main(String[] args) throws Exception {
358.50 + File file = new File(System.getProperty("test.src", "."), "ding.sf2");
358.51 + FileInputStream fis = new FileInputStream(file);
358.52 + BufferedInputStream bis = new BufferedInputStream(fis);
358.53 + try
358.54 + {
358.55 + Soundbank sf2 = new SF2SoundbankReader().getSoundbank(bis);
358.56 + assertTrue(sf2.getInstruments().length == 1);
358.57 + Patch patch = sf2.getInstruments()[0].getPatch();
358.58 + assertTrue(patch.getProgram() == 0);
358.59 + assertTrue(patch.getBank() == 0);
358.60 + }
358.61 + finally
358.62 + {
358.63 + bis.close();
358.64 + }
358.65 + }
358.66 +}
359.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
359.2 +++ b/test/javax/sound/midi/Gervill/SF2SoundbankReader/TestGetSoundbankInputStream2.java Tue Feb 03 22:02:55 2009 -0800
359.3 @@ -0,0 +1,119 @@
359.4 +/*
359.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
359.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
359.7 + *
359.8 + * This code is free software; you can redistribute it and/or modify it
359.9 + * under the terms of the GNU General Public License version 2 only, as
359.10 + * published by the Free Software Foundation. Sun designates this
359.11 + * particular file as subject to the "Classpath" exception as provided
359.12 + * by Sun in the LICENSE file that accompanied this code.
359.13 + *
359.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
359.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
359.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
359.17 + * version 2 for more details (a copy is included in the LICENSE file that
359.18 + * accompanied this code).
359.19 + *
359.20 + * You should have received a copy of the GNU General Public License version
359.21 + * 2 along with this work; if not, write to the Free Software Foundation,
359.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
359.23 + *
359.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
359.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
359.26 + * have any questions.
359.27 + */
359.28 +
359.29 +/* @test
359.30 + @summary Test SF2SoundbankReader getSoundbank(InputStream) method using
359.31 + very bad InputStream which can only read 1 byte at time */
359.32 +
359.33 +import java.io.BufferedInputStream;
359.34 +import java.io.File;
359.35 +import java.io.FileInputStream;
359.36 +import java.io.IOException;
359.37 +import java.io.InputStream;
359.38 +
359.39 +import javax.sound.midi.Patch;
359.40 +import javax.sound.midi.Soundbank;
359.41 +
359.42 +import com.sun.media.sound.SF2SoundbankReader;
359.43 +
359.44 +public class TestGetSoundbankInputStream2 {
359.45 +
359.46 + private static class BadInputStream extends InputStream
359.47 + {
359.48 +
359.49 + InputStream is;
359.50 +
359.51 + public BadInputStream(InputStream is)
359.52 + {
359.53 + this.is = is;
359.54 + }
359.55 +
359.56 + public int read() throws IOException {
359.57 + return is.read();
359.58 + }
359.59 +
359.60 + public int read(byte[] b, int off, int len) throws IOException {
359.61 + if(len > 1) len = 1;
359.62 + return is.read(b, off, len);
359.63 + }
359.64 +
359.65 + public int read(byte[] b) throws IOException {
359.66 + return read(b, 0, b.length);
359.67 + }
359.68 +
359.69 + public long skip(long n) throws IOException {
359.70 + if(n > 1) n = 1;
359.71 + return is.skip(n);
359.72 + }
359.73 +
359.74 + public int available() throws IOException {
359.75 + int avail = is.available();
359.76 + if(avail > 1) avail = 1;
359.77 + return avail;
359.78 + }
359.79 +
359.80 + public void close() throws IOException {
359.81 + is.close();
359.82 + }
359.83 +
359.84 + public synchronized void mark(int readlimit) {
359.85 + is.mark(readlimit);
359.86 + }
359.87 +
359.88 + public boolean markSupported() {
359.89 + return is.markSupported();
359.90 + }
359.91 +
359.92 + public synchronized void reset() throws IOException {
359.93 + is.reset();
359.94 + }
359.95 +
359.96 + }
359.97 +
359.98 + private static void assertTrue(boolean value) throws Exception
359.99 + {
359.100 + if(!value)
359.101 + throw new RuntimeException("assertTrue fails!");
359.102 + }
359.103 +
359.104 + public static void main(String[] args) throws Exception {
359.105 + File file = new File(System.getProperty("test.src", "."), "ding.sf2");
359.106 + FileInputStream fis = new FileInputStream(file);
359.107 + BufferedInputStream bis = new BufferedInputStream(fis);
359.108 + try
359.109 + {
359.110 + InputStream badis = new BadInputStream(bis);
359.111 + Soundbank sf2 = new SF2SoundbankReader().getSoundbank(badis);
359.112 + assertTrue(sf2.getInstruments().length == 1);
359.113 + Patch patch = sf2.getInstruments()[0].getPatch();
359.114 + assertTrue(patch.getProgram() == 0);
359.115 + assertTrue(patch.getBank() == 0);
359.116 + }
359.117 + finally
359.118 + {
359.119 + bis.close();
359.120 + }
359.121 + }
359.122 +}
360.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
360.2 +++ b/test/javax/sound/midi/Gervill/SF2SoundbankReader/TestGetSoundbankUrl.java Tue Feb 03 22:02:55 2009 -0800
360.3 @@ -0,0 +1,54 @@
360.4 +/*
360.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
360.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
360.7 + *
360.8 + * This code is free software; you can redistribute it and/or modify it
360.9 + * under the terms of the GNU General Public License version 2 only, as
360.10 + * published by the Free Software Foundation. Sun designates this
360.11 + * particular file as subject to the "Classpath" exception as provided
360.12 + * by Sun in the LICENSE file that accompanied this code.
360.13 + *
360.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
360.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
360.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
360.17 + * version 2 for more details (a copy is included in the LICENSE file that
360.18 + * accompanied this code).
360.19 + *
360.20 + * You should have received a copy of the GNU General Public License version
360.21 + * 2 along with this work; if not, write to the Free Software Foundation,
360.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
360.23 + *
360.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
360.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
360.26 + * have any questions.
360.27 + */
360.28 +
360.29 +/* @test
360.30 + @summary Test SF2SoundbankReader getSoundbank(File) method */
360.31 +
360.32 +import java.io.File;
360.33 +import java.net.URL;
360.34 +
360.35 +import javax.sound.midi.Patch;
360.36 +import javax.sound.midi.Soundbank;
360.37 +
360.38 +import com.sun.media.sound.SF2SoundbankReader;
360.39 +
360.40 +public class TestGetSoundbankUrl {
360.41 +
360.42 + private static void assertTrue(boolean value) throws Exception
360.43 + {
360.44 + if(!value)
360.45 + throw new RuntimeException("assertTrue fails!");
360.46 + }
360.47 +
360.48 + public static void main(String[] args) throws Exception {
360.49 + File file = new File(System.getProperty("test.src", "."), "ding.sf2");
360.50 + URL url = file.toURI().toURL();
360.51 + Soundbank sf2 = new SF2SoundbankReader().getSoundbank(url);
360.52 + assertTrue(sf2.getInstruments().length == 1);
360.53 + Patch patch = sf2.getInstruments()[0].getPatch();
360.54 + assertTrue(patch.getProgram() == 0);
360.55 + assertTrue(patch.getBank() == 0);
360.56 + }
360.57 +}
361.1 Binary file test/javax/sound/midi/Gervill/SF2SoundbankReader/ding.sf2 has changed
362.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
362.2 +++ b/test/javax/sound/midi/Gervill/SimpleInstrument/AddModelInstrument.java Tue Feb 03 22:02:55 2009 -0800
362.3 @@ -0,0 +1,86 @@
362.4 +/*
362.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
362.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
362.7 + *
362.8 + * This code is free software; you can redistribute it and/or modify it
362.9 + * under the terms of the GNU General Public License version 2 only, as
362.10 + * published by the Free Software Foundation. Sun designates this
362.11 + * particular file as subject to the "Classpath" exception as provided
362.12 + * by Sun in the LICENSE file that accompanied this code.
362.13 + *
362.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
362.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
362.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
362.17 + * version 2 for more details (a copy is included in the LICENSE file that
362.18 + * accompanied this code).
362.19 + *
362.20 + * You should have received a copy of the GNU General Public License version
362.21 + * 2 along with this work; if not, write to the Free Software Foundation,
362.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
362.23 + *
362.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
362.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
362.26 + * have any questions.
362.27 + */
362.28 +
362.29 +/* @test
362.30 + @summary Test SimpleInstrument add(ModelInstrument) method */
362.31 +
362.32 +import javax.sound.sampled.*;
362.33 +
362.34 +import com.sun.media.sound.*;
362.35 +
362.36 +public class AddModelInstrument {
362.37 +
362.38 + private static void assertEquals(Object a, Object b) throws Exception
362.39 + {
362.40 + if(!a.equals(b))
362.41 + throw new RuntimeException("assertEquals fails!");
362.42 + }
362.43 +
362.44 + public static void main(String[] args) throws Exception {
362.45 +
362.46 + SimpleInstrument instrument = new SimpleInstrument();
362.47 +
362.48 + ModelPerformer[] performers = new ModelPerformer[2];
362.49 +
362.50 + performers[0] = new ModelPerformer();
362.51 + performers[0].setExclusiveClass(1);
362.52 + performers[0].setKeyFrom(36);
362.53 + performers[0].setKeyTo(48);
362.54 + performers[0].setVelFrom(16);
362.55 + performers[0].setVelTo(80);
362.56 + performers[0].setSelfNonExclusive(true);
362.57 + performers[0].setDefaultConnectionsEnabled(false);
362.58 + performers[0].getConnectionBlocks().add(new ModelConnectionBlock());
362.59 + performers[0].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
362.60 +
362.61 + performers[1] = new ModelPerformer();
362.62 + performers[1].setExclusiveClass(0);
362.63 + performers[1].setKeyFrom(12);
362.64 + performers[1].setKeyTo(24);
362.65 + performers[1].setVelFrom(20);
362.66 + performers[1].setVelTo(90);
362.67 + performers[1].setSelfNonExclusive(false);
362.68 + performers[0].setDefaultConnectionsEnabled(true);
362.69 + performers[1].getConnectionBlocks().add(new ModelConnectionBlock());
362.70 + performers[1].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
362.71 +
362.72 + SimpleInstrument subins = new SimpleInstrument();
362.73 + subins.add(performers[0]);
362.74 + instrument.add(subins);
362.75 + instrument.add(performers[1]);
362.76 + ModelPerformer[] performers2 = instrument.getPerformers();
362.77 + for (int i = 0; i < performers2.length; i++) {
362.78 + assertEquals(performers[i].getConnectionBlocks(), performers2[i].getConnectionBlocks());
362.79 + assertEquals(performers[i].getExclusiveClass(), performers2[i].getExclusiveClass());
362.80 + assertEquals(performers[i].getKeyFrom(), performers2[i].getKeyFrom());
362.81 + assertEquals(performers[i].getKeyTo(), performers2[i].getKeyTo());
362.82 + assertEquals(performers[i].getVelFrom(), performers2[i].getVelFrom());
362.83 + assertEquals(performers[i].getVelTo(), performers2[i].getVelTo());
362.84 + assertEquals(performers[i].getOscillators(), performers2[i].getOscillators());
362.85 + assertEquals(performers[i].isSelfNonExclusive(), performers2[i].isSelfNonExclusive());
362.86 + assertEquals(performers[i].isDefaultConnectionsEnabled(), performers2[i].isDefaultConnectionsEnabled());
362.87 + }
362.88 + }
362.89 +}
363.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
363.2 +++ b/test/javax/sound/midi/Gervill/SimpleInstrument/AddModelInstrumentIntInt.java Tue Feb 03 22:02:55 2009 -0800
363.3 @@ -0,0 +1,91 @@
363.4 +/*
363.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
363.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
363.7 + *
363.8 + * This code is free software; you can redistribute it and/or modify it
363.9 + * under the terms of the GNU General Public License version 2 only, as
363.10 + * published by the Free Software Foundation. Sun designates this
363.11 + * particular file as subject to the "Classpath" exception as provided
363.12 + * by Sun in the LICENSE file that accompanied this code.
363.13 + *
363.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
363.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
363.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
363.17 + * version 2 for more details (a copy is included in the LICENSE file that
363.18 + * accompanied this code).
363.19 + *
363.20 + * You should have received a copy of the GNU General Public License version
363.21 + * 2 along with this work; if not, write to the Free Software Foundation,
363.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
363.23 + *
363.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
363.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
363.26 + * have any questions.
363.27 + */
363.28 +
363.29 +/* @test
363.30 + @summary Test SimpleInstrument add(ModelInstrument,int,int) method */
363.31 +
363.32 +import javax.sound.sampled.*;
363.33 +
363.34 +import com.sun.media.sound.*;
363.35 +
363.36 +public class AddModelInstrumentIntInt {
363.37 +
363.38 + private static void assertEquals(Object a, Object b) throws Exception
363.39 + {
363.40 + if(!a.equals(b))
363.41 + throw new RuntimeException("assertEquals fails!");
363.42 + }
363.43 +
363.44 + public static void main(String[] args) throws Exception {
363.45 +
363.46 + SimpleInstrument instrument = new SimpleInstrument();
363.47 +
363.48 + ModelPerformer[] performers = new ModelPerformer[2];
363.49 +
363.50 + performers[0] = new ModelPerformer();
363.51 + performers[0].setExclusiveClass(1);
363.52 + performers[0].setKeyFrom(36);
363.53 + performers[0].setKeyTo(48);
363.54 + performers[0].setVelFrom(16);
363.55 + performers[0].setVelTo(80);
363.56 + performers[0].setSelfNonExclusive(true);
363.57 + performers[0].setDefaultConnectionsEnabled(false);
363.58 + performers[0].getConnectionBlocks().add(new ModelConnectionBlock());
363.59 + performers[0].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
363.60 +
363.61 + performers[1] = new ModelPerformer();
363.62 + performers[1].setExclusiveClass(0);
363.63 + performers[1].setKeyFrom(12);
363.64 + performers[1].setKeyTo(24);
363.65 + performers[1].setVelFrom(20);
363.66 + performers[1].setVelTo(90);
363.67 + performers[1].setSelfNonExclusive(false);
363.68 + performers[0].setDefaultConnectionsEnabled(true);
363.69 + performers[1].getConnectionBlocks().add(new ModelConnectionBlock());
363.70 + performers[1].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
363.71 +
363.72 + SimpleInstrument subins = new SimpleInstrument();
363.73 + subins.add(performers[0]);
363.74 + instrument.add(subins, 18, 40);
363.75 + ModelPerformer[] performers2 = instrument.getPerformers();
363.76 + for (int i = 0; i < performers2.length; i++) {
363.77 + assertEquals(performers[i].getConnectionBlocks(), performers2[i].getConnectionBlocks());
363.78 + assertEquals(performers[i].getExclusiveClass(), performers2[i].getExclusiveClass());
363.79 + if(performers[i].getKeyFrom() < 18)
363.80 + assertEquals(18, performers2[i].getKeyFrom());
363.81 + else
363.82 + assertEquals(performers[i].getKeyFrom(), performers2[i].getKeyFrom());
363.83 + if(performers[i].getKeyTo() > 40)
363.84 + assertEquals(40, performers2[i].getKeyTo());
363.85 + else
363.86 + assertEquals(performers[i].getKeyTo(), performers2[i].getKeyTo());
363.87 + assertEquals(performers[i].getVelFrom(), performers2[i].getVelFrom());
363.88 + assertEquals(performers[i].getVelTo(), performers2[i].getVelTo());
363.89 + assertEquals(performers[i].getOscillators(), performers2[i].getOscillators());
363.90 + assertEquals(performers[i].isSelfNonExclusive(), performers2[i].isSelfNonExclusive());
363.91 + assertEquals(performers[i].isDefaultConnectionsEnabled(), performers2[i].isDefaultConnectionsEnabled());
363.92 + }
363.93 + }
363.94 +}
364.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
364.2 +++ b/test/javax/sound/midi/Gervill/SimpleInstrument/AddModelInstrumentIntIntIntInt.java Tue Feb 03 22:02:55 2009 -0800
364.3 @@ -0,0 +1,97 @@
364.4 +/*
364.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
364.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
364.7 + *
364.8 + * This code is free software; you can redistribute it and/or modify it
364.9 + * under the terms of the GNU General Public License version 2 only, as
364.10 + * published by the Free Software Foundation. Sun designates this
364.11 + * particular file as subject to the "Classpath" exception as provided
364.12 + * by Sun in the LICENSE file that accompanied this code.
364.13 + *
364.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
364.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
364.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
364.17 + * version 2 for more details (a copy is included in the LICENSE file that
364.18 + * accompanied this code).
364.19 + *
364.20 + * You should have received a copy of the GNU General Public License version
364.21 + * 2 along with this work; if not, write to the Free Software Foundation,
364.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
364.23 + *
364.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
364.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
364.26 + * have any questions.
364.27 + */
364.28 +
364.29 +/* @test
364.30 + @summary Test SimpleInstrument add(ModelInstrument,int,int,int,int) method */
364.31 +
364.32 +import javax.sound.sampled.*;
364.33 +
364.34 +import com.sun.media.sound.*;
364.35 +
364.36 +public class AddModelInstrumentIntIntIntInt {
364.37 +
364.38 + private static void assertEquals(Object a, Object b) throws Exception
364.39 + {
364.40 + if(!a.equals(b))
364.41 + throw new RuntimeException("assertEquals fails!");
364.42 + }
364.43 +
364.44 + public static void main(String[] args) throws Exception {
364.45 +
364.46 + SimpleInstrument instrument = new SimpleInstrument();
364.47 +
364.48 + ModelPerformer[] performers = new ModelPerformer[2];
364.49 +
364.50 + performers[0] = new ModelPerformer();
364.51 + performers[0].setExclusiveClass(1);
364.52 + performers[0].setKeyFrom(36);
364.53 + performers[0].setKeyTo(48);
364.54 + performers[0].setVelFrom(16);
364.55 + performers[0].setVelTo(80);
364.56 + performers[0].setSelfNonExclusive(true);
364.57 + performers[0].setDefaultConnectionsEnabled(false);
364.58 + performers[0].getConnectionBlocks().add(new ModelConnectionBlock());
364.59 + performers[0].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
364.60 +
364.61 + performers[1] = new ModelPerformer();
364.62 + performers[1].setExclusiveClass(0);
364.63 + performers[1].setKeyFrom(12);
364.64 + performers[1].setKeyTo(24);
364.65 + performers[1].setVelFrom(20);
364.66 + performers[1].setVelTo(90);
364.67 + performers[1].setSelfNonExclusive(false);
364.68 + performers[0].setDefaultConnectionsEnabled(true);
364.69 + performers[1].getConnectionBlocks().add(new ModelConnectionBlock());
364.70 + performers[1].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
364.71 +
364.72 + SimpleInstrument subins = new SimpleInstrument();
364.73 + subins.add(performers[0]);
364.74 + instrument.add(subins,18,40,20,75);
364.75 + ModelPerformer[] performers2 = instrument.getPerformers();
364.76 + for (int i = 0; i < performers2.length; i++) {
364.77 + assertEquals(performers[i].getConnectionBlocks(), performers2[i].getConnectionBlocks());
364.78 + assertEquals(performers[i].getExclusiveClass(), performers2[i].getExclusiveClass());
364.79 + if(performers[i].getKeyFrom() < 18)
364.80 + assertEquals(18, performers2[i].getKeyFrom());
364.81 + else
364.82 + assertEquals(performers[i].getKeyFrom(), performers2[i].getKeyFrom());
364.83 + if(performers[i].getKeyTo() > 40)
364.84 + assertEquals(40, performers2[i].getKeyTo());
364.85 + else
364.86 + assertEquals(performers[i].getKeyTo(), performers2[i].getKeyTo());
364.87 + if(performers[i].getVelFrom() < 20)
364.88 + assertEquals(20, performers2[i].getVelFrom());
364.89 + else
364.90 + assertEquals(performers[i].getVelFrom(), performers2[i].getVelFrom());
364.91 + if(performers[i].getVelTo() > 75)
364.92 + assertEquals(75, performers2[i].getVelTo());
364.93 + else
364.94 + assertEquals(performers[i].getVelTo(), performers2[i].getVelTo());
364.95 + assertEquals(performers[i].getOscillators(), performers2[i].getOscillators());
364.96 + assertEquals(performers[i].isSelfNonExclusive(), performers2[i].isSelfNonExclusive());
364.97 + assertEquals(performers[i].isDefaultConnectionsEnabled(), performers2[i].isDefaultConnectionsEnabled());
364.98 + }
364.99 + }
364.100 +}
365.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
365.2 +++ b/test/javax/sound/midi/Gervill/SimpleInstrument/AddModelInstrumentIntIntIntIntInt.java Tue Feb 03 22:02:55 2009 -0800
365.3 @@ -0,0 +1,97 @@
365.4 +/*
365.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
365.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
365.7 + *
365.8 + * This code is free software; you can redistribute it and/or modify it
365.9 + * under the terms of the GNU General Public License version 2 only, as
365.10 + * published by the Free Software Foundation. Sun designates this
365.11 + * particular file as subject to the "Classpath" exception as provided
365.12 + * by Sun in the LICENSE file that accompanied this code.
365.13 + *
365.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
365.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
365.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
365.17 + * version 2 for more details (a copy is included in the LICENSE file that
365.18 + * accompanied this code).
365.19 + *
365.20 + * You should have received a copy of the GNU General Public License version
365.21 + * 2 along with this work; if not, write to the Free Software Foundation,
365.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
365.23 + *
365.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
365.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
365.26 + * have any questions.
365.27 + */
365.28 +
365.29 +/* @test
365.30 + @summary Test SimpleInstrument add(ModelInstrument,int,int,int,int,int) method */
365.31 +
365.32 +import javax.sound.sampled.*;
365.33 +
365.34 +import com.sun.media.sound.*;
365.35 +
365.36 +public class AddModelInstrumentIntIntIntIntInt {
365.37 +
365.38 + private static void assertEquals(Object a, Object b) throws Exception
365.39 + {
365.40 + if(!a.equals(b))
365.41 + throw new RuntimeException("assertEquals fails!");
365.42 + }
365.43 +
365.44 + public static void main(String[] args) throws Exception {
365.45 +
365.46 + SimpleInstrument instrument = new SimpleInstrument();
365.47 +
365.48 + ModelPerformer[] performers = new ModelPerformer[2];
365.49 +
365.50 + performers[0] = new ModelPerformer();
365.51 + performers[0].setExclusiveClass(1);
365.52 + performers[0].setKeyFrom(36);
365.53 + performers[0].setKeyTo(48);
365.54 + performers[0].setVelFrom(16);
365.55 + performers[0].setVelTo(80);
365.56 + performers[0].setSelfNonExclusive(true);
365.57 + performers[0].setDefaultConnectionsEnabled(false);
365.58 + performers[0].getConnectionBlocks().add(new ModelConnectionBlock());
365.59 + performers[0].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
365.60 +
365.61 + performers[1] = new ModelPerformer();
365.62 + performers[1].setExclusiveClass(0);
365.63 + performers[1].setKeyFrom(12);
365.64 + performers[1].setKeyTo(24);
365.65 + performers[1].setVelFrom(20);
365.66 + performers[1].setVelTo(90);
365.67 + performers[1].setSelfNonExclusive(false);
365.68 + performers[0].setDefaultConnectionsEnabled(true);
365.69 + performers[1].getConnectionBlocks().add(new ModelConnectionBlock());
365.70 + performers[1].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
365.71 +
365.72 + SimpleInstrument subins = new SimpleInstrument();
365.73 + subins.add(performers[0]);
365.74 + instrument.add(subins,18,40,20,75,12);
365.75 + ModelPerformer[] performers2 = instrument.getPerformers();
365.76 + for (int i = 0; i < performers2.length; i++) {
365.77 + assertEquals(performers[i].getConnectionBlocks(), performers2[i].getConnectionBlocks());
365.78 + assertEquals(12, performers2[i].getExclusiveClass());
365.79 + if(performers[i].getKeyFrom() < 18)
365.80 + assertEquals(18, performers2[i].getKeyFrom());
365.81 + else
365.82 + assertEquals(performers[i].getKeyFrom(), performers2[i].getKeyFrom());
365.83 + if(performers[i].getKeyTo() > 40)
365.84 + assertEquals(40, performers2[i].getKeyTo());
365.85 + else
365.86 + assertEquals(performers[i].getKeyTo(), performers2[i].getKeyTo());
365.87 + if(performers[i].getVelFrom() < 20)
365.88 + assertEquals(20, performers2[i].getVelFrom());
365.89 + else
365.90 + assertEquals(performers[i].getVelFrom(), performers2[i].getVelFrom());
365.91 + if(performers[i].getVelTo() > 75)
365.92 + assertEquals(75, performers2[i].getVelTo());
365.93 + else
365.94 + assertEquals(performers[i].getVelTo(), performers2[i].getVelTo());
365.95 + assertEquals(performers[i].getOscillators(), performers2[i].getOscillators());
365.96 + assertEquals(performers[i].isSelfNonExclusive(), performers2[i].isSelfNonExclusive());
365.97 + assertEquals(performers[i].isDefaultConnectionsEnabled(), performers2[i].isDefaultConnectionsEnabled());
365.98 + }
365.99 + }
365.100 +}
366.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
366.2 +++ b/test/javax/sound/midi/Gervill/SimpleInstrument/AddModelPerformer.java Tue Feb 03 22:02:55 2009 -0800
366.3 @@ -0,0 +1,83 @@
366.4 +/*
366.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
366.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
366.7 + *
366.8 + * This code is free software; you can redistribute it and/or modify it
366.9 + * under the terms of the GNU General Public License version 2 only, as
366.10 + * published by the Free Software Foundation. Sun designates this
366.11 + * particular file as subject to the "Classpath" exception as provided
366.12 + * by Sun in the LICENSE file that accompanied this code.
366.13 + *
366.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
366.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
366.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
366.17 + * version 2 for more details (a copy is included in the LICENSE file that
366.18 + * accompanied this code).
366.19 + *
366.20 + * You should have received a copy of the GNU General Public License version
366.21 + * 2 along with this work; if not, write to the Free Software Foundation,
366.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
366.23 + *
366.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
366.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
366.26 + * have any questions.
366.27 + */
366.28 +
366.29 +/* @test
366.30 + @summary Test SimpleInstrument add(ModelPerformer) method */
366.31 +
366.32 +import javax.sound.sampled.*;
366.33 +
366.34 +import com.sun.media.sound.*;
366.35 +
366.36 +public class AddModelPerformer {
366.37 +
366.38 + private static void assertEquals(Object a, Object b) throws Exception
366.39 + {
366.40 + if(!a.equals(b))
366.41 + throw new RuntimeException("assertEquals fails!");
366.42 + }
366.43 +
366.44 + public static void main(String[] args) throws Exception {
366.45 +
366.46 + SimpleInstrument instrument = new SimpleInstrument();
366.47 +
366.48 + ModelPerformer[] performers = new ModelPerformer[2];
366.49 +
366.50 + performers[0] = new ModelPerformer();
366.51 + performers[0].setExclusiveClass(1);
366.52 + performers[0].setKeyFrom(36);
366.53 + performers[0].setKeyTo(48);
366.54 + performers[0].setVelFrom(16);
366.55 + performers[0].setVelTo(80);
366.56 + performers[0].setSelfNonExclusive(true);
366.57 + performers[0].setDefaultConnectionsEnabled(false);
366.58 + performers[0].getConnectionBlocks().add(new ModelConnectionBlock());
366.59 + performers[0].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
366.60 +
366.61 + performers[1] = new ModelPerformer();
366.62 + performers[1].setExclusiveClass(0);
366.63 + performers[1].setKeyFrom(12);
366.64 + performers[1].setKeyTo(24);
366.65 + performers[1].setVelFrom(20);
366.66 + performers[1].setVelTo(90);
366.67 + performers[1].setSelfNonExclusive(false);
366.68 + performers[0].setDefaultConnectionsEnabled(true);
366.69 + performers[1].getConnectionBlocks().add(new ModelConnectionBlock());
366.70 + performers[1].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
366.71 +
366.72 + instrument.add(performers[0]);
366.73 + ModelPerformer[] performers2 = instrument.getPerformers();
366.74 + for (int i = 0; i < performers2.length; i++) {
366.75 + assertEquals(performers[i].getConnectionBlocks(), performers2[i].getConnectionBlocks());
366.76 + assertEquals(performers[i].getExclusiveClass(), performers2[i].getExclusiveClass());
366.77 + assertEquals(performers[i].getKeyFrom(), performers2[i].getKeyFrom());
366.78 + assertEquals(performers[i].getKeyTo(), performers2[i].getKeyTo());
366.79 + assertEquals(performers[i].getVelFrom(), performers2[i].getVelFrom());
366.80 + assertEquals(performers[i].getVelTo(), performers2[i].getVelTo());
366.81 + assertEquals(performers[i].getOscillators(), performers2[i].getOscillators());
366.82 + assertEquals(performers[i].isSelfNonExclusive(), performers2[i].isSelfNonExclusive());
366.83 + assertEquals(performers[i].isDefaultConnectionsEnabled(), performers2[i].isDefaultConnectionsEnabled());
366.84 + }
366.85 + }
366.86 +}
367.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
367.2 +++ b/test/javax/sound/midi/Gervill/SimpleInstrument/AddModelPerformerArray.java Tue Feb 03 22:02:55 2009 -0800
367.3 @@ -0,0 +1,83 @@
367.4 +/*
367.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
367.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
367.7 + *
367.8 + * This code is free software; you can redistribute it and/or modify it
367.9 + * under the terms of the GNU General Public License version 2 only, as
367.10 + * published by the Free Software Foundation. Sun designates this
367.11 + * particular file as subject to the "Classpath" exception as provided
367.12 + * by Sun in the LICENSE file that accompanied this code.
367.13 + *
367.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
367.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
367.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
367.17 + * version 2 for more details (a copy is included in the LICENSE file that
367.18 + * accompanied this code).
367.19 + *
367.20 + * You should have received a copy of the GNU General Public License version
367.21 + * 2 along with this work; if not, write to the Free Software Foundation,
367.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
367.23 + *
367.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
367.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
367.26 + * have any questions.
367.27 + */
367.28 +
367.29 +/* @test
367.30 + @summary Test SimpleInstrument add(ModelPerformer[]) method */
367.31 +
367.32 +import javax.sound.sampled.*;
367.33 +
367.34 +import com.sun.media.sound.*;
367.35 +
367.36 +public class AddModelPerformerArray {
367.37 +
367.38 + private static void assertEquals(Object a, Object b) throws Exception
367.39 + {
367.40 + if(!a.equals(b))
367.41 + throw new RuntimeException("assertEquals fails!");
367.42 + }
367.43 +
367.44 + public static void main(String[] args) throws Exception {
367.45 +
367.46 + SimpleInstrument instrument = new SimpleInstrument();
367.47 +
367.48 + ModelPerformer[] performers = new ModelPerformer[2];
367.49 +
367.50 + performers[0] = new ModelPerformer();
367.51 + performers[0].setExclusiveClass(1);
367.52 + performers[0].setKeyFrom(36);
367.53 + performers[0].setKeyTo(48);
367.54 + performers[0].setVelFrom(16);
367.55 + performers[0].setVelTo(80);
367.56 + performers[0].setSelfNonExclusive(true);
367.57 + performers[0].setDefaultConnectionsEnabled(false);
367.58 + performers[0].getConnectionBlocks().add(new ModelConnectionBlock());
367.59 + performers[0].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
367.60 +
367.61 + performers[1] = new ModelPerformer();
367.62 + performers[1].setExclusiveClass(0);
367.63 + performers[1].setKeyFrom(12);
367.64 + performers[1].setKeyTo(24);
367.65 + performers[1].setVelFrom(20);
367.66 + performers[1].setVelTo(90);
367.67 + performers[1].setSelfNonExclusive(false);
367.68 + performers[0].setDefaultConnectionsEnabled(true);
367.69 + performers[1].getConnectionBlocks().add(new ModelConnectionBlock());
367.70 + performers[1].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
367.71 +
367.72 + instrument.add(performers);
367.73 + ModelPerformer[] performers2 = instrument.getPerformers();
367.74 + for (int i = 0; i < performers2.length; i++) {
367.75 + assertEquals(performers[i].getConnectionBlocks(), performers2[i].getConnectionBlocks());
367.76 + assertEquals(performers[i].getExclusiveClass(), performers2[i].getExclusiveClass());
367.77 + assertEquals(performers[i].getKeyFrom(), performers2[i].getKeyFrom());
367.78 + assertEquals(performers[i].getKeyTo(), performers2[i].getKeyTo());
367.79 + assertEquals(performers[i].getVelFrom(), performers2[i].getVelFrom());
367.80 + assertEquals(performers[i].getVelTo(), performers2[i].getVelTo());
367.81 + assertEquals(performers[i].getOscillators(), performers2[i].getOscillators());
367.82 + assertEquals(performers[i].isSelfNonExclusive(), performers2[i].isSelfNonExclusive());
367.83 + assertEquals(performers[i].isDefaultConnectionsEnabled(), performers2[i].isDefaultConnectionsEnabled());
367.84 + }
367.85 + }
367.86 +}
368.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
368.2 +++ b/test/javax/sound/midi/Gervill/SimpleInstrument/AddModelPerformerArrayIntInt.java Tue Feb 03 22:02:55 2009 -0800
368.3 @@ -0,0 +1,89 @@
368.4 +/*
368.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
368.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
368.7 + *
368.8 + * This code is free software; you can redistribute it and/or modify it
368.9 + * under the terms of the GNU General Public License version 2 only, as
368.10 + * published by the Free Software Foundation. Sun designates this
368.11 + * particular file as subject to the "Classpath" exception as provided
368.12 + * by Sun in the LICENSE file that accompanied this code.
368.13 + *
368.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
368.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
368.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
368.17 + * version 2 for more details (a copy is included in the LICENSE file that
368.18 + * accompanied this code).
368.19 + *
368.20 + * You should have received a copy of the GNU General Public License version
368.21 + * 2 along with this work; if not, write to the Free Software Foundation,
368.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
368.23 + *
368.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
368.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
368.26 + * have any questions.
368.27 + */
368.28 +
368.29 +/* @test
368.30 + @summary Test SimpleInstrument add(ModelPerformer[],int,int) method */
368.31 +
368.32 +import javax.sound.sampled.*;
368.33 +
368.34 +import com.sun.media.sound.*;
368.35 +
368.36 +public class AddModelPerformerArrayIntInt {
368.37 +
368.38 + private static void assertEquals(Object a, Object b) throws Exception
368.39 + {
368.40 + if(!a.equals(b))
368.41 + throw new RuntimeException("assertEquals fails!");
368.42 + }
368.43 +
368.44 + public static void main(String[] args) throws Exception {
368.45 +
368.46 + SimpleInstrument instrument = new SimpleInstrument();
368.47 +
368.48 + ModelPerformer[] performers = new ModelPerformer[2];
368.49 +
368.50 + performers[0] = new ModelPerformer();
368.51 + performers[0].setExclusiveClass(1);
368.52 + performers[0].setKeyFrom(36);
368.53 + performers[0].setKeyTo(48);
368.54 + performers[0].setVelFrom(16);
368.55 + performers[0].setVelTo(80);
368.56 + performers[0].setSelfNonExclusive(true);
368.57 + performers[0].setDefaultConnectionsEnabled(false);
368.58 + performers[0].getConnectionBlocks().add(new ModelConnectionBlock());
368.59 + performers[0].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
368.60 +
368.61 + performers[1] = new ModelPerformer();
368.62 + performers[1].setExclusiveClass(0);
368.63 + performers[1].setKeyFrom(12);
368.64 + performers[1].setKeyTo(24);
368.65 + performers[1].setVelFrom(20);
368.66 + performers[1].setVelTo(90);
368.67 + performers[1].setSelfNonExclusive(false);
368.68 + performers[0].setDefaultConnectionsEnabled(true);
368.69 + performers[1].getConnectionBlocks().add(new ModelConnectionBlock());
368.70 + performers[1].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
368.71 +
368.72 + instrument.add(performers,18,40);
368.73 + ModelPerformer[] performers2 = instrument.getPerformers();
368.74 + for (int i = 0; i < performers2.length; i++) {
368.75 + assertEquals(performers[i].getConnectionBlocks(), performers2[i].getConnectionBlocks());
368.76 + assertEquals(performers[i].getExclusiveClass(), performers2[i].getExclusiveClass());
368.77 + if(performers[i].getKeyFrom() < 18)
368.78 + assertEquals(18, performers2[i].getKeyFrom());
368.79 + else
368.80 + assertEquals(performers[i].getKeyFrom(), performers2[i].getKeyFrom());
368.81 + if(performers[i].getKeyTo() > 40)
368.82 + assertEquals(40, performers2[i].getKeyTo());
368.83 + else
368.84 + assertEquals(performers[i].getKeyTo(), performers2[i].getKeyTo());
368.85 + assertEquals(performers[i].getVelFrom(), performers2[i].getVelFrom());
368.86 + assertEquals(performers[i].getVelTo(), performers2[i].getVelTo());
368.87 + assertEquals(performers[i].getOscillators(), performers2[i].getOscillators());
368.88 + assertEquals(performers[i].isSelfNonExclusive(), performers2[i].isSelfNonExclusive());
368.89 + assertEquals(performers[i].isDefaultConnectionsEnabled(), performers2[i].isDefaultConnectionsEnabled());
368.90 + }
368.91 + }
368.92 +}
369.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
369.2 +++ b/test/javax/sound/midi/Gervill/SimpleInstrument/AddModelPerformerArrayIntIntIntInt.java Tue Feb 03 22:02:55 2009 -0800
369.3 @@ -0,0 +1,95 @@
369.4 +/*
369.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
369.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
369.7 + *
369.8 + * This code is free software; you can redistribute it and/or modify it
369.9 + * under the terms of the GNU General Public License version 2 only, as
369.10 + * published by the Free Software Foundation. Sun designates this
369.11 + * particular file as subject to the "Classpath" exception as provided
369.12 + * by Sun in the LICENSE file that accompanied this code.
369.13 + *
369.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
369.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
369.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
369.17 + * version 2 for more details (a copy is included in the LICENSE file that
369.18 + * accompanied this code).
369.19 + *
369.20 + * You should have received a copy of the GNU General Public License version
369.21 + * 2 along with this work; if not, write to the Free Software Foundation,
369.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
369.23 + *
369.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
369.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
369.26 + * have any questions.
369.27 + */
369.28 +
369.29 +/* @test
369.30 + @summary Test SimpleInstrument add(ModelPerformer[],int,int,int,int) method */
369.31 +
369.32 +import javax.sound.sampled.*;
369.33 +
369.34 +import com.sun.media.sound.*;
369.35 +
369.36 +public class AddModelPerformerArrayIntIntIntInt {
369.37 +
369.38 + private static void assertEquals(Object a, Object b) throws Exception
369.39 + {
369.40 + if(!a.equals(b))
369.41 + throw new RuntimeException("assertEquals fails!");
369.42 + }
369.43 +
369.44 + public static void main(String[] args) throws Exception {
369.45 +
369.46 + SimpleInstrument instrument = new SimpleInstrument();
369.47 +
369.48 + ModelPerformer[] performers = new ModelPerformer[2];
369.49 +
369.50 + performers[0] = new ModelPerformer();
369.51 + performers[0].setExclusiveClass(1);
369.52 + performers[0].setKeyFrom(36);
369.53 + performers[0].setKeyTo(48);
369.54 + performers[0].setVelFrom(16);
369.55 + performers[0].setVelTo(80);
369.56 + performers[0].setSelfNonExclusive(true);
369.57 + performers[0].setDefaultConnectionsEnabled(false);
369.58 + performers[0].getConnectionBlocks().add(new ModelConnectionBlock());
369.59 + performers[0].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
369.60 +
369.61 + performers[1] = new ModelPerformer();
369.62 + performers[1].setExclusiveClass(0);
369.63 + performers[1].setKeyFrom(12);
369.64 + performers[1].setKeyTo(24);
369.65 + performers[1].setVelFrom(20);
369.66 + performers[1].setVelTo(90);
369.67 + performers[1].setSelfNonExclusive(false);
369.68 + performers[0].setDefaultConnectionsEnabled(true);
369.69 + performers[1].getConnectionBlocks().add(new ModelConnectionBlock());
369.70 + performers[1].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
369.71 +
369.72 + instrument.add(performers,18,40,20,75);
369.73 + ModelPerformer[] performers2 = instrument.getPerformers();
369.74 + for (int i = 0; i < performers2.length; i++) {
369.75 + assertEquals(performers[i].getConnectionBlocks(), performers2[i].getConnectionBlocks());
369.76 + assertEquals(performers[i].getExclusiveClass(), performers2[i].getExclusiveClass());
369.77 + if(performers[i].getKeyFrom() < 18)
369.78 + assertEquals(18, performers2[i].getKeyFrom());
369.79 + else
369.80 + assertEquals(performers[i].getKeyFrom(), performers2[i].getKeyFrom());
369.81 + if(performers[i].getKeyTo() > 40)
369.82 + assertEquals(40, performers2[i].getKeyTo());
369.83 + else
369.84 + assertEquals(performers[i].getKeyTo(), performers2[i].getKeyTo());
369.85 + if(performers[i].getVelFrom() < 20)
369.86 + assertEquals(20, performers2[i].getVelFrom());
369.87 + else
369.88 + assertEquals(performers[i].getVelFrom(), performers2[i].getVelFrom());
369.89 + if(performers[i].getVelTo() > 75)
369.90 + assertEquals(75, performers2[i].getVelTo());
369.91 + else
369.92 + assertEquals(performers[i].getVelTo(), performers2[i].getVelTo());
369.93 + assertEquals(performers[i].getOscillators(), performers2[i].getOscillators());
369.94 + assertEquals(performers[i].isSelfNonExclusive(), performers2[i].isSelfNonExclusive());
369.95 + assertEquals(performers[i].isDefaultConnectionsEnabled(), performers2[i].isDefaultConnectionsEnabled());
369.96 + }
369.97 + }
369.98 +}
370.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
370.2 +++ b/test/javax/sound/midi/Gervill/SimpleInstrument/AddModelPerformerArrayIntIntIntIntInt.java Tue Feb 03 22:02:55 2009 -0800
370.3 @@ -0,0 +1,95 @@
370.4 +/*
370.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
370.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
370.7 + *
370.8 + * This code is free software; you can redistribute it and/or modify it
370.9 + * under the terms of the GNU General Public License version 2 only, as
370.10 + * published by the Free Software Foundation. Sun designates this
370.11 + * particular file as subject to the "Classpath" exception as provided
370.12 + * by Sun in the LICENSE file that accompanied this code.
370.13 + *
370.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
370.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
370.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
370.17 + * version 2 for more details (a copy is included in the LICENSE file that
370.18 + * accompanied this code).
370.19 + *
370.20 + * You should have received a copy of the GNU General Public License version
370.21 + * 2 along with this work; if not, write to the Free Software Foundation,
370.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
370.23 + *
370.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
370.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
370.26 + * have any questions.
370.27 + */
370.28 +
370.29 +/* @test
370.30 + @summary Test SimpleInstrument add(ModelPerformer[],int,int,int,int,int) method */
370.31 +
370.32 +import javax.sound.sampled.*;
370.33 +
370.34 +import com.sun.media.sound.*;
370.35 +
370.36 +public class AddModelPerformerArrayIntIntIntIntInt {
370.37 +
370.38 + private static void assertEquals(Object a, Object b) throws Exception
370.39 + {
370.40 + if(!a.equals(b))
370.41 + throw new RuntimeException("assertEquals fails!");
370.42 + }
370.43 +
370.44 + public static void main(String[] args) throws Exception {
370.45 +
370.46 + SimpleInstrument instrument = new SimpleInstrument();
370.47 +
370.48 + ModelPerformer[] performers = new ModelPerformer[2];
370.49 +
370.50 + performers[0] = new ModelPerformer();
370.51 + performers[0].setExclusiveClass(1);
370.52 + performers[0].setKeyFrom(36);
370.53 + performers[0].setKeyTo(48);
370.54 + performers[0].setVelFrom(16);
370.55 + performers[0].setVelTo(80);
370.56 + performers[0].setSelfNonExclusive(true);
370.57 + performers[0].setDefaultConnectionsEnabled(false);
370.58 + performers[0].getConnectionBlocks().add(new ModelConnectionBlock());
370.59 + performers[0].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
370.60 +
370.61 + performers[1] = new ModelPerformer();
370.62 + performers[1].setExclusiveClass(0);
370.63 + performers[1].setKeyFrom(12);
370.64 + performers[1].setKeyTo(24);
370.65 + performers[1].setVelFrom(20);
370.66 + performers[1].setVelTo(90);
370.67 + performers[1].setSelfNonExclusive(false);
370.68 + performers[0].setDefaultConnectionsEnabled(true);
370.69 + performers[1].getConnectionBlocks().add(new ModelConnectionBlock());
370.70 + performers[1].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
370.71 +
370.72 + instrument.add(performers,18,40,20,75,12);
370.73 + ModelPerformer[] performers2 = instrument.getPerformers();
370.74 + for (int i = 0; i < performers2.length; i++) {
370.75 + assertEquals(performers[i].getConnectionBlocks(), performers2[i].getConnectionBlocks());
370.76 + assertEquals(12, performers2[i].getExclusiveClass());
370.77 + if(performers[i].getKeyFrom() < 18)
370.78 + assertEquals(18, performers2[i].getKeyFrom());
370.79 + else
370.80 + assertEquals(performers[i].getKeyFrom(), performers2[i].getKeyFrom());
370.81 + if(performers[i].getKeyTo() > 40)
370.82 + assertEquals(40, performers2[i].getKeyTo());
370.83 + else
370.84 + assertEquals(performers[i].getKeyTo(), performers2[i].getKeyTo());
370.85 + if(performers[i].getVelFrom() < 20)
370.86 + assertEquals(20, performers2[i].getVelFrom());
370.87 + else
370.88 + assertEquals(performers[i].getVelFrom(), performers2[i].getVelFrom());
370.89 + if(performers[i].getVelTo() > 75)
370.90 + assertEquals(75, performers2[i].getVelTo());
370.91 + else
370.92 + assertEquals(performers[i].getVelTo(), performers2[i].getVelTo());
370.93 + assertEquals(performers[i].getOscillators(), performers2[i].getOscillators());
370.94 + assertEquals(performers[i].isSelfNonExclusive(), performers2[i].isSelfNonExclusive());
370.95 + assertEquals(performers[i].isDefaultConnectionsEnabled(), performers2[i].isDefaultConnectionsEnabled());
370.96 + }
370.97 + }
370.98 +}
371.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
371.2 +++ b/test/javax/sound/midi/Gervill/SimpleInstrument/AddModelPerformerIntInt.java Tue Feb 03 22:02:55 2009 -0800
371.3 @@ -0,0 +1,89 @@
371.4 +/*
371.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
371.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
371.7 + *
371.8 + * This code is free software; you can redistribute it and/or modify it
371.9 + * under the terms of the GNU General Public License version 2 only, as
371.10 + * published by the Free Software Foundation. Sun designates this
371.11 + * particular file as subject to the "Classpath" exception as provided
371.12 + * by Sun in the LICENSE file that accompanied this code.
371.13 + *
371.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
371.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
371.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
371.17 + * version 2 for more details (a copy is included in the LICENSE file that
371.18 + * accompanied this code).
371.19 + *
371.20 + * You should have received a copy of the GNU General Public License version
371.21 + * 2 along with this work; if not, write to the Free Software Foundation,
371.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
371.23 + *
371.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
371.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
371.26 + * have any questions.
371.27 + */
371.28 +
371.29 +/* @test
371.30 + @summary Test SimpleInstrument add(ModelPerformer,int,int) method */
371.31 +
371.32 +import javax.sound.sampled.*;
371.33 +
371.34 +import com.sun.media.sound.*;
371.35 +
371.36 +public class AddModelPerformerIntInt {
371.37 +
371.38 + private static void assertEquals(Object a, Object b) throws Exception
371.39 + {
371.40 + if(!a.equals(b))
371.41 + throw new RuntimeException("assertEquals fails!");
371.42 + }
371.43 +
371.44 + public static void main(String[] args) throws Exception {
371.45 +
371.46 + SimpleInstrument instrument = new SimpleInstrument();
371.47 +
371.48 + ModelPerformer[] performers = new ModelPerformer[2];
371.49 +
371.50 + performers[0] = new ModelPerformer();
371.51 + performers[0].setExclusiveClass(1);
371.52 + performers[0].setKeyFrom(36);
371.53 + performers[0].setKeyTo(48);
371.54 + performers[0].setVelFrom(16);
371.55 + performers[0].setVelTo(80);
371.56 + performers[0].setSelfNonExclusive(true);
371.57 + performers[0].setDefaultConnectionsEnabled(false);
371.58 + performers[0].getConnectionBlocks().add(new ModelConnectionBlock());
371.59 + performers[0].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
371.60 +
371.61 + performers[1] = new ModelPerformer();
371.62 + performers[1].setExclusiveClass(0);
371.63 + performers[1].setKeyFrom(12);
371.64 + performers[1].setKeyTo(24);
371.65 + performers[1].setVelFrom(20);
371.66 + performers[1].setVelTo(90);
371.67 + performers[1].setSelfNonExclusive(false);
371.68 + performers[0].setDefaultConnectionsEnabled(true);
371.69 + performers[1].getConnectionBlocks().add(new ModelConnectionBlock());
371.70 + performers[1].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
371.71 +
371.72 + instrument.add(performers[0],18,40);
371.73 + ModelPerformer[] performers2 = instrument.getPerformers();
371.74 + for (int i = 0; i < performers2.length; i++) {
371.75 + assertEquals(performers[i].getConnectionBlocks(), performers2[i].getConnectionBlocks());
371.76 + assertEquals(performers[i].getExclusiveClass(), performers2[i].getExclusiveClass());
371.77 + if(performers[i].getKeyFrom() < 18)
371.78 + assertEquals(18, performers2[i].getKeyFrom());
371.79 + else
371.80 + assertEquals(performers[i].getKeyFrom(), performers2[i].getKeyFrom());
371.81 + if(performers[i].getKeyTo() > 40)
371.82 + assertEquals(40, performers2[i].getKeyTo());
371.83 + else
371.84 + assertEquals(performers[i].getKeyTo(), performers2[i].getKeyTo());
371.85 + assertEquals(performers[i].getVelFrom(), performers2[i].getVelFrom());
371.86 + assertEquals(performers[i].getVelTo(), performers2[i].getVelTo());
371.87 + assertEquals(performers[i].getOscillators(), performers2[i].getOscillators());
371.88 + assertEquals(performers[i].isSelfNonExclusive(), performers2[i].isSelfNonExclusive());
371.89 + assertEquals(performers[i].isDefaultConnectionsEnabled(), performers2[i].isDefaultConnectionsEnabled());
371.90 + }
371.91 + }
371.92 +}
372.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
372.2 +++ b/test/javax/sound/midi/Gervill/SimpleInstrument/AddModelPerformerIntIntIntInt.java Tue Feb 03 22:02:55 2009 -0800
372.3 @@ -0,0 +1,95 @@
372.4 +/*
372.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
372.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
372.7 + *
372.8 + * This code is free software; you can redistribute it and/or modify it
372.9 + * under the terms of the GNU General Public License version 2 only, as
372.10 + * published by the Free Software Foundation. Sun designates this
372.11 + * particular file as subject to the "Classpath" exception as provided
372.12 + * by Sun in the LICENSE file that accompanied this code.
372.13 + *
372.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
372.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
372.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
372.17 + * version 2 for more details (a copy is included in the LICENSE file that
372.18 + * accompanied this code).
372.19 + *
372.20 + * You should have received a copy of the GNU General Public License version
372.21 + * 2 along with this work; if not, write to the Free Software Foundation,
372.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
372.23 + *
372.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
372.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
372.26 + * have any questions.
372.27 + */
372.28 +
372.29 +/* @test
372.30 + @summary Test SimpleInstrument add(ModelPerformer,int,int,int,int) method */
372.31 +
372.32 +import javax.sound.sampled.*;
372.33 +
372.34 +import com.sun.media.sound.*;
372.35 +
372.36 +public class AddModelPerformerIntIntIntInt {
372.37 +
372.38 + private static void assertEquals(Object a, Object b) throws Exception
372.39 + {
372.40 + if(!a.equals(b))
372.41 + throw new RuntimeException("assertEquals fails!");
372.42 + }
372.43 +
372.44 + public static void main(String[] args) throws Exception {
372.45 +
372.46 + SimpleInstrument instrument = new SimpleInstrument();
372.47 +
372.48 + ModelPerformer[] performers = new ModelPerformer[2];
372.49 +
372.50 + performers[0] = new ModelPerformer();
372.51 + performers[0].setExclusiveClass(1);
372.52 + performers[0].setKeyFrom(36);
372.53 + performers[0].setKeyTo(48);
372.54 + performers[0].setVelFrom(16);
372.55 + performers[0].setVelTo(80);
372.56 + performers[0].setSelfNonExclusive(true);
372.57 + performers[0].setDefaultConnectionsEnabled(false);
372.58 + performers[0].getConnectionBlocks().add(new ModelConnectionBlock());
372.59 + performers[0].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
372.60 +
372.61 + performers[1] = new ModelPerformer();
372.62 + performers[1].setExclusiveClass(0);
372.63 + performers[1].setKeyFrom(12);
372.64 + performers[1].setKeyTo(24);
372.65 + performers[1].setVelFrom(20);
372.66 + performers[1].setVelTo(90);
372.67 + performers[1].setSelfNonExclusive(false);
372.68 + performers[0].setDefaultConnectionsEnabled(true);
372.69 + performers[1].getConnectionBlocks().add(new ModelConnectionBlock());
372.70 + performers[1].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
372.71 +
372.72 + instrument.add(performers[0],18,40,20,75);
372.73 + ModelPerformer[] performers2 = instrument.getPerformers();
372.74 + for (int i = 0; i < performers2.length; i++) {
372.75 + assertEquals(performers[i].getConnectionBlocks(), performers2[i].getConnectionBlocks());
372.76 + assertEquals(performers[i].getExclusiveClass(), performers2[i].getExclusiveClass());
372.77 + if(performers[i].getKeyFrom() < 18)
372.78 + assertEquals(18, performers2[i].getKeyFrom());
372.79 + else
372.80 + assertEquals(performers[i].getKeyFrom(), performers2[i].getKeyFrom());
372.81 + if(performers[i].getKeyTo() > 40)
372.82 + assertEquals(40, performers2[i].getKeyTo());
372.83 + else
372.84 + assertEquals(performers[i].getKeyTo(), performers2[i].getKeyTo());
372.85 + if(performers[i].getVelFrom() < 20)
372.86 + assertEquals(20, performers2[i].getVelFrom());
372.87 + else
372.88 + assertEquals(performers[i].getVelFrom(), performers2[i].getVelFrom());
372.89 + if(performers[i].getVelTo() > 75)
372.90 + assertEquals(75, performers2[i].getVelTo());
372.91 + else
372.92 + assertEquals(performers[i].getVelTo(), performers2[i].getVelTo());
372.93 + assertEquals(performers[i].getOscillators(), performers2[i].getOscillators());
372.94 + assertEquals(performers[i].isSelfNonExclusive(), performers2[i].isSelfNonExclusive());
372.95 + assertEquals(performers[i].isDefaultConnectionsEnabled(), performers2[i].isDefaultConnectionsEnabled());
372.96 + }
372.97 + }
372.98 +}
373.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
373.2 +++ b/test/javax/sound/midi/Gervill/SimpleInstrument/AddModelPerformerIntIntIntIntInt.java Tue Feb 03 22:02:55 2009 -0800
373.3 @@ -0,0 +1,95 @@
373.4 +/*
373.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
373.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
373.7 + *
373.8 + * This code is free software; you can redistribute it and/or modify it
373.9 + * under the terms of the GNU General Public License version 2 only, as
373.10 + * published by the Free Software Foundation. Sun designates this
373.11 + * particular file as subject to the "Classpath" exception as provided
373.12 + * by Sun in the LICENSE file that accompanied this code.
373.13 + *
373.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
373.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
373.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
373.17 + * version 2 for more details (a copy is included in the LICENSE file that
373.18 + * accompanied this code).
373.19 + *
373.20 + * You should have received a copy of the GNU General Public License version
373.21 + * 2 along with this work; if not, write to the Free Software Foundation,
373.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
373.23 + *
373.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
373.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
373.26 + * have any questions.
373.27 + */
373.28 +
373.29 +/* @test
373.30 + @summary Test SimpleInstrument add(ModelPerformer,int,int,int,int,int) method */
373.31 +
373.32 +import javax.sound.sampled.*;
373.33 +
373.34 +import com.sun.media.sound.*;
373.35 +
373.36 +public class AddModelPerformerIntIntIntIntInt {
373.37 +
373.38 + private static void assertEquals(Object a, Object b) throws Exception
373.39 + {
373.40 + if(!a.equals(b))
373.41 + throw new RuntimeException("assertEquals fails!");
373.42 + }
373.43 +
373.44 + public static void main(String[] args) throws Exception {
373.45 +
373.46 + SimpleInstrument instrument = new SimpleInstrument();
373.47 +
373.48 + ModelPerformer[] performers = new ModelPerformer[2];
373.49 +
373.50 + performers[0] = new ModelPerformer();
373.51 + performers[0].setExclusiveClass(1);
373.52 + performers[0].setKeyFrom(36);
373.53 + performers[0].setKeyTo(48);
373.54 + performers[0].setVelFrom(16);
373.55 + performers[0].setVelTo(80);
373.56 + performers[0].setSelfNonExclusive(true);
373.57 + performers[0].setDefaultConnectionsEnabled(false);
373.58 + performers[0].getConnectionBlocks().add(new ModelConnectionBlock());
373.59 + performers[0].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
373.60 +
373.61 + performers[1] = new ModelPerformer();
373.62 + performers[1].setExclusiveClass(0);
373.63 + performers[1].setKeyFrom(12);
373.64 + performers[1].setKeyTo(24);
373.65 + performers[1].setVelFrom(20);
373.66 + performers[1].setVelTo(90);
373.67 + performers[1].setSelfNonExclusive(false);
373.68 + performers[0].setDefaultConnectionsEnabled(true);
373.69 + performers[1].getConnectionBlocks().add(new ModelConnectionBlock());
373.70 + performers[1].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
373.71 +
373.72 + instrument.add(performers[0],18,40,20,75,12);
373.73 + ModelPerformer[] performers2 = instrument.getPerformers();
373.74 + for (int i = 0; i < performers2.length; i++) {
373.75 + assertEquals(performers[i].getConnectionBlocks(), performers2[i].getConnectionBlocks());
373.76 + assertEquals(12, performers2[i].getExclusiveClass());
373.77 + if(performers[i].getKeyFrom() < 18)
373.78 + assertEquals(18, performers2[i].getKeyFrom());
373.79 + else
373.80 + assertEquals(performers[i].getKeyFrom(), performers2[i].getKeyFrom());
373.81 + if(performers[i].getKeyTo() > 40)
373.82 + assertEquals(40, performers2[i].getKeyTo());
373.83 + else
373.84 + assertEquals(performers[i].getKeyTo(), performers2[i].getKeyTo());
373.85 + if(performers[i].getVelFrom() < 20)
373.86 + assertEquals(20, performers2[i].getVelFrom());
373.87 + else
373.88 + assertEquals(performers[i].getVelFrom(), performers2[i].getVelFrom());
373.89 + if(performers[i].getVelTo() > 75)
373.90 + assertEquals(75, performers2[i].getVelTo());
373.91 + else
373.92 + assertEquals(performers[i].getVelTo(), performers2[i].getVelTo());
373.93 + assertEquals(performers[i].getOscillators(), performers2[i].getOscillators());
373.94 + assertEquals(performers[i].isSelfNonExclusive(), performers2[i].isSelfNonExclusive());
373.95 + assertEquals(performers[i].isDefaultConnectionsEnabled(), performers2[i].isDefaultConnectionsEnabled());
373.96 + }
373.97 + }
373.98 +}
374.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
374.2 +++ b/test/javax/sound/midi/Gervill/SimpleInstrument/Clear.java Tue Feb 03 22:02:55 2009 -0800
374.3 @@ -0,0 +1,73 @@
374.4 +/*
374.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
374.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
374.7 + *
374.8 + * This code is free software; you can redistribute it and/or modify it
374.9 + * under the terms of the GNU General Public License version 2 only, as
374.10 + * published by the Free Software Foundation. Sun designates this
374.11 + * particular file as subject to the "Classpath" exception as provided
374.12 + * by Sun in the LICENSE file that accompanied this code.
374.13 + *
374.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
374.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
374.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
374.17 + * version 2 for more details (a copy is included in the LICENSE file that
374.18 + * accompanied this code).
374.19 + *
374.20 + * You should have received a copy of the GNU General Public License version
374.21 + * 2 along with this work; if not, write to the Free Software Foundation,
374.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
374.23 + *
374.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
374.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
374.26 + * have any questions.
374.27 + */
374.28 +
374.29 +/* @test
374.30 + @summary Test SimpleInstrument clear method */
374.31 +
374.32 +import javax.sound.sampled.*;
374.33 +
374.34 +import com.sun.media.sound.*;
374.35 +
374.36 +public class Clear {
374.37 +
374.38 + private static void assertEquals(Object a, Object b) throws Exception
374.39 + {
374.40 + if(!a.equals(b))
374.41 + throw new RuntimeException("assertEquals fails!");
374.42 + }
374.43 +
374.44 + public static void main(String[] args) throws Exception {
374.45 +
374.46 + SimpleInstrument instrument = new SimpleInstrument();
374.47 +
374.48 + ModelPerformer[] performers = new ModelPerformer[2];
374.49 +
374.50 + performers[0] = new ModelPerformer();
374.51 + performers[0].setExclusiveClass(1);
374.52 + performers[0].setKeyFrom(36);
374.53 + performers[0].setKeyTo(48);
374.54 + performers[0].setVelFrom(16);
374.55 + performers[0].setVelTo(80);
374.56 + performers[0].setSelfNonExclusive(true);
374.57 + performers[0].setDefaultConnectionsEnabled(false);
374.58 + performers[0].getConnectionBlocks().add(new ModelConnectionBlock());
374.59 + performers[0].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
374.60 +
374.61 + performers[1] = new ModelPerformer();
374.62 + performers[1].setExclusiveClass(0);
374.63 + performers[1].setKeyFrom(12);
374.64 + performers[1].setKeyTo(24);
374.65 + performers[1].setVelFrom(20);
374.66 + performers[1].setVelTo(90);
374.67 + performers[1].setSelfNonExclusive(false);
374.68 + performers[0].setDefaultConnectionsEnabled(true);
374.69 + performers[1].getConnectionBlocks().add(new ModelConnectionBlock());
374.70 + performers[1].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
374.71 +
374.72 + instrument.add(performers[0]);
374.73 + instrument.clear();
374.74 + assertEquals(instrument.getPerformers().length, 0);
374.75 + }
374.76 +}
375.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
375.2 +++ b/test/javax/sound/midi/Gervill/SimpleInstrument/SetName.java Tue Feb 03 22:02:55 2009 -0800
375.3 @@ -0,0 +1,72 @@
375.4 +/*
375.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
375.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
375.7 + *
375.8 + * This code is free software; you can redistribute it and/or modify it
375.9 + * under the terms of the GNU General Public License version 2 only, as
375.10 + * published by the Free Software Foundation. Sun designates this
375.11 + * particular file as subject to the "Classpath" exception as provided
375.12 + * by Sun in the LICENSE file that accompanied this code.
375.13 + *
375.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
375.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
375.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
375.17 + * version 2 for more details (a copy is included in the LICENSE file that
375.18 + * accompanied this code).
375.19 + *
375.20 + * You should have received a copy of the GNU General Public License version
375.21 + * 2 along with this work; if not, write to the Free Software Foundation,
375.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
375.23 + *
375.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
375.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
375.26 + * have any questions.
375.27 + */
375.28 +
375.29 +/* @test
375.30 + @summary Test SimpleInstrument setName(String) method */
375.31 +
375.32 +import javax.sound.sampled.*;
375.33 +
375.34 +import com.sun.media.sound.*;
375.35 +
375.36 +public class SetName {
375.37 +
375.38 + private static void assertEquals(Object a, Object b) throws Exception
375.39 + {
375.40 + if(!a.equals(b))
375.41 + throw new RuntimeException("assertEquals fails!");
375.42 + }
375.43 +
375.44 + public static void main(String[] args) throws Exception {
375.45 +
375.46 + SimpleInstrument instrument = new SimpleInstrument();
375.47 +
375.48 + ModelPerformer[] performers = new ModelPerformer[2];
375.49 +
375.50 + performers[0] = new ModelPerformer();
375.51 + performers[0].setExclusiveClass(1);
375.52 + performers[0].setKeyFrom(36);
375.53 + performers[0].setKeyTo(48);
375.54 + performers[0].setVelFrom(16);
375.55 + performers[0].setVelTo(80);
375.56 + performers[0].setSelfNonExclusive(true);
375.57 + performers[0].setDefaultConnectionsEnabled(false);
375.58 + performers[0].getConnectionBlocks().add(new ModelConnectionBlock());
375.59 + performers[0].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
375.60 +
375.61 + performers[1] = new ModelPerformer();
375.62 + performers[1].setExclusiveClass(0);
375.63 + performers[1].setKeyFrom(12);
375.64 + performers[1].setKeyTo(24);
375.65 + performers[1].setVelFrom(20);
375.66 + performers[1].setVelTo(90);
375.67 + performers[1].setSelfNonExclusive(false);
375.68 + performers[0].setDefaultConnectionsEnabled(true);
375.69 + performers[1].getConnectionBlocks().add(new ModelConnectionBlock());
375.70 + performers[1].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
375.71 +
375.72 + instrument.setName("hello");
375.73 + assertEquals(instrument.getName(), "hello");
375.74 + }
375.75 +}
376.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
376.2 +++ b/test/javax/sound/midi/Gervill/SimpleInstrument/SetPatch.java Tue Feb 03 22:02:55 2009 -0800
376.3 @@ -0,0 +1,75 @@
376.4 +/*
376.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
376.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
376.7 + *
376.8 + * This code is free software; you can redistribute it and/or modify it
376.9 + * under the terms of the GNU General Public License version 2 only, as
376.10 + * published by the Free Software Foundation. Sun designates this
376.11 + * particular file as subject to the "Classpath" exception as provided
376.12 + * by Sun in the LICENSE file that accompanied this code.
376.13 + *
376.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
376.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376.17 + * version 2 for more details (a copy is included in the LICENSE file that
376.18 + * accompanied this code).
376.19 + *
376.20 + * You should have received a copy of the GNU General Public License version
376.21 + * 2 along with this work; if not, write to the Free Software Foundation,
376.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
376.23 + *
376.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
376.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
376.26 + * have any questions.
376.27 + */
376.28 +
376.29 +/* @test
376.30 + @summary Test SimpleInstrument setPatch(Patch) method */
376.31 +
376.32 +import javax.sound.midi.Patch;
376.33 +import javax.sound.sampled.*;
376.34 +
376.35 +import com.sun.media.sound.*;
376.36 +
376.37 +public class SetPatch {
376.38 +
376.39 + private static void assertEquals(Object a, Object b) throws Exception
376.40 + {
376.41 + if(!a.equals(b))
376.42 + throw new RuntimeException("assertEquals fails!");
376.43 + }
376.44 +
376.45 + public static void main(String[] args) throws Exception {
376.46 +
376.47 + SimpleInstrument instrument = new SimpleInstrument();
376.48 +
376.49 + ModelPerformer[] performers = new ModelPerformer[2];
376.50 +
376.51 + performers[0] = new ModelPerformer();
376.52 + performers[0].setExclusiveClass(1);
376.53 + performers[0].setKeyFrom(36);
376.54 + performers[0].setKeyTo(48);
376.55 + performers[0].setVelFrom(16);
376.56 + performers[0].setVelTo(80);
376.57 + performers[0].setSelfNonExclusive(true);
376.58 + performers[0].setDefaultConnectionsEnabled(false);
376.59 + performers[0].getConnectionBlocks().add(new ModelConnectionBlock());
376.60 + performers[0].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
376.61 +
376.62 + performers[1] = new ModelPerformer();
376.63 + performers[1].setExclusiveClass(0);
376.64 + performers[1].setKeyFrom(12);
376.65 + performers[1].setKeyTo(24);
376.66 + performers[1].setVelFrom(20);
376.67 + performers[1].setVelTo(90);
376.68 + performers[1].setSelfNonExclusive(false);
376.69 + performers[0].setDefaultConnectionsEnabled(true);
376.70 + performers[1].getConnectionBlocks().add(new ModelConnectionBlock());
376.71 + performers[1].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));
376.72 +
376.73 + Patch patch = new Patch(0,36);
376.74 + instrument.setPatch(patch);
376.75 + assertEquals(instrument.getPatch().getProgram(), patch.getProgram());
376.76 + assertEquals(instrument.getPatch().getBank(), patch.getBank());
376.77 + }
376.78 +}
377.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
377.2 +++ b/test/javax/sound/midi/Gervill/SimpleSoundbank/AddInstrument.java Tue Feb 03 22:02:55 2009 -0800
377.3 @@ -0,0 +1,51 @@
377.4 +/*
377.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
377.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
377.7 + *
377.8 + * This code is free software; you can redistribute it and/or modify it
377.9 + * under the terms of the GNU General Public License version 2 only, as
377.10 + * published by the Free Software Foundation. Sun designates this
377.11 + * particular file as subject to the "Classpath" exception as provided
377.12 + * by Sun in the LICENSE file that accompanied this code.
377.13 + *
377.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
377.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
377.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
377.17 + * version 2 for more details (a copy is included in the LICENSE file that
377.18 + * accompanied this code).
377.19 + *
377.20 + * You should have received a copy of the GNU General Public License version
377.21 + * 2 along with this work; if not, write to the Free Software Foundation,
377.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
377.23 + *
377.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
377.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
377.26 + * have any questions.
377.27 + */
377.28 +
377.29 +/* @test
377.30 + @summary Test SimpleSoundbank addInstrument method */
377.31 +
377.32 +import javax.sound.midi.Patch;
377.33 +import javax.sound.sampled.*;
377.34 +
377.35 +import com.sun.media.sound.*;
377.36 +
377.37 +public class AddInstrument {
377.38 +
377.39 + private static void assertEquals(Object a, Object b) throws Exception
377.40 + {
377.41 + if(!a.equals(b))
377.42 + throw new RuntimeException("assertEquals fails!");
377.43 + }
377.44 +
377.45 + public static void main(String[] args) throws Exception {
377.46 + SimpleSoundbank soundbank = new SimpleSoundbank();
377.47 + SimpleInstrument ins = new SimpleInstrument();
377.48 + ins.setPatch(new Patch(3,7));
377.49 + soundbank.addInstrument(ins);
377.50 + assertEquals(soundbank.getInstruments().length, 1);
377.51 + assertEquals(soundbank.getInstruments()[0], ins);
377.52 +
377.53 + }
377.54 +}
378.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
378.2 +++ b/test/javax/sound/midi/Gervill/SimpleSoundbank/AddResource.java Tue Feb 03 22:02:55 2009 -0800
378.3 @@ -0,0 +1,52 @@
378.4 +/*
378.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
378.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
378.7 + *
378.8 + * This code is free software; you can redistribute it and/or modify it
378.9 + * under the terms of the GNU General Public License version 2 only, as
378.10 + * published by the Free Software Foundation. Sun designates this
378.11 + * particular file as subject to the "Classpath" exception as provided
378.12 + * by Sun in the LICENSE file that accompanied this code.
378.13 + *
378.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
378.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
378.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
378.17 + * version 2 for more details (a copy is included in the LICENSE file that
378.18 + * accompanied this code).
378.19 + *
378.20 + * You should have received a copy of the GNU General Public License version
378.21 + * 2 along with this work; if not, write to the Free Software Foundation,
378.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
378.23 + *
378.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
378.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
378.26 + * have any questions.
378.27 + */
378.28 +
378.29 +/* @test
378.30 + @summary Test SimpleSoundbank addResource method */
378.31 +
378.32 +import javax.sound.midi.SoundbankResource;
378.33 +import javax.sound.sampled.*;
378.34 +
378.35 +import com.sun.media.sound.*;
378.36 +
378.37 +public class AddResource {
378.38 +
378.39 + private static void assertEquals(Object a, Object b) throws Exception
378.40 + {
378.41 + if(!a.equals(b))
378.42 + throw new RuntimeException("assertEquals fails!");
378.43 + }
378.44 +
378.45 + public static void main(String[] args) throws Exception {
378.46 + SimpleSoundbank soundbank = new SimpleSoundbank();
378.47 + SoundbankResource res = new SoundbankResource(soundbank, "test", null) {
378.48 + public Object getData() {
378.49 + return null;
378.50 + }};
378.51 + soundbank.addResource(res);
378.52 + assertEquals(soundbank.getResources().length, 1);
378.53 + assertEquals(soundbank.getResources()[0], res);
378.54 + }
378.55 +}
379.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
379.2 +++ b/test/javax/sound/midi/Gervill/SimpleSoundbank/GetInstrument.java Tue Feb 03 22:02:55 2009 -0800
379.3 @@ -0,0 +1,50 @@
379.4 +/*
379.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
379.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
379.7 + *
379.8 + * This code is free software; you can redistribute it and/or modify it
379.9 + * under the terms of the GNU General Public License version 2 only, as
379.10 + * published by the Free Software Foundation. Sun designates this
379.11 + * particular file as subject to the "Classpath" exception as provided
379.12 + * by Sun in the LICENSE file that accompanied this code.
379.13 + *
379.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
379.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
379.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
379.17 + * version 2 for more details (a copy is included in the LICENSE file that
379.18 + * accompanied this code).
379.19 + *
379.20 + * You should have received a copy of the GNU General Public License version
379.21 + * 2 along with this work; if not, write to the Free Software Foundation,
379.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
379.23 + *
379.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
379.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
379.26 + * have any questions.
379.27 + */
379.28 +
379.29 +/* @test
379.30 + @summary Test SimpleSoundbank getInstrument method */
379.31 +
379.32 +import javax.sound.midi.Patch;
379.33 +import javax.sound.sampled.*;
379.34 +
379.35 +import com.sun.media.sound.*;
379.36 +
379.37 +public class GetInstrument {
379.38 +
379.39 + private static void assertEquals(Object a, Object b) throws Exception
379.40 + {
379.41 + if(!a.equals(b))
379.42 + throw new RuntimeException("assertEquals fails!");
379.43 + }
379.44 +
379.45 + public static void main(String[] args) throws Exception {
379.46 + SimpleSoundbank soundbank = new SimpleSoundbank();
379.47 + SimpleInstrument ins = new SimpleInstrument();
379.48 + ins.setPatch(new Patch(3,7));
379.49 + soundbank.addInstrument(ins);
379.50 + assertEquals(soundbank.getInstrument(new Patch(3,7)), ins);
379.51 +
379.52 + }
379.53 +}
380.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
380.2 +++ b/test/javax/sound/midi/Gervill/SimpleSoundbank/RemoveInstrument.java Tue Feb 03 22:02:55 2009 -0800
380.3 @@ -0,0 +1,58 @@
380.4 +/*
380.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
380.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
380.7 + *
380.8 + * This code is free software; you can redistribute it and/or modify it
380.9 + * under the terms of the GNU General Public License version 2 only, as
380.10 + * published by the Free Software Foundation. Sun designates this
380.11 + * particular file as subject to the "Classpath" exception as provided
380.12 + * by Sun in the LICENSE file that accompanied this code.
380.13 + *
380.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
380.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
380.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
380.17 + * version 2 for more details (a copy is included in the LICENSE file that
380.18 + * accompanied this code).
380.19 + *
380.20 + * You should have received a copy of the GNU General Public License version
380.21 + * 2 along with this work; if not, write to the Free Software Foundation,
380.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
380.23 + *
380.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
380.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
380.26 + * have any questions.
380.27 + */
380.28 +
380.29 +/* @test
380.30 + @summary Test SimpleSoundbank removeInstrument method */
380.31 +
380.32 +import javax.sound.midi.Patch;
380.33 +import javax.sound.sampled.*;
380.34 +
380.35 +import com.sun.media.sound.*;
380.36 +
380.37 +public class RemoveInstrument {
380.38 +
380.39 + private static void assertEquals(Object a, Object b) throws Exception
380.40 + {
380.41 + if(!a.equals(b))
380.42 + throw new RuntimeException("assertEquals fails!");
380.43 + }
380.44 +
380.45 + private static void assertTrue(boolean a) throws Exception
380.46 + {
380.47 + if(!a)
380.48 + throw new RuntimeException("assertEquals fails!");
380.49 + }
380.50 +
380.51 + public static void main(String[] args) throws Exception {
380.52 + SimpleSoundbank soundbank = new SimpleSoundbank();
380.53 + SimpleInstrument ins = new SimpleInstrument();
380.54 + ins.setPatch(new Patch(3,7));
380.55 + soundbank.addInstrument(ins);
380.56 + soundbank.removeInstrument(ins);
380.57 + assertEquals(soundbank.getInstruments().length, 0);
380.58 + assertTrue(soundbank.getInstrument(new Patch(3,7)) == null);
380.59 +
380.60 + }
380.61 +}
381.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
381.2 +++ b/test/javax/sound/midi/Gervill/SimpleSoundbank/SetDescription.java Tue Feb 03 22:02:55 2009 -0800
381.3 @@ -0,0 +1,47 @@
381.4 +/*
381.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
381.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
381.7 + *
381.8 + * This code is free software; you can redistribute it and/or modify it
381.9 + * under the terms of the GNU General Public License version 2 only, as
381.10 + * published by the Free Software Foundation. Sun designates this
381.11 + * particular file as subject to the "Classpath" exception as provided
381.12 + * by Sun in the LICENSE file that accompanied this code.
381.13 + *
381.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
381.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
381.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
381.17 + * version 2 for more details (a copy is included in the LICENSE file that
381.18 + * accompanied this code).
381.19 + *
381.20 + * You should have received a copy of the GNU General Public License version
381.21 + * 2 along with this work; if not, write to the Free Software Foundation,
381.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
381.23 + *
381.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
381.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
381.26 + * have any questions.
381.27 + */
381.28 +
381.29 +/* @test
381.30 + @summary Test SimpleSoundbank setDescription method */
381.31 +
381.32 +import javax.sound.sampled.*;
381.33 +
381.34 +import com.sun.media.sound.*;
381.35 +
381.36 +public class SetDescription {
381.37 +
381.38 + private static void assertEquals(Object a, Object b) throws Exception
381.39 + {
381.40 + if(!a.equals(b))
381.41 + throw new RuntimeException("assertEquals fails!");
381.42 + }
381.43 +
381.44 + public static void main(String[] args) throws Exception {
381.45 + SimpleSoundbank soundbank = new SimpleSoundbank();
381.46 + soundbank.setDescription("hello");
381.47 + assertEquals(soundbank.getDescription(), "hello");
381.48 +
381.49 + }
381.50 +}
382.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
382.2 +++ b/test/javax/sound/midi/Gervill/SimpleSoundbank/SetName.java Tue Feb 03 22:02:55 2009 -0800
382.3 @@ -0,0 +1,47 @@
382.4 +/*
382.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
382.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
382.7 + *
382.8 + * This code is free software; you can redistribute it and/or modify it
382.9 + * under the terms of the GNU General Public License version 2 only, as
382.10 + * published by the Free Software Foundation. Sun designates this
382.11 + * particular file as subject to the "Classpath" exception as provided
382.12 + * by Sun in the LICENSE file that accompanied this code.
382.13 + *
382.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
382.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
382.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
382.17 + * version 2 for more details (a copy is included in the LICENSE file that
382.18 + * accompanied this code).
382.19 + *
382.20 + * You should have received a copy of the GNU General Public License version
382.21 + * 2 along with this work; if not, write to the Free Software Foundation,
382.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
382.23 + *
382.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
382.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
382.26 + * have any questions.
382.27 + */
382.28 +
382.29 +/* @test
382.30 + @summary Test SimpleSoundbank setName method */
382.31 +
382.32 +import javax.sound.sampled.*;
382.33 +
382.34 +import com.sun.media.sound.*;
382.35 +
382.36 +public class SetName {
382.37 +
382.38 + private static void assertEquals(Object a, Object b) throws Exception
382.39 + {
382.40 + if(!a.equals(b))
382.41 + throw new RuntimeException("assertEquals fails!");
382.42 + }
382.43 +
382.44 + public static void main(String[] args) throws Exception {
382.45 + SimpleSoundbank soundbank = new SimpleSoundbank();
382.46 + soundbank.setName("hello");
382.47 + assertEquals(soundbank.getName(), "hello");
382.48 +
382.49 + }
382.50 +}
383.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
383.2 +++ b/test/javax/sound/midi/Gervill/SimpleSoundbank/SetVendor.java Tue Feb 03 22:02:55 2009 -0800
383.3 @@ -0,0 +1,47 @@
383.4 +/*
383.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
383.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
383.7 + *
383.8 + * This code is free software; you can redistribute it and/or modify it
383.9 + * under the terms of the GNU General Public License version 2 only, as
383.10 + * published by the Free Software Foundation. Sun designates this
383.11 + * particular file as subject to the "Classpath" exception as provided
383.12 + * by Sun in the LICENSE file that accompanied this code.
383.13 + *
383.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
383.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
383.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
383.17 + * version 2 for more details (a copy is included in the LICENSE file that
383.18 + * accompanied this code).
383.19 + *
383.20 + * You should have received a copy of the GNU General Public License version
383.21 + * 2 along with this work; if not, write to the Free Software Foundation,
383.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
383.23 + *
383.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
383.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
383.26 + * have any questions.
383.27 + */
383.28 +
383.29 +/* @test
383.30 + @summary Test SimpleSoundbank setVendor method */
383.31 +
383.32 +import javax.sound.sampled.*;
383.33 +
383.34 +import com.sun.media.sound.*;
383.35 +
383.36 +public class SetVendor {
383.37 +
383.38 + private static void assertEquals(Object a, Object b) throws Exception
383.39 + {
383.40 + if(!a.equals(b))
383.41 + throw new RuntimeException("assertEquals fails!");
383.42 + }
383.43 +
383.44 + public static void main(String[] args) throws Exception {
383.45 + SimpleSoundbank soundbank = new SimpleSoundbank();
383.46 + soundbank.setVendor("hello");
383.47 + assertEquals(soundbank.getVendor(), "hello");
383.48 +
383.49 + }
383.50 +}
384.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
384.2 +++ b/test/javax/sound/midi/Gervill/SimpleSoundbank/SetVersion.java Tue Feb 03 22:02:55 2009 -0800
384.3 @@ -0,0 +1,47 @@
384.4 +/*
384.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
384.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
384.7 + *
384.8 + * This code is free software; you can redistribute it and/or modify it
384.9 + * under the terms of the GNU General Public License version 2 only, as
384.10 + * published by the Free Software Foundation. Sun designates this
384.11 + * particular file as subject to the "Classpath" exception as provided
384.12 + * by Sun in the LICENSE file that accompanied this code.
384.13 + *
384.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
384.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
384.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
384.17 + * version 2 for more details (a copy is included in the LICENSE file that
384.18 + * accompanied this code).
384.19 + *
384.20 + * You should have received a copy of the GNU General Public License version
384.21 + * 2 along with this work; if not, write to the Free Software Foundation,
384.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
384.23 + *
384.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
384.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
384.26 + * have any questions.
384.27 + */
384.28 +
384.29 +/* @test
384.30 + @summary Test SimpleSoundbank setVersion method */
384.31 +
384.32 +import javax.sound.sampled.*;
384.33 +
384.34 +import com.sun.media.sound.*;
384.35 +
384.36 +public class SetVersion {
384.37 +
384.38 + private static void assertEquals(Object a, Object b) throws Exception
384.39 + {
384.40 + if(!a.equals(b))
384.41 + throw new RuntimeException("assertEquals fails!");
384.42 + }
384.43 +
384.44 + public static void main(String[] args) throws Exception {
384.45 + SimpleSoundbank soundbank = new SimpleSoundbank();
384.46 + soundbank.setVersion("hello");
384.47 + assertEquals(soundbank.getVersion(), "hello");
384.48 +
384.49 + }
384.50 +}
385.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
385.2 +++ b/test/javax/sound/midi/Gervill/SoftAudioBuffer/Array.java Tue Feb 03 22:02:55 2009 -0800
385.3 @@ -0,0 +1,54 @@
385.4 +/*
385.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
385.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
385.7 + *
385.8 + * This code is free software; you can redistribute it and/or modify it
385.9 + * under the terms of the GNU General Public License version 2 only, as
385.10 + * published by the Free Software Foundation. Sun designates this
385.11 + * particular file as subject to the "Classpath" exception as provided
385.12 + * by Sun in the LICENSE file that accompanied this code.
385.13 + *
385.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
385.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
385.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
385.17 + * version 2 for more details (a copy is included in the LICENSE file that
385.18 + * accompanied this code).
385.19 + *
385.20 + * You should have received a copy of the GNU General Public License version
385.21 + * 2 along with this work; if not, write to the Free Software Foundation,
385.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
385.23 + *
385.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
385.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
385.26 + * have any questions.
385.27 + */
385.28 +
385.29 +/* @test
385.30 + @summary Test SoftAudioBuffer array method */
385.31 +
385.32 +import javax.sound.midi.Patch;
385.33 +import javax.sound.sampled.*;
385.34 +
385.35 +import com.sun.media.sound.*;
385.36 +
385.37 +public class Array {
385.38 +
385.39 + private static void assertEquals(Object a, Object b) throws Exception
385.40 + {
385.41 + if(!a.equals(b))
385.42 + throw new RuntimeException("assertEquals fails!");
385.43 + }
385.44 +
385.45 + private static void assertTrue(boolean value) throws Exception
385.46 + {
385.47 + if(!value)
385.48 + throw new RuntimeException("assertTrue fails!");
385.49 + }
385.50 +
385.51 + public static void main(String[] args) throws Exception {
385.52 + AudioFormat frm = new AudioFormat(8000, 8, 1, true, false);
385.53 + SoftAudioBuffer buff = new SoftAudioBuffer(377, frm);
385.54 + float[] ar = buff.array();
385.55 + assertEquals(ar.length, 377);
385.56 + }
385.57 +}
386.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
386.2 +++ b/test/javax/sound/midi/Gervill/SoftAudioBuffer/Clear.java Tue Feb 03 22:02:55 2009 -0800
386.3 @@ -0,0 +1,56 @@
386.4 +/*
386.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
386.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
386.7 + *
386.8 + * This code is free software; you can redistribute it and/or modify it
386.9 + * under the terms of the GNU General Public License version 2 only, as
386.10 + * published by the Free Software Foundation. Sun designates this
386.11 + * particular file as subject to the "Classpath" exception as provided
386.12 + * by Sun in the LICENSE file that accompanied this code.
386.13 + *
386.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
386.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
386.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
386.17 + * version 2 for more details (a copy is included in the LICENSE file that
386.18 + * accompanied this code).
386.19 + *
386.20 + * You should have received a copy of the GNU General Public License version
386.21 + * 2 along with this work; if not, write to the Free Software Foundation,
386.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
386.23 + *
386.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
386.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
386.26 + * have any questions.
386.27 + */
386.28 +
386.29 +/* @test
386.30 + @summary Test SoftAudioBuffer clear method */
386.31 +
386.32 +import javax.sound.midi.Patch;
386.33 +import javax.sound.sampled.*;
386.34 +
386.35 +import com.sun.media.sound.*;
386.36 +
386.37 +public class Clear {
386.38 +
386.39 + private static void assertEquals(Object a, Object b) throws Exception
386.40 + {
386.41 + if(!a.equals(b))
386.42 + throw new RuntimeException("assertEquals fails!");
386.43 + }
386.44 +
386.45 + private static void assertTrue(boolean value) throws Exception
386.46 + {
386.47 + if(!value)
386.48 + throw new RuntimeException("assertTrue fails!");
386.49 + }
386.50 +
386.51 + public static void main(String[] args) throws Exception {
386.52 + AudioFormat frm = new AudioFormat(8000, 8, 1, true, false);
386.53 + SoftAudioBuffer buff = new SoftAudioBuffer(377, frm);
386.54 + buff.array();
386.55 + assertTrue(!buff.isSilent());
386.56 + buff.clear();
386.57 + assertTrue(buff.isSilent());
386.58 + }
386.59 +}
387.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
387.2 +++ b/test/javax/sound/midi/Gervill/SoftAudioBuffer/Get.java Tue Feb 03 22:02:55 2009 -0800
387.3 @@ -0,0 +1,68 @@
387.4 +/*
387.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
387.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
387.7 + *
387.8 + * This code is free software; you can redistribute it and/or modify it
387.9 + * under the terms of the GNU General Public License version 2 only, as
387.10 + * published by the Free Software Foundation. Sun designates this
387.11 + * particular file as subject to the "Classpath" exception as provided
387.12 + * by Sun in the LICENSE file that accompanied this code.
387.13 + *
387.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
387.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
387.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
387.17 + * version 2 for more details (a copy is included in the LICENSE file that
387.18 + * accompanied this code).
387.19 + *
387.20 + * You should have received a copy of the GNU General Public License version
387.21 + * 2 along with this work; if not, write to the Free Software Foundation,
387.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
387.23 + *
387.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
387.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
387.26 + * have any questions.
387.27 + */
387.28 +
387.29 +/* @test
387.30 + @summary Test SoftAudioBuffer get method */
387.31 +
387.32 +import javax.sound.midi.Patch;
387.33 +import javax.sound.sampled.*;
387.34 +
387.35 +import com.sun.media.sound.*;
387.36 +
387.37 +public class Get {
387.38 +
387.39 + private static void assertEquals(Object a, Object b) throws Exception
387.40 + {
387.41 + if(!a.equals(b))
387.42 + throw new RuntimeException("assertEquals fails!");
387.43 + }
387.44 +
387.45 + private static void assertTrue(boolean value) throws Exception
387.46 + {
387.47 + if(!value)
387.48 + throw new RuntimeException("assertTrue fails!");
387.49 + }
387.50 +
387.51 + public static void main(String[] args) throws Exception {
387.52 + AudioFormat frm = new AudioFormat(8000, 16, 1, true, false);
387.53 + SoftAudioBuffer buff = new SoftAudioBuffer(100, frm);
387.54 + float[] ar = buff.array();
387.55 + for (int i = 0; i < ar.length; i++) {
387.56 + if(i % 2 == 0)
387.57 + ar[i] = 1;
387.58 + if(i % 2 == 0)
387.59 + ar[i] = -0.5f;
387.60 + }
387.61 +
387.62 + byte[] bbuff = new byte[ar.length*frm.getFrameSize()];
387.63 + buff.get(bbuff, 0);
387.64 + float[] ar2 = new float[ar.length];
387.65 + AudioFloatConverter.getConverter(frm).toFloatArray(bbuff, ar2);
387.66 +
387.67 + for (int i = 0; i < ar2.length; i++)
387.68 + if(Math.abs(ar[i] - ar2[i]) > 0.001)
387.69 + throw new Exception("conversion failure!");
387.70 + }
387.71 +}
388.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
388.2 +++ b/test/javax/sound/midi/Gervill/SoftAudioBuffer/NewSoftAudioBuffer.java Tue Feb 03 22:02:55 2009 -0800
388.3 @@ -0,0 +1,55 @@
388.4 +/*
388.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
388.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
388.7 + *
388.8 + * This code is free software; you can redistribute it and/or modify it
388.9 + * under the terms of the GNU General Public License version 2 only, as
388.10 + * published by the Free Software Foundation. Sun designates this
388.11 + * particular file as subject to the "Classpath" exception as provided
388.12 + * by Sun in the LICENSE file that accompanied this code.
388.13 + *
388.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
388.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
388.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
388.17 + * version 2 for more details (a copy is included in the LICENSE file that
388.18 + * accompanied this code).
388.19 + *
388.20 + * You should have received a copy of the GNU General Public License version
388.21 + * 2 along with this work; if not, write to the Free Software Foundation,
388.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
388.23 + *
388.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
388.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
388.26 + * have any questions.
388.27 + */
388.28 +
388.29 +/* @test
388.30 + @summary Test SoftAudioBuffer constructor */
388.31 +
388.32 +import javax.sound.midi.Patch;
388.33 +import javax.sound.sampled.*;
388.34 +
388.35 +import com.sun.media.sound.*;
388.36 +
388.37 +public class NewSoftAudioBuffer {
388.38 +
388.39 + private static void assertEquals(Object a, Object b) throws Exception
388.40 + {
388.41 + if(!a.equals(b))
388.42 + throw new RuntimeException("assertEquals fails!");
388.43 + }
388.44 +
388.45 + private static void assertTrue(boolean value) throws Exception
388.46 + {
388.47 + if(!value)
388.48 + throw new RuntimeException("assertTrue fails!");
388.49 + }
388.50 +
388.51 + public static void main(String[] args) throws Exception {
388.52 + AudioFormat frm = new AudioFormat(8000, 8, 1, true, false);
388.53 + SoftAudioBuffer buff = new SoftAudioBuffer(377, frm);
388.54 + assertEquals(buff.getSize(), 377);
388.55 + assertEquals(buff.getFormat(), frm);
388.56 + assertTrue(buff.isSilent());
388.57 + }
388.58 +}
389.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
389.2 +++ b/test/javax/sound/midi/Gervill/SoftAudioSynthesizer/DummySourceDataLine.java Tue Feb 03 22:02:55 2009 -0800
389.3 @@ -0,0 +1,232 @@
389.4 +/*
389.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
389.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
389.7 + *
389.8 + * This code is free software; you can redistribute it and/or modify it
389.9 + * under the terms of the GNU General Public License version 2 only, as
389.10 + * published by the Free Software Foundation. Sun designates this
389.11 + * particular file as subject to the "Classpath" exception as provided
389.12 + * by Sun in the LICENSE file that accompanied this code.
389.13 + *
389.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
389.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
389.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
389.17 + * version 2 for more details (a copy is included in the LICENSE file that
389.18 + * accompanied this code).
389.19 + *
389.20 + * You should have received a copy of the GNU General Public License version
389.21 + * 2 along with this work; if not, write to the Free Software Foundation,
389.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
389.23 + *
389.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
389.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
389.26 + * have any questions.
389.27 + */
389.28 +
389.29 +import java.util.ArrayList;
389.30 +
389.31 +import javax.sound.sampled.AudioFormat;
389.32 +import javax.sound.sampled.AudioSystem;
389.33 +import javax.sound.sampled.Control;
389.34 +import javax.sound.sampled.DataLine;
389.35 +import javax.sound.sampled.LineListener;
389.36 +import javax.sound.sampled.LineUnavailableException;
389.37 +import javax.sound.sampled.SourceDataLine;
389.38 +import javax.sound.sampled.AudioFormat.Encoding;
389.39 +import javax.sound.sampled.Control.Type;
389.40 +
389.41 +import com.sun.media.sound.AudioFloatConverter;
389.42 +
389.43 +/**
389.44 + * This is a SourceDataLine simulator used for testing SoftSynthesizer
389.45 + * without using real SourceDataLine / Audio Device.
389.46 + *
389.47 + * @author Karl Helgason
389.48 + */
389.49 +
389.50 +public class DummySourceDataLine implements SourceDataLine {
389.51 +
389.52 + private int bufferSize = -1;
389.53 +
389.54 + private AudioFormat format = new AudioFormat(44100.0f, 16, 2, true, false);
389.55 +
389.56 + private DataLine.Info sourceLineInfo;
389.57 +
389.58 + private boolean active = false;
389.59 +
389.60 + private long framepos = 0;
389.61 +
389.62 + private boolean opened = false;
389.63 +
389.64 + private int framesize = 0;
389.65 +
389.66 + public DummySourceDataLine()
389.67 + {
389.68 + ArrayList<AudioFormat> formats = new ArrayList<AudioFormat>();
389.69 + for (int channels = 1; channels <= 2; channels++) {
389.70 + formats.add(new AudioFormat(Encoding.PCM_SIGNED,
389.71 + AudioSystem.NOT_SPECIFIED, 8, channels, channels,
389.72 + AudioSystem.NOT_SPECIFIED, false));
389.73 + formats.add(new AudioFormat(Encoding.PCM_UNSIGNED,
389.74 + AudioSystem.NOT_SPECIFIED, 8, channels, channels,
389.75 + AudioSystem.NOT_SPECIFIED, false));
389.76 + for (int bits = 16; bits < 32; bits += 8) {
389.77 + formats.add(new AudioFormat(Encoding.PCM_SIGNED,
389.78 + AudioSystem.NOT_SPECIFIED, bits, channels, channels
389.79 + * bits / 8, AudioSystem.NOT_SPECIFIED, false));
389.80 + formats.add(new AudioFormat(Encoding.PCM_UNSIGNED,
389.81 + AudioSystem.NOT_SPECIFIED, bits, channels, channels
389.82 + * bits / 8, AudioSystem.NOT_SPECIFIED, false));
389.83 + formats.add(new AudioFormat(Encoding.PCM_SIGNED,
389.84 + AudioSystem.NOT_SPECIFIED, bits, channels, channels
389.85 + * bits / 8, AudioSystem.NOT_SPECIFIED, true));
389.86 + formats.add(new AudioFormat(Encoding.PCM_UNSIGNED,
389.87 + AudioSystem.NOT_SPECIFIED, bits, channels, channels
389.88 + * bits / 8, AudioSystem.NOT_SPECIFIED, true));
389.89 + }
389.90 + formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT,
389.91 + AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4,
389.92 + AudioSystem.NOT_SPECIFIED, false));
389.93 + formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT,
389.94 + AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4,
389.95 + AudioSystem.NOT_SPECIFIED, true));
389.96 + formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT,
389.97 + AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8,
389.98 + AudioSystem.NOT_SPECIFIED, false));
389.99 + formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT,
389.100 + AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8,
389.101 + AudioSystem.NOT_SPECIFIED, true));
389.102 + }
389.103 + AudioFormat[] formats_array = formats.toArray(new AudioFormat[formats
389.104 + .size()]);
389.105 + sourceLineInfo = new DataLine.Info(SourceDataLine.class,
389.106 + formats_array, AudioSystem.NOT_SPECIFIED,
389.107 + AudioSystem.NOT_SPECIFIED);
389.108 +
389.109 + }
389.110 +
389.111 + public void open() throws LineUnavailableException {
389.112 + open(format);
389.113 + }
389.114 +
389.115 + public void open(AudioFormat format) throws LineUnavailableException {
389.116 + if (bufferSize == -1)
389.117 + bufferSize = ((int) (format.getFrameRate() / 2))
389.118 + * format.getFrameSize();
389.119 + open(format, bufferSize);
389.120 + }
389.121 +
389.122 + public void open(AudioFormat format, int bufferSize)
389.123 + throws LineUnavailableException {
389.124 + this.format = format;
389.125 + this.bufferSize = bufferSize;
389.126 + this.framesize = format.getFrameSize();
389.127 + opened = true;
389.128 + }
389.129 +
389.130 + public boolean isOpen() {
389.131 + return opened;
389.132 + }
389.133 +
389.134 + public int write(byte[] b, int off, int len) {
389.135 + if (!isOpen())
389.136 + return 0;
389.137 + if (len % framesize != 0)
389.138 + throw new IllegalArgumentException(
389.139 + "Number of bytes does not represent an integral number of sample frames.");
389.140 +
389.141 +
389.142 + int flen = len / framesize;
389.143 + framepos += flen;
389.144 +
389.145 + long time = (long) (flen * (1000.0 / (double) getFormat()
389.146 + .getSampleRate()));
389.147 + try {
389.148 + Thread.sleep(time);
389.149 + } catch (InterruptedException e) {
389.150 + e.printStackTrace();
389.151 + return 0;
389.152 + }
389.153 +
389.154 + return len;
389.155 + }
389.156 +
389.157 + public int available() {
389.158 + return 0;
389.159 + }
389.160 +
389.161 + public void drain() {
389.162 + }
389.163 +
389.164 + public void flush() {
389.165 + }
389.166 +
389.167 + public int getBufferSize() {
389.168 + return bufferSize;
389.169 + }
389.170 +
389.171 + public AudioFormat getFormat() {
389.172 + return format;
389.173 + }
389.174 +
389.175 + public int getFramePosition() {
389.176 + return (int) getLongFramePosition();
389.177 + }
389.178 +
389.179 + public float getLevel() {
389.180 + return AudioSystem.NOT_SPECIFIED;
389.181 + }
389.182 +
389.183 + public long getLongFramePosition() {
389.184 + return framepos;
389.185 + }
389.186 +
389.187 + public long getMicrosecondPosition() {
389.188 + return (long) (getLongFramePosition() * (1000000.0 / (double) getFormat()
389.189 + .getSampleRate()));
389.190 + }
389.191 +
389.192 + public boolean isActive() {
389.193 + return active;
389.194 + }
389.195 +
389.196 + public boolean isRunning() {
389.197 + return active;
389.198 + }
389.199 +
389.200 + public void start() {
389.201 + active = true;
389.202 + }
389.203 +
389.204 + public void stop() {
389.205 + active = false;
389.206 + }
389.207 +
389.208 + public void close() {
389.209 + stop();
389.210 + }
389.211 +
389.212 + public Control getControl(Type control) {
389.213 + throw new IllegalArgumentException("Unsupported control type : "
389.214 + + control);
389.215 + }
389.216 +
389.217 + public Control[] getControls() {
389.218 + return new Control[0];
389.219 + }
389.220 +
389.221 + public javax.sound.sampled.Line.Info getLineInfo() {
389.222 + return sourceLineInfo;
389.223 + }
389.224 +
389.225 + public boolean isControlSupported(Type control) {
389.226 + return false;
389.227 + }
389.228 +
389.229 + public void addLineListener(LineListener listener) {
389.230 + }
389.231 +
389.232 + public void removeLineListener(LineListener listener) {
389.233 + }
389.234 +
389.235 +}
390.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
390.2 +++ b/test/javax/sound/midi/Gervill/SoftAudioSynthesizer/GetFormat.java Tue Feb 03 22:02:55 2009 -0800
390.3 @@ -0,0 +1,61 @@
390.4 +/*
390.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
390.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
390.7 + *
390.8 + * This code is free software; you can redistribute it and/or modify it
390.9 + * under the terms of the GNU General Public License version 2 only, as
390.10 + * published by the Free Software Foundation. Sun designates this
390.11 + * particular file as subject to the "Classpath" exception as provided
390.12 + * by Sun in the LICENSE file that accompanied this code.
390.13 + *
390.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
390.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
390.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
390.17 + * version 2 for more details (a copy is included in the LICENSE file that
390.18 + * accompanied this code).
390.19 + *
390.20 + * You should have received a copy of the GNU General Public License version
390.21 + * 2 along with this work; if not, write to the Free Software Foundation,
390.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
390.23 + *
390.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
390.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
390.26 + * have any questions.
390.27 + */
390.28 +
390.29 +/* @test
390.30 + @summary Test SoftAudioSynthesizer getFormat method */
390.31 +
390.32 +import javax.sound.midi.MidiUnavailableException;
390.33 +import javax.sound.midi.Patch;
390.34 +import javax.sound.sampled.*;
390.35 +
390.36 +import com.sun.media.sound.*;
390.37 +
390.38 +public class GetFormat {
390.39 +
390.40 + private static void assertEquals(Object a, Object b) throws Exception
390.41 + {
390.42 + if(!a.equals(b))
390.43 + throw new RuntimeException("assertEquals fails!");
390.44 + }
390.45 +
390.46 + private static void assertTrue(boolean value) throws Exception
390.47 + {
390.48 + if(!value)
390.49 + throw new RuntimeException("assertTrue fails!");
390.50 + }
390.51 +
390.52 + public static void main(String[] args) throws Exception {
390.53 + AudioSynthesizer synth = new SoftSynthesizer();
390.54 + AudioFormat defformat = synth.getFormat();
390.55 + assertTrue(defformat != null);
390.56 + synth.openStream(null, null);
390.57 + assertTrue(synth.getFormat().toString().equals(defformat.toString()));
390.58 + synth.close();
390.59 + AudioFormat custformat = new AudioFormat(8000, 16, 1, true, false);
390.60 + synth.openStream(custformat, null);
390.61 + assertTrue(synth.getFormat().toString().equals(custformat.toString()));
390.62 + synth.close();
390.63 + }
390.64 +}
391.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
391.2 +++ b/test/javax/sound/midi/Gervill/SoftAudioSynthesizer/GetPropertyInfo.java Tue Feb 03 22:02:55 2009 -0800
391.3 @@ -0,0 +1,53 @@
391.4 +/*
391.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
391.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
391.7 + *
391.8 + * This code is free software; you can redistribute it and/or modify it
391.9 + * under the terms of the GNU General Public License version 2 only, as
391.10 + * published by the Free Software Foundation. Sun designates this
391.11 + * particular file as subject to the "Classpath" exception as provided
391.12 + * by Sun in the LICENSE file that accompanied this code.
391.13 + *
391.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
391.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
391.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
391.17 + * version 2 for more details (a copy is included in the LICENSE file that
391.18 + * accompanied this code).
391.19 + *
391.20 + * You should have received a copy of the GNU General Public License version
391.21 + * 2 along with this work; if not, write to the Free Software Foundation,
391.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
391.23 + *
391.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
391.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
391.26 + * have any questions.
391.27 + */
391.28 +
391.29 +/* @test
391.30 + @summary Test SoftAudioSynthesizer getPropertyInfo method */
391.31 +
391.32 +import javax.sound.midi.Patch;
391.33 +import javax.sound.sampled.*;
391.34 +
391.35 +import com.sun.media.sound.*;
391.36 +
391.37 +public class GetPropertyInfo {
391.38 +
391.39 + private static void assertEquals(Object a, Object b) throws Exception
391.40 + {
391.41 + if(!a.equals(b))
391.42 + throw new RuntimeException("assertEquals fails!");
391.43 + }
391.44 +
391.45 + private static void assertTrue(boolean value) throws Exception
391.46 + {
391.47 + if(!value)
391.48 + throw new RuntimeException("assertTrue fails!");
391.49 + }
391.50 +
391.51 + public static void main(String[] args) throws Exception {
391.52 + AudioSynthesizer synth = new SoftSynthesizer();
391.53 + AudioSynthesizerPropertyInfo[] info = synth.getPropertyInfo(null);
391.54 + assertTrue(info != null);
391.55 + }
391.56 +}
392.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
392.2 +++ b/test/javax/sound/midi/Gervill/SoftAudioSynthesizer/Open.java Tue Feb 03 22:02:55 2009 -0800
392.3 @@ -0,0 +1,54 @@
392.4 +/*
392.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
392.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
392.7 + *
392.8 + * This code is free software; you can redistribute it and/or modify it
392.9 + * under the terms of the GNU General Public License version 2 only, as
392.10 + * published by the Free Software Foundation. Sun designates this
392.11 + * particular file as subject to the "Classpath" exception as provided
392.12 + * by Sun in the LICENSE file that accompanied this code.
392.13 + *
392.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
392.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
392.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
392.17 + * version 2 for more details (a copy is included in the LICENSE file that
392.18 + * accompanied this code).
392.19 + *
392.20 + * You should have received a copy of the GNU General Public License version
392.21 + * 2 along with this work; if not, write to the Free Software Foundation,
392.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
392.23 + *
392.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
392.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
392.26 + * have any questions.
392.27 + */
392.28 +
392.29 +/* @test
392.30 + @summary Test SoftAudioSynthesizer open method */
392.31 +
392.32 +import javax.sound.midi.Patch;
392.33 +import javax.sound.sampled.*;
392.34 +
392.35 +import com.sun.media.sound.*;
392.36 +
392.37 +public class Open {
392.38 +
392.39 + private static void assertEquals(Object a, Object b) throws Exception
392.40 + {
392.41 + if(!a.equals(b))
392.42 + throw new RuntimeException("assertEquals fails!");
392.43 + }
392.44 +
392.45 + private static void assertTrue(boolean value) throws Exception
392.46 + {
392.47 + if(!value)
392.48 + throw new RuntimeException("assertTrue fails!");
392.49 + }
392.50 +
392.51 + public static void main(String[] args) throws Exception {
392.52 + AudioSynthesizer synth = new SoftSynthesizer();
392.53 + SourceDataLine line = new DummySourceDataLine(); //AudioSystem.getSourceDataLine(new AudioFormat(44100, 16, 2, true, false));
392.54 + synth.open(line, null);
392.55 + synth.close();
392.56 + }
392.57 +}
393.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
393.2 +++ b/test/javax/sound/midi/Gervill/SoftAudioSynthesizer/OpenStream.java Tue Feb 03 22:02:55 2009 -0800
393.3 @@ -0,0 +1,54 @@
393.4 +/*
393.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
393.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
393.7 + *
393.8 + * This code is free software; you can redistribute it and/or modify it
393.9 + * under the terms of the GNU General Public License version 2 only, as
393.10 + * published by the Free Software Foundation. Sun designates this
393.11 + * particular file as subject to the "Classpath" exception as provided
393.12 + * by Sun in the LICENSE file that accompanied this code.
393.13 + *
393.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
393.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
393.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
393.17 + * version 2 for more details (a copy is included in the LICENSE file that
393.18 + * accompanied this code).
393.19 + *
393.20 + * You should have received a copy of the GNU General Public License version
393.21 + * 2 along with this work; if not, write to the Free Software Foundation,
393.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
393.23 + *
393.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
393.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
393.26 + * have any questions.
393.27 + */
393.28 +
393.29 +/* @test
393.30 + @summary Test SoftAudioSynthesizer openStream method */
393.31 +
393.32 +import javax.sound.midi.Patch;
393.33 +import javax.sound.sampled.*;
393.34 +
393.35 +import com.sun.media.sound.*;
393.36 +
393.37 +public class OpenStream {
393.38 +
393.39 + private static void assertEquals(Object a, Object b) throws Exception
393.40 + {
393.41 + if(!a.equals(b))
393.42 + throw new RuntimeException("assertEquals fails!");
393.43 + }
393.44 +
393.45 + private static void assertTrue(boolean value) throws Exception
393.46 + {
393.47 + if(!value)
393.48 + throw new RuntimeException("assertTrue fails!");
393.49 + }
393.50 +
393.51 + public static void main(String[] args) throws Exception {
393.52 + AudioSynthesizer synth = new SoftSynthesizer();
393.53 + synth.openStream(null, null);
393.54 + assertTrue(synth.isOpen());
393.55 + synth.close();
393.56 + }
393.57 +}
394.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
394.2 +++ b/test/javax/sound/midi/Gervill/SoftChannel/AllNotesOff.java Tue Feb 03 22:02:55 2009 -0800
394.3 @@ -0,0 +1,64 @@
394.4 +/*
394.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
394.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
394.7 + *
394.8 + * This code is free software; you can redistribute it and/or modify it
394.9 + * under the terms of the GNU General Public License version 2 only, as
394.10 + * published by the Free Software Foundation. Sun designates this
394.11 + * particular file as subject to the "Classpath" exception as provided
394.12 + * by Sun in the LICENSE file that accompanied this code.
394.13 + *
394.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
394.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
394.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
394.17 + * version 2 for more details (a copy is included in the LICENSE file that
394.18 + * accompanied this code).
394.19 + *
394.20 + * You should have received a copy of the GNU General Public License version
394.21 + * 2 along with this work; if not, write to the Free Software Foundation,
394.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
394.23 + *
394.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
394.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
394.26 + * have any questions.
394.27 + */
394.28 +
394.29 +/* @test
394.30 + @summary Test SoftChannel allNotesOff method */
394.31 +
394.32 +import javax.sound.midi.*;
394.33 +import javax.sound.sampled.*;
394.34 +
394.35 +import com.sun.media.sound.*;
394.36 +
394.37 +public class AllNotesOff {
394.38 +
394.39 + private static void assertEquals(Object a, Object b) throws Exception
394.40 + {
394.41 + if(!a.equals(b))
394.42 + throw new RuntimeException("assertEquals fails!");
394.43 + }
394.44 +
394.45 + private static void assertTrue(boolean value) throws Exception
394.46 + {
394.47 + if(!value)
394.48 + throw new RuntimeException("assertTrue fails!");
394.49 + }
394.50 +
394.51 + public static void main(String[] args) throws Exception {
394.52 + SoftTestUtils soft = new SoftTestUtils();
394.53 + MidiChannel channel = soft.synth.getChannels()[0];
394.54 +
394.55 + channel.noteOn(60, 64);
394.56 + soft.read(1);
394.57 + VoiceStatus[] v = soft.synth.getVoiceStatus();
394.58 + assertEquals(v[0].note, 60);
394.59 + assertEquals(v[0].active, true);
394.60 + channel.allNotesOff();
394.61 + soft.read(1);
394.62 + v = soft.synth.getVoiceStatus();
394.63 + assertEquals(v[0].active, false);
394.64 +
394.65 + soft.close();
394.66 + }
394.67 +}
395.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
395.2 +++ b/test/javax/sound/midi/Gervill/SoftChannel/AllSoundOff.java Tue Feb 03 22:02:55 2009 -0800
395.3 @@ -0,0 +1,64 @@
395.4 +/*
395.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
395.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
395.7 + *
395.8 + * This code is free software; you can redistribute it and/or modify it
395.9 + * under the terms of the GNU General Public License version 2 only, as
395.10 + * published by the Free Software Foundation. Sun designates this
395.11 + * particular file as subject to the "Classpath" exception as provided
395.12 + * by Sun in the LICENSE file that accompanied this code.
395.13 + *
395.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
395.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
395.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
395.17 + * version 2 for more details (a copy is included in the LICENSE file that
395.18 + * accompanied this code).
395.19 + *
395.20 + * You should have received a copy of the GNU General Public License version
395.21 + * 2 along with this work; if not, write to the Free Software Foundation,
395.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
395.23 + *
395.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
395.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
395.26 + * have any questions.
395.27 + */
395.28 +
395.29 +/* @test
395.30 + @summary Test SoftChannel allSoundOff method */
395.31 +
395.32 +import javax.sound.midi.*;
395.33 +import javax.sound.sampled.*;
395.34 +
395.35 +import com.sun.media.sound.*;
395.36 +
395.37 +public class AllSoundOff {
395.38 +
395.39 + private static void assertEquals(Object a, Object b) throws Exception
395.40 + {
395.41 + if(!a.equals(b))
395.42 + throw new RuntimeException("assertEquals fails!");
395.43 + }
395.44 +
395.45 + private static void assertTrue(boolean value) throws Exception
395.46 + {
395.47 + if(!value)
395.48 + throw new RuntimeException("assertTrue fails!");
395.49 + }
395.50 +
395.51 + public static void main(String[] args) throws Exception {
395.52 + SoftTestUtils soft = new SoftTestUtils();
395.53 + MidiChannel channel = soft.synth.getChannels()[0];
395.54 +
395.55 + channel.noteOn(60, 64);
395.56 + soft.read(1);
395.57 + VoiceStatus[] v = soft.synth.getVoiceStatus();
395.58 + assertEquals(v[0].note, 60);
395.59 + assertEquals(v[0].active, true);
395.60 + channel.allSoundOff();
395.61 + soft.read(1);
395.62 + v = soft.synth.getVoiceStatus();
395.63 + assertEquals(v[0].active, false);
395.64 +
395.65 + soft.close();
395.66 + }
395.67 +}
396.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
396.2 +++ b/test/javax/sound/midi/Gervill/SoftChannel/ChannelPressure.java Tue Feb 03 22:02:55 2009 -0800
396.3 @@ -0,0 +1,59 @@
396.4 +/*
396.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
396.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
396.7 + *
396.8 + * This code is free software; you can redistribute it and/or modify it
396.9 + * under the terms of the GNU General Public License version 2 only, as
396.10 + * published by the Free Software Foundation. Sun designates this
396.11 + * particular file as subject to the "Classpath" exception as provided
396.12 + * by Sun in the LICENSE file that accompanied this code.
396.13 + *
396.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
396.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
396.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
396.17 + * version 2 for more details (a copy is included in the LICENSE file that
396.18 + * accompanied this code).
396.19 + *
396.20 + * You should have received a copy of the GNU General Public License version
396.21 + * 2 along with this work; if not, write to the Free Software Foundation,
396.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
396.23 + *
396.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
396.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
396.26 + * have any questions.
396.27 + */
396.28 +
396.29 +/* @test
396.30 + @summary Test SoftChannel channelPressure method */
396.31 +
396.32 +import javax.sound.midi.*;
396.33 +import javax.sound.sampled.*;
396.34 +
396.35 +import com.sun.media.sound.*;
396.36 +
396.37 +public class ChannelPressure {
396.38 +
396.39 + private static void assertEquals(Object a, Object b) throws Exception
396.40 + {
396.41 + if(!a.equals(b))
396.42 + throw new RuntimeException("assertEquals fails!");
396.43 + }
396.44 +
396.45 + private static void assertTrue(boolean value) throws Exception
396.46 + {
396.47 + if(!value)
396.48 + throw new RuntimeException("assertTrue fails!");
396.49 + }
396.50 +
396.51 + public static void main(String[] args) throws Exception {
396.52 + SoftTestUtils soft = new SoftTestUtils();
396.53 + MidiChannel channel = soft.synth.getChannels()[0];
396.54 +
396.55 + channel.setChannelPressure(10);
396.56 + assertEquals(channel.getChannelPressure(), 10);
396.57 + channel.setChannelPressure(90);
396.58 + assertEquals(channel.getChannelPressure(), 90);
396.59 +
396.60 + soft.close();
396.61 + }
396.62 +}
397.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
397.2 +++ b/test/javax/sound/midi/Gervill/SoftChannel/Controller.java Tue Feb 03 22:02:55 2009 -0800
397.3 @@ -0,0 +1,62 @@
397.4 +/*
397.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
397.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
397.7 + *
397.8 + * This code is free software; you can redistribute it and/or modify it
397.9 + * under the terms of the GNU General Public License version 2 only, as
397.10 + * published by the Free Software Foundation. Sun designates this
397.11 + * particular file as subject to the "Classpath" exception as provided
397.12 + * by Sun in the LICENSE file that accompanied this code.
397.13 + *
397.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
397.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
397.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
397.17 + * version 2 for more details (a copy is included in the LICENSE file that
397.18 + * accompanied this code).
397.19 + *
397.20 + * You should have received a copy of the GNU General Public License version
397.21 + * 2 along with this work; if not, write to the Free Software Foundation,
397.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
397.23 + *
397.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
397.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
397.26 + * have any questions.
397.27 + */
397.28 +
397.29 +/* @test
397.30 + @summary Test SoftChannel controller method */
397.31 +
397.32 +import javax.sound.midi.*;
397.33 +import javax.sound.sampled.*;
397.34 +
397.35 +import com.sun.media.sound.*;
397.36 +
397.37 +public class Controller {
397.38 +
397.39 + private static void assertEquals(Object a, Object b) throws Exception
397.40 + {
397.41 + if(!a.equals(b))
397.42 + throw new RuntimeException("assertEquals fails!");
397.43 + }
397.44 +
397.45 + private static void assertTrue(boolean value) throws Exception
397.46 + {
397.47 + if(!value)
397.48 + throw new RuntimeException("assertTrue fails!");
397.49 + }
397.50 +
397.51 + public static void main(String[] args) throws Exception {
397.52 + SoftTestUtils soft = new SoftTestUtils();
397.53 + MidiChannel channel = soft.synth.getChannels()[0];
397.54 +
397.55 + for (int i = 0; i < 128; i++) {
397.56 + if(i == 0 || i == 32) continue;
397.57 + channel.controlChange(i, 10);
397.58 + assertEquals(channel.getController(i), 10);
397.59 + channel.controlChange(i, 100);
397.60 + assertEquals(channel.getController(i), 100);
397.61 + }
397.62 +
397.63 + soft.close();
397.64 + }
397.65 +}
398.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
398.2 +++ b/test/javax/sound/midi/Gervill/SoftChannel/LocalControl.java Tue Feb 03 22:02:55 2009 -0800
398.3 @@ -0,0 +1,60 @@
398.4 +/*
398.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
398.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
398.7 + *
398.8 + * This code is free software; you can redistribute it and/or modify it
398.9 + * under the terms of the GNU General Public License version 2 only, as
398.10 + * published by the Free Software Foundation. Sun designates this
398.11 + * particular file as subject to the "Classpath" exception as provided
398.12 + * by Sun in the LICENSE file that accompanied this code.
398.13 + *
398.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
398.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
398.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
398.17 + * version 2 for more details (a copy is included in the LICENSE file that
398.18 + * accompanied this code).
398.19 + *
398.20 + * You should have received a copy of the GNU General Public License version
398.21 + * 2 along with this work; if not, write to the Free Software Foundation,
398.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
398.23 + *
398.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
398.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
398.26 + * have any questions.
398.27 + */
398.28 +
398.29 +/* @test
398.30 + @summary Test SoftChannel localControl method */
398.31 +
398.32 +import javax.sound.midi.*;
398.33 +import javax.sound.sampled.*;
398.34 +
398.35 +import com.sun.media.sound.*;
398.36 +
398.37 +public class LocalControl {
398.38 +
398.39 + private static void assertEquals(Object a, Object b) throws Exception
398.40 + {
398.41 + if(!a.equals(b))
398.42 + throw new RuntimeException("assertEquals fails!");
398.43 + }
398.44 +
398.45 + private static void assertTrue(boolean value) throws Exception
398.46 + {
398.47 + if(!value)
398.48 + throw new RuntimeException("assertTrue fails!");
398.49 + }
398.50 +
398.51 + public static void main(String[] args) throws Exception {
398.52 + SoftTestUtils soft = new SoftTestUtils();
398.53 + MidiChannel channel = soft.synth.getChannels()[0];
398.54 +
398.55 + // Local control not supported
398.56 + // because this is a software synthesizer
398.57 + // localControl() should always return false
398.58 + assertEquals(channel.localControl(true), false);
398.59 + assertEquals(channel.localControl(false), false);
398.60 +
398.61 + soft.close();
398.62 + }
398.63 +}
399.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
399.2 +++ b/test/javax/sound/midi/Gervill/SoftChannel/Mono.java Tue Feb 03 22:02:55 2009 -0800
399.3 @@ -0,0 +1,59 @@
399.4 +/*
399.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
399.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
399.7 + *
399.8 + * This code is free software; you can redistribute it and/or modify it
399.9 + * under the terms of the GNU General Public License version 2 only, as
399.10 + * published by the Free Software Foundation. Sun designates this
399.11 + * particular file as subject to the "Classpath" exception as provided
399.12 + * by Sun in the LICENSE file that accompanied this code.
399.13 + *
399.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
399.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
399.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
399.17 + * version 2 for more details (a copy is included in the LICENSE file that
399.18 + * accompanied this code).
399.19 + *
399.20 + * You should have received a copy of the GNU General Public License version
399.21 + * 2 along with this work; if not, write to the Free Software Foundation,
399.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
399.23 + *
399.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
399.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
399.26 + * have any questions.
399.27 + */
399.28 +
399.29 +/* @test
399.30 + @summary Test SoftChannel mono method */
399.31 +
399.32 +import javax.sound.midi.*;
399.33 +import javax.sound.sampled.*;
399.34 +
399.35 +import com.sun.media.sound.*;
399.36 +
399.37 +public class Mono {
399.38 +
399.39 + private static void assertEquals(Object a, Object b) throws Exception
399.40 + {
399.41 + if(!a.equals(b))
399.42 + throw new RuntimeException("assertEquals fails!");
399.43 + }
399.44 +
399.45 + private static void assertTrue(boolean value) throws Exception
399.46 + {
399.47 + if(!value)
399.48 + throw new RuntimeException("assertTrue fails!");
399.49 + }
399.50 +
399.51 + public static void main(String[] args) throws Exception {
399.52 + SoftTestUtils soft = new SoftTestUtils();
399.53 + MidiChannel channel = soft.synth.getChannels()[0];
399.54 +
399.55 + channel.setMono(true);
399.56 + assertEquals(channel.getMono(), true);
399.57 + channel.setMono(false);
399.58 + assertEquals(channel.getMono(), false);
399.59 +
399.60 + soft.close();
399.61 + }
399.62 +}
400.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
400.2 +++ b/test/javax/sound/midi/Gervill/SoftChannel/Mute.java Tue Feb 03 22:02:55 2009 -0800
400.3 @@ -0,0 +1,59 @@
400.4 +/*
400.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
400.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
400.7 + *
400.8 + * This code is free software; you can redistribute it and/or modify it
400.9 + * under the terms of the GNU General Public License version 2 only, as
400.10 + * published by the Free Software Foundation. Sun designates this
400.11 + * particular file as subject to the "Classpath" exception as provided
400.12 + * by Sun in the LICENSE file that accompanied this code.
400.13 + *
400.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
400.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
400.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
400.17 + * version 2 for more details (a copy is included in the LICENSE file that
400.18 + * accompanied this code).
400.19 + *
400.20 + * You should have received a copy of the GNU General Public License version
400.21 + * 2 along with this work; if not, write to the Free Software Foundation,
400.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
400.23 + *
400.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
400.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
400.26 + * have any questions.
400.27 + */
400.28 +
400.29 +/* @test
400.30 + @summary Test SoftChannel mute method */
400.31 +
400.32 +import javax.sound.midi.*;
400.33 +import javax.sound.sampled.*;
400.34 +
400.35 +import com.sun.media.sound.*;
400.36 +
400.37 +public class Mute {
400.38 +
400.39 + private static void assertEquals(Object a, Object b) throws Exception
400.40 + {
400.41 + if(!a.equals(b))
400.42 + throw new RuntimeException("assertEquals fails!");
400.43 + }
400.44 +
400.45 + private static void assertTrue(boolean value) throws Exception
400.46 + {
400.47 + if(!value)
400.48 + throw new RuntimeException("assertTrue fails!");
400.49 + }
400.50 +
400.51 + public static void main(String[] args) throws Exception {
400.52 + SoftTestUtils soft = new SoftTestUtils();
400.53 + MidiChannel channel = soft.synth.getChannels()[0];
400.54 +
400.55 + channel.setMute(true);
400.56 + assertEquals(channel.getMute(), true);
400.57 + channel.setMute(false);
400.58 + assertEquals(channel.getMute(), false);
400.59 +
400.60 + soft.close();
400.61 + }
400.62 +}
401.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
401.2 +++ b/test/javax/sound/midi/Gervill/SoftChannel/NoteOff.java Tue Feb 03 22:02:55 2009 -0800
401.3 @@ -0,0 +1,64 @@
401.4 +/*
401.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
401.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
401.7 + *
401.8 + * This code is free software; you can redistribute it and/or modify it
401.9 + * under the terms of the GNU General Public License version 2 only, as
401.10 + * published by the Free Software Foundation. Sun designates this
401.11 + * particular file as subject to the "Classpath" exception as provided
401.12 + * by Sun in the LICENSE file that accompanied this code.
401.13 + *
401.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
401.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
401.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
401.17 + * version 2 for more details (a copy is included in the LICENSE file that
401.18 + * accompanied this code).
401.19 + *
401.20 + * You should have received a copy of the GNU General Public License version
401.21 + * 2 along with this work; if not, write to the Free Software Foundation,
401.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
401.23 + *
401.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
401.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
401.26 + * have any questions.
401.27 + */
401.28 +
401.29 +/* @test
401.30 + @summary Test SoftChannel noteOff method */
401.31 +
401.32 +import javax.sound.midi.*;
401.33 +import javax.sound.sampled.*;
401.34 +
401.35 +import com.sun.media.sound.*;
401.36 +
401.37 +public class NoteOff {
401.38 +
401.39 + private static void assertEquals(Object a, Object b) throws Exception
401.40 + {
401.41 + if(!a.equals(b))
401.42 + throw new RuntimeException("assertEquals fails!");
401.43 + }
401.44 +
401.45 + private static void assertTrue(boolean value) throws Exception
401.46 + {
401.47 + if(!value)
401.48 + throw new RuntimeException("assertTrue fails!");
401.49 + }
401.50 +
401.51 + public static void main(String[] args) throws Exception {
401.52 + SoftTestUtils soft = new SoftTestUtils();
401.53 + MidiChannel channel = soft.synth.getChannels()[0];
401.54 +
401.55 + channel.noteOn(60, 64);
401.56 + soft.read(1);
401.57 + VoiceStatus[] v = soft.synth.getVoiceStatus();
401.58 + assertEquals(v[0].note, 60);
401.59 + assertEquals(v[0].active, true);
401.60 + channel.noteOff(60);
401.61 + soft.read(1);
401.62 + v = soft.synth.getVoiceStatus();;
401.63 + assertEquals(v[0].active, false);
401.64 +
401.65 + soft.close();
401.66 + }
401.67 +}
402.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
402.2 +++ b/test/javax/sound/midi/Gervill/SoftChannel/NoteOff2.java Tue Feb 03 22:02:55 2009 -0800
402.3 @@ -0,0 +1,64 @@
402.4 +/*
402.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
402.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
402.7 + *
402.8 + * This code is free software; you can redistribute it and/or modify it
402.9 + * under the terms of the GNU General Public License version 2 only, as
402.10 + * published by the Free Software Foundation. Sun designates this
402.11 + * particular file as subject to the "Classpath" exception as provided
402.12 + * by Sun in the LICENSE file that accompanied this code.
402.13 + *
402.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
402.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
402.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
402.17 + * version 2 for more details (a copy is included in the LICENSE file that
402.18 + * accompanied this code).
402.19 + *
402.20 + * You should have received a copy of the GNU General Public License version
402.21 + * 2 along with this work; if not, write to the Free Software Foundation,
402.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
402.23 + *
402.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
402.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
402.26 + * have any questions.
402.27 + */
402.28 +
402.29 +/* @test
402.30 + @summary Test SoftChannel noteOff method */
402.31 +
402.32 +import javax.sound.midi.*;
402.33 +import javax.sound.sampled.*;
402.34 +
402.35 +import com.sun.media.sound.*;
402.36 +
402.37 +public class NoteOff2 {
402.38 +
402.39 + private static void assertEquals(Object a, Object b) throws Exception
402.40 + {
402.41 + if(!a.equals(b))
402.42 + throw new RuntimeException("assertEquals fails!");
402.43 + }
402.44 +
402.45 + private static void assertTrue(boolean value) throws Exception
402.46 + {
402.47 + if(!value)
402.48 + throw new RuntimeException("assertTrue fails!");
402.49 + }
402.50 +
402.51 + public static void main(String[] args) throws Exception {
402.52 + SoftTestUtils soft = new SoftTestUtils();
402.53 + MidiChannel channel = soft.synth.getChannels()[0];
402.54 +
402.55 + channel.noteOn(60, 64);
402.56 + soft.read(1);
402.57 + VoiceStatus[] v = soft.synth.getVoiceStatus();
402.58 + assertEquals(v[0].note, 60);
402.59 + assertEquals(v[0].active, true);
402.60 + channel.noteOff(60);
402.61 + soft.read(1);
402.62 + v = soft.synth.getVoiceStatus();;
402.63 + assertEquals(v[0].active, false);
402.64 +
402.65 + soft.close();
402.66 + }
402.67 +}
403.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
403.2 +++ b/test/javax/sound/midi/Gervill/SoftChannel/NoteOn.java Tue Feb 03 22:02:55 2009 -0800
403.3 @@ -0,0 +1,64 @@
403.4 +/*
403.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
403.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
403.7 + *
403.8 + * This code is free software; you can redistribute it and/or modify it
403.9 + * under the terms of the GNU General Public License version 2 only, as
403.10 + * published by the Free Software Foundation. Sun designates this
403.11 + * particular file as subject to the "Classpath" exception as provided
403.12 + * by Sun in the LICENSE file that accompanied this code.
403.13 + *
403.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
403.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
403.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
403.17 + * version 2 for more details (a copy is included in the LICENSE file that
403.18 + * accompanied this code).
403.19 + *
403.20 + * You should have received a copy of the GNU General Public License version
403.21 + * 2 along with this work; if not, write to the Free Software Foundation,
403.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
403.23 + *
403.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
403.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
403.26 + * have any questions.
403.27 + */
403.28 +
403.29 +/* @test
403.30 + @summary Test SoftChannel noteOn method */
403.31 +
403.32 +import javax.sound.midi.*;
403.33 +import javax.sound.sampled.*;
403.34 +
403.35 +import com.sun.media.sound.*;
403.36 +
403.37 +public class NoteOn {
403.38 +
403.39 + private static void assertEquals(Object a, Object b) throws Exception
403.40 + {
403.41 + if(!a.equals(b))
403.42 + throw new RuntimeException("assertEquals fails!");
403.43 + }
403.44 +
403.45 + private static void assertTrue(boolean value) throws Exception
403.46 + {
403.47 + if(!value)
403.48 + throw new RuntimeException("assertTrue fails!");
403.49 + }
403.50 +
403.51 + public static void main(String[] args) throws Exception {
403.52 + SoftTestUtils soft = new SoftTestUtils();
403.53 + MidiChannel channel = soft.synth.getChannels()[0];
403.54 +
403.55 + channel.noteOn(60, 64);
403.56 + soft.read(1);
403.57 + VoiceStatus[] v = soft.synth.getVoiceStatus();
403.58 + assertEquals(v[0].note, 60);
403.59 + assertEquals(v[0].active, true);
403.60 + channel.noteOn(60, 0);
403.61 + soft.read(1);
403.62 + v = soft.synth.getVoiceStatus();
403.63 + assertEquals(v[0].active, false);
403.64 +
403.65 + soft.close();
403.66 + }
403.67 +}
404.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
404.2 +++ b/test/javax/sound/midi/Gervill/SoftChannel/Omni.java Tue Feb 03 22:02:55 2009 -0800
404.3 @@ -0,0 +1,61 @@
404.4 +/*
404.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
404.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
404.7 + *
404.8 + * This code is free software; you can redistribute it and/or modify it
404.9 + * under the terms of the GNU General Public License version 2 only, as
404.10 + * published by the Free Software Foundation. Sun designates this
404.11 + * particular file as subject to the "Classpath" exception as provided
404.12 + * by Sun in the LICENSE file that accompanied this code.
404.13 + *
404.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
404.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
404.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
404.17 + * version 2 for more details (a copy is included in the LICENSE file that
404.18 + * accompanied this code).
404.19 + *
404.20 + * You should have received a copy of the GNU General Public License version
404.21 + * 2 along with this work; if not, write to the Free Software Foundation,
404.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
404.23 + *
404.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
404.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
404.26 + * have any questions.
404.27 + */
404.28 +
404.29 +/* @test
404.30 + @summary Test SoftChannel omni method */
404.31 +
404.32 +import javax.sound.midi.*;
404.33 +import javax.sound.sampled.*;
404.34 +
404.35 +import com.sun.media.sound.*;
404.36 +
404.37 +public class Omni {
404.38 +
404.39 + private static void assertEquals(Object a, Object b) throws Exception
404.40 + {
404.41 + if(!a.equals(b))
404.42 + throw new RuntimeException("assertEquals fails!");
404.43 + }
404.44 +
404.45 + private static void assertTrue(boolean value) throws Exception
404.46 + {
404.47 + if(!value)
404.48 + throw new RuntimeException("assertTrue fails!");
404.49 + }
404.50 +
404.51 + public static void main(String[] args) throws Exception {
404.52 + SoftTestUtils soft = new SoftTestUtils();
404.53 + MidiChannel channel = soft.synth.getChannels()[0];
404.54 +
404.55 + channel.setOmni(true);
404.56 + // Poly or Omni not supported by GM2
404.57 + // getOmni() should always return false
404.58 + assertEquals(channel.getOmni(), false);
404.59 + channel.setOmni(false);
404.60 + assertEquals(channel.getOmni(), false);
404.61 +
404.62 + soft.close();
404.63 + }
404.64 +}
405.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
405.2 +++ b/test/javax/sound/midi/Gervill/SoftChannel/PitchBend.java Tue Feb 03 22:02:55 2009 -0800
405.3 @@ -0,0 +1,59 @@
405.4 +/*
405.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
405.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
405.7 + *
405.8 + * This code is free software; you can redistribute it and/or modify it
405.9 + * under the terms of the GNU General Public License version 2 only, as
405.10 + * published by the Free Software Foundation. Sun designates this
405.11 + * particular file as subject to the "Classpath" exception as provided
405.12 + * by Sun in the LICENSE file that accompanied this code.
405.13 + *
405.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
405.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
405.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
405.17 + * version 2 for more details (a copy is included in the LICENSE file that
405.18 + * accompanied this code).
405.19 + *
405.20 + * You should have received a copy of the GNU General Public License version
405.21 + * 2 along with this work; if not, write to the Free Software Foundation,
405.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
405.23 + *
405.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
405.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
405.26 + * have any questions.
405.27 + */
405.28 +
405.29 +/* @test
405.30 + @summary Test SoftChannel pitchBend method */
405.31 +
405.32 +import javax.sound.midi.*;
405.33 +import javax.sound.sampled.*;
405.34 +
405.35 +import com.sun.media.sound.*;
405.36 +
405.37 +public class PitchBend {
405.38 +
405.39 + private static void assertEquals(Object a, Object b) throws Exception
405.40 + {
405.41 + if(!a.equals(b))
405.42 + throw new RuntimeException("assertEquals fails!");
405.43 + }
405.44 +
405.45 + private static void assertTrue(boolean value) throws Exception
405.46 + {
405.47 + if(!value)
405.48 + throw new RuntimeException("assertTrue fails!");
405.49 + }
405.50 +
405.51 + public static void main(String[] args) throws Exception {
405.52 + SoftTestUtils soft = new SoftTestUtils();
405.53 + MidiChannel channel = soft.synth.getChannels()[0];
405.54 +
405.55 + channel.setPitchBend(10);
405.56 + assertEquals(channel.getPitchBend(), 10);
405.57 + channel.setPitchBend(9000);
405.58 + assertEquals(channel.getPitchBend(), 9000);
405.59 +
405.60 + soft.close();
405.61 + }
405.62 +}
406.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
406.2 +++ b/test/javax/sound/midi/Gervill/SoftChannel/PolyPressure.java Tue Feb 03 22:02:55 2009 -0800
406.3 @@ -0,0 +1,61 @@
406.4 +/*
406.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
406.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
406.7 + *
406.8 + * This code is free software; you can redistribute it and/or modify it
406.9 + * under the terms of the GNU General Public License version 2 only, as
406.10 + * published by the Free Software Foundation. Sun designates this
406.11 + * particular file as subject to the "Classpath" exception as provided
406.12 + * by Sun in the LICENSE file that accompanied this code.
406.13 + *
406.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
406.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
406.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
406.17 + * version 2 for more details (a copy is included in the LICENSE file that
406.18 + * accompanied this code).
406.19 + *
406.20 + * You should have received a copy of the GNU General Public License version
406.21 + * 2 along with this work; if not, write to the Free Software Foundation,
406.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
406.23 + *
406.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
406.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
406.26 + * have any questions.
406.27 + */
406.28 +
406.29 +/* @test
406.30 + @summary Test SoftChannel polyPressure method */
406.31 +
406.32 +import javax.sound.midi.*;
406.33 +import javax.sound.sampled.*;
406.34 +
406.35 +import com.sun.media.sound.*;
406.36 +
406.37 +public class PolyPressure {
406.38 +
406.39 + private static void assertEquals(Object a, Object b) throws Exception
406.40 + {
406.41 + if(!a.equals(b))
406.42 + throw new RuntimeException("assertEquals fails!");
406.43 + }
406.44 +
406.45 + private static void assertTrue(boolean value) throws Exception
406.46 + {
406.47 + if(!value)
406.48 + throw new RuntimeException("assertTrue fails!");
406.49 + }
406.50 +
406.51 + public static void main(String[] args) throws Exception {
406.52 + SoftTestUtils soft = new SoftTestUtils();
406.53 + MidiChannel channel = soft.synth.getChannels()[0];
406.54 +
406.55 + for (int i = 0; i < 128; i++) {
406.56 + channel.setPolyPressure(i, 10);
406.57 + assertEquals(channel.getPolyPressure(i),10);
406.58 + channel.setPolyPressure(i, 100);
406.59 + assertEquals(channel.getPolyPressure(i),100);
406.60 + }
406.61 +
406.62 + soft.close();
406.63 + }
406.64 +}
407.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
407.2 +++ b/test/javax/sound/midi/Gervill/SoftChannel/ProgramChange.java Tue Feb 03 22:02:55 2009 -0800
407.3 @@ -0,0 +1,59 @@
407.4 +/*
407.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
407.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
407.7 + *
407.8 + * This code is free software; you can redistribute it and/or modify it
407.9 + * under the terms of the GNU General Public License version 2 only, as
407.10 + * published by the Free Software Foundation. Sun designates this
407.11 + * particular file as subject to the "Classpath" exception as provided
407.12 + * by Sun in the LICENSE file that accompanied this code.
407.13 + *
407.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
407.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
407.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
407.17 + * version 2 for more details (a copy is included in the LICENSE file that
407.18 + * accompanied this code).
407.19 + *
407.20 + * You should have received a copy of the GNU General Public License version
407.21 + * 2 along with this work; if not, write to the Free Software Foundation,
407.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
407.23 + *
407.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
407.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
407.26 + * have any questions.
407.27 + */
407.28 +
407.29 +/* @test
407.30 + @summary Test SoftChannel programChange method */
407.31 +
407.32 +import javax.sound.midi.*;
407.33 +import javax.sound.sampled.*;
407.34 +
407.35 +import com.sun.media.sound.*;
407.36 +
407.37 +public class ProgramChange {
407.38 +
407.39 + private static void assertEquals(Object a, Object b) throws Exception
407.40 + {
407.41 + if(!a.equals(b))
407.42 + throw new RuntimeException("assertEquals fails!");
407.43 + }
407.44 +
407.45 + private static void assertTrue(boolean value) throws Exception
407.46 + {
407.47 + if(!value)
407.48 + throw new RuntimeException("assertTrue fails!");
407.49 + }
407.50 +
407.51 + public static void main(String[] args) throws Exception {
407.52 + SoftTestUtils soft = new SoftTestUtils();
407.53 + MidiChannel channel = soft.synth.getChannels()[0];
407.54 +
407.55 + channel.programChange(36);
407.56 + assertEquals(channel.getProgram(), 36);
407.57 + channel.programChange(48);
407.58 + assertEquals(channel.getProgram(), 48);
407.59 +
407.60 + soft.close();
407.61 + }
407.62 +}
408.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
408.2 +++ b/test/javax/sound/midi/Gervill/SoftChannel/ResetAllControllers.java Tue Feb 03 22:02:55 2009 -0800
408.3 @@ -0,0 +1,132 @@
408.4 +/*
408.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
408.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
408.7 + *
408.8 + * This code is free software; you can redistribute it and/or modify it
408.9 + * under the terms of the GNU General Public License version 2 only, as
408.10 + * published by the Free Software Foundation. Sun designates this
408.11 + * particular file as subject to the "Classpath" exception as provided
408.12 + * by Sun in the LICENSE file that accompanied this code.
408.13 + *
408.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
408.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
408.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
408.17 + * version 2 for more details (a copy is included in the LICENSE file that
408.18 + * accompanied this code).
408.19 + *
408.20 + * You should have received a copy of the GNU General Public License version
408.21 + * 2 along with this work; if not, write to the Free Software Foundation,
408.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
408.23 + *
408.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
408.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
408.26 + * have any questions.
408.27 + */
408.28 +
408.29 +/* @test
408.30 + @summary Test SoftChannel resetAllControllers method */
408.31 +
408.32 +import javax.sound.midi.*;
408.33 +import javax.sound.sampled.*;
408.34 +
408.35 +import com.sun.media.sound.*;
408.36 +
408.37 +public class ResetAllControllers {
408.38 +
408.39 + public static boolean[] dontResetControls = new boolean[128];
408.40 + static {
408.41 + for (int i = 0; i < dontResetControls.length; i++)
408.42 + dontResetControls[i] = false;
408.43 +
408.44 + dontResetControls[0] = true; // Bank Select (MSB)
408.45 + dontResetControls[32] = true; // Bank Select (LSB)
408.46 + dontResetControls[7] = true; // Channel Volume (MSB)
408.47 + dontResetControls[8] = true; // Balance (MSB)
408.48 + dontResetControls[10] = true; // Pan (MSB)
408.49 + dontResetControls[11] = true; // Expression (MSB)
408.50 + dontResetControls[91] = true; // Effects 1 Depth (default: Reverb Send)
408.51 + dontResetControls[92] = true; // Effects 2 Depth (default: Tremolo Depth)
408.52 + dontResetControls[93] = true; // Effects 3 Depth (default: Chorus Send)
408.53 + dontResetControls[94] = true; // Effects 4 Depth (default: Celeste [Detune] Depth)
408.54 + dontResetControls[95] = true; // Effects 5 Depth (default: Phaser Depth)
408.55 + dontResetControls[70] = true; // Sound Controller 1 (default: Sound Variation)
408.56 + dontResetControls[71] = true; // Sound Controller 2 (default: Timbre / Harmonic Quality)
408.57 + dontResetControls[72] = true; // Sound Controller 3 (default: Release Time)
408.58 + dontResetControls[73] = true; // Sound Controller 4 (default: Attack Time)
408.59 + dontResetControls[74] = true; // Sound Controller 5 (default: Brightness)
408.60 + dontResetControls[75] = true; // Sound Controller 6 (GM2 default: Decay Time)
408.61 + dontResetControls[76] = true; // Sound Controller 7 (GM2 default: Vibrato Rate)
408.62 + dontResetControls[77] = true; // Sound Controller 8 (GM2 default: Vibrato Depth)
408.63 + dontResetControls[78] = true; // Sound Controller 9 (GM2 default: Vibrato Delay)
408.64 + dontResetControls[79] = true; // Sound Controller 10 (GM2 default: Undefined)
408.65 + dontResetControls[120] = true; // All Sound Off
408.66 + dontResetControls[121] = true; // Reset All Controllers
408.67 + dontResetControls[122] = true; // Local Control On/Off
408.68 + dontResetControls[123] = true; // All Notes Off
408.69 + dontResetControls[124] = true; // Omni Mode Off
408.70 + dontResetControls[125] = true; // Omni Mode On
408.71 + dontResetControls[126] = true; // Poly Mode Off
408.72 + dontResetControls[127] = true; // Poly Mode On
408.73 +
408.74 + dontResetControls[6] = true; // Data Entry (MSB)
408.75 + dontResetControls[38] = true; // Data Entry (LSB)
408.76 + dontResetControls[96] = true; // Data Increment
408.77 + dontResetControls[97] = true; // Data Decrement
408.78 + dontResetControls[98] = true; // Non-Registered Parameter Number (LSB)
408.79 + dontResetControls[99] = true; // Non-Registered Parameter Number(MSB)
408.80 + dontResetControls[100] = true; // RPN = Null
408.81 + dontResetControls[101] = true; // RPN = Null
408.82 + }
408.83 +
408.84 + private static void assertEquals(Object a, Object b) throws Exception
408.85 + {
408.86 + if(!a.equals(b))
408.87 + throw new RuntimeException("assertEquals fails!");
408.88 + }
408.89 +
408.90 + private static void assertTrue(boolean value) throws Exception
408.91 + {
408.92 + if(!value)
408.93 + throw new RuntimeException("assertTrue fails!");
408.94 + }
408.95 +
408.96 + public static void main(String[] args) throws Exception {
408.97 + SoftTestUtils soft = new SoftTestUtils();
408.98 + MidiChannel channel = soft.synth.getChannels()[0];
408.99 +
408.100 + // First let all controls contain non-default values
408.101 + for (int i = 0; i < 128; i++)
408.102 + channel.setPolyPressure(i, 10);
408.103 + channel.setChannelPressure(10);
408.104 + channel.setPitchBend(2192);
408.105 + for (int i = 0; i < 120; i++)
408.106 + channel.controlChange(i, 1);
408.107 + channel.resetAllControllers();
408.108 +
408.109 + // Now check if resetAllControllers did what it was suppose to do
408.110 +
408.111 + for (int i = 0; i < 128; i++)
408.112 + assertEquals(channel.getPolyPressure(i), 0);
408.113 + assertEquals(channel.getChannelPressure(), 0);
408.114 + assertEquals(channel.getPitchBend(),8192);
408.115 + for (int i = 0; i < 120; i++)
408.116 + if(!dontResetControls[i])
408.117 + assertEquals(channel.getController(i), 0);
408.118 + assertEquals(channel.getController(71), 64); // Filter Resonance
408.119 + assertEquals(channel.getController(72), 64); // Release Time
408.120 + assertEquals(channel.getController(73), 64); // Attack Time
408.121 + assertEquals(channel.getController(74), 64); // Brightness
408.122 + assertEquals(channel.getController(75), 64); // Decay Time
408.123 + assertEquals(channel.getController(76), 64); // Vibrato Rate
408.124 + assertEquals(channel.getController(77), 64); // Vibrato Depth
408.125 + assertEquals(channel.getController(78), 64); // Vibrato Delay
408.126 + assertEquals(channel.getController(8), 64); // Balance
408.127 + assertEquals(channel.getController(11), 127); // Expression
408.128 + assertEquals(channel.getController(98), 127); // NRPN Null
408.129 + assertEquals(channel.getController(99), 127); // NRPN Null
408.130 + assertEquals(channel.getController(100), 127); // RPN = Null
408.131 + assertEquals(channel.getController(101), 127); // RPN = Null
408.132 +
408.133 + soft.close();
408.134 + }
408.135 +}
409.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
409.2 +++ b/test/javax/sound/midi/Gervill/SoftChannel/SoftTestUtils.java Tue Feb 03 22:02:55 2009 -0800
409.3 @@ -0,0 +1,111 @@
409.4 +/*
409.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
409.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
409.7 + *
409.8 + * This code is free software; you can redistribute it and/or modify it
409.9 + * under the terms of the GNU General Public License version 2 only, as
409.10 + * published by the Free Software Foundation. Sun designates this
409.11 + * particular file as subject to the "Classpath" exception as provided
409.12 + * by Sun in the LICENSE file that accompanied this code.
409.13 + *
409.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
409.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
409.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
409.17 + * version 2 for more details (a copy is included in the LICENSE file that
409.18 + * accompanied this code).
409.19 + *
409.20 + * You should have received a copy of the GNU General Public License version
409.21 + * 2 along with this work; if not, write to the Free Software Foundation,
409.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
409.23 + *
409.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
409.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
409.26 + * have any questions.
409.27 + */
409.28 +
409.29 +import java.io.IOException;
409.30 +
409.31 +import javax.sound.midi.*;
409.32 +import javax.sound.sampled.*;
409.33 +
409.34 +import com.sun.media.sound.*;
409.35 +
409.36 +public class SoftTestUtils {
409.37 +
409.38 + public AudioSynthesizer synth = new SoftSynthesizer();
409.39 + public AudioInputStream stream;
409.40 + public byte[] tmpbuffer = new byte[1024];
409.41 +
409.42 + public static SF2Soundbank createTestSoundBank()
409.43 + {
409.44 + SF2Soundbank sf2 = new SF2Soundbank();
409.45 + AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
409.46 + float[] data = new float[44100+1000];
409.47 + float fr = 440/format.getSampleRate();
409.48 + for (int i = 0; i < data.length; i++)
409.49 + data[i] = (float)Math.sin(i*fr*2*Math.PI);
409.50 + byte[] bdata = new byte[data.length*format.getFrameSize()];
409.51 + AudioFloatConverter.getConverter(format).toByteArray(data, bdata);
409.52 + SF2Sample sample = new SF2Sample(sf2);
409.53 + sample.setName("Test Sample");
409.54 + sample.setData(bdata);
409.55 + sample.setStartLoop(500);
409.56 + sample.setEndLoop(data.length - 500);
409.57 + sample.setSampleRate((long) format.getSampleRate());
409.58 + sample.setOriginalPitch(69);
409.59 + sf2.addResource(sample);
409.60 + SF2Layer layer = new SF2Layer(sf2);
409.61 + layer.setName("Test Layer");
409.62 + sf2.addResource(layer);
409.63 + SF2LayerRegion region = new SF2LayerRegion();
409.64 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
409.65 + region.setSample(sample);
409.66 + layer.getRegions().add(region);
409.67 + SF2Instrument ins = new SF2Instrument(sf2);
409.68 + ins.setName("Test Instrument");
409.69 + sf2.addInstrument(ins);
409.70 + SF2InstrumentRegion insregion = new SF2InstrumentRegion();
409.71 + insregion.setLayer(layer);
409.72 + ins.getRegions().add(insregion);
409.73 +
409.74 + return sf2;
409.75 + }
409.76 +
409.77 + public SoftTestUtils() throws Exception {
409.78 + stream = synth.openStream(null, null);
409.79 + synth.unloadAllInstruments(synth.getDefaultSoundbank());
409.80 + synth.loadAllInstruments(createTestSoundBank());
409.81 + }
409.82 +
409.83 + public void close() throws Exception {
409.84 + stream.close();
409.85 + stream = null;
409.86 + synth.close();
409.87 + synth = null;
409.88 + }
409.89 +
409.90 + public void read(double seconds) throws IOException
409.91 + {
409.92 + int bufflen =
409.93 + stream.getFormat().getFrameSize() *
409.94 + (int)(stream.getFormat().getFrameRate() * seconds);
409.95 + while(bufflen != 0)
409.96 + {
409.97 + if(bufflen > 1024)
409.98 + bufflen -= stream.read(tmpbuffer,0,1024);
409.99 + else
409.100 + bufflen -= stream.read(tmpbuffer,0, bufflen);
409.101 + }
409.102 + }
409.103 +
409.104 + public VoiceStatus findVoice(int channel, int note) {
409.105 + VoiceStatus[] v = synth.getVoiceStatus();
409.106 + for (int k = 0; k < v.length; k++)
409.107 + if(v[k].active)
409.108 + if(v[k].channel == channel)
409.109 + if(v[k].note == note)
409.110 + return v[k];
409.111 + return null;
409.112 + }
409.113 +
409.114 +}
410.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
410.2 +++ b/test/javax/sound/midi/Gervill/SoftChannel/Solo.java Tue Feb 03 22:02:55 2009 -0800
410.3 @@ -0,0 +1,59 @@
410.4 +/*
410.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
410.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
410.7 + *
410.8 + * This code is free software; you can redistribute it and/or modify it
410.9 + * under the terms of the GNU General Public License version 2 only, as
410.10 + * published by the Free Software Foundation. Sun designates this
410.11 + * particular file as subject to the "Classpath" exception as provided
410.12 + * by Sun in the LICENSE file that accompanied this code.
410.13 + *
410.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
410.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
410.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
410.17 + * version 2 for more details (a copy is included in the LICENSE file that
410.18 + * accompanied this code).
410.19 + *
410.20 + * You should have received a copy of the GNU General Public License version
410.21 + * 2 along with this work; if not, write to the Free Software Foundation,
410.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
410.23 + *
410.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
410.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
410.26 + * have any questions.
410.27 + */
410.28 +
410.29 +/* @test
410.30 + @summary Test SoftChannel solo method */
410.31 +
410.32 +import javax.sound.midi.*;
410.33 +import javax.sound.sampled.*;
410.34 +
410.35 +import com.sun.media.sound.*;
410.36 +
410.37 +public class Solo {
410.38 +
410.39 + private static void assertEquals(Object a, Object b) throws Exception
410.40 + {
410.41 + if(!a.equals(b))
410.42 + throw new RuntimeException("assertEquals fails!");
410.43 + }
410.44 +
410.45 + private static void assertTrue(boolean value) throws Exception
410.46 + {
410.47 + if(!value)
410.48 + throw new RuntimeException("assertTrue fails!");
410.49 + }
410.50 +
410.51 + public static void main(String[] args) throws Exception {
410.52 + SoftTestUtils soft = new SoftTestUtils();
410.53 + MidiChannel channel = soft.synth.getChannels()[0];
410.54 +
410.55 + channel.setSolo(true);
410.56 + assertEquals(channel.getSolo(), true);
410.57 + channel.setSolo(false);
410.58 + assertEquals(channel.getSolo(), false);
410.59 +
410.60 + soft.close();
410.61 + }
410.62 +}
411.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
411.2 +++ b/test/javax/sound/midi/Gervill/SoftCubicResampler/Interpolate.java Tue Feb 03 22:02:55 2009 -0800
411.3 @@ -0,0 +1,113 @@
411.4 +/*
411.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
411.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
411.7 + *
411.8 + * This code is free software; you can redistribute it and/or modify it
411.9 + * under the terms of the GNU General Public License version 2 only, as
411.10 + * published by the Free Software Foundation. Sun designates this
411.11 + * particular file as subject to the "Classpath" exception as provided
411.12 + * by Sun in the LICENSE file that accompanied this code.
411.13 + *
411.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
411.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
411.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
411.17 + * version 2 for more details (a copy is included in the LICENSE file that
411.18 + * accompanied this code).
411.19 + *
411.20 + * You should have received a copy of the GNU General Public License version
411.21 + * 2 along with this work; if not, write to the Free Software Foundation,
411.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
411.23 + *
411.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
411.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
411.26 + * have any questions.
411.27 + */
411.28 +
411.29 +/* @test
411.30 + @summary Test SoftCubicResampler interpolate method */
411.31 +
411.32 +import java.io.File;
411.33 +import java.io.FileOutputStream;
411.34 +import java.io.IOException;
411.35 +
411.36 +import javax.sound.sampled.*;
411.37 +
411.38 +import com.sun.media.sound.*;
411.39 +
411.40 +public class Interpolate {
411.41 +
411.42 + private static float getResamplerTestValue(double i)
411.43 + {
411.44 + return (float)Math.sin(i / 10.0);
411.45 + }
411.46 +
411.47 + private static void perfectInterpolation(float[] in_offset, float in_end,
411.48 + float[] startpitch, float pitchstep, float[] out, int[] out_offset,
411.49 + int out_end) {
411.50 +
411.51 + float pitch = startpitch[0];
411.52 + float ix = in_offset[0];
411.53 + int ox = out_offset[0];
411.54 + float ix_end = in_end;
411.55 + int ox_end = out_end;
411.56 + if (pitchstep == 0f) {
411.57 + while (ix < ix_end && ox < ox_end) {
411.58 + out[ox++] = getResamplerTestValue(ix);
411.59 + ix += pitch;
411.60 + }
411.61 + } else {
411.62 + while (ix < ix_end && ox < ox_end) {
411.63 + out[ox++] = getResamplerTestValue(ix);
411.64 + ix += pitch;
411.65 + pitch += pitchstep;
411.66 + }
411.67 + }
411.68 + in_offset[0] = ix;
411.69 + out_offset[0] = ox;
411.70 + startpitch[0] = pitch;
411.71 +
411.72 + }
411.73 +
411.74 + private static float testResampler(SoftAbstractResampler resampler, float p_pitch, float p_pitch2)
411.75 + {
411.76 + float[] testbuffer = new float[4096];
411.77 + float[] testbuffer2 = new float[1024];
411.78 + float[] testbuffer3 = new float[1024];
411.79 + for (int i = 0; i < testbuffer.length; i++)
411.80 + testbuffer[i] = getResamplerTestValue(i);
411.81 + int pads = resampler.getPadding();
411.82 + float pitchstep = (p_pitch2 - p_pitch)/1024f;
411.83 + int[] out_offset2 = {0};
411.84 + int[] out_offset3 = {0};
411.85 + resampler.interpolate(testbuffer, new float[] {pads}, testbuffer.length - pads, new float[] {p_pitch}, pitchstep, testbuffer2, out_offset2, testbuffer2.length);
411.86 + perfectInterpolation(new float[] {pads}, testbuffer.length - pads, new float[] {p_pitch}, pitchstep, testbuffer3, out_offset3, testbuffer3.length);
411.87 + int out_off = out_offset2[0];
411.88 + if(out_offset3[0] < out_off)
411.89 + out_off = out_offset3[0];
411.90 + float ac_error = 0;
411.91 + int counter = 0;
411.92 + for (int i = pads; i < out_off; i++) {
411.93 + ac_error += Math.abs(testbuffer2[i] - testbuffer3[i]);
411.94 + counter++;
411.95 + }
411.96 + return ac_error / ((float)counter);
411.97 + }
411.98 +
411.99 + private static void fail(String error) throws Exception
411.100 + {
411.101 + throw new RuntimeException(error);
411.102 + }
411.103 +
411.104 + public static void main(String[] args) throws Exception {
411.105 + SoftCubicResampler resampler = new SoftCubicResampler();
411.106 + float max = testResampler(resampler, 0.3f, 0.3f);
411.107 + if(max > 0.005)
411.108 + fail("Interpolation failed, error="+max);
411.109 + max = testResampler(resampler, 0.3f, 0.01f);
411.110 + if(max > 0.005)
411.111 + fail("Interpolation failed, error="+max);
411.112 + max = testResampler(resampler, 1.0f, 0.00f);
411.113 + if(max > 0.005)
411.114 + fail("Interpolation failed, error="+max);
411.115 + }
411.116 +}
412.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
412.2 +++ b/test/javax/sound/midi/Gervill/SoftLanczosResampler/Interpolate.java Tue Feb 03 22:02:55 2009 -0800
412.3 @@ -0,0 +1,113 @@
412.4 +/*
412.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
412.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
412.7 + *
412.8 + * This code is free software; you can redistribute it and/or modify it
412.9 + * under the terms of the GNU General Public License version 2 only, as
412.10 + * published by the Free Software Foundation. Sun designates this
412.11 + * particular file as subject to the "Classpath" exception as provided
412.12 + * by Sun in the LICENSE file that accompanied this code.
412.13 + *
412.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
412.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
412.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
412.17 + * version 2 for more details (a copy is included in the LICENSE file that
412.18 + * accompanied this code).
412.19 + *
412.20 + * You should have received a copy of the GNU General Public License version
412.21 + * 2 along with this work; if not, write to the Free Software Foundation,
412.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
412.23 + *
412.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
412.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
412.26 + * have any questions.
412.27 + */
412.28 +
412.29 +/* @test
412.30 + @summary Test SoftLanczosResampler interpolate method */
412.31 +
412.32 +import java.io.File;
412.33 +import java.io.FileOutputStream;
412.34 +import java.io.IOException;
412.35 +
412.36 +import javax.sound.sampled.*;
412.37 +
412.38 +import com.sun.media.sound.*;
412.39 +
412.40 +public class Interpolate {
412.41 +
412.42 + private static float getResamplerTestValue(double i)
412.43 + {
412.44 + return (float)Math.sin(i / 10.0);
412.45 + }
412.46 +
412.47 + private static void perfectInterpolation(float[] in_offset, float in_end,
412.48 + float[] startpitch, float pitchstep, float[] out, int[] out_offset,
412.49 + int out_end) {
412.50 +
412.51 + float pitch = startpitch[0];
412.52 + float ix = in_offset[0];
412.53 + int ox = out_offset[0];
412.54 + float ix_end = in_end;
412.55 + int ox_end = out_end;
412.56 + if (pitchstep == 0f) {
412.57 + while (ix < ix_end && ox < ox_end) {
412.58 + out[ox++] = getResamplerTestValue(ix);
412.59 + ix += pitch;
412.60 + }
412.61 + } else {
412.62 + while (ix < ix_end && ox < ox_end) {
412.63 + out[ox++] = getResamplerTestValue(ix);
412.64 + ix += pitch;
412.65 + pitch += pitchstep;
412.66 + }
412.67 + }
412.68 + in_offset[0] = ix;
412.69 + out_offset[0] = ox;
412.70 + startpitch[0] = pitch;
412.71 +
412.72 + }
412.73 +
412.74 + private static float testResampler(SoftAbstractResampler resampler, float p_pitch, float p_pitch2)
412.75 + {
412.76 + float[] testbuffer = new float[4096];
412.77 + float[] testbuffer2 = new float[1024];
412.78 + float[] testbuffer3 = new float[1024];
412.79 + for (int i = 0; i < testbuffer.length; i++)
412.80 + testbuffer[i] = getResamplerTestValue(i);
412.81 + int pads = resampler.getPadding();
412.82 + float pitchstep = (p_pitch2 - p_pitch)/1024f;
412.83 + int[] out_offset2 = {0};
412.84 + int[] out_offset3 = {0};
412.85 + resampler.interpolate(testbuffer, new float[] {pads}, testbuffer.length - pads, new float[] {p_pitch}, pitchstep, testbuffer2, out_offset2, testbuffer2.length);
412.86 + perfectInterpolation(new float[] {pads}, testbuffer.length - pads, new float[] {p_pitch}, pitchstep, testbuffer3, out_offset3, testbuffer3.length);
412.87 + int out_off = out_offset2[0];
412.88 + if(out_offset3[0] < out_off)
412.89 + out_off = out_offset3[0];
412.90 + float ac_error = 0;
412.91 + int counter = 0;
412.92 + for (int i = pads; i < out_off; i++) {
412.93 + ac_error += Math.abs(testbuffer2[i] - testbuffer3[i]);
412.94 + counter++;
412.95 + }
412.96 + return ac_error / ((float)counter);
412.97 + }
412.98 +
412.99 + private static void fail(String error) throws Exception
412.100 + {
412.101 + throw new RuntimeException(error);
412.102 + }
412.103 +
412.104 + public static void main(String[] args) throws Exception {
412.105 + SoftLanczosResampler resampler = new SoftLanczosResampler();
412.106 + float max = testResampler(resampler, 0.3f, 0.3f);
412.107 + if(max > 0.01)
412.108 + fail("Interpolation failed, error="+max);
412.109 + max = testResampler(resampler, 0.3f, 0.01f);
412.110 + if(max > 0.01)
412.111 + fail("Interpolation failed, error="+max);
412.112 + max = testResampler(resampler, 1.0f, 0.00f);
412.113 + if(max > 0.01)
412.114 + fail("Interpolation failed, error="+max);
412.115 + }
412.116 +}
412.117 \ No newline at end of file
413.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
413.2 +++ b/test/javax/sound/midi/Gervill/SoftLimiter/ProcessAudio_replace_mix.java Tue Feb 03 22:02:55 2009 -0800
413.3 @@ -0,0 +1,96 @@
413.4 +/*
413.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
413.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
413.7 + *
413.8 + * This code is free software; you can redistribute it and/or modify it
413.9 + * under the terms of the GNU General Public License version 2 only, as
413.10 + * published by the Free Software Foundation. Sun designates this
413.11 + * particular file as subject to the "Classpath" exception as provided
413.12 + * by Sun in the LICENSE file that accompanied this code.
413.13 + *
413.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
413.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
413.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
413.17 + * version 2 for more details (a copy is included in the LICENSE file that
413.18 + * accompanied this code).
413.19 + *
413.20 + * You should have received a copy of the GNU General Public License version
413.21 + * 2 along with this work; if not, write to the Free Software Foundation,
413.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
413.23 + *
413.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
413.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
413.26 + * have any questions.
413.27 + */
413.28 +
413.29 +/* @test
413.30 + @summary Test SoftLimiter processAudio method */
413.31 +
413.32 +import javax.sound.midi.MidiUnavailableException;
413.33 +import javax.sound.midi.Patch;
413.34 +import javax.sound.sampled.*;
413.35 +
413.36 +import com.sun.media.sound.*;
413.37 +
413.38 +public class ProcessAudio_replace_mix {
413.39 +
413.40 + private static void assertEquals(Object a, Object b) throws Exception
413.41 + {
413.42 + if(!a.equals(b))
413.43 + throw new RuntimeException("assertEquals fails!");
413.44 + }
413.45 +
413.46 + private static void assertTrue(boolean value) throws Exception
413.47 + {
413.48 + if(!value)
413.49 + throw new RuntimeException("assertTrue fails!");
413.50 + }
413.51 +
413.52 + public static void main(String[] args) throws Exception {
413.53 + SoftSynthesizer synth = new SoftSynthesizer();
413.54 + synth.openStream(null, null);
413.55 +
413.56 + SoftAudioBuffer in1 = new SoftAudioBuffer(250, synth.getFormat());
413.57 + SoftAudioBuffer in2 = new SoftAudioBuffer(250, synth.getFormat());
413.58 + SoftAudioBuffer out1 = new SoftAudioBuffer(250, synth.getFormat());
413.59 + SoftAudioBuffer out2 = new SoftAudioBuffer(250, synth.getFormat());
413.60 +
413.61 + float[] testdata1 = new float[in1.getSize()];
413.62 + float[] testdata2 = new float[in2.getSize()];
413.63 + float[] n1a = in1.array();
413.64 + float[] n2a = in2.array();
413.65 + float[] out1a = out1.array();
413.66 + float[] out2a = out2.array();
413.67 + for (int i = 0; i < n1a.length; i++) {
413.68 + testdata1[i] = (float)Math.sin(i*0.3)*0.9f;
413.69 + testdata2[i] = (float)Math.sin(i*0.4)*0.9f;
413.70 + n1a[i] = testdata1[i];
413.71 + n2a[i] = testdata2[i];
413.72 + out1a[i] = 1;
413.73 + out2a[i] = 1;
413.74 + }
413.75 +
413.76 + SoftLimiter limiter = new SoftLimiter();
413.77 + limiter.init(44100, 147);
413.78 + limiter.setMixMode(true);
413.79 + limiter.setInput(0, in1);
413.80 + limiter.setInput(1, in2);
413.81 + limiter.setOutput(0, out1);
413.82 + limiter.setOutput(1, out2);
413.83 + limiter.processControlLogic();
413.84 + limiter.processAudio();
413.85 + limiter.processControlLogic();
413.86 + limiter.processAudio();
413.87 + // Limiter should delay audio by one buffer,
413.88 + // and there should almost no different in output v.s. input
413.89 + for (int i = 0; i < n1a.length; i++) {
413.90 + if(Math.abs(out1a[i] - testdata1[i] - 1) > 0.00001)
413.91 + throw new Exception("input != output");
413.92 + if(Math.abs(out2a[i] - testdata2[i] - 1) > 0.00001)
413.93 + throw new Exception("input != output");
413.94 + }
413.95 +
413.96 + synth.close();
413.97 +
413.98 + }
413.99 +}
414.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
414.2 +++ b/test/javax/sound/midi/Gervill/SoftLimiter/ProcessAudio_replace_mix_mono.java Tue Feb 03 22:02:55 2009 -0800
414.3 @@ -0,0 +1,83 @@
414.4 +/*
414.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
414.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
414.7 + *
414.8 + * This code is free software; you can redistribute it and/or modify it
414.9 + * under the terms of the GNU General Public License version 2 only, as
414.10 + * published by the Free Software Foundation. Sun designates this
414.11 + * particular file as subject to the "Classpath" exception as provided
414.12 + * by Sun in the LICENSE file that accompanied this code.
414.13 + *
414.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
414.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
414.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
414.17 + * version 2 for more details (a copy is included in the LICENSE file that
414.18 + * accompanied this code).
414.19 + *
414.20 + * You should have received a copy of the GNU General Public License version
414.21 + * 2 along with this work; if not, write to the Free Software Foundation,
414.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
414.23 + *
414.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
414.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
414.26 + * have any questions.
414.27 + */
414.28 +
414.29 +/* @test
414.30 + @summary Test SoftLimiter processAudio method */
414.31 +
414.32 +import javax.sound.midi.MidiUnavailableException;
414.33 +import javax.sound.midi.Patch;
414.34 +import javax.sound.sampled.*;
414.35 +
414.36 +import com.sun.media.sound.*;
414.37 +
414.38 +public class ProcessAudio_replace_mix_mono {
414.39 +
414.40 + private static void assertEquals(Object a, Object b) throws Exception
414.41 + {
414.42 + if(!a.equals(b))
414.43 + throw new RuntimeException("assertEquals fails!");
414.44 + }
414.45 +
414.46 + private static void assertTrue(boolean value) throws Exception
414.47 + {
414.48 + if(!value)
414.49 + throw new RuntimeException("assertTrue fails!");
414.50 + }
414.51 +
414.52 + public static void main(String[] args) throws Exception {
414.53 + SoftSynthesizer synth = new SoftSynthesizer();
414.54 + synth.openStream(new AudioFormat(44100, 16, 1, true, false), null);
414.55 +
414.56 + SoftAudioBuffer in1 = new SoftAudioBuffer(250, synth.getFormat());
414.57 + SoftAudioBuffer out1 = new SoftAudioBuffer(250, synth.getFormat());
414.58 +
414.59 + float[] testdata1 = new float[in1.getSize()];
414.60 + float[] n1a = in1.array();
414.61 + float[] out1a = out1.array();
414.62 + for (int i = 0; i < n1a.length; i++) {
414.63 + testdata1[i] = (float)Math.sin(i*0.3)*0.9f;
414.64 + n1a[i] = testdata1[i];
414.65 + out1a[i] = 1;
414.66 + }
414.67 +
414.68 + SoftLimiter limiter = new SoftLimiter();
414.69 + limiter.init(44100, 147);
414.70 + limiter.setMixMode(true);
414.71 + limiter.setInput(0, in1);
414.72 + limiter.setOutput(0, out1);
414.73 + limiter.processControlLogic();
414.74 + limiter.processAudio();
414.75 + limiter.processControlLogic();
414.76 + limiter.processAudio();
414.77 + // Limiter should delay audio by one buffer,
414.78 + // and there should almost no different in output v.s. input
414.79 + for (int i = 0; i < n1a.length; i++) {
414.80 + if(Math.abs(out1a[i] - testdata1[i] - 1) > 0.00001)
414.81 + throw new Exception("input != output");
414.82 + }
414.83 +
414.84 + synth.close();
414.85 + }
414.86 +}
415.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
415.2 +++ b/test/javax/sound/midi/Gervill/SoftLimiter/ProcessAudio_replace_mix_mono_overdrive.java Tue Feb 03 22:02:55 2009 -0800
415.3 @@ -0,0 +1,84 @@
415.4 +/*
415.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
415.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
415.7 + *
415.8 + * This code is free software; you can redistribute it and/or modify it
415.9 + * under the terms of the GNU General Public License version 2 only, as
415.10 + * published by the Free Software Foundation. Sun designates this
415.11 + * particular file as subject to the "Classpath" exception as provided
415.12 + * by Sun in the LICENSE file that accompanied this code.
415.13 + *
415.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
415.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
415.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
415.17 + * version 2 for more details (a copy is included in the LICENSE file that
415.18 + * accompanied this code).
415.19 + *
415.20 + * You should have received a copy of the GNU General Public License version
415.21 + * 2 along with this work; if not, write to the Free Software Foundation,
415.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
415.23 + *
415.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
415.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
415.26 + * have any questions.
415.27 + */
415.28 +
415.29 +/* @test
415.30 + @summary Test SoftLimiter processAudio method */
415.31 +
415.32 +
415.33 +import javax.sound.midi.MidiUnavailableException;
415.34 +import javax.sound.midi.Patch;
415.35 +import javax.sound.sampled.*;
415.36 +
415.37 +import com.sun.media.sound.*;
415.38 +
415.39 +public class ProcessAudio_replace_mix_mono_overdrive {
415.40 +
415.41 + private static void assertEquals(Object a, Object b) throws Exception
415.42 + {
415.43 + if(!a.equals(b))
415.44 + throw new RuntimeException("assertEquals fails!");
415.45 + }
415.46 +
415.47 + private static void assertTrue(boolean value) throws Exception
415.48 + {
415.49 + if(!value)
415.50 + throw new RuntimeException("assertTrue fails!");
415.51 + }
415.52 +
415.53 + public static void main(String[] args) throws Exception {
415.54 + SoftSynthesizer synth = new SoftSynthesizer();
415.55 + synth.openStream(new AudioFormat(44100, 16, 1, true, false), null);
415.56 +
415.57 + SoftAudioBuffer in1 = new SoftAudioBuffer(250, synth.getFormat());
415.58 + SoftAudioBuffer out1 = new SoftAudioBuffer(250, synth.getFormat());
415.59 +
415.60 + float[] testdata1 = new float[in1.getSize()];
415.61 + float[] n1a = in1.array();
415.62 + float[] out1a = out1.array();
415.63 + for (int i = 0; i < n1a.length; i++) {
415.64 + testdata1[i] = (float)Math.sin(i*0.3)*2.5f;
415.65 + n1a[i] = testdata1[i];
415.66 + out1a[i] = 1;
415.67 + }
415.68 +
415.69 + SoftLimiter limiter = new SoftLimiter();
415.70 + limiter.init(44100, 147);
415.71 + limiter.setMixMode(true);
415.72 + limiter.setInput(0, in1);
415.73 + limiter.setOutput(0, out1);
415.74 + limiter.processControlLogic();
415.75 + limiter.processAudio();
415.76 + limiter.processControlLogic();
415.77 + limiter.processAudio();
415.78 + // Limiter should delay audio by one buffer,
415.79 + // and there should almost no different in output v.s. input
415.80 + for (int i = 0; i < n1a.length; i++) {
415.81 + if(Math.abs(out1a[i]-1) > 1.0)
415.82 + throw new Exception("abs(output)>1");
415.83 + }
415.84 +
415.85 + synth.close();
415.86 + }
415.87 +}
416.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
416.2 +++ b/test/javax/sound/midi/Gervill/SoftLimiter/ProcessAudio_replace_mix_overdrive.java Tue Feb 03 22:02:55 2009 -0800
416.3 @@ -0,0 +1,95 @@
416.4 +/*
416.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
416.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
416.7 + *
416.8 + * This code is free software; you can redistribute it and/or modify it
416.9 + * under the terms of the GNU General Public License version 2 only, as
416.10 + * published by the Free Software Foundation. Sun designates this
416.11 + * particular file as subject to the "Classpath" exception as provided
416.12 + * by Sun in the LICENSE file that accompanied this code.
416.13 + *
416.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
416.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
416.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
416.17 + * version 2 for more details (a copy is included in the LICENSE file that
416.18 + * accompanied this code).
416.19 + *
416.20 + * You should have received a copy of the GNU General Public License version
416.21 + * 2 along with this work; if not, write to the Free Software Foundation,
416.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
416.23 + *
416.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
416.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
416.26 + * have any questions.
416.27 + */
416.28 +
416.29 +/* @test
416.30 + @summary Test SoftLimiter processAudio method */
416.31 +
416.32 +import javax.sound.midi.MidiUnavailableException;
416.33 +import javax.sound.midi.Patch;
416.34 +import javax.sound.sampled.*;
416.35 +
416.36 +import com.sun.media.sound.*;
416.37 +
416.38 +public class ProcessAudio_replace_mix_overdrive {
416.39 +
416.40 + private static void assertEquals(Object a, Object b) throws Exception
416.41 + {
416.42 + if(!a.equals(b))
416.43 + throw new RuntimeException("assertEquals fails!");
416.44 + }
416.45 +
416.46 + private static void assertTrue(boolean value) throws Exception
416.47 + {
416.48 + if(!value)
416.49 + throw new RuntimeException("assertTrue fails!");
416.50 + }
416.51 +
416.52 + public static void main(String[] args) throws Exception {
416.53 + SoftSynthesizer synth = new SoftSynthesizer();
416.54 + synth.openStream(null, null);
416.55 +
416.56 + SoftAudioBuffer in1 = new SoftAudioBuffer(250, synth.getFormat());
416.57 + SoftAudioBuffer in2 = new SoftAudioBuffer(250, synth.getFormat());
416.58 + SoftAudioBuffer out1 = new SoftAudioBuffer(250, synth.getFormat());
416.59 + SoftAudioBuffer out2 = new SoftAudioBuffer(250, synth.getFormat());
416.60 +
416.61 + float[] testdata1 = new float[in1.getSize()];
416.62 + float[] testdata2 = new float[in2.getSize()];
416.63 + float[] n1a = in1.array();
416.64 + float[] n2a = in2.array();
416.65 + float[] out1a = out1.array();
416.66 + float[] out2a = out2.array();
416.67 + for (int i = 0; i < n1a.length; i++) {
416.68 + testdata1[i] = (float)Math.sin(i*0.3)*2.5f;
416.69 + testdata2[i] = (float)Math.sin(i*0.4)*2.5f;
416.70 + n1a[i] = testdata1[i];
416.71 + n2a[i] = testdata2[i];
416.72 + out1a[i] = 1;
416.73 + out2a[i] = 1;
416.74 + }
416.75 +
416.76 + SoftLimiter limiter = new SoftLimiter();
416.77 + limiter.init(44100, 147);
416.78 + limiter.setMixMode(true);
416.79 + limiter.setInput(0, in1);
416.80 + limiter.setInput(1, in2);
416.81 + limiter.setOutput(0, out1);
416.82 + limiter.setOutput(1, out2);
416.83 + limiter.processControlLogic();
416.84 + limiter.processAudio();
416.85 + limiter.processControlLogic();
416.86 + limiter.processAudio();
416.87 + // Limiter should delay audio by one buffer,
416.88 + // and there should almost no different in output v.s. input
416.89 + for (int i = 0; i < n1a.length; i++) {
416.90 + if(Math.abs(out1a[i]-1) > 1.0)
416.91 + throw new Exception("abs(output)>1");
416.92 + if(Math.abs(out2a[i]-1) > 1.0)
416.93 + throw new Exception("abs(output)>1");
416.94 + }
416.95 +
416.96 + synth.close();
416.97 + }
416.98 +}
417.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
417.2 +++ b/test/javax/sound/midi/Gervill/SoftLimiter/ProcessAudio_replace_normal.java Tue Feb 03 22:02:55 2009 -0800
417.3 @@ -0,0 +1,95 @@
417.4 +/*
417.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
417.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
417.7 + *
417.8 + * This code is free software; you can redistribute it and/or modify it
417.9 + * under the terms of the GNU General Public License version 2 only, as
417.10 + * published by the Free Software Foundation. Sun designates this
417.11 + * particular file as subject to the "Classpath" exception as provided
417.12 + * by Sun in the LICENSE file that accompanied this code.
417.13 + *
417.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
417.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
417.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
417.17 + * version 2 for more details (a copy is included in the LICENSE file that
417.18 + * accompanied this code).
417.19 + *
417.20 + * You should have received a copy of the GNU General Public License version
417.21 + * 2 along with this work; if not, write to the Free Software Foundation,
417.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
417.23 + *
417.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
417.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
417.26 + * have any questions.
417.27 + */
417.28 +
417.29 +/* @test
417.30 + @summary Test SoftLimiter processAudio method */
417.31 +
417.32 +import javax.sound.midi.MidiUnavailableException;
417.33 +import javax.sound.midi.Patch;
417.34 +import javax.sound.sampled.*;
417.35 +
417.36 +import com.sun.media.sound.*;
417.37 +
417.38 +public class ProcessAudio_replace_normal {
417.39 +
417.40 + private static void assertEquals(Object a, Object b) throws Exception
417.41 + {
417.42 + if(!a.equals(b))
417.43 + throw new RuntimeException("assertEquals fails!");
417.44 + }
417.45 +
417.46 + private static void assertTrue(boolean value) throws Exception
417.47 + {
417.48 + if(!value)
417.49 + throw new RuntimeException("assertTrue fails!");
417.50 + }
417.51 +
417.52 + public static void main(String[] args) throws Exception {
417.53 + SoftSynthesizer synth = new SoftSynthesizer();
417.54 + synth.openStream(null, null);
417.55 +
417.56 + SoftAudioBuffer in1 = new SoftAudioBuffer(250, synth.getFormat());
417.57 + SoftAudioBuffer in2 = new SoftAudioBuffer(250, synth.getFormat());
417.58 + SoftAudioBuffer out1 = new SoftAudioBuffer(250, synth.getFormat());
417.59 + SoftAudioBuffer out2 = new SoftAudioBuffer(250, synth.getFormat());
417.60 +
417.61 + float[] testdata1 = new float[in1.getSize()];
417.62 + float[] testdata2 = new float[in2.getSize()];
417.63 + float[] n1a = in1.array();
417.64 + float[] n2a = in2.array();
417.65 + float[] out1a = out1.array();
417.66 + float[] out2a = out2.array();
417.67 + for (int i = 0; i < n1a.length; i++) {
417.68 + testdata1[i] = (float)Math.sin(i*0.3)*0.9f;
417.69 + testdata2[i] = (float)Math.sin(i*0.4)*0.9f;
417.70 + n1a[i] = testdata1[i];
417.71 + n2a[i] = testdata2[i];
417.72 + out1a[i] = 1;
417.73 + out2a[i] = 1;
417.74 + }
417.75 +
417.76 + SoftLimiter limiter = new SoftLimiter();
417.77 + limiter.init(44100, 147);
417.78 + limiter.setMixMode(false);
417.79 + limiter.setInput(0, in1);
417.80 + limiter.setInput(1, in2);
417.81 + limiter.setOutput(0, out1);
417.82 + limiter.setOutput(1, out2);
417.83 + limiter.processControlLogic();
417.84 + limiter.processAudio();
417.85 + limiter.processControlLogic();
417.86 + limiter.processAudio();
417.87 + // Limiter should delay audio by one buffer,
417.88 + // and there should almost no different in output v.s. input
417.89 + for (int i = 0; i < n1a.length; i++) {
417.90 + if(Math.abs(out1a[i] - testdata1[i]) > 0.00001)
417.91 + throw new Exception("input != output");
417.92 + if(Math.abs(out2a[i] - testdata2[i]) > 0.00001)
417.93 + throw new Exception("input != output");
417.94 + }
417.95 +
417.96 + synth.close();
417.97 + }
417.98 +}
418.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
418.2 +++ b/test/javax/sound/midi/Gervill/SoftLimiter/ProcessAudio_replace_normal_mono.java Tue Feb 03 22:02:55 2009 -0800
418.3 @@ -0,0 +1,83 @@
418.4 +/*
418.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
418.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
418.7 + *
418.8 + * This code is free software; you can redistribute it and/or modify it
418.9 + * under the terms of the GNU General Public License version 2 only, as
418.10 + * published by the Free Software Foundation. Sun designates this
418.11 + * particular file as subject to the "Classpath" exception as provided
418.12 + * by Sun in the LICENSE file that accompanied this code.
418.13 + *
418.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
418.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
418.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
418.17 + * version 2 for more details (a copy is included in the LICENSE file that
418.18 + * accompanied this code).
418.19 + *
418.20 + * You should have received a copy of the GNU General Public License version
418.21 + * 2 along with this work; if not, write to the Free Software Foundation,
418.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
418.23 + *
418.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
418.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
418.26 + * have any questions.
418.27 + */
418.28 +
418.29 +/* @test
418.30 + @summary Test SoftLimiter processAudio method */
418.31 +
418.32 +import javax.sound.midi.MidiUnavailableException;
418.33 +import javax.sound.midi.Patch;
418.34 +import javax.sound.sampled.*;
418.35 +
418.36 +import com.sun.media.sound.*;
418.37 +
418.38 +public class ProcessAudio_replace_normal_mono {
418.39 +
418.40 + private static void assertEquals(Object a, Object b) throws Exception
418.41 + {
418.42 + if(!a.equals(b))
418.43 + throw new RuntimeException("assertEquals fails!");
418.44 + }
418.45 +
418.46 + private static void assertTrue(boolean value) throws Exception
418.47 + {
418.48 + if(!value)
418.49 + throw new RuntimeException("assertTrue fails!");
418.50 + }
418.51 +
418.52 + public static void main(String[] args) throws Exception {
418.53 + SoftSynthesizer synth = new SoftSynthesizer();
418.54 + synth.openStream(new AudioFormat(44100, 16, 1, true, false), null);
418.55 +
418.56 + SoftAudioBuffer in1 = new SoftAudioBuffer(250, synth.getFormat());
418.57 + SoftAudioBuffer out1 = new SoftAudioBuffer(250, synth.getFormat());
418.58 +
418.59 + float[] testdata1 = new float[in1.getSize()];
418.60 + float[] n1a = in1.array();
418.61 + float[] out1a = out1.array();
418.62 + for (int i = 0; i < n1a.length; i++) {
418.63 + testdata1[i] = (float)Math.sin(i*0.3)*0.9f;
418.64 + n1a[i] = testdata1[i];
418.65 + out1a[i] = 1;
418.66 + }
418.67 +
418.68 + SoftLimiter limiter = new SoftLimiter();
418.69 + limiter.init(44100, 147);
418.70 + limiter.setMixMode(false);
418.71 + limiter.setInput(0, in1);
418.72 + limiter.setOutput(0, out1);
418.73 + limiter.processControlLogic();
418.74 + limiter.processAudio();
418.75 + limiter.processControlLogic();
418.76 + limiter.processAudio();
418.77 + // Limiter should delay audio by one buffer,
418.78 + // and there should almost no different in output v.s. input
418.79 + for (int i = 0; i < n1a.length; i++) {
418.80 + if(Math.abs(out1a[i] - testdata1[i]) > 0.00001)
418.81 + throw new Exception("input != output");
418.82 + }
418.83 +
418.84 + synth.close();
418.85 + }
418.86 +}
419.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
419.2 +++ b/test/javax/sound/midi/Gervill/SoftLimiter/ProcessAudio_replace_overdrive.java Tue Feb 03 22:02:55 2009 -0800
419.3 @@ -0,0 +1,95 @@
419.4 +/*
419.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
419.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
419.7 + *
419.8 + * This code is free software; you can redistribute it and/or modify it
419.9 + * under the terms of the GNU General Public License version 2 only, as
419.10 + * published by the Free Software Foundation. Sun designates this
419.11 + * particular file as subject to the "Classpath" exception as provided
419.12 + * by Sun in the LICENSE file that accompanied this code.
419.13 + *
419.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
419.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
419.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
419.17 + * version 2 for more details (a copy is included in the LICENSE file that
419.18 + * accompanied this code).
419.19 + *
419.20 + * You should have received a copy of the GNU General Public License version
419.21 + * 2 along with this work; if not, write to the Free Software Foundation,
419.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
419.23 + *
419.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
419.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
419.26 + * have any questions.
419.27 + */
419.28 +
419.29 +/* @test
419.30 + @summary Test SoftLimiter processAudio method */
419.31 +
419.32 +import javax.sound.midi.MidiUnavailableException;
419.33 +import javax.sound.midi.Patch;
419.34 +import javax.sound.sampled.*;
419.35 +
419.36 +import com.sun.media.sound.*;
419.37 +
419.38 +public class ProcessAudio_replace_overdrive {
419.39 +
419.40 + private static void assertEquals(Object a, Object b) throws Exception
419.41 + {
419.42 + if(!a.equals(b))
419.43 + throw new RuntimeException("assertEquals fails!");
419.44 + }
419.45 +
419.46 + private static void assertTrue(boolean value) throws Exception
419.47 + {
419.48 + if(!value)
419.49 + throw new RuntimeException("assertTrue fails!");
419.50 + }
419.51 +
419.52 + public static void main(String[] args) throws Exception {
419.53 + SoftSynthesizer synth = new SoftSynthesizer();
419.54 + synth.openStream(null, null);
419.55 +
419.56 + SoftAudioBuffer in1 = new SoftAudioBuffer(250, synth.getFormat());
419.57 + SoftAudioBuffer in2 = new SoftAudioBuffer(250, synth.getFormat());
419.58 + SoftAudioBuffer out1 = new SoftAudioBuffer(250, synth.getFormat());
419.59 + SoftAudioBuffer out2 = new SoftAudioBuffer(250, synth.getFormat());
419.60 +
419.61 + float[] testdata1 = new float[in1.getSize()];
419.62 + float[] testdata2 = new float[in2.getSize()];
419.63 + float[] n1a = in1.array();
419.64 + float[] n2a = in2.array();
419.65 + float[] out1a = out1.array();
419.66 + float[] out2a = out2.array();
419.67 + for (int i = 0; i < n1a.length; i++) {
419.68 + testdata1[i] = (float)Math.sin(i*0.3)*2.5f;
419.69 + testdata2[i] = (float)Math.sin(i*0.4)*2.5f;
419.70 + n1a[i] = testdata1[i];
419.71 + n2a[i] = testdata2[i];
419.72 + out1a[i] = 1;
419.73 + out2a[i] = 1;
419.74 + }
419.75 +
419.76 + SoftLimiter limiter = new SoftLimiter();
419.77 + limiter.init(44100, 147);
419.78 + limiter.setMixMode(false);
419.79 + limiter.setInput(0, in1);
419.80 + limiter.setInput(1, in2);
419.81 + limiter.setOutput(0, out1);
419.82 + limiter.setOutput(1, out2);
419.83 + limiter.processControlLogic();
419.84 + limiter.processAudio();
419.85 + limiter.processControlLogic();
419.86 + limiter.processAudio();
419.87 + // Limiter should delay audio by one buffer,
419.88 + // and there should almost no different in output v.s. input
419.89 + for (int i = 0; i < n1a.length; i++) {
419.90 + if(Math.abs(out1a[i]) > 1.0)
419.91 + throw new Exception("abs(output)>1");
419.92 + if(Math.abs(out2a[i]) > 1.0)
419.93 + throw new Exception("abs(output)>1");
419.94 + }
419.95 +
419.96 + synth.close();
419.97 + }
419.98 +}
420.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
420.2 +++ b/test/javax/sound/midi/Gervill/SoftLimiter/ProcessAudio_replace_overdrive_mono.java Tue Feb 03 22:02:55 2009 -0800
420.3 @@ -0,0 +1,83 @@
420.4 +/*
420.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
420.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
420.7 + *
420.8 + * This code is free software; you can redistribute it and/or modify it
420.9 + * under the terms of the GNU General Public License version 2 only, as
420.10 + * published by the Free Software Foundation. Sun designates this
420.11 + * particular file as subject to the "Classpath" exception as provided
420.12 + * by Sun in the LICENSE file that accompanied this code.
420.13 + *
420.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
420.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
420.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
420.17 + * version 2 for more details (a copy is included in the LICENSE file that
420.18 + * accompanied this code).
420.19 + *
420.20 + * You should have received a copy of the GNU General Public License version
420.21 + * 2 along with this work; if not, write to the Free Software Foundation,
420.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
420.23 + *
420.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
420.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
420.26 + * have any questions.
420.27 + */
420.28 +
420.29 +/* @test
420.30 + @summary Test SoftLimiter processAudio method */
420.31 +
420.32 +import javax.sound.midi.MidiUnavailableException;
420.33 +import javax.sound.midi.Patch;
420.34 +import javax.sound.sampled.*;
420.35 +
420.36 +import com.sun.media.sound.*;
420.37 +
420.38 +public class ProcessAudio_replace_overdrive_mono {
420.39 +
420.40 + private static void assertEquals(Object a, Object b) throws Exception
420.41 + {
420.42 + if(!a.equals(b))
420.43 + throw new RuntimeException("assertEquals fails!");
420.44 + }
420.45 +
420.46 + private static void assertTrue(boolean value) throws Exception
420.47 + {
420.48 + if(!value)
420.49 + throw new RuntimeException("assertTrue fails!");
420.50 + }
420.51 +
420.52 + public static void main(String[] args) throws Exception {
420.53 + SoftSynthesizer synth = new SoftSynthesizer();
420.54 + synth.openStream(new AudioFormat(44100, 16, 1, true, false), null);
420.55 +
420.56 + SoftAudioBuffer in1 = new SoftAudioBuffer(250, synth.getFormat());
420.57 + SoftAudioBuffer out1 = new SoftAudioBuffer(250, synth.getFormat());
420.58 +
420.59 + float[] testdata1 = new float[in1.getSize()];
420.60 + float[] n1a = in1.array();
420.61 + float[] out1a = out1.array();
420.62 + for (int i = 0; i < n1a.length; i++) {
420.63 + testdata1[i] = (float)Math.sin(i*0.3)*2.5f;
420.64 + n1a[i] = testdata1[i];
420.65 + out1a[i] = 1;
420.66 + }
420.67 +
420.68 + SoftLimiter limiter = new SoftLimiter();
420.69 + limiter.init(44100, 147);
420.70 + limiter.setMixMode(false);
420.71 + limiter.setInput(0, in1);
420.72 + limiter.setOutput(0, out1);
420.73 + limiter.processControlLogic();
420.74 + limiter.processAudio();
420.75 + limiter.processControlLogic();
420.76 + limiter.processAudio();
420.77 + // Limiter should delay audio by one buffer,
420.78 + // and there should almost no different in output v.s. input
420.79 + for (int i = 0; i < n1a.length; i++) {
420.80 + if(Math.abs(out1a[i]) > 1.0)
420.81 + throw new Exception("abs(output)>1");
420.82 + }
420.83 +
420.84 + synth.close();
420.85 + }
420.86 +}
421.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
421.2 +++ b/test/javax/sound/midi/Gervill/SoftLinearResampler/Interpolate.java Tue Feb 03 22:02:55 2009 -0800
421.3 @@ -0,0 +1,113 @@
421.4 +/*
421.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
421.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
421.7 + *
421.8 + * This code is free software; you can redistribute it and/or modify it
421.9 + * under the terms of the GNU General Public License version 2 only, as
421.10 + * published by the Free Software Foundation. Sun designates this
421.11 + * particular file as subject to the "Classpath" exception as provided
421.12 + * by Sun in the LICENSE file that accompanied this code.
421.13 + *
421.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
421.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
421.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
421.17 + * version 2 for more details (a copy is included in the LICENSE file that
421.18 + * accompanied this code).
421.19 + *
421.20 + * You should have received a copy of the GNU General Public License version
421.21 + * 2 along with this work; if not, write to the Free Software Foundation,
421.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
421.23 + *
421.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
421.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
421.26 + * have any questions.
421.27 + */
421.28 +
421.29 +/* @test
421.30 + @summary Test SoftLinearResampler interpolate method */
421.31 +
421.32 +import java.io.File;
421.33 +import java.io.FileOutputStream;
421.34 +import java.io.IOException;
421.35 +
421.36 +import javax.sound.sampled.*;
421.37 +
421.38 +import com.sun.media.sound.*;
421.39 +
421.40 +public class Interpolate {
421.41 +
421.42 + private static float getResamplerTestValue(double i)
421.43 + {
421.44 + return (float)Math.sin(i / 10.0);
421.45 + }
421.46 +
421.47 + private static void perfectInterpolation(float[] in_offset, float in_end,
421.48 + float[] startpitch, float pitchstep, float[] out, int[] out_offset,
421.49 + int out_end) {
421.50 +
421.51 + float pitch = startpitch[0];
421.52 + float ix = in_offset[0];
421.53 + int ox = out_offset[0];
421.54 + float ix_end = in_end;
421.55 + int ox_end = out_end;
421.56 + if (pitchstep == 0f) {
421.57 + while (ix < ix_end && ox < ox_end) {
421.58 + out[ox++] = getResamplerTestValue(ix);
421.59 + ix += pitch;
421.60 + }
421.61 + } else {
421.62 + while (ix < ix_end && ox < ox_end) {
421.63 + out[ox++] = getResamplerTestValue(ix);
421.64 + ix += pitch;
421.65 + pitch += pitchstep;
421.66 + }
421.67 + }
421.68 + in_offset[0] = ix;
421.69 + out_offset[0] = ox;
421.70 + startpitch[0] = pitch;
421.71 +
421.72 + }
421.73 +
421.74 + private static float testResampler(SoftAbstractResampler resampler, float p_pitch, float p_pitch2)
421.75 + {
421.76 + float[] testbuffer = new float[4096];
421.77 + float[] testbuffer2 = new float[1024];
421.78 + float[] testbuffer3 = new float[1024];
421.79 + for (int i = 0; i < testbuffer.length; i++)
421.80 + testbuffer[i] = getResamplerTestValue(i);
421.81 + int pads = resampler.getPadding();
421.82 + float pitchstep = (p_pitch2 - p_pitch)/1024f;
421.83 + int[] out_offset2 = {0};
421.84 + int[] out_offset3 = {0};
421.85 + resampler.interpolate(testbuffer, new float[] {pads}, testbuffer.length - pads, new float[] {p_pitch}, pitchstep, testbuffer2, out_offset2, testbuffer2.length);
421.86 + perfectInterpolation(new float[] {pads}, testbuffer.length - pads, new float[] {p_pitch}, pitchstep, testbuffer3, out_offset3, testbuffer3.length);
421.87 + int out_off = out_offset2[0];
421.88 + if(out_offset3[0] < out_off)
421.89 + out_off = out_offset3[0];
421.90 + float ac_error = 0;
421.91 + int counter = 0;
421.92 + for (int i = pads; i < out_off; i++) {
421.93 + ac_error += Math.abs(testbuffer2[i] - testbuffer3[i]);
421.94 + counter++;
421.95 + }
421.96 + return ac_error / ((float)counter);
421.97 + }
421.98 +
421.99 + private static void fail(String error) throws Exception
421.100 + {
421.101 + throw new RuntimeException(error);
421.102 + }
421.103 +
421.104 + public static void main(String[] args) throws Exception {
421.105 + SoftLinearResampler resampler = new SoftLinearResampler();
421.106 + float max = testResampler(resampler, 0.3f, 0.3f);
421.107 + if(max > 0.001)
421.108 + fail("Interpolation failed, error="+max);
421.109 + max = testResampler(resampler, 0.3f, 0.01f);
421.110 + if(max > 0.001)
421.111 + fail("Interpolation failed, error="+max);
421.112 + max = testResampler(resampler, 1.0f, 0.00f);
421.113 + if(max > 0.001)
421.114 + fail("Interpolation failed, error="+max);
421.115 + }
421.116 +}
421.117 \ No newline at end of file
422.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
422.2 +++ b/test/javax/sound/midi/Gervill/SoftLinearResampler2/Interpolate.java Tue Feb 03 22:02:55 2009 -0800
422.3 @@ -0,0 +1,113 @@
422.4 +/*
422.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
422.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
422.7 + *
422.8 + * This code is free software; you can redistribute it and/or modify it
422.9 + * under the terms of the GNU General Public License version 2 only, as
422.10 + * published by the Free Software Foundation. Sun designates this
422.11 + * particular file as subject to the "Classpath" exception as provided
422.12 + * by Sun in the LICENSE file that accompanied this code.
422.13 + *
422.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
422.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
422.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
422.17 + * version 2 for more details (a copy is included in the LICENSE file that
422.18 + * accompanied this code).
422.19 + *
422.20 + * You should have received a copy of the GNU General Public License version
422.21 + * 2 along with this work; if not, write to the Free Software Foundation,
422.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
422.23 + *
422.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
422.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
422.26 + * have any questions.
422.27 + */
422.28 +
422.29 +/* @test
422.30 + @summary Test SoftLinearResampler2 interpolate method */
422.31 +
422.32 +import java.io.File;
422.33 +import java.io.FileOutputStream;
422.34 +import java.io.IOException;
422.35 +
422.36 +import javax.sound.sampled.*;
422.37 +
422.38 +import com.sun.media.sound.*;
422.39 +
422.40 +public class Interpolate {
422.41 +
422.42 + private static float getResamplerTestValue(double i)
422.43 + {
422.44 + return (float)Math.sin(i / 10.0);
422.45 + }
422.46 +
422.47 + private static void perfectInterpolation(float[] in_offset, float in_end,
422.48 + float[] startpitch, float pitchstep, float[] out, int[] out_offset,
422.49 + int out_end) {
422.50 +
422.51 + float pitch = startpitch[0];
422.52 + float ix = in_offset[0];
422.53 + int ox = out_offset[0];
422.54 + float ix_end = in_end;
422.55 + int ox_end = out_end;
422.56 + if (pitchstep == 0f) {
422.57 + while (ix < ix_end && ox < ox_end) {
422.58 + out[ox++] = getResamplerTestValue(ix);
422.59 + ix += pitch;
422.60 + }
422.61 + } else {
422.62 + while (ix < ix_end && ox < ox_end) {
422.63 + out[ox++] = getResamplerTestValue(ix);
422.64 + ix += pitch;
422.65 + pitch += pitchstep;
422.66 + }
422.67 + }
422.68 + in_offset[0] = ix;
422.69 + out_offset[0] = ox;
422.70 + startpitch[0] = pitch;
422.71 +
422.72 + }
422.73 +
422.74 + private static float testResampler(SoftAbstractResampler resampler, float p_pitch, float p_pitch2)
422.75 + {
422.76 + float[] testbuffer = new float[4096];
422.77 + float[] testbuffer2 = new float[1024];
422.78 + float[] testbuffer3 = new float[1024];
422.79 + for (int i = 0; i < testbuffer.length; i++)
422.80 + testbuffer[i] = getResamplerTestValue(i);
422.81 + int pads = resampler.getPadding();
422.82 + float pitchstep = (p_pitch2 - p_pitch)/1024f;
422.83 + int[] out_offset2 = {0};
422.84 + int[] out_offset3 = {0};
422.85 + resampler.interpolate(testbuffer, new float[] {pads}, testbuffer.length - pads, new float[] {p_pitch}, pitchstep, testbuffer2, out_offset2, testbuffer2.length);
422.86 + perfectInterpolation(new float[] {pads}, testbuffer.length - pads, new float[] {p_pitch}, pitchstep, testbuffer3, out_offset3, testbuffer3.length);
422.87 + int out_off = out_offset2[0];
422.88 + if(out_offset3[0] < out_off)
422.89 + out_off = out_offset3[0];
422.90 + float ac_error = 0;
422.91 + int counter = 0;
422.92 + for (int i = pads; i < out_off; i++) {
422.93 + ac_error += Math.abs(testbuffer2[i] - testbuffer3[i]);
422.94 + counter++;
422.95 + }
422.96 + return ac_error / ((float)counter);
422.97 + }
422.98 +
422.99 + private static void fail(String error) throws Exception
422.100 + {
422.101 + throw new RuntimeException(error);
422.102 + }
422.103 +
422.104 + public static void main(String[] args) throws Exception {
422.105 + SoftLinearResampler2 resampler = new SoftLinearResampler2();
422.106 + float max = testResampler(resampler, 0.3f, 0.3f);
422.107 + if(max > 0.2)
422.108 + fail("Interpolation failed, error="+max);
422.109 + max = testResampler(resampler, 0.3f, 0.01f);
422.110 + if(max > 0.2)
422.111 + fail("Interpolation failed, error="+max);
422.112 + max = testResampler(resampler, 1.0f, 0.00f);
422.113 + if(max > 0.2)
422.114 + fail("Interpolation failed, error="+max);
422.115 + }
422.116 +}
422.117 \ No newline at end of file
423.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
423.2 +++ b/test/javax/sound/midi/Gervill/SoftPointResampler/Interpolate.java Tue Feb 03 22:02:55 2009 -0800
423.3 @@ -0,0 +1,113 @@
423.4 +/*
423.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
423.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
423.7 + *
423.8 + * This code is free software; you can redistribute it and/or modify it
423.9 + * under the terms of the GNU General Public License version 2 only, as
423.10 + * published by the Free Software Foundation. Sun designates this
423.11 + * particular file as subject to the "Classpath" exception as provided
423.12 + * by Sun in the LICENSE file that accompanied this code.
423.13 + *
423.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
423.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
423.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
423.17 + * version 2 for more details (a copy is included in the LICENSE file that
423.18 + * accompanied this code).
423.19 + *
423.20 + * You should have received a copy of the GNU General Public License version
423.21 + * 2 along with this work; if not, write to the Free Software Foundation,
423.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
423.23 + *
423.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
423.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
423.26 + * have any questions.
423.27 + */
423.28 +
423.29 +/* @test
423.30 + @summary Test SoftPointResampler interpolate method */
423.31 +
423.32 +import java.io.File;
423.33 +import java.io.FileOutputStream;
423.34 +import java.io.IOException;
423.35 +
423.36 +import javax.sound.sampled.*;
423.37 +
423.38 +import com.sun.media.sound.*;
423.39 +
423.40 +public class Interpolate {
423.41 +
423.42 + private static float getResamplerTestValue(double i)
423.43 + {
423.44 + return (float)Math.sin(i / 10.0);
423.45 + }
423.46 +
423.47 + private static void perfectInterpolation(float[] in_offset, float in_end,
423.48 + float[] startpitch, float pitchstep, float[] out, int[] out_offset,
423.49 + int out_end) {
423.50 +
423.51 + float pitch = startpitch[0];
423.52 + float ix = in_offset[0];
423.53 + int ox = out_offset[0];
423.54 + float ix_end = in_end;
423.55 + int ox_end = out_end;
423.56 + if (pitchstep == 0f) {
423.57 + while (ix < ix_end && ox < ox_end) {
423.58 + out[ox++] = getResamplerTestValue(ix);
423.59 + ix += pitch;
423.60 + }
423.61 + } else {
423.62 + while (ix < ix_end && ox < ox_end) {
423.63 + out[ox++] = getResamplerTestValue(ix);
423.64 + ix += pitch;
423.65 + pitch += pitchstep;
423.66 + }
423.67 + }
423.68 + in_offset[0] = ix;
423.69 + out_offset[0] = ox;
423.70 + startpitch[0] = pitch;
423.71 +
423.72 + }
423.73 +
423.74 + private static float testResampler(SoftAbstractResampler resampler, float p_pitch, float p_pitch2)
423.75 + {
423.76 + float[] testbuffer = new float[4096];
423.77 + float[] testbuffer2 = new float[1024];
423.78 + float[] testbuffer3 = new float[1024];
423.79 + for (int i = 0; i < testbuffer.length; i++)
423.80 + testbuffer[i] = getResamplerTestValue(i);
423.81 + int pads = resampler.getPadding();
423.82 + float pitchstep = (p_pitch2 - p_pitch)/1024f;
423.83 + int[] out_offset2 = {0};
423.84 + int[] out_offset3 = {0};
423.85 + resampler.interpolate(testbuffer, new float[] {pads}, testbuffer.length - pads, new float[] {p_pitch}, pitchstep, testbuffer2, out_offset2, testbuffer2.length);
423.86 + perfectInterpolation(new float[] {pads}, testbuffer.length - pads, new float[] {p_pitch}, pitchstep, testbuffer3, out_offset3, testbuffer3.length);
423.87 + int out_off = out_offset2[0];
423.88 + if(out_offset3[0] < out_off)
423.89 + out_off = out_offset3[0];
423.90 + float ac_error = 0;
423.91 + int counter = 0;
423.92 + for (int i = pads; i < out_off; i++) {
423.93 + ac_error += Math.abs(testbuffer2[i] - testbuffer3[i]);
423.94 + counter++;
423.95 + }
423.96 + return ac_error / ((float)counter);
423.97 + }
423.98 +
423.99 + private static void fail(String error) throws Exception
423.100 + {
423.101 + throw new RuntimeException(error);
423.102 + }
423.103 +
423.104 + public static void main(String[] args) throws Exception {
423.105 + SoftPointResampler resampler = new SoftPointResampler();
423.106 + float max = testResampler(resampler, 0.3f, 0.3f);
423.107 + if(max > 0.2)
423.108 + fail("Interpolation failed, error="+max);
423.109 + max = testResampler(resampler, 0.3f, 0.01f);
423.110 + if(max > 0.2)
423.111 + fail("Interpolation failed, error="+max);
423.112 + max = testResampler(resampler, 1.0f, 0.00f);
423.113 + if(max > 0.2)
423.114 + fail("Interpolation failed, error="+max);
423.115 + }
423.116 +}
423.117 \ No newline at end of file
424.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
424.2 +++ b/test/javax/sound/midi/Gervill/SoftProvider/GetDevice.java Tue Feb 03 22:02:55 2009 -0800
424.3 @@ -0,0 +1,70 @@
424.4 +/*
424.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
424.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
424.7 + *
424.8 + * This code is free software; you can redistribute it and/or modify it
424.9 + * under the terms of the GNU General Public License version 2 only, as
424.10 + * published by the Free Software Foundation. Sun designates this
424.11 + * particular file as subject to the "Classpath" exception as provided
424.12 + * by Sun in the LICENSE file that accompanied this code.
424.13 + *
424.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
424.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
424.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
424.17 + * version 2 for more details (a copy is included in the LICENSE file that
424.18 + * accompanied this code).
424.19 + *
424.20 + * You should have received a copy of the GNU General Public License version
424.21 + * 2 along with this work; if not, write to the Free Software Foundation,
424.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
424.23 + *
424.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
424.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
424.26 + * have any questions.
424.27 + */
424.28 +
424.29 +/* @test
424.30 + @summary Test SoftProvider getDevice method */
424.31 +
424.32 +import javax.sound.midi.MidiDevice;
424.33 +import javax.sound.midi.MidiUnavailableException;
424.34 +import javax.sound.midi.Patch;
424.35 +import javax.sound.sampled.*;
424.36 +import javax.sound.midi.MidiDevice.Info;
424.37 +
424.38 +import com.sun.media.sound.*;
424.39 +
424.40 +public class GetDevice {
424.41 +
424.42 + private static void assertEquals(Object a, Object b) throws Exception
424.43 + {
424.44 + if(!a.equals(b))
424.45 + throw new RuntimeException("assertEquals fails!");
424.46 + }
424.47 +
424.48 + private static void assertTrue(boolean value) throws Exception
424.49 + {
424.50 + if(!value)
424.51 + throw new RuntimeException("assertTrue fails!");
424.52 + }
424.53 +
424.54 +
424.55 + private static class FakeInfo extends Info {
424.56 + public FakeInfo() {
424.57 + super("a", "b", "c", "d");
424.58 + }
424.59 + }
424.60 +
424.61 + public static void main(String[] args) throws Exception {
424.62 + SoftProvider provider = new SoftProvider();
424.63 + Info[] infos = provider.getDeviceInfo();
424.64 + assertTrue(infos.length > 0);
424.65 + for (int i = 0; i < infos.length; i++) {
424.66 + assertTrue(infos[i] != null);
424.67 + MidiDevice d = provider.getDevice(infos[i]);
424.68 + assertTrue(d instanceof SoftSynthesizer);
424.69 + }
424.70 + assertTrue(provider.getDevice(new FakeInfo()) == null);
424.71 +
424.72 + }
424.73 +}
425.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
425.2 +++ b/test/javax/sound/midi/Gervill/SoftReceiver/Close.java Tue Feb 03 22:02:55 2009 -0800
425.3 @@ -0,0 +1,59 @@
425.4 +/*
425.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
425.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
425.7 + *
425.8 + * This code is free software; you can redistribute it and/or modify it
425.9 + * under the terms of the GNU General Public License version 2 only, as
425.10 + * published by the Free Software Foundation. Sun designates this
425.11 + * particular file as subject to the "Classpath" exception as provided
425.12 + * by Sun in the LICENSE file that accompanied this code.
425.13 + *
425.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
425.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
425.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
425.17 + * version 2 for more details (a copy is included in the LICENSE file that
425.18 + * accompanied this code).
425.19 + *
425.20 + * You should have received a copy of the GNU General Public License version
425.21 + * 2 along with this work; if not, write to the Free Software Foundation,
425.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
425.23 + *
425.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
425.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
425.26 + * have any questions.
425.27 + */
425.28 +
425.29 +/* @test
425.30 + @summary Test SoftReceiver close method */
425.31 +
425.32 +import javax.sound.midi.*;
425.33 +import javax.sound.sampled.*;
425.34 +
425.35 +import com.sun.media.sound.*;
425.36 +
425.37 +public class Close {
425.38 +
425.39 + private static void assertEquals(Object a, Object b) throws Exception
425.40 + {
425.41 + if(!a.equals(b))
425.42 + throw new RuntimeException("assertEquals fails!");
425.43 + }
425.44 +
425.45 + private static void assertTrue(boolean value) throws Exception
425.46 + {
425.47 + if(!value)
425.48 + throw new RuntimeException("assertTrue fails!");
425.49 + }
425.50 +
425.51 + public static void main(String[] args) throws Exception {
425.52 + SoftTestUtils soft = new SoftTestUtils();
425.53 + MidiChannel channel = soft.synth.getChannels()[0];
425.54 + Receiver receiver = soft.synth.getReceiver();
425.55 +
425.56 + assertEquals(soft.synth.getReceivers().size(), 1);
425.57 + receiver.close();
425.58 + assertEquals(soft.synth.getReceivers().size(), 0);
425.59 +
425.60 + soft.close();
425.61 + }
425.62 +}
426.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
426.2 +++ b/test/javax/sound/midi/Gervill/SoftReceiver/Send_ActiveSense.java Tue Feb 03 22:02:55 2009 -0800
426.3 @@ -0,0 +1,82 @@
426.4 +/*
426.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
426.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
426.7 + *
426.8 + * This code is free software; you can redistribute it and/or modify it
426.9 + * under the terms of the GNU General Public License version 2 only, as
426.10 + * published by the Free Software Foundation. Sun designates this
426.11 + * particular file as subject to the "Classpath" exception as provided
426.12 + * by Sun in the LICENSE file that accompanied this code.
426.13 + *
426.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
426.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
426.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
426.17 + * version 2 for more details (a copy is included in the LICENSE file that
426.18 + * accompanied this code).
426.19 + *
426.20 + * You should have received a copy of the GNU General Public License version
426.21 + * 2 along with this work; if not, write to the Free Software Foundation,
426.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
426.23 + *
426.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
426.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
426.26 + * have any questions.
426.27 + */
426.28 +
426.29 +/* @test
426.30 + @summary Test SoftReceiver send method */
426.31 +
426.32 +import javax.sound.midi.*;
426.33 +import javax.sound.sampled.*;
426.34 +
426.35 +import com.sun.media.sound.*;
426.36 +
426.37 +public class Send_ActiveSense {
426.38 +
426.39 + private static void assertEquals(Object a, Object b) throws Exception
426.40 + {
426.41 + if(!a.equals(b))
426.42 + throw new RuntimeException("assertEquals fails!");
426.43 + }
426.44 +
426.45 + private static void assertTrue(boolean value) throws Exception
426.46 + {
426.47 + if(!value)
426.48 + throw new RuntimeException("assertTrue fails!");
426.49 + }
426.50 +
426.51 + public static void sendActiveSens(Receiver r) throws Exception
426.52 + {
426.53 + ShortMessage smsg = new ShortMessage();
426.54 + smsg.setMessage(ShortMessage.ACTIVE_SENSING);
426.55 + r.send(smsg, -1);
426.56 + }
426.57 +
426.58 + public static void main(String[] args) throws Exception {
426.59 + SoftTestUtils soft = new SoftTestUtils();
426.60 + MidiChannel channel = soft.synth.getChannels()[0];
426.61 + Receiver receiver = soft.synth.getReceiver();
426.62 +
426.63 + sendActiveSens(receiver);
426.64 +
426.65 + // 1. Check if notes are keept active
426.66 + // if send active sens every 200-300 msec
426.67 +
426.68 + sendActiveSens(receiver);
426.69 + channel.noteOn(60, 64);
426.70 + assertTrue(soft.findVoice(0,60) != null);
426.71 + for (int i = 0; i < 10; i++) {
426.72 + soft.read(0.2); // read 200 msec
426.73 + sendActiveSens(receiver);
426.74 + assertTrue(soft.findVoice(0,60) != null);
426.75 + }
426.76 + // 2. Now we stop send active sense message
426.77 + // and the note should be killed off
426.78 + soft.read(2);
426.79 + assertTrue(soft.findVoice(0,60) == null);
426.80 +
426.81 +
426.82 +
426.83 + soft.close();
426.84 + }
426.85 +}
427.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
427.2 +++ b/test/javax/sound/midi/Gervill/SoftReceiver/Send_AllNotesOff.java Tue Feb 03 22:02:55 2009 -0800
427.3 @@ -0,0 +1,64 @@
427.4 +/*
427.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
427.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
427.7 + *
427.8 + * This code is free software; you can redistribute it and/or modify it
427.9 + * under the terms of the GNU General Public License version 2 only, as
427.10 + * published by the Free Software Foundation. Sun designates this
427.11 + * particular file as subject to the "Classpath" exception as provided
427.12 + * by Sun in the LICENSE file that accompanied this code.
427.13 + *
427.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
427.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
427.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
427.17 + * version 2 for more details (a copy is included in the LICENSE file that
427.18 + * accompanied this code).
427.19 + *
427.20 + * You should have received a copy of the GNU General Public License version
427.21 + * 2 along with this work; if not, write to the Free Software Foundation,
427.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
427.23 + *
427.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
427.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
427.26 + * have any questions.
427.27 + */
427.28 +
427.29 +/* @test
427.30 + @summary Test SoftReceiver send method */
427.31 +
427.32 +import javax.sound.midi.*;
427.33 +import javax.sound.sampled.*;
427.34 +
427.35 +import com.sun.media.sound.*;
427.36 +
427.37 +public class Send_AllNotesOff {
427.38 +
427.39 + private static void assertEquals(Object a, Object b) throws Exception
427.40 + {
427.41 + if(!a.equals(b))
427.42 + throw new RuntimeException("assertEquals fails!");
427.43 + }
427.44 +
427.45 + private static void assertTrue(boolean value) throws Exception
427.46 + {
427.47 + if(!value)
427.48 + throw new RuntimeException("assertTrue fails!");
427.49 + }
427.50 +
427.51 + public static void main(String[] args) throws Exception {
427.52 + SoftTestUtils soft = new SoftTestUtils();
427.53 + MidiChannel channel = soft.synth.getChannels()[0];
427.54 + Receiver receiver = soft.synth.getReceiver();
427.55 +
427.56 + channel.noteOn(60, 64);
427.57 + soft.read(1);
427.58 + assertTrue(soft.findVoice(0,60) != null);
427.59 + ShortMessage smsg = new ShortMessage();
427.60 + smsg.setMessage(ShortMessage.CONTROL_CHANGE,0, 123,0);
427.61 + receiver.send(smsg, -1);
427.62 + soft.read(1);
427.63 + assertTrue(soft.findVoice(0,60) == null);
427.64 +
427.65 + soft.close();
427.66 + }
427.67 +}
428.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
428.2 +++ b/test/javax/sound/midi/Gervill/SoftReceiver/Send_AllSoundOff.java Tue Feb 03 22:02:55 2009 -0800
428.3 @@ -0,0 +1,64 @@
428.4 +/*
428.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
428.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
428.7 + *
428.8 + * This code is free software; you can redistribute it and/or modify it
428.9 + * under the terms of the GNU General Public License version 2 only, as
428.10 + * published by the Free Software Foundation. Sun designates this
428.11 + * particular file as subject to the "Classpath" exception as provided
428.12 + * by Sun in the LICENSE file that accompanied this code.
428.13 + *
428.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
428.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
428.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
428.17 + * version 2 for more details (a copy is included in the LICENSE file that
428.18 + * accompanied this code).
428.19 + *
428.20 + * You should have received a copy of the GNU General Public License version
428.21 + * 2 along with this work; if not, write to the Free Software Foundation,
428.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
428.23 + *
428.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
428.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
428.26 + * have any questions.
428.27 + */
428.28 +
428.29 +/* @test
428.30 + @summary Test SoftReceiver send method */
428.31 +
428.32 +import javax.sound.midi.*;
428.33 +import javax.sound.sampled.*;
428.34 +
428.35 +import com.sun.media.sound.*;
428.36 +
428.37 +public class Send_AllSoundOff {
428.38 +
428.39 + private static void assertEquals(Object a, Object b) throws Exception
428.40 + {
428.41 + if(!a.equals(b))
428.42 + throw new RuntimeException("assertEquals fails!");
428.43 + }
428.44 +
428.45 + private static void assertTrue(boolean value) throws Exception
428.46 + {
428.47 + if(!value)
428.48 + throw new RuntimeException("assertTrue fails!");
428.49 + }
428.50 +
428.51 + public static void main(String[] args) throws Exception {
428.52 + SoftTestUtils soft = new SoftTestUtils();
428.53 + MidiChannel channel = soft.synth.getChannels()[0];
428.54 + Receiver receiver = soft.synth.getReceiver();
428.55 +
428.56 + channel.noteOn(60, 64);
428.57 + soft.read(1);
428.58 + assertTrue(soft.findVoice(0,60) != null);
428.59 + ShortMessage smsg = new ShortMessage();
428.60 + smsg.setMessage(ShortMessage.CONTROL_CHANGE,0, 120,0);
428.61 + receiver.send(smsg, -1);
428.62 + soft.read(1);
428.63 + assertTrue(soft.findVoice(0,60) == null);
428.64 +
428.65 + soft.close();
428.66 + }
428.67 +}
429.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
429.2 +++ b/test/javax/sound/midi/Gervill/SoftReceiver/Send_ChannelPressure.java Tue Feb 03 22:02:55 2009 -0800
429.3 @@ -0,0 +1,63 @@
429.4 +/*
429.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
429.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
429.7 + *
429.8 + * This code is free software; you can redistribute it and/or modify it
429.9 + * under the terms of the GNU General Public License version 2 only, as
429.10 + * published by the Free Software Foundation. Sun designates this
429.11 + * particular file as subject to the "Classpath" exception as provided
429.12 + * by Sun in the LICENSE file that accompanied this code.
429.13 + *
429.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
429.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
429.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
429.17 + * version 2 for more details (a copy is included in the LICENSE file that
429.18 + * accompanied this code).
429.19 + *
429.20 + * You should have received a copy of the GNU General Public License version
429.21 + * 2 along with this work; if not, write to the Free Software Foundation,
429.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
429.23 + *
429.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
429.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
429.26 + * have any questions.
429.27 + */
429.28 +
429.29 +/* @test
429.30 + @summary Test SoftReceiver send method */
429.31 +
429.32 +import javax.sound.midi.*;
429.33 +import javax.sound.sampled.*;
429.34 +
429.35 +import com.sun.media.sound.*;
429.36 +
429.37 +public class Send_ChannelPressure {
429.38 +
429.39 + private static void assertEquals(Object a, Object b) throws Exception
429.40 + {
429.41 + if(!a.equals(b))
429.42 + throw new RuntimeException("assertEquals fails!");
429.43 + }
429.44 +
429.45 + private static void assertTrue(boolean value) throws Exception
429.46 + {
429.47 + if(!value)
429.48 + throw new RuntimeException("assertTrue fails!");
429.49 + }
429.50 +
429.51 + public static void main(String[] args) throws Exception {
429.52 + SoftTestUtils soft = new SoftTestUtils();
429.53 + MidiChannel channel = soft.synth.getChannels()[0];
429.54 + Receiver receiver = soft.synth.getReceiver();
429.55 +
429.56 + ShortMessage smsg = new ShortMessage();
429.57 + smsg.setMessage(ShortMessage.CHANNEL_PRESSURE,0, 10,0);
429.58 + receiver.send(smsg, -1);
429.59 + assertEquals(channel.getChannelPressure(), 10);
429.60 + smsg.setMessage(ShortMessage.CHANNEL_PRESSURE,0, 90,0);
429.61 + receiver.send(smsg, -1);
429.62 + assertEquals(channel.getChannelPressure(), 90);
429.63 +
429.64 + soft.close();
429.65 + }
429.66 +}
430.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
430.2 +++ b/test/javax/sound/midi/Gervill/SoftReceiver/Send_Controller.java Tue Feb 03 22:02:55 2009 -0800
430.3 @@ -0,0 +1,66 @@
430.4 +/*
430.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
430.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
430.7 + *
430.8 + * This code is free software; you can redistribute it and/or modify it
430.9 + * under the terms of the GNU General Public License version 2 only, as
430.10 + * published by the Free Software Foundation. Sun designates this
430.11 + * particular file as subject to the "Classpath" exception as provided
430.12 + * by Sun in the LICENSE file that accompanied this code.
430.13 + *
430.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
430.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
430.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
430.17 + * version 2 for more details (a copy is included in the LICENSE file that
430.18 + * accompanied this code).
430.19 + *
430.20 + * You should have received a copy of the GNU General Public License version
430.21 + * 2 along with this work; if not, write to the Free Software Foundation,
430.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
430.23 + *
430.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
430.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
430.26 + * have any questions.
430.27 + */
430.28 +
430.29 +/* @test
430.30 + @summary Test SoftReceiver send method */
430.31 +
430.32 +import javax.sound.midi.*;
430.33 +import javax.sound.sampled.*;
430.34 +
430.35 +import com.sun.media.sound.*;
430.36 +
430.37 +public class Send_Controller {
430.38 +
430.39 + private static void assertEquals(Object a, Object b) throws Exception
430.40 + {
430.41 + if(!a.equals(b))
430.42 + throw new RuntimeException("assertEquals fails!");
430.43 + }
430.44 +
430.45 + private static void assertTrue(boolean value) throws Exception
430.46 + {
430.47 + if(!value)
430.48 + throw new RuntimeException("assertTrue fails!");
430.49 + }
430.50 +
430.51 + public static void main(String[] args) throws Exception {
430.52 + SoftTestUtils soft = new SoftTestUtils();
430.53 + MidiChannel channel = soft.synth.getChannels()[0];
430.54 + Receiver receiver = soft.synth.getReceiver();
430.55 +
430.56 + ShortMessage smsg = new ShortMessage();
430.57 + for (int i = 0; i < 128; i++) {
430.58 + if(i == 0 || i == 32) continue;
430.59 + smsg.setMessage(ShortMessage.CONTROL_CHANGE,0, i,10);
430.60 + receiver.send(smsg, -1);
430.61 + assertEquals(channel.getController(i), 10);
430.62 + smsg.setMessage(ShortMessage.CONTROL_CHANGE,0, i,100);
430.63 + receiver.send(smsg, -1);
430.64 + assertEquals(channel.getController(i), 100);
430.65 + }
430.66 +
430.67 + soft.close();
430.68 + }
430.69 +}
431.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
431.2 +++ b/test/javax/sound/midi/Gervill/SoftReceiver/Send_Mono.java Tue Feb 03 22:02:55 2009 -0800
431.3 @@ -0,0 +1,75 @@
431.4 +/*
431.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
431.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
431.7 + *
431.8 + * This code is free software; you can redistribute it and/or modify it
431.9 + * under the terms of the GNU General Public License version 2 only, as
431.10 + * published by the Free Software Foundation. Sun designates this
431.11 + * particular file as subject to the "Classpath" exception as provided
431.12 + * by Sun in the LICENSE file that accompanied this code.
431.13 + *
431.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
431.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
431.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
431.17 + * version 2 for more details (a copy is included in the LICENSE file that
431.18 + * accompanied this code).
431.19 + *
431.20 + * You should have received a copy of the GNU General Public License version
431.21 + * 2 along with this work; if not, write to the Free Software Foundation,
431.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
431.23 + *
431.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
431.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
431.26 + * have any questions.
431.27 + */
431.28 +
431.29 +/* @test
431.30 + @summary Test SoftReceiver send method */
431.31 +
431.32 +import javax.sound.midi.*;
431.33 +import javax.sound.sampled.*;
431.34 +
431.35 +import com.sun.media.sound.*;
431.36 +
431.37 +public class Send_Mono {
431.38 +
431.39 + private static void assertEquals(Object a, Object b) throws Exception
431.40 + {
431.41 + if(!a.equals(b))
431.42 + throw new RuntimeException("assertEquals fails!");
431.43 + }
431.44 +
431.45 + private static void assertTrue(boolean value) throws Exception
431.46 + {
431.47 + if(!value)
431.48 + throw new RuntimeException("assertTrue fails!");
431.49 + }
431.50 +
431.51 + public static void main(String[] args) throws Exception {
431.52 + SoftTestUtils soft = new SoftTestUtils();
431.53 + MidiChannel channel = soft.synth.getChannels()[0];
431.54 + Receiver receiver = soft.synth.getReceiver();
431.55 +
431.56 + ShortMessage smsg = new ShortMessage();
431.57 + smsg.setMessage(ShortMessage.CONTROL_CHANGE,0, 126,100);
431.58 + receiver.send(smsg, -1);
431.59 + assertEquals(channel.getMono(), false);
431.60 + smsg.setMessage(ShortMessage.CONTROL_CHANGE,0, 126,1);
431.61 + receiver.send(smsg, -1);
431.62 + assertEquals(channel.getMono(), true);
431.63 + smsg.setMessage(ShortMessage.CONTROL_CHANGE,0, 127,0);
431.64 + receiver.send(smsg, -1);
431.65 + assertEquals(channel.getMono(), false);
431.66 +
431.67 + // Check if send mono triggers AllNotesOff
431.68 + channel.noteOn(60, 64);
431.69 + soft.read(1);
431.70 + assertTrue(soft.findVoice(0,60) != null);
431.71 + smsg.setMessage(ShortMessage.CONTROL_CHANGE,0, 127,0);
431.72 + receiver.send(smsg, -1);
431.73 + soft.read(1);
431.74 + assertTrue(soft.findVoice(0,60) == null);
431.75 +
431.76 + soft.close();
431.77 + }
431.78 +}
432.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
432.2 +++ b/test/javax/sound/midi/Gervill/SoftReceiver/Send_NoteOff.java Tue Feb 03 22:02:55 2009 -0800
432.3 @@ -0,0 +1,65 @@
432.4 +/*
432.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
432.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
432.7 + *
432.8 + * This code is free software; you can redistribute it and/or modify it
432.9 + * under the terms of the GNU General Public License version 2 only, as
432.10 + * published by the Free Software Foundation. Sun designates this
432.11 + * particular file as subject to the "Classpath" exception as provided
432.12 + * by Sun in the LICENSE file that accompanied this code.
432.13 + *
432.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
432.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
432.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
432.17 + * version 2 for more details (a copy is included in the LICENSE file that
432.18 + * accompanied this code).
432.19 + *
432.20 + * You should have received a copy of the GNU General Public License version
432.21 + * 2 along with this work; if not, write to the Free Software Foundation,
432.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
432.23 + *
432.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
432.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
432.26 + * have any questions.
432.27 + */
432.28 +
432.29 +/* @test
432.30 + @summary Test SoftReceiver send method */
432.31 +
432.32 +import javax.sound.midi.*;
432.33 +import javax.sound.sampled.*;
432.34 +
432.35 +import com.sun.media.sound.*;
432.36 +
432.37 +public class Send_NoteOff {
432.38 +
432.39 + private static void assertEquals(Object a, Object b) throws Exception
432.40 + {
432.41 + if(!a.equals(b))
432.42 + throw new RuntimeException("assertEquals fails!");
432.43 + }
432.44 +
432.45 + private static void assertTrue(boolean value) throws Exception
432.46 + {
432.47 + if(!value)
432.48 + throw new RuntimeException("assertTrue fails!");
432.49 + }
432.50 +
432.51 + public static void main(String[] args) throws Exception {
432.52 + SoftTestUtils soft = new SoftTestUtils();
432.53 + MidiChannel channel = soft.synth.getChannels()[0];
432.54 + Receiver receiver = soft.synth.getReceiver();
432.55 +
432.56 + ShortMessage smsg = new ShortMessage();
432.57 + smsg.setMessage(ShortMessage.NOTE_ON,0, 60, 64);
432.58 + receiver.send(smsg, -1);
432.59 + soft.read(1);
432.60 + assertTrue(soft.findVoice(0,60) != null);
432.61 + smsg.setMessage(ShortMessage.NOTE_OFF,0, 60, 0);
432.62 + receiver.send(smsg, -1);
432.63 + soft.read(1);
432.64 + assertTrue(soft.findVoice(0,60) == null);
432.65 +
432.66 + soft.close();
432.67 + }
432.68 +}
433.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
433.2 +++ b/test/javax/sound/midi/Gervill/SoftReceiver/Send_NoteOn.java Tue Feb 03 22:02:55 2009 -0800
433.3 @@ -0,0 +1,65 @@
433.4 +/*
433.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
433.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
433.7 + *
433.8 + * This code is free software; you can redistribute it and/or modify it
433.9 + * under the terms of the GNU General Public License version 2 only, as
433.10 + * published by the Free Software Foundation. Sun designates this
433.11 + * particular file as subject to the "Classpath" exception as provided
433.12 + * by Sun in the LICENSE file that accompanied this code.
433.13 + *
433.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
433.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
433.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
433.17 + * version 2 for more details (a copy is included in the LICENSE file that
433.18 + * accompanied this code).
433.19 + *
433.20 + * You should have received a copy of the GNU General Public License version
433.21 + * 2 along with this work; if not, write to the Free Software Foundation,
433.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
433.23 + *
433.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
433.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
433.26 + * have any questions.
433.27 + */
433.28 +
433.29 +/* @test
433.30 + @summary Test SoftReceiver send method */
433.31 +
433.32 +import javax.sound.midi.*;
433.33 +import javax.sound.sampled.*;
433.34 +
433.35 +import com.sun.media.sound.*;
433.36 +
433.37 +public class Send_NoteOn {
433.38 +
433.39 + private static void assertEquals(Object a, Object b) throws Exception
433.40 + {
433.41 + if(!a.equals(b))
433.42 + throw new RuntimeException("assertEquals fails!");
433.43 + }
433.44 +
433.45 + private static void assertTrue(boolean value) throws Exception
433.46 + {
433.47 + if(!value)
433.48 + throw new RuntimeException("assertTrue fails!");
433.49 + }
433.50 +
433.51 + public static void main(String[] args) throws Exception {
433.52 + SoftTestUtils soft = new SoftTestUtils();
433.53 + MidiChannel channel = soft.synth.getChannels()[0];
433.54 + Receiver receiver = soft.synth.getReceiver();
433.55 +
433.56 + ShortMessage smsg = new ShortMessage();
433.57 + smsg.setMessage(ShortMessage.NOTE_ON,0, 60, 64);
433.58 + receiver.send(smsg, -1);
433.59 + soft.read(1);
433.60 + assertTrue(soft.findVoice(0,60) != null);
433.61 + smsg.setMessage(ShortMessage.NOTE_ON,0, 60, 0);
433.62 + receiver.send(smsg, -1);
433.63 + soft.read(1);
433.64 + assertTrue(soft.findVoice(0,60) == null);
433.65 +
433.66 + soft.close();
433.67 + }
433.68 +}
434.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
434.2 +++ b/test/javax/sound/midi/Gervill/SoftReceiver/Send_NoteOn_AllChannels.java Tue Feb 03 22:02:55 2009 -0800
434.3 @@ -0,0 +1,71 @@
434.4 +/*
434.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
434.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
434.7 + *
434.8 + * This code is free software; you can redistribute it and/or modify it
434.9 + * under the terms of the GNU General Public License version 2 only, as
434.10 + * published by the Free Software Foundation. Sun designates this
434.11 + * particular file as subject to the "Classpath" exception as provided
434.12 + * by Sun in the LICENSE file that accompanied this code.
434.13 + *
434.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
434.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
434.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
434.17 + * version 2 for more details (a copy is included in the LICENSE file that
434.18 + * accompanied this code).
434.19 + *
434.20 + * You should have received a copy of the GNU General Public License version
434.21 + * 2 along with this work; if not, write to the Free Software Foundation,
434.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
434.23 + *
434.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
434.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
434.26 + * have any questions.
434.27 + */
434.28 +
434.29 +/* @test
434.30 + @summary Test SoftReceiver send method */
434.31 +
434.32 +import javax.sound.midi.*;
434.33 +import javax.sound.sampled.*;
434.34 +
434.35 +import com.sun.media.sound.*;
434.36 +
434.37 +public class Send_NoteOn_AllChannels {
434.38 +
434.39 + private static void assertEquals(Object a, Object b) throws Exception
434.40 + {
434.41 + if(!a.equals(b))
434.42 + throw new RuntimeException("assertEquals fails!");
434.43 + }
434.44 +
434.45 + private static void assertTrue(boolean value) throws Exception
434.46 + {
434.47 + if(!value)
434.48 + throw new RuntimeException("assertTrue fails!");
434.49 + }
434.50 +
434.51 + public static void main(String[] args) throws Exception {
434.52 + SoftTestUtils soft = new SoftTestUtils();
434.53 + MidiChannel channel = soft.synth.getChannels()[0];
434.54 + Receiver receiver = soft.synth.getReceiver();
434.55 +
434.56 + for (int i = 0; i < 15; i++) {
434.57 + if(i == 9) i++;
434.58 + ShortMessage smsg = new ShortMessage();
434.59 + smsg.setMessage(ShortMessage.NOTE_ON,i, 60, 64);
434.60 + receiver.send(smsg, -1);
434.61 + soft.read(1);
434.62 + VoiceStatus voice = soft.findVoice(i,60);
434.63 + assertTrue(voice != null);
434.64 + smsg.setMessage(ShortMessage.NOTE_ON,i, 60, 0);
434.65 + receiver.send(smsg, -1);
434.66 + soft.read(1);
434.67 + voice = soft.findVoice(i,60);
434.68 + assertTrue(voice == null);
434.69 + soft.read(1);
434.70 + }
434.71 +
434.72 + soft.close();
434.73 + }
434.74 +}
435.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
435.2 +++ b/test/javax/sound/midi/Gervill/SoftReceiver/Send_NoteOn_Delayed.java Tue Feb 03 22:02:55 2009 -0800
435.3 @@ -0,0 +1,67 @@
435.4 +/*
435.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
435.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
435.7 + *
435.8 + * This code is free software; you can redistribute it and/or modify it
435.9 + * under the terms of the GNU General Public License version 2 only, as
435.10 + * published by the Free Software Foundation. Sun designates this
435.11 + * particular file as subject to the "Classpath" exception as provided
435.12 + * by Sun in the LICENSE file that accompanied this code.
435.13 + *
435.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
435.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
435.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
435.17 + * version 2 for more details (a copy is included in the LICENSE file that
435.18 + * accompanied this code).
435.19 + *
435.20 + * You should have received a copy of the GNU General Public License version
435.21 + * 2 along with this work; if not, write to the Free Software Foundation,
435.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
435.23 + *
435.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
435.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
435.26 + * have any questions.
435.27 + */
435.28 +
435.29 +/* @test
435.30 + @summary Test SoftReceiver send method */
435.31 +
435.32 +import javax.sound.midi.*;
435.33 +import javax.sound.sampled.*;
435.34 +
435.35 +import com.sun.media.sound.*;
435.36 +
435.37 +public class Send_NoteOn_Delayed {
435.38 +
435.39 + private static void assertEquals(Object a, Object b) throws Exception
435.40 + {
435.41 + if(!a.equals(b))
435.42 + throw new RuntimeException("assertEquals fails!");
435.43 + }
435.44 +
435.45 + private static void assertTrue(boolean value) throws Exception
435.46 + {
435.47 + if(!value)
435.48 + throw new RuntimeException("assertTrue fails!");
435.49 + }
435.50 +
435.51 + public static void main(String[] args) throws Exception {
435.52 + SoftTestUtils soft = new SoftTestUtils();
435.53 + MidiChannel channel = soft.synth.getChannels()[0];
435.54 + Receiver receiver = soft.synth.getReceiver();
435.55 +
435.56 + ShortMessage smsg = new ShortMessage();
435.57 + smsg.setMessage(ShortMessage.NOTE_ON,0, 60, 64);
435.58 + receiver.send(smsg, 2000000); // Delay sending note for 2 sec
435.59 + soft.read(1);
435.60 + assertTrue(soft.findVoice(0,60) == null);
435.61 + soft.read(2);
435.62 + assertTrue(soft.findVoice(0,60) != null);
435.63 + smsg.setMessage(ShortMessage.NOTE_ON,0, 60, 0);
435.64 + receiver.send(smsg, -1);
435.65 + soft.read(1);
435.66 + assertTrue(soft.findVoice(0,60) == null);
435.67 +
435.68 + soft.close();
435.69 + }
435.70 +}
436.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
436.2 +++ b/test/javax/sound/midi/Gervill/SoftReceiver/Send_NoteOn_Multiple.java Tue Feb 03 22:02:55 2009 -0800
436.3 @@ -0,0 +1,76 @@
436.4 +/*
436.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
436.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
436.7 + *
436.8 + * This code is free software; you can redistribute it and/or modify it
436.9 + * under the terms of the GNU General Public License version 2 only, as
436.10 + * published by the Free Software Foundation. Sun designates this
436.11 + * particular file as subject to the "Classpath" exception as provided
436.12 + * by Sun in the LICENSE file that accompanied this code.
436.13 + *
436.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
436.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
436.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
436.17 + * version 2 for more details (a copy is included in the LICENSE file that
436.18 + * accompanied this code).
436.19 + *
436.20 + * You should have received a copy of the GNU General Public License version
436.21 + * 2 along with this work; if not, write to the Free Software Foundation,
436.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
436.23 + *
436.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
436.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
436.26 + * have any questions.
436.27 + */
436.28 +
436.29 +/* @test
436.30 + @summary Test SoftReceiver send method */
436.31 +
436.32 +import javax.sound.midi.*;
436.33 +import javax.sound.sampled.*;
436.34 +
436.35 +import com.sun.media.sound.*;
436.36 +
436.37 +public class Send_NoteOn_Multiple {
436.38 +
436.39 + private static void assertEquals(Object a, Object b) throws Exception
436.40 + {
436.41 + if(!a.equals(b))
436.42 + throw new RuntimeException("assertEquals fails!");
436.43 + }
436.44 +
436.45 + private static void assertTrue(boolean value) throws Exception
436.46 + {
436.47 + if(!value)
436.48 + throw new RuntimeException("assertTrue fails!");
436.49 + }
436.50 +
436.51 + public static void main(String[] args) throws Exception {
436.52 + SoftTestUtils soft = new SoftTestUtils();
436.53 + MidiChannel channel = soft.synth.getChannels()[0];
436.54 + Receiver receiver = soft.synth.getReceiver();
436.55 +
436.56 + ShortMessage smsg = new ShortMessage();
436.57 + smsg.setMessage(ShortMessage.NOTE_ON,0, 60, 64);
436.58 + receiver.send(smsg, -1);
436.59 + smsg.setMessage(ShortMessage.NOTE_ON,0, 61, 64);
436.60 + receiver.send(smsg, -1);
436.61 + smsg.setMessage(ShortMessage.NOTE_ON,0, 62, 64);
436.62 + receiver.send(smsg, -1);
436.63 + soft.read(1);
436.64 + assertTrue(soft.findVoice(0,60) != null);
436.65 + assertTrue(soft.findVoice(0,61) != null);
436.66 + assertTrue(soft.findVoice(0,62) != null);
436.67 +
436.68 + smsg.setMessage(ShortMessage.NOTE_ON,0, 60, 0);
436.69 + receiver.send(smsg, -1);
436.70 + smsg.setMessage(ShortMessage.NOTE_ON,0, 61, 0);
436.71 + receiver.send(smsg, -1);
436.72 + soft.read(1);
436.73 + assertTrue(soft.findVoice(0,60) == null);
436.74 + assertTrue(soft.findVoice(0,61) == null);
436.75 + assertTrue(soft.findVoice(0,62) != null);
436.76 +
436.77 + soft.close();
436.78 + }
436.79 +}
437.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
437.2 +++ b/test/javax/sound/midi/Gervill/SoftReceiver/Send_Omni.java Tue Feb 03 22:02:55 2009 -0800
437.3 @@ -0,0 +1,74 @@
437.4 +/*
437.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
437.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
437.7 + *
437.8 + * This code is free software; you can redistribute it and/or modify it
437.9 + * under the terms of the GNU General Public License version 2 only, as
437.10 + * published by the Free Software Foundation. Sun designates this
437.11 + * particular file as subject to the "Classpath" exception as provided
437.12 + * by Sun in the LICENSE file that accompanied this code.
437.13 + *
437.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
437.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
437.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
437.17 + * version 2 for more details (a copy is included in the LICENSE file that
437.18 + * accompanied this code).
437.19 + *
437.20 + * You should have received a copy of the GNU General Public License version
437.21 + * 2 along with this work; if not, write to the Free Software Foundation,
437.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
437.23 + *
437.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
437.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
437.26 + * have any questions.
437.27 + */
437.28 +
437.29 +/* @test
437.30 + @summary Test SoftReceiver send method */
437.31 +
437.32 +import javax.sound.midi.*;
437.33 +import javax.sound.sampled.*;
437.34 +
437.35 +import com.sun.media.sound.*;
437.36 +
437.37 +public class Send_Omni {
437.38 +
437.39 + private static void assertEquals(Object a, Object b) throws Exception
437.40 + {
437.41 + if(!a.equals(b))
437.42 + throw new RuntimeException("assertEquals fails!");
437.43 + }
437.44 +
437.45 + private static void assertTrue(boolean value) throws Exception
437.46 + {
437.47 + if(!value)
437.48 + throw new RuntimeException("assertTrue fails!");
437.49 + }
437.50 +
437.51 + public static void main(String[] args) throws Exception {
437.52 + SoftTestUtils soft = new SoftTestUtils();
437.53 + MidiChannel channel = soft.synth.getChannels()[0];
437.54 + Receiver receiver = soft.synth.getReceiver();
437.55 +
437.56 + ShortMessage smsg = new ShortMessage();
437.57 + smsg.setMessage(ShortMessage.CONTROL_CHANGE,0, 125,0);
437.58 + receiver.send(smsg, -1);
437.59 + // Poly or Omni not supported by GM2
437.60 + // getOmni() should always return false
437.61 + assertEquals(channel.getOmni(), false);
437.62 + smsg.setMessage(ShortMessage.CONTROL_CHANGE,0, 124,0);
437.63 + receiver.send(smsg, -1);
437.64 + assertEquals(channel.getOmni(), false);
437.65 +
437.66 + // Check if send omni triggers AllNotesOff
437.67 + channel.noteOn(60, 64);
437.68 + soft.read(1);
437.69 + assertTrue(soft.findVoice(0,60) != null);
437.70 + smsg.setMessage(ShortMessage.CONTROL_CHANGE,0, 124,0);
437.71 + receiver.send(smsg, -1);
437.72 + soft.read(1);
437.73 + assertTrue(soft.findVoice(0,60) == null);
437.74 +
437.75 + soft.close();
437.76 + }
437.77 +}
438.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
438.2 +++ b/test/javax/sound/midi/Gervill/SoftReceiver/Send_PitchBend.java Tue Feb 03 22:02:55 2009 -0800
438.3 @@ -0,0 +1,63 @@
438.4 +/*
438.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
438.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
438.7 + *
438.8 + * This code is free software; you can redistribute it and/or modify it
438.9 + * under the terms of the GNU General Public License version 2 only, as
438.10 + * published by the Free Software Foundation. Sun designates this
438.11 + * particular file as subject to the "Classpath" exception as provided
438.12 + * by Sun in the LICENSE file that accompanied this code.
438.13 + *
438.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
438.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
438.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
438.17 + * version 2 for more details (a copy is included in the LICENSE file that
438.18 + * accompanied this code).
438.19 + *
438.20 + * You should have received a copy of the GNU General Public License version
438.21 + * 2 along with this work; if not, write to the Free Software Foundation,
438.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
438.23 + *
438.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
438.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
438.26 + * have any questions.
438.27 + */
438.28 +
438.29 +/* @test
438.30 + @summary Test SoftReceiver send method */
438.31 +
438.32 +import javax.sound.midi.*;
438.33 +import javax.sound.sampled.*;
438.34 +
438.35 +import com.sun.media.sound.*;
438.36 +
438.37 +public class Send_PitchBend {
438.38 +
438.39 + private static void assertEquals(Object a, Object b) throws Exception
438.40 + {
438.41 + if(!a.equals(b))
438.42 + throw new RuntimeException("assertEquals fails!");
438.43 + }
438.44 +
438.45 + private static void assertTrue(boolean value) throws Exception
438.46 + {
438.47 + if(!value)
438.48 + throw new RuntimeException("assertTrue fails!");
438.49 + }
438.50 +
438.51 + public static void main(String[] args) throws Exception {
438.52 + SoftTestUtils soft = new SoftTestUtils();
438.53 + MidiChannel channel = soft.synth.getChannels()[0];
438.54 + Receiver receiver = soft.synth.getReceiver();
438.55 +
438.56 + ShortMessage smsg = new ShortMessage();
438.57 + smsg.setMessage(ShortMessage.PITCH_BEND,0, 10,0);
438.58 + receiver.send(smsg, -1);
438.59 + assertEquals(channel.getPitchBend(), 10);
438.60 + smsg.setMessage(ShortMessage.PITCH_BEND,0, 9000%128,9000/128);
438.61 + receiver.send(smsg, -1);
438.62 + assertEquals(channel.getPitchBend(), 9000);
438.63 +
438.64 + soft.close();
438.65 + }
438.66 +}
439.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
439.2 +++ b/test/javax/sound/midi/Gervill/SoftReceiver/Send_PolyPressure.java Tue Feb 03 22:02:55 2009 -0800
439.3 @@ -0,0 +1,65 @@
439.4 +/*
439.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
439.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
439.7 + *
439.8 + * This code is free software; you can redistribute it and/or modify it
439.9 + * under the terms of the GNU General Public License version 2 only, as
439.10 + * published by the Free Software Foundation. Sun designates this
439.11 + * particular file as subject to the "Classpath" exception as provided
439.12 + * by Sun in the LICENSE file that accompanied this code.
439.13 + *
439.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
439.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
439.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
439.17 + * version 2 for more details (a copy is included in the LICENSE file that
439.18 + * accompanied this code).
439.19 + *
439.20 + * You should have received a copy of the GNU General Public License version
439.21 + * 2 along with this work; if not, write to the Free Software Foundation,
439.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
439.23 + *
439.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
439.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
439.26 + * have any questions.
439.27 + */
439.28 +
439.29 +/* @test
439.30 + @summary Test SoftReceiver send method */
439.31 +
439.32 +import javax.sound.midi.*;
439.33 +import javax.sound.sampled.*;
439.34 +
439.35 +import com.sun.media.sound.*;
439.36 +
439.37 +public class Send_PolyPressure {
439.38 +
439.39 + private static void assertEquals(Object a, Object b) throws Exception
439.40 + {
439.41 + if(!a.equals(b))
439.42 + throw new RuntimeException("assertEquals fails!");
439.43 + }
439.44 +
439.45 + private static void assertTrue(boolean value) throws Exception
439.46 + {
439.47 + if(!value)
439.48 + throw new RuntimeException("assertTrue fails!");
439.49 + }
439.50 +
439.51 + public static void main(String[] args) throws Exception {
439.52 + SoftTestUtils soft = new SoftTestUtils();
439.53 + MidiChannel channel = soft.synth.getChannels()[0];
439.54 + Receiver receiver = soft.synth.getReceiver();
439.55 +
439.56 + ShortMessage smsg = new ShortMessage();
439.57 + for (int i = 0; i < 128; i++) {
439.58 + smsg.setMessage(ShortMessage.POLY_PRESSURE,0, i, 10);
439.59 + receiver.send(smsg, -1);
439.60 + assertEquals(channel.getPolyPressure(i),10);
439.61 + smsg.setMessage(ShortMessage.POLY_PRESSURE,0, i, 100);
439.62 + receiver.send(smsg, -1);
439.63 + assertEquals(channel.getPolyPressure(i),100);
439.64 + }
439.65 +
439.66 + soft.close();
439.67 + }
439.68 +}
440.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
440.2 +++ b/test/javax/sound/midi/Gervill/SoftReceiver/Send_ProgramChange.java Tue Feb 03 22:02:55 2009 -0800
440.3 @@ -0,0 +1,63 @@
440.4 +/*
440.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
440.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
440.7 + *
440.8 + * This code is free software; you can redistribute it and/or modify it
440.9 + * under the terms of the GNU General Public License version 2 only, as
440.10 + * published by the Free Software Foundation. Sun designates this
440.11 + * particular file as subject to the "Classpath" exception as provided
440.12 + * by Sun in the LICENSE file that accompanied this code.
440.13 + *
440.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
440.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
440.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
440.17 + * version 2 for more details (a copy is included in the LICENSE file that
440.18 + * accompanied this code).
440.19 + *
440.20 + * You should have received a copy of the GNU General Public License version
440.21 + * 2 along with this work; if not, write to the Free Software Foundation,
440.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
440.23 + *
440.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
440.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
440.26 + * have any questions.
440.27 + */
440.28 +
440.29 +/* @test
440.30 + @summary Test SoftReceiver send method */
440.31 +
440.32 +import javax.sound.midi.*;
440.33 +import javax.sound.sampled.*;
440.34 +
440.35 +import com.sun.media.sound.*;
440.36 +
440.37 +public class Send_ProgramChange {
440.38 +
440.39 + private static void assertEquals(Object a, Object b) throws Exception
440.40 + {
440.41 + if(!a.equals(b))
440.42 + throw new RuntimeException("assertEquals fails!");
440.43 + }
440.44 +
440.45 + private static void assertTrue(boolean value) throws Exception
440.46 + {
440.47 + if(!value)
440.48 + throw new RuntimeException("assertTrue fails!");
440.49 + }
440.50 +
440.51 + public static void main(String[] args) throws Exception {
440.52 + SoftTestUtils soft = new SoftTestUtils();
440.53 + MidiChannel channel = soft.synth.getChannels()[0];
440.54 + Receiver receiver = soft.synth.getReceiver();
440.55 +
440.56 + ShortMessage smsg = new ShortMessage();
440.57 + smsg.setMessage(ShortMessage.PROGRAM_CHANGE,0, 36,0);
440.58 + receiver.send(smsg, -1);
440.59 + assertEquals(channel.getProgram(), 36);
440.60 + smsg.setMessage(ShortMessage.PROGRAM_CHANGE,0, 48,0);
440.61 + receiver.send(smsg, -1);
440.62 + assertEquals(channel.getProgram(), 48);
440.63 +
440.64 + soft.close();
440.65 + }
440.66 +}
441.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
441.2 +++ b/test/javax/sound/midi/Gervill/SoftReceiver/Send_ResetAllControllers.java Tue Feb 03 22:02:55 2009 -0800
441.3 @@ -0,0 +1,136 @@
441.4 +/*
441.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
441.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
441.7 + *
441.8 + * This code is free software; you can redistribute it and/or modify it
441.9 + * under the terms of the GNU General Public License version 2 only, as
441.10 + * published by the Free Software Foundation. Sun designates this
441.11 + * particular file as subject to the "Classpath" exception as provided
441.12 + * by Sun in the LICENSE file that accompanied this code.
441.13 + *
441.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
441.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
441.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
441.17 + * version 2 for more details (a copy is included in the LICENSE file that
441.18 + * accompanied this code).
441.19 + *
441.20 + * You should have received a copy of the GNU General Public License version
441.21 + * 2 along with this work; if not, write to the Free Software Foundation,
441.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
441.23 + *
441.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
441.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
441.26 + * have any questions.
441.27 + */
441.28 +
441.29 +/* @test
441.30 + @summary Test SoftReceiver send method */
441.31 +
441.32 +import javax.sound.midi.*;
441.33 +import javax.sound.sampled.*;
441.34 +
441.35 +import com.sun.media.sound.*;
441.36 +
441.37 +public class Send_ResetAllControllers {
441.38 +
441.39 + public static boolean[] dontResetControls = new boolean[128];
441.40 + static {
441.41 + for (int i = 0; i < dontResetControls.length; i++)
441.42 + dontResetControls[i] = false;
441.43 +
441.44 + dontResetControls[0] = true; // Bank Select (MSB)
441.45 + dontResetControls[32] = true; // Bank Select (LSB)
441.46 + dontResetControls[7] = true; // Channel Volume (MSB)
441.47 + dontResetControls[8] = true; // Balance (MSB)
441.48 + dontResetControls[10] = true; // Pan (MSB)
441.49 + dontResetControls[11] = true; // Expression (MSB)
441.50 + dontResetControls[91] = true; // Effects 1 Depth (default: Reverb Send)
441.51 + dontResetControls[92] = true; // Effects 2 Depth (default: Tremolo Depth)
441.52 + dontResetControls[93] = true; // Effects 3 Depth (default: Chorus Send)
441.53 + dontResetControls[94] = true; // Effects 4 Depth (default: Celeste [Detune] Depth)
441.54 + dontResetControls[95] = true; // Effects 5 Depth (default: Phaser Depth)
441.55 + dontResetControls[70] = true; // Sound Controller 1 (default: Sound Variation)
441.56 + dontResetControls[71] = true; // Sound Controller 2 (default: Timbre / Harmonic Quality)
441.57 + dontResetControls[72] = true; // Sound Controller 3 (default: Release Time)
441.58 + dontResetControls[73] = true; // Sound Controller 4 (default: Attack Time)
441.59 + dontResetControls[74] = true; // Sound Controller 5 (default: Brightness)
441.60 + dontResetControls[75] = true; // Sound Controller 6 (GM2 default: Decay Time)
441.61 + dontResetControls[76] = true; // Sound Controller 7 (GM2 default: Vibrato Rate)
441.62 + dontResetControls[77] = true; // Sound Controller 8 (GM2 default: Vibrato Depth)
441.63 + dontResetControls[78] = true; // Sound Controller 9 (GM2 default: Vibrato Delay)
441.64 + dontResetControls[79] = true; // Sound Controller 10 (GM2 default: Undefined)
441.65 + dontResetControls[120] = true; // All Sound Off
441.66 + dontResetControls[121] = true; // Reset All Controllers
441.67 + dontResetControls[122] = true; // Local Control On/Off
441.68 + dontResetControls[123] = true; // All Notes Off
441.69 + dontResetControls[124] = true; // Omni Mode Off
441.70 + dontResetControls[125] = true; // Omni Mode On
441.71 + dontResetControls[126] = true; // Poly Mode Off
441.72 + dontResetControls[127] = true; // Poly Mode On
441.73 +
441.74 + dontResetControls[6] = true; // Data Entry (MSB)
441.75 + dontResetControls[38] = true; // Data Entry (LSB)
441.76 + dontResetControls[96] = true; // Data Increment
441.77 + dontResetControls[97] = true; // Data Decrement
441.78 + dontResetControls[98] = true; // Non-Registered Parameter Number (LSB)
441.79 + dontResetControls[99] = true; // Non-Registered Parameter Number(MSB)
441.80 + dontResetControls[100] = true; // RPN = Null
441.81 + dontResetControls[101] = true; // RPN = Null
441.82 + }
441.83 +
441.84 + private static void assertEquals(Object a, Object b) throws Exception
441.85 + {
441.86 + if(!a.equals(b))
441.87 + throw new RuntimeException("assertEquals fails!");
441.88 + }
441.89 +
441.90 + private static void assertTrue(boolean value) throws Exception
441.91 + {
441.92 + if(!value)
441.93 + throw new RuntimeException("assertTrue fails!");
441.94 + }
441.95 +
441.96 + public static void main(String[] args) throws Exception {
441.97 + SoftTestUtils soft = new SoftTestUtils();
441.98 + MidiChannel channel = soft.synth.getChannels()[0];
441.99 + Receiver receiver = soft.synth.getReceiver();
441.100 +
441.101 + // First let all controls contain non-default values
441.102 + for (int i = 0; i < 128; i++)
441.103 + channel.setPolyPressure(i, 10);
441.104 + channel.setChannelPressure(10);
441.105 + channel.setPitchBend(2192);
441.106 + for (int i = 0; i < 120; i++)
441.107 + channel.controlChange(i, 1);
441.108 +
441.109 + ShortMessage smsg = new ShortMessage();
441.110 + smsg.setMessage(ShortMessage.CONTROL_CHANGE,0, 121,0);
441.111 + receiver.send(smsg, -1);
441.112 +
441.113 + // Now check if resetAllControllers did what it was suppose to do
441.114 +
441.115 + for (int i = 0; i < 128; i++)
441.116 + assertEquals(channel.getPolyPressure(i), 0);
441.117 + assertEquals(channel.getChannelPressure(), 0);
441.118 + assertEquals(channel.getPitchBend(),8192);
441.119 + for (int i = 0; i < 120; i++)
441.120 + if(!dontResetControls[i])
441.121 + assertEquals(channel.getController(i), 0);
441.122 + assertEquals(channel.getController(71), 64); // Filter Resonance
441.123 + assertEquals(channel.getController(72), 64); // Release Time
441.124 + assertEquals(channel.getController(73), 64); // Attack Time
441.125 + assertEquals(channel.getController(74), 64); // Brightness
441.126 + assertEquals(channel.getController(75), 64); // Decay Time
441.127 + assertEquals(channel.getController(76), 64); // Vibrato Rate
441.128 + assertEquals(channel.getController(77), 64); // Vibrato Depth
441.129 + assertEquals(channel.getController(78), 64); // Vibrato Delay
441.130 + assertEquals(channel.getController(8), 64); // Balance
441.131 + assertEquals(channel.getController(11), 127); // Expression
441.132 + assertEquals(channel.getController(98), 127); // NRPN Null
441.133 + assertEquals(channel.getController(99), 127); // NRPN Null
441.134 + assertEquals(channel.getController(100), 127); // RPN = Null
441.135 + assertEquals(channel.getController(101), 127); // RPN = Null
441.136 +
441.137 + soft.close();
441.138 + }
441.139 +}
442.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
442.2 +++ b/test/javax/sound/midi/Gervill/SoftReceiver/SoftTestUtils.java Tue Feb 03 22:02:55 2009 -0800
442.3 @@ -0,0 +1,111 @@
442.4 +/*
442.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
442.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
442.7 + *
442.8 + * This code is free software; you can redistribute it and/or modify it
442.9 + * under the terms of the GNU General Public License version 2 only, as
442.10 + * published by the Free Software Foundation. Sun designates this
442.11 + * particular file as subject to the "Classpath" exception as provided
442.12 + * by Sun in the LICENSE file that accompanied this code.
442.13 + *
442.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
442.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
442.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
442.17 + * version 2 for more details (a copy is included in the LICENSE file that
442.18 + * accompanied this code).
442.19 + *
442.20 + * You should have received a copy of the GNU General Public License version
442.21 + * 2 along with this work; if not, write to the Free Software Foundation,
442.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
442.23 + *
442.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
442.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
442.26 + * have any questions.
442.27 + */
442.28 +
442.29 +import java.io.IOException;
442.30 +
442.31 +import javax.sound.midi.*;
442.32 +import javax.sound.sampled.*;
442.33 +
442.34 +import com.sun.media.sound.*;
442.35 +
442.36 +public class SoftTestUtils {
442.37 +
442.38 + public AudioSynthesizer synth = new SoftSynthesizer();
442.39 + public AudioInputStream stream;
442.40 + public byte[] tmpbuffer = new byte[1024];
442.41 +
442.42 + public static SF2Soundbank createTestSoundBank()
442.43 + {
442.44 + SF2Soundbank sf2 = new SF2Soundbank();
442.45 + AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
442.46 + float[] data = new float[44100+1000];
442.47 + float fr = 440/format.getSampleRate();
442.48 + for (int i = 0; i < data.length; i++)
442.49 + data[i] = (float)Math.sin(i*fr*2*Math.PI);
442.50 + byte[] bdata = new byte[data.length*format.getFrameSize()];
442.51 + AudioFloatConverter.getConverter(format).toByteArray(data, bdata);
442.52 + SF2Sample sample = new SF2Sample(sf2);
442.53 + sample.setName("Test Sample");
442.54 + sample.setData(bdata);
442.55 + sample.setStartLoop(500);
442.56 + sample.setEndLoop(data.length - 500);
442.57 + sample.setSampleRate((long) format.getSampleRate());
442.58 + sample.setOriginalPitch(69);
442.59 + sf2.addResource(sample);
442.60 + SF2Layer layer = new SF2Layer(sf2);
442.61 + layer.setName("Test Layer");
442.62 + sf2.addResource(layer);
442.63 + SF2LayerRegion region = new SF2LayerRegion();
442.64 + region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
442.65 + region.setSample(sample);
442.66 + layer.getRegions().add(region);
442.67 + SF2Instrument ins = new SF2Instrument(sf2);
442.68 + ins.setName("Test Instrument");
442.69 + sf2.addInstrument(ins);
442.70 + SF2InstrumentRegion insregion = new SF2InstrumentRegion();
442.71 + insregion.setLayer(layer);
442.72 + ins.getRegions().add(insregion);
442.73 +
442.74 + return sf2;
442.75 + }
442.76 +
442.77 + public SoftTestUtils() throws Exception {
442.78 + stream = synth.openStream(null, null);
442.79 + synth.unloadAllInstruments(synth.getDefaultSoundbank());
442.80 + synth.loadAllInstruments(createTestSoundBank());
442.81 + }
442.82 +
442.83 + public void close() throws Exception {
442.84 + stream.close();
442.85 + stream = null;
442.86 + synth.close();
442.87 + synth = null;
442.88 + }
442.89 +
442.90 + public void read(double seconds) throws IOException
442.91 + {
442.92 + int bufflen =
442.93 + stream.getFormat().getFrameSize() *
442.94 + (int)(stream.getFormat().getFrameRate() * seconds);
442.95 + while(bufflen != 0)
442.96 + {
442.97 + if(bufflen > 1024)
442.98 + bufflen -= stream.read(tmpbuffer,0,1024);
442.99 + else
442.100 + bufflen -= stream.read(tmpbuffer,0, bufflen);
442.101 + }
442.102 + }
442.103 +
442.104 + public VoiceStatus findVoice(int channel, int note) {
442.105 + VoiceStatus[] v = synth.getVoiceStatus();
442.106 + for (int k = 0; k < v.length; k++)
442.107 + if(v[k].active)
442.108 + if(v[k].channel == channel)
442.109 + if(v[k].note == note)
442.110 + return v[k];
442.111 + return null;
442.112 + }
442.113 +
442.114 +}
443.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
443.2 +++ b/test/javax/sound/midi/Gervill/SoftSincResampler/Interpolate.java Tue Feb 03 22:02:55 2009 -0800
443.3 @@ -0,0 +1,113 @@
443.4 +/*
443.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
443.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
443.7 + *
443.8 + * This code is free software; you can redistribute it and/or modify it
443.9 + * under the terms of the GNU General Public License version 2 only, as
443.10 + * published by the Free Software Foundation. Sun designates this
443.11 + * particular file as subject to the "Classpath" exception as provided
443.12 + * by Sun in the LICENSE file that accompanied this code.
443.13 + *
443.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
443.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
443.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
443.17 + * version 2 for more details (a copy is included in the LICENSE file that
443.18 + * accompanied this code).
443.19 + *
443.20 + * You should have received a copy of the GNU General Public License version
443.21 + * 2 along with this work; if not, write to the Free Software Foundation,
443.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
443.23 + *
443.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
443.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
443.26 + * have any questions.
443.27 + */
443.28 +
443.29 +/* @test
443.30 + @summary Test SoftSincResampler interpolate method */
443.31 +
443.32 +import java.io.File;
443.33 +import java.io.FileOutputStream;
443.34 +import java.io.IOException;
443.35 +
443.36 +import javax.sound.sampled.*;
443.37 +
443.38 +import com.sun.media.sound.*;
443.39 +
443.40 +public class Interpolate {
443.41 +
443.42 + private static float getResamplerTestValue(double i)
443.43 + {
443.44 + return (float)Math.sin(i / 10.0);
443.45 + }
443.46 +
443.47 + private static void perfectInterpolation(float[] in_offset, float in_end,
443.48 + float[] startpitch, float pitchstep, float[] out, int[] out_offset,
443.49 + int out_end) {
443.50 +
443.51 + float pitch = startpitch[0];
443.52 + float ix = in_offset[0];
443.53 + int ox = out_offset[0];
443.54 + float ix_end = in_end;
443.55 + int ox_end = out_end;
443.56 + if (pitchstep == 0f) {
443.57 + while (ix < ix_end && ox < ox_end) {
443.58 + out[ox++] = getResamplerTestValue(ix);
443.59 + ix += pitch;
443.60 + }
443.61 + } else {
443.62 + while (ix < ix_end && ox < ox_end) {
443.63 + out[ox++] = getResamplerTestValue(ix);
443.64 + ix += pitch;
443.65 + pitch += pitchstep;
443.66 + }
443.67 + }
443.68 + in_offset[0] = ix;
443.69 + out_offset[0] = ox;
443.70 + startpitch[0] = pitch;
443.71 +
443.72 + }
443.73 +
443.74 + private static float testResampler(SoftAbstractResampler resampler, float p_pitch, float p_pitch2)
443.75 + {
443.76 + float[] testbuffer = new float[4096];
443.77 + float[] testbuffer2 = new float[1024];
443.78 + float[] testbuffer3 = new float[1024];
443.79 + for (int i = 0; i < testbuffer.length; i++)
443.80 + testbuffer[i] = getResamplerTestValue(i);
443.81 + int pads = resampler.getPadding();
443.82 + float pitchstep = (p_pitch2 - p_pitch)/1024f;
443.83 + int[] out_offset2 = {0};
443.84 + int[] out_offset3 = {0};
443.85 + resampler.interpolate(testbuffer, new float[] {pads}, testbuffer.length - pads, new float[] {p_pitch}, pitchstep, testbuffer2, out_offset2, testbuffer2.length);
443.86 + perfectInterpolation(new float[] {pads}, testbuffer.length - pads, new float[] {p_pitch}, pitchstep, testbuffer3, out_offset3, testbuffer3.length);
443.87 + int out_off = out_offset2[0];
443.88 + if(out_offset3[0] < out_off)
443.89 + out_off = out_offset3[0];
443.90 + float ac_error = 0;
443.91 + int counter = 0;
443.92 + for (int i = pads; i < out_off; i++) {
443.93 + ac_error += Math.abs(testbuffer2[i] - testbuffer3[i]);
443.94 + counter++;
443.95 + }
443.96 + return ac_error / ((float)counter);
443.97 + }
443.98 +
443.99 + private static void fail(String error) throws Exception
443.100 + {
443.101 + throw new RuntimeException(error);
443.102 + }
443.103 +
443.104 + public static void main(String[] args) throws Exception {
443.105 + SoftSincResampler resampler = new SoftSincResampler();
443.106 + float max = testResampler(resampler, 0.3f, 0.3f);
443.107 + if(max > 0.0001)
443.108 + fail("Interpolation failed, error="+max);
443.109 + max = testResampler(resampler, 0.3f, 0.01f);
443.110 + if(max > 0.0001)
443.111 + fail("Interpolation failed, error="+max);
443.112 + max = testResampler(resampler, 1.0f, 0.00f);
443.113 + if(max > 0.0001)
443.114 + fail("Interpolation failed, error="+max);
443.115 + }
443.116 +}
443.117 \ No newline at end of file
444.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
444.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/Close.java Tue Feb 03 22:02:55 2009 -0800
444.3 @@ -0,0 +1,58 @@
444.4 +/*
444.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
444.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
444.7 + *
444.8 + * This code is free software; you can redistribute it and/or modify it
444.9 + * under the terms of the GNU General Public License version 2 only, as
444.10 + * published by the Free Software Foundation. Sun designates this
444.11 + * particular file as subject to the "Classpath" exception as provided
444.12 + * by Sun in the LICENSE file that accompanied this code.
444.13 + *
444.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
444.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
444.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
444.17 + * version 2 for more details (a copy is included in the LICENSE file that
444.18 + * accompanied this code).
444.19 + *
444.20 + * You should have received a copy of the GNU General Public License version
444.21 + * 2 along with this work; if not, write to the Free Software Foundation,
444.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
444.23 + *
444.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
444.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
444.26 + * have any questions.
444.27 + */
444.28 +
444.29 +/* @test
444.30 + @summary Test SoftSynthesizer close method */
444.31 +
444.32 +import javax.sound.midi.MidiDevice;
444.33 +import javax.sound.midi.MidiUnavailableException;
444.34 +import javax.sound.midi.Patch;
444.35 +import javax.sound.sampled.*;
444.36 +import javax.sound.midi.MidiDevice.Info;
444.37 +
444.38 +import com.sun.media.sound.*;
444.39 +
444.40 +public class Close {
444.41 +
444.42 + private static void assertEquals(Object a, Object b) throws Exception
444.43 + {
444.44 + if(!a.equals(b))
444.45 + throw new RuntimeException("assertEquals fails!");
444.46 + }
444.47 +
444.48 + private static void assertTrue(boolean value) throws Exception
444.49 + {
444.50 + if(!value)
444.51 + throw new RuntimeException("assertTrue fails!");
444.52 + }
444.53 +
444.54 + public static void main(String[] args) throws Exception {
444.55 + AudioSynthesizer synth = new SoftSynthesizer();
444.56 + synth.openStream(null, null);
444.57 + synth.close();
444.58 + assertTrue(!synth.isOpen());
444.59 +
444.60 + }
444.61 +}
445.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
445.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/DummySourceDataLine.java Tue Feb 03 22:02:55 2009 -0800
445.3 @@ -0,0 +1,232 @@
445.4 +/*
445.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
445.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
445.7 + *
445.8 + * This code is free software; you can redistribute it and/or modify it
445.9 + * under the terms of the GNU General Public License version 2 only, as
445.10 + * published by the Free Software Foundation. Sun designates this
445.11 + * particular file as subject to the "Classpath" exception as provided
445.12 + * by Sun in the LICENSE file that accompanied this code.
445.13 + *
445.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
445.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
445.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
445.17 + * version 2 for more details (a copy is included in the LICENSE file that
445.18 + * accompanied this code).
445.19 + *
445.20 + * You should have received a copy of the GNU General Public License version
445.21 + * 2 along with this work; if not, write to the Free Software Foundation,
445.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
445.23 + *
445.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
445.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
445.26 + * have any questions.
445.27 + */
445.28 +
445.29 +import java.util.ArrayList;
445.30 +
445.31 +import javax.sound.sampled.AudioFormat;
445.32 +import javax.sound.sampled.AudioSystem;
445.33 +import javax.sound.sampled.Control;
445.34 +import javax.sound.sampled.DataLine;
445.35 +import javax.sound.sampled.LineListener;
445.36 +import javax.sound.sampled.LineUnavailableException;
445.37 +import javax.sound.sampled.SourceDataLine;
445.38 +import javax.sound.sampled.AudioFormat.Encoding;
445.39 +import javax.sound.sampled.Control.Type;
445.40 +
445.41 +import com.sun.media.sound.AudioFloatConverter;
445.42 +
445.43 +/**
445.44 + * This is a SourceDataLine simulator used for testing SoftSynthesizer
445.45 + * without using real SourceDataLine / Audio Device.
445.46 + *
445.47 + * @author Karl Helgason
445.48 + */
445.49 +
445.50 +public class DummySourceDataLine implements SourceDataLine {
445.51 +
445.52 + private int bufferSize = -1;
445.53 +
445.54 + private AudioFormat format = new AudioFormat(44100.0f, 16, 2, true, false);
445.55 +
445.56 + private DataLine.Info sourceLineInfo;
445.57 +
445.58 + private boolean active = false;
445.59 +
445.60 + private long framepos = 0;
445.61 +
445.62 + private boolean opened = false;
445.63 +
445.64 + private int framesize = 0;
445.65 +
445.66 + public DummySourceDataLine()
445.67 + {
445.68 + ArrayList<AudioFormat> formats = new ArrayList<AudioFormat>();
445.69 + for (int channels = 1; channels <= 2; channels++) {
445.70 + formats.add(new AudioFormat(Encoding.PCM_SIGNED,
445.71 + AudioSystem.NOT_SPECIFIED, 8, channels, channels,
445.72 + AudioSystem.NOT_SPECIFIED, false));
445.73 + formats.add(new AudioFormat(Encoding.PCM_UNSIGNED,
445.74 + AudioSystem.NOT_SPECIFIED, 8, channels, channels,
445.75 + AudioSystem.NOT_SPECIFIED, false));
445.76 + for (int bits = 16; bits < 32; bits += 8) {
445.77 + formats.add(new AudioFormat(Encoding.PCM_SIGNED,
445.78 + AudioSystem.NOT_SPECIFIED, bits, channels, channels
445.79 + * bits / 8, AudioSystem.NOT_SPECIFIED, false));
445.80 + formats.add(new AudioFormat(Encoding.PCM_UNSIGNED,
445.81 + AudioSystem.NOT_SPECIFIED, bits, channels, channels
445.82 + * bits / 8, AudioSystem.NOT_SPECIFIED, false));
445.83 + formats.add(new AudioFormat(Encoding.PCM_SIGNED,
445.84 + AudioSystem.NOT_SPECIFIED, bits, channels, channels
445.85 + * bits / 8, AudioSystem.NOT_SPECIFIED, true));
445.86 + formats.add(new AudioFormat(Encoding.PCM_UNSIGNED,
445.87 + AudioSystem.NOT_SPECIFIED, bits, channels, channels
445.88 + * bits / 8, AudioSystem.NOT_SPECIFIED, true));
445.89 + }
445.90 + formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT,
445.91 + AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4,
445.92 + AudioSystem.NOT_SPECIFIED, false));
445.93 + formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT,
445.94 + AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4,
445.95 + AudioSystem.NOT_SPECIFIED, true));
445.96 + formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT,
445.97 + AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8,
445.98 + AudioSystem.NOT_SPECIFIED, false));
445.99 + formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT,
445.100 + AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8,
445.101 + AudioSystem.NOT_SPECIFIED, true));
445.102 + }
445.103 + AudioFormat[] formats_array = formats.toArray(new AudioFormat[formats
445.104 + .size()]);
445.105 + sourceLineInfo = new DataLine.Info(SourceDataLine.class,
445.106 + formats_array, AudioSystem.NOT_SPECIFIED,
445.107 + AudioSystem.NOT_SPECIFIED);
445.108 +
445.109 + }
445.110 +
445.111 + public void open() throws LineUnavailableException {
445.112 + open(format);
445.113 + }
445.114 +
445.115 + public void open(AudioFormat format) throws LineUnavailableException {
445.116 + if (bufferSize == -1)
445.117 + bufferSize = ((int) (format.getFrameRate() / 2))
445.118 + * format.getFrameSize();
445.119 + open(format, bufferSize);
445.120 + }
445.121 +
445.122 + public void open(AudioFormat format, int bufferSize)
445.123 + throws LineUnavailableException {
445.124 + this.format = format;
445.125 + this.bufferSize = bufferSize;
445.126 + this.framesize = format.getFrameSize();
445.127 + opened = true;
445.128 + }
445.129 +
445.130 + public boolean isOpen() {
445.131 + return opened;
445.132 + }
445.133 +
445.134 + public int write(byte[] b, int off, int len) {
445.135 + if (!isOpen())
445.136 + return 0;
445.137 + if (len % framesize != 0)
445.138 + throw new IllegalArgumentException(
445.139 + "Number of bytes does not represent an integral number of sample frames.");
445.140 +
445.141 +
445.142 + int flen = len / framesize;
445.143 + framepos += flen;
445.144 +
445.145 + long time = (long) (flen * (1000.0 / (double) getFormat()
445.146 + .getSampleRate()));
445.147 + try {
445.148 + Thread.sleep(time);
445.149 + } catch (InterruptedException e) {
445.150 + e.printStackTrace();
445.151 + return 0;
445.152 + }
445.153 +
445.154 + return len;
445.155 + }
445.156 +
445.157 + public int available() {
445.158 + return 0;
445.159 + }
445.160 +
445.161 + public void drain() {
445.162 + }
445.163 +
445.164 + public void flush() {
445.165 + }
445.166 +
445.167 + public int getBufferSize() {
445.168 + return bufferSize;
445.169 + }
445.170 +
445.171 + public AudioFormat getFormat() {
445.172 + return format;
445.173 + }
445.174 +
445.175 + public int getFramePosition() {
445.176 + return (int) getLongFramePosition();
445.177 + }
445.178 +
445.179 + public float getLevel() {
445.180 + return AudioSystem.NOT_SPECIFIED;
445.181 + }
445.182 +
445.183 + public long getLongFramePosition() {
445.184 + return framepos;
445.185 + }
445.186 +
445.187 + public long getMicrosecondPosition() {
445.188 + return (long) (getLongFramePosition() * (1000000.0 / (double) getFormat()
445.189 + .getSampleRate()));
445.190 + }
445.191 +
445.192 + public boolean isActive() {
445.193 + return active;
445.194 + }
445.195 +
445.196 + public boolean isRunning() {
445.197 + return active;
445.198 + }
445.199 +
445.200 + public void start() {
445.201 + active = true;
445.202 + }
445.203 +
445.204 + public void stop() {
445.205 + active = false;
445.206 + }
445.207 +
445.208 + public void close() {
445.209 + stop();
445.210 + }
445.211 +
445.212 + public Control getControl(Type control) {
445.213 + throw new IllegalArgumentException("Unsupported control type : "
445.214 + + control);
445.215 + }
445.216 +
445.217 + public Control[] getControls() {
445.218 + return new Control[0];
445.219 + }
445.220 +
445.221 + public javax.sound.sampled.Line.Info getLineInfo() {
445.222 + return sourceLineInfo;
445.223 + }
445.224 +
445.225 + public boolean isControlSupported(Type control) {
445.226 + return false;
445.227 + }
445.228 +
445.229 + public void addLineListener(LineListener listener) {
445.230 + }
445.231 +
445.232 + public void removeLineListener(LineListener listener) {
445.233 + }
445.234 +
445.235 +}
446.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
446.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/GetAvailableInstruments.java Tue Feb 03 22:02:55 2009 -0800
446.3 @@ -0,0 +1,63 @@
446.4 +/*
446.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
446.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
446.7 + *
446.8 + * This code is free software; you can redistribute it and/or modify it
446.9 + * under the terms of the GNU General Public License version 2 only, as
446.10 + * published by the Free Software Foundation. Sun designates this
446.11 + * particular file as subject to the "Classpath" exception as provided
446.12 + * by Sun in the LICENSE file that accompanied this code.
446.13 + *
446.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
446.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
446.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
446.17 + * version 2 for more details (a copy is included in the LICENSE file that
446.18 + * accompanied this code).
446.19 + *
446.20 + * You should have received a copy of the GNU General Public License version
446.21 + * 2 along with this work; if not, write to the Free Software Foundation,
446.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
446.23 + *
446.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
446.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
446.26 + * have any questions.
446.27 + */
446.28 +
446.29 +/* @test
446.30 + @summary Test SoftSynthesizer getAvailableInstruments method */
446.31 +
446.32 +import javax.sound.midi.MidiDevice;
446.33 +import javax.sound.midi.MidiUnavailableException;
446.34 +import javax.sound.midi.Patch;
446.35 +import javax.sound.midi.Soundbank;
446.36 +import javax.sound.sampled.*;
446.37 +import javax.sound.midi.MidiDevice.Info;
446.38 +
446.39 +import com.sun.media.sound.*;
446.40 +
446.41 +public class GetAvailableInstruments {
446.42 +
446.43 + private static void assertEquals(Object a, Object b) throws Exception
446.44 + {
446.45 + if(!a.equals(b))
446.46 + throw new RuntimeException("assertEquals fails!");
446.47 + }
446.48 +
446.49 + private static void assertTrue(boolean value) throws Exception
446.50 + {
446.51 + if(!value)
446.52 + throw new RuntimeException("assertTrue fails!");
446.53 + }
446.54 +
446.55 + public static void main(String[] args) throws Exception {
446.56 + AudioSynthesizer synth = new SoftSynthesizer();
446.57 + synth.openStream(null, null);
446.58 + Soundbank defsbk = synth.getDefaultSoundbank();
446.59 + if(defsbk != null)
446.60 + {
446.61 + assertTrue(defsbk.getInstruments().length == synth.getAvailableInstruments().length);
446.62 + }
446.63 + synth.close();
446.64 +
446.65 + }
446.66 +}
447.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
447.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/GetChannels.java Tue Feb 03 22:02:55 2009 -0800
447.3 @@ -0,0 +1,64 @@
447.4 +/*
447.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
447.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
447.7 + *
447.8 + * This code is free software; you can redistribute it and/or modify it
447.9 + * under the terms of the GNU General Public License version 2 only, as
447.10 + * published by the Free Software Foundation. Sun designates this
447.11 + * particular file as subject to the "Classpath" exception as provided
447.12 + * by Sun in the LICENSE file that accompanied this code.
447.13 + *
447.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
447.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
447.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
447.17 + * version 2 for more details (a copy is included in the LICENSE file that
447.18 + * accompanied this code).
447.19 + *
447.20 + * You should have received a copy of the GNU General Public License version
447.21 + * 2 along with this work; if not, write to the Free Software Foundation,
447.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
447.23 + *
447.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
447.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
447.26 + * have any questions.
447.27 + */
447.28 +
447.29 +/* @test
447.30 + @summary Test SoftSynthesizer getChannels method */
447.31 +
447.32 +import javax.sound.midi.MidiChannel;
447.33 +import javax.sound.midi.MidiDevice;
447.34 +import javax.sound.midi.MidiUnavailableException;
447.35 +import javax.sound.midi.Patch;
447.36 +import javax.sound.sampled.*;
447.37 +import javax.sound.midi.MidiDevice.Info;
447.38 +
447.39 +import com.sun.media.sound.*;
447.40 +
447.41 +public class GetChannels {
447.42 +
447.43 + private static void assertEquals(Object a, Object b) throws Exception
447.44 + {
447.45 + if(!a.equals(b))
447.46 + throw new RuntimeException("assertEquals fails!");
447.47 + }
447.48 +
447.49 + private static void assertTrue(boolean value) throws Exception
447.50 + {
447.51 + if(!value)
447.52 + throw new RuntimeException("assertTrue fails!");
447.53 + }
447.54 +
447.55 + public static void main(String[] args) throws Exception {
447.56 + AudioSynthesizer synth = new SoftSynthesizer();
447.57 + synth.openStream(null, null);
447.58 + assertTrue(synth.getChannels() != null);
447.59 + assertTrue(synth.getChannels().length == 16);
447.60 + MidiChannel[] channels = synth.getChannels();
447.61 + for (int i = 0; i < channels.length; i++) {
447.62 + assertTrue(channels[i] != null);
447.63 + }
447.64 + synth.close();
447.65 +
447.66 + }
447.67 +}
448.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
448.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/GetDefaultSoundbank.java Tue Feb 03 22:02:55 2009 -0800
448.3 @@ -0,0 +1,58 @@
448.4 +/*
448.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
448.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
448.7 + *
448.8 + * This code is free software; you can redistribute it and/or modify it
448.9 + * under the terms of the GNU General Public License version 2 only, as
448.10 + * published by the Free Software Foundation. Sun designates this
448.11 + * particular file as subject to the "Classpath" exception as provided
448.12 + * by Sun in the LICENSE file that accompanied this code.
448.13 + *
448.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
448.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
448.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
448.17 + * version 2 for more details (a copy is included in the LICENSE file that
448.18 + * accompanied this code).
448.19 + *
448.20 + * You should have received a copy of the GNU General Public License version
448.21 + * 2 along with this work; if not, write to the Free Software Foundation,
448.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
448.23 + *
448.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
448.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
448.26 + * have any questions.
448.27 + */
448.28 +
448.29 +/* @test
448.30 + @summary Test SoftSynthesizer getDefaultSoundbank method */
448.31 +
448.32 +import javax.sound.midi.MidiDevice;
448.33 +import javax.sound.midi.MidiUnavailableException;
448.34 +import javax.sound.midi.Patch;
448.35 +import javax.sound.sampled.*;
448.36 +import javax.sound.midi.MidiDevice.Info;
448.37 +
448.38 +import com.sun.media.sound.*;
448.39 +
448.40 +public class GetDefaultSoundbank {
448.41 +
448.42 + private static void assertEquals(Object a, Object b) throws Exception
448.43 + {
448.44 + if(!a.equals(b))
448.45 + throw new RuntimeException("assertEquals fails!");
448.46 + }
448.47 +
448.48 + private static void assertTrue(boolean value) throws Exception
448.49 + {
448.50 + if(!value)
448.51 + throw new RuntimeException("assertTrue fails!");
448.52 + }
448.53 +
448.54 + public static void main(String[] args) throws Exception {
448.55 + AudioSynthesizer synth = new SoftSynthesizer();
448.56 + synth.openStream(null, null);
448.57 + assertTrue(synth.getDefaultSoundbank() != null);
448.58 + synth.close();
448.59 +
448.60 + }
448.61 +}
449.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
449.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/GetDeviceInfo.java Tue Feb 03 22:02:55 2009 -0800
449.3 @@ -0,0 +1,56 @@
449.4 +/*
449.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
449.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
449.7 + *
449.8 + * This code is free software; you can redistribute it and/or modify it
449.9 + * under the terms of the GNU General Public License version 2 only, as
449.10 + * published by the Free Software Foundation. Sun designates this
449.11 + * particular file as subject to the "Classpath" exception as provided
449.12 + * by Sun in the LICENSE file that accompanied this code.
449.13 + *
449.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
449.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
449.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
449.17 + * version 2 for more details (a copy is included in the LICENSE file that
449.18 + * accompanied this code).
449.19 + *
449.20 + * You should have received a copy of the GNU General Public License version
449.21 + * 2 along with this work; if not, write to the Free Software Foundation,
449.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
449.23 + *
449.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
449.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
449.26 + * have any questions.
449.27 + */
449.28 +
449.29 +/* @test
449.30 + @summary Test SoftSynthesizer getDeviceInfo method */
449.31 +
449.32 +import javax.sound.midi.MidiDevice;
449.33 +import javax.sound.midi.MidiUnavailableException;
449.34 +import javax.sound.midi.Patch;
449.35 +import javax.sound.sampled.*;
449.36 +import javax.sound.midi.MidiDevice.Info;
449.37 +
449.38 +import com.sun.media.sound.*;
449.39 +
449.40 +public class GetDeviceInfo {
449.41 +
449.42 + private static void assertEquals(Object a, Object b) throws Exception
449.43 + {
449.44 + if(!a.equals(b))
449.45 + throw new RuntimeException("assertEquals fails!");
449.46 + }
449.47 +
449.48 + private static void assertTrue(boolean value) throws Exception
449.49 + {
449.50 + if(!value)
449.51 + throw new RuntimeException("assertTrue fails!");
449.52 + }
449.53 +
449.54 + public static void main(String[] args) throws Exception {
449.55 + AudioSynthesizer synth = new SoftSynthesizer();
449.56 + assertTrue(synth.getDeviceInfo() != null);
449.57 +
449.58 + }
449.59 +}
450.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
450.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/GetLatency.java Tue Feb 03 22:02:55 2009 -0800
450.3 @@ -0,0 +1,58 @@
450.4 +/*
450.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
450.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
450.7 + *
450.8 + * This code is free software; you can redistribute it and/or modify it
450.9 + * under the terms of the GNU General Public License version 2 only, as
450.10 + * published by the Free Software Foundation. Sun designates this
450.11 + * particular file as subject to the "Classpath" exception as provided
450.12 + * by Sun in the LICENSE file that accompanied this code.
450.13 + *
450.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
450.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
450.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
450.17 + * version 2 for more details (a copy is included in the LICENSE file that
450.18 + * accompanied this code).
450.19 + *
450.20 + * You should have received a copy of the GNU General Public License version
450.21 + * 2 along with this work; if not, write to the Free Software Foundation,
450.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
450.23 + *
450.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
450.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
450.26 + * have any questions.
450.27 + */
450.28 +
450.29 +/* @test
450.30 + @summary Test SoftSynthesizer getLatency method */
450.31 +
450.32 +import javax.sound.midi.MidiDevice;
450.33 +import javax.sound.midi.MidiUnavailableException;
450.34 +import javax.sound.midi.Patch;
450.35 +import javax.sound.sampled.*;
450.36 +import javax.sound.midi.MidiDevice.Info;
450.37 +
450.38 +import com.sun.media.sound.*;
450.39 +
450.40 +public class GetLatency {
450.41 +
450.42 + private static void assertEquals(Object a, Object b) throws Exception
450.43 + {
450.44 + if(!a.equals(b))
450.45 + throw new RuntimeException("assertEquals fails!");
450.46 + }
450.47 +
450.48 + private static void assertTrue(boolean value) throws Exception
450.49 + {
450.50 + if(!value)
450.51 + throw new RuntimeException("assertTrue fails!");
450.52 + }
450.53 +
450.54 + public static void main(String[] args) throws Exception {
450.55 + AudioSynthesizer synth = new SoftSynthesizer();
450.56 + synth.open(new DummySourceDataLine(), null);
450.57 + assertTrue(synth.getLatency() != -1);
450.58 + synth.close();
450.59 +
450.60 + }
450.61 +}
451.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
451.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/GetLoadedInstruments.java Tue Feb 03 22:02:55 2009 -0800
451.3 @@ -0,0 +1,65 @@
451.4 +/*
451.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
451.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
451.7 + *
451.8 + * This code is free software; you can redistribute it and/or modify it
451.9 + * under the terms of the GNU General Public License version 2 only, as
451.10 + * published by the Free Software Foundation. Sun designates this
451.11 + * particular file as subject to the "Classpath" exception as provided
451.12 + * by Sun in the LICENSE file that accompanied this code.
451.13 + *
451.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
451.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
451.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
451.17 + * version 2 for more details (a copy is included in the LICENSE file that
451.18 + * accompanied this code).
451.19 + *
451.20 + * You should have received a copy of the GNU General Public License version
451.21 + * 2 along with this work; if not, write to the Free Software Foundation,
451.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
451.23 + *
451.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
451.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
451.26 + * have any questions.
451.27 + */
451.28 +
451.29 +/* @test
451.30 + @summary Test SoftSynthesizer getLoadedInstruments method */
451.31 +
451.32 +import javax.sound.midi.MidiDevice;
451.33 +import javax.sound.midi.MidiUnavailableException;
451.34 +import javax.sound.midi.Patch;
451.35 +import javax.sound.midi.Soundbank;
451.36 +import javax.sound.sampled.*;
451.37 +import javax.sound.midi.MidiDevice.Info;
451.38 +
451.39 +import com.sun.media.sound.*;
451.40 +
451.41 +public class GetLoadedInstruments {
451.42 +
451.43 + private static void assertEquals(Object a, Object b) throws Exception
451.44 + {
451.45 + if(!a.equals(b))
451.46 + throw new RuntimeException("assertEquals fails!");
451.47 + }
451.48 +
451.49 + private static void assertTrue(boolean value) throws Exception
451.50 + {
451.51 + if(!value)
451.52 + throw new RuntimeException("assertTrue fails!");
451.53 + }
451.54 +
451.55 + public static void main(String[] args) throws Exception {
451.56 + AudioSynthesizer synth = new SoftSynthesizer();
451.57 + synth.openStream(null, null);
451.58 + Soundbank defsbk = synth.getDefaultSoundbank();
451.59 + if(defsbk != null)
451.60 + {
451.61 + synth.unloadAllInstruments(defsbk);
451.62 + synth.loadAllInstruments(defsbk);
451.63 + assertTrue(synth.getLoadedInstruments().length != 0);
451.64 + }
451.65 + synth.close();
451.66 +
451.67 + }
451.68 +}
452.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
452.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/GetMaxPolyphony.java Tue Feb 03 22:02:55 2009 -0800
452.3 @@ -0,0 +1,58 @@
452.4 +/*
452.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
452.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
452.7 + *
452.8 + * This code is free software; you can redistribute it and/or modify it
452.9 + * under the terms of the GNU General Public License version 2 only, as
452.10 + * published by the Free Software Foundation. Sun designates this
452.11 + * particular file as subject to the "Classpath" exception as provided
452.12 + * by Sun in the LICENSE file that accompanied this code.
452.13 + *
452.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
452.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
452.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
452.17 + * version 2 for more details (a copy is included in the LICENSE file that
452.18 + * accompanied this code).
452.19 + *
452.20 + * You should have received a copy of the GNU General Public License version
452.21 + * 2 along with this work; if not, write to the Free Software Foundation,
452.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
452.23 + *
452.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
452.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
452.26 + * have any questions.
452.27 + */
452.28 +
452.29 +/* @test
452.30 + @summary Test SoftSynthesizer getMaxPolyphony method */
452.31 +
452.32 +import javax.sound.midi.MidiDevice;
452.33 +import javax.sound.midi.MidiUnavailableException;
452.34 +import javax.sound.midi.Patch;
452.35 +import javax.sound.sampled.*;
452.36 +import javax.sound.midi.MidiDevice.Info;
452.37 +
452.38 +import com.sun.media.sound.*;
452.39 +
452.40 +public class GetMaxPolyphony {
452.41 +
452.42 + private static void assertEquals(Object a, Object b) throws Exception
452.43 + {
452.44 + if(!a.equals(b))
452.45 + throw new RuntimeException("assertEquals fails!");
452.46 + }
452.47 +
452.48 + private static void assertTrue(boolean value) throws Exception
452.49 + {
452.50 + if(!value)
452.51 + throw new RuntimeException("assertTrue fails!");
452.52 + }
452.53 +
452.54 + public static void main(String[] args) throws Exception {
452.55 + AudioSynthesizer synth = new SoftSynthesizer();
452.56 + synth.openStream(null, null);
452.57 + assertTrue(synth.getMaxPolyphony() != -1);
452.58 + synth.close();
452.59 +
452.60 + }
452.61 +}
453.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
453.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/GetMaxReceivers.java Tue Feb 03 22:02:55 2009 -0800
453.3 @@ -0,0 +1,56 @@
453.4 +/*
453.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
453.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
453.7 + *
453.8 + * This code is free software; you can redistribute it and/or modify it
453.9 + * under the terms of the GNU General Public License version 2 only, as
453.10 + * published by the Free Software Foundation. Sun designates this
453.11 + * particular file as subject to the "Classpath" exception as provided
453.12 + * by Sun in the LICENSE file that accompanied this code.
453.13 + *
453.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
453.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
453.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
453.17 + * version 2 for more details (a copy is included in the LICENSE file that
453.18 + * accompanied this code).
453.19 + *
453.20 + * You should have received a copy of the GNU General Public License version
453.21 + * 2 along with this work; if not, write to the Free Software Foundation,
453.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
453.23 + *
453.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
453.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
453.26 + * have any questions.
453.27 + */
453.28 +
453.29 +/* @test
453.30 + @summary Test SoftSynthesizer getMaxReceivers method */
453.31 +
453.32 +import javax.sound.midi.MidiDevice;
453.33 +import javax.sound.midi.MidiUnavailableException;
453.34 +import javax.sound.midi.Patch;
453.35 +import javax.sound.sampled.*;
453.36 +import javax.sound.midi.MidiDevice.Info;
453.37 +
453.38 +import com.sun.media.sound.*;
453.39 +
453.40 +public class GetMaxReceivers {
453.41 +
453.42 + private static void assertEquals(Object a, Object b) throws Exception
453.43 + {
453.44 + if(!a.equals(b))
453.45 + throw new RuntimeException("assertEquals fails!");
453.46 + }
453.47 +
453.48 + private static void assertTrue(boolean value) throws Exception
453.49 + {
453.50 + if(!value)
453.51 + throw new RuntimeException("assertTrue fails!");
453.52 + }
453.53 +
453.54 + public static void main(String[] args) throws Exception {
453.55 + AudioSynthesizer synth = new SoftSynthesizer();
453.56 + assertTrue(synth.getMaxReceivers() == -1);
453.57 +
453.58 + }
453.59 +}
454.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
454.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/GetMaxTransmitters.java Tue Feb 03 22:02:55 2009 -0800
454.3 @@ -0,0 +1,56 @@
454.4 +/*
454.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
454.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
454.7 + *
454.8 + * This code is free software; you can redistribute it and/or modify it
454.9 + * under the terms of the GNU General Public License version 2 only, as
454.10 + * published by the Free Software Foundation. Sun designates this
454.11 + * particular file as subject to the "Classpath" exception as provided
454.12 + * by Sun in the LICENSE file that accompanied this code.
454.13 + *
454.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
454.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
454.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
454.17 + * version 2 for more details (a copy is included in the LICENSE file that
454.18 + * accompanied this code).
454.19 + *
454.20 + * You should have received a copy of the GNU General Public License version
454.21 + * 2 along with this work; if not, write to the Free Software Foundation,
454.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
454.23 + *
454.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
454.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
454.26 + * have any questions.
454.27 + */
454.28 +
454.29 +/* @test
454.30 + @summary Test SoftSynthesizer getMaxTransmitters method */
454.31 +
454.32 +import javax.sound.midi.MidiDevice;
454.33 +import javax.sound.midi.MidiUnavailableException;
454.34 +import javax.sound.midi.Patch;
454.35 +import javax.sound.sampled.*;
454.36 +import javax.sound.midi.MidiDevice.Info;
454.37 +
454.38 +import com.sun.media.sound.*;
454.39 +
454.40 +public class GetMaxTransmitters {
454.41 +
454.42 + private static void assertEquals(Object a, Object b) throws Exception
454.43 + {
454.44 + if(!a.equals(b))
454.45 + throw new RuntimeException("assertEquals fails!");
454.46 + }
454.47 +
454.48 + private static void assertTrue(boolean value) throws Exception
454.49 + {
454.50 + if(!value)
454.51 + throw new RuntimeException("assertTrue fails!");
454.52 + }
454.53 +
454.54 + public static void main(String[] args) throws Exception {
454.55 + AudioSynthesizer synth = new SoftSynthesizer();
454.56 + assertTrue(synth.getMaxTransmitters() == 0);
454.57 +
454.58 + }
454.59 +}
455.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
455.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/GetMicrosecondPosition.java Tue Feb 03 22:02:55 2009 -0800
455.3 @@ -0,0 +1,64 @@
455.4 +/*
455.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
455.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
455.7 + *
455.8 + * This code is free software; you can redistribute it and/or modify it
455.9 + * under the terms of the GNU General Public License version 2 only, as
455.10 + * published by the Free Software Foundation. Sun designates this
455.11 + * particular file as subject to the "Classpath" exception as provided
455.12 + * by Sun in the LICENSE file that accompanied this code.
455.13 + *
455.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
455.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
455.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
455.17 + * version 2 for more details (a copy is included in the LICENSE file that
455.18 + * accompanied this code).
455.19 + *
455.20 + * You should have received a copy of the GNU General Public License version
455.21 + * 2 along with this work; if not, write to the Free Software Foundation,
455.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
455.23 + *
455.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
455.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
455.26 + * have any questions.
455.27 + */
455.28 +
455.29 +/* @test
455.30 + @summary Test SoftSynthesizer getMicrosecondPosition method */
455.31 +
455.32 +import java.io.IOException;
455.33 +
455.34 +import javax.sound.midi.MidiDevice;
455.35 +import javax.sound.midi.MidiUnavailableException;
455.36 +import javax.sound.midi.Patch;
455.37 +import javax.sound.sampled.*;
455.38 +import javax.sound.midi.MidiDevice.Info;
455.39 +
455.40 +import com.sun.media.sound.*;
455.41 +
455.42 +public class GetMicrosecondPosition {
455.43 +
455.44 + private static void assertEquals(Object a, Object b) throws Exception
455.45 + {
455.46 + if(!a.equals(b))
455.47 + throw new RuntimeException("assertEquals fails!");
455.48 + }
455.49 +
455.50 + private static void assertTrue(boolean value) throws Exception
455.51 + {
455.52 + if(!value)
455.53 + throw new RuntimeException("assertTrue fails!");
455.54 + }
455.55 +
455.56 + public static void main(String[] args) throws Exception {
455.57 + AudioSynthesizer synth = new SoftSynthesizer();
455.58 + AudioInputStream stream = synth.openStream(null, null);
455.59 + assertTrue(synth.getMicrosecondPosition() == 0);
455.60 + AudioFormat format = stream.getFormat();
455.61 + byte[] buff = new byte[((int)format.getFrameRate())*format.getFrameSize()];;
455.62 + stream.read(buff);
455.63 + assertTrue(Math.abs(synth.getMicrosecondPosition()-1000000) < 10000);
455.64 + synth.close();
455.65 +
455.66 + }
455.67 +}
456.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
456.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/GetReceiver.java Tue Feb 03 22:02:55 2009 -0800
456.3 @@ -0,0 +1,63 @@
456.4 +/*
456.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
456.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
456.7 + *
456.8 + * This code is free software; you can redistribute it and/or modify it
456.9 + * under the terms of the GNU General Public License version 2 only, as
456.10 + * published by the Free Software Foundation. Sun designates this
456.11 + * particular file as subject to the "Classpath" exception as provided
456.12 + * by Sun in the LICENSE file that accompanied this code.
456.13 + *
456.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
456.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
456.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
456.17 + * version 2 for more details (a copy is included in the LICENSE file that
456.18 + * accompanied this code).
456.19 + *
456.20 + * You should have received a copy of the GNU General Public License version
456.21 + * 2 along with this work; if not, write to the Free Software Foundation,
456.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
456.23 + *
456.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
456.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
456.26 + * have any questions.
456.27 + */
456.28 +
456.29 +/* @test
456.30 + @summary Test SoftSynthesizer getReceiver method */
456.31 +
456.32 +import javax.sound.midi.MidiDevice;
456.33 +import javax.sound.midi.MidiUnavailableException;
456.34 +import javax.sound.midi.Patch;
456.35 +import javax.sound.midi.Receiver;
456.36 +import javax.sound.sampled.*;
456.37 +import javax.sound.midi.MidiDevice.Info;
456.38 +
456.39 +import com.sun.media.sound.*;
456.40 +
456.41 +public class GetReceiver {
456.42 +
456.43 + private static void assertEquals(Object a, Object b) throws Exception
456.44 + {
456.45 + if(!a.equals(b))
456.46 + throw new RuntimeException("assertEquals fails!");
456.47 + }
456.48 +
456.49 + private static void assertTrue(boolean value) throws Exception
456.50 + {
456.51 + if(!value)
456.52 + throw new RuntimeException("assertTrue fails!");
456.53 + }
456.54 +
456.55 + public static void main(String[] args) throws Exception {
456.56 + AudioSynthesizer synth = new SoftSynthesizer();
456.57 + synth.open(new DummySourceDataLine(), null);
456.58 + Receiver recv = synth.getReceiver();
456.59 + assertTrue(recv != null);
456.60 + Receiver recv2 = synth.getReceiver();
456.61 + assertTrue(recv2 != null);
456.62 + assertTrue(recv2 != recv);
456.63 + synth.close();
456.64 +
456.65 + }
456.66 +}
457.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
457.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/GetReceiver2.java Tue Feb 03 22:02:55 2009 -0800
457.3 @@ -0,0 +1,62 @@
457.4 +/*
457.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
457.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
457.7 + *
457.8 + * This code is free software; you can redistribute it and/or modify it
457.9 + * under the terms of the GNU General Public License version 2 only, as
457.10 + * published by the Free Software Foundation. Sun designates this
457.11 + * particular file as subject to the "Classpath" exception as provided
457.12 + * by Sun in the LICENSE file that accompanied this code.
457.13 + *
457.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
457.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
457.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
457.17 + * version 2 for more details (a copy is included in the LICENSE file that
457.18 + * accompanied this code).
457.19 + *
457.20 + * You should have received a copy of the GNU General Public License version
457.21 + * 2 along with this work; if not, write to the Free Software Foundation,
457.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
457.23 + *
457.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
457.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
457.26 + * have any questions.
457.27 + */
457.28 +
457.29 +/* @test
457.30 + @summary Test SoftSynthesizer getReceiver method */
457.31 +
457.32 +import javax.sound.midi.Receiver;
457.33 +import javax.sound.midi.ShortMessage;
457.34 +
457.35 +import com.sun.media.sound.AudioSynthesizer;
457.36 +import com.sun.media.sound.SoftSynthesizer;
457.37 +
457.38 +public class GetReceiver2 {
457.39 +
457.40 + private static void assertTrue(boolean value) throws Exception
457.41 + {
457.42 + if(!value)
457.43 + throw new RuntimeException("assertTrue fails!");
457.44 + }
457.45 +
457.46 + public static void main(String[] args) throws Exception {
457.47 + AudioSynthesizer synth = new SoftSynthesizer();
457.48 + Receiver recv = synth.getReceiver();
457.49 + assertTrue(recv != null);
457.50 + ShortMessage sm = new ShortMessage();
457.51 + sm.setMessage(ShortMessage.NOTE_OFF, 0, 64, 64);
457.52 + synth.open(new DummySourceDataLine(), null);
457.53 + recv.send(sm, -1);
457.54 + synth.close();
457.55 + try
457.56 + {
457.57 + recv.send(sm, -1);
457.58 + throw new RuntimeException("Exception not thrown!");
457.59 + }
457.60 + catch(Exception e)
457.61 + {
457.62 + // Just checking if exception is thrown
457.63 + }
457.64 + }
457.65 +}
458.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
458.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/GetReceivers.java Tue Feb 03 22:02:55 2009 -0800
458.3 @@ -0,0 +1,63 @@
458.4 +/*
458.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
458.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
458.7 + *
458.8 + * This code is free software; you can redistribute it and/or modify it
458.9 + * under the terms of the GNU General Public License version 2 only, as
458.10 + * published by the Free Software Foundation. Sun designates this
458.11 + * particular file as subject to the "Classpath" exception as provided
458.12 + * by Sun in the LICENSE file that accompanied this code.
458.13 + *
458.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
458.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
458.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
458.17 + * version 2 for more details (a copy is included in the LICENSE file that
458.18 + * accompanied this code).
458.19 + *
458.20 + * You should have received a copy of the GNU General Public License version
458.21 + * 2 along with this work; if not, write to the Free Software Foundation,
458.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
458.23 + *
458.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
458.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
458.26 + * have any questions.
458.27 + */
458.28 +
458.29 +/* @test
458.30 + @summary Test SoftSynthesizer getReceivers method */
458.31 +
458.32 +import javax.sound.midi.MidiDevice;
458.33 +import javax.sound.midi.MidiUnavailableException;
458.34 +import javax.sound.midi.Patch;
458.35 +import javax.sound.midi.Receiver;
458.36 +import javax.sound.sampled.*;
458.37 +import javax.sound.midi.MidiDevice.Info;
458.38 +
458.39 +import com.sun.media.sound.*;
458.40 +
458.41 +public class GetReceivers {
458.42 +
458.43 + private static void assertEquals(Object a, Object b) throws Exception
458.44 + {
458.45 + if(!a.equals(b))
458.46 + throw new RuntimeException("assertEquals fails!");
458.47 + }
458.48 +
458.49 + private static void assertTrue(boolean value) throws Exception
458.50 + {
458.51 + if(!value)
458.52 + throw new RuntimeException("assertTrue fails!");
458.53 + }
458.54 +
458.55 + public static void main(String[] args) throws Exception {
458.56 + AudioSynthesizer synth = new SoftSynthesizer();
458.57 + synth.open(new DummySourceDataLine(), null);
458.58 + assertTrue(synth.getReceivers().size() == 0);
458.59 + Receiver recv = synth.getReceiver();
458.60 + assertTrue(synth.getReceivers().size() == 1);
458.61 + recv.close();
458.62 + assertTrue(synth.getReceivers().size() == 0);
458.63 + synth.close();
458.64 +
458.65 + }
458.66 +}
459.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
459.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/GetTransmitter.java Tue Feb 03 22:02:55 2009 -0800
459.3 @@ -0,0 +1,63 @@
459.4 +/*
459.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
459.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
459.7 + *
459.8 + * This code is free software; you can redistribute it and/or modify it
459.9 + * under the terms of the GNU General Public License version 2 only, as
459.10 + * published by the Free Software Foundation. Sun designates this
459.11 + * particular file as subject to the "Classpath" exception as provided
459.12 + * by Sun in the LICENSE file that accompanied this code.
459.13 + *
459.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
459.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
459.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
459.17 + * version 2 for more details (a copy is included in the LICENSE file that
459.18 + * accompanied this code).
459.19 + *
459.20 + * You should have received a copy of the GNU General Public License version
459.21 + * 2 along with this work; if not, write to the Free Software Foundation,
459.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
459.23 + *
459.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
459.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
459.26 + * have any questions.
459.27 + */
459.28 +
459.29 +/* @test
459.30 + @summary Test SoftSynthesizer getTransmitter method */
459.31 +
459.32 +import javax.sound.midi.MidiDevice;
459.33 +import javax.sound.midi.MidiUnavailableException;
459.34 +import javax.sound.midi.Patch;
459.35 +import javax.sound.sampled.*;
459.36 +import javax.sound.midi.MidiDevice.Info;
459.37 +
459.38 +import com.sun.media.sound.*;
459.39 +
459.40 +public class GetTransmitter {
459.41 +
459.42 + private static void assertEquals(Object a, Object b) throws Exception
459.43 + {
459.44 + if(!a.equals(b))
459.45 + throw new RuntimeException("assertEquals fails!");
459.46 + }
459.47 +
459.48 + private static void assertTrue(boolean value) throws Exception
459.49 + {
459.50 + if(!value)
459.51 + throw new RuntimeException("assertTrue fails!");
459.52 + }
459.53 +
459.54 + public static void main(String[] args) throws Exception {
459.55 + AudioSynthesizer synth = new SoftSynthesizer();
459.56 + synth.open(new DummySourceDataLine(), null);
459.57 + try
459.58 + {
459.59 + synth.getTransmitter();
459.60 + throw new Exception("MidiUnavailableException not thrown!");
459.61 + } catch (MidiUnavailableException e) {
459.62 + }
459.63 + synth.close();
459.64 +
459.65 + }
459.66 +}
460.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
460.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/GetTransmitters.java Tue Feb 03 22:02:55 2009 -0800
460.3 @@ -0,0 +1,58 @@
460.4 +/*
460.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
460.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
460.7 + *
460.8 + * This code is free software; you can redistribute it and/or modify it
460.9 + * under the terms of the GNU General Public License version 2 only, as
460.10 + * published by the Free Software Foundation. Sun designates this
460.11 + * particular file as subject to the "Classpath" exception as provided
460.12 + * by Sun in the LICENSE file that accompanied this code.
460.13 + *
460.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
460.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
460.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
460.17 + * version 2 for more details (a copy is included in the LICENSE file that
460.18 + * accompanied this code).
460.19 + *
460.20 + * You should have received a copy of the GNU General Public License version
460.21 + * 2 along with this work; if not, write to the Free Software Foundation,
460.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
460.23 + *
460.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
460.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
460.26 + * have any questions.
460.27 + */
460.28 +
460.29 +/* @test
460.30 + @summary Test SoftSynthesizer getTransmitters method */
460.31 +
460.32 +import javax.sound.midi.MidiDevice;
460.33 +import javax.sound.midi.MidiUnavailableException;
460.34 +import javax.sound.midi.Patch;
460.35 +import javax.sound.sampled.*;
460.36 +import javax.sound.midi.MidiDevice.Info;
460.37 +
460.38 +import com.sun.media.sound.*;
460.39 +
460.40 +public class GetTransmitters {
460.41 +
460.42 + private static void assertEquals(Object a, Object b) throws Exception
460.43 + {
460.44 + if(!a.equals(b))
460.45 + throw new RuntimeException("assertEquals fails!");
460.46 + }
460.47 +
460.48 + private static void assertTrue(boolean value) throws Exception
460.49 + {
460.50 + if(!value)
460.51 + throw new RuntimeException("assertTrue fails!");
460.52 + }
460.53 +
460.54 + public static void main(String[] args) throws Exception {
460.55 + AudioSynthesizer synth = new SoftSynthesizer();
460.56 + synth.open(new DummySourceDataLine(), null);
460.57 + assertTrue(synth.getTransmitters().size() == 0);
460.58 + synth.close();
460.59 +
460.60 + }
460.61 +}
461.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
461.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/GetVoiceStatus.java Tue Feb 03 22:02:55 2009 -0800
461.3 @@ -0,0 +1,61 @@
461.4 +/*
461.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
461.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
461.7 + *
461.8 + * This code is free software; you can redistribute it and/or modify it
461.9 + * under the terms of the GNU General Public License version 2 only, as
461.10 + * published by the Free Software Foundation. Sun designates this
461.11 + * particular file as subject to the "Classpath" exception as provided
461.12 + * by Sun in the LICENSE file that accompanied this code.
461.13 + *
461.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
461.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
461.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
461.17 + * version 2 for more details (a copy is included in the LICENSE file that
461.18 + * accompanied this code).
461.19 + *
461.20 + * You should have received a copy of the GNU General Public License version
461.21 + * 2 along with this work; if not, write to the Free Software Foundation,
461.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
461.23 + *
461.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
461.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
461.26 + * have any questions.
461.27 + */
461.28 +
461.29 +/* @test
461.30 + @summary Test SoftSynthesizer getVoiceStatus method */
461.31 +
461.32 +import javax.sound.midi.MidiDevice;
461.33 +import javax.sound.midi.MidiUnavailableException;
461.34 +import javax.sound.midi.Patch;
461.35 +import javax.sound.midi.VoiceStatus;
461.36 +import javax.sound.sampled.*;
461.37 +import javax.sound.midi.MidiDevice.Info;
461.38 +
461.39 +import com.sun.media.sound.*;
461.40 +
461.41 +public class GetVoiceStatus {
461.42 +
461.43 + private static void assertEquals(Object a, Object b) throws Exception
461.44 + {
461.45 + if(!a.equals(b))
461.46 + throw new RuntimeException("assertEquals fails!");
461.47 + }
461.48 +
461.49 + private static void assertTrue(boolean value) throws Exception
461.50 + {
461.51 + if(!value)
461.52 + throw new RuntimeException("assertTrue fails!");
461.53 + }
461.54 +
461.55 + public static void main(String[] args) throws Exception {
461.56 + AudioSynthesizer synth = new SoftSynthesizer();
461.57 + synth.openStream(null, null);
461.58 + VoiceStatus[] v = synth.getVoiceStatus();
461.59 + assertTrue(v != null);
461.60 + assertTrue(synth.getChannels().length != synth.getMaxPolyphony());
461.61 + synth.close();
461.62 +
461.63 + }
461.64 +}
462.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
462.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/ImplicitOpenClose.java Tue Feb 03 22:02:55 2009 -0800
462.3 @@ -0,0 +1,105 @@
462.4 +/*
462.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
462.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
462.7 + *
462.8 + * This code is free software; you can redistribute it and/or modify it
462.9 + * under the terms of the GNU General Public License version 2 only, as
462.10 + * published by the Free Software Foundation. Sun designates this
462.11 + * particular file as subject to the "Classpath" exception as provided
462.12 + * by Sun in the LICENSE file that accompanied this code.
462.13 + *
462.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
462.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
462.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
462.17 + * version 2 for more details (a copy is included in the LICENSE file that
462.18 + * accompanied this code).
462.19 + *
462.20 + * You should have received a copy of the GNU General Public License version
462.21 + * 2 along with this work; if not, write to the Free Software Foundation,
462.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
462.23 + *
462.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
462.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
462.26 + * have any questions.
462.27 + */
462.28 +
462.29 +/* @test
462.30 + @summary Test SoftSynthesizer implicit open/close using getReceiver. */
462.31 +
462.32 +import java.lang.reflect.Field;
462.33 +
462.34 +import javax.sound.midi.MidiDevice;
462.35 +import javax.sound.midi.MidiSystem;
462.36 +import javax.sound.midi.MidiUnavailableException;
462.37 +import javax.sound.midi.Patch;
462.38 +import javax.sound.midi.Receiver;
462.39 +import javax.sound.midi.Synthesizer;
462.40 +import javax.sound.sampled.*;
462.41 +import javax.sound.midi.MidiDevice.Info;
462.42 +
462.43 +import com.sun.media.sound.*;
462.44 +
462.45 +public class ImplicitOpenClose {
462.46 +
462.47 + public static void main(String[] args) throws Exception {
462.48 + Field f = SoftSynthesizer.class.getDeclaredField("testline");
462.49 + f.setAccessible(true);
462.50 + f.set(null, new DummySourceDataLine());
462.51 +
462.52 + Synthesizer synth = new SoftSynthesizer();
462.53 +
462.54 + ReferenceCountingDevice rcd = (ReferenceCountingDevice)synth;
462.55 +
462.56 + // Test single open/close cycle
462.57 +
462.58 + Receiver recv = rcd.getReceiverReferenceCounting();
462.59 + if(!synth.isOpen())
462.60 + throw new Exception("Synthesizer not open!");
462.61 + recv.close();
462.62 + if(synth.isOpen())
462.63 + throw new Exception("Synthesizer not closed!");
462.64 +
462.65 + // Test using 2 receiver cycle
462.66 +
462.67 + Receiver recv1 = rcd.getReceiverReferenceCounting();
462.68 + if(!synth.isOpen())
462.69 + throw new Exception("Synthesizer not open!");
462.70 + Receiver recv2 = rcd.getReceiverReferenceCounting();
462.71 + if(!synth.isOpen())
462.72 + throw new Exception("Synthesizer not open!");
462.73 +
462.74 + recv2.close();
462.75 + if(!synth.isOpen())
462.76 + throw new Exception("Synthesizer was closed!");
462.77 + recv1.close();
462.78 + if(synth.isOpen())
462.79 + throw new Exception("Synthesizer not closed!");
462.80 +
462.81 + // Test for explicit,implicit conflict
462.82 +
462.83 + synth.open();
462.84 + Receiver recv3 = rcd.getReceiverReferenceCounting();
462.85 + if(!synth.isOpen())
462.86 + throw new Exception("Synthesizer not open!");
462.87 + recv3.close();
462.88 + if(!synth.isOpen())
462.89 + throw new Exception("Synthesizer was closed!");
462.90 + synth.close();
462.91 + if(synth.isOpen())
462.92 + throw new Exception("Synthesizer not closed!");
462.93 +
462.94 + // Test for implicit,explicit conflict
462.95 +
462.96 + recv3 = rcd.getReceiverReferenceCounting();
462.97 + synth.open();
462.98 + if(!synth.isOpen())
462.99 + throw new Exception("Synthesizer not open!");
462.100 + recv3.close();
462.101 + if(!synth.isOpen())
462.102 + throw new Exception("Synthesizer was closed!");
462.103 + synth.close();
462.104 + if(synth.isOpen())
462.105 + throw new Exception("Synthesizer not closed!");
462.106 +
462.107 + }
462.108 +}
463.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
463.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/IsOpen.java Tue Feb 03 22:02:55 2009 -0800
463.3 @@ -0,0 +1,59 @@
463.4 +/*
463.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
463.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
463.7 + *
463.8 + * This code is free software; you can redistribute it and/or modify it
463.9 + * under the terms of the GNU General Public License version 2 only, as
463.10 + * published by the Free Software Foundation. Sun designates this
463.11 + * particular file as subject to the "Classpath" exception as provided
463.12 + * by Sun in the LICENSE file that accompanied this code.
463.13 + *
463.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
463.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
463.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
463.17 + * version 2 for more details (a copy is included in the LICENSE file that
463.18 + * accompanied this code).
463.19 + *
463.20 + * You should have received a copy of the GNU General Public License version
463.21 + * 2 along with this work; if not, write to the Free Software Foundation,
463.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
463.23 + *
463.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
463.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
463.26 + * have any questions.
463.27 + */
463.28 +
463.29 +/* @test
463.30 + @summary Test SoftSynthesizer isOpen method */
463.31 +
463.32 +import javax.sound.midi.MidiDevice;
463.33 +import javax.sound.midi.MidiUnavailableException;
463.34 +import javax.sound.midi.Patch;
463.35 +import javax.sound.sampled.*;
463.36 +import javax.sound.midi.MidiDevice.Info;
463.37 +
463.38 +import com.sun.media.sound.*;
463.39 +
463.40 +public class IsOpen {
463.41 +
463.42 + private static void assertEquals(Object a, Object b) throws Exception
463.43 + {
463.44 + if(!a.equals(b))
463.45 + throw new RuntimeException("assertEquals fails!");
463.46 + }
463.47 +
463.48 + private static void assertTrue(boolean value) throws Exception
463.49 + {
463.50 + if(!value)
463.51 + throw new RuntimeException("assertTrue fails!");
463.52 + }
463.53 +
463.54 + public static void main(String[] args) throws Exception {
463.55 + AudioSynthesizer synth = new SoftSynthesizer();
463.56 + synth.openStream(null, null);
463.57 + assertTrue(synth.isOpen());
463.58 + synth.close();
463.59 + assertTrue(!synth.isOpen());
463.60 +
463.61 + }
463.62 +}
464.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
464.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/IsSoundbankSupported.java Tue Feb 03 22:02:55 2009 -0800
464.3 @@ -0,0 +1,95 @@
464.4 +/*
464.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
464.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
464.7 + *
464.8 + * This code is free software; you can redistribute it and/or modify it
464.9 + * under the terms of the GNU General Public License version 2 only, as
464.10 + * published by the Free Software Foundation. Sun designates this
464.11 + * particular file as subject to the "Classpath" exception as provided
464.12 + * by Sun in the LICENSE file that accompanied this code.
464.13 + *
464.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
464.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
464.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
464.17 + * version 2 for more details (a copy is included in the LICENSE file that
464.18 + * accompanied this code).
464.19 + *
464.20 + * You should have received a copy of the GNU General Public License version
464.21 + * 2 along with this work; if not, write to the Free Software Foundation,
464.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
464.23 + *
464.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
464.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
464.26 + * have any questions.
464.27 + */
464.28 +
464.29 +/* @test
464.30 + @summary Test SoftSynthesizer isSoundbankSupported method */
464.31 +
464.32 +import javax.sound.midi.Instrument;
464.33 +import javax.sound.midi.MidiDevice;
464.34 +import javax.sound.midi.MidiUnavailableException;
464.35 +import javax.sound.midi.Patch;
464.36 +import javax.sound.midi.Soundbank;
464.37 +import javax.sound.midi.SoundbankResource;
464.38 +import javax.sound.sampled.*;
464.39 +import javax.sound.midi.MidiDevice.Info;
464.40 +
464.41 +import com.sun.media.sound.*;
464.42 +
464.43 +public class IsSoundbankSupported {
464.44 +
464.45 + private static void assertEquals(Object a, Object b) throws Exception
464.46 + {
464.47 + if(!a.equals(b))
464.48 + throw new RuntimeException("assertEquals fails!");
464.49 + }
464.50 +
464.51 + private static void assertTrue(boolean value) throws Exception
464.52 + {
464.53 + if(!value)
464.54 + throw new RuntimeException("assertTrue fails!");
464.55 + }
464.56 +
464.57 + public static void main(String[] args) throws Exception {
464.58 + AudioSynthesizer synth = new SoftSynthesizer();
464.59 + synth.openStream(null, null);
464.60 + SimpleSoundbank sbk = new SimpleSoundbank();
464.61 + SimpleInstrument ins = new SimpleInstrument();
464.62 + sbk.addInstrument(ins);
464.63 + assertTrue(synth.isSoundbankSupported(sbk));
464.64 + Soundbank dummysbk = new Soundbank()
464.65 + {
464.66 + public String getName() {
464.67 + return null;
464.68 + }
464.69 + public String getVersion() {
464.70 + return null;
464.71 + }
464.72 + public String getVendor() {
464.73 + return null;
464.74 + }
464.75 + public String getDescription() {
464.76 + return null;
464.77 + }
464.78 + public SoundbankResource[] getResources() {
464.79 + return null;
464.80 + }
464.81 + public Instrument[] getInstruments() {
464.82 + Instrument ins = new Instrument(null, null, null, null)
464.83 + {
464.84 + public Object getData() {
464.85 + return null;
464.86 + }
464.87 + };
464.88 + return new Instrument[] {ins};
464.89 + }
464.90 + public Instrument getInstrument(Patch patch) {
464.91 + return null;
464.92 + }
464.93 + };
464.94 + assertTrue(!synth.isSoundbankSupported(dummysbk));
464.95 + synth.close();
464.96 +
464.97 + }
464.98 +}
465.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
465.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/LoadAllInstruments.java Tue Feb 03 22:02:55 2009 -0800
465.3 @@ -0,0 +1,73 @@
465.4 +/*
465.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
465.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
465.7 + *
465.8 + * This code is free software; you can redistribute it and/or modify it
465.9 + * under the terms of the GNU General Public License version 2 only, as
465.10 + * published by the Free Software Foundation. Sun designates this
465.11 + * particular file as subject to the "Classpath" exception as provided
465.12 + * by Sun in the LICENSE file that accompanied this code.
465.13 + *
465.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
465.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
465.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
465.17 + * version 2 for more details (a copy is included in the LICENSE file that
465.18 + * accompanied this code).
465.19 + *
465.20 + * You should have received a copy of the GNU General Public License version
465.21 + * 2 along with this work; if not, write to the Free Software Foundation,
465.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
465.23 + *
465.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
465.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
465.26 + * have any questions.
465.27 + */
465.28 +
465.29 +/* @test
465.30 + @summary Test SoftSynthesizer loadAllInstruments method */
465.31 +
465.32 +import javax.sound.midi.MidiDevice;
465.33 +import javax.sound.midi.MidiUnavailableException;
465.34 +import javax.sound.midi.Patch;
465.35 +import javax.sound.midi.Soundbank;
465.36 +import javax.sound.sampled.*;
465.37 +import javax.sound.midi.MidiDevice.Info;
465.38 +
465.39 +import com.sun.media.sound.*;
465.40 +
465.41 +public class LoadAllInstruments {
465.42 +
465.43 + private static void assertEquals(Object a, Object b) throws Exception
465.44 + {
465.45 + if(!a.equals(b))
465.46 + throw new RuntimeException("assertEquals fails!");
465.47 + }
465.48 +
465.49 + private static void assertTrue(boolean value) throws Exception
465.50 + {
465.51 + if(!value)
465.52 + throw new RuntimeException("assertTrue fails!");
465.53 + }
465.54 +
465.55 + public static void main(String[] args) throws Exception {
465.56 + AudioSynthesizer synth = new SoftSynthesizer();
465.57 + synth.openStream(null, null);
465.58 + Soundbank defsbk = synth.getDefaultSoundbank();
465.59 + if(defsbk != null)
465.60 + {
465.61 + assertTrue(synth.getLoadedInstruments().length == 0);
465.62 + synth.unloadAllInstruments(defsbk);
465.63 + SimpleSoundbank sbk = new SimpleSoundbank();
465.64 + SimpleInstrument ins = new SimpleInstrument();
465.65 + ins.setPatch(new Patch(0,1));
465.66 + sbk.addInstrument(ins);
465.67 + SimpleInstrument ins2 = new SimpleInstrument();
465.68 + ins2.setPatch(new Patch(0,2));
465.69 + sbk.addInstrument(ins2);
465.70 + synth.loadAllInstruments(sbk);
465.71 + assertTrue(synth.getLoadedInstruments().length == 2);
465.72 + }
465.73 + synth.close();
465.74 +
465.75 + }
465.76 +}
466.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
466.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/LoadInstrument.java Tue Feb 03 22:02:55 2009 -0800
466.3 @@ -0,0 +1,73 @@
466.4 +/*
466.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
466.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
466.7 + *
466.8 + * This code is free software; you can redistribute it and/or modify it
466.9 + * under the terms of the GNU General Public License version 2 only, as
466.10 + * published by the Free Software Foundation. Sun designates this
466.11 + * particular file as subject to the "Classpath" exception as provided
466.12 + * by Sun in the LICENSE file that accompanied this code.
466.13 + *
466.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
466.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
466.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
466.17 + * version 2 for more details (a copy is included in the LICENSE file that
466.18 + * accompanied this code).
466.19 + *
466.20 + * You should have received a copy of the GNU General Public License version
466.21 + * 2 along with this work; if not, write to the Free Software Foundation,
466.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
466.23 + *
466.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
466.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
466.26 + * have any questions.
466.27 + */
466.28 +
466.29 +/* @test
466.30 + @summary Test SoftSynthesizer loadAllInstrument method */
466.31 +
466.32 +import javax.sound.midi.MidiDevice;
466.33 +import javax.sound.midi.MidiUnavailableException;
466.34 +import javax.sound.midi.Patch;
466.35 +import javax.sound.midi.Soundbank;
466.36 +import javax.sound.sampled.*;
466.37 +import javax.sound.midi.MidiDevice.Info;
466.38 +
466.39 +import com.sun.media.sound.*;
466.40 +
466.41 +public class LoadInstrument {
466.42 +
466.43 + private static void assertEquals(Object a, Object b) throws Exception
466.44 + {
466.45 + if(!a.equals(b))
466.46 + throw new RuntimeException("assertEquals fails!");
466.47 + }
466.48 +
466.49 + private static void assertTrue(boolean value) throws Exception
466.50 + {
466.51 + if(!value)
466.52 + throw new RuntimeException("assertTrue fails!");
466.53 + }
466.54 +
466.55 + public static void main(String[] args) throws Exception {
466.56 + AudioSynthesizer synth = new SoftSynthesizer();
466.57 + synth.openStream(null, null);
466.58 + Soundbank defsbk = synth.getDefaultSoundbank();
466.59 + if(defsbk != null)
466.60 + {
466.61 + assertTrue(synth.getLoadedInstruments().length == 0);
466.62 + synth.unloadAllInstruments(defsbk);
466.63 + SimpleSoundbank sbk = new SimpleSoundbank();
466.64 + SimpleInstrument ins = new SimpleInstrument();
466.65 + ins.setPatch(new Patch(0,1));
466.66 + sbk.addInstrument(ins);
466.67 + SimpleInstrument ins2 = new SimpleInstrument();
466.68 + ins2.setPatch(new Patch(0,2));
466.69 + sbk.addInstrument(ins2);
466.70 + synth.loadInstrument(ins2);
466.71 + assertTrue(synth.getLoadedInstruments().length == 1);
466.72 + }
466.73 + synth.close();
466.74 +
466.75 + }
466.76 +}
467.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
467.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/LoadInstruments.java Tue Feb 03 22:02:55 2009 -0800
467.3 @@ -0,0 +1,73 @@
467.4 +/*
467.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
467.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
467.7 + *
467.8 + * This code is free software; you can redistribute it and/or modify it
467.9 + * under the terms of the GNU General Public License version 2 only, as
467.10 + * published by the Free Software Foundation. Sun designates this
467.11 + * particular file as subject to the "Classpath" exception as provided
467.12 + * by Sun in the LICENSE file that accompanied this code.
467.13 + *
467.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
467.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
467.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
467.17 + * version 2 for more details (a copy is included in the LICENSE file that
467.18 + * accompanied this code).
467.19 + *
467.20 + * You should have received a copy of the GNU General Public License version
467.21 + * 2 along with this work; if not, write to the Free Software Foundation,
467.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
467.23 + *
467.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
467.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
467.26 + * have any questions.
467.27 + */
467.28 +
467.29 +/* @test
467.30 + @summary Test SoftSynthesizer loadAllInstruments method */
467.31 +
467.32 +import javax.sound.midi.MidiDevice;
467.33 +import javax.sound.midi.MidiUnavailableException;
467.34 +import javax.sound.midi.Patch;
467.35 +import javax.sound.midi.Soundbank;
467.36 +import javax.sound.sampled.*;
467.37 +import javax.sound.midi.MidiDevice.Info;
467.38 +
467.39 +import com.sun.media.sound.*;
467.40 +
467.41 +public class LoadInstruments {
467.42 +
467.43 + private static void assertEquals(Object a, Object b) throws Exception
467.44 + {
467.45 + if(!a.equals(b))
467.46 + throw new RuntimeException("assertEquals fails!");
467.47 + }
467.48 +
467.49 + private static void assertTrue(boolean value) throws Exception
467.50 + {
467.51 + if(!value)
467.52 + throw new RuntimeException("assertTrue fails!");
467.53 + }
467.54 +
467.55 + public static void main(String[] args) throws Exception {
467.56 + AudioSynthesizer synth = new SoftSynthesizer();
467.57 + synth.openStream(null, null);
467.58 + Soundbank defsbk = synth.getDefaultSoundbank();
467.59 + if(defsbk != null)
467.60 + {
467.61 + assertTrue(synth.getLoadedInstruments().length == 0);
467.62 + synth.unloadAllInstruments(defsbk);
467.63 + SimpleSoundbank sbk = new SimpleSoundbank();
467.64 + SimpleInstrument ins = new SimpleInstrument();
467.65 + ins.setPatch(new Patch(0,1));
467.66 + sbk.addInstrument(ins);
467.67 + SimpleInstrument ins2 = new SimpleInstrument();
467.68 + ins2.setPatch(new Patch(0,2));
467.69 + sbk.addInstrument(ins2);
467.70 + synth.loadInstruments(sbk, new Patch[] {ins2.getPatch()});
467.71 + assertTrue(synth.getLoadedInstruments().length == 1);
467.72 + }
467.73 + synth.close();
467.74 +
467.75 + }
467.76 +}
468.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
468.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/Open.java Tue Feb 03 22:02:55 2009 -0800
468.3 @@ -0,0 +1,64 @@
468.4 +/*
468.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
468.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
468.7 + *
468.8 + * This code is free software; you can redistribute it and/or modify it
468.9 + * under the terms of the GNU General Public License version 2 only, as
468.10 + * published by the Free Software Foundation. Sun designates this
468.11 + * particular file as subject to the "Classpath" exception as provided
468.12 + * by Sun in the LICENSE file that accompanied this code.
468.13 + *
468.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
468.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
468.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
468.17 + * version 2 for more details (a copy is included in the LICENSE file that
468.18 + * accompanied this code).
468.19 + *
468.20 + * You should have received a copy of the GNU General Public License version
468.21 + * 2 along with this work; if not, write to the Free Software Foundation,
468.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
468.23 + *
468.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
468.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
468.26 + * have any questions.
468.27 + */
468.28 +
468.29 +/* @test
468.30 + @summary Test SoftSynthesizer open method */
468.31 +
468.32 +import java.lang.reflect.Field;
468.33 +
468.34 +import javax.sound.midi.MidiDevice;
468.35 +import javax.sound.midi.MidiUnavailableException;
468.36 +import javax.sound.midi.Patch;
468.37 +import javax.sound.sampled.*;
468.38 +import javax.sound.midi.MidiDevice.Info;
468.39 +
468.40 +import com.sun.media.sound.*;
468.41 +
468.42 +public class Open {
468.43 +
468.44 + private static void assertEquals(Object a, Object b) throws Exception
468.45 + {
468.46 + if(!a.equals(b))
468.47 + throw new RuntimeException("assertEquals fails!");
468.48 + }
468.49 +
468.50 + private static void assertTrue(boolean value) throws Exception
468.51 + {
468.52 + if(!value)
468.53 + throw new RuntimeException("assertTrue fails!");
468.54 + }
468.55 +
468.56 + public static void main(String[] args) throws Exception {
468.57 + Field f = SoftSynthesizer.class.getDeclaredField("testline");
468.58 + f.setAccessible(true);
468.59 + f.set(null, new DummySourceDataLine());
468.60 +
468.61 + AudioSynthesizer synth = new SoftSynthesizer();
468.62 + synth.open();
468.63 + assertTrue(synth.isOpen());
468.64 + synth.close();
468.65 +
468.66 + }
468.67 +}
469.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
469.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/OpenStream.java Tue Feb 03 22:02:55 2009 -0800
469.3 @@ -0,0 +1,58 @@
469.4 +/*
469.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
469.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
469.7 + *
469.8 + * This code is free software; you can redistribute it and/or modify it
469.9 + * under the terms of the GNU General Public License version 2 only, as
469.10 + * published by the Free Software Foundation. Sun designates this
469.11 + * particular file as subject to the "Classpath" exception as provided
469.12 + * by Sun in the LICENSE file that accompanied this code.
469.13 + *
469.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
469.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
469.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
469.17 + * version 2 for more details (a copy is included in the LICENSE file that
469.18 + * accompanied this code).
469.19 + *
469.20 + * You should have received a copy of the GNU General Public License version
469.21 + * 2 along with this work; if not, write to the Free Software Foundation,
469.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
469.23 + *
469.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
469.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
469.26 + * have any questions.
469.27 + */
469.28 +
469.29 +/* @test
469.30 + @summary Test SoftSynthesizer openStream method */
469.31 +
469.32 +import javax.sound.midi.MidiDevice;
469.33 +import javax.sound.midi.MidiUnavailableException;
469.34 +import javax.sound.midi.Patch;
469.35 +import javax.sound.sampled.*;
469.36 +import javax.sound.midi.MidiDevice.Info;
469.37 +
469.38 +import com.sun.media.sound.*;
469.39 +
469.40 +public class OpenStream {
469.41 +
469.42 + private static void assertEquals(Object a, Object b) throws Exception
469.43 + {
469.44 + if(!a.equals(b))
469.45 + throw new RuntimeException("assertEquals fails!");
469.46 + }
469.47 +
469.48 + private static void assertTrue(boolean value) throws Exception
469.49 + {
469.50 + if(!value)
469.51 + throw new RuntimeException("assertTrue fails!");
469.52 + }
469.53 +
469.54 + public static void main(String[] args) throws Exception {
469.55 + AudioSynthesizer synth = new SoftSynthesizer();
469.56 + synth.openStream(null, null);
469.57 + assertTrue(synth.isOpen());
469.58 + synth.close();
469.59 +
469.60 + }
469.61 +}
470.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
470.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/RemapInstrument.java Tue Feb 03 22:02:55 2009 -0800
470.3 @@ -0,0 +1,76 @@
470.4 +/*
470.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
470.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
470.7 + *
470.8 + * This code is free software; you can redistribute it and/or modify it
470.9 + * under the terms of the GNU General Public License version 2 only, as
470.10 + * published by the Free Software Foundation. Sun designates this
470.11 + * particular file as subject to the "Classpath" exception as provided
470.12 + * by Sun in the LICENSE file that accompanied this code.
470.13 + *
470.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
470.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
470.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
470.17 + * version 2 for more details (a copy is included in the LICENSE file that
470.18 + * accompanied this code).
470.19 + *
470.20 + * You should have received a copy of the GNU General Public License version
470.21 + * 2 along with this work; if not, write to the Free Software Foundation,
470.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
470.23 + *
470.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
470.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
470.26 + * have any questions.
470.27 + */
470.28 +
470.29 +/* @test
470.30 + @summary Test SoftSynthesizer remapInstrument method */
470.31 +
470.32 +import javax.sound.midi.Instrument;
470.33 +import javax.sound.midi.MidiDevice;
470.34 +import javax.sound.midi.MidiUnavailableException;
470.35 +import javax.sound.midi.Patch;
470.36 +import javax.sound.midi.Soundbank;
470.37 +import javax.sound.sampled.*;
470.38 +import javax.sound.midi.MidiDevice.Info;
470.39 +
470.40 +import com.sun.media.sound.*;
470.41 +
470.42 +public class RemapInstrument {
470.43 +
470.44 + private static void assertEquals(Object a, Object b) throws Exception
470.45 + {
470.46 + if(!a.equals(b))
470.47 + throw new RuntimeException("assertEquals fails!");
470.48 + }
470.49 +
470.50 + private static void assertTrue(boolean value) throws Exception
470.51 + {
470.52 + if(!value)
470.53 + throw new RuntimeException("assertTrue fails!");
470.54 + }
470.55 +
470.56 + public static void main(String[] args) throws Exception {
470.57 + AudioSynthesizer synth = new SoftSynthesizer();
470.58 + synth.openStream(null, null);
470.59 + Soundbank defsbk = synth.getDefaultSoundbank();
470.60 + if(defsbk != null)
470.61 + {
470.62 + Instrument ins0 = defsbk.getInstrument(new Patch(0,0));
470.63 + Instrument ins10 = defsbk.getInstrument(new Patch(0,10));
470.64 + assertTrue(synth.remapInstrument(ins0, ins10));
470.65 + Instrument[] loaded = synth.getLoadedInstruments();
470.66 + for (int i = 0; i < loaded.length; i++) {
470.67 + if(loaded[i].getPatch().getBank() == 0)
470.68 + if(loaded[i].getPatch().getProgram() == 10)
470.69 + {
470.70 + assertEquals(loaded[i].getName(), ins0.getName());
470.71 + break;
470.72 + }
470.73 + }
470.74 +
470.75 + }
470.76 + synth.close();
470.77 +
470.78 + }
470.79 +}
471.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
471.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/TestRender1.java Tue Feb 03 22:02:55 2009 -0800
471.3 @@ -0,0 +1,214 @@
471.4 +/*
471.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
471.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
471.7 + *
471.8 + * This code is free software; you can redistribute it and/or modify it
471.9 + * under the terms of the GNU General Public License version 2 only, as
471.10 + * published by the Free Software Foundation. Sun designates this
471.11 + * particular file as subject to the "Classpath" exception as provided
471.12 + * by Sun in the LICENSE file that accompanied this code.
471.13 + *
471.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
471.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
471.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
471.17 + * version 2 for more details (a copy is included in the LICENSE file that
471.18 + * accompanied this code).
471.19 + *
471.20 + * You should have received a copy of the GNU General Public License version
471.21 + * 2 along with this work; if not, write to the Free Software Foundation,
471.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
471.23 + *
471.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
471.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
471.26 + * have any questions.
471.27 + */
471.28 +
471.29 +/* @test
471.30 + @summary Test SoftSynthesizer simple note rendering in many settings */
471.31 +
471.32 +import java.io.File;
471.33 +import java.io.FileInputStream;
471.34 +import java.io.BufferedInputStream;
471.35 +import java.io.FileInputStream;
471.36 +import java.io.IOException;
471.37 +import java.io.InputStream;
471.38 +import java.io.OutputStream;
471.39 +import java.util.HashMap;
471.40 +import java.util.Map;
471.41 +
471.42 +import javax.sound.sampled.*;
471.43 +import javax.sound.midi.*;
471.44 +
471.45 +import com.sun.media.sound.*;
471.46 +
471.47 +public class TestRender1 {
471.48 +
471.49 + public static double send(Sequence seq, Receiver recv) {
471.50 + float divtype = seq.getDivisionType();
471.51 + assert (seq.getDivisionType() == Sequence.PPQ);
471.52 + Track[] tracks = seq.getTracks();
471.53 + int[] trackspos = new int[tracks.length];
471.54 + int mpq = 60000000 / 100;
471.55 + int seqres = seq.getResolution();
471.56 + long lasttick = 0;
471.57 + long curtime = 0;
471.58 + while (true) {
471.59 + MidiEvent selevent = null;
471.60 + int seltrack = -1;
471.61 + for (int i = 0; i < tracks.length; i++) {
471.62 + int trackpos = trackspos[i];
471.63 + Track track = tracks[i];
471.64 + if (trackpos < track.size()) {
471.65 + MidiEvent event = track.get(trackpos);
471.66 + if (selevent == null
471.67 + || event.getTick() < selevent.getTick()) {
471.68 + selevent = event;
471.69 + seltrack = i;
471.70 + }
471.71 + }
471.72 + }
471.73 + if (seltrack == -1)
471.74 + break;
471.75 + trackspos[seltrack]++;
471.76 + long tick = selevent.getTick();
471.77 + if (divtype == Sequence.PPQ)
471.78 + curtime += ((tick - lasttick) * mpq) / seqres;
471.79 + else
471.80 + curtime = (long) ((tick * 1000000.0 * divtype) / seqres);
471.81 + lasttick = tick;
471.82 + MidiMessage msg = selevent.getMessage();
471.83 + if (msg instanceof MetaMessage) {
471.84 + if (divtype == Sequence.PPQ)
471.85 + if (((MetaMessage) msg).getType() == 0x51) {
471.86 + byte[] data = ((MetaMessage) msg).getData();
471.87 + mpq = ((data[0] & 0xff) << 16)
471.88 + | ((data[1] & 0xff) << 8) | (data[2] & 0xff);
471.89 + }
471.90 + } else {
471.91 + if (recv != null)
471.92 + recv.send(msg, curtime);
471.93 + }
471.94 + }
471.95 +
471.96 + return curtime / 1000000.0;
471.97 + }
471.98 +
471.99 + public static void test(AudioFormat format, Map<String, Object> info)
471.100 + throws Exception {
471.101 + OutputStream nullout = new OutputStream() {
471.102 + public void write(int b) throws IOException {
471.103 + }
471.104 +
471.105 + public void write(byte[] b, int off, int len) throws IOException {
471.106 + }
471.107 +
471.108 + public void write(byte[] b) throws IOException {
471.109 + }
471.110 + };
471.111 + render(nullout, format, info);
471.112 + }
471.113 +
471.114 + public static void render(OutputStream os, AudioFormat format,
471.115 + Map<String, Object> info) throws Exception {
471.116 + AudioSynthesizer synth = (AudioSynthesizer) new SoftSynthesizer();
471.117 + AudioInputStream stream = synth.openStream(format, info);
471.118 + Receiver recv = synth.getReceiver();
471.119 + Soundbank defsbk = synth.getDefaultSoundbank();
471.120 + if (defsbk != null)
471.121 + synth.unloadAllInstruments(defsbk);
471.122 + synth.loadAllInstruments(soundbank);
471.123 +
471.124 + double totalTime = 5;
471.125 + send(sequence, recv);
471.126 +
471.127 + long len = (long) (stream.getFormat().getFrameRate() * (totalTime + 4));
471.128 + stream = new AudioInputStream(stream, stream.getFormat(), len);
471.129 +
471.130 + long t = System.currentTimeMillis();
471.131 + AudioSystem.write(stream, AudioFileFormat.Type.WAVE, os);
471.132 + t = System.currentTimeMillis() - t;
471.133 + stream.close();
471.134 + }
471.135 +
471.136 +
471.137 + static Soundbank soundbank;
471.138 +
471.139 + static Sequence sequence;
471.140 +
471.141 + public static InputStream getInputStream(String filename) throws IOException
471.142 + {
471.143 + File file = new File(System.getProperty("test.src", "."), filename);
471.144 + FileInputStream fis = new FileInputStream(file);
471.145 + return new BufferedInputStream(fis);
471.146 + }
471.147 +
471.148 + public static void main(String[] args) throws Exception {
471.149 +
471.150 + InputStream sb = getInputStream("ding.sf2");
471.151 + soundbank = MidiSystem.getSoundbank(sb);
471.152 + sb.close();
471.153 +
471.154 + InputStream si = getInputStream("expresso.mid");
471.155 + sequence = MidiSystem.getSequence(si);
471.156 + si.close();
471.157 +
471.158 + AudioFormat format;
471.159 + Map<String, Object> info = new HashMap<String, Object>();
471.160 + {
471.161 + format = new AudioFormat(22050, 16, 2, true, false);
471.162 + test(format, info);
471.163 + format = new AudioFormat(44100, 16, 2, true, false);
471.164 + test(format, info);
471.165 + }
471.166 + {
471.167 + format = new AudioFormat(44100, 8, 2, true, false);
471.168 + test(format, info);
471.169 + format = new AudioFormat(44100, 16, 2, true, false);
471.170 + test(format, info);
471.171 + format = new AudioFormat(44100, 24, 2, true, false);
471.172 + test(format, info);
471.173 + }
471.174 + {
471.175 + format = new AudioFormat(44100, 16, 1, true, false);
471.176 + test(format, info);
471.177 + format = new AudioFormat(44100, 16, 2, true, false);
471.178 + test(format, info);
471.179 + }
471.180 + {
471.181 + format = new AudioFormat(44100, 16, 2, true, false);
471.182 +
471.183 + info.clear();
471.184 + info.put("control rate", 100f);
471.185 + test(format, info);
471.186 + info.clear();
471.187 + info.put("control rate", 147f);
471.188 + test(format, info);
471.189 +
471.190 + }
471.191 + {
471.192 + format = new AudioFormat(44100, 16, 2, true, false);
471.193 +
471.194 + info.clear();
471.195 + info.put("interpolation", "point");
471.196 + test(format, info);
471.197 + info.clear();
471.198 + info.put("interpolation", "linear");
471.199 + test(format, info);
471.200 + info.clear();
471.201 + info.put("interpolation", "cubic");
471.202 + test(format, info);
471.203 + }
471.204 + {
471.205 + format = new AudioFormat(44100, 16, 2, true, false);
471.206 + info.clear();
471.207 + info.put("max polyphony", 4);
471.208 + test(format, info);
471.209 + info.clear();
471.210 + info.put("max polyphony", 16);
471.211 + test(format, info);
471.212 + info.clear();
471.213 +
471.214 + }
471.215 +
471.216 + }
471.217 +}
472.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
472.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/UnloadAllInstruments.java Tue Feb 03 22:02:55 2009 -0800
472.3 @@ -0,0 +1,69 @@
472.4 +/*
472.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
472.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
472.7 + *
472.8 + * This code is free software; you can redistribute it and/or modify it
472.9 + * under the terms of the GNU General Public License version 2 only, as
472.10 + * published by the Free Software Foundation. Sun designates this
472.11 + * particular file as subject to the "Classpath" exception as provided
472.12 + * by Sun in the LICENSE file that accompanied this code.
472.13 + *
472.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
472.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
472.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
472.17 + * version 2 for more details (a copy is included in the LICENSE file that
472.18 + * accompanied this code).
472.19 + *
472.20 + * You should have received a copy of the GNU General Public License version
472.21 + * 2 along with this work; if not, write to the Free Software Foundation,
472.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
472.23 + *
472.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
472.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
472.26 + * have any questions.
472.27 + */
472.28 +
472.29 +/* @test
472.30 + @summary Test SoftSynthesizer unloadAllInstruments method */
472.31 +
472.32 +import javax.sound.midi.MidiDevice;
472.33 +import javax.sound.midi.MidiUnavailableException;
472.34 +import javax.sound.midi.Patch;
472.35 +import javax.sound.midi.Soundbank;
472.36 +import javax.sound.sampled.*;
472.37 +import javax.sound.midi.MidiDevice.Info;
472.38 +
472.39 +import com.sun.media.sound.*;
472.40 +
472.41 +public class UnloadAllInstruments {
472.42 +
472.43 + private static void assertEquals(Object a, Object b) throws Exception
472.44 + {
472.45 + if(!a.equals(b))
472.46 + throw new RuntimeException("assertEquals fails!");
472.47 + }
472.48 +
472.49 + private static void assertTrue(boolean value) throws Exception
472.50 + {
472.51 + if(!value)
472.52 + throw new RuntimeException("assertTrue fails!");
472.53 + }
472.54 +
472.55 + public static void main(String[] args) throws Exception {
472.56 + AudioSynthesizer synth = new SoftSynthesizer();
472.57 + synth.openStream(null, null);
472.58 + Soundbank defsbk = synth.getDefaultSoundbank();
472.59 + if(defsbk != null)
472.60 + {
472.61 + assertTrue(synth.getLoadedInstruments().length == 0);
472.62 + synth.unloadAllInstruments(defsbk);
472.63 + assertTrue(synth.getAvailableInstruments().length == 0);
472.64 + synth.loadAllInstruments(defsbk);
472.65 + assertTrue(synth.getLoadedInstruments().length != 0);
472.66 + synth.unloadAllInstruments(defsbk);
472.67 + assertTrue(synth.getLoadedInstruments().length == 0);
472.68 + }
472.69 + synth.close();
472.70 +
472.71 + }
472.72 +}
473.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
473.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/UnloadInstrument.java Tue Feb 03 22:02:55 2009 -0800
473.3 @@ -0,0 +1,75 @@
473.4 +/*
473.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
473.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
473.7 + *
473.8 + * This code is free software; you can redistribute it and/or modify it
473.9 + * under the terms of the GNU General Public License version 2 only, as
473.10 + * published by the Free Software Foundation. Sun designates this
473.11 + * particular file as subject to the "Classpath" exception as provided
473.12 + * by Sun in the LICENSE file that accompanied this code.
473.13 + *
473.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
473.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
473.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
473.17 + * version 2 for more details (a copy is included in the LICENSE file that
473.18 + * accompanied this code).
473.19 + *
473.20 + * You should have received a copy of the GNU General Public License version
473.21 + * 2 along with this work; if not, write to the Free Software Foundation,
473.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
473.23 + *
473.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
473.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
473.26 + * have any questions.
473.27 + */
473.28 +
473.29 +/* @test
473.30 + @summary Test SoftSynthesizer unloadInstrument method */
473.31 +
473.32 +import javax.sound.midi.MidiDevice;
473.33 +import javax.sound.midi.MidiUnavailableException;
473.34 +import javax.sound.midi.Patch;
473.35 +import javax.sound.midi.Soundbank;
473.36 +import javax.sound.sampled.*;
473.37 +import javax.sound.midi.MidiDevice.Info;
473.38 +
473.39 +import com.sun.media.sound.*;
473.40 +
473.41 +public class UnloadInstrument {
473.42 +
473.43 + private static void assertEquals(Object a, Object b) throws Exception
473.44 + {
473.45 + if(!a.equals(b))
473.46 + throw new RuntimeException("assertEquals fails!");
473.47 + }
473.48 +
473.49 + private static void assertTrue(boolean value) throws Exception
473.50 + {
473.51 + if(!value)
473.52 + throw new RuntimeException("assertTrue fails!");
473.53 + }
473.54 +
473.55 + public static void main(String[] args) throws Exception {
473.56 + AudioSynthesizer synth = new SoftSynthesizer();
473.57 + synth.openStream(null, null);
473.58 + Soundbank defsbk = synth.getDefaultSoundbank();
473.59 + if(defsbk != null)
473.60 + {
473.61 + assertTrue(synth.getLoadedInstruments().length == 0);
473.62 + synth.unloadAllInstruments(defsbk);
473.63 + SimpleSoundbank sbk = new SimpleSoundbank();
473.64 + SimpleInstrument ins = new SimpleInstrument();
473.65 + ins.setPatch(new Patch(0,1));
473.66 + sbk.addInstrument(ins);
473.67 + SimpleInstrument ins2 = new SimpleInstrument();
473.68 + ins2.setPatch(new Patch(0,2));
473.69 + sbk.addInstrument(ins2);
473.70 + synth.loadInstrument(ins2);
473.71 + assertTrue(synth.getLoadedInstruments().length == 1);
473.72 + synth.unloadInstrument(ins2);
473.73 + assertTrue(synth.getLoadedInstruments().length == 0);
473.74 + }
473.75 + synth.close();
473.76 +
473.77 + }
473.78 +}
474.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
474.2 +++ b/test/javax/sound/midi/Gervill/SoftSynthesizer/UnloadInstruments.java Tue Feb 03 22:02:55 2009 -0800
474.3 @@ -0,0 +1,75 @@
474.4 +/*
474.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
474.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
474.7 + *
474.8 + * This code is free software; you can redistribute it and/or modify it
474.9 + * under the terms of the GNU General Public License version 2 only, as
474.10 + * published by the Free Software Foundation. Sun designates this
474.11 + * particular file as subject to the "Classpath" exception as provided
474.12 + * by Sun in the LICENSE file that accompanied this code.
474.13 + *
474.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
474.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
474.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
474.17 + * version 2 for more details (a copy is included in the LICENSE file that
474.18 + * accompanied this code).
474.19 + *
474.20 + * You should have received a copy of the GNU General Public License version
474.21 + * 2 along with this work; if not, write to the Free Software Foundation,
474.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
474.23 + *
474.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
474.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
474.26 + * have any questions.
474.27 + */
474.28 +
474.29 +/* @test
474.30 + @summary Test SoftSynthesizer unloadInstruments method */
474.31 +
474.32 +import javax.sound.midi.MidiDevice;
474.33 +import javax.sound.midi.MidiUnavailableException;
474.34 +import javax.sound.midi.Patch;
474.35 +import javax.sound.midi.Soundbank;
474.36 +import javax.sound.sampled.*;
474.37 +import javax.sound.midi.MidiDevice.Info;
474.38 +
474.39 +import com.sun.media.sound.*;
474.40 +
474.41 +public class UnloadInstruments {
474.42 +
474.43 + private static void assertEquals(Object a, Object b) throws Exception
474.44 + {
474.45 + if(!a.equals(b))
474.46 + throw new RuntimeException("assertEquals fails!");
474.47 + }
474.48 +
474.49 + private static void assertTrue(boolean value) throws Exception
474.50 + {
474.51 + if(!value)
474.52 + throw new RuntimeException("assertTrue fails!");
474.53 + }
474.54 +
474.55 + public static void main(String[] args) throws Exception {
474.56 + AudioSynthesizer synth = new SoftSynthesizer();
474.57 + synth.openStream(null, null);
474.58 + Soundbank defsbk = synth.getDefaultSoundbank();
474.59 + if(defsbk != null)
474.60 + {
474.61 + assertTrue(synth.getLoadedInstruments().length == 0);
474.62 + synth.unloadAllInstruments(defsbk);
474.63 + SimpleSoundbank sbk = new SimpleSoundbank();
474.64 + SimpleInstrument ins = new SimpleInstrument();
474.65 + ins.setPatch(new Patch(0,1));
474.66 + sbk.addInstrument(ins);
474.67 + SimpleInstrument ins2 = new SimpleInstrument();
474.68 + ins2.setPatch(new Patch(0,2));
474.69 + sbk.addInstrument(ins2);
474.70 + synth.loadInstrument(ins2);
474.71 + assertTrue(synth.getLoadedInstruments().length == 1);
474.72 + synth.unloadInstruments(sbk, new Patch[] {ins2.getPatch()});
474.73 + assertTrue(synth.getLoadedInstruments().length == 0);
474.74 + }
474.75 + synth.close();
474.76 +
474.77 + }
474.78 +}
475.1 Binary file test/javax/sound/midi/Gervill/SoftSynthesizer/ding.sf2 has changed
476.1 Binary file test/javax/sound/midi/Gervill/SoftSynthesizer/expresso.mid has changed
477.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
477.2 +++ b/test/javax/sound/midi/Gervill/SoftTuning/GetName.java Tue Feb 03 22:02:55 2009 -0800
477.3 @@ -0,0 +1,54 @@
477.4 +/*
477.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
477.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
477.7 + *
477.8 + * This code is free software; you can redistribute it and/or modify it
477.9 + * under the terms of the GNU General Public License version 2 only, as
477.10 + * published by the Free Software Foundation. Sun designates this
477.11 + * particular file as subject to the "Classpath" exception as provided
477.12 + * by Sun in the LICENSE file that accompanied this code.
477.13 + *
477.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
477.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
477.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
477.17 + * version 2 for more details (a copy is included in the LICENSE file that
477.18 + * accompanied this code).
477.19 + *
477.20 + * You should have received a copy of the GNU General Public License version
477.21 + * 2 along with this work; if not, write to the Free Software Foundation,
477.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
477.23 + *
477.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
477.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
477.26 + * have any questions.
477.27 + */
477.28 +
477.29 +/* @test
477.30 + @summary Test SoftTuning getName method */
477.31 +
477.32 +import javax.sound.midi.MidiUnavailableException;
477.33 +import javax.sound.midi.Patch;
477.34 +import javax.sound.sampled.*;
477.35 +
477.36 +import com.sun.media.sound.*;
477.37 +
477.38 +public class GetName {
477.39 +
477.40 + private static void assertEquals(Object a, Object b) throws Exception
477.41 + {
477.42 + if(!a.equals(b))
477.43 + throw new RuntimeException("assertEquals fails!");
477.44 + }
477.45 +
477.46 + private static void assertTrue(boolean value) throws Exception
477.47 + {
477.48 + if(!value)
477.49 + throw new RuntimeException("assertTrue fails!");
477.50 + }
477.51 +
477.52 + public static void main(String[] args) throws Exception {
477.53 + SoftTuning tuning = new SoftTuning();
477.54 + tuning.setName("custom");
477.55 + assertEquals(tuning.getName(), "custom");
477.56 + }
477.57 +}
478.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
478.2 +++ b/test/javax/sound/midi/Gervill/SoftTuning/GetTuning.java Tue Feb 03 22:02:55 2009 -0800
478.3 @@ -0,0 +1,56 @@
478.4 +/*
478.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
478.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
478.7 + *
478.8 + * This code is free software; you can redistribute it and/or modify it
478.9 + * under the terms of the GNU General Public License version 2 only, as
478.10 + * published by the Free Software Foundation. Sun designates this
478.11 + * particular file as subject to the "Classpath" exception as provided
478.12 + * by Sun in the LICENSE file that accompanied this code.
478.13 + *
478.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
478.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
478.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
478.17 + * version 2 for more details (a copy is included in the LICENSE file that
478.18 + * accompanied this code).
478.19 + *
478.20 + * You should have received a copy of the GNU General Public License version
478.21 + * 2 along with this work; if not, write to the Free Software Foundation,
478.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
478.23 + *
478.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
478.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
478.26 + * have any questions.
478.27 + */
478.28 +
478.29 +/* @test
478.30 + @summary Test SoftTuning getTuning method */
478.31 +
478.32 +import javax.sound.midi.MidiUnavailableException;
478.33 +import javax.sound.midi.Patch;
478.34 +import javax.sound.sampled.*;
478.35 +
478.36 +import com.sun.media.sound.*;
478.37 +
478.38 +public class GetTuning {
478.39 +
478.40 + private static void assertEquals(Object a, Object b) throws Exception
478.41 + {
478.42 + if(!a.equals(b))
478.43 + throw new RuntimeException("assertEquals fails!");
478.44 + }
478.45 +
478.46 + private static void assertTrue(boolean value) throws Exception
478.47 + {
478.48 + if(!value)
478.49 + throw new RuntimeException("assertTrue fails!");
478.50 + }
478.51 +
478.52 + public static void main(String[] args) throws Exception {
478.53 + SoftTuning tuning = new SoftTuning();
478.54 + double[] tunings = tuning.getTuning();
478.55 + for (int i = 0; i < tunings.length; i++) {
478.56 + assertTrue(Math.abs(tunings[i]-i*100) < 0.00001);
478.57 + }
478.58 + }
478.59 +}
479.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
479.2 +++ b/test/javax/sound/midi/Gervill/SoftTuning/GetTuningInt.java Tue Feb 03 22:02:55 2009 -0800
479.3 @@ -0,0 +1,53 @@
479.4 +/*
479.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
479.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
479.7 + *
479.8 + * This code is free software; you can redistribute it and/or modify it
479.9 + * under the terms of the GNU General Public License version 2 only, as
479.10 + * published by the Free Software Foundation. Sun designates this
479.11 + * particular file as subject to the "Classpath" exception as provided
479.12 + * by Sun in the LICENSE file that accompanied this code.
479.13 + *
479.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
479.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
479.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
479.17 + * version 2 for more details (a copy is included in the LICENSE file that
479.18 + * accompanied this code).
479.19 + *
479.20 + * You should have received a copy of the GNU General Public License version
479.21 + * 2 along with this work; if not, write to the Free Software Foundation,
479.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
479.23 + *
479.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
479.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
479.26 + * have any questions.
479.27 + */
479.28 +
479.29 +/* @test
479.30 + @summary Test SoftTuning getTuning(int) method */
479.31 +
479.32 +import javax.sound.midi.MidiUnavailableException;
479.33 +import javax.sound.midi.Patch;
479.34 +import javax.sound.sampled.*;
479.35 +
479.36 +import com.sun.media.sound.*;
479.37 +
479.38 +public class GetTuningInt {
479.39 +
479.40 + private static void assertEquals(Object a, Object b) throws Exception
479.41 + {
479.42 + if(!a.equals(b))
479.43 + throw new RuntimeException("assertEquals fails!");
479.44 + }
479.45 +
479.46 + private static void assertTrue(boolean value) throws Exception
479.47 + {
479.48 + if(!value)
479.49 + throw new RuntimeException("assertTrue fails!");
479.50 + }
479.51 +
479.52 + public static void main(String[] args) throws Exception {
479.53 + SoftTuning tuning = new SoftTuning();
479.54 + assertTrue(Math.abs(tuning.getTuning(36)-3600) < 0.00001);
479.55 + }
479.56 +}
480.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
480.2 +++ b/test/javax/sound/midi/Gervill/SoftTuning/Load1.java Tue Feb 03 22:02:55 2009 -0800
480.3 @@ -0,0 +1,101 @@
480.4 +/*
480.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
480.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
480.7 + *
480.8 + * This code is free software; you can redistribute it and/or modify it
480.9 + * under the terms of the GNU General Public License version 2 only, as
480.10 + * published by the Free Software Foundation. Sun designates this
480.11 + * particular file as subject to the "Classpath" exception as provided
480.12 + * by Sun in the LICENSE file that accompanied this code.
480.13 + *
480.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
480.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
480.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
480.17 + * version 2 for more details (a copy is included in the LICENSE file that
480.18 + * accompanied this code).
480.19 + *
480.20 + * You should have received a copy of the GNU General Public License version
480.21 + * 2 along with this work; if not, write to the Free Software Foundation,
480.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
480.23 + *
480.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
480.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
480.26 + * have any questions.
480.27 + */
480.28 +
480.29 +/* @test
480.30 + @summary Test SoftTuning load method */
480.31 +
480.32 +import java.io.UnsupportedEncodingException;
480.33 +
480.34 +import javax.sound.midi.MidiUnavailableException;
480.35 +import javax.sound.midi.Patch;
480.36 +import javax.sound.sampled.*;
480.37 +
480.38 +import com.sun.media.sound.*;
480.39 +
480.40 +public class Load1 {
480.41 +
480.42 + private static void assertEquals(Object a, Object b) throws Exception
480.43 + {
480.44 + if(!a.equals(b))
480.45 + throw new RuntimeException("assertEquals fails!");
480.46 + }
480.47 +
480.48 + private static void assertTrue(boolean value) throws Exception
480.49 + {
480.50 + if(!value)
480.51 + throw new RuntimeException("assertTrue fails!");
480.52 + }
480.53 +
480.54 + public static void main(String[] args) throws Exception {
480.55 + // http://www.midi.org/about-midi/tuning.shtml
480.56 + // 0x01 BULK TUNING DUMP
480.57 + SoftTuning tuning = new SoftTuning();
480.58 + byte[] name;
480.59 + name = "Testing123 ".getBytes("ascii");
480.60 +
480.61 + int[] msg = new int[24+3*128];
480.62 + int[] head = {0xf0,0x7e,0x7f,0x08,0x01,0x00};
480.63 + int ox = 0;
480.64 + for (int i = 0; i < head.length; i++)
480.65 + msg[ox++] = head[i];
480.66 + for (int i = 0; i < name.length; i++)
480.67 + msg[ox++] = name[i];
480.68 + for (int i = 0; i < 128; i++) {
480.69 + msg[ox++] = i;
480.70 + msg[ox++] = 64;
480.71 + msg[ox++] = 0;
480.72 + }
480.73 +
480.74 + // Calc checksum
480.75 + int x = msg[1] & 0xFF; // 7E
480.76 + x = x ^ (msg[2] & 0xFF); // <device ID>
480.77 + x = x ^ (msg[4] & 0xFF); // nn
480.78 + x = x ^ (msg[5] & 0xFF); // tt
480.79 + for (int i = 22; i < msg.length - 2; i++)
480.80 + x = x ^ (msg[i] & 0xFF);
480.81 + msg[ox++] = (x & 127);
480.82 +
480.83 + msg[ox++] = 0xf7;
480.84 + byte[] bmsg = new byte[msg.length];
480.85 + for (int i = 0; i < bmsg.length; i++)
480.86 + bmsg[i] = (byte)msg[i];
480.87 +
480.88 + tuning.load(bmsg);
480.89 + assertEquals(tuning.getName(), "Testing123 ");
480.90 + double[] tunings = tuning.getTuning();
480.91 + for (int i = 0; i < tunings.length; i++)
480.92 + assertTrue(Math.abs(tunings[i]-(i*100 + 50)) < 0.00001);
480.93 +
480.94 + // Check if tuning fails if checksum is wrong
480.95 + /*
480.96 + msg[msg.length - 2] += 10;
480.97 + for (int i = 0; i < bmsg.length; i++)
480.98 + bmsg[i] = (byte)msg[i];
480.99 + tuning = new SoftTuning();
480.100 + tuning.load(bmsg);
480.101 + assertTrue(!tuning.getName().equals("Testing123 "));
480.102 + */
480.103 + }
480.104 +}
481.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
481.2 +++ b/test/javax/sound/midi/Gervill/SoftTuning/Load2.java Tue Feb 03 22:02:55 2009 -0800
481.3 @@ -0,0 +1,71 @@
481.4 +/*
481.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
481.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
481.7 + *
481.8 + * This code is free software; you can redistribute it and/or modify it
481.9 + * under the terms of the GNU General Public License version 2 only, as
481.10 + * published by the Free Software Foundation. Sun designates this
481.11 + * particular file as subject to the "Classpath" exception as provided
481.12 + * by Sun in the LICENSE file that accompanied this code.
481.13 + *
481.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
481.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
481.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
481.17 + * version 2 for more details (a copy is included in the LICENSE file that
481.18 + * accompanied this code).
481.19 + *
481.20 + * You should have received a copy of the GNU General Public License version
481.21 + * 2 along with this work; if not, write to the Free Software Foundation,
481.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
481.23 + *
481.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
481.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
481.26 + * have any questions.
481.27 + */
481.28 +
481.29 +/* @test
481.30 + @summary Test SoftTuning load method */
481.31 +
481.32 +import javax.sound.midi.MidiUnavailableException;
481.33 +import javax.sound.midi.Patch;
481.34 +import javax.sound.sampled.*;
481.35 +
481.36 +import com.sun.media.sound.*;
481.37 +
481.38 +public class Load2 {
481.39 +
481.40 + private static void assertEquals(Object a, Object b) throws Exception
481.41 + {
481.42 + if(!a.equals(b))
481.43 + throw new RuntimeException("assertEquals fails!");
481.44 + }
481.45 +
481.46 + private static void assertTrue(boolean value) throws Exception
481.47 + {
481.48 + if(!value)
481.49 + throw new RuntimeException("assertTrue fails!");
481.50 + }
481.51 +
481.52 + public static void main(String[] args) throws Exception {
481.53 + // http://www.midi.org/about-midi/tuning.shtml
481.54 + // 0x02 SINGLE NOTE TUNING CHANGE (REAL-TIME)
481.55 + SoftTuning tuning = new SoftTuning();
481.56 + int[] msg = {0xf0,0x7f,0x7f,0x08,0x02,0x10,0x02,
481.57 + 36,36,64,0,
481.58 + 40,70,0,0,
481.59 + 0xf7};
481.60 + byte[] bmsg = new byte[msg.length];
481.61 + for (int i = 0; i < bmsg.length; i++)
481.62 + bmsg[i] = (byte)msg[i];
481.63 + tuning.load(bmsg);
481.64 + double[] tunings = tuning.getTuning();
481.65 + for (int i = 0; i < tunings.length; i++) {
481.66 + if(i == 36)
481.67 + assertTrue(Math.abs(tunings[i]-3650)< 0.00001);
481.68 + else if(i == 40)
481.69 + assertTrue(Math.abs(tunings[i]-7000) < 0.00001);
481.70 + else
481.71 + assertTrue(Math.abs(tunings[i]-i*100) < 0.00001);
481.72 + }
481.73 + }
481.74 +}
482.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
482.2 +++ b/test/javax/sound/midi/Gervill/SoftTuning/Load4.java Tue Feb 03 22:02:55 2009 -0800
482.3 @@ -0,0 +1,104 @@
482.4 +/*
482.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
482.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
482.7 + *
482.8 + * This code is free software; you can redistribute it and/or modify it
482.9 + * under the terms of the GNU General Public License version 2 only, as
482.10 + * published by the Free Software Foundation. Sun designates this
482.11 + * particular file as subject to the "Classpath" exception as provided
482.12 + * by Sun in the LICENSE file that accompanied this code.
482.13 + *
482.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
482.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
482.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
482.17 + * version 2 for more details (a copy is included in the LICENSE file that
482.18 + * accompanied this code).
482.19 + *
482.20 + * You should have received a copy of the GNU General Public License version
482.21 + * 2 along with this work; if not, write to the Free Software Foundation,
482.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
482.23 + *
482.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
482.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
482.26 + * have any questions.
482.27 + */
482.28 +
482.29 +/* @test
482.30 + @summary Test SoftTuning load method */
482.31 +
482.32 +import java.io.UnsupportedEncodingException;
482.33 +
482.34 +import javax.sound.midi.MidiUnavailableException;
482.35 +import javax.sound.midi.Patch;
482.36 +import javax.sound.sampled.*;
482.37 +
482.38 +import com.sun.media.sound.*;
482.39 +
482.40 +public class Load4 {
482.41 +
482.42 + private static void assertEquals(Object a, Object b) throws Exception
482.43 + {
482.44 + if(!a.equals(b))
482.45 + throw new RuntimeException("assertEquals fails!");
482.46 + }
482.47 +
482.48 + private static void assertTrue(boolean value) throws Exception
482.49 + {
482.50 + if(!value)
482.51 + throw new RuntimeException("assertTrue fails!");
482.52 + }
482.53 +
482.54 + public static void main(String[] args) throws Exception {
482.55 + // http://www.midi.org/about-midi/tuning_extens.shtml
482.56 + // 0x04 KEY-BASED TUNING DUMP
482.57 + SoftTuning tuning = new SoftTuning();
482.58 + byte[] name;
482.59 + name = "Testing123 ".getBytes("ascii");
482.60 +
482.61 + int[] msg = new int[25+3*128];
482.62 + int[] head = {0xf0,0x7e,0x7f,0x08,0x04,0x00,0x00};
482.63 + int ox = 0;
482.64 + for (int i = 0; i < head.length; i++)
482.65 + msg[ox++] = head[i];
482.66 + for (int i = 0; i < name.length; i++)
482.67 + msg[ox++] = name[i];
482.68 + for (int i = 0; i < 128; i++) {
482.69 + msg[ox++] = i;
482.70 + msg[ox++] = 64;
482.71 + msg[ox++] = 0;
482.72 + }
482.73 +
482.74 + // Calc checksum
482.75 + int x = msg[1] & 0xFF;
482.76 + for (int i = 2; i < msg.length - 2; i++)
482.77 + x = x ^ (msg[i] & 0xFF);
482.78 + msg[ox++] = (x & 127);
482.79 +
482.80 + msg[ox++] = 0xf7;
482.81 + byte[] bmsg = new byte[msg.length];
482.82 + for (int i = 0; i < bmsg.length; i++)
482.83 + bmsg[i] = (byte)msg[i];
482.84 +
482.85 + tuning.load(bmsg);
482.86 + assertEquals(tuning.getName(), "Testing123 ");
482.87 + double[] tunings = tuning.getTuning();
482.88 + for (int i = 0; i < tunings.length; i++)
482.89 + assertTrue(Math.abs(tunings[i]-(i*100 + 50)) < 0.00001);
482.90 +
482.91 + // Check if tuning fails if checksum is wrong
482.92 + msg[msg.length - 2] += 10;
482.93 + for (int i = 0; i < bmsg.length; i++)
482.94 + bmsg[i] = (byte)msg[i];
482.95 + tuning = new SoftTuning();
482.96 + tuning.load(bmsg);
482.97 + assertTrue(!tuning.getName().equals("Testing123 "));
482.98 +
482.99 + // Check if tuning fails if checksum is wrong
482.100 + msg[msg.length - 2] += 10;
482.101 + for (int i = 0; i < bmsg.length; i++)
482.102 + bmsg[i] = (byte)msg[i];
482.103 + tuning = new SoftTuning();
482.104 + tuning.load(bmsg);
482.105 + assertTrue(!tuning.getName().equals("Testing123 "));
482.106 + }
482.107 +}
483.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
483.2 +++ b/test/javax/sound/midi/Gervill/SoftTuning/Load5.java Tue Feb 03 22:02:55 2009 -0800
483.3 @@ -0,0 +1,87 @@
483.4 +/*
483.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
483.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
483.7 + *
483.8 + * This code is free software; you can redistribute it and/or modify it
483.9 + * under the terms of the GNU General Public License version 2 only, as
483.10 + * published by the Free Software Foundation. Sun designates this
483.11 + * particular file as subject to the "Classpath" exception as provided
483.12 + * by Sun in the LICENSE file that accompanied this code.
483.13 + *
483.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
483.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
483.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
483.17 + * version 2 for more details (a copy is included in the LICENSE file that
483.18 + * accompanied this code).
483.19 + *
483.20 + * You should have received a copy of the GNU General Public License version
483.21 + * 2 along with this work; if not, write to the Free Software Foundation,
483.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
483.23 + *
483.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
483.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
483.26 + * have any questions.
483.27 + */
483.28 +
483.29 +/* @test
483.30 + @summary Test SoftTuning load method */
483.31 +
483.32 +import java.io.UnsupportedEncodingException;
483.33 +
483.34 +import javax.sound.midi.MidiUnavailableException;
483.35 +import javax.sound.midi.Patch;
483.36 +import javax.sound.sampled.*;
483.37 +
483.38 +import com.sun.media.sound.*;
483.39 +
483.40 +public class Load5 {
483.41 +
483.42 + private static void assertEquals(Object a, Object b) throws Exception
483.43 + {
483.44 + if(!a.equals(b))
483.45 + throw new RuntimeException("assertEquals fails!");
483.46 + }
483.47 +
483.48 + private static void assertTrue(boolean value) throws Exception
483.49 + {
483.50 + if(!value)
483.51 + throw new RuntimeException("assertTrue fails!");
483.52 + }
483.53 +
483.54 + public static void main(String[] args) throws Exception {
483.55 + // http://www.midi.org/about-midi/tuning_extens.shtml
483.56 + // 0x05 SCALE/OCTAVE TUNING DUMP, 1 byte format
483.57 + SoftTuning tuning = new SoftTuning();
483.58 +
483.59 + byte[] name;
483.60 + name = "Testing123 ".getBytes("ascii");
483.61 + int[] msg = {0xf0,0x7e,0x7f,0x08,0x05,0,0,
483.62 + name[0],name[1],name[2],name[3],name[4],name[5],name[6],
483.63 + name[7],name[8],name[9],name[10],name[11],name[12],name[13],
483.64 + name[14],name[15],
483.65 + 5,10,15,20,25,30,35,40,45,50,51,52,0,
483.66 + 0xf7};
483.67 + // Calc checksum
483.68 + int x = msg[1] & 0xFF;
483.69 + for (int i = 2; i < msg.length - 2; i++)
483.70 + x = x ^ (msg[i] & 0xFF);
483.71 + msg[msg.length-2] = (x & 127);
483.72 +
483.73 + int[] oct = {5,10,15,20,25,30,35,40,45,50,51,52};
483.74 + byte[] bmsg = new byte[msg.length];
483.75 + for (int i = 0; i < bmsg.length; i++)
483.76 + bmsg[i] = (byte)msg[i];
483.77 + tuning.load(bmsg);
483.78 + double[] tunings = tuning.getTuning();
483.79 + for (int i = 0; i < tunings.length; i++)
483.80 + assertTrue(Math.abs(tunings[i]-(i*100 + (oct[i%12]-64))) < 0.00001);
483.81 +
483.82 + // Check if tuning fails if checksum is wrong
483.83 + msg[msg.length - 2] += 10;
483.84 + for (int i = 0; i < bmsg.length; i++)
483.85 + bmsg[i] = (byte)msg[i];
483.86 + tuning = new SoftTuning();
483.87 + tuning.load(bmsg);
483.88 + assertTrue(!tuning.getName().equals("Testing123 "));
483.89 + }
483.90 +}
484.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
484.2 +++ b/test/javax/sound/midi/Gervill/SoftTuning/Load6.java Tue Feb 03 22:02:55 2009 -0800
484.3 @@ -0,0 +1,91 @@
484.4 +/*
484.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
484.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
484.7 + *
484.8 + * This code is free software; you can redistribute it and/or modify it
484.9 + * under the terms of the GNU General Public License version 2 only, as
484.10 + * published by the Free Software Foundation. Sun designates this
484.11 + * particular file as subject to the "Classpath" exception as provided
484.12 + * by Sun in the LICENSE file that accompanied this code.
484.13 + *
484.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
484.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
484.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
484.17 + * version 2 for more details (a copy is included in the LICENSE file that
484.18 + * accompanied this code).
484.19 + *
484.20 + * You should have received a copy of the GNU General Public License version
484.21 + * 2 along with this work; if not, write to the Free Software Foundation,
484.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
484.23 + *
484.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
484.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
484.26 + * have any questions.
484.27 + */
484.28 +
484.29 +/* @test
484.30 + @summary Test SoftTuning load method */
484.31 +
484.32 +import java.io.UnsupportedEncodingException;
484.33 +
484.34 +import javax.sound.midi.MidiUnavailableException;
484.35 +import javax.sound.midi.Patch;
484.36 +import javax.sound.sampled.*;
484.37 +
484.38 +import com.sun.media.sound.*;
484.39 +
484.40 +public class Load6 {
484.41 +
484.42 + private static void assertEquals(Object a, Object b) throws Exception
484.43 + {
484.44 + if(!a.equals(b))
484.45 + throw new RuntimeException("assertEquals fails!");
484.46 + }
484.47 +
484.48 + private static void assertTrue(boolean value) throws Exception
484.49 + {
484.50 + if(!value)
484.51 + throw new RuntimeException("assertTrue fails!");
484.52 + }
484.53 +
484.54 + public static void main(String[] args) throws Exception {
484.55 + // http://www.midi.org/about-midi/tuning_extens.shtml
484.56 + // 0x06 SCALE/OCTAVE TUNING DUMP, 2 byte format
484.57 + SoftTuning tuning = new SoftTuning();
484.58 +
484.59 + byte[] name;
484.60 + name = "Testing123 ".getBytes("ascii");
484.61 + int[] msg = {0xf0,0x7e,0x7f,0x08,0x06,0,0,
484.62 + name[0],name[1],name[2],name[3],name[4],name[5],name[6],
484.63 + name[7],name[8],name[9],name[10],name[11],name[12],name[13],
484.64 + name[14],name[15],
484.65 + 5,10,15,20,25,30,35,40,45,50,51,52,
484.66 + 5,10,15,20,25,30,35,40,45,50,51,52,
484.67 + 0,0xf7};
484.68 + // Calc checksum
484.69 + int x = msg[1] & 0xFF;
484.70 + for (int i = 2; i < msg.length - 2; i++)
484.71 + x = x ^ (msg[i] & 0xFF);
484.72 + msg[msg.length-2] = (x & 127);
484.73 +
484.74 + int[] oct = {5,10,15,20,25,30,35,40,45,50,51,52,5,10,15,20,25,30,35,40,45,50,51,52};
484.75 + byte[] bmsg = new byte[msg.length];
484.76 + for (int i = 0; i < bmsg.length; i++)
484.77 + bmsg[i] = (byte)msg[i];
484.78 + tuning.load(bmsg);
484.79 + double[] tunings = tuning.getTuning();
484.80 + for (int i = 0; i < tunings.length; i++)
484.81 + {
484.82 + double c = (oct[(i%12)*2]*128 + oct[(i%12)*2+1] -8192)*(100.0/8192.0);
484.83 + assertTrue(Math.abs(tunings[i]-(i*100 + (c))) < 0.00001);
484.84 + }
484.85 +
484.86 + // Check if tuning fails if checksum is wrong
484.87 + msg[msg.length - 2] += 10;
484.88 + for (int i = 0; i < bmsg.length; i++)
484.89 + bmsg[i] = (byte)msg[i];
484.90 + tuning = new SoftTuning();
484.91 + tuning.load(bmsg);
484.92 + assertTrue(!tuning.getName().equals("Testing123 "));
484.93 + }
484.94 +}
485.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
485.2 +++ b/test/javax/sound/midi/Gervill/SoftTuning/Load7.java Tue Feb 03 22:02:55 2009 -0800
485.3 @@ -0,0 +1,72 @@
485.4 +/*
485.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
485.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
485.7 + *
485.8 + * This code is free software; you can redistribute it and/or modify it
485.9 + * under the terms of the GNU General Public License version 2 only, as
485.10 + * published by the Free Software Foundation. Sun designates this
485.11 + * particular file as subject to the "Classpath" exception as provided
485.12 + * by Sun in the LICENSE file that accompanied this code.
485.13 + *
485.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
485.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
485.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
485.17 + * version 2 for more details (a copy is included in the LICENSE file that
485.18 + * accompanied this code).
485.19 + *
485.20 + * You should have received a copy of the GNU General Public License version
485.21 + * 2 along with this work; if not, write to the Free Software Foundation,
485.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
485.23 + *
485.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
485.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
485.26 + * have any questions.
485.27 + */
485.28 +
485.29 +/* @test
485.30 + @summary Test SoftTuning load method */
485.31 +
485.32 +import javax.sound.midi.MidiUnavailableException;
485.33 +import javax.sound.midi.Patch;
485.34 +import javax.sound.sampled.*;
485.35 +
485.36 +import com.sun.media.sound.*;
485.37 +
485.38 +public class Load7 {
485.39 +
485.40 + private static void assertEquals(Object a, Object b) throws Exception
485.41 + {
485.42 + if(!a.equals(b))
485.43 + throw new RuntimeException("assertEquals fails!");
485.44 + }
485.45 +
485.46 + private static void assertTrue(boolean value) throws Exception
485.47 + {
485.48 + if(!value)
485.49 + throw new RuntimeException("assertTrue fails!");
485.50 + }
485.51 +
485.52 + public static void main(String[] args) throws Exception {
485.53 + // http://www.midi.org/about-midi/tuning_extens.shtml
485.54 + // 0x07 SINGLE NOTE TUNING CHANGE (NON REAL-TIME) (BANK)
485.55 + SoftTuning tuning = new SoftTuning();
485.56 + int[] msg = {0xf0,0x7f,0x7f,0x08,0x07,0x00,0x00,0x02,
485.57 + 36,36,64,0,
485.58 + 40,70,0,0,
485.59 + 0xf7};
485.60 + byte[] bmsg = new byte[msg.length];
485.61 + for (int i = 0; i < bmsg.length; i++)
485.62 + bmsg[i] = (byte)msg[i];
485.63 + tuning.load(bmsg);
485.64 + double[] tunings = tuning.getTuning();
485.65 + for (int i = 0; i < tunings.length; i++) {
485.66 + if(i == 36)
485.67 + assertTrue(Math.abs(tunings[i]-3650)< 0.00001);
485.68 + else if(i == 40)
485.69 + assertTrue(Math.abs(tunings[i]-7000) < 0.00001);
485.70 + else
485.71 + assertTrue(Math.abs(tunings[i]-i*100) < 0.00001);
485.72 + }
485.73 +
485.74 + }
485.75 +}
486.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
486.2 +++ b/test/javax/sound/midi/Gervill/SoftTuning/Load8.java Tue Feb 03 22:02:55 2009 -0800
486.3 @@ -0,0 +1,65 @@
486.4 +/*
486.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
486.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
486.7 + *
486.8 + * This code is free software; you can redistribute it and/or modify it
486.9 + * under the terms of the GNU General Public License version 2 only, as
486.10 + * published by the Free Software Foundation. Sun designates this
486.11 + * particular file as subject to the "Classpath" exception as provided
486.12 + * by Sun in the LICENSE file that accompanied this code.
486.13 + *
486.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
486.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
486.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
486.17 + * version 2 for more details (a copy is included in the LICENSE file that
486.18 + * accompanied this code).
486.19 + *
486.20 + * You should have received a copy of the GNU General Public License version
486.21 + * 2 along with this work; if not, write to the Free Software Foundation,
486.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
486.23 + *
486.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
486.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
486.26 + * have any questions.
486.27 + */
486.28 +
486.29 +/* @test
486.30 + @summary Test SoftTuning load method */
486.31 +
486.32 +import javax.sound.midi.MidiUnavailableException;
486.33 +import javax.sound.midi.Patch;
486.34 +import javax.sound.sampled.*;
486.35 +
486.36 +import com.sun.media.sound.*;
486.37 +
486.38 +public class Load8 {
486.39 +
486.40 + private static void assertEquals(Object a, Object b) throws Exception
486.41 + {
486.42 + if(!a.equals(b))
486.43 + throw new RuntimeException("assertEquals fails!");
486.44 + }
486.45 +
486.46 + private static void assertTrue(boolean value) throws Exception
486.47 + {
486.48 + if(!value)
486.49 + throw new RuntimeException("assertTrue fails!");
486.50 + }
486.51 +
486.52 + public static void main(String[] args) throws Exception {
486.53 + // http://www.midi.org/about-midi/tuning-scale.shtml
486.54 + // 0x08 scale/octave tuning 1-byte form (Non Real-Time/REAL-TIME)
486.55 + SoftTuning tuning = new SoftTuning();
486.56 + int[] msg = {0xf0,0x7f,0x7f,0x08,0x08,0x03,0x7f,0x7f,
486.57 + 5,10,15,20,25,30,35,40,45,50,51,52,
486.58 + 0xf7};
486.59 + int[] oct = {5,10,15,20,25,30,35,40,45,50,51,52};
486.60 + byte[] bmsg = new byte[msg.length];
486.61 + for (int i = 0; i < bmsg.length; i++)
486.62 + bmsg[i] = (byte)msg[i];
486.63 + tuning.load(bmsg);
486.64 + double[] tunings = tuning.getTuning();
486.65 + for (int i = 0; i < tunings.length; i++)
486.66 + assertTrue(Math.abs(tunings[i]-(i*100 + (oct[i%12]-64))) < 0.00001);
486.67 + }
486.68 +}
487.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
487.2 +++ b/test/javax/sound/midi/Gervill/SoftTuning/Load9.java Tue Feb 03 22:02:55 2009 -0800
487.3 @@ -0,0 +1,69 @@
487.4 +/*
487.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
487.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
487.7 + *
487.8 + * This code is free software; you can redistribute it and/or modify it
487.9 + * under the terms of the GNU General Public License version 2 only, as
487.10 + * published by the Free Software Foundation. Sun designates this
487.11 + * particular file as subject to the "Classpath" exception as provided
487.12 + * by Sun in the LICENSE file that accompanied this code.
487.13 + *
487.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
487.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
487.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
487.17 + * version 2 for more details (a copy is included in the LICENSE file that
487.18 + * accompanied this code).
487.19 + *
487.20 + * You should have received a copy of the GNU General Public License version
487.21 + * 2 along with this work; if not, write to the Free Software Foundation,
487.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
487.23 + *
487.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
487.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
487.26 + * have any questions.
487.27 + */
487.28 +
487.29 +/* @test
487.30 + @summary Test SoftTuning load method */
487.31 +
487.32 +import javax.sound.midi.MidiUnavailableException;
487.33 +import javax.sound.midi.Patch;
487.34 +import javax.sound.sampled.*;
487.35 +
487.36 +import com.sun.media.sound.*;
487.37 +
487.38 +public class Load9 {
487.39 +
487.40 + private static void assertEquals(Object a, Object b) throws Exception
487.41 + {
487.42 + if(!a.equals(b))
487.43 + throw new RuntimeException("assertEquals fails!");
487.44 + }
487.45 +
487.46 + private static void assertTrue(boolean value) throws Exception
487.47 + {
487.48 + if(!value)
487.49 + throw new RuntimeException("assertTrue fails!");
487.50 + }
487.51 +
487.52 + public static void main(String[] args) throws Exception {
487.53 + // http://www.midi.org/about-midi/tuning-scale.shtml
487.54 + // 0x09 scale/octave tuning 2-byte form (Non Real-Time/REAL-TIME)
487.55 + SoftTuning tuning = new SoftTuning();
487.56 + int[] msg = {0xf0,0x7f,0x7f,0x08,0x09,0x03,0x7f,0x7f,
487.57 + 5,10,15,20,25,30,35,40,45,50,51,52,
487.58 + 5,10,15,20,25,30,35,40,45,50,51,52,
487.59 + 0xf7};
487.60 + int[] oct = {5,10,15,20,25,30,35,40,45,50,51,52,5,10,15,20,25,30,35,40,45,50,51,52};
487.61 + byte[] bmsg = new byte[msg.length];
487.62 + for (int i = 0; i < bmsg.length; i++)
487.63 + bmsg[i] = (byte)msg[i];
487.64 + tuning.load(bmsg);
487.65 + double[] tunings = tuning.getTuning();
487.66 + for (int i = 0; i < tunings.length; i++)
487.67 + {
487.68 + double c = (oct[(i%12)*2]*128 + oct[(i%12)*2+1] -8192)*(100.0/8192.0);
487.69 + assertTrue(Math.abs(tunings[i]-(i*100 + (c))) < 0.00001);
487.70 + }
487.71 + }
487.72 +}
488.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
488.2 +++ b/test/javax/sound/midi/Gervill/SoftTuning/NewSoftTuning.java Tue Feb 03 22:02:55 2009 -0800
488.3 @@ -0,0 +1,56 @@
488.4 +/*
488.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
488.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
488.7 + *
488.8 + * This code is free software; you can redistribute it and/or modify it
488.9 + * under the terms of the GNU General Public License version 2 only, as
488.10 + * published by the Free Software Foundation. Sun designates this
488.11 + * particular file as subject to the "Classpath" exception as provided
488.12 + * by Sun in the LICENSE file that accompanied this code.
488.13 + *
488.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
488.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
488.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
488.17 + * version 2 for more details (a copy is included in the LICENSE file that
488.18 + * accompanied this code).
488.19 + *
488.20 + * You should have received a copy of the GNU General Public License version
488.21 + * 2 along with this work; if not, write to the Free Software Foundation,
488.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
488.23 + *
488.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
488.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
488.26 + * have any questions.
488.27 + */
488.28 +
488.29 +/* @test
488.30 + @summary Test SoftTuning constructor */
488.31 +
488.32 +import javax.sound.midi.MidiUnavailableException;
488.33 +import javax.sound.midi.Patch;
488.34 +import javax.sound.sampled.*;
488.35 +
488.36 +import com.sun.media.sound.*;
488.37 +
488.38 +public class NewSoftTuning {
488.39 +
488.40 + private static void assertEquals(Object a, Object b) throws Exception
488.41 + {
488.42 + if(!a.equals(b))
488.43 + throw new RuntimeException("assertEquals fails!");
488.44 + }
488.45 +
488.46 + private static void assertTrue(boolean value) throws Exception
488.47 + {
488.48 + if(!value)
488.49 + throw new RuntimeException("assertTrue fails!");
488.50 + }
488.51 +
488.52 + public static void main(String[] args) throws Exception {
488.53 + SoftTuning tuning = new SoftTuning();
488.54 + double[] tunings = tuning.getTuning();
488.55 + for (int i = 0; i < tunings.length; i++) {
488.56 + assertTrue(Math.abs(tunings[i]-i*100) < 0.00001);
488.57 + }
488.58 + }
488.59 +}
489.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
489.2 +++ b/test/javax/sound/midi/Gervill/SoftTuning/NewSoftTuningByteArray.java Tue Feb 03 22:02:55 2009 -0800
489.3 @@ -0,0 +1,63 @@
489.4 +/*
489.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
489.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489.7 + *
489.8 + * This code is free software; you can redistribute it and/or modify it
489.9 + * under the terms of the GNU General Public License version 2 only, as
489.10 + * published by the Free Software Foundation. Sun designates this
489.11 + * particular file as subject to the "Classpath" exception as provided
489.12 + * by Sun in the LICENSE file that accompanied this code.
489.13 + *
489.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
489.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
489.17 + * version 2 for more details (a copy is included in the LICENSE file that
489.18 + * accompanied this code).
489.19 + *
489.20 + * You should have received a copy of the GNU General Public License version
489.21 + * 2 along with this work; if not, write to the Free Software Foundation,
489.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489.23 + *
489.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
489.26 + * have any questions.
489.27 + */
489.28 +
489.29 +/* @test
489.30 + @summary Test SoftTuning constructor */
489.31 +
489.32 +import javax.sound.midi.MidiUnavailableException;
489.33 +import javax.sound.midi.Patch;
489.34 +import javax.sound.sampled.*;
489.35 +
489.36 +import com.sun.media.sound.*;
489.37 +
489.38 +public class NewSoftTuningByteArray {
489.39 +
489.40 + private static void assertEquals(Object a, Object b) throws Exception
489.41 + {
489.42 + if(!a.equals(b))
489.43 + throw new RuntimeException("assertEquals fails!");
489.44 + }
489.45 +
489.46 + private static void assertTrue(boolean value) throws Exception
489.47 + {
489.48 + if(!value)
489.49 + throw new RuntimeException("assertTrue fails!");
489.50 + }
489.51 +
489.52 + public static void main(String[] args) throws Exception {
489.53 + // RealTime: Scale/Octave tuning in 1-byte format
489.54 + int[] msg = {0xf0,0x7f,0x7f,0x08,0x08,0x03,0x7f,0x7f,
489.55 + 5,10,15,20,25,30,35,40,45,50,51,52,
489.56 + 0xf7};
489.57 + int[] oct = {5,10,15,20,25,30,35,40,45,50,51,52};
489.58 + byte[] bmsg = new byte[msg.length];
489.59 + for (int i = 0; i < bmsg.length; i++)
489.60 + bmsg[i] = (byte)msg[i];
489.61 + SoftTuning tuning = new SoftTuning(bmsg);
489.62 + double[] tunings = tuning.getTuning();
489.63 + for (int i = 0; i < tunings.length; i++)
489.64 + assertTrue(Math.abs(tunings[i]-(i*100 + (oct[i%12]-64))) < 0.00001);
489.65 + }
489.66 +}
490.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
490.2 +++ b/test/javax/sound/midi/Gervill/SoftTuning/NewSoftTuningPatch.java Tue Feb 03 22:02:55 2009 -0800
490.3 @@ -0,0 +1,54 @@
490.4 +/*
490.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
490.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
490.7 + *
490.8 + * This code is free software; you can redistribute it and/or modify it
490.9 + * under the terms of the GNU General Public License version 2 only, as
490.10 + * published by the Free Software Foundation. Sun designates this
490.11 + * particular file as subject to the "Classpath" exception as provided
490.12 + * by Sun in the LICENSE file that accompanied this code.
490.13 + *
490.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
490.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
490.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
490.17 + * version 2 for more details (a copy is included in the LICENSE file that
490.18 + * accompanied this code).
490.19 + *
490.20 + * You should have received a copy of the GNU General Public License version
490.21 + * 2 along with this work; if not, write to the Free Software Foundation,
490.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
490.23 + *
490.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
490.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
490.26 + * have any questions.
490.27 + */
490.28 +
490.29 +/* @test
490.30 + @summary Test SoftTuning constructor */
490.31 +
490.32 +import javax.sound.midi.MidiUnavailableException;
490.33 +import javax.sound.midi.Patch;
490.34 +import javax.sound.sampled.*;
490.35 +
490.36 +import com.sun.media.sound.*;
490.37 +
490.38 +public class NewSoftTuningPatch {
490.39 +
490.40 + private static void assertEquals(Object a, Object b) throws Exception
490.41 + {
490.42 + if(!a.equals(b))
490.43 + throw new RuntimeException("assertEquals fails!");
490.44 + }
490.45 +
490.46 + private static void assertTrue(boolean value) throws Exception
490.47 + {
490.48 + if(!value)
490.49 + throw new RuntimeException("assertTrue fails!");
490.50 + }
490.51 +
490.52 + public static void main(String[] args) throws Exception {
490.53 + SoftTuning tuning = new SoftTuning(new Patch(8,32));
490.54 + assertEquals(tuning.getPatch().getProgram(), 32);
490.55 + assertEquals(tuning.getPatch().getBank(), 8);
490.56 + }
490.57 +}
491.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
491.2 +++ b/test/javax/sound/midi/Gervill/SoftTuning/NewSoftTuningPatchByteArray.java Tue Feb 03 22:02:55 2009 -0800
491.3 @@ -0,0 +1,65 @@
491.4 +/*
491.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
491.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
491.7 + *
491.8 + * This code is free software; you can redistribute it and/or modify it
491.9 + * under the terms of the GNU General Public License version 2 only, as
491.10 + * published by the Free Software Foundation. Sun designates this
491.11 + * particular file as subject to the "Classpath" exception as provided
491.12 + * by Sun in the LICENSE file that accompanied this code.
491.13 + *
491.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
491.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
491.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
491.17 + * version 2 for more details (a copy is included in the LICENSE file that
491.18 + * accompanied this code).
491.19 + *
491.20 + * You should have received a copy of the GNU General Public License version
491.21 + * 2 along with this work; if not, write to the Free Software Foundation,
491.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
491.23 + *
491.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
491.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
491.26 + * have any questions.
491.27 + */
491.28 +
491.29 +/* @test
491.30 + @summary Test SoftTuning constructor */
491.31 +
491.32 +import javax.sound.midi.MidiUnavailableException;
491.33 +import javax.sound.midi.Patch;
491.34 +import javax.sound.sampled.*;
491.35 +
491.36 +import com.sun.media.sound.*;
491.37 +
491.38 +public class NewSoftTuningPatchByteArray {
491.39 +
491.40 + private static void assertEquals(Object a, Object b) throws Exception
491.41 + {
491.42 + if(!a.equals(b))
491.43 + throw new RuntimeException("assertEquals fails!");
491.44 + }
491.45 +
491.46 + private static void assertTrue(boolean value) throws Exception
491.47 + {
491.48 + if(!value)
491.49 + throw new RuntimeException("assertTrue fails!");
491.50 + }
491.51 +
491.52 + public static void main(String[] args) throws Exception {
491.53 + // RealTime: Scale/Octave tuning in 1-byte format
491.54 + int[] msg = {0xf0,0x7f,0x7f,0x08,0x08,0x03,0x7f,0x7f,
491.55 + 5,10,15,20,25,30,35,40,45,50,51,52,
491.56 + 0xf7};
491.57 + int[] oct = {5,10,15,20,25,30,35,40,45,50,51,52};
491.58 + byte[] bmsg = new byte[msg.length];
491.59 + for (int i = 0; i < bmsg.length; i++)
491.60 + bmsg[i] = (byte)msg[i];
491.61 + SoftTuning tuning = new SoftTuning(new Patch(8,32),bmsg);
491.62 + double[] tunings = tuning.getTuning();
491.63 + for (int i = 0; i < tunings.length; i++)
491.64 + assertTrue(Math.abs(tunings[i]-(i*100 + (oct[i%12]-64))) < 0.00001);
491.65 + assertEquals(tuning.getPatch().getProgram(), 32);
491.66 + assertEquals(tuning.getPatch().getBank(), 8);
491.67 + }
491.68 +}
492.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
492.2 +++ b/test/javax/swing/JColorChooser/Test4222508.html Tue Feb 03 22:02:55 2009 -0800
492.3 @@ -0,0 +1,9 @@
492.4 +<html>
492.5 +<body>
492.6 +Use the check box above the color chooser to disable it.
492.7 +You could not choose a color using by the disable color chooser.
492.8 +
492.9 +<applet width="600" height="400" code="Test4222508.class">
492.10 +</applet>
492.11 +</body>
492.12 +</html>
493.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
493.2 +++ b/test/javax/swing/JColorChooser/Test4222508.java Tue Feb 03 22:02:55 2009 -0800
493.3 @@ -0,0 +1,56 @@
493.4 +/*
493.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
493.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
493.7 + *
493.8 + * This code is free software; you can redistribute it and/or modify it
493.9 + * under the terms of the GNU General Public License version 2 only, as
493.10 + * published by the Free Software Foundation.
493.11 + *
493.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
493.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
493.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
493.15 + * version 2 for more details (a copy is included in the LICENSE file that
493.16 + * accompanied this code).
493.17 + *
493.18 + * You should have received a copy of the GNU General Public License version
493.19 + * 2 along with this work; if not, write to the Free Software Foundation,
493.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
493.21 + *
493.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
493.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
493.24 + * have any questions.
493.25 + */
493.26 +
493.27 +/*
493.28 + * @test
493.29 + * @bug 4222508
493.30 + * @summary Tests the color chooser disabling
493.31 + * @author Sergey Malenkov
493.32 + * @run applet/manual=yesno Test4222508.html
493.33 + */
493.34 +
493.35 +import java.awt.BorderLayout;
493.36 +import java.awt.event.ItemEvent;
493.37 +import java.awt.event.ItemListener;
493.38 +import javax.swing.JApplet;
493.39 +import javax.swing.JCheckBox;
493.40 +import javax.swing.JColorChooser;
493.41 +
493.42 +public final class Test4222508 extends JApplet implements ItemListener {
493.43 +
493.44 + private JCheckBox checkbox;
493.45 + private JColorChooser chooser;
493.46 +
493.47 + @Override
493.48 + public void init() {
493.49 + this.chooser = new JColorChooser();
493.50 + this.checkbox = new JCheckBox("Enable the color chooser below", true);
493.51 + this.checkbox.addItemListener(this);
493.52 + add(BorderLayout.NORTH, this.checkbox);
493.53 + add(BorderLayout.CENTER, this.chooser);
493.54 + }
493.55 +
493.56 + public void itemStateChanged(ItemEvent event) {
493.57 + this.chooser.setEnabled(this.checkbox.isSelected());
493.58 + }
493.59 +}
494.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
494.2 +++ b/test/javax/swing/JFileChooser/6698013/bug6698013.html Tue Feb 03 22:02:55 2009 -0800
494.3 @@ -0,0 +1,8 @@
494.4 +<html>
494.5 +<body>
494.6 +<applet code="bug6698013.class" width=200 height=200></applet>
494.7 +1. Go into 'subdir' folder via double click
494.8 +2. Return to parent directory
494.9 +3. Go into 'subdir' folder: select 'subdir' folder and press the 'Open' button
494.10 +</body>
494.11 +</html>
495.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
495.2 +++ b/test/javax/swing/JFileChooser/6698013/bug6698013.java Tue Feb 03 22:02:55 2009 -0800
495.3 @@ -0,0 +1,174 @@
495.4 +/* @test %W% %E%
495.5 + @bug 6698013
495.6 + @summary JFileChooser can no longer navigate non-local file systems.
495.7 + @author Pavel Porvatov
495.8 + @run applet/manual=done bug6698013.html
495.9 +*/
495.10 +
495.11 +import javax.swing.*;
495.12 +import javax.swing.filechooser.FileSystemView;
495.13 +import java.io.File;
495.14 +
495.15 +public class bug6698013 extends JApplet {
495.16 +
495.17 + final static VirtualFile root = new VirtualFile("testdir", true);
495.18 +
495.19 + final static VirtualFile rootFile = new VirtualFile("testdir/test.txt", false);
495.20 +
495.21 + final static VirtualFile subdir = new VirtualFile("testdir/subdir", true);
495.22 +
495.23 + final static VirtualFile subdirFile = new VirtualFile("testdir/subdir/subtest.txt", false);
495.24 +
495.25 + public static void main(String[] args) {
495.26 + JFileChooser chooser = new JFileChooser(new VirtualFileSystemView());
495.27 + chooser.setCurrentDirectory(root);
495.28 + chooser.showSaveDialog(null);
495.29 + }
495.30 +
495.31 + public void init() {
495.32 + JFileChooser chooser = new JFileChooser(new VirtualFileSystemView());
495.33 + chooser.setCurrentDirectory(root);
495.34 + chooser.showSaveDialog(null);
495.35 + }
495.36 +}
495.37 +
495.38 +class VirtualFileSystemView extends FileSystemView {
495.39 +
495.40 + public boolean isRoot(File dir) {
495.41 + return bug6698013.root.equals(dir);
495.42 + }
495.43 +
495.44 + public File createNewFolder(File dir) {
495.45 + return null;
495.46 + }
495.47 +
495.48 + public File[] getRoots() {
495.49 + return new File[]{bug6698013.root};
495.50 + }
495.51 +
495.52 + public boolean isDrive(File dir) {
495.53 + return false;
495.54 + }
495.55 +
495.56 + public boolean isFloppyDrive(File dir) {
495.57 + return false;
495.58 + }
495.59 +
495.60 + public File getParentDirectory(File dir) {
495.61 + if (dir == null) {
495.62 + return null;
495.63 + }
495.64 +
495.65 + return new VirtualFile(dir.getPath(), true).getParentFile();
495.66 + }
495.67 +
495.68 + public File[] getFiles(File dir, boolean hide_hidden) {
495.69 + if (dir.equals(bug6698013.root)) {
495.70 + return new File[]{bug6698013.rootFile, bug6698013.subdir};
495.71 + }
495.72 +
495.73 + if (dir.equals(bug6698013.subdir)) {
495.74 + return new File[]{bug6698013.subdirFile};
495.75 + }
495.76 +
495.77 + return null;
495.78 + }
495.79 +
495.80 + public File getHomeDirectory() {
495.81 + return bug6698013.root;
495.82 + }
495.83 +
495.84 + public File getDefaultDirectory() {
495.85 + return getHomeDirectory();
495.86 + }
495.87 +
495.88 + public String getSystemDisplayName(File file) {
495.89 + return file.getName();
495.90 + }
495.91 +
495.92 + public Boolean isTraversable(File file) {
495.93 + return Boolean.valueOf(file.isDirectory());
495.94 + }
495.95 +}
495.96 +
495.97 +/**
495.98 + * A Virtual File. Contains a path and a directory flag that
495.99 + * represents the location of a virtual file to be contained in the
495.100 + * Virtual FileSystemView.
495.101 + */
495.102 +class VirtualFile extends File {
495.103 +
495.104 + private static final long serialVersionUID = 0L;
495.105 +
495.106 + private String path;
495.107 +
495.108 + private boolean directory;
495.109 +
495.110 + public VirtualFile(String path, boolean directory) {
495.111 + super(path);
495.112 + this.path = path;
495.113 + this.directory = directory;
495.114 + }
495.115 +
495.116 + public File getParentFile() {
495.117 + int index = path.lastIndexOf('/');
495.118 +
495.119 + if (index == -1) {
495.120 + return null;
495.121 + }
495.122 +
495.123 + return new VirtualFile(path.substring(0, index), true);
495.124 + }
495.125 +
495.126 + public File getCanonicalFile() {
495.127 + return this;
495.128 + }
495.129 +
495.130 + public String getParent() {
495.131 + File parent_file = getParentFile();
495.132 +
495.133 + return parent_file == null ? null : parent_file.getPath();
495.134 + }
495.135 +
495.136 + public String getName() {
495.137 + int index = path.lastIndexOf('/');
495.138 +
495.139 + return index == -1 ? path : path.substring(index + 1);
495.140 + }
495.141 +
495.142 + public String getPath() {
495.143 + return path;
495.144 + }
495.145 +
495.146 + public String getAbsolutePath() {
495.147 + return path;
495.148 + }
495.149 +
495.150 + public String getCanonicalPath() {
495.151 + return path;
495.152 + }
495.153 +
495.154 + public String toString() {
495.155 + return path;
495.156 + }
495.157 +
495.158 + public boolean equals(Object obj) {
495.159 + return obj instanceof VirtualFile && path.equals(obj.toString());
495.160 + }
495.161 +
495.162 + public int hashCode() {
495.163 + return path.hashCode();
495.164 + }
495.165 +
495.166 + public boolean canWrite() {
495.167 + return true;
495.168 + }
495.169 +
495.170 + public boolean isDirectory() {
495.171 + return directory;
495.172 + }
495.173 +
495.174 + public boolean exists() {
495.175 + return true;
495.176 + }
495.177 +}
496.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
496.2 +++ b/test/javax/swing/JSlider/6794836/bug6794836.java Tue Feb 03 22:02:55 2009 -0800
496.3 @@ -0,0 +1,80 @@
496.4 +/*
496.5 + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
496.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
496.7 + *
496.8 + * This code is free software; you can redistribute it and/or modify it
496.9 + * under the terms of the GNU General Public License version 2 only, as
496.10 + * published by the Free Software Foundation.
496.11 + *
496.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
496.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
496.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
496.15 + * version 2 for more details (a copy is included in the LICENSE file that
496.16 + * accompanied this code).
496.17 + *
496.18 + * You should have received a copy of the GNU General Public License version
496.19 + * 2 along with this work; if not, write to the Free Software Foundation,
496.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
496.21 + *
496.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
496.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
496.24 + * have any questions.
496.25 + */
496.26 +
496.27 +/* @test
496.28 + * @bug 6794836
496.29 + * @summary BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
496.30 + * @author Pavel Porvatov
496.31 + * @run main bug6794836
496.32 + */
496.33 +
496.34 +import javax.swing.*;
496.35 +import javax.swing.plaf.basic.BasicSliderUI;
496.36 +import java.lang.reflect.Method;
496.37 +import java.util.Hashtable;
496.38 +
496.39 +public class bug6794836 {
496.40 + public static void main(String[] args) throws Exception {
496.41 + new bug6794836().run();
496.42 + }
496.43 +
496.44 + public void run() throws Exception {
496.45 + JSlider slider = new JSlider(0, Integer.MAX_VALUE);
496.46 +
496.47 + slider.setPaintLabels(true);
496.48 +
496.49 + JLabel minLabel = new JLabel("Min");
496.50 + JLabel maxLabel = new JLabel("Max");
496.51 +
496.52 + Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>();
496.53 +
496.54 + labelTable.put(Integer.MIN_VALUE, minLabel);
496.55 + labelTable.put(Integer.MAX_VALUE, maxLabel);
496.56 +
496.57 + slider.setLabelTable(labelTable);
496.58 +
496.59 + BasicSliderUI ui = (BasicSliderUI) slider.getUI();
496.60 +
496.61 + if (invokeMethod("getHighestValueLabel", ui) != maxLabel) {
496.62 + fail("invalid getHighestValueLabel result");
496.63 + }
496.64 +
496.65 + if (invokeMethod("getLowestValueLabel", ui) != minLabel) {
496.66 + fail("invalid getLowestValueLabel result");
496.67 + }
496.68 +
496.69 + System.out.println("The bug6794836 test passed");
496.70 + }
496.71 +
496.72 + private static Object invokeMethod(String name, BasicSliderUI ui) throws Exception {
496.73 + Method method = BasicSliderUI.class.getDeclaredMethod(name, null);
496.74 +
496.75 + method.setAccessible(true);
496.76 +
496.77 + return method.invoke(ui, null);
496.78 + }
496.79 +
496.80 + private static void fail(String s) {
496.81 + throw new RuntimeException("Test failed: " + s);
496.82 + }
496.83 +}
497.1 --- a/test/sun/text/resources/LocaleData Thu Jan 29 21:46:48 2009 -0800
497.2 +++ b/test/sun/text/resources/LocaleData Tue Feb 03 22:02:55 2009 -0800
497.3 @@ -5518,3 +5518,11 @@
497.4 FormatData/sv/AmPmMarkers/0=fm
497.5 FormatData/sv/AmPmMarkers/1=em
497.6
497.7 +# JE, GG, IM (6544471)
497.8 +LocaleNames//JE=Jersey
497.9 +LocaleNames//GG=Guernsey
497.10 +LocaleNames//IM=Isle Of Man
497.11 +
497.12 +# BL, MF (6627549)
497.13 +LocaleNames//BL=Saint Barth\u00e9lemy
497.14 +LocaleNames//MF=Saint Martin