From 2fe8b1b92fa2a9b93fea0ed0cb62802237b82e8d Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Tue, 8 Dec 2020 22:26:17 +0900 Subject: Renaming of files in preparation for code style tools. Signed-off-by: Michele Calgaro (cherry picked from commit fce86b22a2367f1be1f9aae5e1ba3d18d1371b74) --- akode_artsplugin/CMakeLists.txt | 4 +- akode_artsplugin/Makefile.am | 6 +- arts/Makefile.am | 2 +- arts/gui/common/CMakeLists.txt | 6 +- arts/gui/common/Makefile.am | 8 +- arts/gui/common/artsgui.idl | 2 +- arts/gui/common/genericguifactory_impl.cc | 56 - arts/gui/common/genericguifactory_impl.cpp | 56 + arts/midi/CMakeLists.txt | 18 +- arts/midi/Makefile.am | 20 +- arts/midi/README.midi | 2 +- arts/midi/alsamidigateway_impl.cc | 243 ---- arts/midi/alsamidigateway_impl.cpp | 243 ++++ arts/midi/alsamidiport_impl.cc | 232 ---- arts/midi/alsamidiport_impl.cpp | 232 ++++ arts/midi/artsmidi.idl | 2 +- arts/midi/audiomiditimer_impl.cc | 116 -- arts/midi/audiomiditimer_impl.cpp | 116 ++ arts/midi/audiosync_impl.cc | 203 --- arts/midi/audiosync_impl.cpp | 203 +++ arts/midi/audiotimer.cc | 98 -- arts/midi/audiotimer.cpp | 98 ++ arts/midi/midiclient_impl.cc | 274 ---- arts/midi/midiclient_impl.cpp | 274 ++++ arts/midi/midimanager_impl.cc | 156 --- arts/midi/midimanager_impl.cpp | 156 +++ arts/midi/midimanagerport_impl.cc | 71 - arts/midi/midimanagerport_impl.cpp | 71 + arts/midi/midisend.cc | 375 ------ arts/midi/midisend.cpp | 375 ++++++ arts/midi/midisyncgroup_impl.cc | 125 -- arts/midi/midisyncgroup_impl.cpp | 125 ++ arts/midi/midisynctest.cc | 137 -- arts/midi/midisynctest.cpp | 137 ++ arts/midi/miditest_impl.cc | 57 - arts/midi/miditest_impl.cpp | 57 + arts/midi/miditimercommon.cc | 72 - arts/midi/miditimercommon.cpp | 72 + arts/midi/rawmidiport_impl.cc | 306 ----- arts/midi/rawmidiport_impl.cpp | 306 +++++ arts/midi/systemmiditimer_impl.cc | 105 -- arts/midi/systemmiditimer_impl.cpp | 105 ++ arts/midi/timestampmath.cc | 112 -- arts/midi/timestampmath.cpp | 112 ++ arts/modules/CMakeLists.txt | 4 +- arts/modules/Makefile.am | 6 +- arts/modules/README.environments | 2 +- arts/modules/README.modules | 4 +- arts/modules/artsmodules.idl | 2 +- arts/modules/common/CMakeLists.txt | 10 +- arts/modules/common/Makefile.am | 14 +- arts/modules/common/artsmodulescommon.idl | 2 +- arts/modules/common/effectrackslot_impl.cc | 114 -- arts/modules/common/effectrackslot_impl.cpp | 114 ++ arts/modules/common/env_container_impl.cc | 136 -- arts/modules/common/env_container_impl.cpp | 136 ++ arts/modules/common/env_context_impl.cc | 72 - arts/modules/common/env_context_impl.cpp | 72 + arts/modules/common/env_effectrackitem_impl.cc | 399 ------ arts/modules/common/env_effectrackitem_impl.cpp | 399 ++++++ arts/modules/common/env_instrumentitem_impl.cc | 113 -- arts/modules/common/env_instrumentitem_impl.cpp | 113 ++ arts/modules/common/env_item_impl.cc | 48 - arts/modules/common/env_item_impl.cpp | 48 + arts/modules/common/env_mixeritem_impl.cc | 367 ----- arts/modules/common/env_mixeritem_impl.cpp | 367 +++++ arts/modules/effects/CMakeLists.txt | 20 +- arts/modules/effects/Makefile.am | 22 +- arts/modules/effects/artsmoduleseffects.idl | 2 +- arts/modules/effects/effect_wavecapture_impl.cc | 61 - arts/modules/effects/effect_wavecapture_impl.cpp | 61 + arts/modules/effects/fivebandmonocomplexeq_impl.cc | 208 --- .../modules/effects/fivebandmonocomplexeq_impl.cpp | 208 +++ arts/modules/effects/freeverb/allpass.cpp | 2 +- arts/modules/effects/freeverb/allpass.h | 48 + arts/modules/effects/freeverb/allpass.hpp | 48 - arts/modules/effects/freeverb/comb.cpp | 2 +- arts/modules/effects/freeverb/comb.h | 55 + arts/modules/effects/freeverb/comb.hpp | 55 - arts/modules/effects/freeverb/revmodel.cpp | 2 +- arts/modules/effects/freeverb/revmodel.h | 87 ++ arts/modules/effects/freeverb/revmodel.hpp | 87 -- arts/modules/effects/freeverbguifactory_impl.cc | 107 -- arts/modules/effects/freeverbguifactory_impl.cpp | 107 ++ arts/modules/effects/monostereoconversion_impl.cc | 160 --- arts/modules/effects/monostereoconversion_impl.cpp | 160 +++ .../effects/stereocompressorguifactory_impl.cc | 111 -- .../effects/stereocompressorguifactory_impl.cpp | 111 ++ arts/modules/effects/synth_freeverb_impl.cc | 84 -- arts/modules/effects/synth_freeverb_impl.cpp | 84 ++ .../effects/synth_stereo_compressor_impl.cc | 132 -- .../effects/synth_stereo_compressor_impl.cpp | 132 ++ .../effects/synth_stereo_fir_equalizer_impl.cc | 221 --- .../effects/synth_stereo_fir_equalizer_impl.cpp | 221 +++ .../effects/synth_stereo_pitch_shift_fft_impl.cc | 63 - .../effects/synth_stereo_pitch_shift_fft_impl.cpp | 63 + .../effects/synth_stereo_pitch_shift_impl.cc | 51 - .../effects/synth_stereo_pitch_shift_impl.cpp | 51 + arts/modules/effects/synth_voice_removal_impl.cc | 106 -- arts/modules/effects/synth_voice_removal_impl.cpp | 106 ++ .../modules/effects/voiceremovalguifactory_impl.cc | 74 - .../effects/voiceremovalguifactory_impl.cpp | 74 + arts/modules/mixers/CMakeLists.txt | 10 +- arts/modules/mixers/Makefile.am | 12 +- arts/modules/mixers/artsmodulesmixers.idl | 2 +- .../mixers/littlestereomixerchannel_impl.cc | 134 -- .../mixers/littlestereomixerchannel_impl.cpp | 134 ++ arts/modules/mixers/monosimplemixerchannel_impl.cc | 106 -- .../modules/mixers/monosimplemixerchannel_impl.cpp | 106 ++ .../monosimplemixerchannelguifactory_impl.cc | 94 -- .../monosimplemixerchannelguifactory_impl.cpp | 94 ++ arts/modules/mixers/simplemixerchannel_impl.cc | 132 -- arts/modules/mixers/simplemixerchannel_impl.cpp | 132 ++ .../mixers/simplemixerchannelguifactory_impl.cc | 82 -- .../mixers/simplemixerchannelguifactory_impl.cpp | 82 ++ arts/modules/synth/CMakeLists.txt | 30 +- arts/modules/synth/Makefile.am | 26 +- arts/modules/synth/artsmodulessynth.idl | 2 +- arts/modules/synth/objectcache_impl.cc | 73 - arts/modules/synth/objectcache_impl.cpp | 73 + arts/modules/synth/synth_atan_saturate_impl.cc | 54 - arts/modules/synth/synth_atan_saturate_impl.cpp | 54 + arts/modules/synth/synth_autopanner_impl.cc | 50 - arts/modules/synth/synth_autopanner_impl.cpp | 50 + arts/modules/synth/synth_brickwall_limiter_impl.cc | 51 - .../modules/synth/synth_brickwall_limiter_impl.cpp | 51 + arts/modules/synth/synth_capture_wav_impl.cc | 169 --- arts/modules/synth/synth_capture_wav_impl.cpp | 169 +++ arts/modules/synth/synth_cdelay_impl.cc | 122 -- arts/modules/synth/synth_cdelay_impl.cpp | 122 ++ arts/modules/synth/synth_compressor_impl.cc | 139 -- arts/modules/synth/synth_compressor_impl.cpp | 139 ++ arts/modules/synth/synth_data_impl.cc | 50 - arts/modules/synth/synth_data_impl.cpp | 50 + arts/modules/synth/synth_debug_impl.cc | 60 - arts/modules/synth/synth_debug_impl.cpp | 60 + arts/modules/synth/synth_delay_impl.cc | 138 -- arts/modules/synth/synth_delay_impl.cpp | 138 ++ arts/modules/synth/synth_div_impl.cc | 45 - arts/modules/synth/synth_div_impl.cpp | 45 + arts/modules/synth/synth_envelope_adsr_impl.cc | 121 -- arts/modules/synth/synth_envelope_adsr_impl.cpp | 121 ++ arts/modules/synth/synth_fm_source_impl.cc | 61 - arts/modules/synth/synth_fm_source_impl.cpp | 61 + arts/modules/synth/synth_fx_cflanger_impl.cc | 96 -- arts/modules/synth/synth_fx_cflanger_impl.cpp | 96 ++ arts/modules/synth/synth_midi_debug_impl.cc | 88 -- arts/modules/synth/synth_midi_debug_impl.cpp | 88 ++ arts/modules/synth/synth_midi_test_impl.cc | 692 ---------- arts/modules/synth/synth_midi_test_impl.cpp | 692 ++++++++++ arts/modules/synth/synth_moog_vcf_impl.cc | 91 -- arts/modules/synth/synth_moog_vcf_impl.cpp | 91 ++ arts/modules/synth/synth_nil_impl.cc | 36 - arts/modules/synth/synth_nil_impl.cpp | 36 + arts/modules/synth/synth_noise_impl.cc | 63 - arts/modules/synth/synth_noise_impl.cpp | 63 + arts/modules/synth/synth_osc_impl.cc | 253 ---- arts/modules/synth/synth_osc_impl.cpp | 253 ++++ arts/modules/synth/synth_pitch_shift_fft_impl.cc | 431 ------ arts/modules/synth/synth_pitch_shift_fft_impl.cpp | 431 ++++++ arts/modules/synth/synth_pitch_shift_impl.cc | 196 --- arts/modules/synth/synth_pitch_shift_impl.cpp | 196 +++ arts/modules/synth/synth_play_pat_impl.cc | 529 -------- arts/modules/synth/synth_play_pat_impl.cpp | 529 ++++++++ arts/modules/synth/synth_pscale_impl.cc | 53 - arts/modules/synth/synth_pscale_impl.cpp | 53 + arts/modules/synth/synth_rc_impl.cc | 110 -- arts/modules/synth/synth_rc_impl.cpp | 110 ++ arts/modules/synth/synth_sequence_freq_impl.cc | 130 -- arts/modules/synth/synth_sequence_freq_impl.cpp | 130 ++ arts/modules/synth/synth_sequence_impl.cc | 131 -- arts/modules/synth/synth_sequence_impl.cpp | 131 ++ arts/modules/synth/synth_shelve_cutoff_impl.cc | 71 - arts/modules/synth/synth_shelve_cutoff_impl.cpp | 71 + arts/modules/synth/synth_std_equalizer_impl.cc | 207 --- arts/modules/synth/synth_std_equalizer_impl.cpp | 207 +++ arts/modules/synth/synth_tremolo_impl.cc | 51 - arts/modules/synth/synth_tremolo_impl.cpp | 51 + arts/modules/synth/synth_wave_pulse_impl.cc | 52 - arts/modules/synth/synth_wave_pulse_impl.cpp | 52 + arts/modules/synth/synth_wave_softsaw_impl.cc | 50 - arts/modules/synth/synth_wave_softsaw_impl.cpp | 50 + arts/modules/synth/synth_wave_square_impl.cc | 39 - arts/modules/synth/synth_wave_square_impl.cpp | 39 + arts/modules/synth/synth_wave_tri_impl.cc | 39 - arts/modules/synth/synth_wave_tri_impl.cpp | 39 + arts/modules/synth/synth_xfade_impl.cc | 45 - arts/modules/synth/synth_xfade_impl.cpp | 45 + arts/runtime/CMakeLists.txt | 8 +- arts/runtime/Makefile.am | 10 +- arts/runtime/artsbuilder.idl | 2 +- arts/runtime/artsbuilderloader_impl.cc | 285 ---- arts/runtime/artsbuilderloader_impl.cpp | 285 ++++ arts/runtime/compatibility.cc | 56 - arts/runtime/compatibility.cpp | 56 + arts/runtime/localfactory_impl.cc | 15 - arts/runtime/localfactory_impl.cpp | 15 + arts/runtime/moduleinfo.cc | 106 -- arts/runtime/moduleinfo.cpp | 106 ++ arts/runtime/sequenceutils.cc | 188 --- arts/runtime/sequenceutils.cpp | 188 +++ arts/runtime/structurebuilder_impl.cc | 347 ----- arts/runtime/structurebuilder_impl.cpp | 347 +++++ arts/runtime/structures_impl.cc | 1421 -------------------- arts/runtime/structures_impl.cpp | 1421 ++++++++++++++++++++ audiofile_artsplugin/CMakeLists.txt | 4 +- audiofile_artsplugin/Makefile.am | 6 +- doc/artsbuilder/faq.docbook | 4 +- doc/artsbuilder/helping.docbook | 2 +- doc/artsbuilder/mcop.docbook | 4 +- mpeglib/lib/splay/huffmantable.cpp | 2 +- mpeglib/lib/splay/mpeglayer1.cpp | 2 +- mpeglib/lib/splay/mpeglayer2.cpp | 2 +- mpeglib/lib/splay/mpeglayer3.cpp | 2 +- mpeglib/lib/splay/mpegtable.cpp | 2 +- mpeglib/lib/splay/mpegtoraw.cpp | 2 +- mpeglib_artsplug/CMakeLists.txt | 10 +- mpeglib_artsplug/Makefile.am | 14 +- mpeglib_artsplug/doemacs | 2 +- mpg123_artsplugin/Makefile.am | 4 +- noatun/Makefile.am | 2 +- noatun/library/noatunarts/CMakeLists.txt | 4 +- noatun/library/noatunarts/Equalizer_impl.cpp | 2 +- noatun/library/noatunarts/Makefile.am | 6 +- .../library/noatunarts/StereoEffectStack_impl.cpp | 2 +- noatun/modules/artseffects/CMakeLists.txt | 4 +- noatun/modules/artseffects/Makefile.am | 8 +- noatun/modules/artseffects/extrastereo_impl.cc | 153 --- noatun/modules/artseffects/extrastereo_impl.cpp | 153 +++ noatun/modules/artseffects/extrastereogui_impl.cc | 28 - noatun/modules/artseffects/extrastereogui_impl.cpp | 28 + noatun/modules/winskin/vis/CMakeLists.txt | 4 +- noatun/modules/winskin/vis/Makefile.am | 8 +- oggvorbis_artsplugin/CMakeLists.txt | 4 +- oggvorbis_artsplugin/Makefile.am | 4 +- tdemid/README | 6 +- tdemid/slman.cpp | 2 +- tdemid/songlist.cpp | 2 +- xine_artsplugin/CMakeLists.txt | 4 +- xine_artsplugin/Makefile.am | 4 +- 240 files changed, 13485 insertions(+), 13485 deletions(-) delete mode 100644 arts/gui/common/genericguifactory_impl.cc create mode 100644 arts/gui/common/genericguifactory_impl.cpp delete mode 100644 arts/midi/alsamidigateway_impl.cc create mode 100644 arts/midi/alsamidigateway_impl.cpp delete mode 100644 arts/midi/alsamidiport_impl.cc create mode 100644 arts/midi/alsamidiport_impl.cpp delete mode 100644 arts/midi/audiomiditimer_impl.cc create mode 100644 arts/midi/audiomiditimer_impl.cpp delete mode 100644 arts/midi/audiosync_impl.cc create mode 100644 arts/midi/audiosync_impl.cpp delete mode 100644 arts/midi/audiotimer.cc create mode 100644 arts/midi/audiotimer.cpp delete mode 100644 arts/midi/midiclient_impl.cc create mode 100644 arts/midi/midiclient_impl.cpp delete mode 100644 arts/midi/midimanager_impl.cc create mode 100644 arts/midi/midimanager_impl.cpp delete mode 100644 arts/midi/midimanagerport_impl.cc create mode 100644 arts/midi/midimanagerport_impl.cpp delete mode 100644 arts/midi/midisend.cc create mode 100644 arts/midi/midisend.cpp delete mode 100644 arts/midi/midisyncgroup_impl.cc create mode 100644 arts/midi/midisyncgroup_impl.cpp delete mode 100644 arts/midi/midisynctest.cc create mode 100644 arts/midi/midisynctest.cpp delete mode 100644 arts/midi/miditest_impl.cc create mode 100644 arts/midi/miditest_impl.cpp delete mode 100644 arts/midi/miditimercommon.cc create mode 100644 arts/midi/miditimercommon.cpp delete mode 100644 arts/midi/rawmidiport_impl.cc create mode 100644 arts/midi/rawmidiport_impl.cpp delete mode 100644 arts/midi/systemmiditimer_impl.cc create mode 100644 arts/midi/systemmiditimer_impl.cpp delete mode 100644 arts/midi/timestampmath.cc create mode 100644 arts/midi/timestampmath.cpp delete mode 100644 arts/modules/common/effectrackslot_impl.cc create mode 100644 arts/modules/common/effectrackslot_impl.cpp delete mode 100644 arts/modules/common/env_container_impl.cc create mode 100644 arts/modules/common/env_container_impl.cpp delete mode 100644 arts/modules/common/env_context_impl.cc create mode 100644 arts/modules/common/env_context_impl.cpp delete mode 100644 arts/modules/common/env_effectrackitem_impl.cc create mode 100644 arts/modules/common/env_effectrackitem_impl.cpp delete mode 100644 arts/modules/common/env_instrumentitem_impl.cc create mode 100644 arts/modules/common/env_instrumentitem_impl.cpp delete mode 100644 arts/modules/common/env_item_impl.cc create mode 100644 arts/modules/common/env_item_impl.cpp delete mode 100644 arts/modules/common/env_mixeritem_impl.cc create mode 100644 arts/modules/common/env_mixeritem_impl.cpp delete mode 100644 arts/modules/effects/effect_wavecapture_impl.cc create mode 100644 arts/modules/effects/effect_wavecapture_impl.cpp delete mode 100644 arts/modules/effects/fivebandmonocomplexeq_impl.cc create mode 100644 arts/modules/effects/fivebandmonocomplexeq_impl.cpp create mode 100644 arts/modules/effects/freeverb/allpass.h delete mode 100644 arts/modules/effects/freeverb/allpass.hpp create mode 100644 arts/modules/effects/freeverb/comb.h delete mode 100644 arts/modules/effects/freeverb/comb.hpp create mode 100644 arts/modules/effects/freeverb/revmodel.h delete mode 100644 arts/modules/effects/freeverb/revmodel.hpp delete mode 100644 arts/modules/effects/freeverbguifactory_impl.cc create mode 100644 arts/modules/effects/freeverbguifactory_impl.cpp delete mode 100644 arts/modules/effects/monostereoconversion_impl.cc create mode 100644 arts/modules/effects/monostereoconversion_impl.cpp delete mode 100644 arts/modules/effects/stereocompressorguifactory_impl.cc create mode 100644 arts/modules/effects/stereocompressorguifactory_impl.cpp delete mode 100644 arts/modules/effects/synth_freeverb_impl.cc create mode 100644 arts/modules/effects/synth_freeverb_impl.cpp delete mode 100644 arts/modules/effects/synth_stereo_compressor_impl.cc create mode 100644 arts/modules/effects/synth_stereo_compressor_impl.cpp delete mode 100644 arts/modules/effects/synth_stereo_fir_equalizer_impl.cc create mode 100644 arts/modules/effects/synth_stereo_fir_equalizer_impl.cpp delete mode 100644 arts/modules/effects/synth_stereo_pitch_shift_fft_impl.cc create mode 100644 arts/modules/effects/synth_stereo_pitch_shift_fft_impl.cpp delete mode 100644 arts/modules/effects/synth_stereo_pitch_shift_impl.cc create mode 100644 arts/modules/effects/synth_stereo_pitch_shift_impl.cpp delete mode 100644 arts/modules/effects/synth_voice_removal_impl.cc create mode 100644 arts/modules/effects/synth_voice_removal_impl.cpp delete mode 100644 arts/modules/effects/voiceremovalguifactory_impl.cc create mode 100644 arts/modules/effects/voiceremovalguifactory_impl.cpp delete mode 100644 arts/modules/mixers/littlestereomixerchannel_impl.cc create mode 100644 arts/modules/mixers/littlestereomixerchannel_impl.cpp delete mode 100644 arts/modules/mixers/monosimplemixerchannel_impl.cc create mode 100644 arts/modules/mixers/monosimplemixerchannel_impl.cpp delete mode 100644 arts/modules/mixers/monosimplemixerchannelguifactory_impl.cc create mode 100644 arts/modules/mixers/monosimplemixerchannelguifactory_impl.cpp delete mode 100644 arts/modules/mixers/simplemixerchannel_impl.cc create mode 100644 arts/modules/mixers/simplemixerchannel_impl.cpp delete mode 100644 arts/modules/mixers/simplemixerchannelguifactory_impl.cc create mode 100644 arts/modules/mixers/simplemixerchannelguifactory_impl.cpp delete mode 100644 arts/modules/synth/objectcache_impl.cc create mode 100644 arts/modules/synth/objectcache_impl.cpp delete mode 100644 arts/modules/synth/synth_atan_saturate_impl.cc create mode 100644 arts/modules/synth/synth_atan_saturate_impl.cpp delete mode 100644 arts/modules/synth/synth_autopanner_impl.cc create mode 100644 arts/modules/synth/synth_autopanner_impl.cpp delete mode 100644 arts/modules/synth/synth_brickwall_limiter_impl.cc create mode 100644 arts/modules/synth/synth_brickwall_limiter_impl.cpp delete mode 100644 arts/modules/synth/synth_capture_wav_impl.cc create mode 100644 arts/modules/synth/synth_capture_wav_impl.cpp delete mode 100644 arts/modules/synth/synth_cdelay_impl.cc create mode 100644 arts/modules/synth/synth_cdelay_impl.cpp delete mode 100644 arts/modules/synth/synth_compressor_impl.cc create mode 100644 arts/modules/synth/synth_compressor_impl.cpp delete mode 100644 arts/modules/synth/synth_data_impl.cc create mode 100644 arts/modules/synth/synth_data_impl.cpp delete mode 100644 arts/modules/synth/synth_debug_impl.cc create mode 100644 arts/modules/synth/synth_debug_impl.cpp delete mode 100644 arts/modules/synth/synth_delay_impl.cc create mode 100644 arts/modules/synth/synth_delay_impl.cpp delete mode 100644 arts/modules/synth/synth_div_impl.cc create mode 100644 arts/modules/synth/synth_div_impl.cpp delete mode 100644 arts/modules/synth/synth_envelope_adsr_impl.cc create mode 100644 arts/modules/synth/synth_envelope_adsr_impl.cpp delete mode 100644 arts/modules/synth/synth_fm_source_impl.cc create mode 100644 arts/modules/synth/synth_fm_source_impl.cpp delete mode 100644 arts/modules/synth/synth_fx_cflanger_impl.cc create mode 100644 arts/modules/synth/synth_fx_cflanger_impl.cpp delete mode 100644 arts/modules/synth/synth_midi_debug_impl.cc create mode 100644 arts/modules/synth/synth_midi_debug_impl.cpp delete mode 100644 arts/modules/synth/synth_midi_test_impl.cc create mode 100644 arts/modules/synth/synth_midi_test_impl.cpp delete mode 100644 arts/modules/synth/synth_moog_vcf_impl.cc create mode 100644 arts/modules/synth/synth_moog_vcf_impl.cpp delete mode 100644 arts/modules/synth/synth_nil_impl.cc create mode 100644 arts/modules/synth/synth_nil_impl.cpp delete mode 100644 arts/modules/synth/synth_noise_impl.cc create mode 100644 arts/modules/synth/synth_noise_impl.cpp delete mode 100644 arts/modules/synth/synth_osc_impl.cc create mode 100644 arts/modules/synth/synth_osc_impl.cpp delete mode 100644 arts/modules/synth/synth_pitch_shift_fft_impl.cc create mode 100644 arts/modules/synth/synth_pitch_shift_fft_impl.cpp delete mode 100644 arts/modules/synth/synth_pitch_shift_impl.cc create mode 100644 arts/modules/synth/synth_pitch_shift_impl.cpp delete mode 100644 arts/modules/synth/synth_play_pat_impl.cc create mode 100644 arts/modules/synth/synth_play_pat_impl.cpp delete mode 100644 arts/modules/synth/synth_pscale_impl.cc create mode 100644 arts/modules/synth/synth_pscale_impl.cpp delete mode 100644 arts/modules/synth/synth_rc_impl.cc create mode 100644 arts/modules/synth/synth_rc_impl.cpp delete mode 100644 arts/modules/synth/synth_sequence_freq_impl.cc create mode 100644 arts/modules/synth/synth_sequence_freq_impl.cpp delete mode 100644 arts/modules/synth/synth_sequence_impl.cc create mode 100644 arts/modules/synth/synth_sequence_impl.cpp delete mode 100644 arts/modules/synth/synth_shelve_cutoff_impl.cc create mode 100644 arts/modules/synth/synth_shelve_cutoff_impl.cpp delete mode 100644 arts/modules/synth/synth_std_equalizer_impl.cc create mode 100644 arts/modules/synth/synth_std_equalizer_impl.cpp delete mode 100644 arts/modules/synth/synth_tremolo_impl.cc create mode 100644 arts/modules/synth/synth_tremolo_impl.cpp delete mode 100644 arts/modules/synth/synth_wave_pulse_impl.cc create mode 100644 arts/modules/synth/synth_wave_pulse_impl.cpp delete mode 100644 arts/modules/synth/synth_wave_softsaw_impl.cc create mode 100644 arts/modules/synth/synth_wave_softsaw_impl.cpp delete mode 100644 arts/modules/synth/synth_wave_square_impl.cc create mode 100644 arts/modules/synth/synth_wave_square_impl.cpp delete mode 100644 arts/modules/synth/synth_wave_tri_impl.cc create mode 100644 arts/modules/synth/synth_wave_tri_impl.cpp delete mode 100644 arts/modules/synth/synth_xfade_impl.cc create mode 100644 arts/modules/synth/synth_xfade_impl.cpp delete mode 100644 arts/runtime/artsbuilderloader_impl.cc create mode 100644 arts/runtime/artsbuilderloader_impl.cpp delete mode 100644 arts/runtime/compatibility.cc create mode 100644 arts/runtime/compatibility.cpp delete mode 100644 arts/runtime/localfactory_impl.cc create mode 100644 arts/runtime/localfactory_impl.cpp delete mode 100644 arts/runtime/moduleinfo.cc create mode 100644 arts/runtime/moduleinfo.cpp delete mode 100644 arts/runtime/sequenceutils.cc create mode 100644 arts/runtime/sequenceutils.cpp delete mode 100644 arts/runtime/structurebuilder_impl.cc create mode 100644 arts/runtime/structurebuilder_impl.cpp delete mode 100644 arts/runtime/structures_impl.cc create mode 100644 arts/runtime/structures_impl.cpp delete mode 100644 noatun/modules/artseffects/extrastereo_impl.cc create mode 100644 noatun/modules/artseffects/extrastereo_impl.cpp delete mode 100644 noatun/modules/artseffects/extrastereogui_impl.cc create mode 100644 noatun/modules/artseffects/extrastereogui_impl.cpp diff --git a/akode_artsplugin/CMakeLists.txt b/akode_artsplugin/CMakeLists.txt index 6ff72d4d..726c074f 100644 --- a/akode_artsplugin/CMakeLists.txt +++ b/akode_artsplugin/CMakeLists.txt @@ -31,7 +31,7 @@ link_directories( tde_add_library( arts_akode SHARED AUTOMOC SOURCES - akodearts.cc akodePlayObject_impl.cpp + akodearts.cpp akodePlayObject_impl.cpp akodeMPCPlayObject_impl.cpp akodeMPEGPlayObject_impl.cpp akodeFFMPEGPlayObject_impl.cpp akodeXiphPlayObject_impl.cpp akodeVorbisStreamPlayObject_impl.cpp akodeSpeexStreamPlayObject_impl.cpp @@ -43,7 +43,7 @@ tde_add_library( arts_akode SHARED AUTOMOC add_custom_command( OUTPUT - akodearts.cc akodearts.h + akodearts.cpp akodearts.h akodearts.mcoptype akodearts.mcopclass COMMAND ${ARTS_MCOPIDL_EXECUTABLE} -t -I${ARTS_INCLUDEDIR} ${CMAKE_CURRENT_SOURCE_DIR}/akodearts.idl diff --git a/akode_artsplugin/Makefile.am b/akode_artsplugin/Makefile.am index 230a6a01..73d256f1 100644 --- a/akode_artsplugin/Makefile.am +++ b/akode_artsplugin/Makefile.am @@ -4,7 +4,7 @@ noinst_HEADERS = akodePlayObject_impl.h lib_LTLIBRARIES = libarts_akode.la -libarts_akode_la_SOURCES = akodearts.cc akodePlayObject_impl.cpp \ +libarts_akode_la_SOURCES = akodearts.cpp akodePlayObject_impl.cpp \ akodeMPCPlayObject_impl.cpp akodeMPEGPlayObject_impl.cpp \ akodeFFMPEGPlayObject_impl.cpp akodeXiphPlayObject_impl.cpp \ akodeVorbisStreamPlayObject_impl.cpp akodeSpeexStreamPlayObject_impl.cpp @@ -16,7 +16,7 @@ libarts_akode_la_COMPILE_FIRST = akodearts.h $(srcdir)/akodePlayObject_impl.cpp: akodearts.h akodearts.mcopclass: akodearts.h akodearts.mcoptype: akodearts.h -akodearts.cc akodearts.h: $(srcdir)/akodearts.idl +akodearts.cpp akodearts.h: $(srcdir)/akodearts.idl $(MCOPIDL) -t $(INCLUDES) $(srcdir)/akodearts.idl mcoptypedir = $(libdir)/mcop @@ -42,5 +42,5 @@ mcopclassdir = $(libdir)/mcop mcopclass_DATA = akodePlayObject.mcopclass \ $(AKODE_MPC) $(AKODE_MPEG) $(AKODE_XIPH) $(AKODE_FFMPEG) -CLEANFILES=akodearts.h akodearts.cc akodearts.mcopclass akodearts.mcoptype +CLEANFILES=akodearts.h akodearts.cpp akodearts.mcopclass akodearts.mcoptype diff --git a/arts/Makefile.am b/arts/Makefile.am index f98d9c01..43f056d7 100644 --- a/arts/Makefile.am +++ b/arts/Makefile.am @@ -6,4 +6,4 @@ SUBDIRS = runtime midi gui modules examples $(ARTS_BUILD_KDE) DIST_SUBDIRS = runtime midi gui modules examples builder tools messages: - $(XGETTEXT) modules/*/*.cpp modules/*/*.cc gui/*/*.cpp gui/*/*.cc -o $(podir)/artsmodules.pot + $(XGETTEXT) modules/*/*.cpp gui/*/*.cpp -o $(podir)/artsmodules.pot diff --git a/arts/gui/common/CMakeLists.txt b/arts/gui/common/CMakeLists.txt index 6fa63e44..030e3c65 100644 --- a/arts/gui/common/CMakeLists.txt +++ b/arts/gui/common/CMakeLists.txt @@ -27,14 +27,14 @@ link_directories( ##### artsgui (library) ######################### tde_add_library( artsgui_idl SHARED - SOURCES artsgui.cc + SOURCES artsgui.cpp VERSION 0.0.0 LINK mcop ${DL_LIBRARIES} ${ARTS_LIBRARIES} DESTINATION ${LIB_INSTALL_DIR} ) tde_add_library( artsgui SHARED - SOURCES genericguifactory_impl.cc + SOURCES genericguifactory_impl.cpp VERSION 0.0.0 LINK artsgui_idl-shared DESTINATION ${LIB_INSTALL_DIR} @@ -42,7 +42,7 @@ tde_add_library( artsgui SHARED add_custom_command( OUTPUT - artsgui.cc artsgui.h + artsgui.cpp artsgui.h artsgui.mcoptype artsgui.mcopclass COMMAND ${ARTS_MCOPIDL_EXECUTABLE} -t -I${ARTS_INCLUDEDIR} ${CMAKE_CURRENT_SOURCE_DIR}/artsgui.idl diff --git a/arts/gui/common/Makefile.am b/arts/gui/common/Makefile.am index 9d82449f..3368a235 100644 --- a/arts/gui/common/Makefile.am +++ b/arts/gui/common/Makefile.am @@ -2,23 +2,23 @@ lib_LTLIBRARIES = libartsgui_idl.la libartsgui.la INCLUDES= -I$(arts_includes) -I$(top_builddir)/arts/runtime $(all_includes) -libartsgui_idl_la_SOURCES = artsgui.cc +libartsgui_idl_la_SOURCES = artsgui.cpp libartsgui_idl_la_LIBADD = -lmcop $(LIBDL) libartsgui_idl_la_LDFLAGS = $(all_libraries) -L$(arts_libraries) \ -no-undefined -libartsgui_la_SOURCES = genericguifactory_impl.cc +libartsgui_la_SOURCES = genericguifactory_impl.cpp libartsgui_la_LIBADD = libartsgui_idl.la libartsgui_la_LDFLAGS = $(all_libraries) -no-undefined libartsgui_la_COMPILE_FIRST = artsgui.h -artsgui.cc artsgui.h: $(srcdir)/artsgui.idl $(MCOPIDL) +artsgui.cpp artsgui.h: $(srcdir)/artsgui.idl $(MCOPIDL) $(MCOPIDL) -t -I$(includedir)/arts $(srcdir)/artsgui.idl artsgui.mcoptype: artsgui.h artsgui.mcopclass: artsgui.h -DISTCLEANFILES = artsgui.cc artsgui.h \ +DISTCLEANFILES = artsgui.cpp artsgui.h \ artsgui.mcoptype artsgui.mcopclass ####### install idl files diff --git a/arts/gui/common/artsgui.idl b/arts/gui/common/artsgui.idl index c7d0554e..76b6a8c5 100644 --- a/arts/gui/common/artsgui.idl +++ b/arts/gui/common/artsgui.idl @@ -23,7 +23,7 @@ */ /* - * DISCLAIMER: The interfaces in artsgui.idl (and the derived .cc/.h files) + * DISCLAIMER: The interfaces in artsgui.idl (and the derived .cpp/.h files) * DO NOT GUARANTEE BINARY COMPATIBILITY YET. * * They are intended for developers. You shouldn't expect that applications in diff --git a/arts/gui/common/genericguifactory_impl.cc b/arts/gui/common/genericguifactory_impl.cc deleted file mode 100644 index 163d7e21..00000000 --- a/arts/gui/common/genericguifactory_impl.cc +++ /dev/null @@ -1,56 +0,0 @@ - /* - - Copyright (C) 2001 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "artsgui.h" -#include "debug.h" - -using namespace Arts; -using namespace std; - -namespace Arts { - -class GenericGuiFactory_impl : public GenericGuiFactory_skel { -public: - Widget createGui(Object runningObject); -}; -REGISTER_IMPLEMENTATION(GenericGuiFactory_impl); - -} - -Widget GenericGuiFactory_impl::createGui(Object runningObject) -{ - Arts::Widget result = Arts::Widget::null(); - arts_return_val_if_fail(!runningObject.isNull(), result); - - TraderQuery query; - query.supports("Interface","Arts::GuiFactory"); - query.supports("CanCreate",runningObject._interfaceName()); - - vector *queryResults = query.query(); - if(queryResults->size()) - { - Arts::GuiFactory factory = SubClass((*queryResults)[0].interfaceName()); - result = factory.createGui(runningObject); - } - delete queryResults; - return result; -} diff --git a/arts/gui/common/genericguifactory_impl.cpp b/arts/gui/common/genericguifactory_impl.cpp new file mode 100644 index 00000000..163d7e21 --- /dev/null +++ b/arts/gui/common/genericguifactory_impl.cpp @@ -0,0 +1,56 @@ + /* + + Copyright (C) 2001 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "artsgui.h" +#include "debug.h" + +using namespace Arts; +using namespace std; + +namespace Arts { + +class GenericGuiFactory_impl : public GenericGuiFactory_skel { +public: + Widget createGui(Object runningObject); +}; +REGISTER_IMPLEMENTATION(GenericGuiFactory_impl); + +} + +Widget GenericGuiFactory_impl::createGui(Object runningObject) +{ + Arts::Widget result = Arts::Widget::null(); + arts_return_val_if_fail(!runningObject.isNull(), result); + + TraderQuery query; + query.supports("Interface","Arts::GuiFactory"); + query.supports("CanCreate",runningObject._interfaceName()); + + vector *queryResults = query.query(); + if(queryResults->size()) + { + Arts::GuiFactory factory = SubClass((*queryResults)[0].interfaceName()); + result = factory.createGui(runningObject); + } + delete queryResults; + return result; +} diff --git a/arts/midi/CMakeLists.txt b/arts/midi/CMakeLists.txt index 0b91a9fe..c8c0925d 100644 --- a/arts/midi/CMakeLists.txt +++ b/arts/midi/CMakeLists.txt @@ -29,7 +29,7 @@ link_directories( ##### artsmidi (library) ######################## tde_add_library( artsmidi_idl SHARED - SOURCES artsmidi.cc + SOURCES artsmidi.cpp VERSION 0.0.0 LINK ${ARTS_LIBRARIES} ${GLIB2_LIBRARIES} ${GTHREAD2_LIBRARIES} mcop artsflow artsflow_idl DESTINATION ${LIB_INSTALL_DIR} @@ -37,11 +37,11 @@ tde_add_library( artsmidi_idl SHARED tde_add_library( artsmidi SHARED SOURCES - midimanager_impl.cc midiclient_impl.cc - miditest_impl.cc midimanagerport_impl.cc rawmidiport_impl.cc - systemmiditimer_impl.cc audiomiditimer_impl.cc miditimercommon.cc - audiosync_impl.cc audiotimer.cc alsamidigateway_impl.cc - alsamidiport_impl.cc midisyncgroup_impl.cc timestampmath.cc + midimanager_impl.cpp midiclient_impl.cpp + miditest_impl.cpp midimanagerport_impl.cpp rawmidiport_impl.cpp + systemmiditimer_impl.cpp audiomiditimer_impl.cpp miditimercommon.cpp + audiosync_impl.cpp audiotimer.cpp alsamidigateway_impl.cpp + alsamidiport_impl.cpp midisyncgroup_impl.cpp timestampmath.cpp VERSION 0.0.0 LINK artsmidi_idl-shared @@ -50,7 +50,7 @@ tde_add_library( artsmidi SHARED add_custom_command( OUTPUT - artsmidi.cc artsmidi.h + artsmidi.cpp artsmidi.h artsmidi.mcopclass artsmidi.mcoptype COMMAND ${ARTS_MCOPIDL_EXECUTABLE} -t -I${ARTS_INCLUDEDIR} ${CMAKE_CURRENT_SOURCE_DIR}/artsmidi.idl @@ -61,13 +61,13 @@ add_custom_command( ##### midisend (executable) ##################### tde_add_executable( midisend - SOURCES midisend.cc midimsg.c + SOURCES midisend.cpp midimsg.c LINK artsmidi_idl-shared DESTINATION ${BIN_INSTALL_DIR} ) tde_add_check_executable( midisynctest - SOURCES midisynctest.cc + SOURCES midisynctest.cpp LINK artsmidi-shared soundserver_idl ) diff --git a/arts/midi/Makefile.am b/arts/midi/Makefile.am index d097dc85..679ff700 100644 --- a/arts/midi/Makefile.am +++ b/arts/midi/Makefile.am @@ -8,26 +8,26 @@ lib_LTLIBRARIES = libartsmidi_idl.la libartsmidi.la bin_PROGRAMS = midisend noinst_PROGRAMS = midisynctest -midisend_SOURCES = midisend.cc midimsg.c +midisend_SOURCES = midisend.cpp midimsg.c midisend_LDFLAGS = $(all_libraries) $(LIB_QT) $(KDE_RPATH) $(LIBPTHREAD) $(LIB_QT) -lmcop -lartsflow_idl midisend_LDADD = libartsmidi_idl.la -lartsflow_idl midisend_COMPILE_FIRST = artsmidi.h -midisynctest_SOURCES = midisynctest.cc +midisynctest_SOURCES = midisynctest.cpp midisynctest_LDFLAGS = $(all_libraries) $(LIB_QT) $(KDE_RPATH) $(LIBPTHREAD) $(LIB_QT) -lmcop -lartsflow_idl -lartsmidi_idl midisynctest_LDADD = libartsmidi.la -lsoundserver_idl -lartsflow_idl -lartsmidi_idl midisynctest_COMPILE_FIRST = artsmidi.h -libartsmidi_idl_la_SOURCES = artsmidi.cc +libartsmidi_idl_la_SOURCES = artsmidi.cpp libartsmidi_idl_la_LIBADD = -lmcop -lartsflow -lartsflow_idl libartsmidi_idl_la_LDFLAGS = $(all_libraries) -L$(arts_libraries) \ -no-undefined -lartsflow_idl -libartsmidi_la_SOURCES = midimanager_impl.cc midiclient_impl.cc \ - miditest_impl.cc midimanagerport_impl.cc rawmidiport_impl.cc \ - systemmiditimer_impl.cc audiomiditimer_impl.cc miditimercommon.cc \ - audiosync_impl.cc audiotimer.cc alsamidigateway_impl.cc \ - alsamidiport_impl.cc midisyncgroup_impl.cc timestampmath.cc +libartsmidi_la_SOURCES = midimanager_impl.cpp midiclient_impl.cpp \ + miditest_impl.cpp midimanagerport_impl.cpp rawmidiport_impl.cpp \ + systemmiditimer_impl.cpp audiomiditimer_impl.cpp miditimercommon.cpp \ + audiosync_impl.cpp audiotimer.cpp alsamidigateway_impl.cpp \ + alsamidiport_impl.cpp midisyncgroup_impl.cpp timestampmath.cpp libartsmidi_la_COMPILE_FIRST = artsmidi.h libartsmidi_la_LIBADD = libartsmidi_idl.la -lartsflow_idl -lartsflow $(ARTS_LIBASOUND) @@ -36,10 +36,10 @@ libartsmidi_la_LDFLAGS = $(all_libraries) -L$(arts_libraries) \ artsmidi.mcopclass: artsmidi.h artsmidi.mcoptype: artsmidi.h -artsmidi.cc artsmidi.h: $(srcdir)/artsmidi.idl $(MCOPIDL) +artsmidi.cpp artsmidi.h: $(srcdir)/artsmidi.idl $(MCOPIDL) $(MCOPIDL) -t -I$(arts_includes) $(srcdir)/artsmidi.idl -DISTCLEANFILES = artsmidi.cc artsmidi.h \ +DISTCLEANFILES = artsmidi.cpp artsmidi.h \ artsmidi.mcoptype artsmidi.mcopclass ####### install idl files diff --git a/arts/midi/README.midi b/arts/midi/README.midi index 69342b32..a3463fde 100644 --- a/arts/midi/README.midi +++ b/arts/midi/README.midi @@ -250,7 +250,7 @@ synchronized to those of the midi channels. --------------- An example that illustrates most things discussed in this document is -midisynctest.cc, which plays back two synchronized midi streams and samples. +midisynctest.cpp, which plays back two synchronized midi streams and samples. Note that you might want to change the source code, as it hardcodes the location of the .wav file. diff --git a/arts/midi/alsamidigateway_impl.cc b/arts/midi/alsamidigateway_impl.cc deleted file mode 100644 index 4b31042e..00000000 --- a/arts/midi/alsamidigateway_impl.cc +++ /dev/null @@ -1,243 +0,0 @@ - /* - - Copyright (C) 2001-2002 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "artsmidi.h" - -#ifdef HAVE_CONFIG_H -#include -#endif - -/** - * compile real version if we have ALSA support, dummy version otherwise - */ -#if defined(HAVE_ARTS_LIBASOUND2) || defined(HAVE_ARTS_LIBASOUND) - -#ifdef HAVE_ALSA_ASOUNDLIB_H -#include -#elif defined(HAVE_SYS_ASOUNDLIB_H) -#include -#endif - -#include "alsamidiport_impl.h" -#include -#include - -using namespace Arts; -using namespace std; - -class AlsaMidiGateway_impl : virtual public AlsaMidiGateway_skel { -protected: - snd_seq_t *seq; - - struct PortEntry { - int alsaClient, alsaPort; - bool keep; - - AlsaMidiPort port; - MidiClient client; - }; - list ports; - -#ifdef HAVE_ARTS_LIBASOUND2 -/* ALSA-0.9 specific code */ - int alsaOpen() { - return snd_seq_open(&seq, "hw", SND_SEQ_OPEN_DUPLEX, 0); - } - bool alsaScan(MidiManager midiManager) { - snd_seq_client_info_t *cinfo; - snd_seq_port_info_t *pinfo; - - snd_seq_client_info_alloca(&cinfo); - snd_seq_client_info_set_client(cinfo, -1); - - while (snd_seq_query_next_client(seq, cinfo) >= 0) { - int client = snd_seq_client_info_get_client(cinfo); - - snd_seq_port_info_alloca(&pinfo); - snd_seq_port_info_set_client(pinfo, client); - - snd_seq_port_info_set_port(pinfo, -1); - while (snd_seq_query_next_port(seq, pinfo) >= 0) { - unsigned int cap; - - cap = (SND_SEQ_PORT_CAP_SUBS_WRITE|SND_SEQ_PORT_CAP_WRITE); - if ((snd_seq_port_info_get_capability(pinfo) & cap) == cap) { - string name = snd_seq_port_info_get_name(pinfo); - int client = snd_seq_port_info_get_client(pinfo); - int port = snd_seq_port_info_get_port(pinfo); - - createPort(midiManager, name, client, port); - } - } - } - - return true; - } -#else -/* ALSA-0.5 specific code */ - int alsaOpen() { - return snd_seq_open(&seq, SND_SEQ_OPEN); - } - - bool alsaScan(MidiManager midiManager) { - snd_seq_system_info_t sysinfo; - - int err = snd_seq_system_info(seq, &sysinfo); - if (err < 0) - { - arts_warning("snd_seq_systeminfo failed: %s", snd_strerror(err)); - return false; - } - - for(int client = 0; client < sysinfo.clients; client++) - { - snd_seq_client_info_t cinfo; - if (snd_seq_get_any_client_info(seq, client, &cinfo) == 0) - { - for(int port = 0; port < sysinfo.ports; port++) - { - snd_seq_port_info_t pinfo; - if(snd_seq_get_any_port_info(seq, client, port, &pinfo) == 0) - { - unsigned int cap; - cap = (SND_SEQ_PORT_CAP_SUBS_WRITE|SND_SEQ_PORT_CAP_WRITE); - - if ((pinfo.capability & cap) == cap) - createPort(midiManager, pinfo.name, client, port); - } - } - } - } - - return true; - } -#endif - -public: - AlsaMidiGateway_impl() : seq(0) - { - } - - ~AlsaMidiGateway_impl() - { - if(seq) - snd_seq_close(seq); - } - - void createPort(MidiManager midiManager, string name, int client, int port) - { - if(name != "aRts") - { - char nr[1024]; - - sprintf(nr, " (%3d:%-3d)", client, port); - name += nr; - - list::iterator pi = ports.begin(); - while(pi != ports.end() && (pi->alsaClient != client || pi->alsaPort != port)) - pi++; - - if(pi != ports.end()) /* we already have this port */ - pi->keep = true; - else /* we need to create it */ - { - PortEntry pe; - pe.port = AlsaMidiPort::_from_base( - new AlsaMidiPort_impl(seq, client, port)); - - if(pe.port.open()) - { - pe.client = midiManager.addClient(mcdRecord, - mctDestination, - name, name); - pe.client.addInputPort(pe.port); - pe.alsaClient = client; - pe.alsaPort = port; - pe.keep = true; - - ports.push_back(pe); - } - } - } - } - - bool rescan() - { - MidiManager midiManager = DynamicCast(Reference("global:Arts_MidiManager")); - if(midiManager.isNull()) - { - arts_warning("AlsaMidiGateway: can't find MidiManager"); - return false; - } - - if(!seq) - { - int err = alsaOpen(); - if (err < 0) - { - arts_warning("AlsaMidiGateway: could not open sequencer %s", - snd_strerror(err)); - seq = 0; - return false; - } - } - - list::iterator pi; - for(pi = ports.begin(); pi != ports.end(); pi++) - pi->keep = false; - - if(!alsaScan(midiManager)) - return false; - - /* erase those ports that are no longer needed */ - pi = ports.begin(); - while(pi != ports.end()) - { - if(!pi->keep) - pi = ports.erase(pi); - else - pi++; - } - - return true; - } -}; - -#else - -using namespace Arts; -using namespace std; - -class AlsaMidiGateway_impl : virtual public AlsaMidiGateway_skel { -public: - bool rescan() - { - /* dummy version: no ALSA support compiled in */ - return false; - } -}; - -#endif - -namespace Arts { - REGISTER_IMPLEMENTATION(AlsaMidiGateway_impl); -} diff --git a/arts/midi/alsamidigateway_impl.cpp b/arts/midi/alsamidigateway_impl.cpp new file mode 100644 index 00000000..4b31042e --- /dev/null +++ b/arts/midi/alsamidigateway_impl.cpp @@ -0,0 +1,243 @@ + /* + + Copyright (C) 2001-2002 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "artsmidi.h" + +#ifdef HAVE_CONFIG_H +#include +#endif + +/** + * compile real version if we have ALSA support, dummy version otherwise + */ +#if defined(HAVE_ARTS_LIBASOUND2) || defined(HAVE_ARTS_LIBASOUND) + +#ifdef HAVE_ALSA_ASOUNDLIB_H +#include +#elif defined(HAVE_SYS_ASOUNDLIB_H) +#include +#endif + +#include "alsamidiport_impl.h" +#include +#include + +using namespace Arts; +using namespace std; + +class AlsaMidiGateway_impl : virtual public AlsaMidiGateway_skel { +protected: + snd_seq_t *seq; + + struct PortEntry { + int alsaClient, alsaPort; + bool keep; + + AlsaMidiPort port; + MidiClient client; + }; + list ports; + +#ifdef HAVE_ARTS_LIBASOUND2 +/* ALSA-0.9 specific code */ + int alsaOpen() { + return snd_seq_open(&seq, "hw", SND_SEQ_OPEN_DUPLEX, 0); + } + bool alsaScan(MidiManager midiManager) { + snd_seq_client_info_t *cinfo; + snd_seq_port_info_t *pinfo; + + snd_seq_client_info_alloca(&cinfo); + snd_seq_client_info_set_client(cinfo, -1); + + while (snd_seq_query_next_client(seq, cinfo) >= 0) { + int client = snd_seq_client_info_get_client(cinfo); + + snd_seq_port_info_alloca(&pinfo); + snd_seq_port_info_set_client(pinfo, client); + + snd_seq_port_info_set_port(pinfo, -1); + while (snd_seq_query_next_port(seq, pinfo) >= 0) { + unsigned int cap; + + cap = (SND_SEQ_PORT_CAP_SUBS_WRITE|SND_SEQ_PORT_CAP_WRITE); + if ((snd_seq_port_info_get_capability(pinfo) & cap) == cap) { + string name = snd_seq_port_info_get_name(pinfo); + int client = snd_seq_port_info_get_client(pinfo); + int port = snd_seq_port_info_get_port(pinfo); + + createPort(midiManager, name, client, port); + } + } + } + + return true; + } +#else +/* ALSA-0.5 specific code */ + int alsaOpen() { + return snd_seq_open(&seq, SND_SEQ_OPEN); + } + + bool alsaScan(MidiManager midiManager) { + snd_seq_system_info_t sysinfo; + + int err = snd_seq_system_info(seq, &sysinfo); + if (err < 0) + { + arts_warning("snd_seq_systeminfo failed: %s", snd_strerror(err)); + return false; + } + + for(int client = 0; client < sysinfo.clients; client++) + { + snd_seq_client_info_t cinfo; + if (snd_seq_get_any_client_info(seq, client, &cinfo) == 0) + { + for(int port = 0; port < sysinfo.ports; port++) + { + snd_seq_port_info_t pinfo; + if(snd_seq_get_any_port_info(seq, client, port, &pinfo) == 0) + { + unsigned int cap; + cap = (SND_SEQ_PORT_CAP_SUBS_WRITE|SND_SEQ_PORT_CAP_WRITE); + + if ((pinfo.capability & cap) == cap) + createPort(midiManager, pinfo.name, client, port); + } + } + } + } + + return true; + } +#endif + +public: + AlsaMidiGateway_impl() : seq(0) + { + } + + ~AlsaMidiGateway_impl() + { + if(seq) + snd_seq_close(seq); + } + + void createPort(MidiManager midiManager, string name, int client, int port) + { + if(name != "aRts") + { + char nr[1024]; + + sprintf(nr, " (%3d:%-3d)", client, port); + name += nr; + + list::iterator pi = ports.begin(); + while(pi != ports.end() && (pi->alsaClient != client || pi->alsaPort != port)) + pi++; + + if(pi != ports.end()) /* we already have this port */ + pi->keep = true; + else /* we need to create it */ + { + PortEntry pe; + pe.port = AlsaMidiPort::_from_base( + new AlsaMidiPort_impl(seq, client, port)); + + if(pe.port.open()) + { + pe.client = midiManager.addClient(mcdRecord, + mctDestination, + name, name); + pe.client.addInputPort(pe.port); + pe.alsaClient = client; + pe.alsaPort = port; + pe.keep = true; + + ports.push_back(pe); + } + } + } + } + + bool rescan() + { + MidiManager midiManager = DynamicCast(Reference("global:Arts_MidiManager")); + if(midiManager.isNull()) + { + arts_warning("AlsaMidiGateway: can't find MidiManager"); + return false; + } + + if(!seq) + { + int err = alsaOpen(); + if (err < 0) + { + arts_warning("AlsaMidiGateway: could not open sequencer %s", + snd_strerror(err)); + seq = 0; + return false; + } + } + + list::iterator pi; + for(pi = ports.begin(); pi != ports.end(); pi++) + pi->keep = false; + + if(!alsaScan(midiManager)) + return false; + + /* erase those ports that are no longer needed */ + pi = ports.begin(); + while(pi != ports.end()) + { + if(!pi->keep) + pi = ports.erase(pi); + else + pi++; + } + + return true; + } +}; + +#else + +using namespace Arts; +using namespace std; + +class AlsaMidiGateway_impl : virtual public AlsaMidiGateway_skel { +public: + bool rescan() + { + /* dummy version: no ALSA support compiled in */ + return false; + } +}; + +#endif + +namespace Arts { + REGISTER_IMPLEMENTATION(AlsaMidiGateway_impl); +} diff --git a/arts/midi/alsamidiport_impl.cc b/arts/midi/alsamidiport_impl.cc deleted file mode 100644 index 97c8dffa..00000000 --- a/arts/midi/alsamidiport_impl.cc +++ /dev/null @@ -1,232 +0,0 @@ - /* - - Copyright (C) 2001-2002 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "alsamidiport_impl.h" - -#if defined(HAVE_ARTS_LIBASOUND2) || defined(HAVE_ARTS_LIBASOUND) -#include - -#ifdef HAVE_ARTS_LIBASOUND -#define snd_seq_queue_status_alloca(x) \ - *x = (snd_seq_queue_status_t *)alloca(sizeof(snd_seq_queue_status_t)) -#define snd_seq_queue_status_get_tick_time(x) x->tick -#define snd_seq_queue_status_get_real_time(x) (&(x->time)) -#endif - -using namespace std; -using namespace Arts; - -AlsaMidiPort_impl::AlsaMidiPort_impl(snd_seq_t *seq, long client, long port) - : _client(client), _port(port), alsaSeq(seq) -{ - opened = false; -} - -/* interface MidiPort */ -Arts::TimeStamp AlsaMidiPort_impl::time() -{ - snd_seq_queue_status_t *status; - snd_seq_queue_status_alloca(&status); - - snd_seq_get_queue_status(alsaSeq, alsaQueue, status); - snd_seq_tick_time_t ttime = snd_seq_queue_status_get_tick_time(status); - const snd_seq_real_time_t *rtime = - snd_seq_queue_status_get_real_time(status); - - return Arts::TimeStamp(rtime->tv_sec, rtime->tv_nsec / 1000); -} - -Arts::TimeStamp AlsaMidiPort_impl::playTime() -{ - return time(); -} - -void AlsaMidiPort_impl::fillAlsaEvent(snd_seq_event_t *ev, - const MidiCommand& command) -{ - ev->source = alsaSourceAddr; - ev->dest = alsaDestAddr; - - mcopbyte channel = command.status & mcsChannelMask; - - switch(command.status & mcsCommandMask) - { - case mcsNoteOn: - snd_seq_ev_set_noteon(ev, channel, command.data1, command.data2); - break; - case mcsNoteOff: - snd_seq_ev_set_noteoff(ev, channel, command.data1, command.data2); - break; - case mcsProgram: - snd_seq_ev_set_pgmchange(ev, channel, command.data1); - break; - case mcsParameter: - snd_seq_ev_set_controller(ev, channel, command.data1, command.data2); - break; - default: - /* unhandled */ - return; - } -} - -void AlsaMidiPort_impl::sendAlsaEvent(snd_seq_event_t *ev) -{ - int ret = snd_seq_event_output(alsaSeq, ev); - if (ret < 0) { - arts_warning("AlsaMidiPort: error writing note %s\n", - snd_strerror(ret)); - return; - } - flushAlsa(); -} - -void AlsaMidiPort_impl::processCommand(const MidiCommand& command) -{ - snd_seq_event_t ev; - snd_seq_ev_clear(&ev); - - fillAlsaEvent(&ev, command); - sendAlsaEvent(&ev); -} - -void AlsaMidiPort_impl::processEvent(const MidiEvent& event) -{ - snd_seq_event_t ev; - snd_seq_real_time_t time; - - time.tv_sec = event.time.sec; - time.tv_nsec = event.time.usec * 1000; - - snd_seq_ev_clear(&ev); - snd_seq_ev_schedule_real(&ev, alsaQueue, 0, &time); - - fillAlsaEvent(&ev, event.command); - sendAlsaEvent(&ev); -} - -/* interface AlsaMidiPort */ -void AlsaMidiPort_impl::client(long newClient) -{ - if(newClient != _client) - { - _client = newClient; - - if(opened) - { - close(); - open(); - } - - client_changed(newClient); - } -} - -long AlsaMidiPort_impl::client() -{ - return _client; -} - -void AlsaMidiPort_impl::port(long newPort) -{ - if(newPort != _port) - { - _port = newPort; - - if(opened) - { - close(); - open(); - } - - port_changed(newPort); - } -} - -long AlsaMidiPort_impl::port() -{ - return _port; -} - -bool AlsaMidiPort_impl::open() -{ - arts_return_val_if_fail(opened == false, false); - - alsaQueue = snd_seq_alloc_queue(alsaSeq); - alsaClientId = snd_seq_client_id(alsaSeq); - - alsaPort = snd_seq_create_simple_port(alsaSeq, "aRts", - SND_SEQ_PORT_CAP_WRITE | - SND_SEQ_PORT_CAP_SUBS_WRITE | - SND_SEQ_PORT_CAP_READ, - SND_SEQ_PORT_TYPE_MIDI_GENERIC); - if (alsaPort < 0) { - arts_warning("AlsaMidiPort: can't creating port %s\n", - snd_strerror(alsaPort)); - return false; - } - - alsaSourceAddr.client = alsaClientId; - alsaSourceAddr.port = alsaPort; - - alsaDestAddr.client = _client; - alsaDestAddr.port = _port; - - int ret; - ret = snd_seq_connect_to(alsaSeq, alsaPort, - alsaDestAddr.client, - alsaDestAddr.port); - if (ret < 0) { - arts_warning("AlsaMidiPort: error connecting port %s\n", - snd_strerror(ret)); - /* FIXME: destroy port here */ - return false; - } - - snd_seq_start_queue(alsaSeq, alsaQueue, 0); - flushAlsa(); - - opened = true; - return true; -} - -void AlsaMidiPort_impl::close() -{ - if(!opened) - return; - - opened = false; -} - -void AlsaMidiPort_impl::flushAlsa() -{ -#ifdef HAVE_ARTS_LIBASOUND2 - snd_seq_drain_output(alsaSeq); -#else - int err; - while((err = snd_seq_flush_output(alsaSeq)) > 0) - { - arts_debug("alsa flush error %d\n",snd_strerror(err)); - usleep(2000); - } -#endif -} -#endif diff --git a/arts/midi/alsamidiport_impl.cpp b/arts/midi/alsamidiport_impl.cpp new file mode 100644 index 00000000..97c8dffa --- /dev/null +++ b/arts/midi/alsamidiport_impl.cpp @@ -0,0 +1,232 @@ + /* + + Copyright (C) 2001-2002 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "alsamidiport_impl.h" + +#if defined(HAVE_ARTS_LIBASOUND2) || defined(HAVE_ARTS_LIBASOUND) +#include + +#ifdef HAVE_ARTS_LIBASOUND +#define snd_seq_queue_status_alloca(x) \ + *x = (snd_seq_queue_status_t *)alloca(sizeof(snd_seq_queue_status_t)) +#define snd_seq_queue_status_get_tick_time(x) x->tick +#define snd_seq_queue_status_get_real_time(x) (&(x->time)) +#endif + +using namespace std; +using namespace Arts; + +AlsaMidiPort_impl::AlsaMidiPort_impl(snd_seq_t *seq, long client, long port) + : _client(client), _port(port), alsaSeq(seq) +{ + opened = false; +} + +/* interface MidiPort */ +Arts::TimeStamp AlsaMidiPort_impl::time() +{ + snd_seq_queue_status_t *status; + snd_seq_queue_status_alloca(&status); + + snd_seq_get_queue_status(alsaSeq, alsaQueue, status); + snd_seq_tick_time_t ttime = snd_seq_queue_status_get_tick_time(status); + const snd_seq_real_time_t *rtime = + snd_seq_queue_status_get_real_time(status); + + return Arts::TimeStamp(rtime->tv_sec, rtime->tv_nsec / 1000); +} + +Arts::TimeStamp AlsaMidiPort_impl::playTime() +{ + return time(); +} + +void AlsaMidiPort_impl::fillAlsaEvent(snd_seq_event_t *ev, + const MidiCommand& command) +{ + ev->source = alsaSourceAddr; + ev->dest = alsaDestAddr; + + mcopbyte channel = command.status & mcsChannelMask; + + switch(command.status & mcsCommandMask) + { + case mcsNoteOn: + snd_seq_ev_set_noteon(ev, channel, command.data1, command.data2); + break; + case mcsNoteOff: + snd_seq_ev_set_noteoff(ev, channel, command.data1, command.data2); + break; + case mcsProgram: + snd_seq_ev_set_pgmchange(ev, channel, command.data1); + break; + case mcsParameter: + snd_seq_ev_set_controller(ev, channel, command.data1, command.data2); + break; + default: + /* unhandled */ + return; + } +} + +void AlsaMidiPort_impl::sendAlsaEvent(snd_seq_event_t *ev) +{ + int ret = snd_seq_event_output(alsaSeq, ev); + if (ret < 0) { + arts_warning("AlsaMidiPort: error writing note %s\n", + snd_strerror(ret)); + return; + } + flushAlsa(); +} + +void AlsaMidiPort_impl::processCommand(const MidiCommand& command) +{ + snd_seq_event_t ev; + snd_seq_ev_clear(&ev); + + fillAlsaEvent(&ev, command); + sendAlsaEvent(&ev); +} + +void AlsaMidiPort_impl::processEvent(const MidiEvent& event) +{ + snd_seq_event_t ev; + snd_seq_real_time_t time; + + time.tv_sec = event.time.sec; + time.tv_nsec = event.time.usec * 1000; + + snd_seq_ev_clear(&ev); + snd_seq_ev_schedule_real(&ev, alsaQueue, 0, &time); + + fillAlsaEvent(&ev, event.command); + sendAlsaEvent(&ev); +} + +/* interface AlsaMidiPort */ +void AlsaMidiPort_impl::client(long newClient) +{ + if(newClient != _client) + { + _client = newClient; + + if(opened) + { + close(); + open(); + } + + client_changed(newClient); + } +} + +long AlsaMidiPort_impl::client() +{ + return _client; +} + +void AlsaMidiPort_impl::port(long newPort) +{ + if(newPort != _port) + { + _port = newPort; + + if(opened) + { + close(); + open(); + } + + port_changed(newPort); + } +} + +long AlsaMidiPort_impl::port() +{ + return _port; +} + +bool AlsaMidiPort_impl::open() +{ + arts_return_val_if_fail(opened == false, false); + + alsaQueue = snd_seq_alloc_queue(alsaSeq); + alsaClientId = snd_seq_client_id(alsaSeq); + + alsaPort = snd_seq_create_simple_port(alsaSeq, "aRts", + SND_SEQ_PORT_CAP_WRITE | + SND_SEQ_PORT_CAP_SUBS_WRITE | + SND_SEQ_PORT_CAP_READ, + SND_SEQ_PORT_TYPE_MIDI_GENERIC); + if (alsaPort < 0) { + arts_warning("AlsaMidiPort: can't creating port %s\n", + snd_strerror(alsaPort)); + return false; + } + + alsaSourceAddr.client = alsaClientId; + alsaSourceAddr.port = alsaPort; + + alsaDestAddr.client = _client; + alsaDestAddr.port = _port; + + int ret; + ret = snd_seq_connect_to(alsaSeq, alsaPort, + alsaDestAddr.client, + alsaDestAddr.port); + if (ret < 0) { + arts_warning("AlsaMidiPort: error connecting port %s\n", + snd_strerror(ret)); + /* FIXME: destroy port here */ + return false; + } + + snd_seq_start_queue(alsaSeq, alsaQueue, 0); + flushAlsa(); + + opened = true; + return true; +} + +void AlsaMidiPort_impl::close() +{ + if(!opened) + return; + + opened = false; +} + +void AlsaMidiPort_impl::flushAlsa() +{ +#ifdef HAVE_ARTS_LIBASOUND2 + snd_seq_drain_output(alsaSeq); +#else + int err; + while((err = snd_seq_flush_output(alsaSeq)) > 0) + { + arts_debug("alsa flush error %d\n",snd_strerror(err)); + usleep(2000); + } +#endif +} +#endif diff --git a/arts/midi/artsmidi.idl b/arts/midi/artsmidi.idl index ce1c5891..9531d763 100644 --- a/arts/midi/artsmidi.idl +++ b/arts/midi/artsmidi.idl @@ -21,7 +21,7 @@ */ /* - * DISCLAIMER: The interfaces in artsmidi.idl (and the derived .cc/.h files) + * DISCLAIMER: The interfaces in artsmidi.idl (and the derived .cpp/.h files) * DO NOT GUARANTEE BINARY COMPATIBILITY YET. * * They are intended for developers. You shouldn't expect that applications in diff --git a/arts/midi/audiomiditimer_impl.cc b/arts/midi/audiomiditimer_impl.cc deleted file mode 100644 index a185b1cb..00000000 --- a/arts/midi/audiomiditimer_impl.cc +++ /dev/null @@ -1,116 +0,0 @@ - /* - - Copyright (C) 2001 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "artsmidi.h" -#include "artsflow.h" -#include "stdsynthmodule.h" -#include "debug.h" -#include "miditimercommon.h" -#include "audiotimer.h" -#include "flowsystem.h" - -using namespace std; - -namespace Arts { - -class AudioMidiTimerCommon : public MidiTimerCommon, public AudioTimerCallback -{ -protected: - AudioMidiTimerCommon(); - virtual ~AudioMidiTimerCommon(); - - AudioTimer *audioTimer; - -public: - // allocation: share one AudioMidiTimerCommon for everbody who needs one - static AudioMidiTimerCommon *subscribe(); - - TimeStamp time(); - void updateTime(); -}; - -} - -using namespace Arts; - -static AudioMidiTimerCommon *AudioMidiTimerCommon_the = 0; - -AudioMidiTimerCommon::AudioMidiTimerCommon() -{ - AudioMidiTimerCommon_the = this; - - audioTimer = AudioTimer::subscribe(); - audioTimer->addCallback(this); -} - -AudioMidiTimerCommon::~AudioMidiTimerCommon() -{ - audioTimer->removeCallback(this); - audioTimer->unsubscribe(); - - AudioMidiTimerCommon_the = 0; -} - -TimeStamp AudioMidiTimerCommon::time() -{ - return audioTimer->time(); -} - -void AudioMidiTimerCommon::updateTime() -{ - processQueue(); -} - -AudioMidiTimerCommon *AudioMidiTimerCommon::subscribe() -{ - if(!AudioMidiTimerCommon_the) - AudioMidiTimerCommon_the = new AudioMidiTimerCommon(); - AudioMidiTimerCommon_the->refCount++; - return AudioMidiTimerCommon_the; -} - -namespace Arts { - -class AudioMidiTimer_impl : public AudioMidiTimer_skel { -protected: - AudioMidiTimerCommon *timer; -public: - AudioMidiTimer_impl() - { - timer = AudioMidiTimerCommon::subscribe(); - } - ~AudioMidiTimer_impl() - { - timer->unsubscribe(); - } - TimeStamp time() - { - return timer->time(); - } - void queueEvent(MidiPort port, const MidiEvent& event) - { - timer->queueEvent(port, event); - } -}; - -REGISTER_IMPLEMENTATION(AudioMidiTimer_impl); -} diff --git a/arts/midi/audiomiditimer_impl.cpp b/arts/midi/audiomiditimer_impl.cpp new file mode 100644 index 00000000..a185b1cb --- /dev/null +++ b/arts/midi/audiomiditimer_impl.cpp @@ -0,0 +1,116 @@ + /* + + Copyright (C) 2001 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "artsmidi.h" +#include "artsflow.h" +#include "stdsynthmodule.h" +#include "debug.h" +#include "miditimercommon.h" +#include "audiotimer.h" +#include "flowsystem.h" + +using namespace std; + +namespace Arts { + +class AudioMidiTimerCommon : public MidiTimerCommon, public AudioTimerCallback +{ +protected: + AudioMidiTimerCommon(); + virtual ~AudioMidiTimerCommon(); + + AudioTimer *audioTimer; + +public: + // allocation: share one AudioMidiTimerCommon for everbody who needs one + static AudioMidiTimerCommon *subscribe(); + + TimeStamp time(); + void updateTime(); +}; + +} + +using namespace Arts; + +static AudioMidiTimerCommon *AudioMidiTimerCommon_the = 0; + +AudioMidiTimerCommon::AudioMidiTimerCommon() +{ + AudioMidiTimerCommon_the = this; + + audioTimer = AudioTimer::subscribe(); + audioTimer->addCallback(this); +} + +AudioMidiTimerCommon::~AudioMidiTimerCommon() +{ + audioTimer->removeCallback(this); + audioTimer->unsubscribe(); + + AudioMidiTimerCommon_the = 0; +} + +TimeStamp AudioMidiTimerCommon::time() +{ + return audioTimer->time(); +} + +void AudioMidiTimerCommon::updateTime() +{ + processQueue(); +} + +AudioMidiTimerCommon *AudioMidiTimerCommon::subscribe() +{ + if(!AudioMidiTimerCommon_the) + AudioMidiTimerCommon_the = new AudioMidiTimerCommon(); + AudioMidiTimerCommon_the->refCount++; + return AudioMidiTimerCommon_the; +} + +namespace Arts { + +class AudioMidiTimer_impl : public AudioMidiTimer_skel { +protected: + AudioMidiTimerCommon *timer; +public: + AudioMidiTimer_impl() + { + timer = AudioMidiTimerCommon::subscribe(); + } + ~AudioMidiTimer_impl() + { + timer->unsubscribe(); + } + TimeStamp time() + { + return timer->time(); + } + void queueEvent(MidiPort port, const MidiEvent& event) + { + timer->queueEvent(port, event); + } +}; + +REGISTER_IMPLEMENTATION(AudioMidiTimer_impl); +} diff --git a/arts/midi/audiosync_impl.cc b/arts/midi/audiosync_impl.cc deleted file mode 100644 index 20f089df..00000000 --- a/arts/midi/audiosync_impl.cc +++ /dev/null @@ -1,203 +0,0 @@ - /* - - Copyright (C) 2001-2002 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "audiosync_impl.h" -#include "midisyncgroup_impl.h" -#include "audiotimer.h" -#include "audiosubsys.h" -#include "timestampmath.h" - -#undef AUDIO_DEBUG_DRIFT - -using namespace std; -using namespace Arts; - -namespace Arts { - static list audioSyncImplList; -} - -void AudioSync_impl::AudioSyncEvent::execute() -{ - list::iterator i; - - for(i = startModules.begin(); i != startModules.end(); i++) - i->start(); - - for(i = stopModules.begin(); i != stopModules.end(); i++) - i->stop(); -} - -AudioSync_impl::AudioSync_impl() - : newEvent(new AudioSyncEvent), syncGroup(0) -{ - syncOffset = TimeStamp(0,0); - - timer = AudioTimer::subscribe(); - timer->addCallback(this); - - audioSyncImplList.push_back(this); -} - -AudioSync_impl::~AudioSync_impl() -{ - delete newEvent; - - while(!events.empty()) - { - delete events.front(); - events.pop_front(); - } - - if(syncGroup) - { - syncGroup->audioSyncDied(this); - syncGroup = 0; - } - audioSyncImplList.remove(this); - timer->removeCallback(this); - timer->unsubscribe(); -} - -TimeStamp AudioSync_impl::time() -{ - if(syncGroup) - return syncGroup->time(); - else - return audioTime(); -} - -TimeStamp AudioSync_impl::playTime() -{ - if(syncGroup) - return syncGroup->playTime(); - else - return audioPlayTime(); -} - -TimeStamp AudioSync_impl::audioTime() -{ - return timer->time(); -} - -TimeStamp AudioSync_impl::audioPlayTime() -{ - double delay = AudioSubSystem::the()->outputDelay(); - - TimeStamp time = audioTime(); - timeStampDec(time,timeStampFromDouble(delay)); - return time; -} - -TimeStamp AudioSync_impl::clientTime() -{ - TimeStamp time = audioTime(); - timeStampDec(time, syncOffset); - return time; -} - -void AudioSync_impl::queueStart(SynthModule synthModule) -{ - newEvent->startModules.push_back(synthModule); -} - -void AudioSync_impl::queueStop(SynthModule synthModule) -{ - newEvent->stopModules.push_back(synthModule); -} - -void AudioSync_impl::execute() -{ - newEvent->execute(); - newEvent->startModules.clear(); - newEvent->stopModules.clear(); -} - -void AudioSync_impl::executeAt(const TimeStamp& timeStamp) -{ - newEvent->time = timeStamp; - if(syncGroup) - timeStampInc(newEvent->time, syncOffset); - - events.push_back(newEvent); - - newEvent = new AudioSyncEvent; -} - -void AudioSync_impl::updateTime() -{ - TimeStamp now = audioTime(); - list::iterator i; - - i = events.begin(); - while(i != events.end()) - { - AudioSyncEvent *event = *i; - TimeStamp& eventTime = event->time; - - if( now.sec > eventTime.sec - || ((now.sec == eventTime.sec) && (now.usec > eventTime.usec))) - { - event->execute(); - delete event; - i = events.erase(i); - } - else - { - i++; - } - } -} - -void AudioSync_impl::setSyncGroup(MidiSyncGroup_impl *newSyncGroup) -{ - syncGroup = newSyncGroup; -} - -void AudioSync_impl::synchronizeTo(const TimeStamp& time) -{ -#ifdef AUDIO_DEBUG_DRIFT - TimeStamp drift = syncOffset; // debug drift -#endif - - syncOffset = audioPlayTime(); - timeStampDec(syncOffset, time); - -#ifdef AUDIO_DEBUG_DRIFT - timeStampDec(drift, syncOffset); // debug drift - printf("SYNC DRIFT %30s %30s: %f\n", - "AudioSync", "AudioSync", timeStampToDouble(drift)); -#endif -} - -AudioSync_impl *AudioSync_impl::find(AudioSync audioSync) -{ - list::iterator i; - - for(i = audioSyncImplList.begin(); i != audioSyncImplList.end(); i++) - { - if((*i)->_isEqual(audioSync._base())) - return (*i); - } - return 0; -} - -namespace Arts { REGISTER_IMPLEMENTATION(AudioSync_impl); } diff --git a/arts/midi/audiosync_impl.cpp b/arts/midi/audiosync_impl.cpp new file mode 100644 index 00000000..20f089df --- /dev/null +++ b/arts/midi/audiosync_impl.cpp @@ -0,0 +1,203 @@ + /* + + Copyright (C) 2001-2002 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "audiosync_impl.h" +#include "midisyncgroup_impl.h" +#include "audiotimer.h" +#include "audiosubsys.h" +#include "timestampmath.h" + +#undef AUDIO_DEBUG_DRIFT + +using namespace std; +using namespace Arts; + +namespace Arts { + static list audioSyncImplList; +} + +void AudioSync_impl::AudioSyncEvent::execute() +{ + list::iterator i; + + for(i = startModules.begin(); i != startModules.end(); i++) + i->start(); + + for(i = stopModules.begin(); i != stopModules.end(); i++) + i->stop(); +} + +AudioSync_impl::AudioSync_impl() + : newEvent(new AudioSyncEvent), syncGroup(0) +{ + syncOffset = TimeStamp(0,0); + + timer = AudioTimer::subscribe(); + timer->addCallback(this); + + audioSyncImplList.push_back(this); +} + +AudioSync_impl::~AudioSync_impl() +{ + delete newEvent; + + while(!events.empty()) + { + delete events.front(); + events.pop_front(); + } + + if(syncGroup) + { + syncGroup->audioSyncDied(this); + syncGroup = 0; + } + audioSyncImplList.remove(this); + timer->removeCallback(this); + timer->unsubscribe(); +} + +TimeStamp AudioSync_impl::time() +{ + if(syncGroup) + return syncGroup->time(); + else + return audioTime(); +} + +TimeStamp AudioSync_impl::playTime() +{ + if(syncGroup) + return syncGroup->playTime(); + else + return audioPlayTime(); +} + +TimeStamp AudioSync_impl::audioTime() +{ + return timer->time(); +} + +TimeStamp AudioSync_impl::audioPlayTime() +{ + double delay = AudioSubSystem::the()->outputDelay(); + + TimeStamp time = audioTime(); + timeStampDec(time,timeStampFromDouble(delay)); + return time; +} + +TimeStamp AudioSync_impl::clientTime() +{ + TimeStamp time = audioTime(); + timeStampDec(time, syncOffset); + return time; +} + +void AudioSync_impl::queueStart(SynthModule synthModule) +{ + newEvent->startModules.push_back(synthModule); +} + +void AudioSync_impl::queueStop(SynthModule synthModule) +{ + newEvent->stopModules.push_back(synthModule); +} + +void AudioSync_impl::execute() +{ + newEvent->execute(); + newEvent->startModules.clear(); + newEvent->stopModules.clear(); +} + +void AudioSync_impl::executeAt(const TimeStamp& timeStamp) +{ + newEvent->time = timeStamp; + if(syncGroup) + timeStampInc(newEvent->time, syncOffset); + + events.push_back(newEvent); + + newEvent = new AudioSyncEvent; +} + +void AudioSync_impl::updateTime() +{ + TimeStamp now = audioTime(); + list::iterator i; + + i = events.begin(); + while(i != events.end()) + { + AudioSyncEvent *event = *i; + TimeStamp& eventTime = event->time; + + if( now.sec > eventTime.sec + || ((now.sec == eventTime.sec) && (now.usec > eventTime.usec))) + { + event->execute(); + delete event; + i = events.erase(i); + } + else + { + i++; + } + } +} + +void AudioSync_impl::setSyncGroup(MidiSyncGroup_impl *newSyncGroup) +{ + syncGroup = newSyncGroup; +} + +void AudioSync_impl::synchronizeTo(const TimeStamp& time) +{ +#ifdef AUDIO_DEBUG_DRIFT + TimeStamp drift = syncOffset; // debug drift +#endif + + syncOffset = audioPlayTime(); + timeStampDec(syncOffset, time); + +#ifdef AUDIO_DEBUG_DRIFT + timeStampDec(drift, syncOffset); // debug drift + printf("SYNC DRIFT %30s %30s: %f\n", + "AudioSync", "AudioSync", timeStampToDouble(drift)); +#endif +} + +AudioSync_impl *AudioSync_impl::find(AudioSync audioSync) +{ + list::iterator i; + + for(i = audioSyncImplList.begin(); i != audioSyncImplList.end(); i++) + { + if((*i)->_isEqual(audioSync._base())) + return (*i); + } + return 0; +} + +namespace Arts { REGISTER_IMPLEMENTATION(AudioSync_impl); } diff --git a/arts/midi/audiotimer.cc b/arts/midi/audiotimer.cc deleted file mode 100644 index a80e551c..00000000 --- a/arts/midi/audiotimer.cc +++ /dev/null @@ -1,98 +0,0 @@ - /* - - Copyright (C) 2001-2002 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "artsmidi.h" -#include "artsflow.h" -#include "stdsynthmodule.h" -#include "debug.h" -#include "miditimercommon.h" -#include "audiotimer.h" -#include "flowsystem.h" - -using namespace std; -using namespace Arts; - -static AudioTimer *AudioTimer_the = 0; - -AudioTimer::AudioTimer() -{ - AudioTimer_the = this; - samples = seconds = 0; -} - -AudioTimer::~AudioTimer() -{ - AudioTimer_the = 0; -} - -TimeStamp AudioTimer::time() -{ - return TimeStamp(seconds, - (long)((float)samples / samplingRateFloat * 1000000.0)); -} - -void AudioTimer::notify(const Notification &) -{ - list::iterator i; - for(i = callbacks.begin(); i != callbacks.end(); i++) - (*i)->updateTime(); -} - -void AudioTimer::calculateBlock(unsigned long s) -{ - samples += s; - while(samples > samplingRate) - { - samples -= samplingRate; - seconds++; - } - Notification n; - n.receiver = this; - n.ID = 0; - n.data = 0; - n.internal = 0; - NotificationManager::the()->send(n); -} - -AudioTimer *AudioTimer::subscribe() -{ - if(!AudioTimer_the) - { - new AudioTimer(); - AudioTimer_the->_node()->start(); - } - else - { - AudioTimer_the->_copy(); - } - return AudioTimer_the; -} - -void AudioTimer::addCallback(AudioTimerCallback *callback) -{ - callbacks.push_back(callback); -} - -void AudioTimer::removeCallback(AudioTimerCallback *callback) -{ - callbacks.remove(callback); -} diff --git a/arts/midi/audiotimer.cpp b/arts/midi/audiotimer.cpp new file mode 100644 index 00000000..a80e551c --- /dev/null +++ b/arts/midi/audiotimer.cpp @@ -0,0 +1,98 @@ + /* + + Copyright (C) 2001-2002 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "artsmidi.h" +#include "artsflow.h" +#include "stdsynthmodule.h" +#include "debug.h" +#include "miditimercommon.h" +#include "audiotimer.h" +#include "flowsystem.h" + +using namespace std; +using namespace Arts; + +static AudioTimer *AudioTimer_the = 0; + +AudioTimer::AudioTimer() +{ + AudioTimer_the = this; + samples = seconds = 0; +} + +AudioTimer::~AudioTimer() +{ + AudioTimer_the = 0; +} + +TimeStamp AudioTimer::time() +{ + return TimeStamp(seconds, + (long)((float)samples / samplingRateFloat * 1000000.0)); +} + +void AudioTimer::notify(const Notification &) +{ + list::iterator i; + for(i = callbacks.begin(); i != callbacks.end(); i++) + (*i)->updateTime(); +} + +void AudioTimer::calculateBlock(unsigned long s) +{ + samples += s; + while(samples > samplingRate) + { + samples -= samplingRate; + seconds++; + } + Notification n; + n.receiver = this; + n.ID = 0; + n.data = 0; + n.internal = 0; + NotificationManager::the()->send(n); +} + +AudioTimer *AudioTimer::subscribe() +{ + if(!AudioTimer_the) + { + new AudioTimer(); + AudioTimer_the->_node()->start(); + } + else + { + AudioTimer_the->_copy(); + } + return AudioTimer_the; +} + +void AudioTimer::addCallback(AudioTimerCallback *callback) +{ + callbacks.push_back(callback); +} + +void AudioTimer::removeCallback(AudioTimerCallback *callback) +{ + callbacks.remove(callback); +} diff --git a/arts/midi/midiclient_impl.cc b/arts/midi/midiclient_impl.cc deleted file mode 100644 index 0aa2ec6f..00000000 --- a/arts/midi/midiclient_impl.cc +++ /dev/null @@ -1,274 +0,0 @@ - /* - - Copyright (C) 2000-2002 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "midiclient_impl.h" -#include "midimanager_impl.h" -#include "midimanagerport_impl.h" -#include "midisyncgroup_impl.h" -#include "timestampmath.h" - -#undef DEBUG_SYNC_DRIFT - -using namespace Arts; -using namespace std; - -MidiClient_impl::MidiClient_impl(const MidiClientInfo& info, - MidiManager_impl *manager) :_info(info), manager(manager), syncGroup(0) -{ -} - -MidiClient_impl::~MidiClient_impl() -{ - while(!_info.connections.empty()) - disconnect(manager->findClient(_info.connections[0])); - - if(syncGroup) - { - syncGroup->clientDied(this); - syncGroup = 0; - } - manager->removeClient(this); -} - -MidiClientInfo MidiClient_impl::info() -{ - return _info; -} - -void MidiClient_impl::title(const string &newvalue) -{ - _info.title = newvalue; -} - -string MidiClient_impl::title() -{ - return _info.title; -} - -void MidiClient_impl::addInputPort(MidiPort port) -{ - assert(_info.direction == mcdRecord); - - ports.push_back(port); - - // FIXME: should we synchronize inputPorts at all - rebuildConnections(); -} - -MidiPort MidiClient_impl::addOutputPort() -{ - assert(_info.direction == mcdPlay); - - MidiPort port = MidiPort::_from_base(new MidiManagerPort_impl(this)); - ports.push_back(port); - - rebuildConnections(); - return port; -} - -void MidiClient_impl::removePort(MidiPort port) -{ - list::iterator i = ports.begin(); - while(i != ports.end()) - { - if (i->_isEqual(port)) - i = ports.erase(i); - else - i++; - } - - rebuildConnections(); -} - -void MidiClient_impl::rebuildConnections() -{ - _connections.clear(); - - vector::iterator li; - for(li = _info.connections.begin(); li != _info.connections.end(); li++) - { - MidiClient_impl *other = manager->findClient(*li); - assert(other); - - list::iterator pi; - for(pi = other->ports.begin(); pi != other->ports.end(); pi++) - { - MidiClientConnection mcc; - mcc.offset = TimeStamp(0,0); - mcc.port = *pi; - _connections.push_back(mcc); - } - } - adjustSync(); -} - -list *MidiClient_impl::connections() -{ - return &_connections; -} - -static void removeElement(vector& vec, long el) -{ - vector tmp; - vec.swap(tmp); - vector::iterator i; - for(i = tmp.begin(); i != tmp.end(); i++) - if(*i != el) vec.push_back(*i); -} - -void MidiClient_impl::connect(MidiClient_impl *dest) -{ - assert(_info.direction != dest->_info.direction); - - disconnect(dest); - - _info.connections.push_back(dest->ID()); - dest->_info.connections.push_back(ID()); - - list::iterator pi; - - /* add the other clients ports to our connection list */ - for(pi = dest->ports.begin(); pi != dest->ports.end(); pi++) - { - MidiClientConnection mcc; - mcc.offset = TimeStamp(0,0); - mcc.port = *pi; - _connections.push_back(mcc); - } - - /* add our ports to the other clients connection list */ - for(pi = ports.begin(); pi != ports.end(); pi++) - { - MidiClientConnection mcc; - mcc.offset = TimeStamp(0,0); - mcc.port = *pi; - dest->_connections.push_back(mcc); - } - adjustSync(); -} - -void MidiClient_impl::disconnect(MidiClient_impl *dest) -{ - assert(_info.direction != dest->_info.direction); - - removeElement(_info.connections,dest->ID()); - removeElement(dest->_info.connections,ID()); - - list::iterator pi; - - /* remove the other clients ports from our connection list */ - for(pi = dest->ports.begin(); pi != dest->ports.end(); pi++) - { - list::iterator ci = _connections.begin(); - - while(ci != _connections.end()) - { - if(ci->port._isEqual(*pi)) - ci = _connections.erase(ci); - else - ci++; - } - } - - /* remove our ports from the other clients connection list */ - for(pi = ports.begin(); pi != ports.end(); pi++) - { - list::iterator ci = dest->_connections.begin(); - - while(ci != dest->_connections.end()) - { - if(ci->port._isEqual(*pi)) - ci = dest->_connections.erase(ci); - else - ci++; - } - } - adjustSync(); -} - -void MidiClient_impl::synchronizeTo(const TimeStamp& time) -{ - list::iterator i; - - for(i = _connections.begin(); i != _connections.end(); i++) - { - MidiClientConnection& mcc = *i; - -#ifdef DEBUG_SYNC_DRIFT - TimeStamp drift = mcc.offset; // debug drift -#endif - - mcc.offset = mcc.port.playTime(); - timeStampDec(mcc.offset, time); - -#ifdef DEBUG_SYNC_DRIFT - timeStampDec(drift,mcc.offset); // debug drift - printf("SYNC DRIFT %30s %30s: %f\n", - mcc.port._interfaceName().c_str(), _info.title.c_str(), - timeStampToDouble(drift)); -#endif - } -} - -void MidiClient_impl::setSyncGroup(MidiSyncGroup_impl *newSyncGroup) -{ - syncGroup = newSyncGroup; -} - -void MidiClient_impl::adjustSync() -{ - if(syncGroup) - syncGroup->clientChanged(this); - else - synchronizeTo(systemMidiTimer.time()); -} - -TimeStamp MidiClient_impl::time() -{ - if(syncGroup) - return syncGroup->time(); - else - return clientTime(); -} - -TimeStamp MidiClient_impl::playTime() -{ - if(syncGroup) - return syncGroup->playTime(); - else - return systemMidiTimer.time(); -} - -TimeStamp MidiClient_impl::clientTime() -{ - TimeStamp result = playTime(); - - list::iterator i; - for(i = _connections.begin(); i != _connections.end(); i++) - { - TimeStamp time = i->port.time(); - timeStampDec(time, i->offset); - result = timeStampMax(result, time); - } - - return result; -} diff --git a/arts/midi/midiclient_impl.cpp b/arts/midi/midiclient_impl.cpp new file mode 100644 index 00000000..0aa2ec6f --- /dev/null +++ b/arts/midi/midiclient_impl.cpp @@ -0,0 +1,274 @@ + /* + + Copyright (C) 2000-2002 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "midiclient_impl.h" +#include "midimanager_impl.h" +#include "midimanagerport_impl.h" +#include "midisyncgroup_impl.h" +#include "timestampmath.h" + +#undef DEBUG_SYNC_DRIFT + +using namespace Arts; +using namespace std; + +MidiClient_impl::MidiClient_impl(const MidiClientInfo& info, + MidiManager_impl *manager) :_info(info), manager(manager), syncGroup(0) +{ +} + +MidiClient_impl::~MidiClient_impl() +{ + while(!_info.connections.empty()) + disconnect(manager->findClient(_info.connections[0])); + + if(syncGroup) + { + syncGroup->clientDied(this); + syncGroup = 0; + } + manager->removeClient(this); +} + +MidiClientInfo MidiClient_impl::info() +{ + return _info; +} + +void MidiClient_impl::title(const string &newvalue) +{ + _info.title = newvalue; +} + +string MidiClient_impl::title() +{ + return _info.title; +} + +void MidiClient_impl::addInputPort(MidiPort port) +{ + assert(_info.direction == mcdRecord); + + ports.push_back(port); + + // FIXME: should we synchronize inputPorts at all + rebuildConnections(); +} + +MidiPort MidiClient_impl::addOutputPort() +{ + assert(_info.direction == mcdPlay); + + MidiPort port = MidiPort::_from_base(new MidiManagerPort_impl(this)); + ports.push_back(port); + + rebuildConnections(); + return port; +} + +void MidiClient_impl::removePort(MidiPort port) +{ + list::iterator i = ports.begin(); + while(i != ports.end()) + { + if (i->_isEqual(port)) + i = ports.erase(i); + else + i++; + } + + rebuildConnections(); +} + +void MidiClient_impl::rebuildConnections() +{ + _connections.clear(); + + vector::iterator li; + for(li = _info.connections.begin(); li != _info.connections.end(); li++) + { + MidiClient_impl *other = manager->findClient(*li); + assert(other); + + list::iterator pi; + for(pi = other->ports.begin(); pi != other->ports.end(); pi++) + { + MidiClientConnection mcc; + mcc.offset = TimeStamp(0,0); + mcc.port = *pi; + _connections.push_back(mcc); + } + } + adjustSync(); +} + +list *MidiClient_impl::connections() +{ + return &_connections; +} + +static void removeElement(vector& vec, long el) +{ + vector tmp; + vec.swap(tmp); + vector::iterator i; + for(i = tmp.begin(); i != tmp.end(); i++) + if(*i != el) vec.push_back(*i); +} + +void MidiClient_impl::connect(MidiClient_impl *dest) +{ + assert(_info.direction != dest->_info.direction); + + disconnect(dest); + + _info.connections.push_back(dest->ID()); + dest->_info.connections.push_back(ID()); + + list::iterator pi; + + /* add the other clients ports to our connection list */ + for(pi = dest->ports.begin(); pi != dest->ports.end(); pi++) + { + MidiClientConnection mcc; + mcc.offset = TimeStamp(0,0); + mcc.port = *pi; + _connections.push_back(mcc); + } + + /* add our ports to the other clients connection list */ + for(pi = ports.begin(); pi != ports.end(); pi++) + { + MidiClientConnection mcc; + mcc.offset = TimeStamp(0,0); + mcc.port = *pi; + dest->_connections.push_back(mcc); + } + adjustSync(); +} + +void MidiClient_impl::disconnect(MidiClient_impl *dest) +{ + assert(_info.direction != dest->_info.direction); + + removeElement(_info.connections,dest->ID()); + removeElement(dest->_info.connections,ID()); + + list::iterator pi; + + /* remove the other clients ports from our connection list */ + for(pi = dest->ports.begin(); pi != dest->ports.end(); pi++) + { + list::iterator ci = _connections.begin(); + + while(ci != _connections.end()) + { + if(ci->port._isEqual(*pi)) + ci = _connections.erase(ci); + else + ci++; + } + } + + /* remove our ports from the other clients connection list */ + for(pi = ports.begin(); pi != ports.end(); pi++) + { + list::iterator ci = dest->_connections.begin(); + + while(ci != dest->_connections.end()) + { + if(ci->port._isEqual(*pi)) + ci = dest->_connections.erase(ci); + else + ci++; + } + } + adjustSync(); +} + +void MidiClient_impl::synchronizeTo(const TimeStamp& time) +{ + list::iterator i; + + for(i = _connections.begin(); i != _connections.end(); i++) + { + MidiClientConnection& mcc = *i; + +#ifdef DEBUG_SYNC_DRIFT + TimeStamp drift = mcc.offset; // debug drift +#endif + + mcc.offset = mcc.port.playTime(); + timeStampDec(mcc.offset, time); + +#ifdef DEBUG_SYNC_DRIFT + timeStampDec(drift,mcc.offset); // debug drift + printf("SYNC DRIFT %30s %30s: %f\n", + mcc.port._interfaceName().c_str(), _info.title.c_str(), + timeStampToDouble(drift)); +#endif + } +} + +void MidiClient_impl::setSyncGroup(MidiSyncGroup_impl *newSyncGroup) +{ + syncGroup = newSyncGroup; +} + +void MidiClient_impl::adjustSync() +{ + if(syncGroup) + syncGroup->clientChanged(this); + else + synchronizeTo(systemMidiTimer.time()); +} + +TimeStamp MidiClient_impl::time() +{ + if(syncGroup) + return syncGroup->time(); + else + return clientTime(); +} + +TimeStamp MidiClient_impl::playTime() +{ + if(syncGroup) + return syncGroup->playTime(); + else + return systemMidiTimer.time(); +} + +TimeStamp MidiClient_impl::clientTime() +{ + TimeStamp result = playTime(); + + list::iterator i; + for(i = _connections.begin(); i != _connections.end(); i++) + { + TimeStamp time = i->port.time(); + timeStampDec(time, i->offset); + result = timeStampMax(result, time); + } + + return result; +} diff --git a/arts/midi/midimanager_impl.cc b/arts/midi/midimanager_impl.cc deleted file mode 100644 index ea310503..00000000 --- a/arts/midi/midimanager_impl.cc +++ /dev/null @@ -1,156 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "midimanager_impl.h" -#include "midiclient_impl.h" -#include "midisyncgroup_impl.h" -#include "debug.h" - -using namespace Arts; -using namespace std; - -static int cleanReference(const string& reference) -{ - Object test = Reference("global:"+reference); - if(test.isNull()) - { - Dispatcher::the()->globalComm().erase(reference); - return 1; - } - else - return 0; -} - -MidiManager_impl::MidiManager_impl() : nextID(1) -{ - cleanReference("Arts_MidiManager"); - if(!ObjectManager::the()->addGlobalReference(Object::_from_base(_copy()), - "Arts_MidiManager")) - { - arts_warning("can't register Arts::MidiManager"); - } - else - { - arts_debug("Arts::MidiManager registered successfully."); - } - Dispatcher::the()->ioManager()->addTimer(1000, this); -} - -MidiManager_impl::~MidiManager_impl() -{ - Dispatcher::the()->ioManager()->removeTimer(this); -} - -vector *MidiManager_impl::clients() -{ - if(!alsaMidiGateway.isNull()) - { - if(!alsaMidiGateway.rescan()) - alsaMidiGateway = AlsaMidiGateway::null(); - } - - vector *result = new vector; - - list::iterator i; - for(i = _clients.begin(); i != _clients.end(); i++) - result->push_back((*i)->info()); - - return result; -} - -MidiClient MidiManager_impl::addClient(MidiClientDirection direction, - MidiClientType type, const string& title, const string& autoRestoreID) -{ - MidiClientInfo info; - - info.ID = nextID++; - info.direction = direction; - info.type = type; - info.title = title; - info.autoRestoreID = autoRestoreID; - - MidiClient_impl *impl = new MidiClient_impl(info, this); - _clients.push_back(impl); - return MidiClient::_from_base(impl); -} - -void MidiManager_impl::removeClient(MidiClient_impl *client) -{ - _clients.remove(client); -} - -MidiClient_impl *MidiManager_impl::findClient(long clientID) -{ - list::iterator i; - - for(i = _clients.begin(); i != _clients.end(); i++) - { - if((*i)->ID() == clientID) - return (*i); - } - return 0; -} - -void MidiManager_impl::connect(long clientID, long destinationID) -{ - MidiClient_impl *src = findClient(clientID); - MidiClient_impl *dest = findClient(destinationID); - - arts_return_if_fail(src); - arts_return_if_fail(dest); - src->connect(dest); -} - -void MidiManager_impl::disconnect(long clientID, long destinationID) -{ - MidiClient_impl *src = findClient(clientID); - MidiClient_impl *dest = findClient(destinationID); - - arts_return_if_fail(src); - arts_return_if_fail(dest); - src->disconnect(dest); -} - -MidiSyncGroup MidiManager_impl::addSyncGroup() -{ - MidiSyncGroup_impl *impl = new MidiSyncGroup_impl(this); - syncGroups.push_back(impl); - return MidiSyncGroup::_from_base(impl); -} - -void MidiManager_impl::removeSyncGroup(MidiSyncGroup_impl *group) -{ - syncGroups.remove(group); -} - -void MidiManager_impl::notifyTime() -{ - list::iterator i; - for(i = _clients.begin(); i != _clients.end(); i++) - (*i)->adjustSync(); - - list::iterator gi; - for(gi = syncGroups.begin(); gi != syncGroups.end(); gi++) - (*gi)->adjustSync(); -} - -namespace Arts { REGISTER_IMPLEMENTATION(MidiManager_impl); } diff --git a/arts/midi/midimanager_impl.cpp b/arts/midi/midimanager_impl.cpp new file mode 100644 index 00000000..ea310503 --- /dev/null +++ b/arts/midi/midimanager_impl.cpp @@ -0,0 +1,156 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "midimanager_impl.h" +#include "midiclient_impl.h" +#include "midisyncgroup_impl.h" +#include "debug.h" + +using namespace Arts; +using namespace std; + +static int cleanReference(const string& reference) +{ + Object test = Reference("global:"+reference); + if(test.isNull()) + { + Dispatcher::the()->globalComm().erase(reference); + return 1; + } + else + return 0; +} + +MidiManager_impl::MidiManager_impl() : nextID(1) +{ + cleanReference("Arts_MidiManager"); + if(!ObjectManager::the()->addGlobalReference(Object::_from_base(_copy()), + "Arts_MidiManager")) + { + arts_warning("can't register Arts::MidiManager"); + } + else + { + arts_debug("Arts::MidiManager registered successfully."); + } + Dispatcher::the()->ioManager()->addTimer(1000, this); +} + +MidiManager_impl::~MidiManager_impl() +{ + Dispatcher::the()->ioManager()->removeTimer(this); +} + +vector *MidiManager_impl::clients() +{ + if(!alsaMidiGateway.isNull()) + { + if(!alsaMidiGateway.rescan()) + alsaMidiGateway = AlsaMidiGateway::null(); + } + + vector *result = new vector; + + list::iterator i; + for(i = _clients.begin(); i != _clients.end(); i++) + result->push_back((*i)->info()); + + return result; +} + +MidiClient MidiManager_impl::addClient(MidiClientDirection direction, + MidiClientType type, const string& title, const string& autoRestoreID) +{ + MidiClientInfo info; + + info.ID = nextID++; + info.direction = direction; + info.type = type; + info.title = title; + info.autoRestoreID = autoRestoreID; + + MidiClient_impl *impl = new MidiClient_impl(info, this); + _clients.push_back(impl); + return MidiClient::_from_base(impl); +} + +void MidiManager_impl::removeClient(MidiClient_impl *client) +{ + _clients.remove(client); +} + +MidiClient_impl *MidiManager_impl::findClient(long clientID) +{ + list::iterator i; + + for(i = _clients.begin(); i != _clients.end(); i++) + { + if((*i)->ID() == clientID) + return (*i); + } + return 0; +} + +void MidiManager_impl::connect(long clientID, long destinationID) +{ + MidiClient_impl *src = findClient(clientID); + MidiClient_impl *dest = findClient(destinationID); + + arts_return_if_fail(src); + arts_return_if_fail(dest); + src->connect(dest); +} + +void MidiManager_impl::disconnect(long clientID, long destinationID) +{ + MidiClient_impl *src = findClient(clientID); + MidiClient_impl *dest = findClient(destinationID); + + arts_return_if_fail(src); + arts_return_if_fail(dest); + src->disconnect(dest); +} + +MidiSyncGroup MidiManager_impl::addSyncGroup() +{ + MidiSyncGroup_impl *impl = new MidiSyncGroup_impl(this); + syncGroups.push_back(impl); + return MidiSyncGroup::_from_base(impl); +} + +void MidiManager_impl::removeSyncGroup(MidiSyncGroup_impl *group) +{ + syncGroups.remove(group); +} + +void MidiManager_impl::notifyTime() +{ + list::iterator i; + for(i = _clients.begin(); i != _clients.end(); i++) + (*i)->adjustSync(); + + list::iterator gi; + for(gi = syncGroups.begin(); gi != syncGroups.end(); gi++) + (*gi)->adjustSync(); +} + +namespace Arts { REGISTER_IMPLEMENTATION(MidiManager_impl); } diff --git a/arts/midi/midimanagerport_impl.cc b/arts/midi/midimanagerport_impl.cc deleted file mode 100644 index 3b4261a7..00000000 --- a/arts/midi/midimanagerport_impl.cc +++ /dev/null @@ -1,71 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "midimanagerport_impl.h" -#include "midimanager_impl.h" -#include "midiclient_impl.h" -#include "timestampmath.h" - -#include - -using namespace Arts; -using namespace std; - -MidiManagerPort_impl::MidiManagerPort_impl(MidiClient_impl *client) - : client(client) -{ -} - -TimeStamp MidiManagerPort_impl::time() -{ - return client->time(); -} - -TimeStamp MidiManagerPort_impl::playTime() -{ - return client->playTime(); -} - - -void MidiManagerPort_impl::processCommand(const MidiCommand& command) -{ - list *connections = client->connections(); - list::iterator i; - - for(i = connections->begin(); i != connections->end(); i++) - i->port.processCommand(command); -} - -void MidiManagerPort_impl::processEvent(const MidiEvent& event) -{ - list *connections = client->connections(); - list::iterator i; - - for(i = connections->begin(); i != connections->end(); i++) - { - /* relocate the event to the synchronized time */ - TimeStamp time = event.time; - timeStampInc(time, i->offset); - - i->port.processEvent(MidiEvent(time, event.command)); - } -} diff --git a/arts/midi/midimanagerport_impl.cpp b/arts/midi/midimanagerport_impl.cpp new file mode 100644 index 00000000..3b4261a7 --- /dev/null +++ b/arts/midi/midimanagerport_impl.cpp @@ -0,0 +1,71 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "midimanagerport_impl.h" +#include "midimanager_impl.h" +#include "midiclient_impl.h" +#include "timestampmath.h" + +#include + +using namespace Arts; +using namespace std; + +MidiManagerPort_impl::MidiManagerPort_impl(MidiClient_impl *client) + : client(client) +{ +} + +TimeStamp MidiManagerPort_impl::time() +{ + return client->time(); +} + +TimeStamp MidiManagerPort_impl::playTime() +{ + return client->playTime(); +} + + +void MidiManagerPort_impl::processCommand(const MidiCommand& command) +{ + list *connections = client->connections(); + list::iterator i; + + for(i = connections->begin(); i != connections->end(); i++) + i->port.processCommand(command); +} + +void MidiManagerPort_impl::processEvent(const MidiEvent& event) +{ + list *connections = client->connections(); + list::iterator i; + + for(i = connections->begin(); i != connections->end(); i++) + { + /* relocate the event to the synchronized time */ + TimeStamp time = event.time; + timeStampInc(time, i->offset); + + i->port.processEvent(MidiEvent(time, event.command)); + } +} diff --git a/arts/midi/midisend.cc b/arts/midi/midisend.cc deleted file mode 100644 index 2b976d61..00000000 --- a/arts/midi/midisend.cc +++ /dev/null @@ -1,375 +0,0 @@ -/* - -Copyright (C) 1999 Emmeran Seehuber - the_emmy@gmx.de - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -*/ - -/* - Changes: - 16.09.1999 Emmeran "Emmy" Seehuber - - Implementeted mapping of channels and pitches. - - Reworked option parsing, now using getopt(). - Note: The parameters of the programms have changed ! -*/ - -/* -** This program was in original by David G. Slomin. -** It was released to the Public Domain on 1/25/99. -*/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "midisend.h" -#include -#include -#include - -using namespace std; - -int input_fd = -1, test = 0, verbose = 0; -char cFileName[1025]; -int optch; -CMidiMap Map; - -void usage(char *prog) -{ - fprintf(stderr,"\n"); - fprintf(stderr,"Usage: %s [ -f ] [ -m ] [ -v ] [ -t ]\n",prog); - fprintf(stderr," -f the mididevice to read the input from.\n"); - fprintf(stderr," Default is /dev/midi. If you specify a dash, it is stdin\n"); - fprintf(stderr," -m the mapfile to load.\n"); - fprintf(stderr," -v verbose output.\n"); - fprintf(stderr," -t test mode. Generates a testoutput on the midibus\n"); - fprintf(stderr," -l long test mode. Generates a testoutput on the midibus\n"); - exit(1); -} - -void parseArgs(int argc, char** argv) -{ - // Setup default - strcpy(cFileName,"/dev/midi"); - - while((optch = getopt(argc,argv,"m:f:vtl")) > 0) - { - switch(optch) - { - case 'm': if( !Map.readMap(optarg) ) - fprintf(stderr,"%s: can't read file %s!\n",argv[0],optarg); - break; - case 't': test = 1; - break; - case 'l': test = 2; - break; -#ifdef VERSION - case 'v': verbose = 1; printf("MidiSend %s\n", VERSION ); - break; -#endif - case 'f': strncpy(cFileName,optarg,1024); - break; - default: usage(argv[0]); - break; - } - } -} - - -#ifdef COMMON_BINARY -int midisend_main(int argc, char *argv[]) -#else -int main(int argc, char *argv[]) -#endif -{ - Arts::Dispatcher dispatcher; - Arts::MidiManager manager = Arts::Reference("global:Arts_MidiManager"); - - if (manager.isNull()) - { - fprintf(stderr, "%s trouble: No midimanager object found; please start " - "artsd.\n",argv[0]); - exit(EXIT_FAILURE); - } - - /* - ** MIDI input initialization. - */ - - parseArgs(argc,argv); - - string title = string("midisend (") + cFileName +")"; - Arts::MidiClient client - = manager.addClient(Arts::mcdPlay,Arts::mctApplication,title,"midisend"); - Arts::MidiPort port = client.addOutputPort(); - - if(test) - { - if( verbose ) - printf("performing test ...\n"); - unsigned long i,max=5000; - if(test==2) max = 20000; - for(i=0;i Word begins here. - } - } - - // The word starts here - pszWord = pszLine; - - // And now, goto the end of the word. - bCont = true; - while(bCont) { - char cHelp = *pszLine; - switch( cHelp ) - { - case 0: - case ',': - case ';': - case ' ': - case '\n': - case '\r': - case '\t': *pszLine++ = 0; bCont = false; break; // Goto next char - default: pszLine++; break; - } - } - - return true; -} - -void CMidiMap::parseLine(char* pszLine, const char* pszConfigFile, int nConfigLine ) -{ - char* pszWord = 0; - bool bOk = true; - - // Get first word of the line - bOk = bOk && getNextWord(pszLine,pszWord); - if( !bOk ) - return; - - // Skip comments - if( *pszWord == '#' ) - return; - - if( strcmp(pszWord,"PRC") == 0 ) { - bOk = bOk && getNextWord(pszLine,pszWord); - int nOrigChannel = atol(pszWord); - bOk = bOk && getNextWord(pszLine,pszWord); - int nStart = atol(pszWord); - bOk = bOk && getNextWord(pszLine,pszWord); - int nEnd = atol(pszWord); - bOk = bOk && getNextWord(pszLine,pszWord); - int nChannel = atol(pszWord); - if( bOk ) { - channelMaps[nOrigChannel].nChannel = nOrigChannel; - for( int i = nStart; i <= nEnd; i++ ) { - channelMaps[nOrigChannel].channelRemaps[i].nPitch = i; - channelMaps[nOrigChannel].channelRemaps[i].nChannel = nChannel; - } - } - else { - printf("midisend: (PRC) missing parameters at %s:%d\n", pszConfigFile,nConfigLine); - } - return; - } - - if( strcmp(pszWord,"PRD") == 0 ) { - bOk = bOk && getNextWord(pszLine,pszWord); - int nOrigChannel = atol(pszWord); - bOk = bOk && getNextWord(pszLine,pszWord); - int nStart = atol(pszWord); - bOk = bOk && getNextWord(pszLine,pszWord); - int nEnd = atol(pszWord); - bOk = bOk && getNextWord(pszLine,pszWord); - int nPitchDiff = atol(pszWord); - if( bOk ) { - channelMaps[nOrigChannel].nChannel = nOrigChannel; - for( int i = nStart; i <= nEnd; i++ ) { - channelMaps[nOrigChannel].pitchRemaps[i].nPitch = i; - channelMaps[nOrigChannel].pitchRemaps[i].nToPitch = i + nPitchDiff; - } - } - else { - printf("midisend: (PRD) missing parameters at %s:%d\n", pszConfigFile,nConfigLine); - } - return; - } - - if( strcmp(pszWord,"PTC") == 0 ) { - bOk = bOk && getNextWord(pszLine,pszWord); - int nOrigChannel = atol(pszWord); - bOk = bOk && getNextWord(pszLine,pszWord); - int nPitch = atol(pszWord); - bOk = bOk && getNextWord(pszLine,pszWord); - int nToChannel = atol(pszWord); - if( bOk ) { - channelMaps[nOrigChannel].nChannel = nOrigChannel; - channelMaps[nOrigChannel].channelRemaps[nPitch].nPitch = nPitch; - channelMaps[nOrigChannel].channelRemaps[nPitch].nChannel = nToChannel; - } - else { - printf("midisend: (PTC) missing parameters at %s:%d\n", pszConfigFile,nConfigLine); - } - return; - } - - if( strcmp(pszWord,"PTP") == 0 ) { - bOk = bOk && getNextWord(pszLine,pszWord); - int nOrigChannel = atol(pszWord); - bOk = bOk && getNextWord(pszLine,pszWord); - int nPitch = atol(pszWord); - bOk = bOk && getNextWord(pszLine,pszWord); - int nToPitch = atol(pszWord); - if( bOk ) { - channelMaps[nOrigChannel].nChannel = nOrigChannel; - channelMaps[nOrigChannel].pitchRemaps[nPitch].nPitch = nPitch; - channelMaps[nOrigChannel].pitchRemaps[nPitch].nToPitch = nToPitch; - } - else { - printf("midisend: (PTP) missing parameters at %s:%d\n", pszConfigFile,nConfigLine); - } - return; - } - - printf("midisend: Unknown command at %s:%d\n", pszConfigFile,nConfigLine); -} - -void CMidiMap::mapMsg(Byte* msg) -{ - // Get out the data for mapping - int nChannel = midimsgGetChannel(msg); - int nPitch = midimsgGetPitch(msg); - - // Is there something to map for this channel ? - if( channelMaps.find(nChannel) != channelMaps.end() ) { - // => Yes, than do it. - - // C/P => C - if( channelMaps[nChannel].channelRemaps.find(nPitch) != channelMaps[nChannel].channelRemaps.end() ) - midimsgSetChannel(msg,channelMaps[nChannel].channelRemaps[nPitch].nChannel); - - // C/P => P - if( channelMaps[nChannel].pitchRemaps.find(nPitch) != channelMaps[nChannel].pitchRemaps.end() ) { - midimsgSetPitch(msg,channelMaps[nChannel].pitchRemaps[nPitch].nToPitch); - } - } -} diff --git a/arts/midi/midisend.cpp b/arts/midi/midisend.cpp new file mode 100644 index 00000000..2b976d61 --- /dev/null +++ b/arts/midi/midisend.cpp @@ -0,0 +1,375 @@ +/* + +Copyright (C) 1999 Emmeran Seehuber + the_emmy@gmx.de + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +/* + Changes: + 16.09.1999 Emmeran "Emmy" Seehuber + - Implementeted mapping of channels and pitches. + - Reworked option parsing, now using getopt(). + Note: The parameters of the programms have changed ! +*/ + +/* +** This program was in original by David G. Slomin. +** It was released to the Public Domain on 1/25/99. +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "midisend.h" +#include +#include +#include + +using namespace std; + +int input_fd = -1, test = 0, verbose = 0; +char cFileName[1025]; +int optch; +CMidiMap Map; + +void usage(char *prog) +{ + fprintf(stderr,"\n"); + fprintf(stderr,"Usage: %s [ -f ] [ -m ] [ -v ] [ -t ]\n",prog); + fprintf(stderr," -f the mididevice to read the input from.\n"); + fprintf(stderr," Default is /dev/midi. If you specify a dash, it is stdin\n"); + fprintf(stderr," -m the mapfile to load.\n"); + fprintf(stderr," -v verbose output.\n"); + fprintf(stderr," -t test mode. Generates a testoutput on the midibus\n"); + fprintf(stderr," -l long test mode. Generates a testoutput on the midibus\n"); + exit(1); +} + +void parseArgs(int argc, char** argv) +{ + // Setup default + strcpy(cFileName,"/dev/midi"); + + while((optch = getopt(argc,argv,"m:f:vtl")) > 0) + { + switch(optch) + { + case 'm': if( !Map.readMap(optarg) ) + fprintf(stderr,"%s: can't read file %s!\n",argv[0],optarg); + break; + case 't': test = 1; + break; + case 'l': test = 2; + break; +#ifdef VERSION + case 'v': verbose = 1; printf("MidiSend %s\n", VERSION ); + break; +#endif + case 'f': strncpy(cFileName,optarg,1024); + break; + default: usage(argv[0]); + break; + } + } +} + + +#ifdef COMMON_BINARY +int midisend_main(int argc, char *argv[]) +#else +int main(int argc, char *argv[]) +#endif +{ + Arts::Dispatcher dispatcher; + Arts::MidiManager manager = Arts::Reference("global:Arts_MidiManager"); + + if (manager.isNull()) + { + fprintf(stderr, "%s trouble: No midimanager object found; please start " + "artsd.\n",argv[0]); + exit(EXIT_FAILURE); + } + + /* + ** MIDI input initialization. + */ + + parseArgs(argc,argv); + + string title = string("midisend (") + cFileName +")"; + Arts::MidiClient client + = manager.addClient(Arts::mcdPlay,Arts::mctApplication,title,"midisend"); + Arts::MidiPort port = client.addOutputPort(); + + if(test) + { + if( verbose ) + printf("performing test ...\n"); + unsigned long i,max=5000; + if(test==2) max = 20000; + for(i=0;i Word begins here. + } + } + + // The word starts here + pszWord = pszLine; + + // And now, goto the end of the word. + bCont = true; + while(bCont) { + char cHelp = *pszLine; + switch( cHelp ) + { + case 0: + case ',': + case ';': + case ' ': + case '\n': + case '\r': + case '\t': *pszLine++ = 0; bCont = false; break; // Goto next char + default: pszLine++; break; + } + } + + return true; +} + +void CMidiMap::parseLine(char* pszLine, const char* pszConfigFile, int nConfigLine ) +{ + char* pszWord = 0; + bool bOk = true; + + // Get first word of the line + bOk = bOk && getNextWord(pszLine,pszWord); + if( !bOk ) + return; + + // Skip comments + if( *pszWord == '#' ) + return; + + if( strcmp(pszWord,"PRC") == 0 ) { + bOk = bOk && getNextWord(pszLine,pszWord); + int nOrigChannel = atol(pszWord); + bOk = bOk && getNextWord(pszLine,pszWord); + int nStart = atol(pszWord); + bOk = bOk && getNextWord(pszLine,pszWord); + int nEnd = atol(pszWord); + bOk = bOk && getNextWord(pszLine,pszWord); + int nChannel = atol(pszWord); + if( bOk ) { + channelMaps[nOrigChannel].nChannel = nOrigChannel; + for( int i = nStart; i <= nEnd; i++ ) { + channelMaps[nOrigChannel].channelRemaps[i].nPitch = i; + channelMaps[nOrigChannel].channelRemaps[i].nChannel = nChannel; + } + } + else { + printf("midisend: (PRC) missing parameters at %s:%d\n", pszConfigFile,nConfigLine); + } + return; + } + + if( strcmp(pszWord,"PRD") == 0 ) { + bOk = bOk && getNextWord(pszLine,pszWord); + int nOrigChannel = atol(pszWord); + bOk = bOk && getNextWord(pszLine,pszWord); + int nStart = atol(pszWord); + bOk = bOk && getNextWord(pszLine,pszWord); + int nEnd = atol(pszWord); + bOk = bOk && getNextWord(pszLine,pszWord); + int nPitchDiff = atol(pszWord); + if( bOk ) { + channelMaps[nOrigChannel].nChannel = nOrigChannel; + for( int i = nStart; i <= nEnd; i++ ) { + channelMaps[nOrigChannel].pitchRemaps[i].nPitch = i; + channelMaps[nOrigChannel].pitchRemaps[i].nToPitch = i + nPitchDiff; + } + } + else { + printf("midisend: (PRD) missing parameters at %s:%d\n", pszConfigFile,nConfigLine); + } + return; + } + + if( strcmp(pszWord,"PTC") == 0 ) { + bOk = bOk && getNextWord(pszLine,pszWord); + int nOrigChannel = atol(pszWord); + bOk = bOk && getNextWord(pszLine,pszWord); + int nPitch = atol(pszWord); + bOk = bOk && getNextWord(pszLine,pszWord); + int nToChannel = atol(pszWord); + if( bOk ) { + channelMaps[nOrigChannel].nChannel = nOrigChannel; + channelMaps[nOrigChannel].channelRemaps[nPitch].nPitch = nPitch; + channelMaps[nOrigChannel].channelRemaps[nPitch].nChannel = nToChannel; + } + else { + printf("midisend: (PTC) missing parameters at %s:%d\n", pszConfigFile,nConfigLine); + } + return; + } + + if( strcmp(pszWord,"PTP") == 0 ) { + bOk = bOk && getNextWord(pszLine,pszWord); + int nOrigChannel = atol(pszWord); + bOk = bOk && getNextWord(pszLine,pszWord); + int nPitch = atol(pszWord); + bOk = bOk && getNextWord(pszLine,pszWord); + int nToPitch = atol(pszWord); + if( bOk ) { + channelMaps[nOrigChannel].nChannel = nOrigChannel; + channelMaps[nOrigChannel].pitchRemaps[nPitch].nPitch = nPitch; + channelMaps[nOrigChannel].pitchRemaps[nPitch].nToPitch = nToPitch; + } + else { + printf("midisend: (PTP) missing parameters at %s:%d\n", pszConfigFile,nConfigLine); + } + return; + } + + printf("midisend: Unknown command at %s:%d\n", pszConfigFile,nConfigLine); +} + +void CMidiMap::mapMsg(Byte* msg) +{ + // Get out the data for mapping + int nChannel = midimsgGetChannel(msg); + int nPitch = midimsgGetPitch(msg); + + // Is there something to map for this channel ? + if( channelMaps.find(nChannel) != channelMaps.end() ) { + // => Yes, than do it. + + // C/P => C + if( channelMaps[nChannel].channelRemaps.find(nPitch) != channelMaps[nChannel].channelRemaps.end() ) + midimsgSetChannel(msg,channelMaps[nChannel].channelRemaps[nPitch].nChannel); + + // C/P => P + if( channelMaps[nChannel].pitchRemaps.find(nPitch) != channelMaps[nChannel].pitchRemaps.end() ) { + midimsgSetPitch(msg,channelMaps[nChannel].pitchRemaps[nPitch].nToPitch); + } + } +} diff --git a/arts/midi/midisyncgroup_impl.cc b/arts/midi/midisyncgroup_impl.cc deleted file mode 100644 index 5d5305dd..00000000 --- a/arts/midi/midisyncgroup_impl.cc +++ /dev/null @@ -1,125 +0,0 @@ - /* - - Copyright (C) 2002 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "midisyncgroup_impl.h" -#include "audiosync_impl.h" -#include "midiclient_impl.h" -#include "midimanager_impl.h" -#include "timestampmath.h" - -using namespace Arts; -using namespace std; - -MidiSyncGroup_impl::MidiSyncGroup_impl(MidiManager_impl *manager) - : manager(manager) -{ -} - -MidiSyncGroup_impl::~MidiSyncGroup_impl() -{ - /* tell clients we're dead */ - list::iterator i; - for(i = clients.begin(); i != clients.end(); i++) - (*i)->setSyncGroup(0); - - list::iterator ai; - for(ai = audioSyncs.begin(); ai != audioSyncs.end(); ai++) - (*ai)->setSyncGroup(0); - - manager->removeSyncGroup(this); -} - -void MidiSyncGroup_impl::addClient(MidiClient client) -{ - /* add client to list */ - MidiClient_impl *impl = manager->findClient(client.info().ID); - impl->setSyncGroup(this); - clients.push_back(impl); - - impl->synchronizeTo(masterTimer.time()); -} - -void MidiSyncGroup_impl::removeClient(MidiClient client) -{ - /* remove client from the list */ - MidiClient_impl *impl = manager->findClient(client.info().ID); - impl->setSyncGroup(0); - clients.remove(impl); -} - -void MidiSyncGroup_impl::addAudioSync(AudioSync audioSync) -{ - AudioSync_impl *impl = AudioSync_impl::find(audioSync); - impl->setSyncGroup(this); - audioSyncs.push_back(impl); - - impl->synchronizeTo(masterTimer.time()); -} - -void MidiSyncGroup_impl::removeAudioSync(AudioSync audioSync) -{ - AudioSync_impl *impl = AudioSync_impl::find(audioSync); - impl->setSyncGroup(0); - audioSyncs.remove(impl); -} - -void MidiSyncGroup_impl::clientChanged(MidiClient_impl *client) -{ - client->synchronizeTo(masterTimer.time()); -} - -void MidiSyncGroup_impl::clientDied(MidiClient_impl *client) -{ - clients.remove(client); -} - -void MidiSyncGroup_impl::audioSyncDied(AudioSync_impl *audioSync) -{ - audioSyncs.remove(audioSync); -} - -TimeStamp MidiSyncGroup_impl::time() -{ - TimeStamp result = masterTimer.time(); - - list::iterator i; - for(i = clients.begin(); i != clients.end(); i++) - result = timeStampMax(result, (*i)->clientTime()); - - list::iterator ai; - for(ai = audioSyncs.begin(); ai != audioSyncs.end(); ai++) - result = timeStampMax(result, (*ai)->clientTime()); - - return result; -} - -TimeStamp MidiSyncGroup_impl::playTime() -{ - return masterTimer.time(); -} - -void MidiSyncGroup_impl::adjustSync() -{ - list::iterator ai; - for(ai = audioSyncs.begin(); ai != audioSyncs.end(); ai++) - (*ai)->synchronizeTo(masterTimer.time()); -} diff --git a/arts/midi/midisyncgroup_impl.cpp b/arts/midi/midisyncgroup_impl.cpp new file mode 100644 index 00000000..5d5305dd --- /dev/null +++ b/arts/midi/midisyncgroup_impl.cpp @@ -0,0 +1,125 @@ + /* + + Copyright (C) 2002 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "midisyncgroup_impl.h" +#include "audiosync_impl.h" +#include "midiclient_impl.h" +#include "midimanager_impl.h" +#include "timestampmath.h" + +using namespace Arts; +using namespace std; + +MidiSyncGroup_impl::MidiSyncGroup_impl(MidiManager_impl *manager) + : manager(manager) +{ +} + +MidiSyncGroup_impl::~MidiSyncGroup_impl() +{ + /* tell clients we're dead */ + list::iterator i; + for(i = clients.begin(); i != clients.end(); i++) + (*i)->setSyncGroup(0); + + list::iterator ai; + for(ai = audioSyncs.begin(); ai != audioSyncs.end(); ai++) + (*ai)->setSyncGroup(0); + + manager->removeSyncGroup(this); +} + +void MidiSyncGroup_impl::addClient(MidiClient client) +{ + /* add client to list */ + MidiClient_impl *impl = manager->findClient(client.info().ID); + impl->setSyncGroup(this); + clients.push_back(impl); + + impl->synchronizeTo(masterTimer.time()); +} + +void MidiSyncGroup_impl::removeClient(MidiClient client) +{ + /* remove client from the list */ + MidiClient_impl *impl = manager->findClient(client.info().ID); + impl->setSyncGroup(0); + clients.remove(impl); +} + +void MidiSyncGroup_impl::addAudioSync(AudioSync audioSync) +{ + AudioSync_impl *impl = AudioSync_impl::find(audioSync); + impl->setSyncGroup(this); + audioSyncs.push_back(impl); + + impl->synchronizeTo(masterTimer.time()); +} + +void MidiSyncGroup_impl::removeAudioSync(AudioSync audioSync) +{ + AudioSync_impl *impl = AudioSync_impl::find(audioSync); + impl->setSyncGroup(0); + audioSyncs.remove(impl); +} + +void MidiSyncGroup_impl::clientChanged(MidiClient_impl *client) +{ + client->synchronizeTo(masterTimer.time()); +} + +void MidiSyncGroup_impl::clientDied(MidiClient_impl *client) +{ + clients.remove(client); +} + +void MidiSyncGroup_impl::audioSyncDied(AudioSync_impl *audioSync) +{ + audioSyncs.remove(audioSync); +} + +TimeStamp MidiSyncGroup_impl::time() +{ + TimeStamp result = masterTimer.time(); + + list::iterator i; + for(i = clients.begin(); i != clients.end(); i++) + result = timeStampMax(result, (*i)->clientTime()); + + list::iterator ai; + for(ai = audioSyncs.begin(); ai != audioSyncs.end(); ai++) + result = timeStampMax(result, (*ai)->clientTime()); + + return result; +} + +TimeStamp MidiSyncGroup_impl::playTime() +{ + return masterTimer.time(); +} + +void MidiSyncGroup_impl::adjustSync() +{ + list::iterator ai; + for(ai = audioSyncs.begin(); ai != audioSyncs.end(); ai++) + (*ai)->synchronizeTo(masterTimer.time()); +} diff --git a/arts/midi/midisynctest.cc b/arts/midi/midisynctest.cc deleted file mode 100644 index e1278f1b..00000000 --- a/arts/midi/midisynctest.cc +++ /dev/null @@ -1,137 +0,0 @@ - /* - - Copyright (C) 2002 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "config.h" -#include "artsmidi.h" -#include "soundserver.h" -#include "timestampmath.h" -#include "debug.h" -#include -#include - -using namespace Arts; -using namespace std; - -int main() -{ - Dispatcher dispatcher; - - MidiManager midiManager = DynamicCast(Reference("global:Arts_MidiManager")); - if(midiManager.isNull()) - arts_fatal("midimanager is null"); - - SoundServer soundServer = DynamicCast(Reference("global:Arts_SoundServer")); - if(soundServer.isNull()) - arts_fatal("soundServer is null"); - - MidiSyncGroup syncGroup = midiManager.addSyncGroup(); - MidiClient client = midiManager.addClient(mcdPlay, mctApplication, "midisynctest", "midisynctest"); - syncGroup.addClient(client); - - MidiPort port = client.addOutputPort(); - - MidiClient client2 = midiManager.addClient(mcdPlay, mctApplication, "midisynctest2", "midisynctest2"); - - syncGroup.addClient(client2); - - MidiPort port2 = client2.addOutputPort(); - - /* setup audio synchronization */ - AudioSync audioSync; - audioSync = DynamicCast(soundServer.createObject("Arts::AudioSync")); - if(audioSync.isNull()) - arts_fatal("audioSync is null"); - - syncGroup.addAudioSync(audioSync); - - const int C = 60; - const int D = 62; - const int E = 64; - const int F = 65, f = F - 12; - const int G = 67, g = G - 12; - const int A = 69, a = A - 12; - const int H = 71, h = H - 12; - int np = 0; - int notes[] = { C,E,G,E,a,C,E,C,f,a,C,a,g,h,D,h,0 }; - - printf("connect port1 and port2 to two different ports in the artscontrol midi manager,\n" - "hit return"); - getchar(); - - TimeStamp t = port.time(); - timeStampInc(t,TimeStamp(0,100000)); - for(;;) - { - Synth_PLAY_WAV wav; - Synth_AMAN_PLAY sap; - - MidiEvent e; - - e = MidiEvent(t,MidiCommand(mcsNoteOn|0, notes[np], 100)); - - port.processEvent(e); - port2.processEvent(e); - - if((np & 1) == 0) - { - /* setup wave player */ - wav = DynamicCast(soundServer.createObject("Arts::Synth_PLAY_WAV")); - if(wav.isNull()) - arts_fatal("can't create Arts::Synth_PLAY_WAV"); - - sap = DynamicCast(soundServer.createObject("Arts::Synth_AMAN_PLAY")); - if(sap.isNull()) - arts_fatal("can't create Arts::Synth_AMAN_PLAY"); - - wav.filename("/opt/trinity/share/sounds/pop.wav"); - sap.title("midisynctest2"); - sap.autoRestoreID("midisynctest2"); - connect(wav,sap); - - audioSync.queueStart(wav); - audioSync.queueStart(sap); - audioSync.executeAt(t); - } - - timeStampInc(t,TimeStamp(0,100000)); - - e = MidiEvent(t,MidiCommand(mcsNoteOff|0, notes[np], 100)); - - port.processEvent(e); - port2.processEvent(e); - - if((np & 1) == 0) - { - audioSync.queueStop(wav); - audioSync.queueStop(sap); - audioSync.executeAt(t); - } - - timeStampInc(t,TimeStamp(0,400000)); - - while(port.time().sec < (t.sec - 2)) - usleep(100000); - - np++; - if(notes[np] == 0) np = 0; - } -} diff --git a/arts/midi/midisynctest.cpp b/arts/midi/midisynctest.cpp new file mode 100644 index 00000000..e1278f1b --- /dev/null +++ b/arts/midi/midisynctest.cpp @@ -0,0 +1,137 @@ + /* + + Copyright (C) 2002 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "config.h" +#include "artsmidi.h" +#include "soundserver.h" +#include "timestampmath.h" +#include "debug.h" +#include +#include + +using namespace Arts; +using namespace std; + +int main() +{ + Dispatcher dispatcher; + + MidiManager midiManager = DynamicCast(Reference("global:Arts_MidiManager")); + if(midiManager.isNull()) + arts_fatal("midimanager is null"); + + SoundServer soundServer = DynamicCast(Reference("global:Arts_SoundServer")); + if(soundServer.isNull()) + arts_fatal("soundServer is null"); + + MidiSyncGroup syncGroup = midiManager.addSyncGroup(); + MidiClient client = midiManager.addClient(mcdPlay, mctApplication, "midisynctest", "midisynctest"); + syncGroup.addClient(client); + + MidiPort port = client.addOutputPort(); + + MidiClient client2 = midiManager.addClient(mcdPlay, mctApplication, "midisynctest2", "midisynctest2"); + + syncGroup.addClient(client2); + + MidiPort port2 = client2.addOutputPort(); + + /* setup audio synchronization */ + AudioSync audioSync; + audioSync = DynamicCast(soundServer.createObject("Arts::AudioSync")); + if(audioSync.isNull()) + arts_fatal("audioSync is null"); + + syncGroup.addAudioSync(audioSync); + + const int C = 60; + const int D = 62; + const int E = 64; + const int F = 65, f = F - 12; + const int G = 67, g = G - 12; + const int A = 69, a = A - 12; + const int H = 71, h = H - 12; + int np = 0; + int notes[] = { C,E,G,E,a,C,E,C,f,a,C,a,g,h,D,h,0 }; + + printf("connect port1 and port2 to two different ports in the artscontrol midi manager,\n" + "hit return"); + getchar(); + + TimeStamp t = port.time(); + timeStampInc(t,TimeStamp(0,100000)); + for(;;) + { + Synth_PLAY_WAV wav; + Synth_AMAN_PLAY sap; + + MidiEvent e; + + e = MidiEvent(t,MidiCommand(mcsNoteOn|0, notes[np], 100)); + + port.processEvent(e); + port2.processEvent(e); + + if((np & 1) == 0) + { + /* setup wave player */ + wav = DynamicCast(soundServer.createObject("Arts::Synth_PLAY_WAV")); + if(wav.isNull()) + arts_fatal("can't create Arts::Synth_PLAY_WAV"); + + sap = DynamicCast(soundServer.createObject("Arts::Synth_AMAN_PLAY")); + if(sap.isNull()) + arts_fatal("can't create Arts::Synth_AMAN_PLAY"); + + wav.filename("/opt/trinity/share/sounds/pop.wav"); + sap.title("midisynctest2"); + sap.autoRestoreID("midisynctest2"); + connect(wav,sap); + + audioSync.queueStart(wav); + audioSync.queueStart(sap); + audioSync.executeAt(t); + } + + timeStampInc(t,TimeStamp(0,100000)); + + e = MidiEvent(t,MidiCommand(mcsNoteOff|0, notes[np], 100)); + + port.processEvent(e); + port2.processEvent(e); + + if((np & 1) == 0) + { + audioSync.queueStop(wav); + audioSync.queueStop(sap); + audioSync.executeAt(t); + } + + timeStampInc(t,TimeStamp(0,400000)); + + while(port.time().sec < (t.sec - 2)) + usleep(100000); + + np++; + if(notes[np] == 0) np = 0; + } +} diff --git a/arts/midi/miditest_impl.cc b/arts/midi/miditest_impl.cc deleted file mode 100644 index b6ecce90..00000000 --- a/arts/midi/miditest_impl.cc +++ /dev/null @@ -1,57 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "midimanager_impl.h" -#include - -namespace Arts { - -class MidiTest_impl : virtual public MidiTest_skel { -public: - Arts::TimeStamp time() - { - return TimeStamp(0,0); - } - Arts::TimeStamp playTime() - { - return time(); - } - void processCommand(const MidiCommand& command) - { - if((command.status & mcsCommandMask) == mcsNoteOn) - { - mcopbyte ch = command.status & mcsChannelMask; - - printf("noteon ch = %d, note = %d, vel = %d\n", - ch,command.data1,command.data2); - } - } - void processEvent(const MidiEvent& event) - { - printf("At %ld.%06ld: ",event.time.sec,event.time.usec); - processCommand(event.command); - } -}; - -REGISTER_IMPLEMENTATION(MidiTest_impl); -} - diff --git a/arts/midi/miditest_impl.cpp b/arts/midi/miditest_impl.cpp new file mode 100644 index 00000000..b6ecce90 --- /dev/null +++ b/arts/midi/miditest_impl.cpp @@ -0,0 +1,57 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "midimanager_impl.h" +#include + +namespace Arts { + +class MidiTest_impl : virtual public MidiTest_skel { +public: + Arts::TimeStamp time() + { + return TimeStamp(0,0); + } + Arts::TimeStamp playTime() + { + return time(); + } + void processCommand(const MidiCommand& command) + { + if((command.status & mcsCommandMask) == mcsNoteOn) + { + mcopbyte ch = command.status & mcsChannelMask; + + printf("noteon ch = %d, note = %d, vel = %d\n", + ch,command.data1,command.data2); + } + } + void processEvent(const MidiEvent& event) + { + printf("At %ld.%06ld: ",event.time.sec,event.time.usec); + processCommand(event.command); + } +}; + +REGISTER_IMPLEMENTATION(MidiTest_impl); +} + diff --git a/arts/midi/miditimercommon.cc b/arts/midi/miditimercommon.cc deleted file mode 100644 index 69597b32..00000000 --- a/arts/midi/miditimercommon.cc +++ /dev/null @@ -1,72 +0,0 @@ - /* - - Copyright (C) 2001 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "artsmidi.h" -#include "debug.h" -#include "miditimercommon.h" -#include "math.h" - -#undef DEBUG_JITTER - -using namespace std; -using namespace Arts; - -MidiTimerCommon::MidiTimerCommon() :refCount(0) -{ - refCount = 0; -} - -MidiTimerCommon::~MidiTimerCommon() -{ - arts_assert(refCount == 0); -} - -void MidiTimerCommon::processQueue() -{ - TimeStamp now = time(); - - list::iterator n = noteQueue.begin(); - while(n != noteQueue.end()) - { - TSNote& note = *n; - TimeStamp& noteTime = note.event.time; - - if( now.sec > noteTime.sec - || ((now.sec == noteTime.sec) && (now.usec > noteTime.usec))) - { -#ifdef DEBUG_JITTER - float jitter = (now.sec-noteTime.sec) * 1000.0; - jitter += (float)(now.usec-noteTime.usec) / 1000.0; - arts_debug("midi jitter: %f",jitter); -#endif - - note.port.processCommand(note.event.command); - n = noteQueue.erase(n); - } - else n++; - } -} - -void MidiTimerCommon::queueEvent(MidiPort port,const MidiEvent& event) -{ - noteQueue.push_back(TSNote(port, event)); -} diff --git a/arts/midi/miditimercommon.cpp b/arts/midi/miditimercommon.cpp new file mode 100644 index 00000000..69597b32 --- /dev/null +++ b/arts/midi/miditimercommon.cpp @@ -0,0 +1,72 @@ + /* + + Copyright (C) 2001 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "artsmidi.h" +#include "debug.h" +#include "miditimercommon.h" +#include "math.h" + +#undef DEBUG_JITTER + +using namespace std; +using namespace Arts; + +MidiTimerCommon::MidiTimerCommon() :refCount(0) +{ + refCount = 0; +} + +MidiTimerCommon::~MidiTimerCommon() +{ + arts_assert(refCount == 0); +} + +void MidiTimerCommon::processQueue() +{ + TimeStamp now = time(); + + list::iterator n = noteQueue.begin(); + while(n != noteQueue.end()) + { + TSNote& note = *n; + TimeStamp& noteTime = note.event.time; + + if( now.sec > noteTime.sec + || ((now.sec == noteTime.sec) && (now.usec > noteTime.usec))) + { +#ifdef DEBUG_JITTER + float jitter = (now.sec-noteTime.sec) * 1000.0; + jitter += (float)(now.usec-noteTime.usec) / 1000.0; + arts_debug("midi jitter: %f",jitter); +#endif + + note.port.processCommand(note.event.command); + n = noteQueue.erase(n); + } + else n++; + } +} + +void MidiTimerCommon::queueEvent(MidiPort port,const MidiEvent& event) +{ + noteQueue.push_back(TSNote(port, event)); +} diff --git a/arts/midi/rawmidiport_impl.cc b/arts/midi/rawmidiport_impl.cc deleted file mode 100644 index f8311bd6..00000000 --- a/arts/midi/rawmidiport_impl.cc +++ /dev/null @@ -1,306 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "artsmidi.h" -#include -#include -#include - -using namespace std; - -namespace Arts { - -class RawMidiPort_impl : virtual public RawMidiPort_skel, - virtual public IONotify -{ -protected: - int fd; - - string _device; - bool _input, _output; - bool _running; - mcopbyte laststatus; - queue inq; - MidiClient clientRecord, clientPlay; - MidiPort outputPort; - MidiManager manager; - - RawMidiPort self() { - return RawMidiPort::_from_base(_copy()); - } - SystemMidiTimer timer; - -public: - RawMidiPort_impl() - :_device("/dev/midi"), _input(true), _output(true), _running(false), - clientRecord(MidiClient::null()), clientPlay(MidiClient::null()), - outputPort(MidiPort::null()), - manager(Reference("global:Arts_MidiManager")) - { - } - Arts::TimeStamp time() - { - return timer.time(); - } - Arts::TimeStamp playTime() - { - return timer.time(); - } - - // attribute string running; - bool running() { return _running; } - void running(bool newrunning) { - if(_running == newrunning) return; - - if(newrunning) - open(); - else - close(); - - running_changed(_running); - } - - // attribute string device; - void device(const string& newdevice) - { - if(newdevice == _device) return; - - if(_running) - { - close(); - _device = newdevice; - open(); - } - else _device = newdevice; - - device_changed(newdevice); - } - string device() { return _device; } - - // attribute boolean input; - void input(bool newinput) - { - if(newinput == _input) return; - - if(_running) - { - close(); - _input = newinput; - open(); - } - else _input = newinput; - - input_changed(newinput); - } - bool input() { return _input; } - - // attribute boolean output; - void output(bool newoutput) - { - if(newoutput == _output) return; - - if(_running) - { - close(); - _output = newoutput; - open(); - } - else _output = newoutput; - - output_changed(newoutput); - } - bool output() { return _output; } - - bool open() { - arts_return_val_if_fail(_running == false, true); - arts_return_val_if_fail(_output || _input, false); - arts_return_val_if_fail(manager.isNull() == false, false); - laststatus = 0; - - int mode = O_NDELAY; - if(_input) - { - if(_output) - mode |= O_RDWR; - else - mode |= O_RDONLY; - } - else mode |= O_WRONLY; - - fd = ::open(_device.c_str(),mode); - if(fd != -1) - { - IOManager *iom = Dispatcher::the()->ioManager(); - if(_output) - iom->watchFD(fd,IOType::read,this); - - string name = "OSS Midi Port ("+_device+")"; - if(_input) - { - clientRecord = - manager.addClient(mcdRecord,mctDestination,name,name); - clientRecord.addInputPort(self()); - } - if(_output) - { - clientPlay = - manager.addClient(mcdPlay,mctDestination,name,name); - outputPort = clientPlay.addOutputPort(); - } - - _running = true; - running_changed(true); - } - return _running; - } - - void close() - { - arts_return_if_fail(_running == true); - - if(_input) - { - clientRecord.removePort(self()); - clientRecord = MidiClient::null(); - } - if(_output) - { - clientPlay.removePort(outputPort); - clientPlay = MidiClient::null(); - } - - Dispatcher::the()->ioManager()->remove(this,IOType::all); - ::close(fd); - } - - int midiMsgLen(mcopbyte status) - { - switch(status & mcsCommandMask) - { - case mcsNoteOn: - case mcsNoteOff: - case mcsKeyPressure: - case mcsParameter: - case mcsPitchWheel: - return 3; - break; - case mcsProgram: - case mcsChannelPressure: - return 2; - break; - } - return 0; - } - void notifyIO(int fd, int type) - { - arts_return_if_fail(_running); - assert(fd == this->fd); - - // convert iomanager notification types to audiosubsys notification - if(type & IOType::read) - { - mcopbyte buffer[1024]; - int count = read(fd,buffer,1024); - for(int i=0; i read something - * away and hope we'll find a status byte */ - inq.pop(); - } - } - } - void processCommand(const MidiCommand& command) - { - unsigned char message[3] = { command.status, command.data1, command.data2 }; - - int len = midiMsgLen(command.status); - if(midiMsgLen(command.status)) - write(fd, message, len); - } - void processEvent(const MidiEvent& event) - { - timer.queueEvent(self(), event); - } -}; - -REGISTER_IMPLEMENTATION(RawMidiPort_impl); -} - diff --git a/arts/midi/rawmidiport_impl.cpp b/arts/midi/rawmidiport_impl.cpp new file mode 100644 index 00000000..f8311bd6 --- /dev/null +++ b/arts/midi/rawmidiport_impl.cpp @@ -0,0 +1,306 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "artsmidi.h" +#include +#include +#include + +using namespace std; + +namespace Arts { + +class RawMidiPort_impl : virtual public RawMidiPort_skel, + virtual public IONotify +{ +protected: + int fd; + + string _device; + bool _input, _output; + bool _running; + mcopbyte laststatus; + queue inq; + MidiClient clientRecord, clientPlay; + MidiPort outputPort; + MidiManager manager; + + RawMidiPort self() { + return RawMidiPort::_from_base(_copy()); + } + SystemMidiTimer timer; + +public: + RawMidiPort_impl() + :_device("/dev/midi"), _input(true), _output(true), _running(false), + clientRecord(MidiClient::null()), clientPlay(MidiClient::null()), + outputPort(MidiPort::null()), + manager(Reference("global:Arts_MidiManager")) + { + } + Arts::TimeStamp time() + { + return timer.time(); + } + Arts::TimeStamp playTime() + { + return timer.time(); + } + + // attribute string running; + bool running() { return _running; } + void running(bool newrunning) { + if(_running == newrunning) return; + + if(newrunning) + open(); + else + close(); + + running_changed(_running); + } + + // attribute string device; + void device(const string& newdevice) + { + if(newdevice == _device) return; + + if(_running) + { + close(); + _device = newdevice; + open(); + } + else _device = newdevice; + + device_changed(newdevice); + } + string device() { return _device; } + + // attribute boolean input; + void input(bool newinput) + { + if(newinput == _input) return; + + if(_running) + { + close(); + _input = newinput; + open(); + } + else _input = newinput; + + input_changed(newinput); + } + bool input() { return _input; } + + // attribute boolean output; + void output(bool newoutput) + { + if(newoutput == _output) return; + + if(_running) + { + close(); + _output = newoutput; + open(); + } + else _output = newoutput; + + output_changed(newoutput); + } + bool output() { return _output; } + + bool open() { + arts_return_val_if_fail(_running == false, true); + arts_return_val_if_fail(_output || _input, false); + arts_return_val_if_fail(manager.isNull() == false, false); + laststatus = 0; + + int mode = O_NDELAY; + if(_input) + { + if(_output) + mode |= O_RDWR; + else + mode |= O_RDONLY; + } + else mode |= O_WRONLY; + + fd = ::open(_device.c_str(),mode); + if(fd != -1) + { + IOManager *iom = Dispatcher::the()->ioManager(); + if(_output) + iom->watchFD(fd,IOType::read,this); + + string name = "OSS Midi Port ("+_device+")"; + if(_input) + { + clientRecord = + manager.addClient(mcdRecord,mctDestination,name,name); + clientRecord.addInputPort(self()); + } + if(_output) + { + clientPlay = + manager.addClient(mcdPlay,mctDestination,name,name); + outputPort = clientPlay.addOutputPort(); + } + + _running = true; + running_changed(true); + } + return _running; + } + + void close() + { + arts_return_if_fail(_running == true); + + if(_input) + { + clientRecord.removePort(self()); + clientRecord = MidiClient::null(); + } + if(_output) + { + clientPlay.removePort(outputPort); + clientPlay = MidiClient::null(); + } + + Dispatcher::the()->ioManager()->remove(this,IOType::all); + ::close(fd); + } + + int midiMsgLen(mcopbyte status) + { + switch(status & mcsCommandMask) + { + case mcsNoteOn: + case mcsNoteOff: + case mcsKeyPressure: + case mcsParameter: + case mcsPitchWheel: + return 3; + break; + case mcsProgram: + case mcsChannelPressure: + return 2; + break; + } + return 0; + } + void notifyIO(int fd, int type) + { + arts_return_if_fail(_running); + assert(fd == this->fd); + + // convert iomanager notification types to audiosubsys notification + if(type & IOType::read) + { + mcopbyte buffer[1024]; + int count = read(fd,buffer,1024); + for(int i=0; i read something + * away and hope we'll find a status byte */ + inq.pop(); + } + } + } + void processCommand(const MidiCommand& command) + { + unsigned char message[3] = { command.status, command.data1, command.data2 }; + + int len = midiMsgLen(command.status); + if(midiMsgLen(command.status)) + write(fd, message, len); + } + void processEvent(const MidiEvent& event) + { + timer.queueEvent(self(), event); + } +}; + +REGISTER_IMPLEMENTATION(RawMidiPort_impl); +} + diff --git a/arts/midi/systemmiditimer_impl.cc b/arts/midi/systemmiditimer_impl.cc deleted file mode 100644 index 4f7329b2..00000000 --- a/arts/midi/systemmiditimer_impl.cc +++ /dev/null @@ -1,105 +0,0 @@ - /* - - Copyright (C) 2001 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "artsmidi.h" -#include "debug.h" -#include "miditimercommon.h" - -using namespace std; -using namespace Arts; - -namespace Arts { - -class SystemMidiTimerCommon : public MidiTimerCommon, - public TimeNotify { -protected: - SystemMidiTimerCommon(); - virtual ~SystemMidiTimerCommon(); - -public: - // allocation: share one SystemMidiTimerCommon for everbody who needs one - static SystemMidiTimerCommon *subscribe(); - - void notifyTime(); - TimeStamp time(); -}; - -} - -static SystemMidiTimerCommon *SystemMidiTimerCommon_the = 0; - -SystemMidiTimerCommon::SystemMidiTimerCommon() -{ - SystemMidiTimerCommon_the = this; - Dispatcher::the()->ioManager()->addTimer(10, this); -} - -SystemMidiTimerCommon::~SystemMidiTimerCommon() -{ - Dispatcher::the()->ioManager()->removeTimer(this); - SystemMidiTimerCommon_the = 0; -} - -TimeStamp SystemMidiTimerCommon::time() -{ - timeval tv; - gettimeofday(&tv,0); - return TimeStamp(tv.tv_sec, tv.tv_usec); -} - -void SystemMidiTimerCommon::notifyTime() -{ - processQueue(); -} - -SystemMidiTimerCommon *SystemMidiTimerCommon::subscribe() -{ - if(!SystemMidiTimerCommon_the) new SystemMidiTimerCommon(); - SystemMidiTimerCommon_the->refCount++; - return SystemMidiTimerCommon_the; -} - -class SystemMidiTimer_impl : public SystemMidiTimer_skel { -protected: - SystemMidiTimerCommon *timer; -public: - SystemMidiTimer_impl() - { - timer = SystemMidiTimerCommon::subscribe(); - } - ~SystemMidiTimer_impl() - { - timer->unsubscribe(); - } - TimeStamp time() - { - return timer->time(); - } - void queueEvent(MidiPort port, const MidiEvent& event) - { - timer->queueEvent(port, event); - } -}; - -namespace Arts { - REGISTER_IMPLEMENTATION(SystemMidiTimer_impl); -} diff --git a/arts/midi/systemmiditimer_impl.cpp b/arts/midi/systemmiditimer_impl.cpp new file mode 100644 index 00000000..4f7329b2 --- /dev/null +++ b/arts/midi/systemmiditimer_impl.cpp @@ -0,0 +1,105 @@ + /* + + Copyright (C) 2001 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "artsmidi.h" +#include "debug.h" +#include "miditimercommon.h" + +using namespace std; +using namespace Arts; + +namespace Arts { + +class SystemMidiTimerCommon : public MidiTimerCommon, + public TimeNotify { +protected: + SystemMidiTimerCommon(); + virtual ~SystemMidiTimerCommon(); + +public: + // allocation: share one SystemMidiTimerCommon for everbody who needs one + static SystemMidiTimerCommon *subscribe(); + + void notifyTime(); + TimeStamp time(); +}; + +} + +static SystemMidiTimerCommon *SystemMidiTimerCommon_the = 0; + +SystemMidiTimerCommon::SystemMidiTimerCommon() +{ + SystemMidiTimerCommon_the = this; + Dispatcher::the()->ioManager()->addTimer(10, this); +} + +SystemMidiTimerCommon::~SystemMidiTimerCommon() +{ + Dispatcher::the()->ioManager()->removeTimer(this); + SystemMidiTimerCommon_the = 0; +} + +TimeStamp SystemMidiTimerCommon::time() +{ + timeval tv; + gettimeofday(&tv,0); + return TimeStamp(tv.tv_sec, tv.tv_usec); +} + +void SystemMidiTimerCommon::notifyTime() +{ + processQueue(); +} + +SystemMidiTimerCommon *SystemMidiTimerCommon::subscribe() +{ + if(!SystemMidiTimerCommon_the) new SystemMidiTimerCommon(); + SystemMidiTimerCommon_the->refCount++; + return SystemMidiTimerCommon_the; +} + +class SystemMidiTimer_impl : public SystemMidiTimer_skel { +protected: + SystemMidiTimerCommon *timer; +public: + SystemMidiTimer_impl() + { + timer = SystemMidiTimerCommon::subscribe(); + } + ~SystemMidiTimer_impl() + { + timer->unsubscribe(); + } + TimeStamp time() + { + return timer->time(); + } + void queueEvent(MidiPort port, const MidiEvent& event) + { + timer->queueEvent(port, event); + } +}; + +namespace Arts { + REGISTER_IMPLEMENTATION(SystemMidiTimer_impl); +} diff --git a/arts/midi/timestampmath.cc b/arts/midi/timestampmath.cc deleted file mode 100644 index e8d5500a..00000000 --- a/arts/midi/timestampmath.cc +++ /dev/null @@ -1,112 +0,0 @@ - /* - - Copyright (C) 2002 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "timestampmath.h" -#include -#include - -using namespace std; - -namespace Arts { -void timeStampInc(TimeStamp& t, const TimeStamp& delta) -{ - /* expect a normalized t, delta */ - arts_return_if_fail(t.usec >= 0 && t.usec < 1000000); - arts_return_if_fail(delta.usec >= 0 && delta.usec < 1000000); - - t.sec += delta.sec; - t.usec += delta.usec; - - if (t.usec >= 1000000) - { - t.usec -= 1000000; - t.sec += 1; - } - - arts_assert (t.usec >= 0 && t.usec < 1000000); -} - -void timeStampDec(TimeStamp& t, const TimeStamp& delta) -{ - /* expect a normalized t, delta */ - arts_return_if_fail(t.usec >= 0 && t.usec < 1000000); - arts_return_if_fail(delta.usec >= 0 && delta.usec < 1000000); - - t.sec -= delta.sec; - t.usec -= delta.usec; - - if(t.usec < 0) - { - t.usec += 1000000; - t.sec -= 1; - } - - arts_assert(t.usec >= 0 && t.usec < 1000000); -} - -string timeStampToString(const TimeStamp& t) -{ - arts_return_val_if_fail(t.usec >= 0 && t.usec < 1000000, ""); - - char buffer[1024]; - if(t.sec < 0 && t.usec != 0) - { - sprintf(buffer, "-%d.%06d", -t.sec-1, 1000000-t.usec); - } - else - { - sprintf(buffer, "%d.%06d", t.sec, t.usec); - } - return buffer; -} - -double timeStampToDouble(const TimeStamp& t) -{ - arts_return_val_if_fail(t.usec >= 0 && t.usec < 1000000, 0.0); - - return double(t.sec) + double(t.usec)/1000000.0; -} - -TimeStamp timeStampFromDouble(double d) -{ - TimeStamp t; - - arts_return_val_if_fail(d >= 0, t); - - t.sec = int(d); - d -= t.sec; - t.usec = int(d * 1000000.0); - - return t; -} - -TimeStamp timeStampMax(const TimeStamp& t1, const TimeStamp& t2) -{ - if(t1.sec > t2.sec) - return t1; - else if((t1.sec == t2.sec) && (t1.usec > t2.usec)) - return t1; - else - return t2; -} - -} diff --git a/arts/midi/timestampmath.cpp b/arts/midi/timestampmath.cpp new file mode 100644 index 00000000..e8d5500a --- /dev/null +++ b/arts/midi/timestampmath.cpp @@ -0,0 +1,112 @@ + /* + + Copyright (C) 2002 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "timestampmath.h" +#include +#include + +using namespace std; + +namespace Arts { +void timeStampInc(TimeStamp& t, const TimeStamp& delta) +{ + /* expect a normalized t, delta */ + arts_return_if_fail(t.usec >= 0 && t.usec < 1000000); + arts_return_if_fail(delta.usec >= 0 && delta.usec < 1000000); + + t.sec += delta.sec; + t.usec += delta.usec; + + if (t.usec >= 1000000) + { + t.usec -= 1000000; + t.sec += 1; + } + + arts_assert (t.usec >= 0 && t.usec < 1000000); +} + +void timeStampDec(TimeStamp& t, const TimeStamp& delta) +{ + /* expect a normalized t, delta */ + arts_return_if_fail(t.usec >= 0 && t.usec < 1000000); + arts_return_if_fail(delta.usec >= 0 && delta.usec < 1000000); + + t.sec -= delta.sec; + t.usec -= delta.usec; + + if(t.usec < 0) + { + t.usec += 1000000; + t.sec -= 1; + } + + arts_assert(t.usec >= 0 && t.usec < 1000000); +} + +string timeStampToString(const TimeStamp& t) +{ + arts_return_val_if_fail(t.usec >= 0 && t.usec < 1000000, ""); + + char buffer[1024]; + if(t.sec < 0 && t.usec != 0) + { + sprintf(buffer, "-%d.%06d", -t.sec-1, 1000000-t.usec); + } + else + { + sprintf(buffer, "%d.%06d", t.sec, t.usec); + } + return buffer; +} + +double timeStampToDouble(const TimeStamp& t) +{ + arts_return_val_if_fail(t.usec >= 0 && t.usec < 1000000, 0.0); + + return double(t.sec) + double(t.usec)/1000000.0; +} + +TimeStamp timeStampFromDouble(double d) +{ + TimeStamp t; + + arts_return_val_if_fail(d >= 0, t); + + t.sec = int(d); + d -= t.sec; + t.usec = int(d * 1000000.0); + + return t; +} + +TimeStamp timeStampMax(const TimeStamp& t1, const TimeStamp& t2) +{ + if(t1.sec > t2.sec) + return t1; + else if((t1.sec == t2.sec) && (t1.usec > t2.usec)) + return t1; + else + return t2; +} + +} diff --git a/arts/modules/CMakeLists.txt b/arts/modules/CMakeLists.txt index 9f37038c..fb6d07e2 100644 --- a/arts/modules/CMakeLists.txt +++ b/arts/modules/CMakeLists.txt @@ -39,7 +39,7 @@ link_directories( tde_add_library( artsmodules SHARED SOURCES - artsmodules.cc + artsmodules.cpp VERSION 0.0.0 LINK tdecore-shared ${DL_LIBRARIES} mcop artsflow @@ -51,7 +51,7 @@ tde_add_library( artsmodules SHARED add_custom_command( OUTPUT - artsmodules.cc artsmodules.h + artsmodules.cpp artsmodules.h artsmodules.mcoptype artsmodules.mcopclass COMMAND ${ARTS_MCOPIDL_EXECUTABLE} -t -I${CMAKE_SOURCE_DIR}/arts/gui/common diff --git a/arts/modules/Makefile.am b/arts/modules/Makefile.am index d604e8b9..9ac9de04 100644 --- a/arts/modules/Makefile.am +++ b/arts/modules/Makefile.am @@ -25,7 +25,7 @@ MCOPIDLINCLUDES = \ lib_LTLIBRARIES = libartsmodules.la -libartsmodules_la_SOURCES = artsmodules.cc +libartsmodules_la_SOURCES = artsmodules.cpp libartsmodules_la_LIBADD = \ $(top_builddir)/arts/runtime/libartsbuilder.la \ @@ -42,10 +42,10 @@ libartsmodules_la_LDFLAGS = $(all_libraries) -L$(arts_libraries) \ artsmodules.mcopclass: artsmodules.h artsmodules.mcoptype: artsmodules.h -artsmodules.cc artsmodules.h: $(srcdir)/artsmodules.idl $(MCOPIDL) +artsmodules.cpp artsmodules.h: $(srcdir)/artsmodules.idl $(MCOPIDL) $(MCOPIDL) -t $(MCOPIDLINCLUDES) $(srcdir)/artsmodules.idl -DISTCLEANFILES = artsmodules.cc artsmodules.h \ +DISTCLEANFILES = artsmodules.cpp artsmodules.h \ artsmodules.mcoptype artsmodules.mcopclass ####### install idl files diff --git a/arts/modules/README.environments b/arts/modules/README.environments index 0ac64df5..c3b7b985 100644 --- a/arts/modules/README.environments +++ b/arts/modules/README.environments @@ -281,7 +281,7 @@ Basically, you derive an interface from Arts::Environment::Item, like this: and your implementation from Arts::Environment::Item_impl, like this: - // this code is in the .cc file: + // this code is in the .cpp file: #include "artsmodules.h" #include "env_item_impl.h" diff --git a/arts/modules/README.modules b/arts/modules/README.modules index 7113b3a9..2379f618 100644 --- a/arts/modules/README.modules +++ b/arts/modules/README.modules @@ -7,9 +7,9 @@ To add a new module "foo" to aRts: 1. Add a new interface to artsmodules.idl defining the module's input and output parameters. -2. Implement the new module in a new source file foo_impl.cc +2. Implement the new module in a new source file foo_impl.cpp -3. Add foo_impl.cc to the list of libartsmodules_la_SOURCES in +3. Add foo_impl.cpp to the list of libartsmodules_la_SOURCES in Makefile.am. 4. Create a new file mcopclass/foo.mcopclass diff --git a/arts/modules/artsmodules.idl b/arts/modules/artsmodules.idl index c502871d..0148aa5b 100644 --- a/arts/modules/artsmodules.idl +++ b/arts/modules/artsmodules.idl @@ -25,7 +25,7 @@ */ /* - * DISCLAIMER: The interfaces in artsmodules.idl (and the derived .cc/.h files) + * DISCLAIMER: The interfaces in artsmodules.idl (and the derived .cpp/.h files) * DO NOT GUARANTEE BINARY COMPATIBILITY YET. * * They are intended for developers. You shouldn't expect that applications in diff --git a/arts/modules/common/CMakeLists.txt b/arts/modules/common/CMakeLists.txt index 329fb104..ea065260 100644 --- a/arts/modules/common/CMakeLists.txt +++ b/arts/modules/common/CMakeLists.txt @@ -38,10 +38,10 @@ link_directories( tde_add_library( artsmodulescommon SHARED SOURCES - artsmodulescommon.cc effectrackslot_impl.cc - env_container_impl.cc env_context_impl.cc - env_effectrackitem_impl.cc env_instrumentitem_impl.cc - env_item_impl.cc env_mixeritem_impl.cc + artsmodulescommon.cpp effectrackslot_impl.cpp + env_container_impl.cpp env_context_impl.cpp + env_effectrackitem_impl.cpp env_instrumentitem_impl.cpp + env_item_impl.cpp env_mixeritem_impl.cpp VERSION 0.0.0 LINK artsgui_idl-shared artsmidi_idl-shared artsmodulessynth-shared @@ -51,7 +51,7 @@ tde_add_library( artsmodulescommon SHARED add_custom_command( OUTPUT - artsmodulescommon.cc artsmodulescommon.h + artsmodulescommon.cpp artsmodulescommon.h artsmodulescommon.mcopclass artsmodulescommon.mcoptype COMMAND ${ARTS_MCOPIDL_EXECUTABLE} -t -I${CMAKE_SOURCE_DIR}/arts/gui/common diff --git a/arts/modules/common/Makefile.am b/arts/modules/common/Makefile.am index bcf472fc..49cd300b 100644 --- a/arts/modules/common/Makefile.am +++ b/arts/modules/common/Makefile.am @@ -14,11 +14,11 @@ INCLUDES = \ lib_LTLIBRARIES = libartsmodulescommon.la -libartsmodulescommon_la_SOURCES = artsmodulescommon.cc \ - effectrackslot_impl.cc env_container_impl.cc \ - env_context_impl.cc env_effectrackitem_impl.cc \ - env_instrumentitem_impl.cc env_item_impl.cc \ - env_mixeritem_impl.cc +libartsmodulescommon_la_SOURCES = artsmodulescommon.cpp \ + effectrackslot_impl.cpp env_container_impl.cpp \ + env_context_impl.cpp env_effectrackitem_impl.cpp \ + env_instrumentitem_impl.cpp env_item_impl.cpp \ + env_mixeritem_impl.cpp libartsmodulescommon_la_COMPILE_FIRST = artsmodulescommon.h libartsmodulescommon_la_LIBADD = \ @@ -29,10 +29,10 @@ libartsmodulescommon_la_LIBADD = \ libartsmodulescommon_la_LDFLAGS = $(all_libraries) -L$(arts_libraries) -no-undefined -artsmodulescommon.cc artsmodulescommon.h artsmodulescommon.mcoptype artsmodulescommon.mcopclass: $(srcdir)/artsmodulescommon.idl $(MCOPIDL) +artsmodulescommon.cpp artsmodulescommon.h artsmodulescommon.mcoptype artsmodulescommon.mcopclass: $(srcdir)/artsmodulescommon.idl $(MCOPIDL) $(MCOPIDL) -t $(INCLUDES) $(srcdir)/artsmodulescommon.idl -DISTCLEANFILES= artsmodulescommon.cc artsmodulescommon.h artsmodulescommon.mcop* +DISTCLEANFILES= artsmodulescommon.cpp artsmodulescommon.h artsmodulescommon.mcop* artsincludedir = $(includedir)/arts artsinclude_HEADERS = artsmodulescommon.h artsmodulescommon.idl diff --git a/arts/modules/common/artsmodulescommon.idl b/arts/modules/common/artsmodulescommon.idl index 10ccd218..b22394eb 100644 --- a/arts/modules/common/artsmodulescommon.idl +++ b/arts/modules/common/artsmodulescommon.idl @@ -25,7 +25,7 @@ */ /* -* DISCLAIMER: The interfaces in artsmodules.idl (and the derived .cc/.h files) +* DISCLAIMER: The interfaces in artsmodules.idl (and the derived .cpp/.h files) * DO NOT GUARANTEE BINARY COMPATIBILITY YET. * * They are intended for developers. You shouldn't expect that applications in diff --git a/arts/modules/common/effectrackslot_impl.cc b/arts/modules/common/effectrackslot_impl.cc deleted file mode 100644 index 6671031b..00000000 --- a/arts/modules/common/effectrackslot_impl.cc +++ /dev/null @@ -1,114 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2002 Matthias Kretz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ -// $Id$ - -#include "artsmodulescommon.h" -#include -#include - -namespace Arts { -class EffectRackSlot_impl : virtual public EffectRackSlot_skel -{ - private: - HBox _hbox; - VBox _buttonbox; // Buttons - Button _removeButton; - Button _masterButton; - HBox _frame; - Widget _effect; - Frame _spacer; - EffectRackItemGui _effectrackgui; //XXX: need a WeakReference here? - - EffectRackSlot self() { return EffectRackSlot::_from_base( _copy() ); } - - public: - EffectRackSlot_impl() - { - } - - void constructor( Widget parent, Widget effect, EffectRackItemGui effectrackgui ) - { - _effectrackgui = effectrackgui; - - _hbox.parent( parent ); - _hbox.margin( 0 ); - _hbox.spacing( 0 ); - _hbox.framestyle( Sunken | Panel ); - _hbox.linewidth( 1 ); - _hbox.show(); - - _buttonbox.parent( _hbox ); - _buttonbox.margin( 0 ); - _buttonbox.spacing( 0 ); - _buttonbox.show(); - - _removeButton.parent( _buttonbox ); - _removeButton.text( "x" ); - _removeButton.hSizePolicy( spFixed ); - _removeButton.width( 20 ); - _removeButton.height( 20 ); - connect( _removeButton, "clicked_changed", self(), "removeslot" ); - _removeButton.show(); - - _masterButton.parent( _buttonbox ); - _masterButton.text( "MM" ); - _masterButton.toggle( true ); - _masterButton.hSizePolicy( spFixed ); - _masterButton.width( 20 ); - _masterButton.height( 20 ); - connect( _masterButton, "pressed_changed", self(), "tomaster" ); - _masterButton.show(); - - _frame.parent( _hbox ); - _frame.margin( 5 ); - _frame.spacing( 0 ); - _frame.framestyle( Raised | Panel ); - _frame.linewidth( 2 ); - _frame.midlinewidth( 2 ); - _frame.hSizePolicy( spExpanding ); - _frame.show(); - - _effect = effect; - _effect.parent( _frame ); - _effect.show(); - - _spacer.parent( _frame ); - _spacer.hSizePolicy( spExpanding ); - _spacer.show(); - } - - bool removeslot() { return false; } //unused - void removeslot( bool clicked ) - { - if( ! _removeButton.clicked() || ! clicked ) - return; - - // I need to be removed... - _effectrackgui.removeSlot( self() ); - // I should be deleted by now - } - - bool tomaster() { return false; } //unused - void tomaster( bool toggled ) - { - _effectrackgui.routeToMaster( self(), toggled ); - } -}; -REGISTER_IMPLEMENTATION( EffectRackSlot_impl ); -} diff --git a/arts/modules/common/effectrackslot_impl.cpp b/arts/modules/common/effectrackslot_impl.cpp new file mode 100644 index 00000000..6671031b --- /dev/null +++ b/arts/modules/common/effectrackslot_impl.cpp @@ -0,0 +1,114 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Matthias Kretz + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + +*/ +// $Id$ + +#include "artsmodulescommon.h" +#include +#include + +namespace Arts { +class EffectRackSlot_impl : virtual public EffectRackSlot_skel +{ + private: + HBox _hbox; + VBox _buttonbox; // Buttons + Button _removeButton; + Button _masterButton; + HBox _frame; + Widget _effect; + Frame _spacer; + EffectRackItemGui _effectrackgui; //XXX: need a WeakReference here? + + EffectRackSlot self() { return EffectRackSlot::_from_base( _copy() ); } + + public: + EffectRackSlot_impl() + { + } + + void constructor( Widget parent, Widget effect, EffectRackItemGui effectrackgui ) + { + _effectrackgui = effectrackgui; + + _hbox.parent( parent ); + _hbox.margin( 0 ); + _hbox.spacing( 0 ); + _hbox.framestyle( Sunken | Panel ); + _hbox.linewidth( 1 ); + _hbox.show(); + + _buttonbox.parent( _hbox ); + _buttonbox.margin( 0 ); + _buttonbox.spacing( 0 ); + _buttonbox.show(); + + _removeButton.parent( _buttonbox ); + _removeButton.text( "x" ); + _removeButton.hSizePolicy( spFixed ); + _removeButton.width( 20 ); + _removeButton.height( 20 ); + connect( _removeButton, "clicked_changed", self(), "removeslot" ); + _removeButton.show(); + + _masterButton.parent( _buttonbox ); + _masterButton.text( "MM" ); + _masterButton.toggle( true ); + _masterButton.hSizePolicy( spFixed ); + _masterButton.width( 20 ); + _masterButton.height( 20 ); + connect( _masterButton, "pressed_changed", self(), "tomaster" ); + _masterButton.show(); + + _frame.parent( _hbox ); + _frame.margin( 5 ); + _frame.spacing( 0 ); + _frame.framestyle( Raised | Panel ); + _frame.linewidth( 2 ); + _frame.midlinewidth( 2 ); + _frame.hSizePolicy( spExpanding ); + _frame.show(); + + _effect = effect; + _effect.parent( _frame ); + _effect.show(); + + _spacer.parent( _frame ); + _spacer.hSizePolicy( spExpanding ); + _spacer.show(); + } + + bool removeslot() { return false; } //unused + void removeslot( bool clicked ) + { + if( ! _removeButton.clicked() || ! clicked ) + return; + + // I need to be removed... + _effectrackgui.removeSlot( self() ); + // I should be deleted by now + } + + bool tomaster() { return false; } //unused + void tomaster( bool toggled ) + { + _effectrackgui.routeToMaster( self(), toggled ); + } +}; +REGISTER_IMPLEMENTATION( EffectRackSlot_impl ); +} diff --git a/arts/modules/common/env_container_impl.cc b/arts/modules/common/env_container_impl.cc deleted file mode 100644 index 0a6f87d7..00000000 --- a/arts/modules/common/env_container_impl.cc +++ /dev/null @@ -1,136 +0,0 @@ -#include "artsmodulescommon.h" -#include "../runtime/sequenceutils.h" -#include - -using namespace std; - -namespace Arts { -namespace Environment { - -class Container_impl : virtual public Container_skel { -protected: - string _dataDirectory; - Context _context; - vector _items; - - Container self() { return Container::_from_base(_copy()); } -public: - ~Container_impl() - { - // tell items we're going to leave before actually going away - clear(); - } - string dataDirectory() - { - return _dataDirectory; - } - void dataDirectory(const string& newDataDirectory) - { - if(newDataDirectory != _dataDirectory) - { - _dataDirectory = newDataDirectory; - dataDirectory_changed(newDataDirectory); - } - } - Context context() - { - return _context; - } - void context(Context newContext) - { - _context = newContext; - } - vector *items() - { - return new vector(_items); - } - vector *saveToList() - { - vector *result = new vector; - - vector::iterator ii; - for(ii=_items.begin(); ii != _items.end(); ii++) - { - sqprintf(result,"item=%s",ii->_interfaceName().c_str()); - - vector *itemresult = ii->saveToList(); - addSubStringSeq(result,itemresult); - delete itemresult; - } - return result; - } - - void clear() - { - /* FIXME: performance ;) */ - while(!_items.empty()) - removeItem(_items.front()); - } - - void loadFromList(const vector& strlist) - { - string cmd,param; - unsigned long i; - - clear(); - - for(i=0;i *itemlist = getSubStringSeq(&strlist,i); - - if(!item.isNull()) - item.loadFromList(*itemlist); - else - { - // error handling - assert(false); - } - delete itemlist; - } - } - } - } - - vector::iterator findItem(Item item) - { - vector::iterator i; - for(i = _items.begin(); i != _items.end(); i++) - if(i->_isEqual(item)) return i; - - return _items.end(); - } - - void addItem(Item item) - { - vector::iterator i = findItem(item); - arts_return_if_fail(i == _items.end()); - - _items.push_back(item); - item.setContainer(self()); - } - - Item createItem(const string& name) - { - Item item = SubClass(name); - addItem(item); - return item; - } - - void removeItem(Item item) - { - vector::iterator i = findItem(item); - arts_return_if_fail(i != _items.end()); - - _items.erase(i); - item.setContainer(Container::null()); - } -}; -REGISTER_IMPLEMENTATION(Container_impl); -} -} - diff --git a/arts/modules/common/env_container_impl.cpp b/arts/modules/common/env_container_impl.cpp new file mode 100644 index 00000000..0a6f87d7 --- /dev/null +++ b/arts/modules/common/env_container_impl.cpp @@ -0,0 +1,136 @@ +#include "artsmodulescommon.h" +#include "../runtime/sequenceutils.h" +#include + +using namespace std; + +namespace Arts { +namespace Environment { + +class Container_impl : virtual public Container_skel { +protected: + string _dataDirectory; + Context _context; + vector _items; + + Container self() { return Container::_from_base(_copy()); } +public: + ~Container_impl() + { + // tell items we're going to leave before actually going away + clear(); + } + string dataDirectory() + { + return _dataDirectory; + } + void dataDirectory(const string& newDataDirectory) + { + if(newDataDirectory != _dataDirectory) + { + _dataDirectory = newDataDirectory; + dataDirectory_changed(newDataDirectory); + } + } + Context context() + { + return _context; + } + void context(Context newContext) + { + _context = newContext; + } + vector *items() + { + return new vector(_items); + } + vector *saveToList() + { + vector *result = new vector; + + vector::iterator ii; + for(ii=_items.begin(); ii != _items.end(); ii++) + { + sqprintf(result,"item=%s",ii->_interfaceName().c_str()); + + vector *itemresult = ii->saveToList(); + addSubStringSeq(result,itemresult); + delete itemresult; + } + return result; + } + + void clear() + { + /* FIXME: performance ;) */ + while(!_items.empty()) + removeItem(_items.front()); + } + + void loadFromList(const vector& strlist) + { + string cmd,param; + unsigned long i; + + clear(); + + for(i=0;i *itemlist = getSubStringSeq(&strlist,i); + + if(!item.isNull()) + item.loadFromList(*itemlist); + else + { + // error handling + assert(false); + } + delete itemlist; + } + } + } + } + + vector::iterator findItem(Item item) + { + vector::iterator i; + for(i = _items.begin(); i != _items.end(); i++) + if(i->_isEqual(item)) return i; + + return _items.end(); + } + + void addItem(Item item) + { + vector::iterator i = findItem(item); + arts_return_if_fail(i == _items.end()); + + _items.push_back(item); + item.setContainer(self()); + } + + Item createItem(const string& name) + { + Item item = SubClass(name); + addItem(item); + return item; + } + + void removeItem(Item item) + { + vector::iterator i = findItem(item); + arts_return_if_fail(i != _items.end()); + + _items.erase(i); + item.setContainer(Container::null()); + } +}; +REGISTER_IMPLEMENTATION(Container_impl); +} +} + diff --git a/arts/modules/common/env_context_impl.cc b/arts/modules/common/env_context_impl.cc deleted file mode 100644 index a9b19a50..00000000 --- a/arts/modules/common/env_context_impl.cc +++ /dev/null @@ -1,72 +0,0 @@ -#include "artsmodulescommon.h" -#include - -using namespace std; - -namespace Arts { -namespace Environment { - -class Context_impl : virtual public Context_skel { -protected: - struct ContextEntry { - ContextEntry(const string& name, Object object) - : name(name), object(object) - { - } - ContextEntry(const ContextEntry& entry) - : name(entry.name), object(entry.object) - { - } - string name; - Object object; - }; - list entries; - - list::iterator findEntry(const string& name) - { - list::iterator i = entries.begin(); - for(i = entries.begin(); i != entries.end(); i++) - if(i->name == name) return i; - - return entries.end(); - } - - list::iterator findEntry(Object object) - { - list::iterator i = entries.begin(); - for(i = entries.begin(); i != entries.end(); i++) - if(object._isEqual(i->object)) return i; - - return entries.end(); - } - - -public: - void addEntry(const string& name, Object object) - { - arts_return_if_fail(findEntry(name) != entries.end()); - entries.push_back(ContextEntry(name, object)); - } - - string lookupEntry(Object object) - { - list::iterator i = findEntry(object); - - if(i == entries.end()) - return ""; - else - return i->name; - } - - void removeEntry(Object object) - { - list::iterator i = findEntry(object); - - arts_return_if_fail(i != entries.end()); - entries.erase(i); - } -}; -REGISTER_IMPLEMENTATION(Context_impl); -} -} - diff --git a/arts/modules/common/env_context_impl.cpp b/arts/modules/common/env_context_impl.cpp new file mode 100644 index 00000000..a9b19a50 --- /dev/null +++ b/arts/modules/common/env_context_impl.cpp @@ -0,0 +1,72 @@ +#include "artsmodulescommon.h" +#include + +using namespace std; + +namespace Arts { +namespace Environment { + +class Context_impl : virtual public Context_skel { +protected: + struct ContextEntry { + ContextEntry(const string& name, Object object) + : name(name), object(object) + { + } + ContextEntry(const ContextEntry& entry) + : name(entry.name), object(entry.object) + { + } + string name; + Object object; + }; + list entries; + + list::iterator findEntry(const string& name) + { + list::iterator i = entries.begin(); + for(i = entries.begin(); i != entries.end(); i++) + if(i->name == name) return i; + + return entries.end(); + } + + list::iterator findEntry(Object object) + { + list::iterator i = entries.begin(); + for(i = entries.begin(); i != entries.end(); i++) + if(object._isEqual(i->object)) return i; + + return entries.end(); + } + + +public: + void addEntry(const string& name, Object object) + { + arts_return_if_fail(findEntry(name) != entries.end()); + entries.push_back(ContextEntry(name, object)); + } + + string lookupEntry(Object object) + { + list::iterator i = findEntry(object); + + if(i == entries.end()) + return ""; + else + return i->name; + } + + void removeEntry(Object object) + { + list::iterator i = findEntry(object); + + arts_return_if_fail(i != entries.end()); + entries.erase(i); + } +}; +REGISTER_IMPLEMENTATION(Context_impl); +} +} + diff --git a/arts/modules/common/env_effectrackitem_impl.cc b/arts/modules/common/env_effectrackitem_impl.cc deleted file mode 100644 index c082ce24..00000000 --- a/arts/modules/common/env_effectrackitem_impl.cc +++ /dev/null @@ -1,399 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2002-2003 Matthias Kretz - 2002 Arnold Krille - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ -// $Id$ - -#include "artsmodulescommon.h" -#include -#include "env_item_impl.h" -#include -#include -#include -#include - - -// Wether you are able to edit the name of the effectrack with an ugly LineInput or not. -//#define EFFECTRACK_NAME -// We should implement something like a ConfigWidget or at least a KLineInputBox or something... - -namespace Arts { -namespace Environment { - -class EffectRackItem_impl : virtual public EffectRackItem_skel, - virtual public Item_impl -{ -protected: - std::string _name; - AudioManagerClient _amClient; - - struct RackWiring { - RackWiring( const std::string & type, AudioManagerClient _amClient ) - : routedtomaster( false ) - , amClient( _amClient ) - { - effect = SubClass( type ); - - connect( input, effect ); - connect( effect, output ); - } - - inline void setName( const std::string & efname ) - { - name = efname; - input.busname( efname ); - if( ! routedtomaster ) - { - output.title( efname ); - output.autoRestoreID( efname ); - } - } - - inline void start() - { - input.start(); - effect.start(); - output.start(); - } - - inline void stop() - { - input.stop(); - effect.stop(); - output.stop(); - } - - inline void master( bool tomaster ) - { - routedtomaster = tomaster; - - output.stop(); - output = tomaster ? Synth_AMAN_PLAY( amClient ) : Synth_AMAN_PLAY(); - connect( effect, output ); - if( ! tomaster ) - { - output.title( name ); - output.autoRestoreID( name ); - } - output.start(); - } - - bool routedtomaster; - std::string name; - std::string effectName; - Synth_BUS_DOWNLINK input; - Arts::StereoEffect effect; - Synth_AMAN_PLAY output; - AudioManagerClient amClient; - }; - std::vector _wirings; - -public: - EffectRackItem_impl() - : _name( "effect rack" ) - , _amClient( amPlay, _name + " Master", "effectrack_" + _name ) - { - // TODO: check if there's another effect rack with the same name already - if so prefix with 2./3./4. - } - - // readonly attribute sequence effects; - std::vector *effects() - { - std::vector * effects = new std::vector; - for( std::vector::iterator it = _wirings.begin(); it != _wirings.end(); ++it ) - effects->push_back( it->effect ); - return effects; - } - - // attribute long effectCount; - long effectCount() { return _wirings.size(); } - - // attribute string name; - void name(const std::string& newName) { - if(newName != _name) - { - _name = newName; - _amClient.title( _name + " Master" ); - _amClient.autoRestoreID( "effectrack_" + _name ); - for( unsigned int i = 0; i < _wirings.size(); i++ ) - _wirings[i].setName( effectName( i, _wirings[ i ].effectName ) ); - name_changed( newName ); - } - } - std::string name() { return _name; } - - void loadFromList(const std::vector& /*list*/) - { - } - - std::vector *saveToList() - { - std::vector *result = new std::vector; - return result; - } - - std::string effectName( int n, const std::string & en ) - { - char * efname = new char[ _name.length() + en.length() + 128 ]; - sprintf( efname, "%s%02d (%s)", _name.c_str(), n, en.c_str() ); - return efname; - } - - Arts::StereoEffect createEffect( const std::string & type, const std::string & name ) - { - RackWiring wiring( type, _amClient ); - wiring.setName( effectName( _wirings.size() + 1, name ) ); - wiring.start(); - _wirings.push_back( wiring ); - return wiring.effect; - } - - void delEffect( long pos ) - { - _wirings[ pos ].stop(); - _wirings.erase( _wirings.begin() + pos ); - for( unsigned int i = pos; i < _wirings.size(); ++i ) - _wirings[ i ].setName( effectName( i, _wirings[ i ].effectName ) ); - } - - void routeToMaster( long pos, bool tomaster ) - { - _wirings[ pos ].master( tomaster ); - } -}; -REGISTER_IMPLEMENTATION(EffectRackItem_impl); -} - -using namespace Environment; - -typedef WeakReference VBox_wref; - -class EffectRackItemGui_impl : virtual public EffectRackItemGui_skel { -private: - bool _active; - long _effectCount; - std::string _type; - EffectRackItem _effectRack; - - /* widgets */ - VBox_wref _widget; - HBox hbox; - VBox effect_vbox; -#ifdef EFFECTRACK_NAME - LineEdit name; -#endif - ComboBox typebox; - Button addbutton; - GenericGuiFactory guiFactory; - std::vector _slots; - std::map typeforname; - std::map namefortype; - -public: - EffectRackItemGui self() { return EffectRackItemGui::_from_base(_copy()); } - - void redoGui() - { - VBox vbox = _widget; - if(vbox.isNull()) - arts_warning("update with vbox null"); - if(_effectRack.isNull()) - arts_warning("update with _effectRack null"); - if(!_effectRack.isNull() && !vbox.isNull()) - { - vbox.spacing( 0 ); - vbox.margin( 10 ); - hbox = HBox( vbox ); - hbox.spacing( 5 ); - hbox.margin( 0 ); - -#ifdef EFFECTRACK_NAME - name = LineEdit(); - name.caption("name"); - name.text(_effectRack.name()); - name.parent(hbox); - connect(name,"text_changed", _effectRack, "name"); -#endif - - std::vector choices; - TraderQuery query; - query.supports( "Interface", "Arts::StereoEffect" ); - query.supports( "Features", "RackGUI" ); - std::vector *queryResults = query.query(); - for(std::vector::iterator it = queryResults->begin(); it != queryResults->end(); ++it) - { - std::vector * names = it->getProperty( "Name" ); - std::string name = names->empty() ? it->interfaceName() : names->front(); - delete names; - choices.push_back( name ); - typeforname[ name ] = it->interfaceName(); - namefortype[ it->interfaceName() ] = name; - } - delete queryResults; - typebox = ComboBox(); - typebox.choices(choices); - typebox.value(_type); - typebox.parent(hbox); - connect(typebox,"value_changed", self(), "type"); - - addbutton = Button( "add", hbox ); - connect( addbutton, "clicked_changed", self(), "addeffect" ); - - effect_vbox = VBox( vbox ); - effect_vbox.margin( 0 ); - effect_vbox.spacing( 5 ); - effect_vbox.show(); - - Frame spacer; - spacer.parent( effect_vbox ); - spacer.vSizePolicy( spExpanding ); - spacer.show(); - effect_vbox._addChild( spacer, "spacer" ); - - _slots.clear(); - - // add Arts::StereoEffect widgets - std::vector * effects = _effectRack.effects(); - for( std::vector::iterator it = effects->begin(); it != effects->end(); ++it ) - createEffectGui( *it ); - delete effects; - } - else - { - /* FIXME: maybe insert a "dead" label here */ - if(!vbox.isNull()) - vbox.show(); - effect_vbox = VBox::null(); - hbox = HBox::null(); - // name = LineEdit::null(); - typebox = ComboBox::null(); - _slots.clear(); - } - } - - void createEffectGui( Arts::StereoEffect effect ) - { - Widget w = guiFactory.createGui( effect ); - if( ! w.isNull() ) - { - // insert effect GUI into the "Rack" - EffectRackSlot slot( effect_vbox, w, self() ); - _slots.push_back( slot ); - } - } - - void removeSlot( EffectRackSlot slot ) - { - unsigned int i; - for( i = 0; i < _slots.size() && ! _slots[ i ]._isEqual( slot ) ; ++i ); - if( i < _slots.size() ) - { - _slots.erase( _slots.begin() + i ); - _effectRack.delEffect( i ); - } - else - arts_warning( "WARNING: Trying to remove an unknown slot" ); - } - - void routeToMaster( EffectRackSlot slot, bool tomaster ) - { - unsigned int i; - for( i = 0; i < _slots.size() && ! _slots[ i ]._isEqual( slot ) ; ++i ); - if( i < _slots.size() ) - _effectRack.routeToMaster( i, tomaster ); - else - arts_warning( "WARNING: Trying to route an unknown slot" ); - } - - bool active() { return _active; } - void active(bool newActive) - { - if(newActive != _active) - { - _active = newActive; - if(!newActive) - _effectRack = EffectRackItem::null(); - redoGui(); - } - } - - std::string type() - { - return _type; - } - void type(const std::string& t) - { - _type = typeforname[ t ]; - } - - bool addeffect() { return false; } //unused - void addeffect( bool clicked ) - { - if( ! addbutton.clicked() || ! clicked ) - return; - - Arts::StereoEffect effect = _effectRack.createEffect( _type, namefortype[ _type ] ); - createEffectGui( effect ); - } - - Widget initialize(EffectRackItem item) - { - VBox vbox; - vbox._addChild(self(),"the_gui_updating_widget"); - - _widget = vbox; - _effectRack = item; - _active = item.active(); - _type = "Arts::Synth_VOICE_REMOVAL"; - _effectCount = item.effectCount(); - - if(!_effectRack.isNull()) - { - connect(_effectRack, "active_changed", self(), "active"); - } - redoGui(); - - return vbox; - } -}; - -REGISTER_IMPLEMENTATION(EffectRackItemGui_impl); - -class EffectRackGuiFactory_impl : virtual public EffectRackGuiFactory_skel -{ -public: - Widget createGui(Object object) - { - arts_return_val_if_fail(!object.isNull(), Arts::Widget::null()); - - std::string iface = object._interfaceName(); - arts_return_val_if_fail(iface == "Arts::Environment::EffectRackItem", - Arts::Widget::null()); - if(iface == "Arts::Environment::EffectRackItem") - { - EffectRackItem effectRack = DynamicCast(object); - arts_return_val_if_fail(!effectRack.isNull(), Arts::Widget::null()); - - EffectRackItemGui gui; - return gui.initialize(effectRack); - } - return Arts::Widget::null(); - } -}; -REGISTER_IMPLEMENTATION(EffectRackGuiFactory_impl); -} diff --git a/arts/modules/common/env_effectrackitem_impl.cpp b/arts/modules/common/env_effectrackitem_impl.cpp new file mode 100644 index 00000000..c082ce24 --- /dev/null +++ b/arts/modules/common/env_effectrackitem_impl.cpp @@ -0,0 +1,399 @@ +/* This file is part of the KDE project + Copyright (C) 2002-2003 Matthias Kretz + 2002 Arnold Krille + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + +*/ +// $Id$ + +#include "artsmodulescommon.h" +#include +#include "env_item_impl.h" +#include +#include +#include +#include + + +// Wether you are able to edit the name of the effectrack with an ugly LineInput or not. +//#define EFFECTRACK_NAME +// We should implement something like a ConfigWidget or at least a KLineInputBox or something... + +namespace Arts { +namespace Environment { + +class EffectRackItem_impl : virtual public EffectRackItem_skel, + virtual public Item_impl +{ +protected: + std::string _name; + AudioManagerClient _amClient; + + struct RackWiring { + RackWiring( const std::string & type, AudioManagerClient _amClient ) + : routedtomaster( false ) + , amClient( _amClient ) + { + effect = SubClass( type ); + + connect( input, effect ); + connect( effect, output ); + } + + inline void setName( const std::string & efname ) + { + name = efname; + input.busname( efname ); + if( ! routedtomaster ) + { + output.title( efname ); + output.autoRestoreID( efname ); + } + } + + inline void start() + { + input.start(); + effect.start(); + output.start(); + } + + inline void stop() + { + input.stop(); + effect.stop(); + output.stop(); + } + + inline void master( bool tomaster ) + { + routedtomaster = tomaster; + + output.stop(); + output = tomaster ? Synth_AMAN_PLAY( amClient ) : Synth_AMAN_PLAY(); + connect( effect, output ); + if( ! tomaster ) + { + output.title( name ); + output.autoRestoreID( name ); + } + output.start(); + } + + bool routedtomaster; + std::string name; + std::string effectName; + Synth_BUS_DOWNLINK input; + Arts::StereoEffect effect; + Synth_AMAN_PLAY output; + AudioManagerClient amClient; + }; + std::vector _wirings; + +public: + EffectRackItem_impl() + : _name( "effect rack" ) + , _amClient( amPlay, _name + " Master", "effectrack_" + _name ) + { + // TODO: check if there's another effect rack with the same name already - if so prefix with 2./3./4. + } + + // readonly attribute sequence effects; + std::vector *effects() + { + std::vector * effects = new std::vector; + for( std::vector::iterator it = _wirings.begin(); it != _wirings.end(); ++it ) + effects->push_back( it->effect ); + return effects; + } + + // attribute long effectCount; + long effectCount() { return _wirings.size(); } + + // attribute string name; + void name(const std::string& newName) { + if(newName != _name) + { + _name = newName; + _amClient.title( _name + " Master" ); + _amClient.autoRestoreID( "effectrack_" + _name ); + for( unsigned int i = 0; i < _wirings.size(); i++ ) + _wirings[i].setName( effectName( i, _wirings[ i ].effectName ) ); + name_changed( newName ); + } + } + std::string name() { return _name; } + + void loadFromList(const std::vector& /*list*/) + { + } + + std::vector *saveToList() + { + std::vector *result = new std::vector; + return result; + } + + std::string effectName( int n, const std::string & en ) + { + char * efname = new char[ _name.length() + en.length() + 128 ]; + sprintf( efname, "%s%02d (%s)", _name.c_str(), n, en.c_str() ); + return efname; + } + + Arts::StereoEffect createEffect( const std::string & type, const std::string & name ) + { + RackWiring wiring( type, _amClient ); + wiring.setName( effectName( _wirings.size() + 1, name ) ); + wiring.start(); + _wirings.push_back( wiring ); + return wiring.effect; + } + + void delEffect( long pos ) + { + _wirings[ pos ].stop(); + _wirings.erase( _wirings.begin() + pos ); + for( unsigned int i = pos; i < _wirings.size(); ++i ) + _wirings[ i ].setName( effectName( i, _wirings[ i ].effectName ) ); + } + + void routeToMaster( long pos, bool tomaster ) + { + _wirings[ pos ].master( tomaster ); + } +}; +REGISTER_IMPLEMENTATION(EffectRackItem_impl); +} + +using namespace Environment; + +typedef WeakReference VBox_wref; + +class EffectRackItemGui_impl : virtual public EffectRackItemGui_skel { +private: + bool _active; + long _effectCount; + std::string _type; + EffectRackItem _effectRack; + + /* widgets */ + VBox_wref _widget; + HBox hbox; + VBox effect_vbox; +#ifdef EFFECTRACK_NAME + LineEdit name; +#endif + ComboBox typebox; + Button addbutton; + GenericGuiFactory guiFactory; + std::vector _slots; + std::map typeforname; + std::map namefortype; + +public: + EffectRackItemGui self() { return EffectRackItemGui::_from_base(_copy()); } + + void redoGui() + { + VBox vbox = _widget; + if(vbox.isNull()) + arts_warning("update with vbox null"); + if(_effectRack.isNull()) + arts_warning("update with _effectRack null"); + if(!_effectRack.isNull() && !vbox.isNull()) + { + vbox.spacing( 0 ); + vbox.margin( 10 ); + hbox = HBox( vbox ); + hbox.spacing( 5 ); + hbox.margin( 0 ); + +#ifdef EFFECTRACK_NAME + name = LineEdit(); + name.caption("name"); + name.text(_effectRack.name()); + name.parent(hbox); + connect(name,"text_changed", _effectRack, "name"); +#endif + + std::vector choices; + TraderQuery query; + query.supports( "Interface", "Arts::StereoEffect" ); + query.supports( "Features", "RackGUI" ); + std::vector *queryResults = query.query(); + for(std::vector::iterator it = queryResults->begin(); it != queryResults->end(); ++it) + { + std::vector * names = it->getProperty( "Name" ); + std::string name = names->empty() ? it->interfaceName() : names->front(); + delete names; + choices.push_back( name ); + typeforname[ name ] = it->interfaceName(); + namefortype[ it->interfaceName() ] = name; + } + delete queryResults; + typebox = ComboBox(); + typebox.choices(choices); + typebox.value(_type); + typebox.parent(hbox); + connect(typebox,"value_changed", self(), "type"); + + addbutton = Button( "add", hbox ); + connect( addbutton, "clicked_changed", self(), "addeffect" ); + + effect_vbox = VBox( vbox ); + effect_vbox.margin( 0 ); + effect_vbox.spacing( 5 ); + effect_vbox.show(); + + Frame spacer; + spacer.parent( effect_vbox ); + spacer.vSizePolicy( spExpanding ); + spacer.show(); + effect_vbox._addChild( spacer, "spacer" ); + + _slots.clear(); + + // add Arts::StereoEffect widgets + std::vector * effects = _effectRack.effects(); + for( std::vector::iterator it = effects->begin(); it != effects->end(); ++it ) + createEffectGui( *it ); + delete effects; + } + else + { + /* FIXME: maybe insert a "dead" label here */ + if(!vbox.isNull()) + vbox.show(); + effect_vbox = VBox::null(); + hbox = HBox::null(); + // name = LineEdit::null(); + typebox = ComboBox::null(); + _slots.clear(); + } + } + + void createEffectGui( Arts::StereoEffect effect ) + { + Widget w = guiFactory.createGui( effect ); + if( ! w.isNull() ) + { + // insert effect GUI into the "Rack" + EffectRackSlot slot( effect_vbox, w, self() ); + _slots.push_back( slot ); + } + } + + void removeSlot( EffectRackSlot slot ) + { + unsigned int i; + for( i = 0; i < _slots.size() && ! _slots[ i ]._isEqual( slot ) ; ++i ); + if( i < _slots.size() ) + { + _slots.erase( _slots.begin() + i ); + _effectRack.delEffect( i ); + } + else + arts_warning( "WARNING: Trying to remove an unknown slot" ); + } + + void routeToMaster( EffectRackSlot slot, bool tomaster ) + { + unsigned int i; + for( i = 0; i < _slots.size() && ! _slots[ i ]._isEqual( slot ) ; ++i ); + if( i < _slots.size() ) + _effectRack.routeToMaster( i, tomaster ); + else + arts_warning( "WARNING: Trying to route an unknown slot" ); + } + + bool active() { return _active; } + void active(bool newActive) + { + if(newActive != _active) + { + _active = newActive; + if(!newActive) + _effectRack = EffectRackItem::null(); + redoGui(); + } + } + + std::string type() + { + return _type; + } + void type(const std::string& t) + { + _type = typeforname[ t ]; + } + + bool addeffect() { return false; } //unused + void addeffect( bool clicked ) + { + if( ! addbutton.clicked() || ! clicked ) + return; + + Arts::StereoEffect effect = _effectRack.createEffect( _type, namefortype[ _type ] ); + createEffectGui( effect ); + } + + Widget initialize(EffectRackItem item) + { + VBox vbox; + vbox._addChild(self(),"the_gui_updating_widget"); + + _widget = vbox; + _effectRack = item; + _active = item.active(); + _type = "Arts::Synth_VOICE_REMOVAL"; + _effectCount = item.effectCount(); + + if(!_effectRack.isNull()) + { + connect(_effectRack, "active_changed", self(), "active"); + } + redoGui(); + + return vbox; + } +}; + +REGISTER_IMPLEMENTATION(EffectRackItemGui_impl); + +class EffectRackGuiFactory_impl : virtual public EffectRackGuiFactory_skel +{ +public: + Widget createGui(Object object) + { + arts_return_val_if_fail(!object.isNull(), Arts::Widget::null()); + + std::string iface = object._interfaceName(); + arts_return_val_if_fail(iface == "Arts::Environment::EffectRackItem", + Arts::Widget::null()); + if(iface == "Arts::Environment::EffectRackItem") + { + EffectRackItem effectRack = DynamicCast(object); + arts_return_val_if_fail(!effectRack.isNull(), Arts::Widget::null()); + + EffectRackItemGui gui; + return gui.initialize(effectRack); + } + return Arts::Widget::null(); + } +}; +REGISTER_IMPLEMENTATION(EffectRackGuiFactory_impl); +} diff --git a/arts/modules/common/env_instrumentitem_impl.cc b/arts/modules/common/env_instrumentitem_impl.cc deleted file mode 100644 index 17959ca0..00000000 --- a/arts/modules/common/env_instrumentitem_impl.cc +++ /dev/null @@ -1,113 +0,0 @@ -#include -#include "artsmodulescommon.h" -#include "debug.h" -#include "env_item_impl.h" -#include "connect.h" -#include "../runtime/sequenceutils.h" - -namespace Arts { -namespace Environment { - -class InstrumentItem_impl : virtual public InstrumentItem_skel, - virtual public Item_impl -{ -protected: - Synth_MIDI_TEST instrument; - bool running; - -public: - InstrumentItem_impl() : running(false) - { - } - ~InstrumentItem_impl() - { - /* this will allow freeing the instrument */ - if(running) - instrument.stop(); - } - void filename(const std::string& newFilename) - { - if(newFilename != instrument.filename()) - { - instrument.filename(newFilename); - filename_changed(newFilename); - - if(!running) { - instrument.start(); - running = true; - } - } - } - std::string filename() - { - return instrument.filename(); - } - void busname(const std::string& newBusname) - { - if(newBusname != instrument.busname()) - { - instrument.busname(newBusname); - busname_changed(newBusname); - } - } - std::string busname() - { - return instrument.busname(); - } - MidiPort port() - { - return instrument; - } - void loadFromList(const std::vector& list) - { - unsigned long i; - std::string cmd,param; - for(i=0;i *saveToList() - { - std::vector *result = new std::vector; - sqprintf(result,"filename=%s",filename().c_str()); - return result; - } -}; -REGISTER_IMPLEMENTATION(InstrumentItem_impl); - -class InstrumentItemGuiFactory_impl - : virtual public InstrumentItemGuiFactory_skel -{ -public: - Widget createGui(Object object) - { - arts_return_val_if_fail(!object.isNull(), Arts::Widget::null()); - - InstrumentItem instrument = DynamicCast(object); - arts_return_val_if_fail(!instrument.isNull(), Arts::Widget::null()); - - Widget panel; - panel.width(150); panel.height(60); panel.show(); - - LineEdit edit; - edit.x(20); edit.y(10); edit.width(120); edit.height(40); - edit.text(instrument.filename()); - edit.parent(panel); - edit.show(); - connect(edit,"text_changed", instrument, "filename"); - panel._addChild(edit,"editWidget"); - - return panel; - } -}; - -REGISTER_IMPLEMENTATION(InstrumentItemGuiFactory_impl); - -} -} diff --git a/arts/modules/common/env_instrumentitem_impl.cpp b/arts/modules/common/env_instrumentitem_impl.cpp new file mode 100644 index 00000000..17959ca0 --- /dev/null +++ b/arts/modules/common/env_instrumentitem_impl.cpp @@ -0,0 +1,113 @@ +#include +#include "artsmodulescommon.h" +#include "debug.h" +#include "env_item_impl.h" +#include "connect.h" +#include "../runtime/sequenceutils.h" + +namespace Arts { +namespace Environment { + +class InstrumentItem_impl : virtual public InstrumentItem_skel, + virtual public Item_impl +{ +protected: + Synth_MIDI_TEST instrument; + bool running; + +public: + InstrumentItem_impl() : running(false) + { + } + ~InstrumentItem_impl() + { + /* this will allow freeing the instrument */ + if(running) + instrument.stop(); + } + void filename(const std::string& newFilename) + { + if(newFilename != instrument.filename()) + { + instrument.filename(newFilename); + filename_changed(newFilename); + + if(!running) { + instrument.start(); + running = true; + } + } + } + std::string filename() + { + return instrument.filename(); + } + void busname(const std::string& newBusname) + { + if(newBusname != instrument.busname()) + { + instrument.busname(newBusname); + busname_changed(newBusname); + } + } + std::string busname() + { + return instrument.busname(); + } + MidiPort port() + { + return instrument; + } + void loadFromList(const std::vector& list) + { + unsigned long i; + std::string cmd,param; + for(i=0;i *saveToList() + { + std::vector *result = new std::vector; + sqprintf(result,"filename=%s",filename().c_str()); + return result; + } +}; +REGISTER_IMPLEMENTATION(InstrumentItem_impl); + +class InstrumentItemGuiFactory_impl + : virtual public InstrumentItemGuiFactory_skel +{ +public: + Widget createGui(Object object) + { + arts_return_val_if_fail(!object.isNull(), Arts::Widget::null()); + + InstrumentItem instrument = DynamicCast(object); + arts_return_val_if_fail(!instrument.isNull(), Arts::Widget::null()); + + Widget panel; + panel.width(150); panel.height(60); panel.show(); + + LineEdit edit; + edit.x(20); edit.y(10); edit.width(120); edit.height(40); + edit.text(instrument.filename()); + edit.parent(panel); + edit.show(); + connect(edit,"text_changed", instrument, "filename"); + panel._addChild(edit,"editWidget"); + + return panel; + } +}; + +REGISTER_IMPLEMENTATION(InstrumentItemGuiFactory_impl); + +} +} diff --git a/arts/modules/common/env_item_impl.cc b/arts/modules/common/env_item_impl.cc deleted file mode 100644 index 6bc960d8..00000000 --- a/arts/modules/common/env_item_impl.cc +++ /dev/null @@ -1,48 +0,0 @@ -#include "artsmodulescommon.h" -#include "debug.h" -#include "env_item_impl.h" - -using namespace Arts; -using namespace std; - -Environment::Item_impl::Item_impl() - : _active(false) -{ -} - -Environment::Item_impl::~Item_impl() -{ - // Items can't be deleted while they are still inside a Container - arts_assert(_active == false); -} - -Environment::Container Environment::Item_impl::parent() -{ - Container p = _parent; - return p; -} - -void Environment::Item_impl::setContainer(Environment::Container container) -{ - if(container.isNull()) // remove from container - { - arts_return_if_fail(_active == true); - - _parent = container; - _active = false; - } - else // add to container - { - Container p = _parent; - arts_return_if_fail(p.isNull() && _active == false); - - _parent = container; - _active = true; - } - active_changed(_active); -} - -bool Environment::Item_impl::active() -{ - return _active; -} diff --git a/arts/modules/common/env_item_impl.cpp b/arts/modules/common/env_item_impl.cpp new file mode 100644 index 00000000..6bc960d8 --- /dev/null +++ b/arts/modules/common/env_item_impl.cpp @@ -0,0 +1,48 @@ +#include "artsmodulescommon.h" +#include "debug.h" +#include "env_item_impl.h" + +using namespace Arts; +using namespace std; + +Environment::Item_impl::Item_impl() + : _active(false) +{ +} + +Environment::Item_impl::~Item_impl() +{ + // Items can't be deleted while they are still inside a Container + arts_assert(_active == false); +} + +Environment::Container Environment::Item_impl::parent() +{ + Container p = _parent; + return p; +} + +void Environment::Item_impl::setContainer(Environment::Container container) +{ + if(container.isNull()) // remove from container + { + arts_return_if_fail(_active == true); + + _parent = container; + _active = false; + } + else // add to container + { + Container p = _parent; + arts_return_if_fail(p.isNull() && _active == false); + + _parent = container; + _active = true; + } + active_changed(_active); +} + +bool Environment::Item_impl::active() +{ + return _active; +} diff --git a/arts/modules/common/env_mixeritem_impl.cc b/arts/modules/common/env_mixeritem_impl.cc deleted file mode 100644 index 93735dd5..00000000 --- a/arts/modules/common/env_mixeritem_impl.cc +++ /dev/null @@ -1,367 +0,0 @@ -#include "artsmodulescommon.h" -#include "debug.h" -#include "env_item_impl.h" -#include "connect.h" -#include "../runtime/sequenceutils.h" -#include -#include -#include - -#include - -namespace Arts { -namespace Environment { - -class MixerItem_impl : virtual public MixerItem_skel, - virtual public Item_impl -{ -protected: - std::vector _inputs; - std::vector _channels; - std::vector _outputs; - std::string _name; - std::string _type; - AudioManagerClient amClient; - -public: - MixerItem_impl() - : _name("mixer"), _type("Arts::SimpleMixerChannel"), - amClient(amPlay, "Mixer (mixer)","mixer_mixer") - { - } - // readonly attribute sequence channels; - std::vector *channels() { - return new std::vector(_channels); - } - // attribute long channelCount; - void channelCount(long newChannelCount) - { - if((unsigned long)newChannelCount != _channels.size()) - { - while(_channels.size() < (unsigned long)newChannelCount) addChannel(); - while(_channels.size() > (unsigned long)newChannelCount) delChannel(); - channelCount_changed(newChannelCount); - } - } - long channelCount() { return _channels.size(); } - // attribute string name; - void name(const std::string& newName) { - if(newName != _name) - { - _name = newName; - amClient.title(i18n("Mixer (\"%1\")").arg(TQString::fromUtf8(_name.c_str())).utf8().data()); - amClient.autoRestoreID("mixer_"+_name); - for(unsigned int i = 0; i < _inputs.size(); i++) - _inputs[i].busname(channelName(i)); - name_changed(newName); - } - } - std::string name() { return _name; } - // attribute string type; - void type(const std::string& newType) { - if(newType != _type) - { - _type = newType; - type_changed(newType); - } - } - std::string type() { return _type; } - void loadFromList(const std::vector& /*list*/) - { - /* - unsigned long i; - std::string cmd,param; - for(i=0;i *saveToList() - { - std::vector *result = new std::vector; - /* - sqprintf(result,"filename=%s",filename().c_str()); - */ - return result; - } - std::string channelName(int n) - { - char chname[1024]; - sprintf(chname, "%s%02d", _name.c_str(), n); - return chname; - } - void addChannel() - { - Synth_BUS_DOWNLINK input; - MixerChannel channel = SubClass(_type); - Synth_AMAN_PLAY output(amClient); - - std::string chname = channelName(_channels.size()+1); - input.busname(chname); - channel.name(chname); - - input.start(); - channel.start(); - output.start(); - - connect(input, channel); - connect(channel, output); - - _inputs.push_back(input); - _channels.push_back(channel); - _outputs.push_back(output); - } - - void delChannel() - { - unsigned long cc = _channels.size()-1; - - _inputs.resize(cc); - _channels.resize(cc); - _outputs.resize(cc); - } -}; -REGISTER_IMPLEMENTATION(MixerItem_impl); -} - -using namespace Environment; - -typedef WeakReference VBox_wref; - -class MixerItemGui_impl : virtual public MixerItemGui_skel { -private: - bool _active; - long _channelCount; - std::string _type; - MixerItem _item; - - /* widgets */ - VBox_wref _widget; - HBox hbox, channel_hbox; - SpinBox spinbox; - LineEdit name; - ComboBox typebox; - GenericGuiFactory guiFactory; - std::vector channelWidgets; - -public: - MixerItemGui self() { return MixerItemGui::_from_base(_copy()); } - - void updateChannelGui() - { - if(channelWidgets.size() > (unsigned)_item.channelCount()) - channelWidgets.resize(_item.channelCount()); - else - { - std::vector *channels = _item.channels(); - for(unsigned int i = channelWidgets.size(); i < channels->size(); ++i) - { - Widget w = guiFactory.createGui((*channels)[i]); - if(!w.isNull()) - { - w.parent(channel_hbox); - w.show(); - channelWidgets.push_back(w); - } - } - } - } - - void redoGui() - { - VBox vbox = _widget; - if(vbox.isNull()) - arts_warning("update with vbox null"); - if(_item.isNull()) - arts_warning("update with _item null"); - if(!_item.isNull() && !vbox.isNull()) - { - hbox = HBox(); - hbox.parent(vbox); - hbox.show(); - - spinbox = SpinBox(); - spinbox.caption(i18n("channels").utf8().data()); - spinbox.min(0); spinbox.max(32); - spinbox.value(_item.channelCount()); - spinbox.parent(hbox); - spinbox.show(); - connect(spinbox,"value_changed", _item, "channelCount"); - - name = LineEdit(); - name.caption(i18n("name").utf8().data()); - name.text(_item.name()); - name.parent(hbox); - name.show(); - connect(name,"text_changed", _item, "name"); - - typebox = ComboBox(); - typebox.caption(i18n("type").utf8().data()); - std::vector choices; - TraderQuery query; - query.supports("Interface", "Arts::Environment::MixerChannel"); - std::vector *queryResults = query.query(); - for(std::vector::iterator it = queryResults->begin(); it != queryResults->end(); ++it) - choices.push_back(it->interfaceName()); - delete queryResults; - typebox.choices(choices); - typebox.value(_type); - typebox.parent(hbox); - typebox.show(); - connect(typebox,"value_changed", _item, "type"); - - channel_hbox = HBox(); - channel_hbox.parent(vbox); - channel_hbox.show(); - - channelWidgets.clear(); - updateChannelGui(); - - vbox.show(); - } - else - { - /* FIXME: maybe insert a "dead" label here */ - if(!vbox.isNull()) - vbox.show(); - channel_hbox = HBox::null(); - hbox = HBox::null(); - spinbox = SpinBox::null(); - name = LineEdit::null(); - typebox = ComboBox::null(); - channelWidgets.clear(); - } - } - - bool active() { return _active; } - void active(bool newActive) - { - if(newActive != _active) - { - _active = newActive; - if(!newActive) - _item = MixerItem::null(); - redoGui(); - } - } - long channelCount() { return _channelCount; } - void channelCount(long ch) - { - if(_channelCount != ch) - { - _channelCount = ch; - updateChannelGui(); - } - } - std::string type() { - return _type; - } - void type(const std::string& t) - { - if(_type != t) - { - _type = t; - //redoGui(); - } - } - Widget initialize(MixerItem item) - { - TDEGlobal::locale()->insertCatalogue( "artsmodules" ); - VBox vbox; - vbox._addChild(self(),"the_gui_updating_widget"); - - _widget = vbox; - _item = item; - _active = item.active(); - _type = item.type(); - _channelCount = item.channelCount(); - - if(!_item.isNull()) - { - connect(_item, "channelCount_changed", self(), "channelCount"); - connect(_item, "type_changed", self(), "type"); - connect(_item, "active_changed", self(), "active"); - } - redoGui(); - - return vbox; - } -}; - -REGISTER_IMPLEMENTATION(MixerItemGui_impl); - -class MixerGuiFactory_impl : virtual public MixerGuiFactory_skel -{ -public: - Widget createGui(Object object) - { - TDEGlobal::locale()->insertCatalogue( "artsmodules" ); - arts_return_val_if_fail(!object.isNull(), Arts::Widget::null()); - - std::string iface = object._interfaceName(); - arts_return_val_if_fail(iface == "Arts::Environment::MixerItem", - Arts::Widget::null()); - if(iface == "Arts::Environment::MixerItem") - { - MixerItem mixerItem = DynamicCast(object); - arts_return_val_if_fail(!mixerItem.isNull(), Arts::Widget::null()); - -#if 0 - VBox vbox; - vbox.show(); - vbox.width(330); vbox.height(500); - - HBox hbox; - hbox.show(); - hbox.width(330); hbox.height(50); - hbox.parent(vbox); - vbox._addChild(hbox,"hbox"); - - SpinBox spinbox; - spinbox.caption(i18n("channels").utf8().data()); - spinbox.min(0); spinbox.max(32); - spinbox.value(mixerItem.channelCount()); - spinbox.parent(hbox); - spinbox.show(); - connect(spinbox,"value_changed", mixerItem, "channelCount"); - hbox._addChild(spinbox,"channelsWidget"); - - LineEdit name; - name.caption(i18n("name").utf8().data()); - name.caption(mixerItem.name()); - name.parent(hbox); - name.show(); - connect(name,"caption_changed", mixerItem, "name"); - hbox._addChild(name,"nameWidget"); - - HBox channel_hbox; - channel_hbox.show(); - channel_hbox.width(330); hbox.height(450); - channel_hbox.parent(vbox); - vbox._addChild(channel_hbox,"channel_hbox"); - - GenericGuiFactory gf; - - std::vector *channels = mixerItem.channels(); - std::vector::iterator i; - for(i = channels->begin(); i != channels->end(); i++) - { - Widget w = gf.createGui(*i); - w.parent(channel_hbox); - channel_hbox._addChild(w,"channel"); - } -#endif - MixerItemGui gui; - return gui.initialize(mixerItem); - } - return Arts::Widget::null(); - } -}; -REGISTER_IMPLEMENTATION(MixerGuiFactory_impl); -} diff --git a/arts/modules/common/env_mixeritem_impl.cpp b/arts/modules/common/env_mixeritem_impl.cpp new file mode 100644 index 00000000..93735dd5 --- /dev/null +++ b/arts/modules/common/env_mixeritem_impl.cpp @@ -0,0 +1,367 @@ +#include "artsmodulescommon.h" +#include "debug.h" +#include "env_item_impl.h" +#include "connect.h" +#include "../runtime/sequenceutils.h" +#include +#include +#include + +#include + +namespace Arts { +namespace Environment { + +class MixerItem_impl : virtual public MixerItem_skel, + virtual public Item_impl +{ +protected: + std::vector _inputs; + std::vector _channels; + std::vector _outputs; + std::string _name; + std::string _type; + AudioManagerClient amClient; + +public: + MixerItem_impl() + : _name("mixer"), _type("Arts::SimpleMixerChannel"), + amClient(amPlay, "Mixer (mixer)","mixer_mixer") + { + } + // readonly attribute sequence channels; + std::vector *channels() { + return new std::vector(_channels); + } + // attribute long channelCount; + void channelCount(long newChannelCount) + { + if((unsigned long)newChannelCount != _channels.size()) + { + while(_channels.size() < (unsigned long)newChannelCount) addChannel(); + while(_channels.size() > (unsigned long)newChannelCount) delChannel(); + channelCount_changed(newChannelCount); + } + } + long channelCount() { return _channels.size(); } + // attribute string name; + void name(const std::string& newName) { + if(newName != _name) + { + _name = newName; + amClient.title(i18n("Mixer (\"%1\")").arg(TQString::fromUtf8(_name.c_str())).utf8().data()); + amClient.autoRestoreID("mixer_"+_name); + for(unsigned int i = 0; i < _inputs.size(); i++) + _inputs[i].busname(channelName(i)); + name_changed(newName); + } + } + std::string name() { return _name; } + // attribute string type; + void type(const std::string& newType) { + if(newType != _type) + { + _type = newType; + type_changed(newType); + } + } + std::string type() { return _type; } + void loadFromList(const std::vector& /*list*/) + { + /* + unsigned long i; + std::string cmd,param; + for(i=0;i *saveToList() + { + std::vector *result = new std::vector; + /* + sqprintf(result,"filename=%s",filename().c_str()); + */ + return result; + } + std::string channelName(int n) + { + char chname[1024]; + sprintf(chname, "%s%02d", _name.c_str(), n); + return chname; + } + void addChannel() + { + Synth_BUS_DOWNLINK input; + MixerChannel channel = SubClass(_type); + Synth_AMAN_PLAY output(amClient); + + std::string chname = channelName(_channels.size()+1); + input.busname(chname); + channel.name(chname); + + input.start(); + channel.start(); + output.start(); + + connect(input, channel); + connect(channel, output); + + _inputs.push_back(input); + _channels.push_back(channel); + _outputs.push_back(output); + } + + void delChannel() + { + unsigned long cc = _channels.size()-1; + + _inputs.resize(cc); + _channels.resize(cc); + _outputs.resize(cc); + } +}; +REGISTER_IMPLEMENTATION(MixerItem_impl); +} + +using namespace Environment; + +typedef WeakReference VBox_wref; + +class MixerItemGui_impl : virtual public MixerItemGui_skel { +private: + bool _active; + long _channelCount; + std::string _type; + MixerItem _item; + + /* widgets */ + VBox_wref _widget; + HBox hbox, channel_hbox; + SpinBox spinbox; + LineEdit name; + ComboBox typebox; + GenericGuiFactory guiFactory; + std::vector channelWidgets; + +public: + MixerItemGui self() { return MixerItemGui::_from_base(_copy()); } + + void updateChannelGui() + { + if(channelWidgets.size() > (unsigned)_item.channelCount()) + channelWidgets.resize(_item.channelCount()); + else + { + std::vector *channels = _item.channels(); + for(unsigned int i = channelWidgets.size(); i < channels->size(); ++i) + { + Widget w = guiFactory.createGui((*channels)[i]); + if(!w.isNull()) + { + w.parent(channel_hbox); + w.show(); + channelWidgets.push_back(w); + } + } + } + } + + void redoGui() + { + VBox vbox = _widget; + if(vbox.isNull()) + arts_warning("update with vbox null"); + if(_item.isNull()) + arts_warning("update with _item null"); + if(!_item.isNull() && !vbox.isNull()) + { + hbox = HBox(); + hbox.parent(vbox); + hbox.show(); + + spinbox = SpinBox(); + spinbox.caption(i18n("channels").utf8().data()); + spinbox.min(0); spinbox.max(32); + spinbox.value(_item.channelCount()); + spinbox.parent(hbox); + spinbox.show(); + connect(spinbox,"value_changed", _item, "channelCount"); + + name = LineEdit(); + name.caption(i18n("name").utf8().data()); + name.text(_item.name()); + name.parent(hbox); + name.show(); + connect(name,"text_changed", _item, "name"); + + typebox = ComboBox(); + typebox.caption(i18n("type").utf8().data()); + std::vector choices; + TraderQuery query; + query.supports("Interface", "Arts::Environment::MixerChannel"); + std::vector *queryResults = query.query(); + for(std::vector::iterator it = queryResults->begin(); it != queryResults->end(); ++it) + choices.push_back(it->interfaceName()); + delete queryResults; + typebox.choices(choices); + typebox.value(_type); + typebox.parent(hbox); + typebox.show(); + connect(typebox,"value_changed", _item, "type"); + + channel_hbox = HBox(); + channel_hbox.parent(vbox); + channel_hbox.show(); + + channelWidgets.clear(); + updateChannelGui(); + + vbox.show(); + } + else + { + /* FIXME: maybe insert a "dead" label here */ + if(!vbox.isNull()) + vbox.show(); + channel_hbox = HBox::null(); + hbox = HBox::null(); + spinbox = SpinBox::null(); + name = LineEdit::null(); + typebox = ComboBox::null(); + channelWidgets.clear(); + } + } + + bool active() { return _active; } + void active(bool newActive) + { + if(newActive != _active) + { + _active = newActive; + if(!newActive) + _item = MixerItem::null(); + redoGui(); + } + } + long channelCount() { return _channelCount; } + void channelCount(long ch) + { + if(_channelCount != ch) + { + _channelCount = ch; + updateChannelGui(); + } + } + std::string type() { + return _type; + } + void type(const std::string& t) + { + if(_type != t) + { + _type = t; + //redoGui(); + } + } + Widget initialize(MixerItem item) + { + TDEGlobal::locale()->insertCatalogue( "artsmodules" ); + VBox vbox; + vbox._addChild(self(),"the_gui_updating_widget"); + + _widget = vbox; + _item = item; + _active = item.active(); + _type = item.type(); + _channelCount = item.channelCount(); + + if(!_item.isNull()) + { + connect(_item, "channelCount_changed", self(), "channelCount"); + connect(_item, "type_changed", self(), "type"); + connect(_item, "active_changed", self(), "active"); + } + redoGui(); + + return vbox; + } +}; + +REGISTER_IMPLEMENTATION(MixerItemGui_impl); + +class MixerGuiFactory_impl : virtual public MixerGuiFactory_skel +{ +public: + Widget createGui(Object object) + { + TDEGlobal::locale()->insertCatalogue( "artsmodules" ); + arts_return_val_if_fail(!object.isNull(), Arts::Widget::null()); + + std::string iface = object._interfaceName(); + arts_return_val_if_fail(iface == "Arts::Environment::MixerItem", + Arts::Widget::null()); + if(iface == "Arts::Environment::MixerItem") + { + MixerItem mixerItem = DynamicCast(object); + arts_return_val_if_fail(!mixerItem.isNull(), Arts::Widget::null()); + +#if 0 + VBox vbox; + vbox.show(); + vbox.width(330); vbox.height(500); + + HBox hbox; + hbox.show(); + hbox.width(330); hbox.height(50); + hbox.parent(vbox); + vbox._addChild(hbox,"hbox"); + + SpinBox spinbox; + spinbox.caption(i18n("channels").utf8().data()); + spinbox.min(0); spinbox.max(32); + spinbox.value(mixerItem.channelCount()); + spinbox.parent(hbox); + spinbox.show(); + connect(spinbox,"value_changed", mixerItem, "channelCount"); + hbox._addChild(spinbox,"channelsWidget"); + + LineEdit name; + name.caption(i18n("name").utf8().data()); + name.caption(mixerItem.name()); + name.parent(hbox); + name.show(); + connect(name,"caption_changed", mixerItem, "name"); + hbox._addChild(name,"nameWidget"); + + HBox channel_hbox; + channel_hbox.show(); + channel_hbox.width(330); hbox.height(450); + channel_hbox.parent(vbox); + vbox._addChild(channel_hbox,"channel_hbox"); + + GenericGuiFactory gf; + + std::vector *channels = mixerItem.channels(); + std::vector::iterator i; + for(i = channels->begin(); i != channels->end(); i++) + { + Widget w = gf.createGui(*i); + w.parent(channel_hbox); + channel_hbox._addChild(w,"channel"); + } +#endif + MixerItemGui gui; + return gui.initialize(mixerItem); + } + return Arts::Widget::null(); + } +}; +REGISTER_IMPLEMENTATION(MixerGuiFactory_impl); +} diff --git a/arts/modules/effects/CMakeLists.txt b/arts/modules/effects/CMakeLists.txt index 58c847d9..a5136f08 100644 --- a/arts/modules/effects/CMakeLists.txt +++ b/arts/modules/effects/CMakeLists.txt @@ -38,15 +38,15 @@ link_directories( tde_add_library( artsmoduleseffects SHARED AUTOMOC SOURCES - artsmoduleseffects.cc - fivebandmonocomplexeq_impl.cc - monostereoconversion_impl.cc - synth_stereo_pitch_shift_impl.cc synth_stereo_pitch_shift_fft_impl.cc - synth_voice_removal_impl.cc voiceremovalguifactory_impl.cc - synth_stereo_compressor_impl.cc stereocompressorguifactory_impl.cc - synth_stereo_fir_equalizer_impl.cc - synth_freeverb_impl.cc freeverbguifactory_impl.cc - effect_wavecapture_impl.cc + artsmoduleseffects.cpp + fivebandmonocomplexeq_impl.cpp + monostereoconversion_impl.cpp + synth_stereo_pitch_shift_impl.cpp synth_stereo_pitch_shift_fft_impl.cpp + synth_voice_removal_impl.cpp voiceremovalguifactory_impl.cpp + synth_stereo_compressor_impl.cpp stereocompressorguifactory_impl.cpp + synth_stereo_fir_equalizer_impl.cpp + synth_freeverb_impl.cpp freeverbguifactory_impl.cpp + effect_wavecapture_impl.cpp kstereovolumecontrolgui_impl.cpp stereovolumecontrolguifactory_impl.cpp VERSION 0.0.0 EMBED @@ -60,7 +60,7 @@ tde_add_library( artsmoduleseffects SHARED AUTOMOC add_custom_command( OUTPUT - artsmoduleseffects.cc artsmoduleseffects.h + artsmoduleseffects.cpp artsmoduleseffects.h artsmoduleseffects.mcopclass artsmoduleseffects.mcoptype COMMAND ${ARTS_MCOPIDL_EXECUTABLE} -t -I${CMAKE_SOURCE_DIR}/arts/gui/common diff --git a/arts/modules/effects/Makefile.am b/arts/modules/effects/Makefile.am index d5d54aad..a2c3f31f 100644 --- a/arts/modules/effects/Makefile.am +++ b/arts/modules/effects/Makefile.am @@ -20,15 +20,15 @@ INCLUDES = \ lib_LTLIBRARIES = libartsmoduleseffects.la -libartsmoduleseffects_la_SOURCES = artsmoduleseffects.cc \ - fivebandmonocomplexeq_impl.cc \ - monostereoconversion_impl.cc \ - synth_stereo_pitch_shift_impl.cc synth_stereo_pitch_shift_fft_impl.cc \ - synth_voice_removal_impl.cc voiceremovalguifactory_impl.cc \ - synth_stereo_compressor_impl.cc stereocompressorguifactory_impl.cc \ - synth_stereo_fir_equalizer_impl.cc \ - synth_freeverb_impl.cc freeverbguifactory_impl.cc \ - effect_wavecapture_impl.cc \ +libartsmoduleseffects_la_SOURCES = artsmoduleseffects.cpp \ + fivebandmonocomplexeq_impl.cpp \ + monostereoconversion_impl.cpp \ + synth_stereo_pitch_shift_impl.cpp synth_stereo_pitch_shift_fft_impl.cpp \ + synth_voice_removal_impl.cpp voiceremovalguifactory_impl.cpp \ + synth_stereo_compressor_impl.cpp stereocompressorguifactory_impl.cpp \ + synth_stereo_fir_equalizer_impl.cpp \ + synth_freeverb_impl.cpp freeverbguifactory_impl.cpp \ + effect_wavecapture_impl.cpp \ kstereovolumecontrolgui_impl.cpp stereovolumecontrolguifactory_impl.cpp libartsmoduleseffects_la_COMPILE_FIRST = ../../gui/common/artsgui.h \ ../common/artsmodulescommon.h ../../midi/artsmidi.h ../synth/artsmodulessynth.h \ @@ -44,10 +44,10 @@ libartsmoduleseffects_la_LDFLAGS = $(all_libraries) -L$(arts_libraries) -no-unde METASOURCES=AUTO -artsmoduleseffects.cc artsmoduleseffects.h artsmoduleseffects.mcoptype artsmoduleseffects.mcopclass: $(srcdir)/artsmoduleseffects.idl $(MCOPIDL) +artsmoduleseffects.cpp artsmoduleseffects.h artsmoduleseffects.mcoptype artsmoduleseffects.mcopclass: $(srcdir)/artsmoduleseffects.idl $(MCOPIDL) $(MCOPIDL) -t $(INCLUDES) $(srcdir)/artsmoduleseffects.idl -DISTCLEANFILES= artsmoduleseffects.cc artsmoduleseffects.h artsmoduleseffects.mcop* +DISTCLEANFILES= artsmoduleseffects.cpp artsmoduleseffects.h artsmoduleseffects.mcop* artsincludedir = $(includedir)/arts artsinclude_HEADERS = artsmoduleseffects.h artsmoduleseffects.idl diff --git a/arts/modules/effects/artsmoduleseffects.idl b/arts/modules/effects/artsmoduleseffects.idl index 13e978d9..9d7cd871 100644 --- a/arts/modules/effects/artsmoduleseffects.idl +++ b/arts/modules/effects/artsmoduleseffects.idl @@ -18,7 +18,7 @@ */ /* - * DISCLAIMER: The interfaces in envmixer.idl (and the derived .cc/.h files) + * DISCLAIMER: The interfaces in envmixer.idl (and the derived .cpp/.h files) * DO NOT GUARANTEE BINARY COMPATIBILITY YET. * * They are intended for developers. You shouldn't expect that applications in diff --git a/arts/modules/effects/effect_wavecapture_impl.cc b/arts/modules/effects/effect_wavecapture_impl.cc deleted file mode 100644 index 639307a8..00000000 --- a/arts/modules/effects/effect_wavecapture_impl.cc +++ /dev/null @@ -1,61 +0,0 @@ -/* - Copyright (C) 2001 Matthias Kretz - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -/* $Id$ */ - -#include "artsmoduleseffects.h" -#include -#include - -using namespace std; -namespace Arts { - -class Effect_WAVECAPTURE_impl : virtual public Effect_WAVECAPTURE_skel, - virtual public StdSynthModule -{ -protected: - Synth_CAPTURE_WAV _capture; - -public: - void streamStart(); - void streamEnd(); - string filename() { return _capture.filename(); } - void filename( const string &newFilename ) { _capture.filename( newFilename ); } -}; - -void Effect_WAVECAPTURE_impl::streamStart() -{ - _capture.start(); - _node()->virtualize("inleft",_capture._node(),"left"); - _node()->virtualize("inright",_capture._node(),"right"); - _node()->virtualize("outleft",_node(),"inleft"); - _node()->virtualize("outright",_node(),"inright"); -} - -void Effect_WAVECAPTURE_impl::streamEnd() -{ - _node()->devirtualize("inleft",_capture._node(),"left"); - _node()->devirtualize("inright",_capture._node(),"right"); - _node()->devirtualize("outleft",_node(),"inleft"); - _node()->devirtualize("outright",_node(),"inright"); - _capture.stop(); -} - -REGISTER_IMPLEMENTATION(Effect_WAVECAPTURE_impl); - -} diff --git a/arts/modules/effects/effect_wavecapture_impl.cpp b/arts/modules/effects/effect_wavecapture_impl.cpp new file mode 100644 index 00000000..639307a8 --- /dev/null +++ b/arts/modules/effects/effect_wavecapture_impl.cpp @@ -0,0 +1,61 @@ +/* + Copyright (C) 2001 Matthias Kretz + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +/* $Id$ */ + +#include "artsmoduleseffects.h" +#include +#include + +using namespace std; +namespace Arts { + +class Effect_WAVECAPTURE_impl : virtual public Effect_WAVECAPTURE_skel, + virtual public StdSynthModule +{ +protected: + Synth_CAPTURE_WAV _capture; + +public: + void streamStart(); + void streamEnd(); + string filename() { return _capture.filename(); } + void filename( const string &newFilename ) { _capture.filename( newFilename ); } +}; + +void Effect_WAVECAPTURE_impl::streamStart() +{ + _capture.start(); + _node()->virtualize("inleft",_capture._node(),"left"); + _node()->virtualize("inright",_capture._node(),"right"); + _node()->virtualize("outleft",_node(),"inleft"); + _node()->virtualize("outright",_node(),"inright"); +} + +void Effect_WAVECAPTURE_impl::streamEnd() +{ + _node()->devirtualize("inleft",_capture._node(),"left"); + _node()->devirtualize("inright",_capture._node(),"right"); + _node()->devirtualize("outleft",_node(),"inleft"); + _node()->devirtualize("outright",_node(),"inright"); + _capture.stop(); +} + +REGISTER_IMPLEMENTATION(Effect_WAVECAPTURE_impl); + +} diff --git a/arts/modules/effects/fivebandmonocomplexeq_impl.cc b/arts/modules/effects/fivebandmonocomplexeq_impl.cc deleted file mode 100644 index 59d0ef44..00000000 --- a/arts/modules/effects/fivebandmonocomplexeq_impl.cc +++ /dev/null @@ -1,208 +0,0 @@ -/* - - Copyright ( C ) 2002 Arnold Krille - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or ( at your option ) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include -#include -#include -#include -#include -#include - -#include -#include - -namespace Arts { - -class FiveBandMonoComplexEQ_impl : virtual public FiveBandMonoComplexEQ_skel, - virtual public StdSynthModule -{ -private: - Arts::StereoToMono _s2m; - Arts::MonoToStereo _m2s; - Arts::Synth_STD_EQUALIZER _low, _mid1, _mid2, _mid3, _high; -public: - FiveBandMonoComplexEQ_impl() {} - - Arts::StereoToMono s2m() { return _s2m; } - Arts::MonoToStereo m2s() { return _m2s; } - - float lowfreq() { return _low.frequency(); } - void lowfreq( float n ) { _low.frequency( n ); }; - float lowq() { return _low.q(); } - void lowq( float n ) { _low.q( n ); }; - float lowgain() { return _low.low(); } - void lowgain( float n ) { _low.low( n ); }; - - float mid1freq() { return _mid1.frequency(); } - void mid1freq( float n ) { _mid1.frequency( n ); }; - float mid1q() { return _mid1.q(); } - void mid1q( float n ) { _mid1.q( n ); }; - float mid1gain() { return _mid1.mid(); } - void mid1gain( float n ) { _mid1.mid( n ); }; - - float mid2freq() { return _mid2.frequency(); } - void mid2freq( float n ) { _mid2.frequency( n ); }; - float mid2q() { return _mid2.q(); } - void mid2q( float n ) { _mid2.q( n ); }; - float mid2gain() { return _mid2.mid(); } - void mid2gain( float n ) { _mid2.mid( n ); }; - - float mid3freq() { return _mid3.frequency(); } - void mid3freq( float n ) { _mid3.frequency( n ); }; - float mid3q() { return _mid3.q(); } - void mid3q( float n ) { _mid3.q( n ); }; - float mid3gain() { return _mid3.mid(); } - void mid3gain( float n ) { _mid3.mid( n ); }; - - float highfreq() { return _high.frequency(); } - void highfreq( float n ) { _high.frequency( n ); }; - float highq() { return _high.q(); } - void highq( float n ) { _high.q( n ); }; - float highgain() { return _high.high(); } - void highgain( float n ) { _high.high( n ); }; - - void streamInit() - { - _s2m.start(); _low.start(); _mid1.start(); _mid2.start(); _mid3.start(); _high.start(); _m2s.start(); - - _node()->virtualize( "inleft", _s2m._node(), "inleft" ); - _node()->virtualize( "inright", _s2m._node(), "inright" ); - connect( _s2m, "outmono", _low, "invalue" ); - connect( _low, "outvalue", _mid1, "invalue" ); - connect( _mid1, "outvalue", _mid2, "invalue" ); - connect( _mid2, "outvalue", _mid3, "invalue" ); - connect( _mid3, "outvalue", _high, "invalue" ); - connect( _high, "outvalue", _m2s, "inmono" ); - _node()->virtualize( "outleft", _m2s._node(), "outleft" ); - _node()->virtualize( "outright", _m2s._node(), "outright" ); - } -}; -REGISTER_IMPLEMENTATION( FiveBandMonoComplexEQ_impl ); - -class FiveBandMonoComplexEQGuiFactory_impl : virtual public FiveBandMonoComplexEQGuiFactory_skel -{ -public: - Arts::Widget createGui( Arts::Object object ) - { - TDEGlobal::locale()->insertCatalogue( "artsmodules" ); - - arts_return_val_if_fail( !object.isNull(), Arts::Widget::null() ); - FiveBandMonoComplexEQ ch = DynamicCast( object ); - arts_return_val_if_fail( !ch.isNull(), Arts::Widget::null() ); - - Arts::LayoutBox hbox; - hbox.direction( Arts::LeftToRight ); - hbox.layoutmargin( 5 ); hbox.spacing( 5 ); - - Arts::Poti lowgain; lowgain.caption( i18n( "Low Gain" ).utf8().data() ); - lowgain.min( -24 ); lowgain.max( 24 ); - lowgain.value( ch.lowgain() ); connect( lowgain, "value_changed", ch, "lowgain" ); - hbox.addWidget( lowgain ); - PopupBox low; - low.height( 100 ); low.direction( LeftToRight ); - hbox.addWidget( low ); - Arts::VBox lowbox; low.widget( lowbox ); - Arts::Poti lowfreq; lowfreq.color( "grey" ); lowfreq.caption( i18n( "Low Freq" ).utf8().data() ); - lowfreq.min( 20 ); lowfreq.max( 1000 ); - lowfreq.value( ch.lowfreq() ); connect( lowfreq, "value_changed", ch, "lowfreq" ); - lowfreq.parent( lowbox ); lowbox._addChild( lowfreq , "" ); - Arts::Poti lowq; lowq.color( "grey" ); lowq.caption( i18n( "Low Q" ).utf8().data() ); - lowq.min( 0.01 ); lowq.max( 10 ); - lowq.value( ch.lowq() ); connect( lowq, "value_changed", ch, "lowq" ); - lowq.parent( lowbox ); lowbox._addChild( lowq , "" ); - - Arts::Poti mid1gain; mid1gain.caption( i18n( "Mid1 Gain" ).utf8().data() ); - mid1gain.min( -24 ); mid1gain.max( 24 ); - mid1gain.value( ch.mid1gain() ); connect( mid1gain, "value_changed", ch, "mid1gain" ); - hbox.addWidget( mid1gain ); - PopupBox mid1; - mid1.height( 100 ); mid1.direction( LeftToRight ); - hbox.addWidget( mid1 ); - Arts::VBox mid1box; mid1.widget( mid1box ); - Arts::Poti mid1freq; mid1freq.color( "grey" ); mid1freq.caption( i18n( "Mid1 Freq" ).utf8().data() ); - mid1freq.min( 20 ); mid1freq.max( 5000 ); - mid1freq.value( ch.mid1freq() ); connect( mid1freq, "value_changed", ch, "mid1freq" ); - mid1freq.parent( mid1box ); mid1box._addChild( mid1freq , "" ); - Arts::Poti mid1q; mid1q.color( "grey" ); mid1q.caption( i18n( "Mid1 Q" ).utf8().data() ); - mid1q.min( 0.01 ); mid1q.max( 10 ); - mid1q.value( ch.mid1q() ); connect( mid1q, "value_changed", ch, "mid1q" ); - mid1q.parent( mid1box ); mid1box._addChild( mid1q , "" ); - - Arts::Poti mid2gain; mid2gain.caption( i18n( "Mid2 Gain" ).utf8().data() ); - mid2gain.min( -24 ); mid2gain.max( 24 ); - mid2gain.value( ch.mid2gain() ); connect( mid2gain, "value_changed", ch, "mid2gain" ); - hbox.addWidget( mid2gain ); - PopupBox mid2; - mid2.height( 100 ); mid2.direction( LeftToRight ); - hbox.addWidget( mid2 ); - Arts::VBox mid2box; mid2.widget( mid2box ); - Arts::Poti mid2freq; mid2freq.color( "grey" ); mid2freq.caption( i18n( "Mid2 Freq" ).utf8().data() ); - mid2freq.min( 20 ); mid2freq.max( 10000 ); - mid2freq.value( ch.mid2freq() ); connect( mid2freq, "value_changed", ch, "mid2freq" ); - mid2freq.parent( mid2box ); mid2box._addChild( mid2freq , "" ); - Arts::Poti mid2q; mid2q.color( "grey" ); mid2q.caption( i18n( "Mid2 Q" ).utf8().data() ); - mid2q.min( 0.01 ); mid2q.max( 10 ); - mid2q.value( ch.mid2q() ); connect( mid2q, "value_changed", ch, "mid2q" ); - mid2q.parent( mid2box ); mid2box._addChild( mid2q , "" ); - - Arts::Poti mid3gain; mid3gain.caption( i18n( "Mid3 Gain" ).utf8().data() ); - mid3gain.min( -24 ); mid3gain.max( 24 ); - mid3gain.value( ch.mid3gain() ); connect( mid3gain, "value_changed", ch, "mid3gain" ); - hbox.addWidget( mid3gain ); - PopupBox mid3; - mid3.height( 100 ); mid3.direction( LeftToRight ); - hbox.addWidget( mid3 ); - Arts::VBox mid3box; mid3.widget( mid3box ); - Arts::Poti mid3freq; mid3freq.color( "grey" ); mid3freq.caption( i18n( "Mid3 Freq" ).utf8().data() ); - mid3freq.min( 1000 ); mid3freq.max( 10000 ); - mid3freq.value( ch.mid3freq() ); connect( mid3freq, "value_changed", ch, "mid3freq" ); - mid3freq.parent( mid3box ); mid3box._addChild( mid3freq , "" ); - Arts::Poti mid3q; mid3q.color( "grey" ); mid3q.caption( i18n( "Mid3 Q" ).utf8().data() ); - mid3q.min( 0.01 ); mid3q.max( 10 ); - mid3q.value( ch.mid3q() ); connect( mid3q, "value_changed", ch, "mid3q" ); - mid3q.parent( mid3box ); mid3box._addChild( mid3q , "" ); - - Arts::Poti highgain; highgain.caption( i18n( "High Gain" ).utf8().data() ); - highgain.min( -24 ); highgain.max( 24 ); - highgain.value( ch.highgain() ); connect( highgain, "value_changed", ch, "highgain" ); - hbox.addWidget( highgain ); - PopupBox high; - high.height( 100 ); high.direction( LeftToRight ); - hbox.addWidget( high ); - Arts::VBox highbox; high.widget( highbox ); - Arts::Poti highfreq; highfreq.color( "grey" ); highfreq.caption( i18n( "High Freq" ).utf8().data() ); - highfreq.min( 5000 ); highfreq.max( 16000 ); - highfreq.value( ch.highfreq() ); connect( highfreq, "value_changed", ch, "highfreq" ); - highfreq.parent( highbox ); highbox._addChild( highfreq , "" ); - Arts::Poti highq; highq.color( "grey" ); highq.caption( i18n( "High Q" ).utf8().data() ); - highq.min( 0.01 ); highq.max( 10 ); - highq.value( ch.highq() ); connect( highq, "value_changed", ch, "highq" ); - highq.parent( highbox ); highbox._addChild( highq , "" ); - - hbox.addStretch( 100 ); - - return hbox; - } -}; -REGISTER_IMPLEMENTATION( FiveBandMonoComplexEQGuiFactory_impl ); - -} - diff --git a/arts/modules/effects/fivebandmonocomplexeq_impl.cpp b/arts/modules/effects/fivebandmonocomplexeq_impl.cpp new file mode 100644 index 00000000..59d0ef44 --- /dev/null +++ b/arts/modules/effects/fivebandmonocomplexeq_impl.cpp @@ -0,0 +1,208 @@ +/* + + Copyright ( C ) 2002 Arnold Krille + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or ( at your option ) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace Arts { + +class FiveBandMonoComplexEQ_impl : virtual public FiveBandMonoComplexEQ_skel, + virtual public StdSynthModule +{ +private: + Arts::StereoToMono _s2m; + Arts::MonoToStereo _m2s; + Arts::Synth_STD_EQUALIZER _low, _mid1, _mid2, _mid3, _high; +public: + FiveBandMonoComplexEQ_impl() {} + + Arts::StereoToMono s2m() { return _s2m; } + Arts::MonoToStereo m2s() { return _m2s; } + + float lowfreq() { return _low.frequency(); } + void lowfreq( float n ) { _low.frequency( n ); }; + float lowq() { return _low.q(); } + void lowq( float n ) { _low.q( n ); }; + float lowgain() { return _low.low(); } + void lowgain( float n ) { _low.low( n ); }; + + float mid1freq() { return _mid1.frequency(); } + void mid1freq( float n ) { _mid1.frequency( n ); }; + float mid1q() { return _mid1.q(); } + void mid1q( float n ) { _mid1.q( n ); }; + float mid1gain() { return _mid1.mid(); } + void mid1gain( float n ) { _mid1.mid( n ); }; + + float mid2freq() { return _mid2.frequency(); } + void mid2freq( float n ) { _mid2.frequency( n ); }; + float mid2q() { return _mid2.q(); } + void mid2q( float n ) { _mid2.q( n ); }; + float mid2gain() { return _mid2.mid(); } + void mid2gain( float n ) { _mid2.mid( n ); }; + + float mid3freq() { return _mid3.frequency(); } + void mid3freq( float n ) { _mid3.frequency( n ); }; + float mid3q() { return _mid3.q(); } + void mid3q( float n ) { _mid3.q( n ); }; + float mid3gain() { return _mid3.mid(); } + void mid3gain( float n ) { _mid3.mid( n ); }; + + float highfreq() { return _high.frequency(); } + void highfreq( float n ) { _high.frequency( n ); }; + float highq() { return _high.q(); } + void highq( float n ) { _high.q( n ); }; + float highgain() { return _high.high(); } + void highgain( float n ) { _high.high( n ); }; + + void streamInit() + { + _s2m.start(); _low.start(); _mid1.start(); _mid2.start(); _mid3.start(); _high.start(); _m2s.start(); + + _node()->virtualize( "inleft", _s2m._node(), "inleft" ); + _node()->virtualize( "inright", _s2m._node(), "inright" ); + connect( _s2m, "outmono", _low, "invalue" ); + connect( _low, "outvalue", _mid1, "invalue" ); + connect( _mid1, "outvalue", _mid2, "invalue" ); + connect( _mid2, "outvalue", _mid3, "invalue" ); + connect( _mid3, "outvalue", _high, "invalue" ); + connect( _high, "outvalue", _m2s, "inmono" ); + _node()->virtualize( "outleft", _m2s._node(), "outleft" ); + _node()->virtualize( "outright", _m2s._node(), "outright" ); + } +}; +REGISTER_IMPLEMENTATION( FiveBandMonoComplexEQ_impl ); + +class FiveBandMonoComplexEQGuiFactory_impl : virtual public FiveBandMonoComplexEQGuiFactory_skel +{ +public: + Arts::Widget createGui( Arts::Object object ) + { + TDEGlobal::locale()->insertCatalogue( "artsmodules" ); + + arts_return_val_if_fail( !object.isNull(), Arts::Widget::null() ); + FiveBandMonoComplexEQ ch = DynamicCast( object ); + arts_return_val_if_fail( !ch.isNull(), Arts::Widget::null() ); + + Arts::LayoutBox hbox; + hbox.direction( Arts::LeftToRight ); + hbox.layoutmargin( 5 ); hbox.spacing( 5 ); + + Arts::Poti lowgain; lowgain.caption( i18n( "Low Gain" ).utf8().data() ); + lowgain.min( -24 ); lowgain.max( 24 ); + lowgain.value( ch.lowgain() ); connect( lowgain, "value_changed", ch, "lowgain" ); + hbox.addWidget( lowgain ); + PopupBox low; + low.height( 100 ); low.direction( LeftToRight ); + hbox.addWidget( low ); + Arts::VBox lowbox; low.widget( lowbox ); + Arts::Poti lowfreq; lowfreq.color( "grey" ); lowfreq.caption( i18n( "Low Freq" ).utf8().data() ); + lowfreq.min( 20 ); lowfreq.max( 1000 ); + lowfreq.value( ch.lowfreq() ); connect( lowfreq, "value_changed", ch, "lowfreq" ); + lowfreq.parent( lowbox ); lowbox._addChild( lowfreq , "" ); + Arts::Poti lowq; lowq.color( "grey" ); lowq.caption( i18n( "Low Q" ).utf8().data() ); + lowq.min( 0.01 ); lowq.max( 10 ); + lowq.value( ch.lowq() ); connect( lowq, "value_changed", ch, "lowq" ); + lowq.parent( lowbox ); lowbox._addChild( lowq , "" ); + + Arts::Poti mid1gain; mid1gain.caption( i18n( "Mid1 Gain" ).utf8().data() ); + mid1gain.min( -24 ); mid1gain.max( 24 ); + mid1gain.value( ch.mid1gain() ); connect( mid1gain, "value_changed", ch, "mid1gain" ); + hbox.addWidget( mid1gain ); + PopupBox mid1; + mid1.height( 100 ); mid1.direction( LeftToRight ); + hbox.addWidget( mid1 ); + Arts::VBox mid1box; mid1.widget( mid1box ); + Arts::Poti mid1freq; mid1freq.color( "grey" ); mid1freq.caption( i18n( "Mid1 Freq" ).utf8().data() ); + mid1freq.min( 20 ); mid1freq.max( 5000 ); + mid1freq.value( ch.mid1freq() ); connect( mid1freq, "value_changed", ch, "mid1freq" ); + mid1freq.parent( mid1box ); mid1box._addChild( mid1freq , "" ); + Arts::Poti mid1q; mid1q.color( "grey" ); mid1q.caption( i18n( "Mid1 Q" ).utf8().data() ); + mid1q.min( 0.01 ); mid1q.max( 10 ); + mid1q.value( ch.mid1q() ); connect( mid1q, "value_changed", ch, "mid1q" ); + mid1q.parent( mid1box ); mid1box._addChild( mid1q , "" ); + + Arts::Poti mid2gain; mid2gain.caption( i18n( "Mid2 Gain" ).utf8().data() ); + mid2gain.min( -24 ); mid2gain.max( 24 ); + mid2gain.value( ch.mid2gain() ); connect( mid2gain, "value_changed", ch, "mid2gain" ); + hbox.addWidget( mid2gain ); + PopupBox mid2; + mid2.height( 100 ); mid2.direction( LeftToRight ); + hbox.addWidget( mid2 ); + Arts::VBox mid2box; mid2.widget( mid2box ); + Arts::Poti mid2freq; mid2freq.color( "grey" ); mid2freq.caption( i18n( "Mid2 Freq" ).utf8().data() ); + mid2freq.min( 20 ); mid2freq.max( 10000 ); + mid2freq.value( ch.mid2freq() ); connect( mid2freq, "value_changed", ch, "mid2freq" ); + mid2freq.parent( mid2box ); mid2box._addChild( mid2freq , "" ); + Arts::Poti mid2q; mid2q.color( "grey" ); mid2q.caption( i18n( "Mid2 Q" ).utf8().data() ); + mid2q.min( 0.01 ); mid2q.max( 10 ); + mid2q.value( ch.mid2q() ); connect( mid2q, "value_changed", ch, "mid2q" ); + mid2q.parent( mid2box ); mid2box._addChild( mid2q , "" ); + + Arts::Poti mid3gain; mid3gain.caption( i18n( "Mid3 Gain" ).utf8().data() ); + mid3gain.min( -24 ); mid3gain.max( 24 ); + mid3gain.value( ch.mid3gain() ); connect( mid3gain, "value_changed", ch, "mid3gain" ); + hbox.addWidget( mid3gain ); + PopupBox mid3; + mid3.height( 100 ); mid3.direction( LeftToRight ); + hbox.addWidget( mid3 ); + Arts::VBox mid3box; mid3.widget( mid3box ); + Arts::Poti mid3freq; mid3freq.color( "grey" ); mid3freq.caption( i18n( "Mid3 Freq" ).utf8().data() ); + mid3freq.min( 1000 ); mid3freq.max( 10000 ); + mid3freq.value( ch.mid3freq() ); connect( mid3freq, "value_changed", ch, "mid3freq" ); + mid3freq.parent( mid3box ); mid3box._addChild( mid3freq , "" ); + Arts::Poti mid3q; mid3q.color( "grey" ); mid3q.caption( i18n( "Mid3 Q" ).utf8().data() ); + mid3q.min( 0.01 ); mid3q.max( 10 ); + mid3q.value( ch.mid3q() ); connect( mid3q, "value_changed", ch, "mid3q" ); + mid3q.parent( mid3box ); mid3box._addChild( mid3q , "" ); + + Arts::Poti highgain; highgain.caption( i18n( "High Gain" ).utf8().data() ); + highgain.min( -24 ); highgain.max( 24 ); + highgain.value( ch.highgain() ); connect( highgain, "value_changed", ch, "highgain" ); + hbox.addWidget( highgain ); + PopupBox high; + high.height( 100 ); high.direction( LeftToRight ); + hbox.addWidget( high ); + Arts::VBox highbox; high.widget( highbox ); + Arts::Poti highfreq; highfreq.color( "grey" ); highfreq.caption( i18n( "High Freq" ).utf8().data() ); + highfreq.min( 5000 ); highfreq.max( 16000 ); + highfreq.value( ch.highfreq() ); connect( highfreq, "value_changed", ch, "highfreq" ); + highfreq.parent( highbox ); highbox._addChild( highfreq , "" ); + Arts::Poti highq; highq.color( "grey" ); highq.caption( i18n( "High Q" ).utf8().data() ); + highq.min( 0.01 ); highq.max( 10 ); + highq.value( ch.highq() ); connect( highq, "value_changed", ch, "highq" ); + highq.parent( highbox ); highbox._addChild( highq , "" ); + + hbox.addStretch( 100 ); + + return hbox; + } +}; +REGISTER_IMPLEMENTATION( FiveBandMonoComplexEQGuiFactory_impl ); + +} + diff --git a/arts/modules/effects/freeverb/allpass.cpp b/arts/modules/effects/freeverb/allpass.cpp index ca4d8bc5..850337e3 100644 --- a/arts/modules/effects/freeverb/allpass.cpp +++ b/arts/modules/effects/freeverb/allpass.cpp @@ -4,7 +4,7 @@ // http://www.dreampoint.co.uk // This code is public domain -#include "allpass.hpp" +#include "allpass.h" allpass::allpass() { diff --git a/arts/modules/effects/freeverb/allpass.h b/arts/modules/effects/freeverb/allpass.h new file mode 100644 index 00000000..853c7d41 --- /dev/null +++ b/arts/modules/effects/freeverb/allpass.h @@ -0,0 +1,48 @@ +// Allpass filter declaration +// +// Written by Jezar at Dreampoint, June 2000 +// http://www.dreampoint.co.uk +// This code is public domain + +#ifndef _allpass_ +#define _allpass_ +#include "denormals.h" + +class allpass +{ +public: + allpass(); + void setbuffer(float *buf, int size); + inline float process(float inp); + void mute(); + void setfeedback(float val); + float getfeedback(); +// private: + float feedback; + float *buffer; + int bufsize; + int bufidx; +}; + + +// Big to inline - but crucial for speed + +inline float allpass::process(float input) +{ + float output; + float bufout; + + bufout = buffer[bufidx]; + undenormalise(bufout); + + output = -input + bufout; + buffer[bufidx] = input + (bufout*feedback); + + if(++bufidx>=bufsize) bufidx = 0; + + return output; +} + +#endif//_allpass + +//ends diff --git a/arts/modules/effects/freeverb/allpass.hpp b/arts/modules/effects/freeverb/allpass.hpp deleted file mode 100644 index 853c7d41..00000000 --- a/arts/modules/effects/freeverb/allpass.hpp +++ /dev/null @@ -1,48 +0,0 @@ -// Allpass filter declaration -// -// Written by Jezar at Dreampoint, June 2000 -// http://www.dreampoint.co.uk -// This code is public domain - -#ifndef _allpass_ -#define _allpass_ -#include "denormals.h" - -class allpass -{ -public: - allpass(); - void setbuffer(float *buf, int size); - inline float process(float inp); - void mute(); - void setfeedback(float val); - float getfeedback(); -// private: - float feedback; - float *buffer; - int bufsize; - int bufidx; -}; - - -// Big to inline - but crucial for speed - -inline float allpass::process(float input) -{ - float output; - float bufout; - - bufout = buffer[bufidx]; - undenormalise(bufout); - - output = -input + bufout; - buffer[bufidx] = input + (bufout*feedback); - - if(++bufidx>=bufsize) bufidx = 0; - - return output; -} - -#endif//_allpass - -//ends diff --git a/arts/modules/effects/freeverb/comb.cpp b/arts/modules/effects/freeverb/comb.cpp index c05f5069..62be706d 100644 --- a/arts/modules/effects/freeverb/comb.cpp +++ b/arts/modules/effects/freeverb/comb.cpp @@ -4,7 +4,7 @@ // http://www.dreampoint.co.uk // This code is public domain -#include "comb.hpp" +#include "comb.h" comb::comb() { diff --git a/arts/modules/effects/freeverb/comb.h b/arts/modules/effects/freeverb/comb.h new file mode 100644 index 00000000..4a73b615 --- /dev/null +++ b/arts/modules/effects/freeverb/comb.h @@ -0,0 +1,55 @@ +// Comb filter class declaration +// +// Written by Jezar at Dreampoint, June 2000 +// http://www.dreampoint.co.uk +// This code is public domain + +#ifndef _comb_ +#define _comb_ + +#include "denormals.h" + +class comb +{ +public: + comb(); + void setbuffer(float *buf, int size); + inline float process(float inp); + void mute(); + void setdamp(float val); + float getdamp(); + void setfeedback(float val); + float getfeedback(); +private: + float feedback; + float filterstore; + float damp1; + float damp2; + float *buffer; + int bufsize; + int bufidx; +}; + + +// Big to inline - but crucial for speed + +inline float comb::process(float input) +{ + float output; + + output = buffer[bufidx]; + undenormalise(output); + + filterstore = (output*damp2) + (filterstore*damp1); + undenormalise(filterstore); + + buffer[bufidx] = input + (filterstore*feedback); + + if(++bufidx>=bufsize) bufidx = 0; + + return output; +} + +#endif //_comb_ + +//ends diff --git a/arts/modules/effects/freeverb/comb.hpp b/arts/modules/effects/freeverb/comb.hpp deleted file mode 100644 index 4a73b615..00000000 --- a/arts/modules/effects/freeverb/comb.hpp +++ /dev/null @@ -1,55 +0,0 @@ -// Comb filter class declaration -// -// Written by Jezar at Dreampoint, June 2000 -// http://www.dreampoint.co.uk -// This code is public domain - -#ifndef _comb_ -#define _comb_ - -#include "denormals.h" - -class comb -{ -public: - comb(); - void setbuffer(float *buf, int size); - inline float process(float inp); - void mute(); - void setdamp(float val); - float getdamp(); - void setfeedback(float val); - float getfeedback(); -private: - float feedback; - float filterstore; - float damp1; - float damp2; - float *buffer; - int bufsize; - int bufidx; -}; - - -// Big to inline - but crucial for speed - -inline float comb::process(float input) -{ - float output; - - output = buffer[bufidx]; - undenormalise(output); - - filterstore = (output*damp2) + (filterstore*damp1); - undenormalise(filterstore); - - buffer[bufidx] = input + (filterstore*feedback); - - if(++bufidx>=bufsize) bufidx = 0; - - return output; -} - -#endif //_comb_ - -//ends diff --git a/arts/modules/effects/freeverb/revmodel.cpp b/arts/modules/effects/freeverb/revmodel.cpp index 23a766cc..3688dd34 100644 --- a/arts/modules/effects/freeverb/revmodel.cpp +++ b/arts/modules/effects/freeverb/revmodel.cpp @@ -4,7 +4,7 @@ // http://www.dreampoint.co.uk // This code is public domain -#include "revmodel.hpp" +#include "revmodel.h" revmodel::revmodel() { diff --git a/arts/modules/effects/freeverb/revmodel.h b/arts/modules/effects/freeverb/revmodel.h new file mode 100644 index 00000000..aec39dfe --- /dev/null +++ b/arts/modules/effects/freeverb/revmodel.h @@ -0,0 +1,87 @@ +// Reverb model declaration +// +// Written by Jezar at Dreampoint, June 2000 +// http://www.dreampoint.co.uk +// This code is public domain + +#ifndef _revmodel_ +#define _revmodel_ + +#include "comb.h" +#include "allpass.h" +#include "tuning.h" + +class revmodel +{ +public: + revmodel(); + void mute(); + void processmix(float *inputL, float *inputR, float *outputL, float *outputR, long numsamples, int skip); + void processreplace(float *inputL, float *inputR, float *outputL, float *outputR, long numsamples, int skip); + void setroomsize(float value); + float getroomsize(); + void setdamp(float value); + float getdamp(); + void setwet(float value); + float getwet(); + void setdry(float value); + float getdry(); + void setwidth(float value); + float getwidth(); + void setmode(float value); + float getmode(); +private: + void update(); +private: + float gain; + float roomsize,roomsize1; + float damp,damp1; + float wet,wet1,wet2; + float dry; + float width; + float mode; + + // The following are all declared inline + // to remove the need for dynamic allocation + // with its subsequent error-checking messiness + + // Comb filters + comb combL[numcombs]; + comb combR[numcombs]; + + // Allpass filters + allpass allpassL[numallpasses]; + allpass allpassR[numallpasses]; + + // Buffers for the combs + float bufcombL1[combtuningL1]; + float bufcombR1[combtuningR1]; + float bufcombL2[combtuningL2]; + float bufcombR2[combtuningR2]; + float bufcombL3[combtuningL3]; + float bufcombR3[combtuningR3]; + float bufcombL4[combtuningL4]; + float bufcombR4[combtuningR4]; + float bufcombL5[combtuningL5]; + float bufcombR5[combtuningR5]; + float bufcombL6[combtuningL6]; + float bufcombR6[combtuningR6]; + float bufcombL7[combtuningL7]; + float bufcombR7[combtuningR7]; + float bufcombL8[combtuningL8]; + float bufcombR8[combtuningR8]; + + // Buffers for the allpasses + float bufallpassL1[allpasstuningL1]; + float bufallpassR1[allpasstuningR1]; + float bufallpassL2[allpasstuningL2]; + float bufallpassR2[allpasstuningR2]; + float bufallpassL3[allpasstuningL3]; + float bufallpassR3[allpasstuningR3]; + float bufallpassL4[allpasstuningL4]; + float bufallpassR4[allpasstuningR4]; +}; + +#endif//_revmodel_ + +//ends diff --git a/arts/modules/effects/freeverb/revmodel.hpp b/arts/modules/effects/freeverb/revmodel.hpp deleted file mode 100644 index ca6c89a0..00000000 --- a/arts/modules/effects/freeverb/revmodel.hpp +++ /dev/null @@ -1,87 +0,0 @@ -// Reverb model declaration -// -// Written by Jezar at Dreampoint, June 2000 -// http://www.dreampoint.co.uk -// This code is public domain - -#ifndef _revmodel_ -#define _revmodel_ - -#include "comb.hpp" -#include "allpass.hpp" -#include "tuning.h" - -class revmodel -{ -public: - revmodel(); - void mute(); - void processmix(float *inputL, float *inputR, float *outputL, float *outputR, long numsamples, int skip); - void processreplace(float *inputL, float *inputR, float *outputL, float *outputR, long numsamples, int skip); - void setroomsize(float value); - float getroomsize(); - void setdamp(float value); - float getdamp(); - void setwet(float value); - float getwet(); - void setdry(float value); - float getdry(); - void setwidth(float value); - float getwidth(); - void setmode(float value); - float getmode(); -private: - void update(); -private: - float gain; - float roomsize,roomsize1; - float damp,damp1; - float wet,wet1,wet2; - float dry; - float width; - float mode; - - // The following are all declared inline - // to remove the need for dynamic allocation - // with its subsequent error-checking messiness - - // Comb filters - comb combL[numcombs]; - comb combR[numcombs]; - - // Allpass filters - allpass allpassL[numallpasses]; - allpass allpassR[numallpasses]; - - // Buffers for the combs - float bufcombL1[combtuningL1]; - float bufcombR1[combtuningR1]; - float bufcombL2[combtuningL2]; - float bufcombR2[combtuningR2]; - float bufcombL3[combtuningL3]; - float bufcombR3[combtuningR3]; - float bufcombL4[combtuningL4]; - float bufcombR4[combtuningR4]; - float bufcombL5[combtuningL5]; - float bufcombR5[combtuningR5]; - float bufcombL6[combtuningL6]; - float bufcombR6[combtuningR6]; - float bufcombL7[combtuningL7]; - float bufcombR7[combtuningR7]; - float bufcombL8[combtuningL8]; - float bufcombR8[combtuningR8]; - - // Buffers for the allpasses - float bufallpassL1[allpasstuningL1]; - float bufallpassR1[allpasstuningR1]; - float bufallpassL2[allpasstuningL2]; - float bufallpassR2[allpasstuningR2]; - float bufallpassL3[allpasstuningL3]; - float bufallpassR3[allpasstuningR3]; - float bufallpassL4[allpasstuningL4]; - float bufallpassR4[allpasstuningR4]; -}; - -#endif//_revmodel_ - -//ends diff --git a/arts/modules/effects/freeverbguifactory_impl.cc b/arts/modules/effects/freeverbguifactory_impl.cc deleted file mode 100644 index 4b5d4d34..00000000 --- a/arts/modules/effects/freeverbguifactory_impl.cc +++ /dev/null @@ -1,107 +0,0 @@ - /* - - Copyright (C) 2001 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "artsmoduleseffects.h" -#include "debug.h" -#include "connect.h" - -#include -#include - -using namespace std; -using namespace Arts; - -namespace Arts { - -class FreeverbGuiFactory_impl : public FreeverbGuiFactory_skel -{ -public: - Widget createGui(Object freeverb); -}; - -REGISTER_IMPLEMENTATION(FreeverbGuiFactory_impl); - -} - -Widget FreeverbGuiFactory_impl::createGui(Object object) -{ - TDEGlobal::locale()->insertCatalogue( "artsmodules" ); - arts_return_val_if_fail(!object.isNull(), Arts::Widget::null()); - - Synth_FREEVERB freeverb = DynamicCast(object); - arts_return_val_if_fail(!freeverb.isNull(), Arts::Widget::null()); - - HBox hbox; - hbox.width(330); hbox.height(80); hbox.show(); - - Poti roomsize; - roomsize.x(20); roomsize.y(10); roomsize.caption(i18n("roomsize").utf8().data()); - roomsize.color("red"); roomsize.min(0); roomsize.max(1); - roomsize.value(freeverb.roomsize()); - roomsize.range(100); - roomsize.parent(hbox); - roomsize.show(); - connect(roomsize,"value_changed", freeverb, "roomsize"); - hbox._addChild(roomsize,"roomsizeWidget"); - - Poti damp; - damp.x(80); damp.y(10); damp.caption(i18n("damp").utf8().data()); - damp.color("red"); damp.min(0); damp.max(1); - damp.value(freeverb.damp()); - damp.range(100); - damp.parent(hbox); - damp.show(); - connect(damp,"value_changed", freeverb, "damp"); - hbox._addChild(damp,"dampWidget"); - - Poti wet; - wet.x(140); wet.y(10); wet.caption(i18n("wet").utf8().data()); - wet.color("red"); wet.min(0); wet.max(1); - wet.value(freeverb.wet()); - wet.range(100); - wet.parent(hbox); - wet.show(); - connect(wet,"value_changed", freeverb, "wet"); - hbox._addChild(wet,"wetWidget"); - - Poti dry; - dry.x(200); dry.y(10); dry.caption(i18n("dry").utf8().data()); - dry.color("red"); dry.min(0); dry.max(1); - dry.value(freeverb.dry()); - dry.range(100); - dry.parent(hbox); - dry.show(); - connect(dry,"value_changed", freeverb, "dry"); - hbox._addChild(dry,"dryWidget"); - - Poti width; - width.x(260); width.y(10); width.caption(i18n("width").utf8().data()); - width.color("red"); width.min(0); width.max(1); - width.value(freeverb.width()); - width.range(100); - width.parent(hbox); - width.show(); - connect(width,"value_changed", freeverb, "width"); - hbox._addChild(width,"widthWidget"); - - return hbox; -} diff --git a/arts/modules/effects/freeverbguifactory_impl.cpp b/arts/modules/effects/freeverbguifactory_impl.cpp new file mode 100644 index 00000000..4b5d4d34 --- /dev/null +++ b/arts/modules/effects/freeverbguifactory_impl.cpp @@ -0,0 +1,107 @@ + /* + + Copyright (C) 2001 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "artsmoduleseffects.h" +#include "debug.h" +#include "connect.h" + +#include +#include + +using namespace std; +using namespace Arts; + +namespace Arts { + +class FreeverbGuiFactory_impl : public FreeverbGuiFactory_skel +{ +public: + Widget createGui(Object freeverb); +}; + +REGISTER_IMPLEMENTATION(FreeverbGuiFactory_impl); + +} + +Widget FreeverbGuiFactory_impl::createGui(Object object) +{ + TDEGlobal::locale()->insertCatalogue( "artsmodules" ); + arts_return_val_if_fail(!object.isNull(), Arts::Widget::null()); + + Synth_FREEVERB freeverb = DynamicCast(object); + arts_return_val_if_fail(!freeverb.isNull(), Arts::Widget::null()); + + HBox hbox; + hbox.width(330); hbox.height(80); hbox.show(); + + Poti roomsize; + roomsize.x(20); roomsize.y(10); roomsize.caption(i18n("roomsize").utf8().data()); + roomsize.color("red"); roomsize.min(0); roomsize.max(1); + roomsize.value(freeverb.roomsize()); + roomsize.range(100); + roomsize.parent(hbox); + roomsize.show(); + connect(roomsize,"value_changed", freeverb, "roomsize"); + hbox._addChild(roomsize,"roomsizeWidget"); + + Poti damp; + damp.x(80); damp.y(10); damp.caption(i18n("damp").utf8().data()); + damp.color("red"); damp.min(0); damp.max(1); + damp.value(freeverb.damp()); + damp.range(100); + damp.parent(hbox); + damp.show(); + connect(damp,"value_changed", freeverb, "damp"); + hbox._addChild(damp,"dampWidget"); + + Poti wet; + wet.x(140); wet.y(10); wet.caption(i18n("wet").utf8().data()); + wet.color("red"); wet.min(0); wet.max(1); + wet.value(freeverb.wet()); + wet.range(100); + wet.parent(hbox); + wet.show(); + connect(wet,"value_changed", freeverb, "wet"); + hbox._addChild(wet,"wetWidget"); + + Poti dry; + dry.x(200); dry.y(10); dry.caption(i18n("dry").utf8().data()); + dry.color("red"); dry.min(0); dry.max(1); + dry.value(freeverb.dry()); + dry.range(100); + dry.parent(hbox); + dry.show(); + connect(dry,"value_changed", freeverb, "dry"); + hbox._addChild(dry,"dryWidget"); + + Poti width; + width.x(260); width.y(10); width.caption(i18n("width").utf8().data()); + width.color("red"); width.min(0); width.max(1); + width.value(freeverb.width()); + width.range(100); + width.parent(hbox); + width.show(); + connect(width,"value_changed", freeverb, "width"); + hbox._addChild(width,"widthWidget"); + + return hbox; +} diff --git a/arts/modules/effects/monostereoconversion_impl.cc b/arts/modules/effects/monostereoconversion_impl.cc deleted file mode 100644 index 9bf1bbee..00000000 --- a/arts/modules/effects/monostereoconversion_impl.cc +++ /dev/null @@ -1,160 +0,0 @@ -/* - - Copyright ( C ) 2002 Arnold Krille - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or ( at your option ) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include -#include -#include -#include -#include -#include - -#include -#include - -namespace Arts { - -class MonoToStereo_impl : virtual public MonoToStereo_skel, - virtual public StdSynthModule -{ -protected: - float _pan, _pLeft, _pRight; -public: - MonoToStereo_impl() - { - pan( 0 ); - } - - float pan() { return _pan; } - void pan( float pan ) - { - if( pan < -1 ) pan = -1; - if( pan > 1 ) pan = 1; - _pan = pan; - _pLeft = _pRight = 1; - if( _pan < 0 ) - _pRight = 1 + _pan; - else - _pLeft = 1 - _pan; - } - - void calculateBlock( unsigned long samples ) - { - for( unsigned int i=0; i 1 ) pan = 1; - _pan = pan; - _pLeft = _pRight = 1; - if( _pan < 0 ) - _pRight = 1 + _pan; - else - _pLeft = 1 - _pan; - } - - void calculateBlock( unsigned long samples ) - { - for( unsigned int i=0; i1 ) n=1; - if( n<-1 ) n=-1; - _balance = n; - _right = _left = 1; - if( _balance < 0 ) - _right = 1 + _balance; - else - _left = 1 - _balance; - } - - void calculateBlock( unsigned long samples ) - { -//arts_debug( "StereoBalance::calculateBlock( unsigned int %i )", samples ); - for( unsigned long i=0; iinsertCatalogue( "artsmodules" ); - - arts_return_val_if_fail( !object.isNull(), Arts::Widget::null() ); - StereoBalance ch= DynamicCast( object ); - arts_return_val_if_fail( !ch.isNull(), Arts::Widget::null() ); - - Poti bal; - bal.caption( i18n( "Balance" ).utf8().data() ); - bal.min( -1 ); bal.max( 1 ); - bal.value( ch.balance() ); - connect( bal, "value_changed", ch, "balance" ); - - return bal; - } -}; -REGISTER_IMPLEMENTATION( StereoBalanceGuiFactory_impl ); - -} - diff --git a/arts/modules/effects/monostereoconversion_impl.cpp b/arts/modules/effects/monostereoconversion_impl.cpp new file mode 100644 index 00000000..9bf1bbee --- /dev/null +++ b/arts/modules/effects/monostereoconversion_impl.cpp @@ -0,0 +1,160 @@ +/* + + Copyright ( C ) 2002 Arnold Krille + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or ( at your option ) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace Arts { + +class MonoToStereo_impl : virtual public MonoToStereo_skel, + virtual public StdSynthModule +{ +protected: + float _pan, _pLeft, _pRight; +public: + MonoToStereo_impl() + { + pan( 0 ); + } + + float pan() { return _pan; } + void pan( float pan ) + { + if( pan < -1 ) pan = -1; + if( pan > 1 ) pan = 1; + _pan = pan; + _pLeft = _pRight = 1; + if( _pan < 0 ) + _pRight = 1 + _pan; + else + _pLeft = 1 - _pan; + } + + void calculateBlock( unsigned long samples ) + { + for( unsigned int i=0; i 1 ) pan = 1; + _pan = pan; + _pLeft = _pRight = 1; + if( _pan < 0 ) + _pRight = 1 + _pan; + else + _pLeft = 1 - _pan; + } + + void calculateBlock( unsigned long samples ) + { + for( unsigned int i=0; i1 ) n=1; + if( n<-1 ) n=-1; + _balance = n; + _right = _left = 1; + if( _balance < 0 ) + _right = 1 + _balance; + else + _left = 1 - _balance; + } + + void calculateBlock( unsigned long samples ) + { +//arts_debug( "StereoBalance::calculateBlock( unsigned int %i )", samples ); + for( unsigned long i=0; iinsertCatalogue( "artsmodules" ); + + arts_return_val_if_fail( !object.isNull(), Arts::Widget::null() ); + StereoBalance ch= DynamicCast( object ); + arts_return_val_if_fail( !ch.isNull(), Arts::Widget::null() ); + + Poti bal; + bal.caption( i18n( "Balance" ).utf8().data() ); + bal.min( -1 ); bal.max( 1 ); + bal.value( ch.balance() ); + connect( bal, "value_changed", ch, "balance" ); + + return bal; + } +}; +REGISTER_IMPLEMENTATION( StereoBalanceGuiFactory_impl ); + +} + diff --git a/arts/modules/effects/stereocompressorguifactory_impl.cc b/arts/modules/effects/stereocompressorguifactory_impl.cc deleted file mode 100644 index 295ad65d..00000000 --- a/arts/modules/effects/stereocompressorguifactory_impl.cc +++ /dev/null @@ -1,111 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2002 Arnold Krille - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#include -#include - -#include "artsmoduleseffects.h" -#include "connect.h" -#include "debug.h" - -using namespace Arts; - -namespace Arts { - -class StereoCompressorGuiFactory_impl : virtual public StereoCompressorGuiFactory_skel -{ -public: - Widget createGui( Object object ) - { - TDEGlobal::locale()->insertCatalogue( "artsmodules" ); - - arts_return_val_if_fail(!object.isNull(), Arts::Widget::null() ); - - Synth_STEREO_COMPRESSOR comp = DynamicCast(object); - arts_return_val_if_fail(!comp.isNull(), Arts::Widget::null()); - - Poti attack; - attack.caption(i18n("attack").utf8().data()); - attack.color("blue"); - attack.min(0.1); attack.max(250); - attack.value( comp.attack() ); - attack.range(250); - connect( attack, "value_changed", comp, "attack" ); - - Poti release; - release.caption(i18n("release").utf8().data()); - release.color("blue"); - release.min(0.1); release.max(250); - release.value( comp.release() ); - release.range(250); - connect( release, "value_changed", comp, "release" ); - - Poti threshold; - threshold.caption(i18n("thresh.").utf8().data()); - threshold.min(0.00001); threshold.max(1); - threshold.value( comp.threshold() ); - threshold.logarithmic( 2.0 ); - threshold.range(200); - connect( threshold, "value_changed", comp, "threshold" ); - - Poti ratio; - ratio.caption(i18n("ratio").utf8().data()); - ratio.min(0); ratio.max(1); - ratio.value( comp.ratio() ); - ratio.range(200); - connect( ratio, "value_changed", comp, "ratio" ); - - Poti output; - output.caption(i18n("output").utf8().data()); - output.min(0.1); output.max(10.0); - output.value( comp.output() ); - output.logarithmic( 2.0 ); - output.range(200); - connect( output, "value_changed", comp, "output" ); - - Button bon; - bon.text(i18n("Bypass").utf8().data()); - bon.toggle( true ); - connect( bon, "pressed_changed", comp, "thru" ); - - LayoutBox hbox; - hbox.direction( LeftToRight ); hbox.layoutmargin( 5 ); hbox.spacing( 5 ); - PopupBox timesbox; - timesbox.name( "Timings" ); timesbox.direction( LeftToRight ); - LayoutBox times; - times.direction( LeftToRight ); times.spacing( 5 ); - - hbox.addWidget( timesbox ); - times.addSpace( 5 ); - times.addWidget( attack ); - times.addWidget( release ); - times.addSpace( 5 ); - timesbox.widget( times ); - hbox.addWidget( threshold ); - hbox.addWidget( ratio ); - hbox.addWidget( output ); - hbox.addWidget( bon ); - hbox.addStretch( 10 ); - - return hbox; - } -}; -REGISTER_IMPLEMENTATION(StereoCompressorGuiFactory_impl); - -} diff --git a/arts/modules/effects/stereocompressorguifactory_impl.cpp b/arts/modules/effects/stereocompressorguifactory_impl.cpp new file mode 100644 index 00000000..295ad65d --- /dev/null +++ b/arts/modules/effects/stereocompressorguifactory_impl.cpp @@ -0,0 +1,111 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Arnold Krille + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + +*/ + +#include +#include + +#include "artsmoduleseffects.h" +#include "connect.h" +#include "debug.h" + +using namespace Arts; + +namespace Arts { + +class StereoCompressorGuiFactory_impl : virtual public StereoCompressorGuiFactory_skel +{ +public: + Widget createGui( Object object ) + { + TDEGlobal::locale()->insertCatalogue( "artsmodules" ); + + arts_return_val_if_fail(!object.isNull(), Arts::Widget::null() ); + + Synth_STEREO_COMPRESSOR comp = DynamicCast(object); + arts_return_val_if_fail(!comp.isNull(), Arts::Widget::null()); + + Poti attack; + attack.caption(i18n("attack").utf8().data()); + attack.color("blue"); + attack.min(0.1); attack.max(250); + attack.value( comp.attack() ); + attack.range(250); + connect( attack, "value_changed", comp, "attack" ); + + Poti release; + release.caption(i18n("release").utf8().data()); + release.color("blue"); + release.min(0.1); release.max(250); + release.value( comp.release() ); + release.range(250); + connect( release, "value_changed", comp, "release" ); + + Poti threshold; + threshold.caption(i18n("thresh.").utf8().data()); + threshold.min(0.00001); threshold.max(1); + threshold.value( comp.threshold() ); + threshold.logarithmic( 2.0 ); + threshold.range(200); + connect( threshold, "value_changed", comp, "threshold" ); + + Poti ratio; + ratio.caption(i18n("ratio").utf8().data()); + ratio.min(0); ratio.max(1); + ratio.value( comp.ratio() ); + ratio.range(200); + connect( ratio, "value_changed", comp, "ratio" ); + + Poti output; + output.caption(i18n("output").utf8().data()); + output.min(0.1); output.max(10.0); + output.value( comp.output() ); + output.logarithmic( 2.0 ); + output.range(200); + connect( output, "value_changed", comp, "output" ); + + Button bon; + bon.text(i18n("Bypass").utf8().data()); + bon.toggle( true ); + connect( bon, "pressed_changed", comp, "thru" ); + + LayoutBox hbox; + hbox.direction( LeftToRight ); hbox.layoutmargin( 5 ); hbox.spacing( 5 ); + PopupBox timesbox; + timesbox.name( "Timings" ); timesbox.direction( LeftToRight ); + LayoutBox times; + times.direction( LeftToRight ); times.spacing( 5 ); + + hbox.addWidget( timesbox ); + times.addSpace( 5 ); + times.addWidget( attack ); + times.addWidget( release ); + times.addSpace( 5 ); + timesbox.widget( times ); + hbox.addWidget( threshold ); + hbox.addWidget( ratio ); + hbox.addWidget( output ); + hbox.addWidget( bon ); + hbox.addStretch( 10 ); + + return hbox; + } +}; +REGISTER_IMPLEMENTATION(StereoCompressorGuiFactory_impl); + +} diff --git a/arts/modules/effects/synth_freeverb_impl.cc b/arts/modules/effects/synth_freeverb_impl.cc deleted file mode 100644 index a1f35d06..00000000 --- a/arts/modules/effects/synth_freeverb_impl.cc +++ /dev/null @@ -1,84 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "freeverb/revmodel.hpp" -#include "artsmoduleseffects.h" -#include "stdsynthmodule.h" - -using namespace Arts; - -class Synth_FREEVERB_impl : virtual public Synth_FREEVERB_skel, - virtual public StdSynthModule -{ - revmodel *model; -public: - float roomsize() { return model->getroomsize(); } - void roomsize(float newval) { return model->setroomsize(newval); } - - float damp() { return model->getdamp(); } - void damp(float newval) { return model->setdamp(newval); } - - float wet() { return model->getwet(); } - void wet(float newval) { return model->setwet(newval); } - - float dry() { return model->getdry(); } - void dry(float newval) { return model->setdry(newval); } - - float width() { return model->getwidth(); } - void width(float newval) { return model->setwidth(newval); } - - float mode() { return model->getmode(); } - void mode(float newval) { return model->setmode(newval); } - - void streamInit() - { - /* prevent full buffers to be carried over stop-start sequence */ - model->mute(); - } - - void calculateBlock(unsigned long samples) - { - model->processreplace(inleft, inright, outleft, outright, samples,1); - // don't add the original signal - that's what the "dry" argument is for - //for(unsigned long i = 0;i < samples; i++) - //{ - //outleft[i] += inleft[i]; - //outright[i] += inright[i]; - //} - } - Synth_FREEVERB_impl() - { - // "revmodel" object size is far too big, vtable - // can't handle it - model=new revmodel; - // set dry to 1 so it at first sounds like it always did before - // ok, since scaledry = 2 calling dry( 0.5 ) has the desired - // effect - dry( 0.5f ); - } - ~Synth_FREEVERB_impl() - { - delete model; - } -}; - -REGISTER_IMPLEMENTATION(Synth_FREEVERB_impl); diff --git a/arts/modules/effects/synth_freeverb_impl.cpp b/arts/modules/effects/synth_freeverb_impl.cpp new file mode 100644 index 00000000..3b882d48 --- /dev/null +++ b/arts/modules/effects/synth_freeverb_impl.cpp @@ -0,0 +1,84 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "freeverb/revmodel.h" +#include "artsmoduleseffects.h" +#include "stdsynthmodule.h" + +using namespace Arts; + +class Synth_FREEVERB_impl : virtual public Synth_FREEVERB_skel, + virtual public StdSynthModule +{ + revmodel *model; +public: + float roomsize() { return model->getroomsize(); } + void roomsize(float newval) { return model->setroomsize(newval); } + + float damp() { return model->getdamp(); } + void damp(float newval) { return model->setdamp(newval); } + + float wet() { return model->getwet(); } + void wet(float newval) { return model->setwet(newval); } + + float dry() { return model->getdry(); } + void dry(float newval) { return model->setdry(newval); } + + float width() { return model->getwidth(); } + void width(float newval) { return model->setwidth(newval); } + + float mode() { return model->getmode(); } + void mode(float newval) { return model->setmode(newval); } + + void streamInit() + { + /* prevent full buffers to be carried over stop-start sequence */ + model->mute(); + } + + void calculateBlock(unsigned long samples) + { + model->processreplace(inleft, inright, outleft, outright, samples,1); + // don't add the original signal - that's what the "dry" argument is for + //for(unsigned long i = 0;i < samples; i++) + //{ + //outleft[i] += inleft[i]; + //outright[i] += inright[i]; + //} + } + Synth_FREEVERB_impl() + { + // "revmodel" object size is far too big, vtable + // can't handle it + model=new revmodel; + // set dry to 1 so it at first sounds like it always did before + // ok, since scaledry = 2 calling dry( 0.5 ) has the desired + // effect + dry( 0.5f ); + } + ~Synth_FREEVERB_impl() + { + delete model; + } +}; + +REGISTER_IMPLEMENTATION(Synth_FREEVERB_impl); diff --git a/arts/modules/effects/synth_stereo_compressor_impl.cc b/arts/modules/effects/synth_stereo_compressor_impl.cc deleted file mode 100644 index 3add8d46..00000000 --- a/arts/modules/effects/synth_stereo_compressor_impl.cc +++ /dev/null @@ -1,132 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2002 Arnold Krille - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#include "artsmoduleseffects.h" -#include -#include -#include - -using namespace Arts; - -namespace Arts { - -class Synth_STEREO_COMPRESSOR_impl : virtual public Synth_STEREO_COMPRESSOR_skel, - virtual public StdSynthModule -{ -public: - Synth_STEREO_COMPRESSOR_impl() - { - attack( 10 ); - release( 10 ); - threshold( 1 ); - ratio( 0.8 ); - output( 1 ); - _thru = false; - _run = false; - } - - void streamStart() - { - _run = true; - compleft.start(); - compright.start(); - if(!_thru) - connectComp(true); - else - connectThru(true); - } - - void streamEnd() - { - _run = false; - connectComp(false); - connectThru(false); - compleft.stop(); - compright.stop(); - } - - float attack() { return compleft.attack(); }; - void attack( float f ) { compleft.attack(f); compright.attack(f); } - float release() { return compleft.release(); }; - void release( float f ) { compleft.release(f); compright.release(f); } - float threshold() { return compleft.threshold(); }; - void threshold( float f ) { compleft.threshold(f); compright.threshold(f); } - float ratio() { return compleft.ratio(); }; - void ratio( float f ) { compleft.ratio(f); compright.ratio(f); } - float output() { return compleft.output(); }; - void output( float f ) { compleft.output(f); compright.output(f); } - - bool thru() { return _thru; } - void thru( bool f ) - { - if( _thru != f ) - { - if(!_thru) - connectComp(false); - else - connectThru(false); - _thru = f; - if(!_thru) - connectComp(true); - else - connectThru(true); - } - } - -private: - Synth_COMPRESSOR compleft, compright; - bool _thru; - bool _run; - - void connectComp( bool _connect ) - { - if(_connect) - { - _node()->virtualize("inleft",compleft._node(),"invalue"); - _node()->virtualize("inright",compright._node(),"invalue"); - _node()->virtualize("outleft",compleft._node(),"outvalue"); - _node()->virtualize("outright",compright._node(),"outvalue"); - } - else - { - _node()->devirtualize("inleft",compleft._node(),"invalue"); - _node()->devirtualize("inright",compright._node(),"invalue"); - _node()->devirtualize("outleft",compleft._node(),"outvalue"); - _node()->devirtualize("outright",compright._node(),"outvalue"); - } - } - - void connectThru( bool _connect ) - { - if(_connect) - { - _node()->virtualize("inleft",_node(),"outleft"); - _node()->virtualize("inright",_node(),"outright"); - } - else - { - _node()->devirtualize("inleft",_node(),"outleft"); - _node()->devirtualize("inright",_node(),"outright"); - } - } - -}; -REGISTER_IMPLEMENTATION(Synth_STEREO_COMPRESSOR_impl); - -} diff --git a/arts/modules/effects/synth_stereo_compressor_impl.cpp b/arts/modules/effects/synth_stereo_compressor_impl.cpp new file mode 100644 index 00000000..3add8d46 --- /dev/null +++ b/arts/modules/effects/synth_stereo_compressor_impl.cpp @@ -0,0 +1,132 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Arnold Krille + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + +*/ + +#include "artsmoduleseffects.h" +#include +#include +#include + +using namespace Arts; + +namespace Arts { + +class Synth_STEREO_COMPRESSOR_impl : virtual public Synth_STEREO_COMPRESSOR_skel, + virtual public StdSynthModule +{ +public: + Synth_STEREO_COMPRESSOR_impl() + { + attack( 10 ); + release( 10 ); + threshold( 1 ); + ratio( 0.8 ); + output( 1 ); + _thru = false; + _run = false; + } + + void streamStart() + { + _run = true; + compleft.start(); + compright.start(); + if(!_thru) + connectComp(true); + else + connectThru(true); + } + + void streamEnd() + { + _run = false; + connectComp(false); + connectThru(false); + compleft.stop(); + compright.stop(); + } + + float attack() { return compleft.attack(); }; + void attack( float f ) { compleft.attack(f); compright.attack(f); } + float release() { return compleft.release(); }; + void release( float f ) { compleft.release(f); compright.release(f); } + float threshold() { return compleft.threshold(); }; + void threshold( float f ) { compleft.threshold(f); compright.threshold(f); } + float ratio() { return compleft.ratio(); }; + void ratio( float f ) { compleft.ratio(f); compright.ratio(f); } + float output() { return compleft.output(); }; + void output( float f ) { compleft.output(f); compright.output(f); } + + bool thru() { return _thru; } + void thru( bool f ) + { + if( _thru != f ) + { + if(!_thru) + connectComp(false); + else + connectThru(false); + _thru = f; + if(!_thru) + connectComp(true); + else + connectThru(true); + } + } + +private: + Synth_COMPRESSOR compleft, compright; + bool _thru; + bool _run; + + void connectComp( bool _connect ) + { + if(_connect) + { + _node()->virtualize("inleft",compleft._node(),"invalue"); + _node()->virtualize("inright",compright._node(),"invalue"); + _node()->virtualize("outleft",compleft._node(),"outvalue"); + _node()->virtualize("outright",compright._node(),"outvalue"); + } + else + { + _node()->devirtualize("inleft",compleft._node(),"invalue"); + _node()->devirtualize("inright",compright._node(),"invalue"); + _node()->devirtualize("outleft",compleft._node(),"outvalue"); + _node()->devirtualize("outright",compright._node(),"outvalue"); + } + } + + void connectThru( bool _connect ) + { + if(_connect) + { + _node()->virtualize("inleft",_node(),"outleft"); + _node()->virtualize("inright",_node(),"outright"); + } + else + { + _node()->devirtualize("inleft",_node(),"outleft"); + _node()->devirtualize("inright",_node(),"outright"); + } + } + +}; +REGISTER_IMPLEMENTATION(Synth_STEREO_COMPRESSOR_impl); + +} diff --git a/arts/modules/effects/synth_stereo_fir_equalizer_impl.cc b/arts/modules/effects/synth_stereo_fir_equalizer_impl.cc deleted file mode 100644 index 8f15a4dc..00000000 --- a/arts/modules/effects/synth_stereo_fir_equalizer_impl.cc +++ /dev/null @@ -1,221 +0,0 @@ -/* - - Copyright (C) 2001-2002 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include - -#include -#include -#include -#include -#include "artsmoduleseffects.h" - -#include -#include - -#include -#include - -using namespace std; -using namespace Arts; - -static inline bool odd(int x) { return ((x & 1) == 1); } - -/* returns a blackman window: x is supposed to be in the interval [0..1] */ -static inline float blackmanWindow(float x) -{ - if(x < 0) return 0; - if(x > 1) return 0; - return 0.42-0.5*cos(M_PI*x*2)+0.08*cos(4*M_PI*x); -} - -void firapprox(double *filter, int filtersize, vector& points) -{ - assert((filtersize >= 3) && odd(filtersize)); - - int fft_size = 8; - while(fft_size/2 < filtersize) - fft_size *= 2; - - vector::iterator pi = points.begin(); - float lfreq=-2, lval=1.0, rfreq=-1, rval=1.0; - - float *re = (float*) malloc(fft_size * sizeof(float)); - for(int i=0;i rfreq && pi != points.end()) - { - lfreq = rfreq; rfreq = pi->x; - lval = rval; rval = pi->y; - pi++; - } - float pos = (freq-lfreq)/(rfreq-lfreq); - float val = lval*(1.0-pos) + rval*pos; - - //printf("%f %f\n",freq,val); - re[i] = re[fft_size-1-i] = val; - } - - float *filter_re = (float*) malloc(fft_size * sizeof(float)); - float *filter_im = (float*) malloc(fft_size * sizeof(float)); - arts_fft_float (fft_size, 1, re, 0, filter_re, filter_im); - - for(int i=0;i _frequencies; - long _taps; - unsigned long bpos; - double filter[256]; - float lbuffer[256]; - float rbuffer[256]; - -public: - Synth_STEREO_FIR_EQUALIZER_impl() - { - _frequencies.push_back(GraphPoint(0.0,1.0)); - _frequencies.push_back(GraphPoint(1.0,1.0)); - _taps = 3; - for(bpos = 0; bpos < 256; bpos++) - lbuffer[bpos] = rbuffer[bpos] = 0.0; - - calcFilter(); - } - vector *frequencies() { - return new vector(_frequencies); - } - void frequencies(const vector& newFrequencies) - { - _frequencies = newFrequencies; - - calcFilter(); - } - long taps() - { - return _taps; - } - void taps(long newTaps) - { - arts_return_if_fail(newTaps >= 3 && newTaps <= 255); - - if(!odd(newTaps)) - newTaps++; - _taps = newTaps; - - calcFilter(); - } - void calcFilter() - { - firapprox(filter, _taps, _frequencies); - } - void calculateBlock(unsigned long samples) - { - for(unsigned i=0;iinsertCatalogue( "artsmodules" ); - arts_return_val_if_fail(!object.isNull(), Arts::Widget::null()); - - Synth_STEREO_FIR_EQUALIZER equalizer = DynamicCast(object); - arts_return_val_if_fail(!equalizer.isNull(), Arts::Widget::null()); - - VBox vbox; - vbox.show(); - - Graph g; - g.parent(vbox); - g.width(400); - g.height(230); - g.caption(i18n("a graph").utf8().data()); - g.minx(0.0); - g.maxx(1.0); - g.miny(0.0); - g.maxy(1.0); - g.show(); - - GraphLine gline; - gline.graph(g); - vector *points = equalizer.frequencies(); - gline.points(*points); - delete points; - gline.color("red"); - gline.editable(true); - - connect(gline,"points_changed", equalizer, "frequencies"); - g._addChild(gline,"gline"); - - SpinBox spinbox; - spinbox.caption(i18n("channels").utf8().data()); - spinbox.min(3); spinbox.max(255); - spinbox.value(equalizer.taps()); - spinbox.parent(vbox); - spinbox.show(); - connect(spinbox,"value_changed", equalizer, "taps"); - vbox._addChild(spinbox,"spinbox"); - vbox._addChild(g,"g"); - - return vbox; -} diff --git a/arts/modules/effects/synth_stereo_fir_equalizer_impl.cpp b/arts/modules/effects/synth_stereo_fir_equalizer_impl.cpp new file mode 100644 index 00000000..8f15a4dc --- /dev/null +++ b/arts/modules/effects/synth_stereo_fir_equalizer_impl.cpp @@ -0,0 +1,221 @@ +/* + + Copyright (C) 2001-2002 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include + +#include +#include +#include +#include +#include "artsmoduleseffects.h" + +#include +#include + +#include +#include + +using namespace std; +using namespace Arts; + +static inline bool odd(int x) { return ((x & 1) == 1); } + +/* returns a blackman window: x is supposed to be in the interval [0..1] */ +static inline float blackmanWindow(float x) +{ + if(x < 0) return 0; + if(x > 1) return 0; + return 0.42-0.5*cos(M_PI*x*2)+0.08*cos(4*M_PI*x); +} + +void firapprox(double *filter, int filtersize, vector& points) +{ + assert((filtersize >= 3) && odd(filtersize)); + + int fft_size = 8; + while(fft_size/2 < filtersize) + fft_size *= 2; + + vector::iterator pi = points.begin(); + float lfreq=-2, lval=1.0, rfreq=-1, rval=1.0; + + float *re = (float*) malloc(fft_size * sizeof(float)); + for(int i=0;i rfreq && pi != points.end()) + { + lfreq = rfreq; rfreq = pi->x; + lval = rval; rval = pi->y; + pi++; + } + float pos = (freq-lfreq)/(rfreq-lfreq); + float val = lval*(1.0-pos) + rval*pos; + + //printf("%f %f\n",freq,val); + re[i] = re[fft_size-1-i] = val; + } + + float *filter_re = (float*) malloc(fft_size * sizeof(float)); + float *filter_im = (float*) malloc(fft_size * sizeof(float)); + arts_fft_float (fft_size, 1, re, 0, filter_re, filter_im); + + for(int i=0;i _frequencies; + long _taps; + unsigned long bpos; + double filter[256]; + float lbuffer[256]; + float rbuffer[256]; + +public: + Synth_STEREO_FIR_EQUALIZER_impl() + { + _frequencies.push_back(GraphPoint(0.0,1.0)); + _frequencies.push_back(GraphPoint(1.0,1.0)); + _taps = 3; + for(bpos = 0; bpos < 256; bpos++) + lbuffer[bpos] = rbuffer[bpos] = 0.0; + + calcFilter(); + } + vector *frequencies() { + return new vector(_frequencies); + } + void frequencies(const vector& newFrequencies) + { + _frequencies = newFrequencies; + + calcFilter(); + } + long taps() + { + return _taps; + } + void taps(long newTaps) + { + arts_return_if_fail(newTaps >= 3 && newTaps <= 255); + + if(!odd(newTaps)) + newTaps++; + _taps = newTaps; + + calcFilter(); + } + void calcFilter() + { + firapprox(filter, _taps, _frequencies); + } + void calculateBlock(unsigned long samples) + { + for(unsigned i=0;iinsertCatalogue( "artsmodules" ); + arts_return_val_if_fail(!object.isNull(), Arts::Widget::null()); + + Synth_STEREO_FIR_EQUALIZER equalizer = DynamicCast(object); + arts_return_val_if_fail(!equalizer.isNull(), Arts::Widget::null()); + + VBox vbox; + vbox.show(); + + Graph g; + g.parent(vbox); + g.width(400); + g.height(230); + g.caption(i18n("a graph").utf8().data()); + g.minx(0.0); + g.maxx(1.0); + g.miny(0.0); + g.maxy(1.0); + g.show(); + + GraphLine gline; + gline.graph(g); + vector *points = equalizer.frequencies(); + gline.points(*points); + delete points; + gline.color("red"); + gline.editable(true); + + connect(gline,"points_changed", equalizer, "frequencies"); + g._addChild(gline,"gline"); + + SpinBox spinbox; + spinbox.caption(i18n("channels").utf8().data()); + spinbox.min(3); spinbox.max(255); + spinbox.value(equalizer.taps()); + spinbox.parent(vbox); + spinbox.show(); + connect(spinbox,"value_changed", equalizer, "taps"); + vbox._addChild(spinbox,"spinbox"); + vbox._addChild(g,"g"); + + return vbox; +} diff --git a/arts/modules/effects/synth_stereo_pitch_shift_fft_impl.cc b/arts/modules/effects/synth_stereo_pitch_shift_fft_impl.cc deleted file mode 100644 index 390fd04e..00000000 --- a/arts/modules/effects/synth_stereo_pitch_shift_fft_impl.cc +++ /dev/null @@ -1,63 +0,0 @@ -#include "flowsystem.h" -#include "artsmoduleseffects.h" -#include "stdsynthmodule.h" - -using namespace Arts; - -class Synth_STEREO_PITCH_SHIFT_FFT_impl : virtual public Synth_STEREO_PITCH_SHIFT_FFT_skel, - virtual public StdSynthModule -{ -protected: - Synth_PITCH_SHIFT_FFT leftPitchShift, rightPitchShift; - -public: - float speed() { return leftPitchShift.speed(); } - void speed(float newSpeed) - { - leftPitchShift.speed(newSpeed); - rightPitchShift.speed(newSpeed); - } - - float scaleFactor() { return leftPitchShift.scaleFactor(); } - void scaleFactor(float newScaleFactor) - { - leftPitchShift.scaleFactor(newScaleFactor); - rightPitchShift.scaleFactor(newScaleFactor); - } - - long frameSize() { return leftPitchShift.frameSize(); } - void frameSize(long newFrameSize) - { - leftPitchShift.frameSize(newFrameSize); - rightPitchShift.frameSize(newFrameSize); - } - - long oversample() { return leftPitchShift.oversample(); } - void oversample(long newOversample) - { - leftPitchShift.oversample(newOversample); - rightPitchShift.oversample(newOversample); - } - - void streamStart() - { - leftPitchShift.start(); - rightPitchShift.start(); - _node()->virtualize("inleft",leftPitchShift._node(),"inStream"); - _node()->virtualize("outleft",leftPitchShift._node(),"outStream"); - _node()->virtualize("inright",rightPitchShift._node(),"inStream"); - _node()->virtualize("outright",rightPitchShift._node(),"outStream"); - } - - void streamEnd() - { - _node()->devirtualize("inleft",leftPitchShift._node(),"inStream"); - _node()->devirtualize("outleft",leftPitchShift._node(),"outStream"); - _node()->devirtualize("inright",rightPitchShift._node(),"inStream"); - _node()->devirtualize("outright",rightPitchShift._node(),"outStream"); - leftPitchShift.stop(); - rightPitchShift.stop(); - } -}; - -REGISTER_IMPLEMENTATION(Synth_STEREO_PITCH_SHIFT_FFT_impl); diff --git a/arts/modules/effects/synth_stereo_pitch_shift_fft_impl.cpp b/arts/modules/effects/synth_stereo_pitch_shift_fft_impl.cpp new file mode 100644 index 00000000..390fd04e --- /dev/null +++ b/arts/modules/effects/synth_stereo_pitch_shift_fft_impl.cpp @@ -0,0 +1,63 @@ +#include "flowsystem.h" +#include "artsmoduleseffects.h" +#include "stdsynthmodule.h" + +using namespace Arts; + +class Synth_STEREO_PITCH_SHIFT_FFT_impl : virtual public Synth_STEREO_PITCH_SHIFT_FFT_skel, + virtual public StdSynthModule +{ +protected: + Synth_PITCH_SHIFT_FFT leftPitchShift, rightPitchShift; + +public: + float speed() { return leftPitchShift.speed(); } + void speed(float newSpeed) + { + leftPitchShift.speed(newSpeed); + rightPitchShift.speed(newSpeed); + } + + float scaleFactor() { return leftPitchShift.scaleFactor(); } + void scaleFactor(float newScaleFactor) + { + leftPitchShift.scaleFactor(newScaleFactor); + rightPitchShift.scaleFactor(newScaleFactor); + } + + long frameSize() { return leftPitchShift.frameSize(); } + void frameSize(long newFrameSize) + { + leftPitchShift.frameSize(newFrameSize); + rightPitchShift.frameSize(newFrameSize); + } + + long oversample() { return leftPitchShift.oversample(); } + void oversample(long newOversample) + { + leftPitchShift.oversample(newOversample); + rightPitchShift.oversample(newOversample); + } + + void streamStart() + { + leftPitchShift.start(); + rightPitchShift.start(); + _node()->virtualize("inleft",leftPitchShift._node(),"inStream"); + _node()->virtualize("outleft",leftPitchShift._node(),"outStream"); + _node()->virtualize("inright",rightPitchShift._node(),"inStream"); + _node()->virtualize("outright",rightPitchShift._node(),"outStream"); + } + + void streamEnd() + { + _node()->devirtualize("inleft",leftPitchShift._node(),"inStream"); + _node()->devirtualize("outleft",leftPitchShift._node(),"outStream"); + _node()->devirtualize("inright",rightPitchShift._node(),"inStream"); + _node()->devirtualize("outright",rightPitchShift._node(),"outStream"); + leftPitchShift.stop(); + rightPitchShift.stop(); + } +}; + +REGISTER_IMPLEMENTATION(Synth_STEREO_PITCH_SHIFT_FFT_impl); diff --git a/arts/modules/effects/synth_stereo_pitch_shift_impl.cc b/arts/modules/effects/synth_stereo_pitch_shift_impl.cc deleted file mode 100644 index fbf7bb07..00000000 --- a/arts/modules/effects/synth_stereo_pitch_shift_impl.cc +++ /dev/null @@ -1,51 +0,0 @@ -#include "flowsystem.h" -#include "artsmoduleseffects.h" -#include "stdsynthmodule.h" - -#include - -using namespace Arts; - -class Synth_STEREO_PITCH_SHIFT_impl : virtual public Synth_STEREO_PITCH_SHIFT_skel, - virtual public StdSynthModule -{ -protected: - Synth_PITCH_SHIFT leftPitchShift, rightPitchShift; - -public: - float speed() { return leftPitchShift.speed(); } - void speed(float newSpeed) - { - leftPitchShift.speed(newSpeed); - rightPitchShift.speed(newSpeed); - } - - float frequency() { return leftPitchShift.frequency(); } - void frequency(float newFrequency) - { - leftPitchShift.frequency(newFrequency); - rightPitchShift.frequency(newFrequency); - } - - void streamStart() - { - leftPitchShift.start(); - rightPitchShift.start(); - _node()->virtualize("inleft",leftPitchShift._node(),"invalue"); - _node()->virtualize("outleft",leftPitchShift._node(),"outvalue"); - _node()->virtualize("inright",rightPitchShift._node(),"invalue"); - _node()->virtualize("outright",rightPitchShift._node(),"outvalue"); - } - - void streamEnd() - { - _node()->devirtualize("inleft",leftPitchShift._node(),"invalue"); - _node()->devirtualize("outleft",leftPitchShift._node(),"outvalue"); - _node()->devirtualize("inright",rightPitchShift._node(),"invalue"); - _node()->devirtualize("outright",rightPitchShift._node(),"outvalue"); - leftPitchShift.stop(); - rightPitchShift.stop(); - } -}; - -REGISTER_IMPLEMENTATION(Synth_STEREO_PITCH_SHIFT_impl); diff --git a/arts/modules/effects/synth_stereo_pitch_shift_impl.cpp b/arts/modules/effects/synth_stereo_pitch_shift_impl.cpp new file mode 100644 index 00000000..fbf7bb07 --- /dev/null +++ b/arts/modules/effects/synth_stereo_pitch_shift_impl.cpp @@ -0,0 +1,51 @@ +#include "flowsystem.h" +#include "artsmoduleseffects.h" +#include "stdsynthmodule.h" + +#include + +using namespace Arts; + +class Synth_STEREO_PITCH_SHIFT_impl : virtual public Synth_STEREO_PITCH_SHIFT_skel, + virtual public StdSynthModule +{ +protected: + Synth_PITCH_SHIFT leftPitchShift, rightPitchShift; + +public: + float speed() { return leftPitchShift.speed(); } + void speed(float newSpeed) + { + leftPitchShift.speed(newSpeed); + rightPitchShift.speed(newSpeed); + } + + float frequency() { return leftPitchShift.frequency(); } + void frequency(float newFrequency) + { + leftPitchShift.frequency(newFrequency); + rightPitchShift.frequency(newFrequency); + } + + void streamStart() + { + leftPitchShift.start(); + rightPitchShift.start(); + _node()->virtualize("inleft",leftPitchShift._node(),"invalue"); + _node()->virtualize("outleft",leftPitchShift._node(),"outvalue"); + _node()->virtualize("inright",rightPitchShift._node(),"invalue"); + _node()->virtualize("outright",rightPitchShift._node(),"outvalue"); + } + + void streamEnd() + { + _node()->devirtualize("inleft",leftPitchShift._node(),"invalue"); + _node()->devirtualize("outleft",leftPitchShift._node(),"outvalue"); + _node()->devirtualize("inright",rightPitchShift._node(),"invalue"); + _node()->devirtualize("outright",rightPitchShift._node(),"outvalue"); + leftPitchShift.stop(); + rightPitchShift.stop(); + } +}; + +REGISTER_IMPLEMENTATION(Synth_STEREO_PITCH_SHIFT_impl); diff --git a/arts/modules/effects/synth_voice_removal_impl.cc b/arts/modules/effects/synth_voice_removal_impl.cc deleted file mode 100644 index 2ade0879..00000000 --- a/arts/modules/effects/synth_voice_removal_impl.cc +++ /dev/null @@ -1,106 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2002-2003 Matthias Kretz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ -// $Id$ - -#include "artsmoduleseffects.h" -#include -#include -#include - -using namespace Arts; -using namespace std; - -class Synth_VOICE_REMOVAL_impl : virtual public Synth_VOICE_REMOVAL_skel, - virtual public StdSynthModule -{ -protected: - float _position, _frequency; - filter fleft, fright; - -public: - Synth_VOICE_REMOVAL_impl() - : _position( 0 ) - , _frequency( 200 ) - { - } - - float position() { return _position; } - void position(float newPosition) - { - if(newPosition != _position) - { - _position = newPosition; - position_changed(newPosition); - } - } - - float frequency() { return _frequency; } - void frequency(float newFrequency) - { - if(newFrequency != _frequency) - { - _frequency = newFrequency; - // the shelve-lowpass-filter is extremely sensitive to frequencies which - // are out of it's range (it produces NaN's then) so we'll be careful ;) - if(_frequency > 22000.0) _frequency = 22000.0; - if(_frequency < 1.0) _frequency = 1.0; - frequency_changed(_frequency); - } - } - - void streamInit() - { - initfilter(&fleft); - initfilter(&fright); - } - - void calculateBlock(unsigned long samples) - { - setfilter_shelvelowpass(&fleft,_frequency,80.0); - setfilter_shelvelowpass(&fright,_frequency,80.0); - - unsigned long i; - for (i=0; i + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + +*/ +// $Id$ + +#include "artsmoduleseffects.h" +#include +#include +#include + +using namespace Arts; +using namespace std; + +class Synth_VOICE_REMOVAL_impl : virtual public Synth_VOICE_REMOVAL_skel, + virtual public StdSynthModule +{ +protected: + float _position, _frequency; + filter fleft, fright; + +public: + Synth_VOICE_REMOVAL_impl() + : _position( 0 ) + , _frequency( 200 ) + { + } + + float position() { return _position; } + void position(float newPosition) + { + if(newPosition != _position) + { + _position = newPosition; + position_changed(newPosition); + } + } + + float frequency() { return _frequency; } + void frequency(float newFrequency) + { + if(newFrequency != _frequency) + { + _frequency = newFrequency; + // the shelve-lowpass-filter is extremely sensitive to frequencies which + // are out of it's range (it produces NaN's then) so we'll be careful ;) + if(_frequency > 22000.0) _frequency = 22000.0; + if(_frequency < 1.0) _frequency = 1.0; + frequency_changed(_frequency); + } + } + + void streamInit() + { + initfilter(&fleft); + initfilter(&fright); + } + + void calculateBlock(unsigned long samples) + { + setfilter_shelvelowpass(&fleft,_frequency,80.0); + setfilter_shelvelowpass(&fright,_frequency,80.0); + + unsigned long i; + for (i=0; i - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ -// $Id$ - -#include "artsmoduleseffects.h" -#include -#include -#include - -using namespace std; -using namespace Arts; - -namespace Arts { - -class VoiceRemovalGuiFactory_impl : public VoiceRemovalGuiFactory_skel -{ - public: - Widget createGui( Object ); -}; - -REGISTER_IMPLEMENTATION( VoiceRemovalGuiFactory_impl ); - -} - -Widget VoiceRemovalGuiFactory_impl::createGui( Object object ) -{ - arts_return_val_if_fail( ! object.isNull(), Arts::Widget::null() ); - - Synth_VOICE_REMOVAL voiceremoval = DynamicCast( object ); - arts_return_val_if_fail( ! voiceremoval.isNull(), Arts::Widget::null() ); - - HBox hbox; - hbox.width( 140 ); hbox.height( 80 );// hbox.show(); - - Poti position; - position.x( 20 ); position.y( 10 ); position.caption( "position" ); - position.color( "grey" ); position.min( -1 ); position.max( 1 ); - position.value( voiceremoval.position() ); - position.range( 100 ); - position.parent( hbox ); - position.show(); - connect( position, "value_changed", voiceremoval, "position" ); - hbox._addChild( position, "positionWidget" ); - - Poti freq; - freq.x( 80 ); freq.y( 10 ); freq.caption( "freq" ); - freq.color( "red" ); freq.min( 1 ); freq.max( 10000 ); - freq.value( voiceremoval.frequency() ); - freq.range( 400 ); - freq.logarithmic( 2.0 ); - freq.parent( hbox ); - freq.show(); - connect( freq, "value_changed", voiceremoval, "frequency" ); - hbox._addChild( freq, "freqWidget" ); - - - return hbox; -} diff --git a/arts/modules/effects/voiceremovalguifactory_impl.cpp b/arts/modules/effects/voiceremovalguifactory_impl.cpp new file mode 100644 index 00000000..dc9dce20 --- /dev/null +++ b/arts/modules/effects/voiceremovalguifactory_impl.cpp @@ -0,0 +1,74 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Matthias Kretz + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + +*/ +// $Id$ + +#include "artsmoduleseffects.h" +#include +#include +#include + +using namespace std; +using namespace Arts; + +namespace Arts { + +class VoiceRemovalGuiFactory_impl : public VoiceRemovalGuiFactory_skel +{ + public: + Widget createGui( Object ); +}; + +REGISTER_IMPLEMENTATION( VoiceRemovalGuiFactory_impl ); + +} + +Widget VoiceRemovalGuiFactory_impl::createGui( Object object ) +{ + arts_return_val_if_fail( ! object.isNull(), Arts::Widget::null() ); + + Synth_VOICE_REMOVAL voiceremoval = DynamicCast( object ); + arts_return_val_if_fail( ! voiceremoval.isNull(), Arts::Widget::null() ); + + HBox hbox; + hbox.width( 140 ); hbox.height( 80 );// hbox.show(); + + Poti position; + position.x( 20 ); position.y( 10 ); position.caption( "position" ); + position.color( "grey" ); position.min( -1 ); position.max( 1 ); + position.value( voiceremoval.position() ); + position.range( 100 ); + position.parent( hbox ); + position.show(); + connect( position, "value_changed", voiceremoval, "position" ); + hbox._addChild( position, "positionWidget" ); + + Poti freq; + freq.x( 80 ); freq.y( 10 ); freq.caption( "freq" ); + freq.color( "red" ); freq.min( 1 ); freq.max( 10000 ); + freq.value( voiceremoval.frequency() ); + freq.range( 400 ); + freq.logarithmic( 2.0 ); + freq.parent( hbox ); + freq.show(); + connect( freq, "value_changed", voiceremoval, "frequency" ); + hbox._addChild( freq, "freqWidget" ); + + + return hbox; +} diff --git a/arts/modules/mixers/CMakeLists.txt b/arts/modules/mixers/CMakeLists.txt index 98e7147d..7f6d4dc4 100644 --- a/arts/modules/mixers/CMakeLists.txt +++ b/arts/modules/mixers/CMakeLists.txt @@ -37,10 +37,10 @@ link_directories( tde_add_library( artsmodulesmixers SHARED SOURCES - artsmodulesmixers.cc - monosimplemixerchannel_impl.cc monosimplemixerchannelguifactory_impl.cc - simplemixerchannel_impl.cc simplemixerchannelguifactory_impl.cc - littlestereomixerchannel_impl.cc + artsmodulesmixers.cpp + monosimplemixerchannel_impl.cpp monosimplemixerchannelguifactory_impl.cpp + simplemixerchannel_impl.cpp simplemixerchannelguifactory_impl.cpp + littlestereomixerchannel_impl.cpp VERSION 0.0.0 LINK artsgui_idl-shared artsmodulescommon-shared artsmoduleseffects-shared @@ -50,7 +50,7 @@ tde_add_library( artsmodulesmixers SHARED add_custom_command( OUTPUT - artsmodulesmixers.cc artsmodulesmixers.h + artsmodulesmixers.cpp artsmodulesmixers.h artsmodulesmixers.mcopclass artsmodulesmixers.mcoptype COMMAND ${ARTS_MCOPIDL_EXECUTABLE} -t -I${CMAKE_SOURCE_DIR}/arts/gui/common diff --git a/arts/modules/mixers/Makefile.am b/arts/modules/mixers/Makefile.am index b504bfba..0cb0b666 100644 --- a/arts/modules/mixers/Makefile.am +++ b/arts/modules/mixers/Makefile.am @@ -25,10 +25,10 @@ MCOPINCLUDES = \ lib_LTLIBRARIES = libartsmodulesmixers.la -libartsmodulesmixers_la_SOURCES = artsmodulesmixers.cc \ - monosimplemixerchannel_impl.cc monosimplemixerchannelguifactory_impl.cc \ - simplemixerchannel_impl.cc simplemixerchannelguifactory_impl.cc \ - littlestereomixerchannel_impl.cc +libartsmodulesmixers_la_SOURCES = artsmodulesmixers.cpp \ + monosimplemixerchannel_impl.cpp monosimplemixerchannelguifactory_impl.cpp \ + simplemixerchannel_impl.cpp simplemixerchannelguifactory_impl.cpp \ + littlestereomixerchannel_impl.cpp libartsmodulesmixers_la_COMPILE_FIRST = ../synth/artsmodulessynth.h \ ../../midi/artsmidi.h ../common/artsmodulescommon.h ../../gui/common/artsgui.h \ artsmodulesmixers.h @@ -40,10 +40,10 @@ libartsmodulesmixers_la_LIBADD = \ libartsmodulesmixers_la_LDFLAGS = $(all_libraries) -L$(arts_libraries) -no-undefined -artsmodulesmixers.cc artsmodulesmixers.h artsmodulesmixers.mcoptype artsmodulesmixers.mcopclass: $(srcdir)/artsmodulesmixers.idl $(MCOPIDL) +artsmodulesmixers.cpp artsmodulesmixers.h artsmodulesmixers.mcoptype artsmodulesmixers.mcopclass: $(srcdir)/artsmodulesmixers.idl $(MCOPIDL) $(MCOPIDL) -t $(MCOPINCLUDES) $(srcdir)/artsmodulesmixers.idl -DISTCLEANFILES= artsmodulesmixers.cc artsmodulesmixers.h artsmodulesmixers.mcop* +DISTCLEANFILES= artsmodulesmixers.cpp artsmodulesmixers.h artsmodulesmixers.mcop* artsincludedir = $(includedir)/arts artsinclude_HEADERS = artsmodulesmixers.h artsmodulesmixers.idl diff --git a/arts/modules/mixers/artsmodulesmixers.idl b/arts/modules/mixers/artsmodulesmixers.idl index 56ff073b..dbe82c5c 100644 --- a/arts/modules/mixers/artsmodulesmixers.idl +++ b/arts/modules/mixers/artsmodulesmixers.idl @@ -25,7 +25,7 @@ */ /* -* DISCLAIMER: The interfaces in artsmodules.idl (and the derived .cc/.h files) +* DISCLAIMER: The interfaces in artsmodules.idl (and the derived .cpp/.h files) * DO NOT GUARANTEE BINARY COMPATIBILITY YET. * * They are intended for developers. You shouldn't expect that applications in diff --git a/arts/modules/mixers/littlestereomixerchannel_impl.cc b/arts/modules/mixers/littlestereomixerchannel_impl.cc deleted file mode 100644 index 3b14fa39..00000000 --- a/arts/modules/mixers/littlestereomixerchannel_impl.cc +++ /dev/null @@ -1,134 +0,0 @@ - /* - - Copyright ( C ) 2002-2003 Arnold Krille - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "artsmodulesmixers.h" -#include "artsmoduleseffects.h" - -#include -#include -#include -#include -#include "artsgui.h" - -#include - -using namespace Arts; - -namespace Arts { - -class LittleStereoMixerChannel_impl : virtual public LittleStereoMixerChannel_skel, - virtual public StdSynthModule -{ -protected: - std::string _name; - Arts::StereoBalance _balance; - Arts::StereoVolumeControl _volume; -public: - LittleStereoMixerChannel_impl() - { - arts_debug( "LittleStereo startup" ); - if( _balance.isNull() ) arts_debug( "\n\nCouldn't create StereoBalance!!!!\n\n" ); - if( _volume.isNull() ) arts_debug( "\n\nCouldn't create StereoVolumeControl!!!!\n\n" ); - _balance.balance( 0 ); - _volume.scaleFactor( 1 ); - arts_debug( "startup ok\n" ); - } - - std::string name() { return _name; } - void name( const std::string& n ) { arts_debug( "Name = %s", n.c_str() ); _name = n; } - - //Arts::StereoBalance balance() { return _balance; } - - //Arts::StereoVolumeControl volume() { return _volume; } - - float balance() { return _balance.balance(); } - void balance( float n ) { _balance.balance( n ); } - - float volume() { return _volume.scaleFactor(); } - void volume( float n ) { _volume.scaleFactor( n ); } - - void streamInit() - { - arts_debug( "LittleStereo::streamInit()" ); - if( _balance.isNull() ) arts_warning( "Couldn't create StereoBalance!!!!\n" ); - if( _volume.isNull() ) arts_warning( "Couldn't create StereoVolumeControl!!!!\n" ); - - arts_debug( "LittleStereo::streamInit() starts" ); - _balance.start(); - _volume.start(); - - arts_debug( "LittleStereo::streamInit() first connects" ); - _node()->virtualize( "inleft", _balance._node(), "inleft" ); - _node()->virtualize( "inright", _balance._node(), "inright" ); - arts_debug( "LittleStereo::streamInit() middle connects" ); - connect( _balance, "outleft", _volume, "inleft" ); - connect( _balance, "outright", _volume, "inright" ); - arts_debug( "LittleStereo::streamInit() last connects" ); - _node()->virtualize( "outleft", _volume._node(), "outleft" ); - _node()->virtualize( "outright", _volume._node(), "outright" ); - arts_debug( "LittleStereo::streamInit() finished.\nbye" ); - _balance.balance( 0 ); - _volume.scaleFactor( 1 ); - } - - void streamEnd() - { - _balance.stop(); - _volume.stop(); - } - -}; -REGISTER_IMPLEMENTATION( LittleStereoMixerChannel_impl ); - -class LittleStereoMixerChannelGuiFactory_impl : virtual public LittleStereoMixerChannelGuiFactory_skel -{ -public: - Widget createGui( Object object ) - { - arts_return_val_if_fail(!object.isNull(), Arts::Widget::null()); - LittleStereoMixerChannel ch= DynamicCast(object); - arts_return_val_if_fail(!ch.isNull(), Arts::Widget::null()); - - Arts::LayoutBox vbox; - vbox.direction( Arts::TopToBottom ); - - Poti pan; - pan.caption( i18n( "pan" ).utf8().data() ); - pan.color( "grey" ); pan.min( -1.0 ); pan.max( 1.0 ); - pan.value( ch.balance() ); - connect( pan, "value_changed", ch, "balance" ); - vbox.addWidget( pan ); - - Fader volume; - volume.caption( i18n( "volume" ).utf8().data() ); - volume.color( "red" ); volume.min( 0.01 ); volume.max( 2 ); - //volume.logarithmic( 2 ); - volume.value( ch.volume() ); - connect( volume, "value_changed", ch, "volume" ); - vbox.addWidget( volume ); - - return vbox; - } -}; -REGISTER_IMPLEMENTATION( LittleStereoMixerChannelGuiFactory_impl ); - -} - diff --git a/arts/modules/mixers/littlestereomixerchannel_impl.cpp b/arts/modules/mixers/littlestereomixerchannel_impl.cpp new file mode 100644 index 00000000..3b14fa39 --- /dev/null +++ b/arts/modules/mixers/littlestereomixerchannel_impl.cpp @@ -0,0 +1,134 @@ + /* + + Copyright ( C ) 2002-2003 Arnold Krille + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "artsmodulesmixers.h" +#include "artsmoduleseffects.h" + +#include +#include +#include +#include +#include "artsgui.h" + +#include + +using namespace Arts; + +namespace Arts { + +class LittleStereoMixerChannel_impl : virtual public LittleStereoMixerChannel_skel, + virtual public StdSynthModule +{ +protected: + std::string _name; + Arts::StereoBalance _balance; + Arts::StereoVolumeControl _volume; +public: + LittleStereoMixerChannel_impl() + { + arts_debug( "LittleStereo startup" ); + if( _balance.isNull() ) arts_debug( "\n\nCouldn't create StereoBalance!!!!\n\n" ); + if( _volume.isNull() ) arts_debug( "\n\nCouldn't create StereoVolumeControl!!!!\n\n" ); + _balance.balance( 0 ); + _volume.scaleFactor( 1 ); + arts_debug( "startup ok\n" ); + } + + std::string name() { return _name; } + void name( const std::string& n ) { arts_debug( "Name = %s", n.c_str() ); _name = n; } + + //Arts::StereoBalance balance() { return _balance; } + + //Arts::StereoVolumeControl volume() { return _volume; } + + float balance() { return _balance.balance(); } + void balance( float n ) { _balance.balance( n ); } + + float volume() { return _volume.scaleFactor(); } + void volume( float n ) { _volume.scaleFactor( n ); } + + void streamInit() + { + arts_debug( "LittleStereo::streamInit()" ); + if( _balance.isNull() ) arts_warning( "Couldn't create StereoBalance!!!!\n" ); + if( _volume.isNull() ) arts_warning( "Couldn't create StereoVolumeControl!!!!\n" ); + + arts_debug( "LittleStereo::streamInit() starts" ); + _balance.start(); + _volume.start(); + + arts_debug( "LittleStereo::streamInit() first connects" ); + _node()->virtualize( "inleft", _balance._node(), "inleft" ); + _node()->virtualize( "inright", _balance._node(), "inright" ); + arts_debug( "LittleStereo::streamInit() middle connects" ); + connect( _balance, "outleft", _volume, "inleft" ); + connect( _balance, "outright", _volume, "inright" ); + arts_debug( "LittleStereo::streamInit() last connects" ); + _node()->virtualize( "outleft", _volume._node(), "outleft" ); + _node()->virtualize( "outright", _volume._node(), "outright" ); + arts_debug( "LittleStereo::streamInit() finished.\nbye" ); + _balance.balance( 0 ); + _volume.scaleFactor( 1 ); + } + + void streamEnd() + { + _balance.stop(); + _volume.stop(); + } + +}; +REGISTER_IMPLEMENTATION( LittleStereoMixerChannel_impl ); + +class LittleStereoMixerChannelGuiFactory_impl : virtual public LittleStereoMixerChannelGuiFactory_skel +{ +public: + Widget createGui( Object object ) + { + arts_return_val_if_fail(!object.isNull(), Arts::Widget::null()); + LittleStereoMixerChannel ch= DynamicCast(object); + arts_return_val_if_fail(!ch.isNull(), Arts::Widget::null()); + + Arts::LayoutBox vbox; + vbox.direction( Arts::TopToBottom ); + + Poti pan; + pan.caption( i18n( "pan" ).utf8().data() ); + pan.color( "grey" ); pan.min( -1.0 ); pan.max( 1.0 ); + pan.value( ch.balance() ); + connect( pan, "value_changed", ch, "balance" ); + vbox.addWidget( pan ); + + Fader volume; + volume.caption( i18n( "volume" ).utf8().data() ); + volume.color( "red" ); volume.min( 0.01 ); volume.max( 2 ); + //volume.logarithmic( 2 ); + volume.value( ch.volume() ); + connect( volume, "value_changed", ch, "volume" ); + vbox.addWidget( volume ); + + return vbox; + } +}; +REGISTER_IMPLEMENTATION( LittleStereoMixerChannelGuiFactory_impl ); + +} + diff --git a/arts/modules/mixers/monosimplemixerchannel_impl.cc b/arts/modules/mixers/monosimplemixerchannel_impl.cc deleted file mode 100644 index 04bad0ce..00000000 --- a/arts/modules/mixers/monosimplemixerchannel_impl.cc +++ /dev/null @@ -1,106 +0,0 @@ -#include "artsmodulesmixers.h" -#include "flowsystem.h" -#include "stdsynthmodule.h" -#include "connect.h" - -namespace Arts { -class MonoSimpleMixerChannel_impl : virtual public MonoSimpleMixerChannel_skel, - virtual public StdSynthModule -{ -protected: - Synth_STD_EQUALIZER _equalizer; - StereoEffectStack _insertEffects; - Synth_MUL mulGain; - Synth_MUL mulVolumeLeft, mulVolumeRight; - float _gain, _pan, _volume, pLeft, pRight; - std::string _name; -public: - MonoSimpleMixerChannel_impl() - : _gain(1.0), _pan(0), _volume(1.0), pLeft(1), pRight(1) - { - setValue(mulVolumeLeft,"invalue2",_volume*pLeft); - setValue(mulVolumeRight,"invalue2",_volume*pRight); - setValue(mulGain,"invalue2",_gain); - } - - Synth_STD_EQUALIZER equalizer() { return _equalizer; } - StereoEffectStack insertEffects() { return _insertEffects; } - - float gain() { return _gain; } - void gain(float g) - { - if(g != _gain) { - _gain = g; - setValue(mulGain,"invalue2",g); - gain_changed(g); - } - } - - float volume() { return _volume; } - void volume(float v) - { - if(v != _volume) { - _volume = v; - setValue(mulVolumeLeft,"invalue2",v*pLeft); - setValue(mulVolumeRight,"invalue2",v*pRight); - volume_changed(v); - } - } - - float pan() { return _pan; } - void pan(float p) - { - if(p != _pan) - { - _pan = p; - pLeft = 1.0; - pRight = 1.0; - if(p > 0) - pLeft = 1-p; - else - pRight = 1+p; - setValue(mulVolumeLeft,"invalue2",_volume*pLeft); - setValue(mulVolumeRight,"invalue2",_volume*pRight); - pan_changed(p); - } - } - - std::string name() { return _name; } - void name(const std::string& newName) - { - if(_name != newName) { - _name = newName; - name_changed(newName); - } - } - - void streamInit() - { - _equalizer.start(); - mulVolumeLeft.start(); - mulVolumeRight.start(); - mulGain.start(); - //_insertEffects.start(); - - _node()->virtualize("inleft",mulGain._node(),"invalue1"); - connect(mulGain,"outvalue",_equalizer,"invalue"); - //connect(_equalizer,"outvalue",_insertEffects,"inleft"); - //connect(_insertEffects,"outleft",mulVolume,"invalue1"); - connect(_equalizer,"outvalue",mulVolumeLeft,"invalue1"); - connect(_equalizer,"outvalue",mulVolumeRight,"invalue1"); - _node()->virtualize("outleft",mulVolumeLeft._node(),"outvalue"); - _node()->virtualize("outright",mulVolumeRight._node(),"outvalue"); - - } - void streamEnd() - { - _equalizer.stop(); - //_insertEffects.stop(); - mulVolumeLeft.stop(); - mulVolumeRight.stop(); - mulGain.stop(); - } -}; -REGISTER_IMPLEMENTATION(MonoSimpleMixerChannel_impl); -} - diff --git a/arts/modules/mixers/monosimplemixerchannel_impl.cpp b/arts/modules/mixers/monosimplemixerchannel_impl.cpp new file mode 100644 index 00000000..04bad0ce --- /dev/null +++ b/arts/modules/mixers/monosimplemixerchannel_impl.cpp @@ -0,0 +1,106 @@ +#include "artsmodulesmixers.h" +#include "flowsystem.h" +#include "stdsynthmodule.h" +#include "connect.h" + +namespace Arts { +class MonoSimpleMixerChannel_impl : virtual public MonoSimpleMixerChannel_skel, + virtual public StdSynthModule +{ +protected: + Synth_STD_EQUALIZER _equalizer; + StereoEffectStack _insertEffects; + Synth_MUL mulGain; + Synth_MUL mulVolumeLeft, mulVolumeRight; + float _gain, _pan, _volume, pLeft, pRight; + std::string _name; +public: + MonoSimpleMixerChannel_impl() + : _gain(1.0), _pan(0), _volume(1.0), pLeft(1), pRight(1) + { + setValue(mulVolumeLeft,"invalue2",_volume*pLeft); + setValue(mulVolumeRight,"invalue2",_volume*pRight); + setValue(mulGain,"invalue2",_gain); + } + + Synth_STD_EQUALIZER equalizer() { return _equalizer; } + StereoEffectStack insertEffects() { return _insertEffects; } + + float gain() { return _gain; } + void gain(float g) + { + if(g != _gain) { + _gain = g; + setValue(mulGain,"invalue2",g); + gain_changed(g); + } + } + + float volume() { return _volume; } + void volume(float v) + { + if(v != _volume) { + _volume = v; + setValue(mulVolumeLeft,"invalue2",v*pLeft); + setValue(mulVolumeRight,"invalue2",v*pRight); + volume_changed(v); + } + } + + float pan() { return _pan; } + void pan(float p) + { + if(p != _pan) + { + _pan = p; + pLeft = 1.0; + pRight = 1.0; + if(p > 0) + pLeft = 1-p; + else + pRight = 1+p; + setValue(mulVolumeLeft,"invalue2",_volume*pLeft); + setValue(mulVolumeRight,"invalue2",_volume*pRight); + pan_changed(p); + } + } + + std::string name() { return _name; } + void name(const std::string& newName) + { + if(_name != newName) { + _name = newName; + name_changed(newName); + } + } + + void streamInit() + { + _equalizer.start(); + mulVolumeLeft.start(); + mulVolumeRight.start(); + mulGain.start(); + //_insertEffects.start(); + + _node()->virtualize("inleft",mulGain._node(),"invalue1"); + connect(mulGain,"outvalue",_equalizer,"invalue"); + //connect(_equalizer,"outvalue",_insertEffects,"inleft"); + //connect(_insertEffects,"outleft",mulVolume,"invalue1"); + connect(_equalizer,"outvalue",mulVolumeLeft,"invalue1"); + connect(_equalizer,"outvalue",mulVolumeRight,"invalue1"); + _node()->virtualize("outleft",mulVolumeLeft._node(),"outvalue"); + _node()->virtualize("outright",mulVolumeRight._node(),"outvalue"); + + } + void streamEnd() + { + _equalizer.stop(); + //_insertEffects.stop(); + mulVolumeLeft.stop(); + mulVolumeRight.stop(); + mulGain.stop(); + } +}; +REGISTER_IMPLEMENTATION(MonoSimpleMixerChannel_impl); +} + diff --git a/arts/modules/mixers/monosimplemixerchannelguifactory_impl.cc b/arts/modules/mixers/monosimplemixerchannelguifactory_impl.cc deleted file mode 100644 index 28fbab55..00000000 --- a/arts/modules/mixers/monosimplemixerchannelguifactory_impl.cc +++ /dev/null @@ -1,94 +0,0 @@ -#include "artsmodulesmixers.h" -#include "debug.h" -#include "connect.h" - -#include -#include - -namespace Arts { - - class MonoSimpleMixerChannelGuiFactory_impl : virtual public MonoSimpleMixerChannelGuiFactory_skel - { - public: - Widget createGui(Object object) - { - TDEGlobal::locale()->insertCatalogue( "artsmodules" ); - arts_return_val_if_fail(!object.isNull(), Arts::Widget::null()); - MonoSimpleMixerChannel ch= DynamicCast(object); - arts_return_val_if_fail(!ch.isNull(), Arts::Widget::null()); - - Arts::LayoutBox vbox; - vbox.direction( Arts::TopToBottom ); - - Poti gain; - gain.caption(i18n("gain").utf8().data()); - gain.color("red"); gain.min(0.01); gain.max(4); - gain.value(ch.gain()); - connect(gain,"value_changed", ch, "gain"); - vbox.addWidget( gain ); - - Arts::PopupBox eqbox; - eqbox.name( i18n( "EQ" ).utf8().data() ); - eqbox.direction( Arts::TopToBottom ); - vbox.addWidget( eqbox ); - - Arts::LayoutBox eq; - eq.direction( Arts::TopToBottom ); - eqbox.widget( eq ); - - Poti high; - high.caption(i18n("volume","high").utf8().data()); - high.color("blue"); high.min(-12); high.max(12); - high.value(ch.equalizer().high()); - connect(high,"value_changed", ch.equalizer(), "high"); - eq.addWidget( high ); - - Poti mid; - mid.caption(i18n("volume","mid").utf8().data()); - mid.color("blue"); mid.min(-12); mid.max(12); - mid.value(ch.equalizer().mid()); - connect(mid,"value_changed", ch.equalizer(), "mid"); - eq.addWidget( mid ); - - Poti low; - low.caption(i18n("volume","low").utf8().data()); - low.color("blue"); low.min(-12); low.max(12); - low.value(ch.equalizer().low()); - connect(low,"value_changed", ch.equalizer(), "low"); - eq.addWidget( low ); - - Poti frequency; - frequency.caption(i18n("frequency").utf8().data()); - frequency.color("darkgreen"); frequency.min(20); frequency.max(10000); - frequency.value(ch.equalizer().frequency()); - frequency.logarithmic(2.0); - connect(frequency,"value_changed", ch.equalizer(), "frequency"); - eq.addWidget( frequency ); - - Poti q; - q.caption(i18n( "q" ).utf8().data()); - q.color("darkgreen"); q.min(0.01); q.max(10); - q.value(ch.equalizer().q()); - q.logarithmic(2.0); - connect(q,"value_changed", ch.equalizer(), "q"); - eq.addWidget( q ); - - Poti pan; - pan.caption(i18n("pan").utf8().data()); - pan.color("grey"); pan.min(-1.0); pan.max(1.0); - pan.value(ch.pan()); - connect(pan,"value_changed",ch,"pan"); - vbox.addWidget( pan ); - - Fader volume; - volume.caption(i18n("volume").utf8().data()); - volume.color("red"); volume.min(0.01); volume.max(4); - volume.value(ch.volume()); - connect(volume,"value_changed", ch, "volume"); - vbox.addWidget( volume ); - - return vbox; - } - }; - REGISTER_IMPLEMENTATION(MonoSimpleMixerChannelGuiFactory_impl); -} diff --git a/arts/modules/mixers/monosimplemixerchannelguifactory_impl.cpp b/arts/modules/mixers/monosimplemixerchannelguifactory_impl.cpp new file mode 100644 index 00000000..28fbab55 --- /dev/null +++ b/arts/modules/mixers/monosimplemixerchannelguifactory_impl.cpp @@ -0,0 +1,94 @@ +#include "artsmodulesmixers.h" +#include "debug.h" +#include "connect.h" + +#include +#include + +namespace Arts { + + class MonoSimpleMixerChannelGuiFactory_impl : virtual public MonoSimpleMixerChannelGuiFactory_skel + { + public: + Widget createGui(Object object) + { + TDEGlobal::locale()->insertCatalogue( "artsmodules" ); + arts_return_val_if_fail(!object.isNull(), Arts::Widget::null()); + MonoSimpleMixerChannel ch= DynamicCast(object); + arts_return_val_if_fail(!ch.isNull(), Arts::Widget::null()); + + Arts::LayoutBox vbox; + vbox.direction( Arts::TopToBottom ); + + Poti gain; + gain.caption(i18n("gain").utf8().data()); + gain.color("red"); gain.min(0.01); gain.max(4); + gain.value(ch.gain()); + connect(gain,"value_changed", ch, "gain"); + vbox.addWidget( gain ); + + Arts::PopupBox eqbox; + eqbox.name( i18n( "EQ" ).utf8().data() ); + eqbox.direction( Arts::TopToBottom ); + vbox.addWidget( eqbox ); + + Arts::LayoutBox eq; + eq.direction( Arts::TopToBottom ); + eqbox.widget( eq ); + + Poti high; + high.caption(i18n("volume","high").utf8().data()); + high.color("blue"); high.min(-12); high.max(12); + high.value(ch.equalizer().high()); + connect(high,"value_changed", ch.equalizer(), "high"); + eq.addWidget( high ); + + Poti mid; + mid.caption(i18n("volume","mid").utf8().data()); + mid.color("blue"); mid.min(-12); mid.max(12); + mid.value(ch.equalizer().mid()); + connect(mid,"value_changed", ch.equalizer(), "mid"); + eq.addWidget( mid ); + + Poti low; + low.caption(i18n("volume","low").utf8().data()); + low.color("blue"); low.min(-12); low.max(12); + low.value(ch.equalizer().low()); + connect(low,"value_changed", ch.equalizer(), "low"); + eq.addWidget( low ); + + Poti frequency; + frequency.caption(i18n("frequency").utf8().data()); + frequency.color("darkgreen"); frequency.min(20); frequency.max(10000); + frequency.value(ch.equalizer().frequency()); + frequency.logarithmic(2.0); + connect(frequency,"value_changed", ch.equalizer(), "frequency"); + eq.addWidget( frequency ); + + Poti q; + q.caption(i18n( "q" ).utf8().data()); + q.color("darkgreen"); q.min(0.01); q.max(10); + q.value(ch.equalizer().q()); + q.logarithmic(2.0); + connect(q,"value_changed", ch.equalizer(), "q"); + eq.addWidget( q ); + + Poti pan; + pan.caption(i18n("pan").utf8().data()); + pan.color("grey"); pan.min(-1.0); pan.max(1.0); + pan.value(ch.pan()); + connect(pan,"value_changed",ch,"pan"); + vbox.addWidget( pan ); + + Fader volume; + volume.caption(i18n("volume").utf8().data()); + volume.color("red"); volume.min(0.01); volume.max(4); + volume.value(ch.volume()); + connect(volume,"value_changed", ch, "volume"); + vbox.addWidget( volume ); + + return vbox; + } + }; + REGISTER_IMPLEMENTATION(MonoSimpleMixerChannelGuiFactory_impl); +} diff --git a/arts/modules/mixers/simplemixerchannel_impl.cc b/arts/modules/mixers/simplemixerchannel_impl.cc deleted file mode 100644 index 0c00768a..00000000 --- a/arts/modules/mixers/simplemixerchannel_impl.cc +++ /dev/null @@ -1,132 +0,0 @@ -#include "artsmodulesmixers.h" -#include "flowsystem.h" -#include "stdsynthmodule.h" -#include "connect.h" - -namespace Arts { -class SimpleMixerChannel_impl : virtual public SimpleMixerChannel_skel, - virtual public StdSynthModule -{ -protected: - Synth_STD_EQUALIZER _equalizerLeft, _equalizerRight; - StereoEffectStack _insertEffects; - Synth_MUL mulGainLeft, mulGainRight; - Synth_MUL mulVolumeLeft, mulVolumeRight; - float _gainLeft, _gainRight, _pan, _volumeLeft, _volumeRight, pLeft, pRight; - std::string _name; -public: - SimpleMixerChannel_impl() - : _gainLeft(1.0), _gainRight(1.0), _pan(0), _volumeLeft(1.0), _volumeRight(1.0), pLeft(1), pRight(1) - { - setValue(mulVolumeLeft,"invalue2",_volumeLeft*pLeft); - setValue(mulVolumeRight,"invalue2",_volumeRight*pRight); - setValue(mulGainLeft,"invalue2",_gainLeft); - setValue(mulGainRight,"invalue2",_gainRight); - } - - Synth_STD_EQUALIZER equalizerLeft() { return _equalizerLeft; } - Synth_STD_EQUALIZER equalizerRight() { return _equalizerRight; } - StereoEffectStack insertEffects() { return _insertEffects; } - - float gainLeft() { return _gainLeft; } - void gainLeft(float g) - { - if(g != _gainLeft) { - _gainLeft = g; - setValue(mulGainLeft,"invalue2",g); - gainLeft_changed(g); - } - } - - float gainRight() { return _gainRight; } - void gainRight(float g) - { - if(g != _gainRight) { - _gainRight = g; - setValue(mulGainRight,"invalue2",g); - gainRight_changed(g); - } - } - - float volumeLeft() { return _volumeLeft; } - void volumeLeft(float v) - { - if(v != _volumeLeft) { - _volumeLeft = v; - setValue(mulVolumeLeft,"invalue2",v*pLeft); - volumeLeft_changed(v); - } - } - - float volumeRight() { return _volumeRight; } - void volumeRight(float v) - { - if(v != _volumeRight) { - _volumeRight = v; - setValue(mulVolumeRight,"invalue2",v*pRight); - volumeRight_changed(v); - } - } - - float pan() { return _pan; } - void pan(float p) - { - if(p != _pan) - { - _pan = p; - pLeft = 1.0; - pRight = 1.0; - if(p > 0) - pLeft = 1-p; - else - pRight = 1+p; - setValue(mulVolumeLeft,"invalue2",_volumeLeft*pLeft); - setValue(mulVolumeRight,"invalue2",_volumeRight*pRight); - pan_changed(p); - } - } - - std::string name() { return _name; } - void name(const std::string& newName) - { - if(_name != newName) { - _name = newName; - name_changed(newName); - } - } - - void streamInit() - { - _equalizerLeft.start(); - _equalizerRight.start(); - _insertEffects.start(); - mulVolumeLeft.start(); - mulVolumeRight.start(); - mulGainLeft.start(); - mulGainRight.start(); - - _node()->virtualize("inleft",mulGainLeft._node(),"invalue1"); - _node()->virtualize("inright",mulGainRight._node(),"invalue1"); - connect(mulGainLeft,"outvalue",_equalizerLeft,"invalue"); - connect(mulGainRight,"outvalue",_equalizerRight,"invalue"); - connect(_equalizerLeft,"outvalue",_insertEffects,"inleft"); - connect(_equalizerRight,"outvalue",_insertEffects,"inright"); - connect(_insertEffects,"outleft",mulVolumeLeft,"invalue1"); - connect(_insertEffects,"outright",mulVolumeRight,"invalue1"); - _node()->virtualize("outleft",mulVolumeLeft._node(),"outvalue"); - _node()->virtualize("outright",mulVolumeRight._node(),"outvalue"); - } - void streamEnd() - { - _equalizerLeft.stop(); - _equalizerRight.stop(); - _insertEffects.stop(); - mulVolumeLeft.stop(); - mulVolumeRight.stop(); - mulGainLeft.stop(); - mulGainRight.stop(); - } -}; -REGISTER_IMPLEMENTATION(SimpleMixerChannel_impl); -} - diff --git a/arts/modules/mixers/simplemixerchannel_impl.cpp b/arts/modules/mixers/simplemixerchannel_impl.cpp new file mode 100644 index 00000000..0c00768a --- /dev/null +++ b/arts/modules/mixers/simplemixerchannel_impl.cpp @@ -0,0 +1,132 @@ +#include "artsmodulesmixers.h" +#include "flowsystem.h" +#include "stdsynthmodule.h" +#include "connect.h" + +namespace Arts { +class SimpleMixerChannel_impl : virtual public SimpleMixerChannel_skel, + virtual public StdSynthModule +{ +protected: + Synth_STD_EQUALIZER _equalizerLeft, _equalizerRight; + StereoEffectStack _insertEffects; + Synth_MUL mulGainLeft, mulGainRight; + Synth_MUL mulVolumeLeft, mulVolumeRight; + float _gainLeft, _gainRight, _pan, _volumeLeft, _volumeRight, pLeft, pRight; + std::string _name; +public: + SimpleMixerChannel_impl() + : _gainLeft(1.0), _gainRight(1.0), _pan(0), _volumeLeft(1.0), _volumeRight(1.0), pLeft(1), pRight(1) + { + setValue(mulVolumeLeft,"invalue2",_volumeLeft*pLeft); + setValue(mulVolumeRight,"invalue2",_volumeRight*pRight); + setValue(mulGainLeft,"invalue2",_gainLeft); + setValue(mulGainRight,"invalue2",_gainRight); + } + + Synth_STD_EQUALIZER equalizerLeft() { return _equalizerLeft; } + Synth_STD_EQUALIZER equalizerRight() { return _equalizerRight; } + StereoEffectStack insertEffects() { return _insertEffects; } + + float gainLeft() { return _gainLeft; } + void gainLeft(float g) + { + if(g != _gainLeft) { + _gainLeft = g; + setValue(mulGainLeft,"invalue2",g); + gainLeft_changed(g); + } + } + + float gainRight() { return _gainRight; } + void gainRight(float g) + { + if(g != _gainRight) { + _gainRight = g; + setValue(mulGainRight,"invalue2",g); + gainRight_changed(g); + } + } + + float volumeLeft() { return _volumeLeft; } + void volumeLeft(float v) + { + if(v != _volumeLeft) { + _volumeLeft = v; + setValue(mulVolumeLeft,"invalue2",v*pLeft); + volumeLeft_changed(v); + } + } + + float volumeRight() { return _volumeRight; } + void volumeRight(float v) + { + if(v != _volumeRight) { + _volumeRight = v; + setValue(mulVolumeRight,"invalue2",v*pRight); + volumeRight_changed(v); + } + } + + float pan() { return _pan; } + void pan(float p) + { + if(p != _pan) + { + _pan = p; + pLeft = 1.0; + pRight = 1.0; + if(p > 0) + pLeft = 1-p; + else + pRight = 1+p; + setValue(mulVolumeLeft,"invalue2",_volumeLeft*pLeft); + setValue(mulVolumeRight,"invalue2",_volumeRight*pRight); + pan_changed(p); + } + } + + std::string name() { return _name; } + void name(const std::string& newName) + { + if(_name != newName) { + _name = newName; + name_changed(newName); + } + } + + void streamInit() + { + _equalizerLeft.start(); + _equalizerRight.start(); + _insertEffects.start(); + mulVolumeLeft.start(); + mulVolumeRight.start(); + mulGainLeft.start(); + mulGainRight.start(); + + _node()->virtualize("inleft",mulGainLeft._node(),"invalue1"); + _node()->virtualize("inright",mulGainRight._node(),"invalue1"); + connect(mulGainLeft,"outvalue",_equalizerLeft,"invalue"); + connect(mulGainRight,"outvalue",_equalizerRight,"invalue"); + connect(_equalizerLeft,"outvalue",_insertEffects,"inleft"); + connect(_equalizerRight,"outvalue",_insertEffects,"inright"); + connect(_insertEffects,"outleft",mulVolumeLeft,"invalue1"); + connect(_insertEffects,"outright",mulVolumeRight,"invalue1"); + _node()->virtualize("outleft",mulVolumeLeft._node(),"outvalue"); + _node()->virtualize("outright",mulVolumeRight._node(),"outvalue"); + } + void streamEnd() + { + _equalizerLeft.stop(); + _equalizerRight.stop(); + _insertEffects.stop(); + mulVolumeLeft.stop(); + mulVolumeRight.stop(); + mulGainLeft.stop(); + mulGainRight.stop(); + } +}; +REGISTER_IMPLEMENTATION(SimpleMixerChannel_impl); +} + diff --git a/arts/modules/mixers/simplemixerchannelguifactory_impl.cc b/arts/modules/mixers/simplemixerchannelguifactory_impl.cc deleted file mode 100644 index 73ab31e2..00000000 --- a/arts/modules/mixers/simplemixerchannelguifactory_impl.cc +++ /dev/null @@ -1,82 +0,0 @@ -#include "artsmodulesmixers.h" -#include "debug.h" -#include "connect.h" - -#include -#include - -namespace Arts { - class SimpleMixerChannelGuiFactory_impl : virtual public SimpleMixerChannelGuiFactory_skel { - public: - Widget createGui(Object object) - { - TDEGlobal::locale()->insertCatalogue( "artsmodules" ); - arts_return_val_if_fail(!object.isNull(), Arts::Widget::null()); - SimpleMixerChannel ch = DynamicCast(object); - arts_return_val_if_fail(!ch.isNull(), Arts::Widget::null()); - - Arts::LayoutBox vbox; - vbox.direction( Arts::TopToBottom ); - - Poti high; - high.caption(i18n("volume","high").utf8().data()); - high.color("blue"); high.min(-12); high.max(12); - high.value(ch.equalizerLeft().high()); - connect(high,"value_changed", ch.equalizerLeft(), "high"); - connect(high,"value_changed", ch.equalizerRight(), "high"); - vbox.addWidget( high ); - - Poti mid; - mid.caption(i18n("volume","mid").utf8().data()); - mid.color("blue"); mid.min(-12); mid.max(12); - mid.value(ch.equalizerLeft().mid()); - connect(mid,"value_changed", ch.equalizerLeft(), "mid"); - connect(mid,"value_changed", ch.equalizerRight(), "mid"); - vbox.addWidget( mid ); - - Poti low; - low.caption(i18n("volume","low").utf8().data()); - low.color("blue"); low.min(-12); low.max(12); - low.value(ch.equalizerLeft().low()); - connect(low,"value_changed", ch.equalizerLeft(), "low"); - connect(low,"value_changed", ch.equalizerRight(), "low"); - vbox.addWidget( low ); - - Poti frequency; - frequency.caption(i18n("frequency").utf8().data()); - frequency.color("darkgreen"); frequency.min(200); frequency.max(10000); - frequency.value(ch.equalizerLeft().frequency()); - frequency.logarithmic(2.0); - connect(frequency,"value_changed", ch.equalizerLeft(), "frequency"); - connect(frequency,"value_changed", ch.equalizerRight(), "frequency"); - vbox.addWidget( frequency ); - - Poti q; - q.caption(i18n( "q" ).utf8().data()); - q.color("darkgreen"); q.min(0.01); q.max(10); - q.value(ch.equalizerLeft().q()); - q.logarithmic(2.0); - connect(q,"value_changed", ch.equalizerLeft(), "q"); - connect(q,"value_changed", ch.equalizerRight(), "q"); - vbox.addWidget( q ); - - Poti pan; - pan.caption(i18n("pan").utf8().data()); - pan.color("grey"); pan.min(-1.0); pan.max(1.0); - pan.value(ch.pan()); - connect(pan,"value_changed",ch,"pan"); - vbox.addWidget( pan ); - - Fader volume; - volume.caption(i18n("volume").utf8().data()); - volume.color("red"); volume.min(0.01); volume.max(4); - volume.value(ch.volumeLeft()); - connect(volume,"value_changed", ch, "volumeLeft"); - connect(volume,"value_changed", ch, "volumeRight"); - vbox.addWidget( volume ); - - return vbox; - } - }; - REGISTER_IMPLEMENTATION(SimpleMixerChannelGuiFactory_impl); -} diff --git a/arts/modules/mixers/simplemixerchannelguifactory_impl.cpp b/arts/modules/mixers/simplemixerchannelguifactory_impl.cpp new file mode 100644 index 00000000..73ab31e2 --- /dev/null +++ b/arts/modules/mixers/simplemixerchannelguifactory_impl.cpp @@ -0,0 +1,82 @@ +#include "artsmodulesmixers.h" +#include "debug.h" +#include "connect.h" + +#include +#include + +namespace Arts { + class SimpleMixerChannelGuiFactory_impl : virtual public SimpleMixerChannelGuiFactory_skel { + public: + Widget createGui(Object object) + { + TDEGlobal::locale()->insertCatalogue( "artsmodules" ); + arts_return_val_if_fail(!object.isNull(), Arts::Widget::null()); + SimpleMixerChannel ch = DynamicCast(object); + arts_return_val_if_fail(!ch.isNull(), Arts::Widget::null()); + + Arts::LayoutBox vbox; + vbox.direction( Arts::TopToBottom ); + + Poti high; + high.caption(i18n("volume","high").utf8().data()); + high.color("blue"); high.min(-12); high.max(12); + high.value(ch.equalizerLeft().high()); + connect(high,"value_changed", ch.equalizerLeft(), "high"); + connect(high,"value_changed", ch.equalizerRight(), "high"); + vbox.addWidget( high ); + + Poti mid; + mid.caption(i18n("volume","mid").utf8().data()); + mid.color("blue"); mid.min(-12); mid.max(12); + mid.value(ch.equalizerLeft().mid()); + connect(mid,"value_changed", ch.equalizerLeft(), "mid"); + connect(mid,"value_changed", ch.equalizerRight(), "mid"); + vbox.addWidget( mid ); + + Poti low; + low.caption(i18n("volume","low").utf8().data()); + low.color("blue"); low.min(-12); low.max(12); + low.value(ch.equalizerLeft().low()); + connect(low,"value_changed", ch.equalizerLeft(), "low"); + connect(low,"value_changed", ch.equalizerRight(), "low"); + vbox.addWidget( low ); + + Poti frequency; + frequency.caption(i18n("frequency").utf8().data()); + frequency.color("darkgreen"); frequency.min(200); frequency.max(10000); + frequency.value(ch.equalizerLeft().frequency()); + frequency.logarithmic(2.0); + connect(frequency,"value_changed", ch.equalizerLeft(), "frequency"); + connect(frequency,"value_changed", ch.equalizerRight(), "frequency"); + vbox.addWidget( frequency ); + + Poti q; + q.caption(i18n( "q" ).utf8().data()); + q.color("darkgreen"); q.min(0.01); q.max(10); + q.value(ch.equalizerLeft().q()); + q.logarithmic(2.0); + connect(q,"value_changed", ch.equalizerLeft(), "q"); + connect(q,"value_changed", ch.equalizerRight(), "q"); + vbox.addWidget( q ); + + Poti pan; + pan.caption(i18n("pan").utf8().data()); + pan.color("grey"); pan.min(-1.0); pan.max(1.0); + pan.value(ch.pan()); + connect(pan,"value_changed",ch,"pan"); + vbox.addWidget( pan ); + + Fader volume; + volume.caption(i18n("volume").utf8().data()); + volume.color("red"); volume.min(0.01); volume.max(4); + volume.value(ch.volumeLeft()); + connect(volume,"value_changed", ch, "volumeLeft"); + connect(volume,"value_changed", ch, "volumeRight"); + vbox.addWidget( volume ); + + return vbox; + } + }; + REGISTER_IMPLEMENTATION(SimpleMixerChannelGuiFactory_impl); +} diff --git a/arts/modules/synth/CMakeLists.txt b/arts/modules/synth/CMakeLists.txt index 4362aaa7..9930b55d 100644 --- a/arts/modules/synth/CMakeLists.txt +++ b/arts/modules/synth/CMakeLists.txt @@ -34,20 +34,20 @@ link_directories( tde_add_library( artsmodulessynth SHARED SOURCES - artsmodulessynth.cc - synth_xfade_impl.cc synth_autopanner_impl.cc synth_delay_impl.cc - synth_cdelay_impl.cc synth_envelope_adsr_impl.cc synth_pscale_impl.cc - synth_tremolo_impl.cc synth_fx_cflanger_impl.cc synth_compressor_impl.cc - synth_pitch_shift_impl.cc synth_pitch_shift_fft_impl.cc c_filter_stuff.c - synth_shelve_cutoff_impl.cc synth_brickwall_limiter_impl.cc - synth_std_equalizer_impl.cc synth_rc_impl.cc synth_moog_vcf_impl.cc - synth_atan_saturate_impl.cc synth_fm_source_impl.cc - synth_wave_tri_impl.cc synth_noise_impl.cc synth_wave_softsaw_impl.cc - synth_wave_square_impl.cc synth_wave_pulse_impl.cc synth_osc_impl.cc - synth_play_pat_impl.cc synth_capture_wav_impl.cc - synth_midi_test_impl.cc synth_sequence_impl.cc synth_sequence_freq_impl.cc - synth_midi_debug_impl.cc objectcache_impl.cc synth_nil_impl.cc - synth_debug_impl.cc synth_data_impl.cc synth_div_impl.cc + artsmodulessynth.cpp + synth_xfade_impl.cpp synth_autopanner_impl.cpp synth_delay_impl.cpp + synth_cdelay_impl.cpp synth_envelope_adsr_impl.cpp synth_pscale_impl.cpp + synth_tremolo_impl.cpp synth_fx_cflanger_impl.cpp synth_compressor_impl.cpp + synth_pitch_shift_impl.cpp synth_pitch_shift_fft_impl.cpp c_filter_stuff.c + synth_shelve_cutoff_impl.cpp synth_brickwall_limiter_impl.cpp + synth_std_equalizer_impl.cpp synth_rc_impl.cpp synth_moog_vcf_impl.cpp + synth_atan_saturate_impl.cpp synth_fm_source_impl.cpp + synth_wave_tri_impl.cpp synth_noise_impl.cpp synth_wave_softsaw_impl.cpp + synth_wave_square_impl.cpp synth_wave_pulse_impl.cpp synth_osc_impl.cpp + synth_play_pat_impl.cpp synth_capture_wav_impl.cpp + synth_midi_test_impl.cpp synth_sequence_impl.cpp synth_sequence_freq_impl.cpp + synth_midi_debug_impl.cpp objectcache_impl.cpp synth_nil_impl.cpp + synth_debug_impl.cpp synth_data_impl.cpp synth_div_impl.cpp VERSION 0.0.0 LINK artsbuilder-shared artsmidi_idl-shared @@ -57,7 +57,7 @@ tde_add_library( artsmodulessynth SHARED add_custom_command( OUTPUT - artsmodulessynth.cc artsmodulessynth.h + artsmodulessynth.cpp artsmodulessynth.h artsmodulessynth.mcopclass artsmodulessynth.mcoptype COMMAND ${ARTS_MCOPIDL_EXECUTABLE} -t -I${CMAKE_SOURCE_DIR}/arts/gui/common diff --git a/arts/modules/synth/Makefile.am b/arts/modules/synth/Makefile.am index 520b33fe..211d973c 100644 --- a/arts/modules/synth/Makefile.am +++ b/arts/modules/synth/Makefile.am @@ -15,17 +15,17 @@ MCOP_INCLUDES= \ lib_LTLIBRARIES = libartsmodulessynth.la -libartsmodulessynth_la_SOURCES = artsmodulessynth.cc \ - synth_xfade_impl.cc synth_autopanner_impl.cc synth_delay_impl.cc synth_cdelay_impl.cc \ - synth_envelope_adsr_impl.cc synth_pscale_impl.cc \ - synth_tremolo_impl.cc synth_fx_cflanger_impl.cc synth_compressor_impl.cc \ - synth_pitch_shift_impl.cc synth_pitch_shift_fft_impl.cc c_filter_stuff.c synth_shelve_cutoff_impl.cc synth_brickwall_limiter_impl.cc synth_std_equalizer_impl.cc synth_rc_impl.cc synth_moog_vcf_impl.cc synth_atan_saturate_impl.cc \ - synth_fm_source_impl.cc \ - synth_wave_tri_impl.cc synth_noise_impl.cc synth_wave_softsaw_impl.cc synth_wave_square_impl.cc synth_wave_pulse_impl.cc synth_osc_impl.cc synth_play_pat_impl.cc \ - synth_capture_wav_impl.cc \ - synth_midi_test_impl.cc synth_sequence_impl.cc synth_sequence_freq_impl.cc \ - synth_midi_debug_impl.cc objectcache_impl.cc synth_nil_impl.cc synth_debug_impl.cc synth_data_impl.cc \ - synth_div_impl.cc +libartsmodulessynth_la_SOURCES = artsmodulessynth.cpp \ + synth_xfade_impl.cpp synth_autopanner_impl.cpp synth_delay_impl.cpp synth_cdelay_impl.cpp \ + synth_envelope_adsr_impl.cpp synth_pscale_impl.cpp \ + synth_tremolo_impl.cpp synth_fx_cflanger_impl.cpp synth_compressor_impl.cpp \ + synth_pitch_shift_impl.cpp synth_pitch_shift_fft_impl.cpp c_filter_stuff.c synth_shelve_cutoff_impl.cpp synth_brickwall_limiter_impl.cpp synth_std_equalizer_impl.cpp synth_rc_impl.cpp synth_moog_vcf_impl.cpp synth_atan_saturate_impl.cpp \ + synth_fm_source_impl.cpp \ + synth_wave_tri_impl.cpp synth_noise_impl.cpp synth_wave_softsaw_impl.cpp synth_wave_square_impl.cpp synth_wave_pulse_impl.cpp synth_osc_impl.cpp synth_play_pat_impl.cpp \ + synth_capture_wav_impl.cpp \ + synth_midi_test_impl.cpp synth_sequence_impl.cpp synth_sequence_freq_impl.cpp \ + synth_midi_debug_impl.cpp objectcache_impl.cpp synth_nil_impl.cpp synth_debug_impl.cpp synth_data_impl.cpp \ + synth_div_impl.cpp libartsmodulessynth_la_COMPILE_FIRST = artsmodulessynth.h ../../midi/artsmidi.h libartsmodulessynth_la_LIBADD = \ @@ -36,10 +36,10 @@ libartsmodulessynth_la_LIBADD = \ #libartsmodulessynth_la_LIBADD = $(top_builddir)/arts/gui/common/libartsgui_idl.la $(top_builddir)/arts/midi/libartsmidi_idl.la -lartsflow -lartsflow_idl -lmcop $(LIBDL) $(LIB_TDEUI) $(LIB_TDECORE) libartsmodulessynth_la_LDFLAGS = $(all_libraries) -L$(arts_libraries) -lartsflow -lartsgsl -no-undefined -artsmodulessynth.cc artsmodulessynth.h artsmodulessynth.mcoptype artsmodulessynth.mcopclass: $(srcdir)/artsmodulessynth.idl $(MCOPIDL) +artsmodulessynth.cpp artsmodulessynth.h artsmodulessynth.mcoptype artsmodulessynth.mcopclass: $(srcdir)/artsmodulessynth.idl $(MCOPIDL) $(MCOPIDL) -t $(MCOP_INCLUDES) $(srcdir)/artsmodulessynth.idl -DISTCLEANFILES= artsmodulessynth.cc artsmodulessynth.h artsmodulessynth.mcop* +DISTCLEANFILES= artsmodulessynth.cpp artsmodulessynth.h artsmodulessynth.mcop* artsincludedir = $(includedir)/arts artsinclude_HEADERS = artsmodulessynth.h artsmodulessynth.idl diff --git a/arts/modules/synth/artsmodulessynth.idl b/arts/modules/synth/artsmodulessynth.idl index b9ac3d46..6ba4248b 100644 --- a/arts/modules/synth/artsmodulessynth.idl +++ b/arts/modules/synth/artsmodulessynth.idl @@ -25,7 +25,7 @@ */ /* -* DISCLAIMER: The interfaces in artsmodules.idl (and the derived .cc/.h files) +* DISCLAIMER: The interfaces in artsmodules.idl (and the derived .cpp/.h files) * DO NOT GUARANTEE BINARY COMPATIBILITY YET. * * They are intended for developers. You shouldn't expect that applications in diff --git a/arts/modules/synth/objectcache_impl.cc b/arts/modules/synth/objectcache_impl.cc deleted file mode 100644 index d4d833a3..00000000 --- a/arts/modules/synth/objectcache_impl.cc +++ /dev/null @@ -1,73 +0,0 @@ -/* - - Copyright (C) 2000 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "artsmodulessynth.h" -#include - -using namespace Arts; -using namespace std; - -namespace Arts { - - -class ObjectCache_impl : public ObjectCache_skel { -protected: - typedef map *> ObjectCacheMap; - ObjectCacheMap objects; - -public: - ~ObjectCache_impl() - { - ObjectCacheMap::iterator i; - for(i=objects.begin(); i != objects.end(); i++) - { - cout << "ObjectCache: deleting remaining " << - i->first << " objects" << endl; - delete i->second; - } - } - - void put(Object obj, const string& name) - { - list *l = objects[name]; - - if(l == 0) objects[name] = l = new list; - l->push_back(obj); - } - - Object get(const string& name) - { - list *l = objects[name]; - if(l && !l->empty()) - { - Object result = l->front(); - l->pop_front(); - - return result; - } - return Object::null(); - } -}; - -REGISTER_IMPLEMENTATION(ObjectCache_impl); -} - diff --git a/arts/modules/synth/objectcache_impl.cpp b/arts/modules/synth/objectcache_impl.cpp new file mode 100644 index 00000000..d4d833a3 --- /dev/null +++ b/arts/modules/synth/objectcache_impl.cpp @@ -0,0 +1,73 @@ +/* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "artsmodulessynth.h" +#include + +using namespace Arts; +using namespace std; + +namespace Arts { + + +class ObjectCache_impl : public ObjectCache_skel { +protected: + typedef map *> ObjectCacheMap; + ObjectCacheMap objects; + +public: + ~ObjectCache_impl() + { + ObjectCacheMap::iterator i; + for(i=objects.begin(); i != objects.end(); i++) + { + cout << "ObjectCache: deleting remaining " << + i->first << " objects" << endl; + delete i->second; + } + } + + void put(Object obj, const string& name) + { + list *l = objects[name]; + + if(l == 0) objects[name] = l = new list; + l->push_back(obj); + } + + Object get(const string& name) + { + list *l = objects[name]; + if(l && !l->empty()) + { + Object result = l->front(); + l->pop_front(); + + return result; + } + return Object::null(); + } +}; + +REGISTER_IMPLEMENTATION(ObjectCache_impl); +} + diff --git a/arts/modules/synth/synth_atan_saturate_impl.cc b/arts/modules/synth/synth_atan_saturate_impl.cc deleted file mode 100644 index 7eb0b513..00000000 --- a/arts/modules/synth/synth_atan_saturate_impl.cc +++ /dev/null @@ -1,54 +0,0 @@ - /* - - Copyright (C) 2000 Jeff Tranter - tranter@pobox.com - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include -#include -#include "artsmodulessynth.h" -#include "stdsynthmodule.h" - -using namespace Arts; - -// This can be used to get the input signal to the normalized range -// between -1 and 1 that Synth_PLAY can process. The louder the input -// signal, the more the signal is distorted by this module. For very -// small input signals, the output signal is about the input signal -// (no change). - -class Synth_ATAN_SATURATE_impl : virtual public Synth_ATAN_SATURATE_skel, - virtual public StdSynthModule -{ -protected: - float _inscale; - -public: - float inscale() { return _inscale; } - - void inscale(float newInscale) { _inscale = newInscale; } - - void calculateBlock(unsigned long samples) - { - for (unsigned long i=0; i +#include +#include "artsmodulessynth.h" +#include "stdsynthmodule.h" + +using namespace Arts; + +// This can be used to get the input signal to the normalized range +// between -1 and 1 that Synth_PLAY can process. The louder the input +// signal, the more the signal is distorted by this module. For very +// small input signals, the output signal is about the input signal +// (no change). + +class Synth_ATAN_SATURATE_impl : virtual public Synth_ATAN_SATURATE_skel, + virtual public StdSynthModule +{ +protected: + float _inscale; + +public: + float inscale() { return _inscale; } + + void inscale(float newInscale) { _inscale = newInscale; } + + void calculateBlock(unsigned long samples) + { + for (unsigned long i=0; i 1.0) - outvalue[i] = 1.0; - else if (invalue[i] < -1.0) - outvalue[i] = -1.0; - else - outvalue[i] = invalue[i]; - } - } -}; - -REGISTER_IMPLEMENTATION(Synth_BRICKWALL_LIMITER_impl); diff --git a/arts/modules/synth/synth_brickwall_limiter_impl.cpp b/arts/modules/synth/synth_brickwall_limiter_impl.cpp new file mode 100644 index 00000000..aea9d66e --- /dev/null +++ b/arts/modules/synth/synth_brickwall_limiter_impl.cpp @@ -0,0 +1,51 @@ +/* + + Copyright (C) 2000 Jeff Tranter + tranter@pobox.com + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "artsmodulessynth.h" +#include "stdsynthmodule.h" + +using namespace Arts; + +// A brickwall limiter is used to protect equipment (and your ears..) +// from peaks that exceed the dynamic range of your system. It doesn't +// sound good but it's better than digital distortion. + +class Synth_BRICKWALL_LIMITER_impl : virtual public Synth_BRICKWALL_LIMITER_skel, + virtual public StdSynthModule +{ +public: + void calculateBlock(unsigned long samples) + { + unsigned long i; + for(i=0; i 1.0) + outvalue[i] = 1.0; + else if (invalue[i] < -1.0) + outvalue[i] = -1.0; + else + outvalue[i] = invalue[i]; + } + } +}; + +REGISTER_IMPLEMENTATION(Synth_BRICKWALL_LIMITER_impl); diff --git a/arts/modules/synth/synth_capture_wav_impl.cc b/arts/modules/synth/synth_capture_wav_impl.cc deleted file mode 100644 index 84e91648..00000000 --- a/arts/modules/synth/synth_capture_wav_impl.cc +++ /dev/null @@ -1,169 +0,0 @@ - /* - - Copyright (C) 2000, 2001 Stefan Westerfeld - stefan@space.twc.de, Matthias Kretz - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - */ - -#include "artsmodulessynth.h" -#include "convert.h" -#include "mcoputils.h" -#include "stdsynthmodule.h" -#include "debug.h" -#include -#include -#include - -using namespace std; -namespace Arts { - -class Synth_CAPTURE_WAV_impl :virtual public Synth_CAPTURE_WAV_skel, - virtual public StdSynthModule -{ - bool audioinit, scaleerr, running; - int audiofd, byteorder, v,datalen,channels; - - unsigned char *outblock; - unsigned long maxsamples; - - string _filename; - -/**** - - WAV writing code and header taken from kwave. Many thanks go to - Martin Wilz who has written this ;) - - ****/ - - struct wavheader - { - char riffid[4]; - long filelength; - char wavid[4]; - char fmtid[4]; - long fmtlength; - short int mode; - short int channels; - long rate; - long AvgBytesPerSec; - short int BlockAlign; - short int bitspersample; - } header; - -public: - Synth_CAPTURE_WAV_impl(); - void streamInit(); - void calculateBlock(unsigned long samples); - void streamEnd(); - string filename() { return _filename; } - void filename( const string &newFilename ); -}; - -Synth_CAPTURE_WAV_impl::Synth_CAPTURE_WAV_impl() - : running(false), _filename( "capture" ) -{ -} - -void Synth_CAPTURE_WAV_impl::streamInit() -{ - /* - * we use createFilePath to prevent the usual symlink security issues - * in /tmp - add .wav manually as createFilePath substitutes . with _ - */ - string filename = MCOPUtils::createFilePath(_filename)+ ".wav"; - audiofd = open(filename.c_str(),O_WRONLY|O_CREAT|O_TRUNC,0644); - -/* write header */ - - int rate=44100; - int bit=16; - - channels = 2; /* hardcoded here - make it a parameter? */ - - arts_info("capturing output to %s", filename.c_str()); - datalen=0; - - strncpy (header.riffid,"RIFF",4); - strncpy (header.wavid,"WAVE",4); - strncpy (header.fmtid,"fmt ",4); - header.fmtlength=16; - header.filelength=sizeof(struct wavheader); - header.mode=1; - header.channels=channels; - header.rate=rate; - header.AvgBytesPerSec=rate*bit/8; - header.BlockAlign=channels*bit/8; - header.bitspersample=bit; - - write(audiofd,&header,sizeof (struct wavheader)); - write(audiofd,"data",4); - write(audiofd,&datalen,4); - - maxsamples = 0; - outblock = 0; - v = 0; - running = true; -} - -void Synth_CAPTURE_WAV_impl::calculateBlock(unsigned long samples) -{ - if(samples > maxsamples) - { - maxsamples = samples; - outblock = (unsigned char *)realloc(outblock, maxsamples * 4); - // 2 channels, 16 bit - } - - if(channels == 1) - convert_mono_float_16le(samples,left,outblock); - - if(channels == 2) - convert_stereo_2float_i16le(samples,left,right,outblock); - - write(audiofd,outblock,samples*channels*2); - datalen += samples*channels*2; -} - -void Synth_CAPTURE_WAV_impl::streamEnd() -{ -/* rewrite header which now contains the correct size of the file */ - lseek(audiofd,0,SEEK_SET); - header.filelength=sizeof(struct wavheader)+datalen; - write(audiofd,&header,sizeof (struct wavheader)); - write(audiofd,"data",4); - write(audiofd,&datalen,4); - - close(audiofd); - - running = false; -} -void Synth_CAPTURE_WAV_impl::filename( const string &newFilename ) -{ - if(_filename != newFilename) { - _filename = newFilename; - if(running) - { - streamEnd(); - streamInit(); - } - filename_changed(newFilename); - } -} - -REGISTER_IMPLEMENTATION(Synth_CAPTURE_WAV_impl); - -} diff --git a/arts/modules/synth/synth_capture_wav_impl.cpp b/arts/modules/synth/synth_capture_wav_impl.cpp new file mode 100644 index 00000000..84e91648 --- /dev/null +++ b/arts/modules/synth/synth_capture_wav_impl.cpp @@ -0,0 +1,169 @@ + /* + + Copyright (C) 2000, 2001 Stefan Westerfeld + stefan@space.twc.de, Matthias Kretz + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + */ + +#include "artsmodulessynth.h" +#include "convert.h" +#include "mcoputils.h" +#include "stdsynthmodule.h" +#include "debug.h" +#include +#include +#include + +using namespace std; +namespace Arts { + +class Synth_CAPTURE_WAV_impl :virtual public Synth_CAPTURE_WAV_skel, + virtual public StdSynthModule +{ + bool audioinit, scaleerr, running; + int audiofd, byteorder, v,datalen,channels; + + unsigned char *outblock; + unsigned long maxsamples; + + string _filename; + +/**** + + WAV writing code and header taken from kwave. Many thanks go to + Martin Wilz who has written this ;) + + ****/ + + struct wavheader + { + char riffid[4]; + long filelength; + char wavid[4]; + char fmtid[4]; + long fmtlength; + short int mode; + short int channels; + long rate; + long AvgBytesPerSec; + short int BlockAlign; + short int bitspersample; + } header; + +public: + Synth_CAPTURE_WAV_impl(); + void streamInit(); + void calculateBlock(unsigned long samples); + void streamEnd(); + string filename() { return _filename; } + void filename( const string &newFilename ); +}; + +Synth_CAPTURE_WAV_impl::Synth_CAPTURE_WAV_impl() + : running(false), _filename( "capture" ) +{ +} + +void Synth_CAPTURE_WAV_impl::streamInit() +{ + /* + * we use createFilePath to prevent the usual symlink security issues + * in /tmp - add .wav manually as createFilePath substitutes . with _ + */ + string filename = MCOPUtils::createFilePath(_filename)+ ".wav"; + audiofd = open(filename.c_str(),O_WRONLY|O_CREAT|O_TRUNC,0644); + +/* write header */ + + int rate=44100; + int bit=16; + + channels = 2; /* hardcoded here - make it a parameter? */ + + arts_info("capturing output to %s", filename.c_str()); + datalen=0; + + strncpy (header.riffid,"RIFF",4); + strncpy (header.wavid,"WAVE",4); + strncpy (header.fmtid,"fmt ",4); + header.fmtlength=16; + header.filelength=sizeof(struct wavheader); + header.mode=1; + header.channels=channels; + header.rate=rate; + header.AvgBytesPerSec=rate*bit/8; + header.BlockAlign=channels*bit/8; + header.bitspersample=bit; + + write(audiofd,&header,sizeof (struct wavheader)); + write(audiofd,"data",4); + write(audiofd,&datalen,4); + + maxsamples = 0; + outblock = 0; + v = 0; + running = true; +} + +void Synth_CAPTURE_WAV_impl::calculateBlock(unsigned long samples) +{ + if(samples > maxsamples) + { + maxsamples = samples; + outblock = (unsigned char *)realloc(outblock, maxsamples * 4); + // 2 channels, 16 bit + } + + if(channels == 1) + convert_mono_float_16le(samples,left,outblock); + + if(channels == 2) + convert_stereo_2float_i16le(samples,left,right,outblock); + + write(audiofd,outblock,samples*channels*2); + datalen += samples*channels*2; +} + +void Synth_CAPTURE_WAV_impl::streamEnd() +{ +/* rewrite header which now contains the correct size of the file */ + lseek(audiofd,0,SEEK_SET); + header.filelength=sizeof(struct wavheader)+datalen; + write(audiofd,&header,sizeof (struct wavheader)); + write(audiofd,"data",4); + write(audiofd,&datalen,4); + + close(audiofd); + + running = false; +} +void Synth_CAPTURE_WAV_impl::filename( const string &newFilename ) +{ + if(_filename != newFilename) { + _filename = newFilename; + if(running) + { + streamEnd(); + streamInit(); + } + filename_changed(newFilename); + } +} + +REGISTER_IMPLEMENTATION(Synth_CAPTURE_WAV_impl); + +} diff --git a/arts/modules/synth/synth_cdelay_impl.cc b/arts/modules/synth/synth_cdelay_impl.cc deleted file mode 100644 index 0ab3255d..00000000 --- a/arts/modules/synth/synth_cdelay_impl.cc +++ /dev/null @@ -1,122 +0,0 @@ -/* - - Copyright (C) 2000 Jeff Tranter - tranter@pobox.com - 2001 Matthias Kretz - kretz@kde.org - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "artsmodulessynth.h" -#include "stdsynthmodule.h" - -#include -#include - -using namespace Arts; - -// This delays the input signal for an amount of time. The time -// specification can be any number greater or equal zero. -// The delay is constant during the calculation, that means it -// can't be modified. This saves computing time as no interpolation is -// done, and is useful for recursive structures. Actually it can be -// modified, but without interpolation it won't sound too good. See -// the description for Synth_DELAY. - -class Synth_CDELAY_impl : virtual public Synth_CDELAY_skel, - virtual public StdSynthModule -{ -protected: - unsigned long _buffersize; - unsigned long _bitmask; - float *_buffer; // holds the data to be delayed (variable size) - float _delaytime; - unsigned int _readpos; - unsigned int _writepos; - -public: - Synth_CDELAY_impl() : _buffersize( 0 ), _bitmask( 0 ), _buffer( 0 ), _delaytime( 0 ), _readpos( 0 ), _writepos( 0 ) - { - } - - ~Synth_CDELAY_impl() - { - delete[] _buffer; - } - - float time() { return _delaytime; } - - void time(float newTime) - { - _delaytime = newTime; - double n = ceil( log( double(_delaytime * samplingRateFloat )) / log( 2. ) ); - unsigned long newbuffersize = (unsigned long)( pow( 2, n ) ); - unsigned long newbitmask = newbuffersize - 1; - if( newbuffersize != _buffersize ) - { - float *newbuffer = new float[newbuffersize]; - if( newbuffersize > _buffersize ) { - for( unsigned long i = 0; i < _buffersize; i++ ) { - newbuffer[i] = _buffer[_writepos]; - _writepos++; - _writepos &= newbitmask; - } - for( unsigned long i = _buffersize; i < newbuffersize; i++ ) - newbuffer[i] = 0; - } else { - _writepos -= newbuffersize; - _writepos &= newbitmask; - for( unsigned long i = 0; i < newbuffersize; i++ ) { - newbuffer[i] = _buffer[_writepos]; - _writepos++; - _writepos &= newbitmask; - } - } - _buffer = newbuffer; - _buffersize = newbuffersize; - _bitmask = newbitmask; - } - _readpos = (unsigned long)rint( _writepos - _delaytime * samplingRateFloat ) & _bitmask; - time_changed( _delaytime ); - } - - void streamInit() - { - // initialize buffer to all zeroes - if( _buffer ) - for( unsigned long i = 0; i < _buffersize; i++ ) - _buffer[i] = 0.0; - } - - void calculateBlock(unsigned long samples) - { - if( ! _buffer ) { - memcpy( outvalue, invalue, sizeof( float ) * samples ); - return; - } - for( unsigned long i = 0; i < samples; i++ ) { - _buffer[_writepos] = invalue[i]; - outvalue[i] = _buffer[_readpos]; - _readpos++; - _readpos &= _bitmask; - _writepos++; - _writepos &= _bitmask; - } - } -}; -REGISTER_IMPLEMENTATION(Synth_CDELAY_impl); diff --git a/arts/modules/synth/synth_cdelay_impl.cpp b/arts/modules/synth/synth_cdelay_impl.cpp new file mode 100644 index 00000000..0ab3255d --- /dev/null +++ b/arts/modules/synth/synth_cdelay_impl.cpp @@ -0,0 +1,122 @@ +/* + + Copyright (C) 2000 Jeff Tranter + tranter@pobox.com + 2001 Matthias Kretz + kretz@kde.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "artsmodulessynth.h" +#include "stdsynthmodule.h" + +#include +#include + +using namespace Arts; + +// This delays the input signal for an amount of time. The time +// specification can be any number greater or equal zero. +// The delay is constant during the calculation, that means it +// can't be modified. This saves computing time as no interpolation is +// done, and is useful for recursive structures. Actually it can be +// modified, but without interpolation it won't sound too good. See +// the description for Synth_DELAY. + +class Synth_CDELAY_impl : virtual public Synth_CDELAY_skel, + virtual public StdSynthModule +{ +protected: + unsigned long _buffersize; + unsigned long _bitmask; + float *_buffer; // holds the data to be delayed (variable size) + float _delaytime; + unsigned int _readpos; + unsigned int _writepos; + +public: + Synth_CDELAY_impl() : _buffersize( 0 ), _bitmask( 0 ), _buffer( 0 ), _delaytime( 0 ), _readpos( 0 ), _writepos( 0 ) + { + } + + ~Synth_CDELAY_impl() + { + delete[] _buffer; + } + + float time() { return _delaytime; } + + void time(float newTime) + { + _delaytime = newTime; + double n = ceil( log( double(_delaytime * samplingRateFloat )) / log( 2. ) ); + unsigned long newbuffersize = (unsigned long)( pow( 2, n ) ); + unsigned long newbitmask = newbuffersize - 1; + if( newbuffersize != _buffersize ) + { + float *newbuffer = new float[newbuffersize]; + if( newbuffersize > _buffersize ) { + for( unsigned long i = 0; i < _buffersize; i++ ) { + newbuffer[i] = _buffer[_writepos]; + _writepos++; + _writepos &= newbitmask; + } + for( unsigned long i = _buffersize; i < newbuffersize; i++ ) + newbuffer[i] = 0; + } else { + _writepos -= newbuffersize; + _writepos &= newbitmask; + for( unsigned long i = 0; i < newbuffersize; i++ ) { + newbuffer[i] = _buffer[_writepos]; + _writepos++; + _writepos &= newbitmask; + } + } + _buffer = newbuffer; + _buffersize = newbuffersize; + _bitmask = newbitmask; + } + _readpos = (unsigned long)rint( _writepos - _delaytime * samplingRateFloat ) & _bitmask; + time_changed( _delaytime ); + } + + void streamInit() + { + // initialize buffer to all zeroes + if( _buffer ) + for( unsigned long i = 0; i < _buffersize; i++ ) + _buffer[i] = 0.0; + } + + void calculateBlock(unsigned long samples) + { + if( ! _buffer ) { + memcpy( outvalue, invalue, sizeof( float ) * samples ); + return; + } + for( unsigned long i = 0; i < samples; i++ ) { + _buffer[_writepos] = invalue[i]; + outvalue[i] = _buffer[_readpos]; + _readpos++; + _readpos &= _bitmask; + _writepos++; + _writepos &= _bitmask; + } + } +}; +REGISTER_IMPLEMENTATION(Synth_CDELAY_impl); diff --git a/arts/modules/synth/synth_compressor_impl.cc b/arts/modules/synth/synth_compressor_impl.cc deleted file mode 100644 index b27b2be1..00000000 --- a/arts/modules/synth/synth_compressor_impl.cc +++ /dev/null @@ -1,139 +0,0 @@ -/* - - Copyright (C) 2001 Matthias Kretz - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - */ - -#include "artsmodulessynth.h" -#include "stdsynthmodule.h" -#include "debug.h" - -#include -#include - -#ifndef LN2 -# define LN2 0.69314718 -#endif - -#ifndef MAX -# define MAX(a,b) (((a) > (b) ? (a) : (b))) -#endif - -using namespace std; -namespace Arts { - -class Synth_COMPRESSOR_impl : virtual public Synth_COMPRESSOR_skel, - virtual public StdSynthModule -{ -protected: - float _attack, _release, _threshold, _ratiominus1, _output; - float _attackfactor, _releasefactor; - float _volume; - float _compfactor; - bool _autooutput; - -public: - float attack() { return _attack; } - float release() { return _release; } - float threshold() { return _threshold; } - float ratio() { return _ratiominus1 + 1.0; } - float output() { return _output; } - - Synth_COMPRESSOR_impl() - : _threshold( 1 ) - , _ratiominus1( -0.2 ) - , _output( 0 ) - , _autooutput( true ) - { - newCompFactor(); - attack( 10 ); - release( 10 ); - } - - void newCompFactor() - { - _compfactor = _output / pow( _threshold, _ratiominus1 ); - } - - void streamInit() - { - _volume = 0; - } - - void calculateBlock(unsigned long samples) - { - for( unsigned long i = 0; i < samples; i++ ) { - float delta = fabs( invalue[i] ) - _volume; - if( delta > 0.0 ) - _volume += _attackfactor * delta; - else - _volume += _releasefactor * delta; - - if( _volume > _threshold ) - // compress - // this is what it does: - // UtodB(x) = 20 * log( x ) - // dBtoU(x) = pow( 10, x / 20 ) - // outvalue[i] = dBtoU( ( UtodB( volume ) - UtodB( threshold ) ) * ratio + UtodB( threshold ) ) / volume * output * invalue[ i ]; - // showing that it's equal to the formula below - // is left as an exercise to the reader. - outvalue[i] = pow( _volume, _ratiominus1 ) * _compfactor * invalue[ i ]; - else - outvalue[i] = invalue[i] * _output; - } - } - - void attack( float newAttack ) - { // in ms - _attack = newAttack; - // _attackfactor has to be <= 1, that's why we need the MAX here - _attackfactor = LN2 / MAX( _attack / 1000 * samplingRateFloat, LN2 ); - attack_changed( newAttack ); - } - - void release( float newRelease ) - { // in ms - _release = newRelease; - // _releasefactor has to be <= 1, that's why we need the MAX here - _releasefactor = LN2 / MAX( _release / 1000 * samplingRateFloat, LN2 ); - release_changed( newRelease ); - } - - void threshold( float newThreshold ) - { // in V not in dB - _threshold = newThreshold; - newCompFactor(); - threshold_changed( newThreshold ); - } - - void ratio( float newRatio ) - { - _ratiominus1 = newRatio - 1; - newCompFactor(); - ratio_changed( newRatio ); - } - - void output( float newOutput ) - { // in V not in dB - _output = newOutput; - newCompFactor(); - output_changed( newOutput ); - } -}; - -REGISTER_IMPLEMENTATION(Synth_COMPRESSOR_impl); -} diff --git a/arts/modules/synth/synth_compressor_impl.cpp b/arts/modules/synth/synth_compressor_impl.cpp new file mode 100644 index 00000000..b27b2be1 --- /dev/null +++ b/arts/modules/synth/synth_compressor_impl.cpp @@ -0,0 +1,139 @@ +/* + + Copyright (C) 2001 Matthias Kretz + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + */ + +#include "artsmodulessynth.h" +#include "stdsynthmodule.h" +#include "debug.h" + +#include +#include + +#ifndef LN2 +# define LN2 0.69314718 +#endif + +#ifndef MAX +# define MAX(a,b) (((a) > (b) ? (a) : (b))) +#endif + +using namespace std; +namespace Arts { + +class Synth_COMPRESSOR_impl : virtual public Synth_COMPRESSOR_skel, + virtual public StdSynthModule +{ +protected: + float _attack, _release, _threshold, _ratiominus1, _output; + float _attackfactor, _releasefactor; + float _volume; + float _compfactor; + bool _autooutput; + +public: + float attack() { return _attack; } + float release() { return _release; } + float threshold() { return _threshold; } + float ratio() { return _ratiominus1 + 1.0; } + float output() { return _output; } + + Synth_COMPRESSOR_impl() + : _threshold( 1 ) + , _ratiominus1( -0.2 ) + , _output( 0 ) + , _autooutput( true ) + { + newCompFactor(); + attack( 10 ); + release( 10 ); + } + + void newCompFactor() + { + _compfactor = _output / pow( _threshold, _ratiominus1 ); + } + + void streamInit() + { + _volume = 0; + } + + void calculateBlock(unsigned long samples) + { + for( unsigned long i = 0; i < samples; i++ ) { + float delta = fabs( invalue[i] ) - _volume; + if( delta > 0.0 ) + _volume += _attackfactor * delta; + else + _volume += _releasefactor * delta; + + if( _volume > _threshold ) + // compress + // this is what it does: + // UtodB(x) = 20 * log( x ) + // dBtoU(x) = pow( 10, x / 20 ) + // outvalue[i] = dBtoU( ( UtodB( volume ) - UtodB( threshold ) ) * ratio + UtodB( threshold ) ) / volume * output * invalue[ i ]; + // showing that it's equal to the formula below + // is left as an exercise to the reader. + outvalue[i] = pow( _volume, _ratiominus1 ) * _compfactor * invalue[ i ]; + else + outvalue[i] = invalue[i] * _output; + } + } + + void attack( float newAttack ) + { // in ms + _attack = newAttack; + // _attackfactor has to be <= 1, that's why we need the MAX here + _attackfactor = LN2 / MAX( _attack / 1000 * samplingRateFloat, LN2 ); + attack_changed( newAttack ); + } + + void release( float newRelease ) + { // in ms + _release = newRelease; + // _releasefactor has to be <= 1, that's why we need the MAX here + _releasefactor = LN2 / MAX( _release / 1000 * samplingRateFloat, LN2 ); + release_changed( newRelease ); + } + + void threshold( float newThreshold ) + { // in V not in dB + _threshold = newThreshold; + newCompFactor(); + threshold_changed( newThreshold ); + } + + void ratio( float newRatio ) + { + _ratiominus1 = newRatio - 1; + newCompFactor(); + ratio_changed( newRatio ); + } + + void output( float newOutput ) + { // in V not in dB + _output = newOutput; + newCompFactor(); + output_changed( newOutput ); + } +}; + +REGISTER_IMPLEMENTATION(Synth_COMPRESSOR_impl); +} diff --git a/arts/modules/synth/synth_data_impl.cc b/arts/modules/synth/synth_data_impl.cc deleted file mode 100644 index 5b95d400..00000000 --- a/arts/modules/synth/synth_data_impl.cc +++ /dev/null @@ -1,50 +0,0 @@ - /* - - Copyright (C) 2000 Jeff Tranter - tranter@pobox.com - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include -#include "artsmodulessynth.h" -#include "stdsynthmodule.h" - -using namespace Arts; - -// This module outputs a constant stream of data corresponding to the -// value given as it's parameter. - -class Synth_DATA_impl : virtual public Synth_DATA_skel, - virtual public StdSynthModule -{ -protected: - float _value; - -public: - float value() { return _value; } - - void value(float newValue) { _value = newValue; } - - void calculateBlock(unsigned long samples) - { - for (unsigned long i=0; i +#include "artsmodulessynth.h" +#include "stdsynthmodule.h" + +using namespace Arts; + +// This module outputs a constant stream of data corresponding to the +// value given as it's parameter. + +class Synth_DATA_impl : virtual public Synth_DATA_skel, + virtual public StdSynthModule +{ +protected: + float _value; + +public: + float value() { return _value; } + + void value(float newValue) { _value = newValue; } + + void calculateBlock(unsigned long samples) + { + for (unsigned long i=0; i -#include "artsmodulessynth.h" -#include "stdsynthmodule.h" - -using namespace std; -using namespace Arts; - -// You can use this for debugging. It will print out the value of the -// signal at invalue in regular intervals (ca. 1 second), combined -// with the comment you have specified. That way you can find out if -// some signals stay in certain ranges, or if they are there at all. - -class Synth_DEBUG_impl : virtual public Synth_DEBUG_skel, - virtual public StdSynthModule -{ -protected: - string _comment; - int i; - -public: - string comment() { return _comment; } - - void comment(const string &newComment) { _comment = newComment; } - - void streamInit() { i = 0; } - - void calculateBlock(unsigned long samples) - { - for (unsigned long j=0; j +#include "artsmodulessynth.h" +#include "stdsynthmodule.h" + +using namespace std; +using namespace Arts; + +// You can use this for debugging. It will print out the value of the +// signal at invalue in regular intervals (ca. 1 second), combined +// with the comment you have specified. That way you can find out if +// some signals stay in certain ranges, or if they are there at all. + +class Synth_DEBUG_impl : virtual public Synth_DEBUG_skel, + virtual public StdSynthModule +{ +protected: + string _comment; + int i; + +public: + string comment() { return _comment; } + + void comment(const string &newComment) { _comment = newComment; } + + void streamInit() { i = 0; } + + void calculateBlock(unsigned long samples) + { + for (unsigned long j=0; j - -using namespace Arts; - -// This delays the input signal for an amount of time. The time -// specification must be between 0 and 1 for a delay between 0 seconds -// and 1 second. -// -// This kind of delay may not be used in feedback structures. This is -// because it's a variable delay. You can modify it's length while it -// is running, and even set it down to zero. But since in a feedback -// structure the own output is needed to calculate the next samples, a -// delay whose value could drop to zero during synthesis could lead to -// a stall situation. -// -// Use CDELAYs in that setup, perhaps combine a small constant delay -// (of 0.001 seconds) with a flexible delay. -// -// You can also combine a CDELAY and a DELAY to achieve a variable -// length delay with a minimum value in a feedback loop. Just make -// sure that you have a CDELAY involved. - -class Synth_DELAY_impl : virtual public Synth_DELAY_skel, - virtual public StdSynthModule -{ -protected: - unsigned long _buffersize; - unsigned long _bitmask; - float * _buffer; - float _maxdelay; - unsigned int _writepos; - -public: - Synth_DELAY_impl() : _buffersize( 0 ), _bitmask( 0 ), _buffer( 0 ), _maxdelay( 0 ), _writepos( 0 ) - { - maxdelay( 1 ); // take a one second buffer if nothing else is specified - } - - ~Synth_DELAY_impl() - { - delete[] _buffer; - } - - void streamInit() - { - // initialize buffer to all zeroes - for ( unsigned long i = 0; i < _buffersize; i++ ) - _buffer[i] = 0.0; - } - - void calculateBlock(unsigned long samples) - { - for( unsigned long i = 0; i _buffersize ) { - for( unsigned long i = 0; i < _buffersize; i++ ) { - newbuffer[i] = _buffer[_writepos]; - _writepos++; - _writepos &= newbitmask; - } - for( unsigned long i = _buffersize; i < newbuffersize; i++ ) - newbuffer[i] = 0; - } else { - _writepos -= newbuffersize; - _writepos &= newbitmask; - for( unsigned long i = 0; i < newbuffersize; i++ ) { - newbuffer[i] = _buffer[_writepos]; - _writepos++; - _writepos &= newbitmask; - } - } - _buffer = newbuffer; - _buffersize = newbuffersize; - _bitmask = newbitmask; - } - maxdelay_changed( _maxdelay ); - } -}; - -REGISTER_IMPLEMENTATION(Synth_DELAY_impl); diff --git a/arts/modules/synth/synth_delay_impl.cpp b/arts/modules/synth/synth_delay_impl.cpp new file mode 100644 index 00000000..92c23fd1 --- /dev/null +++ b/arts/modules/synth/synth_delay_impl.cpp @@ -0,0 +1,138 @@ +/* + + Copyright (C) 2000 Jeff Tranter + tranter@pobox.com + Stefan Westerfeld + stefan@space.twc.de + Jens Hahn + Jens.Hahn@t-online.de + 2001 Matthias Kretz + kretz@kde.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "artsmodulessynth.h" +#include "stdsynthmodule.h" + +#include + +using namespace Arts; + +// This delays the input signal for an amount of time. The time +// specification must be between 0 and 1 for a delay between 0 seconds +// and 1 second. +// +// This kind of delay may not be used in feedback structures. This is +// because it's a variable delay. You can modify it's length while it +// is running, and even set it down to zero. But since in a feedback +// structure the own output is needed to calculate the next samples, a +// delay whose value could drop to zero during synthesis could lead to +// a stall situation. +// +// Use CDELAYs in that setup, perhaps combine a small constant delay +// (of 0.001 seconds) with a flexible delay. +// +// You can also combine a CDELAY and a DELAY to achieve a variable +// length delay with a minimum value in a feedback loop. Just make +// sure that you have a CDELAY involved. + +class Synth_DELAY_impl : virtual public Synth_DELAY_skel, + virtual public StdSynthModule +{ +protected: + unsigned long _buffersize; + unsigned long _bitmask; + float * _buffer; + float _maxdelay; + unsigned int _writepos; + +public: + Synth_DELAY_impl() : _buffersize( 0 ), _bitmask( 0 ), _buffer( 0 ), _maxdelay( 0 ), _writepos( 0 ) + { + maxdelay( 1 ); // take a one second buffer if nothing else is specified + } + + ~Synth_DELAY_impl() + { + delete[] _buffer; + } + + void streamInit() + { + // initialize buffer to all zeroes + for ( unsigned long i = 0; i < _buffersize; i++ ) + _buffer[i] = 0.0; + } + + void calculateBlock(unsigned long samples) + { + for( unsigned long i = 0; i _buffersize ) { + for( unsigned long i = 0; i < _buffersize; i++ ) { + newbuffer[i] = _buffer[_writepos]; + _writepos++; + _writepos &= newbitmask; + } + for( unsigned long i = _buffersize; i < newbuffersize; i++ ) + newbuffer[i] = 0; + } else { + _writepos -= newbuffersize; + _writepos &= newbitmask; + for( unsigned long i = 0; i < newbuffersize; i++ ) { + newbuffer[i] = _buffer[_writepos]; + _writepos++; + _writepos &= newbitmask; + } + } + _buffer = newbuffer; + _buffersize = newbuffersize; + _bitmask = newbitmask; + } + maxdelay_changed( _maxdelay ); + } +}; + +REGISTER_IMPLEMENTATION(Synth_DELAY_impl); diff --git a/arts/modules/synth/synth_div_impl.cc b/arts/modules/synth/synth_div_impl.cc deleted file mode 100644 index 90c19996..00000000 --- a/arts/modules/synth/synth_div_impl.cc +++ /dev/null @@ -1,45 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld - stefan@space.twc.de - 2004 Matthias Kretz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "artsmodulessynth.h" -#include "stdsynthmodule.h" - -using namespace Arts; - -namespace Arts { - -class Synth_DIV_impl :public Synth_DIV_skel, public StdSynthModule -{ -public: - void calculateBlock(unsigned long samples) - { - unsigned long i; - - for(i = 0;i < samples; i++) - outvalue[i] = invalue1[i] / invalue2[i]; - } -}; - -REGISTER_IMPLEMENTATION(Synth_DIV_impl); - -} diff --git a/arts/modules/synth/synth_div_impl.cpp b/arts/modules/synth/synth_div_impl.cpp new file mode 100644 index 00000000..90c19996 --- /dev/null +++ b/arts/modules/synth/synth_div_impl.cpp @@ -0,0 +1,45 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + 2004 Matthias Kretz + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "artsmodulessynth.h" +#include "stdsynthmodule.h" + +using namespace Arts; + +namespace Arts { + +class Synth_DIV_impl :public Synth_DIV_skel, public StdSynthModule +{ +public: + void calculateBlock(unsigned long samples) + { + unsigned long i; + + for(i = 0;i < samples; i++) + outvalue[i] = invalue1[i] / invalue2[i]; + } +}; + +REGISTER_IMPLEMENTATION(Synth_DIV_impl); + +} diff --git a/arts/modules/synth/synth_envelope_adsr_impl.cc b/arts/modules/synth/synth_envelope_adsr_impl.cc deleted file mode 100644 index e6f47220..00000000 --- a/arts/modules/synth/synth_envelope_adsr_impl.cc +++ /dev/null @@ -1,121 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "artsmodulessynth.h" -#include "debug.h" -#include "stdsynthmodule.h" - -using namespace Arts; - -class Synth_ENVELOPE_ADSR_impl : virtual public Synth_ENVELOPE_ADSR_skel, - virtual public StdSynthModule -{ -protected: - enum { NOOUT, ATTACK, SUSTAIN, DECAY, RELEASE } currentphase; - float level,increment,decrement; -public: - void streamInit() - { - currentphase = NOOUT; - level = 0; - } - void calculateBlock(unsigned long samples); -}; - -void Synth_ENVELOPE_ADSR_impl::calculateBlock(unsigned long samples) -{ - /* FIXME: - * should be rewritten as generic envelope, would certainly - * be faster & more flexible - */ - unsigned long i; - - for(i=0;i= 1) - { - level = 1; - currentphase = DECAY; - decrement = (1-sustain[i]) / - (decay[i] * samplingRateFloat); - } - break; - case DECAY: - level -= decrement; - if (level <= sustain[i]) - { - level = sustain[i]; - currentphase = SUSTAIN; - } - break; - case SUSTAIN: - level = sustain[i]; - break; - } - } - outvalue[i] = invalue[i] * level; - } -} - -REGISTER_IMPLEMENTATION(Synth_ENVELOPE_ADSR_impl); diff --git a/arts/modules/synth/synth_envelope_adsr_impl.cpp b/arts/modules/synth/synth_envelope_adsr_impl.cpp new file mode 100644 index 00000000..e6f47220 --- /dev/null +++ b/arts/modules/synth/synth_envelope_adsr_impl.cpp @@ -0,0 +1,121 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "artsmodulessynth.h" +#include "debug.h" +#include "stdsynthmodule.h" + +using namespace Arts; + +class Synth_ENVELOPE_ADSR_impl : virtual public Synth_ENVELOPE_ADSR_skel, + virtual public StdSynthModule +{ +protected: + enum { NOOUT, ATTACK, SUSTAIN, DECAY, RELEASE } currentphase; + float level,increment,decrement; +public: + void streamInit() + { + currentphase = NOOUT; + level = 0; + } + void calculateBlock(unsigned long samples); +}; + +void Synth_ENVELOPE_ADSR_impl::calculateBlock(unsigned long samples) +{ + /* FIXME: + * should be rewritten as generic envelope, would certainly + * be faster & more flexible + */ + unsigned long i; + + for(i=0;i= 1) + { + level = 1; + currentphase = DECAY; + decrement = (1-sustain[i]) / + (decay[i] * samplingRateFloat); + } + break; + case DECAY: + level -= decrement; + if (level <= sustain[i]) + { + level = sustain[i]; + currentphase = SUSTAIN; + } + break; + case SUSTAIN: + level = sustain[i]; + break; + } + } + outvalue[i] = invalue[i] * level; + } +} + +REGISTER_IMPLEMENTATION(Synth_ENVELOPE_ADSR_impl); diff --git a/arts/modules/synth/synth_fm_source_impl.cc b/arts/modules/synth/synth_fm_source_impl.cc deleted file mode 100644 index 2c2bd0e8..00000000 --- a/arts/modules/synth/synth_fm_source_impl.cc +++ /dev/null @@ -1,61 +0,0 @@ - /* - - Copyright (C) 2000 Jeff Tranter - tranter@pobox.com - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "artsmodulessynth.h" -#include "stdsynthmodule.h" - -using namespace Arts; - -// This is used for frequency modulation. Put your frequency to the -// frequency input and put another signal on the modulator input. Then -// set modlevel to something, say 0.3. The frequency will be modulated -// with modulator then. Just try it. Works nice when you put a -// feedback in there, that means take a combination of the delayed -// output signal from the Synth_FM_SOURCE (you need to put it to some -// oscillator as it only takes the role of Synth_FREQUENCY) and some -// other signal to get good results. Works nicely in combination with -// Synth_WAVE_SIN oscillators. - -class Synth_FM_SOURCE_impl : virtual public Synth_FM_SOURCE_skel, - virtual public StdSynthModule -{ -protected: - static const int SAMPLINGRATE = 44100; - float posn; - -public: - void streamInit() { posn = 0; } - - void calculateBlock(unsigned long samples) - { - for (unsigned long i=0; i 1) - posn -= 1; - pos[i] = posn + modulator[i] * modlevel[i]; - } - } -}; - -REGISTER_IMPLEMENTATION(Synth_FM_SOURCE_impl); diff --git a/arts/modules/synth/synth_fm_source_impl.cpp b/arts/modules/synth/synth_fm_source_impl.cpp new file mode 100644 index 00000000..2c2bd0e8 --- /dev/null +++ b/arts/modules/synth/synth_fm_source_impl.cpp @@ -0,0 +1,61 @@ + /* + + Copyright (C) 2000 Jeff Tranter + tranter@pobox.com + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "artsmodulessynth.h" +#include "stdsynthmodule.h" + +using namespace Arts; + +// This is used for frequency modulation. Put your frequency to the +// frequency input and put another signal on the modulator input. Then +// set modlevel to something, say 0.3. The frequency will be modulated +// with modulator then. Just try it. Works nice when you put a +// feedback in there, that means take a combination of the delayed +// output signal from the Synth_FM_SOURCE (you need to put it to some +// oscillator as it only takes the role of Synth_FREQUENCY) and some +// other signal to get good results. Works nicely in combination with +// Synth_WAVE_SIN oscillators. + +class Synth_FM_SOURCE_impl : virtual public Synth_FM_SOURCE_skel, + virtual public StdSynthModule +{ +protected: + static const int SAMPLINGRATE = 44100; + float posn; + +public: + void streamInit() { posn = 0; } + + void calculateBlock(unsigned long samples) + { + for (unsigned long i=0; i 1) + posn -= 1; + pos[i] = posn + modulator[i] * modlevel[i]; + } + } +}; + +REGISTER_IMPLEMENTATION(Synth_FM_SOURCE_impl); diff --git a/arts/modules/synth/synth_fx_cflanger_impl.cc b/arts/modules/synth/synth_fx_cflanger_impl.cc deleted file mode 100644 index 3f67fd7a..00000000 --- a/arts/modules/synth/synth_fx_cflanger_impl.cc +++ /dev/null @@ -1,96 +0,0 @@ -/* - - Copyright (C) 2000 Jeff Tranter - tranter@pobox.com - Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include -#include "artsmodulessynth.h" -#include "stdsynthmodule.h" - -using namespace Arts; - -class Synth_FX_CFLANGER_impl : virtual public Synth_FX_CFLANGER_skel, - virtual public StdSynthModule -{ -protected: - float _mintime; - float _maxtime; - enum { SAMPLINGRATE = 44100, MAXDELAY = 44100 }; - float *dbuffer; - unsigned long dbpos; - float center; - float range; - -public: - Synth_FX_CFLANGER_impl() - { - dbuffer=new float[MAXDELAY]; - } - ~Synth_FX_CFLANGER_impl() - { - delete [] dbuffer; - } - - float mintime() { return _mintime; } - - void mintime(float newMintime) { _mintime = newMintime; } - - float maxtime() { return _maxtime; } - - void maxtime(float newMaxtime) { _maxtime = newMaxtime; } - - void streamInit() - { - center = (_maxtime + _mintime) / 2; - range = _maxtime - center; - for (int i=0; i +#include "artsmodulessynth.h" +#include "stdsynthmodule.h" + +using namespace Arts; + +class Synth_FX_CFLANGER_impl : virtual public Synth_FX_CFLANGER_skel, + virtual public StdSynthModule +{ +protected: + float _mintime; + float _maxtime; + enum { SAMPLINGRATE = 44100, MAXDELAY = 44100 }; + float *dbuffer; + unsigned long dbpos; + float center; + float range; + +public: + Synth_FX_CFLANGER_impl() + { + dbuffer=new float[MAXDELAY]; + } + ~Synth_FX_CFLANGER_impl() + { + delete [] dbuffer; + } + + float mintime() { return _mintime; } + + void mintime(float newMintime) { _mintime = newMintime; } + + float maxtime() { return _maxtime; } + + void maxtime(float newMaxtime) { _maxtime = newMaxtime; } + + void streamInit() + { + center = (_maxtime + _mintime) / 2; + range = _maxtime - center; + for (int i=0; i -#include "debug.h" -#include "artsmodulessynth.h" -#include "stdsynthmodule.h" - -using namespace Arts; - -class Synth_MIDI_DEBUG_impl : virtual public Synth_MIDI_DEBUG_skel, - virtual public StdSynthModule -{ - SystemMidiTimer timer; - MidiClient client; -public: - Synth_MIDI_DEBUG self() { return Synth_MIDI_DEBUG::_from_base(_copy()); } - - void streamInit() - { - printf("MIDI_DEBUG: streamInit\n"); - MidiManager manager = Reference("global:Arts_MidiManager"); - if(!manager.isNull()) - { - client = manager.addClient(mcdRecord,mctDestination,"midi debug", - "Arts::Synth_MIDI_DEBUG"); - client.addInputPort(self()); - } - else - arts_warning("Synth_MIDI_DEBUG: no midi manager found " - "- not registered"); - } - - void processEvent(const MidiEvent& event) - { - printf("MIDI_DEBUG: scheduling event at %ld.%ld\n", - event.time.sec, event.time.usec); - timer.queueEvent(self(),event); - } - void processCommand(const MidiCommand& command) - { - mcopbyte channel = command.status & mcsChannelMask; - switch(command.status & mcsCommandMask) - { - case mcsNoteOn: printf("MIDI_DEBUG: note on channel %d, " - "note %d, velocity %d\n", channel, - command.data1, command.data2); - break; - case mcsNoteOff: printf("MIDI_DEBUG: note off channel %d, " - "note %d, velocity %d\n", channel, - command.data1, command.data2); - break; - } - } - - TimeStamp time() - { - return timer.time(); - } - - TimeStamp playTime() - { - return timer.time(); - } -}; - -REGISTER_IMPLEMENTATION(Synth_MIDI_DEBUG_impl); diff --git a/arts/modules/synth/synth_midi_debug_impl.cpp b/arts/modules/synth/synth_midi_debug_impl.cpp new file mode 100644 index 00000000..2c4cf711 --- /dev/null +++ b/arts/modules/synth/synth_midi_debug_impl.cpp @@ -0,0 +1,88 @@ +/* + + Copyright (C) 2000 Jeff Tranter + tranter@pobox.com + + (C) 1998 Stefan Westerfeld + stefan@space.twc.de + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + */ + +#include +#include "debug.h" +#include "artsmodulessynth.h" +#include "stdsynthmodule.h" + +using namespace Arts; + +class Synth_MIDI_DEBUG_impl : virtual public Synth_MIDI_DEBUG_skel, + virtual public StdSynthModule +{ + SystemMidiTimer timer; + MidiClient client; +public: + Synth_MIDI_DEBUG self() { return Synth_MIDI_DEBUG::_from_base(_copy()); } + + void streamInit() + { + printf("MIDI_DEBUG: streamInit\n"); + MidiManager manager = Reference("global:Arts_MidiManager"); + if(!manager.isNull()) + { + client = manager.addClient(mcdRecord,mctDestination,"midi debug", + "Arts::Synth_MIDI_DEBUG"); + client.addInputPort(self()); + } + else + arts_warning("Synth_MIDI_DEBUG: no midi manager found " + "- not registered"); + } + + void processEvent(const MidiEvent& event) + { + printf("MIDI_DEBUG: scheduling event at %ld.%ld\n", + event.time.sec, event.time.usec); + timer.queueEvent(self(),event); + } + void processCommand(const MidiCommand& command) + { + mcopbyte channel = command.status & mcsChannelMask; + switch(command.status & mcsCommandMask) + { + case mcsNoteOn: printf("MIDI_DEBUG: note on channel %d, " + "note %d, velocity %d\n", channel, + command.data1, command.data2); + break; + case mcsNoteOff: printf("MIDI_DEBUG: note off channel %d, " + "note %d, velocity %d\n", channel, + command.data1, command.data2); + break; + } + } + + TimeStamp time() + { + return timer.time(); + } + + TimeStamp playTime() + { + return timer.time(); + } +}; + +REGISTER_IMPLEMENTATION(Synth_MIDI_DEBUG_impl); diff --git a/arts/modules/synth/synth_midi_test_impl.cc b/arts/modules/synth/synth_midi_test_impl.cc deleted file mode 100644 index 91714cac..00000000 --- a/arts/modules/synth/synth_midi_test_impl.cc +++ /dev/null @@ -1,692 +0,0 @@ -#include "artsmodulessynth.h" -#include "artsbuilder.h" -#include "stdsynthmodule.h" -#include "objectmanager.h" -#include "connect.h" -#include "flowsystem.h" -#include "debug.h" -#include "dynamicrequest.h" -#include "audiosubsys.h" -#include -#include -#include - -using namespace Arts; -using namespace std; - -/*-------- instrument mapping ---------*/ - -class InstrumentMap { -protected: - struct InstrumentData; - class Tokenizer; - list instruments; - string directory; - void loadLine(const string& line); - -public: - struct InstrumentParam; - - void loadFromList(const string& filename, const vector& list); - StructureDesc getInstrument(mcopbyte channel, mcopbyte note, - mcopbyte velocity, mcopbyte program, - vector*& params); -}; - -struct InstrumentMap::InstrumentParam -{ - string param; - Any value; - - InstrumentParam() - { - } - - InstrumentParam(const InstrumentParam& src) - : param(src.param), value(src.value) - { - } - - InstrumentParam(const string& param, const string& strValue) - : param(param) - { - /* put the string into the any */ - value.type = "string"; - - Buffer b; - b.writeString(strValue); - b.read(value.value, b.size()); - } -}; - -struct InstrumentMap::InstrumentData -{ - struct Range - { - int minValue, maxValue; - Range() : minValue(0), maxValue(0) - { - } - Range(int minValue, int maxValue) - : minValue(minValue), maxValue(maxValue) - { - } - bool match(int value) - { - return (value >= minValue) && (value <= maxValue); - } - }; - Range channel, pitch, program, velocity; - vector params; - StructureDesc instrument; -}; - -class InstrumentMap::Tokenizer { -protected: - bool haveToken, haveNextToken; - string token, nextToken, input; - string::iterator ii; -public: - Tokenizer(const string& line) - : haveToken(false), haveNextToken(false), - input(line+"\n"), ii(input.begin()) - { - /* adding a \n ensures that we will definitely find the last token */ - } - string getToken() - { - if(!haveMore()) - return ""; - - if(haveNextToken) - { - string t = token; - haveNextToken = false; - token = nextToken; - return t; - } - else - { - haveToken = false; - return token; - } - } - bool haveMore() - { - if(haveToken) - return true; - - token = ""; - while(ii != input.end() && !haveToken) - { - const char& c = *ii++; - - if(c == ' ' || c == '\t' || c == '\n') - { - if(!token.empty()) haveToken = true; - } - else if(c == '=') /* || c == '-' || c == '+')*/ - { - if(!token.empty()) - { - haveNextToken = true; - nextToken = c; - } - else - { - token = c; - } - haveToken = true; - } - else - { - token += c; - } - } - return haveToken; - } -}; - -void InstrumentMap::loadLine(const string& line) -{ - Tokenizer t(line); - InstrumentData id; - /* default: no filtering */ - id.channel = InstrumentData::Range(0,15); - id.pitch = id.program = id.velocity = InstrumentData::Range(0,127); - - string s[3]; - int i = 0; - bool seenDo = false; - bool loadOk = false; - - if(t.getToken() != "ON") - { - arts_warning("error in arts-map: lines must start with ON (did start with %s)\n", t.getToken().c_str()); - return; - } - - while(t.haveMore()) - { - const string& token = t.getToken(); - - if(token == "DO") - seenDo = true; - else - { - s[i] = token; - if(i == 2) /* evaluate */ - { - if(s[1] != "=") - { - arts_warning("error in arts-map: no = operator\n"); - return; - } - - if(seenDo) - { - if(s[0] == "structure") - { - string filename = s[2]; - - /* if it's no absolute path, its relative to the map */ - if(!filename.empty() && filename[0] != '/') - filename = directory + "/" + s[2]; - - ifstream infile(filename.c_str()); - string line; - vector strseq; - - while(getline(infile,line)) - strseq.push_back(line); - - id.instrument.loadFromList(strseq); - if(id.instrument.name() != "unknown") - { - loadOk = true; - } - else - { - arts_warning("mapped instrument: " - "can't load structure %s",s[2].c_str()); - } - } - else - { - /* TODO: handle different datatypes */ - id.params.push_back(InstrumentParam(s[0], s[2])); - } - } - else - { - InstrumentData::Range range; - range.minValue = atoi(s[2].c_str()); - range.maxValue = range.minValue; - int i = s[2].find("-",0); - if(i != 0) - { - range.minValue = atoi(s[2].substr(0,i).c_str()); - range.maxValue = - atoi(s[2].substr(i+1,s[2].size()-(i+1)).c_str()); - } - if(s[0] == "pitch") id.pitch = range; - if(s[0] == "channel") id.channel = range; - if(s[0] == "program") id.program = range; - if(s[0] == "velocity") id.velocity = range; - } - i = 0; - } - else i++; - } - } - if(loadOk) instruments.push_back(id); -} - -void InstrumentMap::loadFromList(const string& filename, - const vector& list) -{ - int r = filename.rfind('/'); - if(r > 0) - directory = filename.substr(0,r); - else - directory = ""; - - vector::const_iterator i; - instruments.clear(); - for(i = list.begin(); i != list.end(); i++) loadLine(*i); -} - -StructureDesc InstrumentMap::getInstrument(mcopbyte channel, mcopbyte note, - mcopbyte velocity, mcopbyte program, - vector*& params) -{ - list::iterator i; - for(i = instruments.begin(); i != instruments.end(); i++) - { - InstrumentData &id = *i; - - if(id.channel.match(channel) && id.pitch.match(note) && - id.velocity.match(velocity) && id.program.match(program)) - { - params = &id.params; - return id.instrument; - } - } - - return StructureDesc::null(); -} - - -/*-------instrument mapping end -------*/ - -static SynthModule get_AMAN_PLAY(Object structure) -{ - Object resultObj = structure._getChild("play"); - assert(!resultObj.isNull()); - - SynthModule result = DynamicCast(resultObj); - assert(!result.isNull()); - - return result; -} - -struct TSNote { - MidiPort port; - MidiEvent event; - TSNote(MidiPort port, const MidiEvent& event) : - port(port), event(event) - { - } -}; - -class AutoMidiRelease : public TimeNotify { -public: - vector impls; - AutoMidiRelease() - { - Dispatcher::the()->ioManager()->addTimer(10, this); - } - virtual ~AutoMidiRelease() - { - Dispatcher::the()->ioManager()->removeTimer(this); - } - void notifyTime() - { - vector::iterator i = impls.begin(); - while(i != impls.end()) - { - if(i->terminate()) - { - MidiReleaseHelper& helper = *i; - - arts_debug("one voice terminated"); - // put the MidiReleaseHelper and the voice into the ObjectCache - // (instead of simply freeing it) - ObjectCache cache = helper.cache(); - SynthModule voice = helper.voice(); - get_AMAN_PLAY(voice).stop(); - voice.stop(); - cache.put(voice,helper.name()); - impls.erase(i); - return; - } else i++; - } - } -} *autoMidiRelease; - -// cache startup & shutdown -static class AutoMidiReleaseStart :public StartupClass -{ -public: - void startup() { autoMidiRelease = new AutoMidiRelease(); } - void shutdown() { delete autoMidiRelease; } -} autoMidiReleaseStart; - -class MidiReleaseHelper_impl : virtual public MidiReleaseHelper_skel, - virtual public StdSynthModule -{ -protected: - bool _terminate; - SynthModule _voice; - ObjectCache _cache; - string _name; - -public: - MidiReleaseHelper_impl() - { - autoMidiRelease->impls.push_back(MidiReleaseHelper::_from_base(_copy())); - } - ~MidiReleaseHelper_impl() { - artsdebug("MidiReleaseHelper: one voice is gone now\n"); - } - - - SynthModule voice() { return _voice; } - void voice(SynthModule voice) { _voice = voice; } - - ObjectCache cache() { return _cache; } - void cache(ObjectCache cache) { _cache = cache; } - - string name() { return _name; } - void name(const string& name) { _name = name; } - - bool terminate() { return _terminate; } - void streamStart() { _terminate = false; } - - void calculateBlock(unsigned long /*samples*/) - { - if(done[0] > 0.5) - _terminate = true; - } -}; -REGISTER_IMPLEMENTATION(MidiReleaseHelper_impl); - -class Synth_MIDI_TEST_impl : virtual public Synth_MIDI_TEST_skel, - virtual public StdSynthModule { -protected: - struct ChannelData { - SynthModule voice[128]; - string name[128]; - float pitchShiftValue; - mcopbyte program; - ChannelData() { - // initialize all voices with NULL objects (no lazy create) - for(int i = 0; i < 128; i++) voice[i] = SynthModule::null(); - - pitchShiftValue = 0.0; - program = 0; - } - } *channelData; /* data for all 16 midi channels */ - - bool useMap; - InstrumentMap map; - StructureDesc instrument; - StructureBuilder builder; - AudioManagerClient amClient; - ObjectCache cache; - MidiClient client; - MidiTimer timer; - - string _filename; - string _busname; - string _title; -public: - Synth_MIDI_TEST self() { return Synth_MIDI_TEST::_from_base(_copy()); } - - Synth_MIDI_TEST_impl(); - ~Synth_MIDI_TEST_impl(); - - void filename(const string& newname); - string filename() - { - return _filename; - } - void busname(const string& newname); - string busname() - { - return _busname; - } - string title() - { - return _title; - } - void noteOn(mcopbyte channel, mcopbyte note, mcopbyte velocity); - void noteOff(mcopbyte channel, mcopbyte note); - void pitchWheel(mcopbyte channel, mcopbyte lsb, mcopbyte msb); - - float getFrequency(mcopbyte note,mcopbyte channel); - - void streamStart(); - void streamEnd(); - - TimeStamp time() - { - return timer.time(); - } - TimeStamp playTime() - { - /* - * what the user currently hears is exactly latencySec before our - * port timeStamp (as this is the size of the audio buffer) - */ - double latencySec = AudioSubSystem::the()->outputDelay(); - TimeStamp t = time(); - - int sec = int(latencySec); - t.sec -= sec; - latencySec -= double(sec); - t.usec -= int(latencySec * 1000000.0); - - if (t.usec < 0) - { - t.usec += 1000000; - t.sec -= 1; - } - - arts_assert(t.usec >= 0 && t.usec < 1000000); - return t; - } - void processEvent(const MidiEvent& event) - { - timer.queueEvent(self(),event); - } - void processCommand(const MidiCommand& command) - { - mcopbyte channel = command.status & mcsChannelMask; - - switch(command.status & mcsCommandMask) - { - case mcsNoteOn: noteOn(channel,command.data1,command.data2); - return; - case mcsNoteOff: noteOff(channel,command.data1); - return; - case mcsPitchWheel: pitchWheel(channel,command.data1,command.data2); - return; - case mcsProgram: channelData[channel].program = command.data1; - return; - case mcsParameter: - if(command.data1 == mcpAllNotesOff && command.data2 == 0) - for(mcopbyte note=0; note<128; note++) - noteOff(channel,note); - return; - } - } -}; -REGISTER_IMPLEMENTATION(Synth_MIDI_TEST_impl); - - -void Synth_MIDI_TEST_impl::busname(const string& newname) -{ - // TODO: - _busname = newname; -} - -void Synth_MIDI_TEST_impl::filename(const string& newname) -{ - ifstream infile(newname.c_str()); - string line; - vector strseq; - - while(getline(infile,line)) - strseq.push_back(line); - - _filename = newname; - -/* search extension */ - string::const_reverse_iterator i; - string extension; - bool extensionok = false; - - for(i = newname.rbegin(); i != newname.rend() && !extensionok; i++) - { - if(*i == '.') - extensionok = true; - else - extension.insert(extension.begin(), (char)tolower(*i)); - } - - if(extensionok && extension == "arts") - { - instrument.loadFromList(strseq); - _title = "aRts Instrument ("+instrument.name()+")"; - useMap = false; - } - else if(extensionok && extension == "arts-map") - { - map.loadFromList(newname, strseq); - _title = "aRts Instrument (mapped)"; - useMap = true; - } - - if(!client.isNull()) - client.title(title()); - amClient.title(title()); -} - -Synth_MIDI_TEST_impl::Synth_MIDI_TEST_impl() - : amClient(amPlay, "aRts Instrument","Synth_MIDI_TEST") -{ - useMap = false; - client = MidiClient::null(); - timer = SubClass("Arts::AudioMidiTimer"); - channelData = new ChannelData[16]; -} - -Synth_MIDI_TEST_impl::~Synth_MIDI_TEST_impl() -{ - delete[] channelData; -} - -void Synth_MIDI_TEST_impl::streamStart() -{ - // register with the midi manager - MidiManager manager = Reference("global:Arts_MidiManager"); - if(!manager.isNull()) - { - client = manager.addClient(mcdRecord,mctDestination,title(), - "Arts::Synth_MIDI_TEST"); - client.addInputPort(self()); - } - else - arts_warning("Synth_MIDI_TEST: no midi manager found - not registered"); -} - -void Synth_MIDI_TEST_impl::streamEnd() -{ - client = MidiClient::null(); -} - -void Synth_MIDI_TEST_impl::noteOn(mcopbyte channel, mcopbyte note, - mcopbyte velocity) -{ - if(velocity == 0) - { - noteOff(channel,note); - return; - } - if(!channelData[channel].voice[note].isNull()) - { - noteOff(channel,note); - arts_info("Synth_MIDI_TEST: duplicate noteOn (mixed channels?)"); - } - - vector *params = 0; - if(useMap) - { - mcopbyte program = channelData[channel].program; - StructureDesc sd = map.getInstrument(channel,note,velocity,program,params); - if(sd.isNull()) return; - instrument = sd; - } - - Object structureObject = cache.get(instrument.name()); - if(structureObject.isNull()) - { - arts_debug("creating new structure"); - structureObject = builder.createObject(instrument); - - SynthModule play; - // TODO: allow changing busname! - if(!_busname.empty()) - { - Synth_BUS_UPLINK b; - b.busname(_busname); - play = b; - } - else - { - Synth_AMAN_PLAY a(amClient); - play = a; - } - structureObject._addChild(play,"play"); - connect(structureObject,"left",play,"left"); - connect(structureObject,"right",play,"right"); - } - else - { - arts_debug("used cached structure"); - } - - SynthModule structure = DynamicCast(structureObject); - assert(!structure.isNull()); - - if(params) - { - vector::iterator pi; - for(pi = params->begin(); pi != params->end(); pi++) - { - DynamicRequest req(structure); - - req.method("_set_"+pi->param).param(pi->value).invoke(); - } - } - setValue(structure,"frequency",getFrequency(note,channel)); - setValue(structure,"velocity",(float)velocity/127.0); - setValue(structure,"pressed",1.0); - - get_AMAN_PLAY(structure).start(); - structure.start(); - - channelData[channel].voice[note] = structure; - channelData[channel].name[note] = instrument.name(); -} - -void Synth_MIDI_TEST_impl::noteOff(mcopbyte channel, mcopbyte note) -{ - if(!channelData[channel].voice[note].isNull()) - { - setValue(channelData[channel].voice[note],"pressed",0.0); - - MidiReleaseHelper h; - - h.voice(channelData[channel].voice[note]); - h.cache(cache); - h.name(channelData[channel].name[note]); - - connect(channelData[channel].voice[note],"done",h,"done"); - h.start(); - assert(!h.terminate()); - channelData[channel].voice[note] = SynthModule::null(); - } -} - -float Synth_MIDI_TEST_impl::getFrequency(mcopbyte note, mcopbyte channel) -{ - /* 2 semitones pitchshift */ - return 261.63 * pow(2,((float)(note)+(channelData[channel].pitchShiftValue*2.0))/12.0)/32.0; -} - -void Synth_MIDI_TEST_impl::pitchWheel(mcopbyte channel, - mcopbyte lsb, mcopbyte msb) -{ - mcopbyte note; - - channelData[channel].pitchShiftValue = - (float)((lsb + msb*128) - (0x40*128))/8192.0; - - for(note = 0; note < 128; note++) - { - if(!channelData[channel].voice[note].isNull()) - setValue(channelData[channel].voice[note],"frequency",getFrequency(note,channel)); - } -} diff --git a/arts/modules/synth/synth_midi_test_impl.cpp b/arts/modules/synth/synth_midi_test_impl.cpp new file mode 100644 index 00000000..91714cac --- /dev/null +++ b/arts/modules/synth/synth_midi_test_impl.cpp @@ -0,0 +1,692 @@ +#include "artsmodulessynth.h" +#include "artsbuilder.h" +#include "stdsynthmodule.h" +#include "objectmanager.h" +#include "connect.h" +#include "flowsystem.h" +#include "debug.h" +#include "dynamicrequest.h" +#include "audiosubsys.h" +#include +#include +#include + +using namespace Arts; +using namespace std; + +/*-------- instrument mapping ---------*/ + +class InstrumentMap { +protected: + struct InstrumentData; + class Tokenizer; + list instruments; + string directory; + void loadLine(const string& line); + +public: + struct InstrumentParam; + + void loadFromList(const string& filename, const vector& list); + StructureDesc getInstrument(mcopbyte channel, mcopbyte note, + mcopbyte velocity, mcopbyte program, + vector*& params); +}; + +struct InstrumentMap::InstrumentParam +{ + string param; + Any value; + + InstrumentParam() + { + } + + InstrumentParam(const InstrumentParam& src) + : param(src.param), value(src.value) + { + } + + InstrumentParam(const string& param, const string& strValue) + : param(param) + { + /* put the string into the any */ + value.type = "string"; + + Buffer b; + b.writeString(strValue); + b.read(value.value, b.size()); + } +}; + +struct InstrumentMap::InstrumentData +{ + struct Range + { + int minValue, maxValue; + Range() : minValue(0), maxValue(0) + { + } + Range(int minValue, int maxValue) + : minValue(minValue), maxValue(maxValue) + { + } + bool match(int value) + { + return (value >= minValue) && (value <= maxValue); + } + }; + Range channel, pitch, program, velocity; + vector params; + StructureDesc instrument; +}; + +class InstrumentMap::Tokenizer { +protected: + bool haveToken, haveNextToken; + string token, nextToken, input; + string::iterator ii; +public: + Tokenizer(const string& line) + : haveToken(false), haveNextToken(false), + input(line+"\n"), ii(input.begin()) + { + /* adding a \n ensures that we will definitely find the last token */ + } + string getToken() + { + if(!haveMore()) + return ""; + + if(haveNextToken) + { + string t = token; + haveNextToken = false; + token = nextToken; + return t; + } + else + { + haveToken = false; + return token; + } + } + bool haveMore() + { + if(haveToken) + return true; + + token = ""; + while(ii != input.end() && !haveToken) + { + const char& c = *ii++; + + if(c == ' ' || c == '\t' || c == '\n') + { + if(!token.empty()) haveToken = true; + } + else if(c == '=') /* || c == '-' || c == '+')*/ + { + if(!token.empty()) + { + haveNextToken = true; + nextToken = c; + } + else + { + token = c; + } + haveToken = true; + } + else + { + token += c; + } + } + return haveToken; + } +}; + +void InstrumentMap::loadLine(const string& line) +{ + Tokenizer t(line); + InstrumentData id; + /* default: no filtering */ + id.channel = InstrumentData::Range(0,15); + id.pitch = id.program = id.velocity = InstrumentData::Range(0,127); + + string s[3]; + int i = 0; + bool seenDo = false; + bool loadOk = false; + + if(t.getToken() != "ON") + { + arts_warning("error in arts-map: lines must start with ON (did start with %s)\n", t.getToken().c_str()); + return; + } + + while(t.haveMore()) + { + const string& token = t.getToken(); + + if(token == "DO") + seenDo = true; + else + { + s[i] = token; + if(i == 2) /* evaluate */ + { + if(s[1] != "=") + { + arts_warning("error in arts-map: no = operator\n"); + return; + } + + if(seenDo) + { + if(s[0] == "structure") + { + string filename = s[2]; + + /* if it's no absolute path, its relative to the map */ + if(!filename.empty() && filename[0] != '/') + filename = directory + "/" + s[2]; + + ifstream infile(filename.c_str()); + string line; + vector strseq; + + while(getline(infile,line)) + strseq.push_back(line); + + id.instrument.loadFromList(strseq); + if(id.instrument.name() != "unknown") + { + loadOk = true; + } + else + { + arts_warning("mapped instrument: " + "can't load structure %s",s[2].c_str()); + } + } + else + { + /* TODO: handle different datatypes */ + id.params.push_back(InstrumentParam(s[0], s[2])); + } + } + else + { + InstrumentData::Range range; + range.minValue = atoi(s[2].c_str()); + range.maxValue = range.minValue; + int i = s[2].find("-",0); + if(i != 0) + { + range.minValue = atoi(s[2].substr(0,i).c_str()); + range.maxValue = + atoi(s[2].substr(i+1,s[2].size()-(i+1)).c_str()); + } + if(s[0] == "pitch") id.pitch = range; + if(s[0] == "channel") id.channel = range; + if(s[0] == "program") id.program = range; + if(s[0] == "velocity") id.velocity = range; + } + i = 0; + } + else i++; + } + } + if(loadOk) instruments.push_back(id); +} + +void InstrumentMap::loadFromList(const string& filename, + const vector& list) +{ + int r = filename.rfind('/'); + if(r > 0) + directory = filename.substr(0,r); + else + directory = ""; + + vector::const_iterator i; + instruments.clear(); + for(i = list.begin(); i != list.end(); i++) loadLine(*i); +} + +StructureDesc InstrumentMap::getInstrument(mcopbyte channel, mcopbyte note, + mcopbyte velocity, mcopbyte program, + vector*& params) +{ + list::iterator i; + for(i = instruments.begin(); i != instruments.end(); i++) + { + InstrumentData &id = *i; + + if(id.channel.match(channel) && id.pitch.match(note) && + id.velocity.match(velocity) && id.program.match(program)) + { + params = &id.params; + return id.instrument; + } + } + + return StructureDesc::null(); +} + + +/*-------instrument mapping end -------*/ + +static SynthModule get_AMAN_PLAY(Object structure) +{ + Object resultObj = structure._getChild("play"); + assert(!resultObj.isNull()); + + SynthModule result = DynamicCast(resultObj); + assert(!result.isNull()); + + return result; +} + +struct TSNote { + MidiPort port; + MidiEvent event; + TSNote(MidiPort port, const MidiEvent& event) : + port(port), event(event) + { + } +}; + +class AutoMidiRelease : public TimeNotify { +public: + vector impls; + AutoMidiRelease() + { + Dispatcher::the()->ioManager()->addTimer(10, this); + } + virtual ~AutoMidiRelease() + { + Dispatcher::the()->ioManager()->removeTimer(this); + } + void notifyTime() + { + vector::iterator i = impls.begin(); + while(i != impls.end()) + { + if(i->terminate()) + { + MidiReleaseHelper& helper = *i; + + arts_debug("one voice terminated"); + // put the MidiReleaseHelper and the voice into the ObjectCache + // (instead of simply freeing it) + ObjectCache cache = helper.cache(); + SynthModule voice = helper.voice(); + get_AMAN_PLAY(voice).stop(); + voice.stop(); + cache.put(voice,helper.name()); + impls.erase(i); + return; + } else i++; + } + } +} *autoMidiRelease; + +// cache startup & shutdown +static class AutoMidiReleaseStart :public StartupClass +{ +public: + void startup() { autoMidiRelease = new AutoMidiRelease(); } + void shutdown() { delete autoMidiRelease; } +} autoMidiReleaseStart; + +class MidiReleaseHelper_impl : virtual public MidiReleaseHelper_skel, + virtual public StdSynthModule +{ +protected: + bool _terminate; + SynthModule _voice; + ObjectCache _cache; + string _name; + +public: + MidiReleaseHelper_impl() + { + autoMidiRelease->impls.push_back(MidiReleaseHelper::_from_base(_copy())); + } + ~MidiReleaseHelper_impl() { + artsdebug("MidiReleaseHelper: one voice is gone now\n"); + } + + + SynthModule voice() { return _voice; } + void voice(SynthModule voice) { _voice = voice; } + + ObjectCache cache() { return _cache; } + void cache(ObjectCache cache) { _cache = cache; } + + string name() { return _name; } + void name(const string& name) { _name = name; } + + bool terminate() { return _terminate; } + void streamStart() { _terminate = false; } + + void calculateBlock(unsigned long /*samples*/) + { + if(done[0] > 0.5) + _terminate = true; + } +}; +REGISTER_IMPLEMENTATION(MidiReleaseHelper_impl); + +class Synth_MIDI_TEST_impl : virtual public Synth_MIDI_TEST_skel, + virtual public StdSynthModule { +protected: + struct ChannelData { + SynthModule voice[128]; + string name[128]; + float pitchShiftValue; + mcopbyte program; + ChannelData() { + // initialize all voices with NULL objects (no lazy create) + for(int i = 0; i < 128; i++) voice[i] = SynthModule::null(); + + pitchShiftValue = 0.0; + program = 0; + } + } *channelData; /* data for all 16 midi channels */ + + bool useMap; + InstrumentMap map; + StructureDesc instrument; + StructureBuilder builder; + AudioManagerClient amClient; + ObjectCache cache; + MidiClient client; + MidiTimer timer; + + string _filename; + string _busname; + string _title; +public: + Synth_MIDI_TEST self() { return Synth_MIDI_TEST::_from_base(_copy()); } + + Synth_MIDI_TEST_impl(); + ~Synth_MIDI_TEST_impl(); + + void filename(const string& newname); + string filename() + { + return _filename; + } + void busname(const string& newname); + string busname() + { + return _busname; + } + string title() + { + return _title; + } + void noteOn(mcopbyte channel, mcopbyte note, mcopbyte velocity); + void noteOff(mcopbyte channel, mcopbyte note); + void pitchWheel(mcopbyte channel, mcopbyte lsb, mcopbyte msb); + + float getFrequency(mcopbyte note,mcopbyte channel); + + void streamStart(); + void streamEnd(); + + TimeStamp time() + { + return timer.time(); + } + TimeStamp playTime() + { + /* + * what the user currently hears is exactly latencySec before our + * port timeStamp (as this is the size of the audio buffer) + */ + double latencySec = AudioSubSystem::the()->outputDelay(); + TimeStamp t = time(); + + int sec = int(latencySec); + t.sec -= sec; + latencySec -= double(sec); + t.usec -= int(latencySec * 1000000.0); + + if (t.usec < 0) + { + t.usec += 1000000; + t.sec -= 1; + } + + arts_assert(t.usec >= 0 && t.usec < 1000000); + return t; + } + void processEvent(const MidiEvent& event) + { + timer.queueEvent(self(),event); + } + void processCommand(const MidiCommand& command) + { + mcopbyte channel = command.status & mcsChannelMask; + + switch(command.status & mcsCommandMask) + { + case mcsNoteOn: noteOn(channel,command.data1,command.data2); + return; + case mcsNoteOff: noteOff(channel,command.data1); + return; + case mcsPitchWheel: pitchWheel(channel,command.data1,command.data2); + return; + case mcsProgram: channelData[channel].program = command.data1; + return; + case mcsParameter: + if(command.data1 == mcpAllNotesOff && command.data2 == 0) + for(mcopbyte note=0; note<128; note++) + noteOff(channel,note); + return; + } + } +}; +REGISTER_IMPLEMENTATION(Synth_MIDI_TEST_impl); + + +void Synth_MIDI_TEST_impl::busname(const string& newname) +{ + // TODO: + _busname = newname; +} + +void Synth_MIDI_TEST_impl::filename(const string& newname) +{ + ifstream infile(newname.c_str()); + string line; + vector strseq; + + while(getline(infile,line)) + strseq.push_back(line); + + _filename = newname; + +/* search extension */ + string::const_reverse_iterator i; + string extension; + bool extensionok = false; + + for(i = newname.rbegin(); i != newname.rend() && !extensionok; i++) + { + if(*i == '.') + extensionok = true; + else + extension.insert(extension.begin(), (char)tolower(*i)); + } + + if(extensionok && extension == "arts") + { + instrument.loadFromList(strseq); + _title = "aRts Instrument ("+instrument.name()+")"; + useMap = false; + } + else if(extensionok && extension == "arts-map") + { + map.loadFromList(newname, strseq); + _title = "aRts Instrument (mapped)"; + useMap = true; + } + + if(!client.isNull()) + client.title(title()); + amClient.title(title()); +} + +Synth_MIDI_TEST_impl::Synth_MIDI_TEST_impl() + : amClient(amPlay, "aRts Instrument","Synth_MIDI_TEST") +{ + useMap = false; + client = MidiClient::null(); + timer = SubClass("Arts::AudioMidiTimer"); + channelData = new ChannelData[16]; +} + +Synth_MIDI_TEST_impl::~Synth_MIDI_TEST_impl() +{ + delete[] channelData; +} + +void Synth_MIDI_TEST_impl::streamStart() +{ + // register with the midi manager + MidiManager manager = Reference("global:Arts_MidiManager"); + if(!manager.isNull()) + { + client = manager.addClient(mcdRecord,mctDestination,title(), + "Arts::Synth_MIDI_TEST"); + client.addInputPort(self()); + } + else + arts_warning("Synth_MIDI_TEST: no midi manager found - not registered"); +} + +void Synth_MIDI_TEST_impl::streamEnd() +{ + client = MidiClient::null(); +} + +void Synth_MIDI_TEST_impl::noteOn(mcopbyte channel, mcopbyte note, + mcopbyte velocity) +{ + if(velocity == 0) + { + noteOff(channel,note); + return; + } + if(!channelData[channel].voice[note].isNull()) + { + noteOff(channel,note); + arts_info("Synth_MIDI_TEST: duplicate noteOn (mixed channels?)"); + } + + vector *params = 0; + if(useMap) + { + mcopbyte program = channelData[channel].program; + StructureDesc sd = map.getInstrument(channel,note,velocity,program,params); + if(sd.isNull()) return; + instrument = sd; + } + + Object structureObject = cache.get(instrument.name()); + if(structureObject.isNull()) + { + arts_debug("creating new structure"); + structureObject = builder.createObject(instrument); + + SynthModule play; + // TODO: allow changing busname! + if(!_busname.empty()) + { + Synth_BUS_UPLINK b; + b.busname(_busname); + play = b; + } + else + { + Synth_AMAN_PLAY a(amClient); + play = a; + } + structureObject._addChild(play,"play"); + connect(structureObject,"left",play,"left"); + connect(structureObject,"right",play,"right"); + } + else + { + arts_debug("used cached structure"); + } + + SynthModule structure = DynamicCast(structureObject); + assert(!structure.isNull()); + + if(params) + { + vector::iterator pi; + for(pi = params->begin(); pi != params->end(); pi++) + { + DynamicRequest req(structure); + + req.method("_set_"+pi->param).param(pi->value).invoke(); + } + } + setValue(structure,"frequency",getFrequency(note,channel)); + setValue(structure,"velocity",(float)velocity/127.0); + setValue(structure,"pressed",1.0); + + get_AMAN_PLAY(structure).start(); + structure.start(); + + channelData[channel].voice[note] = structure; + channelData[channel].name[note] = instrument.name(); +} + +void Synth_MIDI_TEST_impl::noteOff(mcopbyte channel, mcopbyte note) +{ + if(!channelData[channel].voice[note].isNull()) + { + setValue(channelData[channel].voice[note],"pressed",0.0); + + MidiReleaseHelper h; + + h.voice(channelData[channel].voice[note]); + h.cache(cache); + h.name(channelData[channel].name[note]); + + connect(channelData[channel].voice[note],"done",h,"done"); + h.start(); + assert(!h.terminate()); + channelData[channel].voice[note] = SynthModule::null(); + } +} + +float Synth_MIDI_TEST_impl::getFrequency(mcopbyte note, mcopbyte channel) +{ + /* 2 semitones pitchshift */ + return 261.63 * pow(2,((float)(note)+(channelData[channel].pitchShiftValue*2.0))/12.0)/32.0; +} + +void Synth_MIDI_TEST_impl::pitchWheel(mcopbyte channel, + mcopbyte lsb, mcopbyte msb) +{ + mcopbyte note; + + channelData[channel].pitchShiftValue = + (float)((lsb + msb*128) - (0x40*128))/8192.0; + + for(note = 0; note < 128; note++) + { + if(!channelData[channel].voice[note].isNull()) + setValue(channelData[channel].voice[note],"frequency",getFrequency(note,channel)); + } +} diff --git a/arts/modules/synth/synth_moog_vcf_impl.cc b/arts/modules/synth/synth_moog_vcf_impl.cc deleted file mode 100644 index 77bf5394..00000000 --- a/arts/modules/synth/synth_moog_vcf_impl.cc +++ /dev/null @@ -1,91 +0,0 @@ -/* - - Copyright (C) 2000 Jeff Tranter - tranter@pobox.com - - (C) 1999 Stefan Westerfeld - stefan@space.twc.de - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - */ - -#include "artsmodulessynth.h" -#include "stdsynthmodule.h" - -using namespace Arts; - -/* -Try this. It's a really nice 4pole. Very Moog like. - -in[x] and out[x] are member variables, init to 0.0 -the controls: - -fc = cutoff, nearly linear [0,1] -> [0, fs/2] -res = resonance [0, 4] -> [no resonance, self-oscillation] -*/ - -class Synth_MOOG_VCF_impl : virtual public Synth_MOOG_VCF_skel, - virtual public StdSynthModule -{ -protected: - float _frequency, _resonance; - double freqcorrect; - double in1, in2, in3, in4; - double out1, out2, out3, out4; - -public: - float frequency() { return _frequency; } - void frequency(float newFrequency) { _frequency = newFrequency; } - - float resonance() { return _resonance; } - void resonance(float newResonance) { _resonance = newResonance; } - - void streamInit() - { - in1 = in2 = in3 = in4 = out1 = out2 = out3 = out4 = 0.0; - } - - void calculateBlock(unsigned long samples) - { - freqcorrect = 1.16 / (double)(samplingRate / 2); - - for (unsigned int i=0; i < samples; i++) - { - double input = invalue[i]; - double fc = _frequency; - double res = _resonance; - double f = fc * freqcorrect; - double fb = res * (1.0 - 0.15 * f * f); - - input -= out4 * fb; - input *= 0.35013 * (f * f) * (f * f); - - out1 = input + 0.3 * in1 + (1 - f) * out1; // Pole 1 - in1 = input; - out2 = out1 + 0.3 * in2 + (1 - f) * out2; // Pole 2 - in2 = out1; - out3 = out2 + 0.3 * in3 + (1 - f) * out3; // Pole 3 - in3 = out2; - out4 = out3 + 0.3 * in4 + (1 - f) * out4; // Pole 4 - in4 = out3; - - outvalue[i] = out4; - } - } - -}; - -REGISTER_IMPLEMENTATION(Synth_MOOG_VCF_impl); diff --git a/arts/modules/synth/synth_moog_vcf_impl.cpp b/arts/modules/synth/synth_moog_vcf_impl.cpp new file mode 100644 index 00000000..77bf5394 --- /dev/null +++ b/arts/modules/synth/synth_moog_vcf_impl.cpp @@ -0,0 +1,91 @@ +/* + + Copyright (C) 2000 Jeff Tranter + tranter@pobox.com + + (C) 1999 Stefan Westerfeld + stefan@space.twc.de + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + */ + +#include "artsmodulessynth.h" +#include "stdsynthmodule.h" + +using namespace Arts; + +/* +Try this. It's a really nice 4pole. Very Moog like. + +in[x] and out[x] are member variables, init to 0.0 +the controls: + +fc = cutoff, nearly linear [0,1] -> [0, fs/2] +res = resonance [0, 4] -> [no resonance, self-oscillation] +*/ + +class Synth_MOOG_VCF_impl : virtual public Synth_MOOG_VCF_skel, + virtual public StdSynthModule +{ +protected: + float _frequency, _resonance; + double freqcorrect; + double in1, in2, in3, in4; + double out1, out2, out3, out4; + +public: + float frequency() { return _frequency; } + void frequency(float newFrequency) { _frequency = newFrequency; } + + float resonance() { return _resonance; } + void resonance(float newResonance) { _resonance = newResonance; } + + void streamInit() + { + in1 = in2 = in3 = in4 = out1 = out2 = out3 = out4 = 0.0; + } + + void calculateBlock(unsigned long samples) + { + freqcorrect = 1.16 / (double)(samplingRate / 2); + + for (unsigned int i=0; i < samples; i++) + { + double input = invalue[i]; + double fc = _frequency; + double res = _resonance; + double f = fc * freqcorrect; + double fb = res * (1.0 - 0.15 * f * f); + + input -= out4 * fb; + input *= 0.35013 * (f * f) * (f * f); + + out1 = input + 0.3 * in1 + (1 - f) * out1; // Pole 1 + in1 = input; + out2 = out1 + 0.3 * in2 + (1 - f) * out2; // Pole 2 + in2 = out1; + out3 = out2 + 0.3 * in3 + (1 - f) * out3; // Pole 3 + in3 = out2; + out4 = out3 + 0.3 * in4 + (1 - f) * out4; // Pole 4 + in4 = out3; + + outvalue[i] = out4; + } + } + +}; + +REGISTER_IMPLEMENTATION(Synth_MOOG_VCF_impl); diff --git a/arts/modules/synth/synth_nil_impl.cc b/arts/modules/synth/synth_nil_impl.cc deleted file mode 100644 index db7b1942..00000000 --- a/arts/modules/synth/synth_nil_impl.cc +++ /dev/null @@ -1,36 +0,0 @@ - /* - - Copyright (C) 2000 Jeff Tranter - tranter@pobox.com - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "artsmodulessynth.h" -#include "stdsynthmodule.h" - -using namespace Arts; - -// This module does nothing. It is only used for test purposes. -class Synth_NIL_impl : virtual public Synth_NIL_skel, - virtual public StdSynthModule -{ -public: - void calculateBlock(unsigned long /*samples*/) { } -}; - -REGISTER_IMPLEMENTATION(Synth_NIL_impl); diff --git a/arts/modules/synth/synth_nil_impl.cpp b/arts/modules/synth/synth_nil_impl.cpp new file mode 100644 index 00000000..db7b1942 --- /dev/null +++ b/arts/modules/synth/synth_nil_impl.cpp @@ -0,0 +1,36 @@ + /* + + Copyright (C) 2000 Jeff Tranter + tranter@pobox.com + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "artsmodulessynth.h" +#include "stdsynthmodule.h" + +using namespace Arts; + +// This module does nothing. It is only used for test purposes. +class Synth_NIL_impl : virtual public Synth_NIL_skel, + virtual public StdSynthModule +{ +public: + void calculateBlock(unsigned long /*samples*/) { } +}; + +REGISTER_IMPLEMENTATION(Synth_NIL_impl); diff --git a/arts/modules/synth/synth_noise_impl.cc b/arts/modules/synth/synth_noise_impl.cc deleted file mode 100644 index 474368e1..00000000 --- a/arts/modules/synth/synth_noise_impl.cc +++ /dev/null @@ -1,63 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include - -#include "artsmodulessynth.h" -#include "stdsynthmodule.h" - -using namespace Arts; - -namespace Arts { - -#define NOISE_SIZE 8192 - -class Synth_NOISE_impl : virtual public Synth_NOISE_skel, - virtual public StdSynthModule -{ - static float noise[NOISE_SIZE]; - static bool noiseInit; - unsigned long pos; -public: - Synth_NOISE_impl() - { - if(!noiseInit) - { - for(unsigned long i=0;i + +#include "artsmodulessynth.h" +#include "stdsynthmodule.h" + +using namespace Arts; + +namespace Arts { + +#define NOISE_SIZE 8192 + +class Synth_NOISE_impl : virtual public Synth_NOISE_skel, + virtual public StdSynthModule +{ + static float noise[NOISE_SIZE]; + static bool noiseInit; + unsigned long pos; +public: + Synth_NOISE_impl() + { + if(!noiseInit) + { + for(unsigned long i=0;i -#include -#include - -#include - -using namespace Arts; - -namespace Arts { - -static double arts_gsl_window_osc(double x) -{ - const double FILTER_H = 22000.0; - const double FILTER_L = 19000.0; - double f = 22050.0 * fabs(x), fact; - - if(f > FILTER_H) - fact = 0.0; - else if (f < FILTER_L) - fact = 1.0; - else - fact = cos(M_PI/2.0*((FILTER_L-f)/(FILTER_H-FILTER_L))); - - return fact; -} - -class Synth_OSC_impl :public Synth_OSC_skel, public StdSynthModule -{ -private: - GslOscConfig cfg; - GslOscData osc; - SynthOscWaveForm _waveForm; - - bool infrequency_connected; - bool modulation_connected; - bool insync_connected; - bool outvalue_connected; - bool outsync_connected; - - void updateConnected() - { - infrequency_connected = inputConnectionCount("infrequency"); - modulation_connected = inputConnectionCount("modulation"); - insync_connected = inputConnectionCount("insync"); - outvalue_connected = outputConnectionCount("outvalue"); - outsync_connected = outputConnectionCount("outsync"); - } -public: - Synth_OSC_impl() { - _waveForm = soWaveTriangle; - - memset(&cfg, 0, sizeof(GslOscConfig)); - memset(&osc, 0, sizeof(GslOscData)); - - cfg.table = 0; - cfg.exponential_fm = 0; - cfg.fm_strength = 0; - cfg.self_fm_strength = 0; - cfg.cfreq = 440; - cfg.fine_tune = 0; - cfg.pulse_width = 0.5; - cfg.pulse_mod_strength = 0; - - waveForm(soWaveSine); - }; - void apply() - { - gsl_osc_config(&osc, &cfg); - } - void streamInit() - { - updateConnected(); - } - void calculateBlock(unsigned long samples) - { - if(connectionCountChanged()) - updateConnected(); - - arts_debug("gop tab%p samples%ld f%p m%p is%p ov%p os%p\n", - cfg.table, samples, infrequency_connected?infrequency:0, - modulation_connected?modulation:0, - insync_connected?insync:0, - outvalue_connected?outvalue:0, - outsync_connected?outsync:0); - - gsl_osc_process(&osc, samples, infrequency_connected?infrequency:0, - modulation_connected?modulation:0, - insync_connected?insync:0, - outvalue_connected?outvalue:0, - outsync_connected?outsync:0); - } - SynthOscWaveForm waveForm() - { - return _waveForm; - } - void waveForm(SynthOscWaveForm wf) - { - if(wf != _waveForm) - { - if(cfg.table) - gsl_osc_table_free(cfg.table); - - float freqs[100]; - int n_freqs = 0; - - freqs[n_freqs] = 20; - while (freqs[n_freqs] < 22000) - { - freqs[n_freqs + 1] = freqs[n_freqs] * M_SQRT2; - n_freqs++; - } - arts_debug("Synth_OSC::waveForm: n_freqs = %d", n_freqs); - cfg.table = gsl_osc_table_create(samplingRateFloat, GslOscWaveForm(wf + 1), arts_gsl_window_osc, n_freqs, freqs); - _waveForm = wf; - apply(); - waveForm_changed(wf); - } - } - bool fmExponential() - { - return cfg.exponential_fm; - } - void fmExponential(bool newFm) - { - bool oldFm = fmExponential(); - - if(newFm != oldFm) - { - cfg.exponential_fm = newFm; - apply(); - fmExponential_changed(newFm); - } - } - float fmStrength() - { - return cfg.fm_strength; - } - void fmStrength(float f) - { - if(cfg.fm_strength != f) - { - cfg.fm_strength = f; - apply(); - fmStrength_changed(f); - } - } - float fmSelfStrength() - { - return cfg.self_fm_strength; - } - void fmSelfStrength(float f) - { - if(cfg.self_fm_strength != f) - { - cfg.self_fm_strength = f; - apply(); - fmSelfStrength_changed(f); - } - } - float phase() - { - return cfg.phase; - } - void phase(float p) - { - if(cfg.phase != p) - { - cfg.phase = p; - apply(); - phase_changed(p); - } - } - float frequency() - { - return cfg.cfreq; - } - void frequency(float f) - { - if(cfg.cfreq != f) - { - cfg.cfreq = f; - apply(); - frequency_changed(f); - } - } - long fineTune() - { - return cfg.fine_tune; - } - void fineTune(long f) - { - if(cfg.fine_tune != f) - { - cfg.fine_tune = f; - apply(); - fineTune_changed(f); - } - } - float pulseWidth() - { - return cfg.pulse_width; - } - void pulseWidth(float pw) - { - if(cfg.pulse_width != pw) - { - cfg.pulse_width = pw; - apply(); - pulseWidth_changed(pw); - } - } - float pulseModStrength() - { - return cfg.pulse_mod_strength; - } - void pulseModStrength(float pms) - { - if(cfg.pulse_mod_strength != pms) - { - cfg.pulse_mod_strength = pms; - apply(); - pulseModStrength_changed(pms); - } - } -}; -REGISTER_IMPLEMENTATION(Synth_OSC_impl); - -} diff --git a/arts/modules/synth/synth_osc_impl.cpp b/arts/modules/synth/synth_osc_impl.cpp new file mode 100644 index 00000000..214c2a16 --- /dev/null +++ b/arts/modules/synth/synth_osc_impl.cpp @@ -0,0 +1,253 @@ + /* + + Copyright (C) 2002 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "artsmodulessynth.h" +#include "debug.h" +#include "stdsynthmodule.h" +#include +#include +#include + +#include + +using namespace Arts; + +namespace Arts { + +static double arts_gsl_window_osc(double x) +{ + const double FILTER_H = 22000.0; + const double FILTER_L = 19000.0; + double f = 22050.0 * fabs(x), fact; + + if(f > FILTER_H) + fact = 0.0; + else if (f < FILTER_L) + fact = 1.0; + else + fact = cos(M_PI/2.0*((FILTER_L-f)/(FILTER_H-FILTER_L))); + + return fact; +} + +class Synth_OSC_impl :public Synth_OSC_skel, public StdSynthModule +{ +private: + GslOscConfig cfg; + GslOscData osc; + SynthOscWaveForm _waveForm; + + bool infrequency_connected; + bool modulation_connected; + bool insync_connected; + bool outvalue_connected; + bool outsync_connected; + + void updateConnected() + { + infrequency_connected = inputConnectionCount("infrequency"); + modulation_connected = inputConnectionCount("modulation"); + insync_connected = inputConnectionCount("insync"); + outvalue_connected = outputConnectionCount("outvalue"); + outsync_connected = outputConnectionCount("outsync"); + } +public: + Synth_OSC_impl() { + _waveForm = soWaveTriangle; + + memset(&cfg, 0, sizeof(GslOscConfig)); + memset(&osc, 0, sizeof(GslOscData)); + + cfg.table = 0; + cfg.exponential_fm = 0; + cfg.fm_strength = 0; + cfg.self_fm_strength = 0; + cfg.cfreq = 440; + cfg.fine_tune = 0; + cfg.pulse_width = 0.5; + cfg.pulse_mod_strength = 0; + + waveForm(soWaveSine); + }; + void apply() + { + gsl_osc_config(&osc, &cfg); + } + void streamInit() + { + updateConnected(); + } + void calculateBlock(unsigned long samples) + { + if(connectionCountChanged()) + updateConnected(); + + arts_debug("gop tab%p samples%ld f%p m%p is%p ov%p os%p\n", + cfg.table, samples, infrequency_connected?infrequency:0, + modulation_connected?modulation:0, + insync_connected?insync:0, + outvalue_connected?outvalue:0, + outsync_connected?outsync:0); + + gsl_osc_process(&osc, samples, infrequency_connected?infrequency:0, + modulation_connected?modulation:0, + insync_connected?insync:0, + outvalue_connected?outvalue:0, + outsync_connected?outsync:0); + } + SynthOscWaveForm waveForm() + { + return _waveForm; + } + void waveForm(SynthOscWaveForm wf) + { + if(wf != _waveForm) + { + if(cfg.table) + gsl_osc_table_free(cfg.table); + + float freqs[100]; + int n_freqs = 0; + + freqs[n_freqs] = 20; + while (freqs[n_freqs] < 22000) + { + freqs[n_freqs + 1] = freqs[n_freqs] * M_SQRT2; + n_freqs++; + } + arts_debug("Synth_OSC::waveForm: n_freqs = %d", n_freqs); + cfg.table = gsl_osc_table_create(samplingRateFloat, GslOscWaveForm(wf + 1), arts_gsl_window_osc, n_freqs, freqs); + _waveForm = wf; + apply(); + waveForm_changed(wf); + } + } + bool fmExponential() + { + return cfg.exponential_fm; + } + void fmExponential(bool newFm) + { + bool oldFm = fmExponential(); + + if(newFm != oldFm) + { + cfg.exponential_fm = newFm; + apply(); + fmExponential_changed(newFm); + } + } + float fmStrength() + { + return cfg.fm_strength; + } + void fmStrength(float f) + { + if(cfg.fm_strength != f) + { + cfg.fm_strength = f; + apply(); + fmStrength_changed(f); + } + } + float fmSelfStrength() + { + return cfg.self_fm_strength; + } + void fmSelfStrength(float f) + { + if(cfg.self_fm_strength != f) + { + cfg.self_fm_strength = f; + apply(); + fmSelfStrength_changed(f); + } + } + float phase() + { + return cfg.phase; + } + void phase(float p) + { + if(cfg.phase != p) + { + cfg.phase = p; + apply(); + phase_changed(p); + } + } + float frequency() + { + return cfg.cfreq; + } + void frequency(float f) + { + if(cfg.cfreq != f) + { + cfg.cfreq = f; + apply(); + frequency_changed(f); + } + } + long fineTune() + { + return cfg.fine_tune; + } + void fineTune(long f) + { + if(cfg.fine_tune != f) + { + cfg.fine_tune = f; + apply(); + fineTune_changed(f); + } + } + float pulseWidth() + { + return cfg.pulse_width; + } + void pulseWidth(float pw) + { + if(cfg.pulse_width != pw) + { + cfg.pulse_width = pw; + apply(); + pulseWidth_changed(pw); + } + } + float pulseModStrength() + { + return cfg.pulse_mod_strength; + } + void pulseModStrength(float pms) + { + if(cfg.pulse_mod_strength != pms) + { + cfg.pulse_mod_strength = pms; + apply(); + pulseModStrength_changed(pms); + } + } +}; +REGISTER_IMPLEMENTATION(Synth_OSC_impl); + +} diff --git a/arts/modules/synth/synth_pitch_shift_fft_impl.cc b/arts/modules/synth/synth_pitch_shift_fft_impl.cc deleted file mode 100644 index f356e1b8..00000000 --- a/arts/modules/synth/synth_pitch_shift_fft_impl.cc +++ /dev/null @@ -1,431 +0,0 @@ -/* - * Copyright (C) 2002 Michael Zuercher - * mzuerche@iastate.edu - * - * Based on an algorithm by Stephan M. Sprenger, http://www.dspdimension.com - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list - * of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - */ - - - -#include "artsmodulessynth.h" -#include "stdsynthmodule.h" -#include //debug only -#include -#include -#include - -#define MAX(a,b) (((a) > (b) ? (a) : (b))) -#define MIN(a,b) (((a) < (b) ? (a) : (b))) - -using namespace Arts; - -class Synth_PITCH_SHIFT_FFT_impl : virtual public Synth_PITCH_SHIFT_FFT_skel, - virtual public StdSynthModule -{ - private: - struct fftBin - { - float magnitude; - float frequency; - float phase; - }; - - bool addPi; - - /* the attributes (gui changeable) */ - /* these can happen on the fly */ - float _scaleFactor, _speed; - /* these require calling setStreamOpts() */ - unsigned int _frameSize, _oversample; - - /* the buffers */ - float *inBuffer, *outBuffer; /* circular buffers (float) */ - float *windowedData; /* windowed and unrolled buffer (float) */ - fftBin *analysisBuf, *synthesisBuf; /* workspaces (fftBin) */ - float *real, *imag; /* place for the FFT to output */ - float *windowCoeffient; - float *scratch; /* used to store imag IFFT results that we don't need */ - float *phaseDiff; - - /* variables to keep us in the right place of the buffers */ - unsigned long bufferOffset; - /* stream not yet ready to go until we have prerolled this many windows */ - unsigned int initStepsRemaining; - - /* some commonly used variables */ - unsigned long stepSize; - double expectedPhaseDiff; - double freqPerBin; - - /* Helper functions */ - void inWindow(float windowedData[], const float *inBuffer, const unsigned int basePopPoint); - void analysis(fftBin analysisBuf[], const float real[]); - void pitchScale(fftBin synthesisBuf[], const fftBin analysisBuf[]); - void synthesis(float windowedData[], fftBin synthesisBuf[]); - void outWindow(float *outBuffer, const unsigned int basePushPoint, const float windowedData[]); - - - public: - /* functions for the plugin interface */ - float speed() { return _speed; } - void speed(float newSpeed) { _speed = newSpeed; } - - float scaleFactor() { return _scaleFactor; } - void scaleFactor(float newScaleFactor) { _scaleFactor = newScaleFactor; } - - long frameSize() { return (long)_frameSize; } - void frameSize(long newFrameSize) - { - setStreamOpts(newFrameSize, _oversample); - } - - long oversample() { return (long)_oversample; } - void oversample(long newOversample) - { - setStreamOpts(_frameSize, newOversample); - } - - /* gets called by arts when it needs more data */ - void calculateBlock(unsigned long samples); - - void streamInit() - { - inBuffer = outBuffer = NULL; - analysisBuf = synthesisBuf = NULL; - real = imag = NULL; - windowedData = NULL; - windowCoeffient = NULL; - scratch = NULL; - phaseDiff = NULL; - - /* setup default stream parameters */ - _speed = 1.0; - _scaleFactor = 0.9; - setStreamOpts(4096,2); - - addPi = false; - } - - void streamEnd() - { - /* clean up buffers */ - delete [] inBuffer; - delete [] outBuffer; - delete [] windowedData; - delete [] analysisBuf; - delete [] synthesisBuf; - delete [] real; - delete [] imag; - delete [] windowCoeffient; - delete [] scratch; - delete [] phaseDiff; - } - - void setStreamOpts(unsigned int frameSize, unsigned int oversample) - { - /* clear any buffers left around */ - delete [] inBuffer; - delete [] outBuffer; - delete [] windowedData; - delete [] analysisBuf; - delete [] synthesisBuf; - delete [] real; - delete [] imag; - delete [] windowCoeffient; - delete [] scratch; - delete [] phaseDiff; - - _frameSize = frameSize; - _oversample = oversample; - - /* create the buffers */ - inBuffer = new float[_frameSize]; - outBuffer = new float[_frameSize]; - windowedData = new float[_frameSize]; - analysisBuf = new fftBin[_frameSize]; - synthesisBuf = new fftBin[_frameSize]; - real = new float[_frameSize]; - imag = new float[_frameSize]; - windowCoeffient = new float[_frameSize]; - scratch = new float[_frameSize]; - phaseDiff = new float[_oversample]; - - - /* set up the windowing coeffients */ - for(unsigned int sample=0; sample < _frameSize; sample++) - { - windowCoeffient[sample] = -0.5*cos(2.0*M_PI*(double)sample/(double)_frameSize)+0.5; - } - - /* we should start at the beginning of the buffers */ - bufferOffset = 0; - - /* stream not yet ready to go until we have prerolled this many windows */ - initStepsRemaining = _oversample; - - /* calculate some commonly used variables */ - stepSize = _frameSize / _oversample; - expectedPhaseDiff = 2*M_PI*(double)stepSize/(double)_frameSize; - freqPerBin = samplingRate/(double)_frameSize; - - for(unsigned int bin=0; bin < _oversample; bin++) - { - phaseDiff[bin] = bin*expectedPhaseDiff; - } - - memset(outBuffer, 0 ,stepSize * sizeof(float)); /* clear the first part of the output accumulator */ - memset(analysisBuf, 0 ,_frameSize * sizeof(fftBin)); - memset(synthesisBuf, 0 ,_frameSize * sizeof(fftBin)); - } -}; - -void Synth_PITCH_SHIFT_FFT_impl::calculateBlock(unsigned long samples) -{ - unsigned long samplesRemaining = samples; - - /* pointers to the arts streams */ - float *inData = inStream; - float *outData = outStream; - - while(samplesRemaining > 0) - { - /* either fill the next window, or take all we have */ - int samplesThisPass = MIN(samplesRemaining,stepSize - (bufferOffset % stepSize)); - - /* copy the incoming data into the buffer */ - memcpy(inBuffer + bufferOffset, inData, samplesThisPass * sizeof(float)); - /* set inData to data we haven't already taken */ - inData += samplesThisPass; - - if((bufferOffset+samplesThisPass) % stepSize) - { - /* if we still have only a partial window (input is still in the - * middle of a window), we can't run it yet, but we have leftover - * output we can use */ - } - else - { - /* round down the the nearest stepSize, and this window is full */ - - if(initStepsRemaining > 0) /* we need to have enough old data for a full block too */ - { - initStepsRemaining--; /* one less step to fill before we can start for real */ - } - else - { - unsigned int stepOffset = (bufferOffset + samplesThisPass) - stepSize; - /* now we have a complete block (not still filling at init) to add the - * new complete window on to */ - - /* ############################ prepare one stepSize ########################### */ - - inWindow(windowedData,inBuffer,stepOffset); - analysis(analysisBuf,windowedData); - pitchScale(synthesisBuf,analysisBuf); - synthesis(windowedData,synthesisBuf); - outWindow(outBuffer,bufferOffset,windowedData); - - /* ############################################################################# */ - } - } - - memcpy(outData, outBuffer + bufferOffset, samplesThisPass * sizeof(float)); - outData += samplesThisPass; - memset(outBuffer + bufferOffset, 0 ,samplesThisPass * sizeof(float)); /* clear the output space that we have used */ - bufferOffset += samplesThisPass; - bufferOffset %= _frameSize; /* wrap if needed before the next frame starts */ - samplesRemaining -= samplesThisPass; - } -} - -void Synth_PITCH_SHIFT_FFT_impl::inWindow(float windowedData[], const float *inBuffer, const unsigned int basePopPoint) -{ - unsigned int sample; - for(sample=0; sample < _frameSize-basePopPoint; sample++) - { - /* window the data and unroll the buffers */ - windowedData[sample] = inBuffer[basePopPoint + sample] * windowCoeffient[sample]; - } - for(; sample < _frameSize; sample++) - { - /* window the data and unroll the buffers */ - windowedData[sample] = inBuffer[(basePopPoint + sample) - _frameSize] * windowCoeffient[sample]; - } -} - -void Synth_PITCH_SHIFT_FFT_impl::analysis(fftBin analysisBuf[], const float windowedData[]) -{ - float lastPhase; - float phaseDrift; - - /* do forward FFT */ - /* const_cast because arts_fft_float is silly */ - arts_fft_float(_frameSize, 0, const_cast(windowedData), NULL, real, imag); - - /* the actual analysis loop */ - for(unsigned int bin=0; bin < _frameSize/2; bin++) - { - lastPhase = analysisBuf[bin].phase; - - /* compute magnitude and phase */ - analysisBuf[bin].magnitude = 2.0 * sqrt(real[bin]*real[bin] + imag[bin]*imag[bin]); - analysisBuf[bin].phase = atan2(imag[bin],real[bin]); - - - /* compute phase difference and subtract expected phase difference */ - phaseDrift = (analysisBuf[bin].phase - lastPhase) - float(phaseDiff[bin % _oversample]); - - /* we now need to map it into the +/- Pi interval */ - while(phaseDrift < -M_PI) - phaseDrift += 2*M_PI; - while(phaseDrift > M_PI) - phaseDrift -= 2*M_PI; - - /* compute true frequency */ - analysisBuf[bin].frequency = (bin + ((phaseDrift * _oversample) / (2*M_PI)))*freqPerBin; - //analysisBuf[bin].frequency = (bin + (phaseDrift/(2*M_PI)))*freqPerBin; - } - -} - -void Synth_PITCH_SHIFT_FFT_impl::pitchScale(fftBin synthesisBuf[], const fftBin analysisBuf[]) -{ - unsigned int sourceBin; - for(unsigned int destBin=0; destBin < _frameSize/2; destBin++) - { - sourceBin = (unsigned int)floor(destBin/_scaleFactor); - if(sourceBin < _frameSize/2) - { - /* new bin overrides existing if magnitude is higher */ - //if(analysisBuf[sourceBin].magnitude > synthesisBuf[destBin].magnitude) - //{ - synthesisBuf[destBin].magnitude = analysisBuf[sourceBin].magnitude; - synthesisBuf[destBin].frequency = analysisBuf[sourceBin].frequency * _scaleFactor; - //} -#if 0 - /* fill empty bins with nearest neighbor */ - if((synthesisBuf[destBin].frequency == 0.0) && (destBin > 0)) - { - cerr << "Empty bins\n"; - synthesisBuf[destBin].frequency = synthesisBuf[destBin-1].frequency; - synthesisBuf[destBin].magnitude = synthesisBuf[destBin-1].magnitude; - } -#endif - } - else - { - synthesisBuf[destBin].magnitude = 0; - } - } -#if 0 - for(unsigned int destBin=0; destBin < _frameSize/2; destBin++) - { - synthesisBuf[destBin].magnitude = analysisBuf[destBin].magnitude; - synthesisBuf[destBin].frequency = analysisBuf[destBin].frequency; - } -#endif -} - -void Synth_PITCH_SHIFT_FFT_impl::synthesis(float windowedData[], fftBin synthesisBuf[]) -{ - double phaseDrift; - -#if 0 - double test; - if(addPi == true) - test = -M_PI; - else - test = 0; -#endif - - for(unsigned int bin=0;bin < _frameSize/2; bin++) - { - /* deviation of this bin's phase from one exactly at the true bin frequency */ - //phaseDrift = (((synthesisBuf[bin].frequency - bin*freqPerBin)/ freqPerBin)*(2*M_PI))/_oversample; - phaseDrift = (synthesisBuf[bin].frequency / freqPerBin - bin)*(2*M_PI)/_oversample; - //phaseDrift = 0; - - - /* calculate the real and imag data */ - real[bin] = synthesisBuf[bin].magnitude * cos(synthesisBuf[bin].phase); - imag[bin] = synthesisBuf[bin].magnitude * sin(synthesisBuf[bin].phase); - - /* accumulate current phase for this wave */ - synthesisBuf[bin].phase += (phaseDrift + phaseDiff[bin % _oversample]); - //synthesisBuf[bin].phase += (phaseDrift + phaseDiff[bin % _oversample] + test); - - /* keep it so that -M_PI < phase < M_PI */ - while(synthesisBuf[bin].phase > M_PI) - synthesisBuf[bin].phase -= 2*M_PI; - while(synthesisBuf[bin].phase <= -M_PI) - synthesisBuf[bin].phase += 2*M_PI; - - -#if 0 - //this needs to happen so that that 'strongest wave' picking in pitchScale works - //but this isn't really the right place to do it - synthesisBuf[bin].magnitude = 0; - synthesisBuf[bin].frequency = 0; -#endif - - } - - /* zero the conjugate numbers */ - for(unsigned int i = _frameSize/2; i < _frameSize; i++) - { - real[i] = 0.0; - imag[i] = 0.0; - } - -#if 0 - if(addPi == false) - addPi = true; - else - addPi = false; -#endif - - /* do the inverse transform */ - arts_fft_float(_frameSize, 1, real, imag, windowedData, scratch); -} - -void Synth_PITCH_SHIFT_FFT_impl::outWindow(float *outBuffer, const unsigned int basePushPoint, const float windowedData[]) -{ - unsigned int sample; - - for(sample=0; sample < _frameSize - basePushPoint; sample++) - { - /* window the data and accumulate it back into the circular buffer */ - outBuffer[sample+basePushPoint] += 2.0 * windowCoeffient[sample] * windowedData[sample]/(_oversample); - } - for(; sample < _frameSize; sample++) - { - /* window the data and accumulate it back into the circular buffer */ - outBuffer[(sample+basePushPoint) - _frameSize] += 2.0 * windowCoeffient[sample] * windowedData[sample]/(_oversample); - } -} - - -REGISTER_IMPLEMENTATION(Synth_PITCH_SHIFT_FFT_impl); diff --git a/arts/modules/synth/synth_pitch_shift_fft_impl.cpp b/arts/modules/synth/synth_pitch_shift_fft_impl.cpp new file mode 100644 index 00000000..f356e1b8 --- /dev/null +++ b/arts/modules/synth/synth_pitch_shift_fft_impl.cpp @@ -0,0 +1,431 @@ +/* + * Copyright (C) 2002 Michael Zuercher + * mzuerche@iastate.edu + * + * Based on an algorithm by Stephan M. Sprenger, http://www.dspdimension.com + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + */ + + + +#include "artsmodulessynth.h" +#include "stdsynthmodule.h" +#include //debug only +#include +#include +#include + +#define MAX(a,b) (((a) > (b) ? (a) : (b))) +#define MIN(a,b) (((a) < (b) ? (a) : (b))) + +using namespace Arts; + +class Synth_PITCH_SHIFT_FFT_impl : virtual public Synth_PITCH_SHIFT_FFT_skel, + virtual public StdSynthModule +{ + private: + struct fftBin + { + float magnitude; + float frequency; + float phase; + }; + + bool addPi; + + /* the attributes (gui changeable) */ + /* these can happen on the fly */ + float _scaleFactor, _speed; + /* these require calling setStreamOpts() */ + unsigned int _frameSize, _oversample; + + /* the buffers */ + float *inBuffer, *outBuffer; /* circular buffers (float) */ + float *windowedData; /* windowed and unrolled buffer (float) */ + fftBin *analysisBuf, *synthesisBuf; /* workspaces (fftBin) */ + float *real, *imag; /* place for the FFT to output */ + float *windowCoeffient; + float *scratch; /* used to store imag IFFT results that we don't need */ + float *phaseDiff; + + /* variables to keep us in the right place of the buffers */ + unsigned long bufferOffset; + /* stream not yet ready to go until we have prerolled this many windows */ + unsigned int initStepsRemaining; + + /* some commonly used variables */ + unsigned long stepSize; + double expectedPhaseDiff; + double freqPerBin; + + /* Helper functions */ + void inWindow(float windowedData[], const float *inBuffer, const unsigned int basePopPoint); + void analysis(fftBin analysisBuf[], const float real[]); + void pitchScale(fftBin synthesisBuf[], const fftBin analysisBuf[]); + void synthesis(float windowedData[], fftBin synthesisBuf[]); + void outWindow(float *outBuffer, const unsigned int basePushPoint, const float windowedData[]); + + + public: + /* functions for the plugin interface */ + float speed() { return _speed; } + void speed(float newSpeed) { _speed = newSpeed; } + + float scaleFactor() { return _scaleFactor; } + void scaleFactor(float newScaleFactor) { _scaleFactor = newScaleFactor; } + + long frameSize() { return (long)_frameSize; } + void frameSize(long newFrameSize) + { + setStreamOpts(newFrameSize, _oversample); + } + + long oversample() { return (long)_oversample; } + void oversample(long newOversample) + { + setStreamOpts(_frameSize, newOversample); + } + + /* gets called by arts when it needs more data */ + void calculateBlock(unsigned long samples); + + void streamInit() + { + inBuffer = outBuffer = NULL; + analysisBuf = synthesisBuf = NULL; + real = imag = NULL; + windowedData = NULL; + windowCoeffient = NULL; + scratch = NULL; + phaseDiff = NULL; + + /* setup default stream parameters */ + _speed = 1.0; + _scaleFactor = 0.9; + setStreamOpts(4096,2); + + addPi = false; + } + + void streamEnd() + { + /* clean up buffers */ + delete [] inBuffer; + delete [] outBuffer; + delete [] windowedData; + delete [] analysisBuf; + delete [] synthesisBuf; + delete [] real; + delete [] imag; + delete [] windowCoeffient; + delete [] scratch; + delete [] phaseDiff; + } + + void setStreamOpts(unsigned int frameSize, unsigned int oversample) + { + /* clear any buffers left around */ + delete [] inBuffer; + delete [] outBuffer; + delete [] windowedData; + delete [] analysisBuf; + delete [] synthesisBuf; + delete [] real; + delete [] imag; + delete [] windowCoeffient; + delete [] scratch; + delete [] phaseDiff; + + _frameSize = frameSize; + _oversample = oversample; + + /* create the buffers */ + inBuffer = new float[_frameSize]; + outBuffer = new float[_frameSize]; + windowedData = new float[_frameSize]; + analysisBuf = new fftBin[_frameSize]; + synthesisBuf = new fftBin[_frameSize]; + real = new float[_frameSize]; + imag = new float[_frameSize]; + windowCoeffient = new float[_frameSize]; + scratch = new float[_frameSize]; + phaseDiff = new float[_oversample]; + + + /* set up the windowing coeffients */ + for(unsigned int sample=0; sample < _frameSize; sample++) + { + windowCoeffient[sample] = -0.5*cos(2.0*M_PI*(double)sample/(double)_frameSize)+0.5; + } + + /* we should start at the beginning of the buffers */ + bufferOffset = 0; + + /* stream not yet ready to go until we have prerolled this many windows */ + initStepsRemaining = _oversample; + + /* calculate some commonly used variables */ + stepSize = _frameSize / _oversample; + expectedPhaseDiff = 2*M_PI*(double)stepSize/(double)_frameSize; + freqPerBin = samplingRate/(double)_frameSize; + + for(unsigned int bin=0; bin < _oversample; bin++) + { + phaseDiff[bin] = bin*expectedPhaseDiff; + } + + memset(outBuffer, 0 ,stepSize * sizeof(float)); /* clear the first part of the output accumulator */ + memset(analysisBuf, 0 ,_frameSize * sizeof(fftBin)); + memset(synthesisBuf, 0 ,_frameSize * sizeof(fftBin)); + } +}; + +void Synth_PITCH_SHIFT_FFT_impl::calculateBlock(unsigned long samples) +{ + unsigned long samplesRemaining = samples; + + /* pointers to the arts streams */ + float *inData = inStream; + float *outData = outStream; + + while(samplesRemaining > 0) + { + /* either fill the next window, or take all we have */ + int samplesThisPass = MIN(samplesRemaining,stepSize - (bufferOffset % stepSize)); + + /* copy the incoming data into the buffer */ + memcpy(inBuffer + bufferOffset, inData, samplesThisPass * sizeof(float)); + /* set inData to data we haven't already taken */ + inData += samplesThisPass; + + if((bufferOffset+samplesThisPass) % stepSize) + { + /* if we still have only a partial window (input is still in the + * middle of a window), we can't run it yet, but we have leftover + * output we can use */ + } + else + { + /* round down the the nearest stepSize, and this window is full */ + + if(initStepsRemaining > 0) /* we need to have enough old data for a full block too */ + { + initStepsRemaining--; /* one less step to fill before we can start for real */ + } + else + { + unsigned int stepOffset = (bufferOffset + samplesThisPass) - stepSize; + /* now we have a complete block (not still filling at init) to add the + * new complete window on to */ + + /* ############################ prepare one stepSize ########################### */ + + inWindow(windowedData,inBuffer,stepOffset); + analysis(analysisBuf,windowedData); + pitchScale(synthesisBuf,analysisBuf); + synthesis(windowedData,synthesisBuf); + outWindow(outBuffer,bufferOffset,windowedData); + + /* ############################################################################# */ + } + } + + memcpy(outData, outBuffer + bufferOffset, samplesThisPass * sizeof(float)); + outData += samplesThisPass; + memset(outBuffer + bufferOffset, 0 ,samplesThisPass * sizeof(float)); /* clear the output space that we have used */ + bufferOffset += samplesThisPass; + bufferOffset %= _frameSize; /* wrap if needed before the next frame starts */ + samplesRemaining -= samplesThisPass; + } +} + +void Synth_PITCH_SHIFT_FFT_impl::inWindow(float windowedData[], const float *inBuffer, const unsigned int basePopPoint) +{ + unsigned int sample; + for(sample=0; sample < _frameSize-basePopPoint; sample++) + { + /* window the data and unroll the buffers */ + windowedData[sample] = inBuffer[basePopPoint + sample] * windowCoeffient[sample]; + } + for(; sample < _frameSize; sample++) + { + /* window the data and unroll the buffers */ + windowedData[sample] = inBuffer[(basePopPoint + sample) - _frameSize] * windowCoeffient[sample]; + } +} + +void Synth_PITCH_SHIFT_FFT_impl::analysis(fftBin analysisBuf[], const float windowedData[]) +{ + float lastPhase; + float phaseDrift; + + /* do forward FFT */ + /* const_cast because arts_fft_float is silly */ + arts_fft_float(_frameSize, 0, const_cast(windowedData), NULL, real, imag); + + /* the actual analysis loop */ + for(unsigned int bin=0; bin < _frameSize/2; bin++) + { + lastPhase = analysisBuf[bin].phase; + + /* compute magnitude and phase */ + analysisBuf[bin].magnitude = 2.0 * sqrt(real[bin]*real[bin] + imag[bin]*imag[bin]); + analysisBuf[bin].phase = atan2(imag[bin],real[bin]); + + + /* compute phase difference and subtract expected phase difference */ + phaseDrift = (analysisBuf[bin].phase - lastPhase) - float(phaseDiff[bin % _oversample]); + + /* we now need to map it into the +/- Pi interval */ + while(phaseDrift < -M_PI) + phaseDrift += 2*M_PI; + while(phaseDrift > M_PI) + phaseDrift -= 2*M_PI; + + /* compute true frequency */ + analysisBuf[bin].frequency = (bin + ((phaseDrift * _oversample) / (2*M_PI)))*freqPerBin; + //analysisBuf[bin].frequency = (bin + (phaseDrift/(2*M_PI)))*freqPerBin; + } + +} + +void Synth_PITCH_SHIFT_FFT_impl::pitchScale(fftBin synthesisBuf[], const fftBin analysisBuf[]) +{ + unsigned int sourceBin; + for(unsigned int destBin=0; destBin < _frameSize/2; destBin++) + { + sourceBin = (unsigned int)floor(destBin/_scaleFactor); + if(sourceBin < _frameSize/2) + { + /* new bin overrides existing if magnitude is higher */ + //if(analysisBuf[sourceBin].magnitude > synthesisBuf[destBin].magnitude) + //{ + synthesisBuf[destBin].magnitude = analysisBuf[sourceBin].magnitude; + synthesisBuf[destBin].frequency = analysisBuf[sourceBin].frequency * _scaleFactor; + //} +#if 0 + /* fill empty bins with nearest neighbor */ + if((synthesisBuf[destBin].frequency == 0.0) && (destBin > 0)) + { + cerr << "Empty bins\n"; + synthesisBuf[destBin].frequency = synthesisBuf[destBin-1].frequency; + synthesisBuf[destBin].magnitude = synthesisBuf[destBin-1].magnitude; + } +#endif + } + else + { + synthesisBuf[destBin].magnitude = 0; + } + } +#if 0 + for(unsigned int destBin=0; destBin < _frameSize/2; destBin++) + { + synthesisBuf[destBin].magnitude = analysisBuf[destBin].magnitude; + synthesisBuf[destBin].frequency = analysisBuf[destBin].frequency; + } +#endif +} + +void Synth_PITCH_SHIFT_FFT_impl::synthesis(float windowedData[], fftBin synthesisBuf[]) +{ + double phaseDrift; + +#if 0 + double test; + if(addPi == true) + test = -M_PI; + else + test = 0; +#endif + + for(unsigned int bin=0;bin < _frameSize/2; bin++) + { + /* deviation of this bin's phase from one exactly at the true bin frequency */ + //phaseDrift = (((synthesisBuf[bin].frequency - bin*freqPerBin)/ freqPerBin)*(2*M_PI))/_oversample; + phaseDrift = (synthesisBuf[bin].frequency / freqPerBin - bin)*(2*M_PI)/_oversample; + //phaseDrift = 0; + + + /* calculate the real and imag data */ + real[bin] = synthesisBuf[bin].magnitude * cos(synthesisBuf[bin].phase); + imag[bin] = synthesisBuf[bin].magnitude * sin(synthesisBuf[bin].phase); + + /* accumulate current phase for this wave */ + synthesisBuf[bin].phase += (phaseDrift + phaseDiff[bin % _oversample]); + //synthesisBuf[bin].phase += (phaseDrift + phaseDiff[bin % _oversample] + test); + + /* keep it so that -M_PI < phase < M_PI */ + while(synthesisBuf[bin].phase > M_PI) + synthesisBuf[bin].phase -= 2*M_PI; + while(synthesisBuf[bin].phase <= -M_PI) + synthesisBuf[bin].phase += 2*M_PI; + + +#if 0 + //this needs to happen so that that 'strongest wave' picking in pitchScale works + //but this isn't really the right place to do it + synthesisBuf[bin].magnitude = 0; + synthesisBuf[bin].frequency = 0; +#endif + + } + + /* zero the conjugate numbers */ + for(unsigned int i = _frameSize/2; i < _frameSize; i++) + { + real[i] = 0.0; + imag[i] = 0.0; + } + +#if 0 + if(addPi == false) + addPi = true; + else + addPi = false; +#endif + + /* do the inverse transform */ + arts_fft_float(_frameSize, 1, real, imag, windowedData, scratch); +} + +void Synth_PITCH_SHIFT_FFT_impl::outWindow(float *outBuffer, const unsigned int basePushPoint, const float windowedData[]) +{ + unsigned int sample; + + for(sample=0; sample < _frameSize - basePushPoint; sample++) + { + /* window the data and accumulate it back into the circular buffer */ + outBuffer[sample+basePushPoint] += 2.0 * windowCoeffient[sample] * windowedData[sample]/(_oversample); + } + for(; sample < _frameSize; sample++) + { + /* window the data and accumulate it back into the circular buffer */ + outBuffer[(sample+basePushPoint) - _frameSize] += 2.0 * windowCoeffient[sample] * windowedData[sample]/(_oversample); + } +} + + +REGISTER_IMPLEMENTATION(Synth_PITCH_SHIFT_FFT_impl); diff --git a/arts/modules/synth/synth_pitch_shift_impl.cc b/arts/modules/synth/synth_pitch_shift_impl.cc deleted file mode 100644 index 37217c8a..00000000 --- a/arts/modules/synth/synth_pitch_shift_impl.cc +++ /dev/null @@ -1,196 +0,0 @@ -/* - - Copyright (C) 2000 Jeff Tranter - tranter@pobox.com - - (C) 1999 Stefan Westerfeld - stefan@space.twc.de - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - */ - -#include -#include "artsmodulessynth.h" -#include "stdsynthmodule.h" - -using namespace Arts; - -class Synth_PITCH_SHIFT_impl : virtual public Synth_PITCH_SHIFT_skel, - virtual public StdSynthModule -{ -protected: - float _speed, _frequency; - - enum { MAXDELAY = 44100 }; - float *dbuffer; - float lfopos, b1pos, b2pos, b1inc, b2inc; - bool b1reset, b2reset, initialized; - int dbpos; - -public: - Synth_PITCH_SHIFT_impl() : _speed(1.0), _frequency(5.0) - { - } - - float speed() { return _speed; } - void speed(float newSpeed) { _speed = newSpeed; } - - float frequency() { return _frequency; } - void frequency(float newFrequency) { _frequency = newFrequency; } - - - void streamInit() - { - dbuffer = new float[MAXDELAY]; - for (dbpos=0; dbpos 1.0 (uppitching) - * - * start with a sample from long ago and slowly decrease delay - */ - if (!b1reset && lfopos > 0.25) { - if (_speed <= 1.0) { - b1pos = 0; - b1inc = 1 - _speed; - } else { - b1inc = 1 - _speed; - b1pos = 10 + ((-b1inc) * (1 / lfoposinc)); - /* 10+ are not strictly necessary */ - } - b1reset = true; - } - - if (!b2reset && lfopos > 0.75) { - if (_speed <= 1.0) { - b2pos = 0; - b2inc = 1 - _speed; - } else{ - b2inc = 1 - _speed; - b2pos = 10 + ((-b2inc) * (1/lfoposinc)); - /* 10+ are not strictly necessary */ - } - b2reset = true; - } - - b1pos += b1inc; - b2pos += b2inc; - - int position, position1; - double error,int_pos; - - /* - * Interpolate value from buffer position 1 - */ - error = modf(b1pos, &int_pos); - - position = dbpos - (int)int_pos; - if (position < 0) - position += MAXDELAY; - position1 = position - 1; - if (position1 < 0) - position1 += MAXDELAY; - - b1value = dbuffer[position] * (1 - error) + dbuffer[position1] * error; - - /* - * Interpolate value from buffer position 2 - */ - error = modf(b2pos,&int_pos); - - position = dbpos - (int)int_pos; - if (position < 0) - position += MAXDELAY; - position1 = position-1; - if ( position1 < 0) - position1 += MAXDELAY; - - b2value = dbuffer[position]*(1-error) + dbuffer[position1]*error; - - /* - * Calculate output signal from these two buffers - */ - - lfo = (sin(pi2 * lfopos) + 1) / 2; - - /* position sin lfo variable - *------------------------------------------------------------------ - * lfo value: 0.25 1 1 => buffer 2 is used - * 0.75 -1 0 => buffer 1 is used - */ - - *outvalue++ = b1value * (1.0 - lfo) + b2value * lfo; - - /* - * increment delay buffer position - */ - dbpos++; - if (dbpos == MAXDELAY) - dbpos = 0; - } - } -}; - -REGISTER_IMPLEMENTATION(Synth_PITCH_SHIFT_impl); diff --git a/arts/modules/synth/synth_pitch_shift_impl.cpp b/arts/modules/synth/synth_pitch_shift_impl.cpp new file mode 100644 index 00000000..37217c8a --- /dev/null +++ b/arts/modules/synth/synth_pitch_shift_impl.cpp @@ -0,0 +1,196 @@ +/* + + Copyright (C) 2000 Jeff Tranter + tranter@pobox.com + + (C) 1999 Stefan Westerfeld + stefan@space.twc.de + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + */ + +#include +#include "artsmodulessynth.h" +#include "stdsynthmodule.h" + +using namespace Arts; + +class Synth_PITCH_SHIFT_impl : virtual public Synth_PITCH_SHIFT_skel, + virtual public StdSynthModule +{ +protected: + float _speed, _frequency; + + enum { MAXDELAY = 44100 }; + float *dbuffer; + float lfopos, b1pos, b2pos, b1inc, b2inc; + bool b1reset, b2reset, initialized; + int dbpos; + +public: + Synth_PITCH_SHIFT_impl() : _speed(1.0), _frequency(5.0) + { + } + + float speed() { return _speed; } + void speed(float newSpeed) { _speed = newSpeed; } + + float frequency() { return _frequency; } + void frequency(float newFrequency) { _frequency = newFrequency; } + + + void streamInit() + { + dbuffer = new float[MAXDELAY]; + for (dbpos=0; dbpos 1.0 (uppitching) + * + * start with a sample from long ago and slowly decrease delay + */ + if (!b1reset && lfopos > 0.25) { + if (_speed <= 1.0) { + b1pos = 0; + b1inc = 1 - _speed; + } else { + b1inc = 1 - _speed; + b1pos = 10 + ((-b1inc) * (1 / lfoposinc)); + /* 10+ are not strictly necessary */ + } + b1reset = true; + } + + if (!b2reset && lfopos > 0.75) { + if (_speed <= 1.0) { + b2pos = 0; + b2inc = 1 - _speed; + } else{ + b2inc = 1 - _speed; + b2pos = 10 + ((-b2inc) * (1/lfoposinc)); + /* 10+ are not strictly necessary */ + } + b2reset = true; + } + + b1pos += b1inc; + b2pos += b2inc; + + int position, position1; + double error,int_pos; + + /* + * Interpolate value from buffer position 1 + */ + error = modf(b1pos, &int_pos); + + position = dbpos - (int)int_pos; + if (position < 0) + position += MAXDELAY; + position1 = position - 1; + if (position1 < 0) + position1 += MAXDELAY; + + b1value = dbuffer[position] * (1 - error) + dbuffer[position1] * error; + + /* + * Interpolate value from buffer position 2 + */ + error = modf(b2pos,&int_pos); + + position = dbpos - (int)int_pos; + if (position < 0) + position += MAXDELAY; + position1 = position-1; + if ( position1 < 0) + position1 += MAXDELAY; + + b2value = dbuffer[position]*(1-error) + dbuffer[position1]*error; + + /* + * Calculate output signal from these two buffers + */ + + lfo = (sin(pi2 * lfopos) + 1) / 2; + + /* position sin lfo variable + *------------------------------------------------------------------ + * lfo value: 0.25 1 1 => buffer 2 is used + * 0.75 -1 0 => buffer 1 is used + */ + + *outvalue++ = b1value * (1.0 - lfo) + b2value * lfo; + + /* + * increment delay buffer position + */ + dbpos++; + if (dbpos == MAXDELAY) + dbpos = 0; + } + } +}; + +REGISTER_IMPLEMENTATION(Synth_PITCH_SHIFT_impl); diff --git a/arts/modules/synth/synth_play_pat_impl.cc b/arts/modules/synth/synth_play_pat_impl.cc deleted file mode 100644 index 7c2699f7..00000000 --- a/arts/modules/synth/synth_play_pat_impl.cc +++ /dev/null @@ -1,529 +0,0 @@ -# /* - - Copyright (C) 2001 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "artsmodulessynth.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -namespace Arts { - -namespace PatchLoader { - typedef unsigned char byte; - typedef unsigned short int word; - typedef unsigned int dword; - typedef char sbyte; - typedef short int sword; - typedef int sdword; - - static int pos = 0; - static int apos = 0; - - inline void xRead(FILE *file, int len, void *data) - { - // printf("(0x%2x) - 0x%02x ... reading %d bytes\n",apos,pos,len); - pos += len; - apos += len; - if(fread(data, len, 1, file) != 1) - fprintf(stdout, "short read\n"); - } - - inline void skip(FILE *file, int len) - { - // printf("(0x%2x) - 0x%02x ... skipping %d bytes\n",apos,pos,len); - pos += len; - apos += len; - while(len > 0) - { - char junk; - if(fread(&junk, 1, 1, file) != 1) - fprintf(stdout, "short read\n"); - len--; - } - } - - - inline void readBytes(FILE *file, unsigned char *bytes, int len) - { - xRead(file, len, bytes); - } - - inline void readString(FILE *file, char *str, int len) - { - xRead(file, len, str); - } - - /* readXXX with sizeof(xxx) == 1 */ - inline void readByte(FILE *file, byte& b) - { - xRead(file, 1, &b); - } - - /* readXXX with sizeof(xxx) == 2 */ - inline void readWord(FILE *file, word& w) - { - byte h, l; - xRead(file, 1, &l); - xRead(file, 1, &h); - w = (h << 8) + l; - } - - inline void readSWord(FILE *file, sword& sw) - { - word w; - readWord(file, w); - sw = (sword)w; - } - - /* readXXX with sizeof(xxx) == 4 */ - inline void readDWord(FILE *file, dword& dw) - { - byte h, l, hh, hl; - xRead(file, 1, &l); - xRead(file, 1, &h); - xRead(file, 1, &hl); - xRead(file, 1, &hh); - dw = (hh << 24) + (hl << 16) + (h << 8) + l; - } - - struct PatHeader { - char id[12]; /* ID='GF1PATCH110' */ - char manufacturer_id[10]; /* Manufacturer ID */ - char description[60]; /* Description of the contained Instruments - or copyright of manufacturer. */ - byte instruments; /* Number of instruments in this patch */ - byte voices; /* Number of voices for sample */ - byte channels; /* Number of output channels - (1=mono,2=stereo) */ - word waveforms; /* Number of waveforms */ - word mastervolume; /* Master volume for all samples */ - dword size; /* Size of the following data */ - char reserved[36]; /* reserved */ - - PatHeader(FILE *file) - { - readString(file, id, 12); - readString(file, manufacturer_id, 10); - readString(file, description, 60); - /* skip(file, 2);*/ - - readByte(file, instruments); - readByte(file, voices); - readByte(file, channels); - - readWord(file, waveforms); - readWord(file, mastervolume); - readDWord(file, size); - - readString(file, reserved, 36); - } - }; - - struct PatInstrument { - word number; - char name[16]; - dword size; /* Size of the whole instrument in bytes. */ - byte layers; - char reserved[40]; - - /* layer? */ - word layerUnknown; - dword layerSize; - byte sampleCount; /* number of samples in this layer (?) */ - char layerReserved[40]; - - PatInstrument(FILE *file) - { - readWord(file, number); - readString(file, name, 16); - readDWord(file, size); - readByte(file, layers); - readString(file, reserved, 40); - - /* layer: (?) */ - readWord(file, layerUnknown); - readDWord(file, layerSize); - readByte(file, sampleCount); - readString(file, reserved, 40); - } - }; - - struct PatPatch { - char filename[7]; /* Wave file name */ - byte fractions; /* Fractions */ - dword wavesize; /* Wave size. - Size of the wave digital data */ - dword loopStart; - dword loopEnd; - word sampleRate; - dword minFreq; - dword maxFreq; - dword origFreq; - sword fineTune; - byte balance; - byte filterRate[6]; - byte filterOffset[6]; - byte tremoloSweep; - byte tremoloRate; - byte tremoloDepth; - byte vibratoSweep; - byte vibratoRate; - byte vibratoDepth; - byte waveFormat; - sword freqScale; - word freqScaleFactor; - char reserved[36]; - - PatPatch(FILE *file) - { - readString(file, filename, 7); - readByte(file, fractions); - readDWord(file, wavesize); - readDWord(file, loopStart); - readDWord(file, loopEnd); - readWord(file, sampleRate); - readDWord(file, minFreq); - readDWord(file, maxFreq); - readDWord(file, origFreq); - readSWord(file, fineTune); - readByte(file, balance); - readBytes(file, filterRate, 6); - readBytes(file, filterOffset, 6); - readByte(file, tremoloSweep); - readByte(file, tremoloRate); - readByte(file, tremoloDepth); - readByte(file, vibratoSweep); - readByte(file, vibratoRate); - readByte(file, vibratoDepth); - readByte(file, waveFormat); - readSWord(file, freqScale); - readWord(file, freqScaleFactor); - readString(file, reserved, 36); - } - }; -} - -class CachedPat : public CachedObject -{ -protected: - struct stat oldstat; - string filename; - bool initOk; - long dataSize; - - CachedPat(Cache *cache, const string& filename); - ~CachedPat(); - -public: - - struct Data { - PatchLoader::PatPatch patch; - mcopbyte *rawdata; - Data(FILE *file) - : patch(file) - { - rawdata = new mcopbyte[patch.wavesize]; - fread(rawdata, 1, patch.wavesize, file); - - // sign conversion only for 16bit! - if(patch.waveFormat & (1 << 1)) - { - for(unsigned int i = 1; i < patch.wavesize; i+=2) - rawdata[i] ^= 0x80; - } - - // unfold ping-pong loops - if(patch.waveFormat & (1 << 3)) - { - int looplen = patch.loopEnd - patch.loopStart; - arts_assert(looplen > 0); - - mcopbyte *newdata = new mcopbyte[patch.wavesize + looplen]; - - // copy head - memcpy(&newdata[0], &rawdata[0], patch.loopStart + looplen); - - // 16 bit unfolding only: - for(int i=0; i dList; - - static CachedPat *load(Cache *cache, const string& filename); - /** - * validity test for the cache - returns false if the object is having - * reflecting the correct contents anymore (e.g. if the file on the - * disk has changed), and there is no point in keeping it in the cache any - * longer - */ - bool isValid(); - /** - * memory usage for the cache - */ - int memoryUsage(); -}; - -CachedPat *CachedPat::load(Cache *cache, const string& filename) -{ - CachedPat *pat; - - pat = (CachedPat *)cache->get(string("CachedPat:")+filename); - if(!pat) { - pat = new CachedPat(cache, filename); - - if(!pat->initOk) // loading failed - { - pat->decRef(); - return 0; - } - } - - return pat; -} - -bool CachedPat::isValid() -{ - if(!initOk) - return false; - - struct stat newstat; - - lstat(filename.c_str(),&newstat); - return(newstat.st_mtime == oldstat.st_mtime); -} - -int CachedPat::memoryUsage() -{ - return dataSize; -} - -CachedPat::CachedPat(Cache *cache, const string& filename) - : CachedObject(cache), filename(filename), initOk(false), dataSize(0) -{ - setKey(string("CachedPat:")+filename); - - if(lstat(filename.c_str(),&oldstat) == -1) - { - arts_info("CachedPat: Can't stat file '%s'", filename.c_str()); - return; - } - - FILE *patfile = fopen(filename.c_str(), "r"); - if(patfile) - { - //PatchLoader::PatHeader header(patfile); - PatchLoader::PatInstrument ins(patfile); - - for(int i=0;ipatch.wavesize; - } - fclose(patfile); - - arts_debug("loaded pat %s",filename.c_str()); - arts_debug(" %d patches, datasize total is %d bytes", - ins.sampleCount, dataSize); - - initOk = true; - } -} - -CachedPat::~CachedPat() -{ - while(!dList.empty()) - { - delete dList.front(); - dList.pop_front(); - } -} - -class Synth_PLAY_PAT_impl : virtual public Synth_PLAY_PAT_skel, - virtual public StdSynthModule -{ -protected: - string _filename; - CachedPat *pat; - CachedPat::Data *selected; - float fpos; - -public: - Synth_PLAY_PAT_impl() - { - pat = 0; - selected = 0; - } - - void unload() - { - if(pat) - { - pat->decRef(); - pat = 0; - } - } - - ~Synth_PLAY_PAT_impl() - { - unload(); - } - - void streamStart() - { - fpos = 0.0; - selected = 0; - } - - void calculateBlock(unsigned long samples) - { - /* the normal offset is 60 - 60 = 12*5 - so we scale with 2^5 = 32 - */ - float freq = frequency[0]; /* * 32.0 / 2.0; * why /2.0? */ - int ifreq = (int)(freq * 1024.0); - if(!selected && pat) - { - int bestdiff = 20000 * 1024; - - list::iterator i; - for(i = pat->dList.begin(); i != pat->dList.end(); i++) - { - int diff = ::abs(double(ifreq - (*i)->patch.origFreq)); - if(diff < bestdiff) - { - selected = *i; - bestdiff = diff; - } - } - - /* drums */ - if(selected && selected->patch.freqScaleFactor == 0) - ifreq = selected->patch.origFreq; - } - if(selected) - { - const PatchLoader::PatPatch& patch = selected->patch; - - /* - * thats just a *guess*, I have no idea how tuning actually - * should work - */ -#if 0 - float tonetune = float(pat.fineTune)/float(pat.freqScaleFactor); - float tuning = pow(2.0, tonetune/12.0); - freq *= tuning; -#endif - //printf("tonetune: %f\n",tonetune); - //printf("tuning: %f\n",tuning); - - float step = double(patch.sampleRate)/samplingRateFloat * - float(ifreq) / float(patch.origFreq); - for(unsigned int i = 0; i < samples; i++) - { - // ASSUME 16bit signed, native byte order - int ifpos = int(fpos)*2; - - // looped? bidi? backw? - if((patch.waveFormat & ((1 << 2) + (1 << 3) + (1 << 4))) - == (1 << 2)) - { - while(ifpos >= signed(patch.loopEnd)) - { - ifpos -= (patch.loopEnd - patch.loopStart); - fpos -= (patch.loopEnd - patch.loopStart)/2; - } - } - - short int *x = (short int *)&selected->rawdata[ifpos]; - float sample = (ifpos >= 0 && ifpos < signed(patch.wavesize))? - x[0]/32768.0:0.0; - float sample1 = ((ifpos+2) >= 0 && (ifpos+2) < signed(patch.wavesize))? - x[1]/32768.0:0.0; - float error = fpos - (int)fpos; - outvalue[i] = sample * (1.0-error) + sample1 * error; - - fpos += step; - } - } - else - { - for(unsigned int i = 0; i < samples; i++) - outvalue[i] = 0.0; - } - } - - void clearDList() - { - selected = 0; - - } - - string filename() { return _filename; } - void filename(const string& newFile) - { - if(newFile == _filename) return; - - unload(); - pat = CachedPat::load(Cache::the(), newFile); - - _filename = newFile; - filename_changed(newFile); - } -}; - -REGISTER_IMPLEMENTATION(Synth_PLAY_PAT_impl); - -} diff --git a/arts/modules/synth/synth_play_pat_impl.cpp b/arts/modules/synth/synth_play_pat_impl.cpp new file mode 100644 index 00000000..7c2699f7 --- /dev/null +++ b/arts/modules/synth/synth_play_pat_impl.cpp @@ -0,0 +1,529 @@ +# /* + + Copyright (C) 2001 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "artsmodulessynth.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +namespace Arts { + +namespace PatchLoader { + typedef unsigned char byte; + typedef unsigned short int word; + typedef unsigned int dword; + typedef char sbyte; + typedef short int sword; + typedef int sdword; + + static int pos = 0; + static int apos = 0; + + inline void xRead(FILE *file, int len, void *data) + { + // printf("(0x%2x) - 0x%02x ... reading %d bytes\n",apos,pos,len); + pos += len; + apos += len; + if(fread(data, len, 1, file) != 1) + fprintf(stdout, "short read\n"); + } + + inline void skip(FILE *file, int len) + { + // printf("(0x%2x) - 0x%02x ... skipping %d bytes\n",apos,pos,len); + pos += len; + apos += len; + while(len > 0) + { + char junk; + if(fread(&junk, 1, 1, file) != 1) + fprintf(stdout, "short read\n"); + len--; + } + } + + + inline void readBytes(FILE *file, unsigned char *bytes, int len) + { + xRead(file, len, bytes); + } + + inline void readString(FILE *file, char *str, int len) + { + xRead(file, len, str); + } + + /* readXXX with sizeof(xxx) == 1 */ + inline void readByte(FILE *file, byte& b) + { + xRead(file, 1, &b); + } + + /* readXXX with sizeof(xxx) == 2 */ + inline void readWord(FILE *file, word& w) + { + byte h, l; + xRead(file, 1, &l); + xRead(file, 1, &h); + w = (h << 8) + l; + } + + inline void readSWord(FILE *file, sword& sw) + { + word w; + readWord(file, w); + sw = (sword)w; + } + + /* readXXX with sizeof(xxx) == 4 */ + inline void readDWord(FILE *file, dword& dw) + { + byte h, l, hh, hl; + xRead(file, 1, &l); + xRead(file, 1, &h); + xRead(file, 1, &hl); + xRead(file, 1, &hh); + dw = (hh << 24) + (hl << 16) + (h << 8) + l; + } + + struct PatHeader { + char id[12]; /* ID='GF1PATCH110' */ + char manufacturer_id[10]; /* Manufacturer ID */ + char description[60]; /* Description of the contained Instruments + or copyright of manufacturer. */ + byte instruments; /* Number of instruments in this patch */ + byte voices; /* Number of voices for sample */ + byte channels; /* Number of output channels + (1=mono,2=stereo) */ + word waveforms; /* Number of waveforms */ + word mastervolume; /* Master volume for all samples */ + dword size; /* Size of the following data */ + char reserved[36]; /* reserved */ + + PatHeader(FILE *file) + { + readString(file, id, 12); + readString(file, manufacturer_id, 10); + readString(file, description, 60); + /* skip(file, 2);*/ + + readByte(file, instruments); + readByte(file, voices); + readByte(file, channels); + + readWord(file, waveforms); + readWord(file, mastervolume); + readDWord(file, size); + + readString(file, reserved, 36); + } + }; + + struct PatInstrument { + word number; + char name[16]; + dword size; /* Size of the whole instrument in bytes. */ + byte layers; + char reserved[40]; + + /* layer? */ + word layerUnknown; + dword layerSize; + byte sampleCount; /* number of samples in this layer (?) */ + char layerReserved[40]; + + PatInstrument(FILE *file) + { + readWord(file, number); + readString(file, name, 16); + readDWord(file, size); + readByte(file, layers); + readString(file, reserved, 40); + + /* layer: (?) */ + readWord(file, layerUnknown); + readDWord(file, layerSize); + readByte(file, sampleCount); + readString(file, reserved, 40); + } + }; + + struct PatPatch { + char filename[7]; /* Wave file name */ + byte fractions; /* Fractions */ + dword wavesize; /* Wave size. + Size of the wave digital data */ + dword loopStart; + dword loopEnd; + word sampleRate; + dword minFreq; + dword maxFreq; + dword origFreq; + sword fineTune; + byte balance; + byte filterRate[6]; + byte filterOffset[6]; + byte tremoloSweep; + byte tremoloRate; + byte tremoloDepth; + byte vibratoSweep; + byte vibratoRate; + byte vibratoDepth; + byte waveFormat; + sword freqScale; + word freqScaleFactor; + char reserved[36]; + + PatPatch(FILE *file) + { + readString(file, filename, 7); + readByte(file, fractions); + readDWord(file, wavesize); + readDWord(file, loopStart); + readDWord(file, loopEnd); + readWord(file, sampleRate); + readDWord(file, minFreq); + readDWord(file, maxFreq); + readDWord(file, origFreq); + readSWord(file, fineTune); + readByte(file, balance); + readBytes(file, filterRate, 6); + readBytes(file, filterOffset, 6); + readByte(file, tremoloSweep); + readByte(file, tremoloRate); + readByte(file, tremoloDepth); + readByte(file, vibratoSweep); + readByte(file, vibratoRate); + readByte(file, vibratoDepth); + readByte(file, waveFormat); + readSWord(file, freqScale); + readWord(file, freqScaleFactor); + readString(file, reserved, 36); + } + }; +} + +class CachedPat : public CachedObject +{ +protected: + struct stat oldstat; + string filename; + bool initOk; + long dataSize; + + CachedPat(Cache *cache, const string& filename); + ~CachedPat(); + +public: + + struct Data { + PatchLoader::PatPatch patch; + mcopbyte *rawdata; + Data(FILE *file) + : patch(file) + { + rawdata = new mcopbyte[patch.wavesize]; + fread(rawdata, 1, patch.wavesize, file); + + // sign conversion only for 16bit! + if(patch.waveFormat & (1 << 1)) + { + for(unsigned int i = 1; i < patch.wavesize; i+=2) + rawdata[i] ^= 0x80; + } + + // unfold ping-pong loops + if(patch.waveFormat & (1 << 3)) + { + int looplen = patch.loopEnd - patch.loopStart; + arts_assert(looplen > 0); + + mcopbyte *newdata = new mcopbyte[patch.wavesize + looplen]; + + // copy head + memcpy(&newdata[0], &rawdata[0], patch.loopStart + looplen); + + // 16 bit unfolding only: + for(int i=0; i dList; + + static CachedPat *load(Cache *cache, const string& filename); + /** + * validity test for the cache - returns false if the object is having + * reflecting the correct contents anymore (e.g. if the file on the + * disk has changed), and there is no point in keeping it in the cache any + * longer + */ + bool isValid(); + /** + * memory usage for the cache + */ + int memoryUsage(); +}; + +CachedPat *CachedPat::load(Cache *cache, const string& filename) +{ + CachedPat *pat; + + pat = (CachedPat *)cache->get(string("CachedPat:")+filename); + if(!pat) { + pat = new CachedPat(cache, filename); + + if(!pat->initOk) // loading failed + { + pat->decRef(); + return 0; + } + } + + return pat; +} + +bool CachedPat::isValid() +{ + if(!initOk) + return false; + + struct stat newstat; + + lstat(filename.c_str(),&newstat); + return(newstat.st_mtime == oldstat.st_mtime); +} + +int CachedPat::memoryUsage() +{ + return dataSize; +} + +CachedPat::CachedPat(Cache *cache, const string& filename) + : CachedObject(cache), filename(filename), initOk(false), dataSize(0) +{ + setKey(string("CachedPat:")+filename); + + if(lstat(filename.c_str(),&oldstat) == -1) + { + arts_info("CachedPat: Can't stat file '%s'", filename.c_str()); + return; + } + + FILE *patfile = fopen(filename.c_str(), "r"); + if(patfile) + { + //PatchLoader::PatHeader header(patfile); + PatchLoader::PatInstrument ins(patfile); + + for(int i=0;ipatch.wavesize; + } + fclose(patfile); + + arts_debug("loaded pat %s",filename.c_str()); + arts_debug(" %d patches, datasize total is %d bytes", + ins.sampleCount, dataSize); + + initOk = true; + } +} + +CachedPat::~CachedPat() +{ + while(!dList.empty()) + { + delete dList.front(); + dList.pop_front(); + } +} + +class Synth_PLAY_PAT_impl : virtual public Synth_PLAY_PAT_skel, + virtual public StdSynthModule +{ +protected: + string _filename; + CachedPat *pat; + CachedPat::Data *selected; + float fpos; + +public: + Synth_PLAY_PAT_impl() + { + pat = 0; + selected = 0; + } + + void unload() + { + if(pat) + { + pat->decRef(); + pat = 0; + } + } + + ~Synth_PLAY_PAT_impl() + { + unload(); + } + + void streamStart() + { + fpos = 0.0; + selected = 0; + } + + void calculateBlock(unsigned long samples) + { + /* the normal offset is 60 + 60 = 12*5 + so we scale with 2^5 = 32 + */ + float freq = frequency[0]; /* * 32.0 / 2.0; * why /2.0? */ + int ifreq = (int)(freq * 1024.0); + if(!selected && pat) + { + int bestdiff = 20000 * 1024; + + list::iterator i; + for(i = pat->dList.begin(); i != pat->dList.end(); i++) + { + int diff = ::abs(double(ifreq - (*i)->patch.origFreq)); + if(diff < bestdiff) + { + selected = *i; + bestdiff = diff; + } + } + + /* drums */ + if(selected && selected->patch.freqScaleFactor == 0) + ifreq = selected->patch.origFreq; + } + if(selected) + { + const PatchLoader::PatPatch& patch = selected->patch; + + /* + * thats just a *guess*, I have no idea how tuning actually + * should work + */ +#if 0 + float tonetune = float(pat.fineTune)/float(pat.freqScaleFactor); + float tuning = pow(2.0, tonetune/12.0); + freq *= tuning; +#endif + //printf("tonetune: %f\n",tonetune); + //printf("tuning: %f\n",tuning); + + float step = double(patch.sampleRate)/samplingRateFloat * + float(ifreq) / float(patch.origFreq); + for(unsigned int i = 0; i < samples; i++) + { + // ASSUME 16bit signed, native byte order + int ifpos = int(fpos)*2; + + // looped? bidi? backw? + if((patch.waveFormat & ((1 << 2) + (1 << 3) + (1 << 4))) + == (1 << 2)) + { + while(ifpos >= signed(patch.loopEnd)) + { + ifpos -= (patch.loopEnd - patch.loopStart); + fpos -= (patch.loopEnd - patch.loopStart)/2; + } + } + + short int *x = (short int *)&selected->rawdata[ifpos]; + float sample = (ifpos >= 0 && ifpos < signed(patch.wavesize))? + x[0]/32768.0:0.0; + float sample1 = ((ifpos+2) >= 0 && (ifpos+2) < signed(patch.wavesize))? + x[1]/32768.0:0.0; + float error = fpos - (int)fpos; + outvalue[i] = sample * (1.0-error) + sample1 * error; + + fpos += step; + } + } + else + { + for(unsigned int i = 0; i < samples; i++) + outvalue[i] = 0.0; + } + } + + void clearDList() + { + selected = 0; + + } + + string filename() { return _filename; } + void filename(const string& newFile) + { + if(newFile == _filename) return; + + unload(); + pat = CachedPat::load(Cache::the(), newFile); + + _filename = newFile; + filename_changed(newFile); + } +}; + +REGISTER_IMPLEMENTATION(Synth_PLAY_PAT_impl); + +} diff --git a/arts/modules/synth/synth_pscale_impl.cc b/arts/modules/synth/synth_pscale_impl.cc deleted file mode 100644 index 72298397..00000000 --- a/arts/modules/synth/synth_pscale_impl.cc +++ /dev/null @@ -1,53 +0,0 @@ -/* - - Copyright (C) 2000 Jeff Tranter - tranter@pobox.com - - (C) 1999 Stefan Westerfeld - stefan@space.twc.de - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - */ - -#include "artsmodulessynth.h" -#include "stdsynthmodule.h" - -using namespace Arts; - -class Synth_PSCALE_impl : virtual public Synth_PSCALE_skel, - virtual public StdSynthModule -{ -protected: - float _top; - -public: - float top() { return _top; } - void top(float newTop) { _top = newTop; } - - void calculateBlock(unsigned long samples) - { - for (unsigned int i=0; i < samples; i++) - { - if (pos[i] >= _top) - outvalue[i] = invalue[i] * (1 - pos[i])/(1 - _top); - else - outvalue[i] = invalue[i] * pos[i] / _top; - } - } - -}; - -REGISTER_IMPLEMENTATION(Synth_PSCALE_impl); diff --git a/arts/modules/synth/synth_pscale_impl.cpp b/arts/modules/synth/synth_pscale_impl.cpp new file mode 100644 index 00000000..72298397 --- /dev/null +++ b/arts/modules/synth/synth_pscale_impl.cpp @@ -0,0 +1,53 @@ +/* + + Copyright (C) 2000 Jeff Tranter + tranter@pobox.com + + (C) 1999 Stefan Westerfeld + stefan@space.twc.de + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + */ + +#include "artsmodulessynth.h" +#include "stdsynthmodule.h" + +using namespace Arts; + +class Synth_PSCALE_impl : virtual public Synth_PSCALE_skel, + virtual public StdSynthModule +{ +protected: + float _top; + +public: + float top() { return _top; } + void top(float newTop) { _top = newTop; } + + void calculateBlock(unsigned long samples) + { + for (unsigned int i=0; i < samples; i++) + { + if (pos[i] >= _top) + outvalue[i] = invalue[i] * (1 - pos[i])/(1 - _top); + else + outvalue[i] = invalue[i] * pos[i] / _top; + } + } + +}; + +REGISTER_IMPLEMENTATION(Synth_PSCALE_impl); diff --git a/arts/modules/synth/synth_rc_impl.cc b/arts/modules/synth/synth_rc_impl.cc deleted file mode 100644 index 12b30260..00000000 --- a/arts/modules/synth/synth_rc_impl.cc +++ /dev/null @@ -1,110 +0,0 @@ -/* - - Copyright (C) 2000 Jeff Tranter - tranter@pobox.com - - (C) 1999 Stefan Westerfeld - stefan@space.twc.de - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - */ - -#include -#include "artsmodulessynth.h" -#include "stdsynthmodule.h" - -using namespace Arts; - -class Synth_RC_impl : virtual public Synth_RC_skel, - virtual public StdSynthModule -{ -protected: - float _b, _f; - float B, dB; - float F, dF, oF, oU, U, Fsoll, Bsoll; - float oldvalue; - -public: - float b() { return _b; } - void b(float newB) { _b = newB; } - - float f() { return _f; } - void f(float newF) { _f = newF; } - - void streamInit() - { - oldvalue = 0; - B = 0; - F = 0; oF = 0; - U = 0; oU = 0; - } - - void calculateBlock(unsigned long samples) - { - unsigned long i, hits; - const float zero_lower = -0.00000001; - const float zero_upper = 0.00000001; - - if (zero_lower < invalue[0] && invalue[0] < zero_upper) - { - /* for comments see equalizer.cc/Synth_STD_EQUALIZER implementation */ - - /* - * This implementation differs from the implementation there, - * because it is done as a kind of powersafing. If no input is - * found, then no output is generated. - */ - if (zero_lower < oldvalue && oldvalue < zero_upper) - { - oldvalue = 0.0; - B = 0.0; - F = 0.0; oF = 0.0; - U = 0.0; oU = 0.0; - hits = 0; - for (i=0; i +#include "artsmodulessynth.h" +#include "stdsynthmodule.h" + +using namespace Arts; + +class Synth_RC_impl : virtual public Synth_RC_skel, + virtual public StdSynthModule +{ +protected: + float _b, _f; + float B, dB; + float F, dF, oF, oU, U, Fsoll, Bsoll; + float oldvalue; + +public: + float b() { return _b; } + void b(float newB) { _b = newB; } + + float f() { return _f; } + void f(float newF) { _f = newF; } + + void streamInit() + { + oldvalue = 0; + B = 0; + F = 0; oF = 0; + U = 0; oU = 0; + } + + void calculateBlock(unsigned long samples) + { + unsigned long i, hits; + const float zero_lower = -0.00000001; + const float zero_upper = 0.00000001; + + if (zero_lower < invalue[0] && invalue[0] < zero_upper) + { + /* for comments see equalizer.cpp/Synth_STD_EQUALIZER implementation */ + + /* + * This implementation differs from the implementation there, + * because it is done as a kind of powersafing. If no input is + * found, then no output is generated. + */ + if (zero_lower < oldvalue && oldvalue < zero_upper) + { + oldvalue = 0.0; + B = 0.0; + F = 0.0; oF = 0.0; + U = 0.0; oU = 0.0; + hits = 0; + for (i=0; i - 2003 Matthias Kretz - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License version 2 - as published by the Free Software Foundation. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -*/ - -#include -#include -#include "artsmodulessynth.h" -#include "stdsynthmodule.h" -#include - -using namespace std; -using namespace Arts; - -class Synth_SEQUENCE_FREQ_impl : virtual public Synth_SEQUENCE_FREQ_skel, - virtual public StdSynthModule -{ -protected: - float _speed; - string _seq; - long posn, delay; - float *fsequence; - float *slen; - -public: - Synth_SEQUENCE_FREQ_impl() - : _speed( 1 ) - , fsequence( 0 ) - , slen( 0 ) - { - } - - ~Synth_SEQUENCE_FREQ_impl() - { - delete[] fsequence; - delete[] slen; - } - - float speed() { return _speed; } - void speed(float newSpeed) { _speed = newSpeed; } - - string seq() { return _seq; } - void seq(const string &newSeq) - { - _seq = newSeq; - parseSeqString(); - } - - void parseSeqString() - { - delete[] fsequence; - delete[] slen; - - long bufferlen = _seq.length(); - fsequence = new float[ bufferlen ]; - slen = new float[ bufferlen ]; - - int i = 0; - int oldpos = 0; - int pos = _seq.find_first_of( ",;", 0 ); - arts_debug( "tokenizer: parse %s", _seq.c_str() ); - while( pos > 0 ) - { - string token = _seq.substr( oldpos, pos - oldpos ); - arts_debug( "tokenizer: pos = %d, oldpos = %d, token = %s", pos, oldpos, token.c_str() ); - handleToken( token, i++ ); - oldpos = pos + 1; - pos = _seq.find_first_of( ",;", oldpos ); - } - string token = _seq.substr( oldpos, _seq.length() - oldpos ); - arts_debug( "tokenizer: pos = %d, oldpos = %d, token = %s", pos, oldpos, token.c_str() ); - handleToken( token, i++ ); - fsequence[ i ] = -1.0; - } - - void handleToken( const string & token, int i ) - { - int colon = token.find( ':' ); - if( colon > -1 ) - { - slen[ i ] = atof( &token.c_str()[ colon + 1 ] ); - fsequence[ i ] = atof( token.substr( 0, colon ).c_str() ); - } - else - { - slen[ i ] = 1; - fsequence[ i ] = atof( token.c_str() ); - } - } - - void streamInit() - { - delay = 0; - posn = 0; - } - - void calculateBlock(unsigned long samples) - { - for (unsigned int i=0; i < samples; i++) - { - delay++; - if (delay > _speed * samplingRate * slen[posn]) - { - posn++; - if (fsequence[posn] == -1.0) - posn = 0; - delay = 0; - } - pos[i] = (int)delay / (_speed * samplingRate * slen[posn]); - frequency[i] = fsequence[posn]; - } - } - -}; - -REGISTER_IMPLEMENTATION(Synth_SEQUENCE_FREQ_impl); diff --git a/arts/modules/synth/synth_sequence_freq_impl.cpp b/arts/modules/synth/synth_sequence_freq_impl.cpp new file mode 100644 index 00000000..e3458d74 --- /dev/null +++ b/arts/modules/synth/synth_sequence_freq_impl.cpp @@ -0,0 +1,130 @@ +/* This file is part of the KDE project + Copyright (C) 2000 Jeff Tranter + 2003 Matthias Kretz + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +#include +#include +#include "artsmodulessynth.h" +#include "stdsynthmodule.h" +#include + +using namespace std; +using namespace Arts; + +class Synth_SEQUENCE_FREQ_impl : virtual public Synth_SEQUENCE_FREQ_skel, + virtual public StdSynthModule +{ +protected: + float _speed; + string _seq; + long posn, delay; + float *fsequence; + float *slen; + +public: + Synth_SEQUENCE_FREQ_impl() + : _speed( 1 ) + , fsequence( 0 ) + , slen( 0 ) + { + } + + ~Synth_SEQUENCE_FREQ_impl() + { + delete[] fsequence; + delete[] slen; + } + + float speed() { return _speed; } + void speed(float newSpeed) { _speed = newSpeed; } + + string seq() { return _seq; } + void seq(const string &newSeq) + { + _seq = newSeq; + parseSeqString(); + } + + void parseSeqString() + { + delete[] fsequence; + delete[] slen; + + long bufferlen = _seq.length(); + fsequence = new float[ bufferlen ]; + slen = new float[ bufferlen ]; + + int i = 0; + int oldpos = 0; + int pos = _seq.find_first_of( ",;", 0 ); + arts_debug( "tokenizer: parse %s", _seq.c_str() ); + while( pos > 0 ) + { + string token = _seq.substr( oldpos, pos - oldpos ); + arts_debug( "tokenizer: pos = %d, oldpos = %d, token = %s", pos, oldpos, token.c_str() ); + handleToken( token, i++ ); + oldpos = pos + 1; + pos = _seq.find_first_of( ",;", oldpos ); + } + string token = _seq.substr( oldpos, _seq.length() - oldpos ); + arts_debug( "tokenizer: pos = %d, oldpos = %d, token = %s", pos, oldpos, token.c_str() ); + handleToken( token, i++ ); + fsequence[ i ] = -1.0; + } + + void handleToken( const string & token, int i ) + { + int colon = token.find( ':' ); + if( colon > -1 ) + { + slen[ i ] = atof( &token.c_str()[ colon + 1 ] ); + fsequence[ i ] = atof( token.substr( 0, colon ).c_str() ); + } + else + { + slen[ i ] = 1; + fsequence[ i ] = atof( token.c_str() ); + } + } + + void streamInit() + { + delay = 0; + posn = 0; + } + + void calculateBlock(unsigned long samples) + { + for (unsigned int i=0; i < samples; i++) + { + delay++; + if (delay > _speed * samplingRate * slen[posn]) + { + posn++; + if (fsequence[posn] == -1.0) + posn = 0; + delay = 0; + } + pos[i] = (int)delay / (_speed * samplingRate * slen[posn]); + frequency[i] = fsequence[posn]; + } + } + +}; + +REGISTER_IMPLEMENTATION(Synth_SEQUENCE_FREQ_impl); diff --git a/arts/modules/synth/synth_sequence_impl.cc b/arts/modules/synth/synth_sequence_impl.cc deleted file mode 100644 index dc2588f5..00000000 --- a/arts/modules/synth/synth_sequence_impl.cc +++ /dev/null @@ -1,131 +0,0 @@ - /* - - Copyright (C) 2000 Jeff Tranter - tranter@pobox.com - - (C) 1999 Stefan Westerfeld - stefan@space.twc.de - - (C) 2003 Matthias Kretz - kretz@kde.org - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - */ - -#include -#include -#include -#include "artsmodulessynth.h" -#include "stdsynthmodule.h" - -using namespace std; -using namespace Arts; - -class Synth_SEQUENCE_impl : virtual public Synth_SEQUENCE_skel, - virtual public StdSynthModule -{ -protected: - float _speed; - string _seq; - long posn, delay; - float *fsequence; - float *slen; - -public: - Synth_SEQUENCE_impl() - : _speed( 1 ) - , fsequence( 0 ) - , slen( 0 ) - { - } - - ~Synth_SEQUENCE_impl() - { - delete [] fsequence; - delete [] slen; - } - - float speed() { return _speed; } - void speed(float newSpeed) { _speed = newSpeed; } - - string seq() { return _seq; } - void seq(const string &newSeq) { _seq = newSeq; } - - void streamInit() - { - char notea[][4]= {"C-", "C#", "D-", "D#", "E-", "F-", "F#", "G-", "G#", "A-", "A#-", "B-", "\0"}; - char noteb[][3]= {"C-", "Db", "D-", "Eb", "E-", "F-", "Gb", "G-", "Ab", "A-", "Bb", "B-", "\0"}; - float freq[] = {261.7,277.2,293.7,311.2,329.7,349.3,370.0,392.0,415.3,440.0, 466.2, 493.9, 0 }; - float zhoch[] = {1,2,4,8,16,32,64,128,256}; - int s = 0, i, oktave; - char *nptr; - float f; - char buffer[1024]; - - strncpy(buffer, _seq.c_str(), 1023); - buffer[ 1023 ] = '\0'; - long bufferlen = strlen(buffer); - delete[] fsequence; - delete[] slen; - fsequence = new float[ bufferlen ]; - slen = new float[ bufferlen ]; - nptr = strtok(buffer, ",;"); - while (nptr) - { - if (nptr[3] == ':') - slen[s] = atof(&nptr[4]); - else - slen[s] = 1; - fprintf(stderr," <%d> %s\n", s, nptr); - oktave = atol(&nptr[2]); - nptr[2] = 0; - f = 0; - for (i=0; notea[i][0]; i++) - if (strcmp(nptr,notea[i]) == 0) - f = freq[i]; - for (i=0; noteb[i][0]; i++) - if (strcmp(nptr, noteb[i]) == 0) - f = freq[i]; - f *= zhoch[oktave] / zhoch[4]; - fsequence[s++] = f; - fprintf(stderr, ">%2.2f\n", f); - nptr = strtok(NULL,",;"); - } - fsequence[s] = 0; - delay = 0; - posn = 0; - } - - void calculateBlock(unsigned long samples) - { - for (unsigned int i=0; i < samples; i++) - { - delay++; - if (delay > _speed * samplingRate * slen[posn]) - { - posn++; - if (fsequence[posn] == 0) - posn = 0; - delay = 0; - } - pos[i] = (int)delay / (_speed * samplingRate * slen[posn]); - frequency[i] = fsequence[posn]; - } - } - -}; - -REGISTER_IMPLEMENTATION(Synth_SEQUENCE_impl); diff --git a/arts/modules/synth/synth_sequence_impl.cpp b/arts/modules/synth/synth_sequence_impl.cpp new file mode 100644 index 00000000..dc2588f5 --- /dev/null +++ b/arts/modules/synth/synth_sequence_impl.cpp @@ -0,0 +1,131 @@ + /* + + Copyright (C) 2000 Jeff Tranter + tranter@pobox.com + + (C) 1999 Stefan Westerfeld + stefan@space.twc.de + + (C) 2003 Matthias Kretz + kretz@kde.org + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + */ + +#include +#include +#include +#include "artsmodulessynth.h" +#include "stdsynthmodule.h" + +using namespace std; +using namespace Arts; + +class Synth_SEQUENCE_impl : virtual public Synth_SEQUENCE_skel, + virtual public StdSynthModule +{ +protected: + float _speed; + string _seq; + long posn, delay; + float *fsequence; + float *slen; + +public: + Synth_SEQUENCE_impl() + : _speed( 1 ) + , fsequence( 0 ) + , slen( 0 ) + { + } + + ~Synth_SEQUENCE_impl() + { + delete [] fsequence; + delete [] slen; + } + + float speed() { return _speed; } + void speed(float newSpeed) { _speed = newSpeed; } + + string seq() { return _seq; } + void seq(const string &newSeq) { _seq = newSeq; } + + void streamInit() + { + char notea[][4]= {"C-", "C#", "D-", "D#", "E-", "F-", "F#", "G-", "G#", "A-", "A#-", "B-", "\0"}; + char noteb[][3]= {"C-", "Db", "D-", "Eb", "E-", "F-", "Gb", "G-", "Ab", "A-", "Bb", "B-", "\0"}; + float freq[] = {261.7,277.2,293.7,311.2,329.7,349.3,370.0,392.0,415.3,440.0, 466.2, 493.9, 0 }; + float zhoch[] = {1,2,4,8,16,32,64,128,256}; + int s = 0, i, oktave; + char *nptr; + float f; + char buffer[1024]; + + strncpy(buffer, _seq.c_str(), 1023); + buffer[ 1023 ] = '\0'; + long bufferlen = strlen(buffer); + delete[] fsequence; + delete[] slen; + fsequence = new float[ bufferlen ]; + slen = new float[ bufferlen ]; + nptr = strtok(buffer, ",;"); + while (nptr) + { + if (nptr[3] == ':') + slen[s] = atof(&nptr[4]); + else + slen[s] = 1; + fprintf(stderr," <%d> %s\n", s, nptr); + oktave = atol(&nptr[2]); + nptr[2] = 0; + f = 0; + for (i=0; notea[i][0]; i++) + if (strcmp(nptr,notea[i]) == 0) + f = freq[i]; + for (i=0; noteb[i][0]; i++) + if (strcmp(nptr, noteb[i]) == 0) + f = freq[i]; + f *= zhoch[oktave] / zhoch[4]; + fsequence[s++] = f; + fprintf(stderr, ">%2.2f\n", f); + nptr = strtok(NULL,",;"); + } + fsequence[s] = 0; + delay = 0; + posn = 0; + } + + void calculateBlock(unsigned long samples) + { + for (unsigned int i=0; i < samples; i++) + { + delay++; + if (delay > _speed * samplingRate * slen[posn]) + { + posn++; + if (fsequence[posn] == 0) + posn = 0; + delay = 0; + } + pos[i] = (int)delay / (_speed * samplingRate * slen[posn]); + frequency[i] = fsequence[posn]; + } + } + +}; + +REGISTER_IMPLEMENTATION(Synth_SEQUENCE_impl); diff --git a/arts/modules/synth/synth_shelve_cutoff_impl.cc b/arts/modules/synth/synth_shelve_cutoff_impl.cc deleted file mode 100644 index 01880b6c..00000000 --- a/arts/modules/synth/synth_shelve_cutoff_impl.cc +++ /dev/null @@ -1,71 +0,0 @@ -/* - - Copyright (C) 2000 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "artsmodulessynth.h" -#include "stdsynthmodule.h" -#include "c_filter_stuff.h" - -using namespace Arts; - -class Synth_SHELVE_CUTOFF_impl : virtual public Synth_SHELVE_CUTOFF_skel, - virtual public StdSynthModule -{ -protected: - filter f; -public: - void streamInit(); - void calculateBlock(unsigned long samples); -}; - -REGISTER_IMPLEMENTATION(Synth_SHELVE_CUTOFF_impl); - -void Synth_SHELVE_CUTOFF_impl::streamInit() -{ - initfilter(&f); -} - -void Synth_SHELVE_CUTOFF_impl::calculateBlock(unsigned long samples) -{ - float filterfrequency = frequency[0]; - - // the shelve-lowpass-filter is extremely sensitive to frequencies which - // are out of it's range (it produces NaN's then) so we'll be careful ;) - if(filterfrequency > 22000.0) filterfrequency = 22000.0; - if(filterfrequency < 1.0) filterfrequency = 1.0; - setfilter_shelvelowpass(&f,filterfrequency,80.0); - - unsigned long i; - - for(i=0;i 22000.0) filterfrequency = 22000.0; + if(filterfrequency < 1.0) filterfrequency = 1.0; + setfilter_shelvelowpass(&f,filterfrequency,80.0); + + unsigned long i; + + for(i=0;i -#include "artsmodulessynth.h" -#include "stdsynthmodule.h" - -using namespace Arts; - -class Synth_STD_EQUALIZER_impl : virtual public Synth_STD_EQUALIZER_skel, - virtual public StdSynthModule -{ -protected: - float _low, _mid, _high, _frequency, _q; - float tlow, tmid, thigh, tfrequency; - float a1, a2, b0, b1, b2, x_0, x_1, x_2, y_1, y_2; - unsigned long all; - -public: - float low() { return _low; } - void low(float newLow) - { - if(newLow != _low) - { - _low = newLow; - calcParameters(); - high_changed(newLow); - } - } - - - float mid() { return _mid; } - void mid(float newMid) - { - if(newMid != _mid) - { - _mid = newMid; - calcParameters(); - mid_changed(newMid); - } - } - - float high() { return _high; } - void high(float newHigh) - { - if(newHigh != _high) - { - _high = newHigh; - calcParameters(); - high_changed(newHigh); - } - } - - - float frequency() { return _frequency; } - void frequency(float newFrequency) - { - if(newFrequency != _frequency) - { - _frequency = newFrequency; - calcParameters(); - frequency_changed(newFrequency); - } - } - - float q() { return _q; } - void q(float newQ) - { - if(newQ != _q) - { - _q = newQ; - calcParameters(); - q_changed(newQ); - } - } - - Synth_STD_EQUALIZER_impl() { - _low = _mid = _high = 0; _q = 0.5; - _frequency = 300; - } - - void calcParameters() - { - /* - - * _low, _mid, _high are in dB, transform them to tlow, tmid, - * thigh using: - * -6dB => 0.5 ; 0dB => 1 ; 6dB = 2.0 ; ... - */ - - tlow = exp(_low * 0.115524530093324); // exp(p[LOW]*ln(2)/6) - tmid = exp(_mid * 0.115524530093324); - thigh = exp(_high * 0.115524530093324); - - // _frequency is given in Hz, we need the w-value (and do clipping if - // it exceeds SR/2) - const float SAMPLING_RATE = 44100.0; - tfrequency = _frequency; - if (tfrequency > SAMPLING_RATE / 2.01) - tfrequency = SAMPLING_RATE / 2.01; - float w = 2 * M_PI * tfrequency / SAMPLING_RATE; - - // Calculations: - float t = 1/tan(w/2); - float tq = t/_q; - float t2 = t*t; - - float a0 = 1+tq+t2; - float a0r = 1/a0; - - // and now the real filter values: - a1 = (2 - 2 * t2) * a0r; - a2 = (1 - tq + t2) * a0r; - b0 = (tlow + tmid * tq + thigh * t2) * a0r; - b1 = (2 * tlow -2 * thigh * t2) * a0r; - b2 = (tlow - tmid * tq + thigh * t2) * a0r; - - // TODO: try if we need that here, or if we can change filter - // coefficients without setting the state to 0 - x_0 = x_1 = x_2 = y_1 = y_2 = 0.0; - all = 0; - } - - void streamInit() - { - calcParameters(); - } - - void calculateBlock(unsigned long samples) - { - all += samples; - - if (all > 1024) - { - /* The _problem_: (observed on a PII-350) - * - * I am not quite sure what happens here, but it seems to be like that: - * - * If an ordinary signal (a mp3 for instance) is sent through the - * equalizer, and then no more input is given (zeros as input), - * the y_1 and y_2 values oscillate for some time, coming closer and - * close to zero. - * - * But before the reach zero, they reach the smallest negative number - * (or smallest positive, or whatever), and stay there - * (because 0.005*smallest_negative will remain smallest_negative). - * - * Since then, the CPU usage for all operations on these floats - * increases, (since handling of smallest_negative seems to be a rare - * case). - * - * The _fix_: - * - * We observe the value of y_1. If it's very close to zero (may be as - * well smallest_positive/smallest_negative), we set it to zero, - * together with y_2. This shouldn't significantly influence - * correctness of the filter, but effectively solves the problem. - * - * If you don't believe me, try without this fix and tell me what - * happens on your computer. - */ - const float zero_lower =-0.00000001; - const float zero_upper = 0.00000001; - all = 0; - - if(zero_lower < y_1 && y_1 < zero_upper) - y_1 = y_2 = 0.0; - } - - unsigned long i; - float tmp; - for (i=0; i +#include "artsmodulessynth.h" +#include "stdsynthmodule.h" + +using namespace Arts; + +class Synth_STD_EQUALIZER_impl : virtual public Synth_STD_EQUALIZER_skel, + virtual public StdSynthModule +{ +protected: + float _low, _mid, _high, _frequency, _q; + float tlow, tmid, thigh, tfrequency; + float a1, a2, b0, b1, b2, x_0, x_1, x_2, y_1, y_2; + unsigned long all; + +public: + float low() { return _low; } + void low(float newLow) + { + if(newLow != _low) + { + _low = newLow; + calcParameters(); + high_changed(newLow); + } + } + + + float mid() { return _mid; } + void mid(float newMid) + { + if(newMid != _mid) + { + _mid = newMid; + calcParameters(); + mid_changed(newMid); + } + } + + float high() { return _high; } + void high(float newHigh) + { + if(newHigh != _high) + { + _high = newHigh; + calcParameters(); + high_changed(newHigh); + } + } + + + float frequency() { return _frequency; } + void frequency(float newFrequency) + { + if(newFrequency != _frequency) + { + _frequency = newFrequency; + calcParameters(); + frequency_changed(newFrequency); + } + } + + float q() { return _q; } + void q(float newQ) + { + if(newQ != _q) + { + _q = newQ; + calcParameters(); + q_changed(newQ); + } + } + + Synth_STD_EQUALIZER_impl() { + _low = _mid = _high = 0; _q = 0.5; + _frequency = 300; + } + + void calcParameters() + { + /* + + * _low, _mid, _high are in dB, transform them to tlow, tmid, + * thigh using: + * -6dB => 0.5 ; 0dB => 1 ; 6dB = 2.0 ; ... + */ + + tlow = exp(_low * 0.115524530093324); // exp(p[LOW]*ln(2)/6) + tmid = exp(_mid * 0.115524530093324); + thigh = exp(_high * 0.115524530093324); + + // _frequency is given in Hz, we need the w-value (and do clipping if + // it exceeds SR/2) + const float SAMPLING_RATE = 44100.0; + tfrequency = _frequency; + if (tfrequency > SAMPLING_RATE / 2.01) + tfrequency = SAMPLING_RATE / 2.01; + float w = 2 * M_PI * tfrequency / SAMPLING_RATE; + + // Calculations: + float t = 1/tan(w/2); + float tq = t/_q; + float t2 = t*t; + + float a0 = 1+tq+t2; + float a0r = 1/a0; + + // and now the real filter values: + a1 = (2 - 2 * t2) * a0r; + a2 = (1 - tq + t2) * a0r; + b0 = (tlow + tmid * tq + thigh * t2) * a0r; + b1 = (2 * tlow -2 * thigh * t2) * a0r; + b2 = (tlow - tmid * tq + thigh * t2) * a0r; + + // TODO: try if we need that here, or if we can change filter + // coefficients without setting the state to 0 + x_0 = x_1 = x_2 = y_1 = y_2 = 0.0; + all = 0; + } + + void streamInit() + { + calcParameters(); + } + + void calculateBlock(unsigned long samples) + { + all += samples; + + if (all > 1024) + { + /* The _problem_: (observed on a PII-350) + * + * I am not quite sure what happens here, but it seems to be like that: + * + * If an ordinary signal (a mp3 for instance) is sent through the + * equalizer, and then no more input is given (zeros as input), + * the y_1 and y_2 values oscillate for some time, coming closer and + * close to zero. + * + * But before the reach zero, they reach the smallest negative number + * (or smallest positive, or whatever), and stay there + * (because 0.005*smallest_negative will remain smallest_negative). + * + * Since then, the CPU usage for all operations on these floats + * increases, (since handling of smallest_negative seems to be a rare + * case). + * + * The _fix_: + * + * We observe the value of y_1. If it's very close to zero (may be as + * well smallest_positive/smallest_negative), we set it to zero, + * together with y_2. This shouldn't significantly influence + * correctness of the filter, but effectively solves the problem. + * + * If you don't believe me, try without this fix and tell me what + * happens on your computer. + */ + const float zero_lower =-0.00000001; + const float zero_upper = 0.00000001; + all = 0; + + if(zero_lower < y_1 && y_1 < zero_upper) + y_1 = y_2 = 0.0; + } + + unsigned long i; + float tmp; + for (i=0; i -#include "artsmodulessynth.h" -#include "stdsynthmodule.h" - -using namespace Arts; - -// The tremolo module modulates the amplitude according to a LFO-Wave. -// Traditionally you would use a sine wave but why limit yourself? -// What you get is a very intense effect that cuts through most -// arrangements because of its high dynamic range. The tremolo effect -// is still one of guitarists favorite effects although it's not as -// popular as in the 1960's. - -class Synth_TREMOLO_impl : virtual public Synth_TREMOLO_skel, - virtual public StdSynthModule -{ -public: - void calculateBlock(unsigned long samples) - { - unsigned long i; - for(i=0; i +#include "artsmodulessynth.h" +#include "stdsynthmodule.h" + +using namespace Arts; + +// The tremolo module modulates the amplitude according to a LFO-Wave. +// Traditionally you would use a sine wave but why limit yourself? +// What you get is a very intense effect that cuts through most +// arrangements because of its high dynamic range. The tremolo effect +// is still one of guitarists favorite effects although it's not as +// popular as in the 1960's. + +class Synth_TREMOLO_impl : virtual public Synth_TREMOLO_skel, + virtual public StdSynthModule +{ +public: + void calculateBlock(unsigned long samples) + { + unsigned long i; + for(i=0; i -#include "artsmodulessynth.h" -#include "stdsynthmodule.h" - -using namespace Arts; - -namespace Arts { - -// This is a sawtooth that has it's trough rounded off using a cosine -// wave. - -class Synth_WAVE_SOFTSAW_impl : virtual public Synth_WAVE_SOFTSAW_skel, - virtual public StdSynthModule -{ -public: - void calculateBlock(unsigned long cycles) - { - for(unsigned long i=0; i 0.9)) - outvalue[i] = 1 - pos[i] * 2; - else - outvalue[i] = cos(pos[i]*2*M_PI); - } -}; - -REGISTER_IMPLEMENTATION(Synth_WAVE_SOFTSAW_impl); - -} diff --git a/arts/modules/synth/synth_wave_softsaw_impl.cpp b/arts/modules/synth/synth_wave_softsaw_impl.cpp new file mode 100644 index 00000000..5765250d --- /dev/null +++ b/arts/modules/synth/synth_wave_softsaw_impl.cpp @@ -0,0 +1,50 @@ + /* + + Copyright (C) 2000 Jeff Tranter + tranter@pobox.com + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include +#include "artsmodulessynth.h" +#include "stdsynthmodule.h" + +using namespace Arts; + +namespace Arts { + +// This is a sawtooth that has it's trough rounded off using a cosine +// wave. + +class Synth_WAVE_SOFTSAW_impl : virtual public Synth_WAVE_SOFTSAW_skel, + virtual public StdSynthModule +{ +public: + void calculateBlock(unsigned long cycles) + { + for(unsigned long i=0; i 0.9)) + outvalue[i] = 1 - pos[i] * 2; + else + outvalue[i] = cos(pos[i]*2*M_PI); + } +}; + +REGISTER_IMPLEMENTATION(Synth_WAVE_SOFTSAW_impl); + +} diff --git a/arts/modules/synth/synth_wave_square_impl.cc b/arts/modules/synth/synth_wave_square_impl.cc deleted file mode 100644 index c5693b18..00000000 --- a/arts/modules/synth/synth_wave_square_impl.cc +++ /dev/null @@ -1,39 +0,0 @@ - /* - - Copyright (C) 2000 Jeff Tranter - tranter@pobox.com - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "artsmodulessynth.h" -#include "stdsynthmodule.h" - -using namespace Arts; - -class Synth_WAVE_SQUARE_impl : virtual public Synth_WAVE_SQUARE_skel, - virtual public StdSynthModule -{ -public: - void calculateBlock(unsigned long samples) - { - unsigned long i; - for(i=0;i -#include -#include -#include -#include -#include -#include -#include -#include - - -using namespace Arts; -using namespace std; - -namespace Arts { - -class ArtsBuilderLoader_impl : virtual public ArtsBuilderLoader_skel { -protected: - set sourceDirs; - - string lastDataVersion; - vector _traderEntries; - vector _modules; - -public: - Object loadObject(Arts::TraderOffer offer) - { - StructureDesc structureDesc; - - vector strseq; - - // load file - vector *filenames = offer.getProperty("File"); - if(filenames->size() == 1) - { - string& filename = filenames->front(); - arts_info("ArtsBuilderLoader: filename = %s", filename.c_str()); - - ifstream infile(filename.c_str()); - string line; - while(getline(infile,line)) strseq.push_back(line); - } - delete filenames; - - structureDesc.loadFromList(strseq); - if(structureDesc.name() != offer.interfaceName()) - { - arts_warning("failed (name = %s).",structureDesc.name().c_str()); - return Object::null(); - } - - StructureBuilder builder; - builder.addFactory(LocalFactory()); - - return builder.createObject(structureDesc); - } - - vector *listFiles(const string& pathname, const char *extension) - { - vector *result = new vector(); - - unsigned long extlen = strlen(extension); - DIR *dir = opendir(pathname.c_str()); - if(dir != 0) - { - struct dirent *de; - while((de = readdir(dir)) != 0) - { - if(strlen(de->d_name) > extlen && - strncmp(&de->d_name[strlen(de->d_name)-extlen], - extension,extlen) == 0) - result->push_back(de->d_name); - } - closedir(dir); - } - return result; - } - - void collectInterfaces(const InterfaceDef& interface, - map& implemented) - { - if(!implemented[interface.name]) - { - implemented[interface.name] = true; - - vector::const_iterator ii; - for(ii = interface.inheritedInterfaces.begin(); - ii != interface.inheritedInterfaces.end(); ii++) - { - InterfaceDef id; - id = Dispatcher::the()->interfaceRepo().queryInterface(*ii); - collectInterfaces(id, implemented); - } - } - } - - string getInterfacesList(const InterfaceDef& interface) - { - map implemented; - map::iterator ii; - string result; - - collectInterfaces(interface, implemented); - - for(ii = implemented.begin(); ii != implemented.end(); ii++) - result += ii->first + ","; - result += "Arts::Object"; - return result; - } - - void scanArtsFile(const string& filename) - { - StructureDesc structureDesc; - vector strseq; - - // load file - { - ifstream infile(filename.c_str()); - string line; - int inmodule = 0; - - while(getline(infile,line)) - { - /* - * TODO - maybe there is a cleaner way? - * - * the following six lines are a bit hackish code to skip - * the module sections of the structures - * - * the problem with the module sections is this: - * we can't be sure that every module is known to the type - * system before we registered them with the type system, - * but as this code should be able to initially register .arts - * files with the type system, we can't rely that it has been - * done already (if we could, what would be the point of - * running this?) - */ - if(strncmp(line.c_str(), "module=", 7) == 0) - inmodule = 1; - - if(strncmp(line.c_str(), "{", 1) == 0 && inmodule == 1) - inmodule = 2; - - if(strncmp(line.c_str(), "}", 1) == 0 && inmodule == 2) - inmodule = 0; - - if(inmodule == 0) - strseq.push_back(line); - } - } - - structureDesc.loadFromList(strseq); - string name = structureDesc.name(); - - - arts_debug("%s [%s]\n",filename.c_str(),name.c_str()); - - /* add to _modules */ - StructureBuilder builder; - ModuleDef md = builder.createTypeInfo(structureDesc); - _modules.push_back(md); - - arts_assert(md.moduleName == name); - arts_assert(!md.interfaces.empty()); - - const InterfaceDef& id = md.interfaces.front(); - - /* add to _traderEntries */ - - TraderEntry entry; - entry.interfaceName = name; - entry.lines.push_back("Buildable=true"); - entry.lines.push_back("Interface="+getInterfacesList(id)); - entry.lines.push_back("Language=aRts"); - entry.lines.push_back("File="+filename); - - _traderEntries.push_back(entry); - /* - * TODO: more entries like - * Author="Stefan Westerfeld " - * URL="http://www.arts-project.org" - * License=... - */ - } - - void rescan() - { - lastDataVersion = dataVersion(); - - _traderEntries.clear(); - _modules.clear(); - - set::iterator si; - for(si = sourceDirs.begin(); si != sourceDirs.end(); si++) - { - vector *files = listFiles(*si, ".arts"); - vector::iterator i; - for(i = files->begin(); i != files->end(); i++) - scanArtsFile(*si + "/" +*i); - delete files; - } - } - - string dataVersion() - { - /* - * change this string if you change the loading algorithm to force - * rescanning even with the same data - */ - string result = "ArtsBuilderLoader:1.1:"; - - bool first = true; - - set::iterator i; - for(i = sourceDirs.begin(); i != sourceDirs.end(); i++) - { - const string& filename = *i; - - if(!first) result += ","; - first = false; - - struct stat st; - if( stat(filename.c_str(), &st) == 0 ) - { - char mtime[32]; - snprintf(mtime,sizeof(mtime),"[%.0f]",difftime(st.st_mtime, (time_t)0)); - result += filename + mtime; - } - else - result += filename + "[-1]"; - } - return result; - } - - vector *traderEntries() - { - if(dataVersion() != lastDataVersion) - rescan(); - - return new vector(_traderEntries); - } - - vector *modules() - { - if(dataVersion() != lastDataVersion) - rescan(); - - return new vector(_modules); - } - - ArtsBuilderLoader_impl() - { - sourceDirs.insert(EXAMPLES_DIR); - - const char *home = getenv("HOME"); - if(home) sourceDirs.insert(home+string("/arts/structures")); - } -}; - -REGISTER_IMPLEMENTATION(ArtsBuilderLoader_impl); -} diff --git a/arts/runtime/artsbuilderloader_impl.cpp b/arts/runtime/artsbuilderloader_impl.cpp new file mode 100644 index 00000000..238daae2 --- /dev/null +++ b/arts/runtime/artsbuilderloader_impl.cpp @@ -0,0 +1,285 @@ + /* + + Copyright (C) 2001 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "artsbuilder.h" +#include "debug.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +using namespace Arts; +using namespace std; + +namespace Arts { + +class ArtsBuilderLoader_impl : virtual public ArtsBuilderLoader_skel { +protected: + set sourceDirs; + + string lastDataVersion; + vector _traderEntries; + vector _modules; + +public: + Object loadObject(Arts::TraderOffer offer) + { + StructureDesc structureDesc; + + vector strseq; + + // load file + vector *filenames = offer.getProperty("File"); + if(filenames->size() == 1) + { + string& filename = filenames->front(); + arts_info("ArtsBuilderLoader: filename = %s", filename.c_str()); + + ifstream infile(filename.c_str()); + string line; + while(getline(infile,line)) strseq.push_back(line); + } + delete filenames; + + structureDesc.loadFromList(strseq); + if(structureDesc.name() != offer.interfaceName()) + { + arts_warning("failed (name = %s).",structureDesc.name().c_str()); + return Object::null(); + } + + StructureBuilder builder; + builder.addFactory(LocalFactory()); + + return builder.createObject(structureDesc); + } + + vector *listFiles(const string& pathname, const char *extension) + { + vector *result = new vector(); + + unsigned long extlen = strlen(extension); + DIR *dir = opendir(pathname.c_str()); + if(dir != 0) + { + struct dirent *de; + while((de = readdir(dir)) != 0) + { + if(strlen(de->d_name) > extlen && + strncmp(&de->d_name[strlen(de->d_name)-extlen], + extension,extlen) == 0) + result->push_back(de->d_name); + } + closedir(dir); + } + return result; + } + + void collectInterfaces(const InterfaceDef& interface, + map& implemented) + { + if(!implemented[interface.name]) + { + implemented[interface.name] = true; + + vector::const_iterator ii; + for(ii = interface.inheritedInterfaces.begin(); + ii != interface.inheritedInterfaces.end(); ii++) + { + InterfaceDef id; + id = Dispatcher::the()->interfaceRepo().queryInterface(*ii); + collectInterfaces(id, implemented); + } + } + } + + string getInterfacesList(const InterfaceDef& interface) + { + map implemented; + map::iterator ii; + string result; + + collectInterfaces(interface, implemented); + + for(ii = implemented.begin(); ii != implemented.end(); ii++) + result += ii->first + ","; + result += "Arts::Object"; + return result; + } + + void scanArtsFile(const string& filename) + { + StructureDesc structureDesc; + vector strseq; + + // load file + { + ifstream infile(filename.c_str()); + string line; + int inmodule = 0; + + while(getline(infile,line)) + { + /* + * TODO - maybe there is a cleaner way? + * + * the following six lines are a bit hackish code to skip + * the module sections of the structures + * + * the problem with the module sections is this: + * we can't be sure that every module is known to the type + * system before we registered them with the type system, + * but as this code should be able to initially register .arts + * files with the type system, we can't rely that it has been + * done already (if we could, what would be the point of + * running this?) + */ + if(strncmp(line.c_str(), "module=", 7) == 0) + inmodule = 1; + + if(strncmp(line.c_str(), "{", 1) == 0 && inmodule == 1) + inmodule = 2; + + if(strncmp(line.c_str(), "}", 1) == 0 && inmodule == 2) + inmodule = 0; + + if(inmodule == 0) + strseq.push_back(line); + } + } + + structureDesc.loadFromList(strseq); + string name = structureDesc.name(); + + + arts_debug("%s [%s]\n",filename.c_str(),name.c_str()); + + /* add to _modules */ + StructureBuilder builder; + ModuleDef md = builder.createTypeInfo(structureDesc); + _modules.push_back(md); + + arts_assert(md.moduleName == name); + arts_assert(!md.interfaces.empty()); + + const InterfaceDef& id = md.interfaces.front(); + + /* add to _traderEntries */ + + TraderEntry entry; + entry.interfaceName = name; + entry.lines.push_back("Buildable=true"); + entry.lines.push_back("Interface="+getInterfacesList(id)); + entry.lines.push_back("Language=aRts"); + entry.lines.push_back("File="+filename); + + _traderEntries.push_back(entry); + /* + * TODO: more entries like + * Author="Stefan Westerfeld " + * URL="http://www.arts-project.org" + * License=... + */ + } + + void rescan() + { + lastDataVersion = dataVersion(); + + _traderEntries.clear(); + _modules.clear(); + + set::iterator si; + for(si = sourceDirs.begin(); si != sourceDirs.end(); si++) + { + vector *files = listFiles(*si, ".arts"); + vector::iterator i; + for(i = files->begin(); i != files->end(); i++) + scanArtsFile(*si + "/" +*i); + delete files; + } + } + + string dataVersion() + { + /* + * change this string if you change the loading algorithm to force + * rescanning even with the same data + */ + string result = "ArtsBuilderLoader:1.1:"; + + bool first = true; + + set::iterator i; + for(i = sourceDirs.begin(); i != sourceDirs.end(); i++) + { + const string& filename = *i; + + if(!first) result += ","; + first = false; + + struct stat st; + if( stat(filename.c_str(), &st) == 0 ) + { + char mtime[32]; + snprintf(mtime,sizeof(mtime),"[%.0f]",difftime(st.st_mtime, (time_t)0)); + result += filename + mtime; + } + else + result += filename + "[-1]"; + } + return result; + } + + vector *traderEntries() + { + if(dataVersion() != lastDataVersion) + rescan(); + + return new vector(_traderEntries); + } + + vector *modules() + { + if(dataVersion() != lastDataVersion) + rescan(); + + return new vector(_modules); + } + + ArtsBuilderLoader_impl() + { + sourceDirs.insert(EXAMPLES_DIR); + + const char *home = getenv("HOME"); + if(home) sourceDirs.insert(home+string("/arts/structures")); + } +}; + +REGISTER_IMPLEMENTATION(ArtsBuilderLoader_impl); +} diff --git a/arts/runtime/compatibility.cc b/arts/runtime/compatibility.cc deleted file mode 100644 index 72bed765..00000000 --- a/arts/runtime/compatibility.cc +++ /dev/null @@ -1,56 +0,0 @@ - /* - - Copyright (C) 1999 Stefan Westerfeld - stefan@space.twc.de - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - */ - -#include "compatibility.h" -#include "debug.h" -#include - -#undef DEBUG_COMPATIBILITY - -using namespace std; - -string Arts::OldFormatTranslator::newModuleName(const string& module) -{ -#ifdef DEBUG_COMPATIBILITY - arts_debug("COMPAT: %s", module.c_str()); -#endif - - if(module.substr(0,10) == "Interface_") return "Arts::"+module; - if(module.substr(0,6) == "Synth_") return "Arts::"+module; - return module; -} - -string Arts::OldFormatTranslator::newPortName(const string& module, const string& port) -{ -#ifdef DEBUG_COMPATIBILITY - arts_debug("COMPAT: %s.%s", module.c_str(), port.c_str()); -#endif - - if(module == "Arts::Synth_MUL") { - if(port == "invalue") return "invalue1"; - if(port == "faktor") return "invalue2"; - } - if(module == "Arts::Synth_ADD") { - if(port == "invalue") return "invalue1"; - if(port == "addit") return "invalue2"; - } - return port; -} diff --git a/arts/runtime/compatibility.cpp b/arts/runtime/compatibility.cpp new file mode 100644 index 00000000..72bed765 --- /dev/null +++ b/arts/runtime/compatibility.cpp @@ -0,0 +1,56 @@ + /* + + Copyright (C) 1999 Stefan Westerfeld + stefan@space.twc.de + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + */ + +#include "compatibility.h" +#include "debug.h" +#include + +#undef DEBUG_COMPATIBILITY + +using namespace std; + +string Arts::OldFormatTranslator::newModuleName(const string& module) +{ +#ifdef DEBUG_COMPATIBILITY + arts_debug("COMPAT: %s", module.c_str()); +#endif + + if(module.substr(0,10) == "Interface_") return "Arts::"+module; + if(module.substr(0,6) == "Synth_") return "Arts::"+module; + return module; +} + +string Arts::OldFormatTranslator::newPortName(const string& module, const string& port) +{ +#ifdef DEBUG_COMPATIBILITY + arts_debug("COMPAT: %s.%s", module.c_str(), port.c_str()); +#endif + + if(module == "Arts::Synth_MUL") { + if(port == "invalue") return "invalue1"; + if(port == "faktor") return "invalue2"; + } + if(module == "Arts::Synth_ADD") { + if(port == "invalue") return "invalue1"; + if(port == "addit") return "invalue2"; + } + return port; +} diff --git a/arts/runtime/localfactory_impl.cc b/arts/runtime/localfactory_impl.cc deleted file mode 100644 index bf55271c..00000000 --- a/arts/runtime/localfactory_impl.cc +++ /dev/null @@ -1,15 +0,0 @@ -#include "artsbuilder.h" - -using namespace Arts; -using namespace std; - -class LocalFactory_impl : virtual public LocalFactory_skel { -public: - Object createObject(const string& name) - { - return SubClass(name); - } -}; - -REGISTER_IMPLEMENTATION(LocalFactory_impl); - diff --git a/arts/runtime/localfactory_impl.cpp b/arts/runtime/localfactory_impl.cpp new file mode 100644 index 00000000..bf55271c --- /dev/null +++ b/arts/runtime/localfactory_impl.cpp @@ -0,0 +1,15 @@ +#include "artsbuilder.h" + +using namespace Arts; +using namespace std; + +class LocalFactory_impl : virtual public LocalFactory_skel { +public: + Object createObject(const string& name) + { + return SubClass(name); + } +}; + +REGISTER_IMPLEMENTATION(LocalFactory_impl); + diff --git a/arts/runtime/moduleinfo.cc b/arts/runtime/moduleinfo.cc deleted file mode 100644 index 7bef4464..00000000 --- a/arts/runtime/moduleinfo.cc +++ /dev/null @@ -1,106 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld - stefan@space.twc.de - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Permission is also granted to link this program with the TQt - library, treating TQt like a library that normally accompanies the - operating system kernel, whether or not that is in fact the case. - - */ - -#include "moduleinfo.h" - -using namespace std; - -static void gatherPorts(Arts::InterfaceDef& idef, Arts::ModuleInfo& minfo, - map& done) -{ - Arts::InterfaceRepo interfaceRepo=Arts::Dispatcher::the()->interfaceRepo(); - - vector::iterator ii = idef.inheritedInterfaces.begin(); - while(ii != idef.inheritedInterfaces.end()) - { - Arts::InterfaceDef inherited = interfaceRepo.queryInterface(*ii++); - gatherPorts(inherited,minfo,done); - } - - if(idef.name == "Arts::Object" || idef.name == "Arts::SynthModule") - { - // don't gather members of these basic interfaces as ports - return; - } - vector::iterator i; - for(i=idef.attributes.begin(); i != idef.attributes.end(); i++) - { - // 1 = direction, 10000 = connectiontype - long complete = 0; - Arts::PortType ptype; - - if(i->flags & Arts::streamIn) - { - ptype.direction = Arts::input; - complete += 1; - } - else if(i->flags & Arts::streamOut) - { - ptype.direction = Arts::output; - complete += 1; - } - - ptype.dataType = i->type; - - if(i->flags & Arts::attributeStream) - { - ptype.connType = Arts::conn_stream; - complete += 10000; - } - else if(i->flags & Arts::attributeAttribute) - { - ptype.connType = Arts::conn_property; - complete += 10000; - } - - ptype.isMultiPort = (i->flags & Arts::streamMulti); - - if(complete == 10001 && !done[i->name]) - { - minfo.portnames.push_back(i->name); - minfo.ports.push_back(ptype); - done[i->name] = true; - } - } -} - -Arts::ModuleInfo makeModuleInfo(const string& name) -{ - Arts::InterfaceRepo interfaceRepo=Arts::Dispatcher::the()->interfaceRepo(); - Arts::InterfaceDef idef = interfaceRepo.queryInterface(name); - Arts::ModuleInfo minfo; - - if(!idef.name.empty()) - { - map done; - minfo.name = name; - minfo.isStructure = false; - minfo.isInterface = false; - - gatherPorts(idef,minfo,done); - } - return minfo; -} - diff --git a/arts/runtime/moduleinfo.cpp b/arts/runtime/moduleinfo.cpp new file mode 100644 index 00000000..7bef4464 --- /dev/null +++ b/arts/runtime/moduleinfo.cpp @@ -0,0 +1,106 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Permission is also granted to link this program with the TQt + library, treating TQt like a library that normally accompanies the + operating system kernel, whether or not that is in fact the case. + + */ + +#include "moduleinfo.h" + +using namespace std; + +static void gatherPorts(Arts::InterfaceDef& idef, Arts::ModuleInfo& minfo, + map& done) +{ + Arts::InterfaceRepo interfaceRepo=Arts::Dispatcher::the()->interfaceRepo(); + + vector::iterator ii = idef.inheritedInterfaces.begin(); + while(ii != idef.inheritedInterfaces.end()) + { + Arts::InterfaceDef inherited = interfaceRepo.queryInterface(*ii++); + gatherPorts(inherited,minfo,done); + } + + if(idef.name == "Arts::Object" || idef.name == "Arts::SynthModule") + { + // don't gather members of these basic interfaces as ports + return; + } + vector::iterator i; + for(i=idef.attributes.begin(); i != idef.attributes.end(); i++) + { + // 1 = direction, 10000 = connectiontype + long complete = 0; + Arts::PortType ptype; + + if(i->flags & Arts::streamIn) + { + ptype.direction = Arts::input; + complete += 1; + } + else if(i->flags & Arts::streamOut) + { + ptype.direction = Arts::output; + complete += 1; + } + + ptype.dataType = i->type; + + if(i->flags & Arts::attributeStream) + { + ptype.connType = Arts::conn_stream; + complete += 10000; + } + else if(i->flags & Arts::attributeAttribute) + { + ptype.connType = Arts::conn_property; + complete += 10000; + } + + ptype.isMultiPort = (i->flags & Arts::streamMulti); + + if(complete == 10001 && !done[i->name]) + { + minfo.portnames.push_back(i->name); + minfo.ports.push_back(ptype); + done[i->name] = true; + } + } +} + +Arts::ModuleInfo makeModuleInfo(const string& name) +{ + Arts::InterfaceRepo interfaceRepo=Arts::Dispatcher::the()->interfaceRepo(); + Arts::InterfaceDef idef = interfaceRepo.queryInterface(name); + Arts::ModuleInfo minfo; + + if(!idef.name.empty()) + { + map done; + minfo.name = name; + minfo.isStructure = false; + minfo.isInterface = false; + + gatherPorts(idef,minfo,done); + } + return minfo; +} + diff --git a/arts/runtime/sequenceutils.cc b/arts/runtime/sequenceutils.cc deleted file mode 100644 index 335287d4..00000000 --- a/arts/runtime/sequenceutils.cc +++ /dev/null @@ -1,188 +0,0 @@ - /* - - Copyright (C) 1999 Stefan Westerfeld - stefan@space.twc.de - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - */ - -#include "sequenceutils.h" -#include -#include -#include - -using namespace std; - -#if 0 -void sqprintf(ArtsCorba::StringSeq *list, const char *fmt, ...) -{ - char p[1024]; - va_list ap; - va_start(ap, fmt); - (void) vsnprintf(p, 1024, fmt, ap); - va_end(ap); - - unsigned long len = list->length(); - list->length(len+1); - (*list)[len] = CORBA::string_dup(p); -} -#endif - -void sqprintf(vector *list, const char *fmt, ...) -{ - char p[1024]; - va_list ap; - va_start(ap, fmt); - (void) vsnprintf(p, 1024, fmt, ap); - va_end(ap); - - list->push_back(p); -} - -int parse_line(const char *in, char *& cmd, char *& param) -{ - int i,cmdlen=0,paramlen=0; - static char static_cmd[1000], static_param[1000]; - - cmd = static_cmd; - param = static_param; - i = 0; - - while(in[i] == ' ' || in[i] == '\t') i++; - - if(in[i] == 0) return(0); - - while(in[i] != '=' && in[i] != 0) cmd[cmdlen++] = in[i++]; - if(in[i] != 0) i++; - while(in[i] != 0) param[paramlen++] = in[i++]; - - cmd[cmdlen] = 0; - param[paramlen] = 0; - - if(paramlen) return(2); - if(cmdlen) return(1); - return(0); -} - -int parse_line(const string& in, string& cmd, string& param) -{ - char *ccmd, *cparam; - int result = parse_line(in.c_str(),ccmd,cparam); - param = cparam; - cmd = ccmd; - return result; -} - -#if 0 -void addSubStringSeq(ArtsCorba::StringSeq *target, ArtsCorba::StringSeq *source) -{ - unsigned long i; - - sqprintf(target,"{"); - for(i=0;ilength();i++) - { - unsigned long len = target->length(); - target->length(len+1); - string srcstring = string(" ") + string((*source)[i]); - (*target)[len] = CORBA::string_dup(srcstring.c_str()); - } - sqprintf(target,"}"); -} -#endif - -void addSubStringSeq(vector *target, const vector *source) -{ - sqprintf(target,"{"); - - vector::const_iterator i; - for(i=source->begin();i != source->end();i++) - target->push_back(" " + *i); - - sqprintf(target,"}"); -} - -#if 0 -void appendStringSeq(ArtsCorba::StringSeq *target, ArtsCorba::StringSeq *source) -{ - unsigned long i; - - for(i=0;ilength();i++) - { - unsigned long len = target->length(); - target->length(len+1); - (*target)[len] = CORBA::string_dup((*source)[i]); - } -} -#endif - -void appendStringSeq(vector *target, const vector *source) -{ - vector::const_iterator i; - for(i=source->begin();i != source->end();i++) - target->push_back(*i); -} - -#if 0 -ArtsCorba::StringSeq *getSubStringSeq(const ArtsCorba::StringSeq *seq,unsigned long& i) -{ - ArtsCorba::StringSeq *result = new ArtsCorba::StringSeq; - char empty[1] = {0}; - char *cmd = empty,*param; - - - while(strcmp(cmd,"{") && ilength()) - parse_line((*seq)[i++],cmd,param); - - int brackets = 1; - - while(ilength()) - { - parse_line((*seq)[i],cmd,param); - if(strcmp(cmd,"{") == 0) brackets++; - if(strcmp(cmd,"}") == 0) brackets--; - if(brackets == 0) return(result); - - unsigned long len = result->length(); - result->length(len+1); - (*result)[len] = CORBA::string_dup((*seq)[i]); - i++; - } - return(result); -} -#endif - -vector *getSubStringSeq(const vector *seq,unsigned long& i) -{ - vector *result = new vector; - string cmd = "",param; - - while(cmd != "{" && isize()) - parse_line((*seq)[i++],cmd,param); - - int brackets = 1; - - while(isize()) - { - parse_line((*seq)[i],cmd,param); - if(cmd == "{") brackets++; - if(cmd == "}") brackets--; - if(brackets == 0) return(result); - - result->push_back((*seq)[i]); - i++; - } - return result; -} diff --git a/arts/runtime/sequenceutils.cpp b/arts/runtime/sequenceutils.cpp new file mode 100644 index 00000000..335287d4 --- /dev/null +++ b/arts/runtime/sequenceutils.cpp @@ -0,0 +1,188 @@ + /* + + Copyright (C) 1999 Stefan Westerfeld + stefan@space.twc.de + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + */ + +#include "sequenceutils.h" +#include +#include +#include + +using namespace std; + +#if 0 +void sqprintf(ArtsCorba::StringSeq *list, const char *fmt, ...) +{ + char p[1024]; + va_list ap; + va_start(ap, fmt); + (void) vsnprintf(p, 1024, fmt, ap); + va_end(ap); + + unsigned long len = list->length(); + list->length(len+1); + (*list)[len] = CORBA::string_dup(p); +} +#endif + +void sqprintf(vector *list, const char *fmt, ...) +{ + char p[1024]; + va_list ap; + va_start(ap, fmt); + (void) vsnprintf(p, 1024, fmt, ap); + va_end(ap); + + list->push_back(p); +} + +int parse_line(const char *in, char *& cmd, char *& param) +{ + int i,cmdlen=0,paramlen=0; + static char static_cmd[1000], static_param[1000]; + + cmd = static_cmd; + param = static_param; + i = 0; + + while(in[i] == ' ' || in[i] == '\t') i++; + + if(in[i] == 0) return(0); + + while(in[i] != '=' && in[i] != 0) cmd[cmdlen++] = in[i++]; + if(in[i] != 0) i++; + while(in[i] != 0) param[paramlen++] = in[i++]; + + cmd[cmdlen] = 0; + param[paramlen] = 0; + + if(paramlen) return(2); + if(cmdlen) return(1); + return(0); +} + +int parse_line(const string& in, string& cmd, string& param) +{ + char *ccmd, *cparam; + int result = parse_line(in.c_str(),ccmd,cparam); + param = cparam; + cmd = ccmd; + return result; +} + +#if 0 +void addSubStringSeq(ArtsCorba::StringSeq *target, ArtsCorba::StringSeq *source) +{ + unsigned long i; + + sqprintf(target,"{"); + for(i=0;ilength();i++) + { + unsigned long len = target->length(); + target->length(len+1); + string srcstring = string(" ") + string((*source)[i]); + (*target)[len] = CORBA::string_dup(srcstring.c_str()); + } + sqprintf(target,"}"); +} +#endif + +void addSubStringSeq(vector *target, const vector *source) +{ + sqprintf(target,"{"); + + vector::const_iterator i; + for(i=source->begin();i != source->end();i++) + target->push_back(" " + *i); + + sqprintf(target,"}"); +} + +#if 0 +void appendStringSeq(ArtsCorba::StringSeq *target, ArtsCorba::StringSeq *source) +{ + unsigned long i; + + for(i=0;ilength();i++) + { + unsigned long len = target->length(); + target->length(len+1); + (*target)[len] = CORBA::string_dup((*source)[i]); + } +} +#endif + +void appendStringSeq(vector *target, const vector *source) +{ + vector::const_iterator i; + for(i=source->begin();i != source->end();i++) + target->push_back(*i); +} + +#if 0 +ArtsCorba::StringSeq *getSubStringSeq(const ArtsCorba::StringSeq *seq,unsigned long& i) +{ + ArtsCorba::StringSeq *result = new ArtsCorba::StringSeq; + char empty[1] = {0}; + char *cmd = empty,*param; + + + while(strcmp(cmd,"{") && ilength()) + parse_line((*seq)[i++],cmd,param); + + int brackets = 1; + + while(ilength()) + { + parse_line((*seq)[i],cmd,param); + if(strcmp(cmd,"{") == 0) brackets++; + if(strcmp(cmd,"}") == 0) brackets--; + if(brackets == 0) return(result); + + unsigned long len = result->length(); + result->length(len+1); + (*result)[len] = CORBA::string_dup((*seq)[i]); + i++; + } + return(result); +} +#endif + +vector *getSubStringSeq(const vector *seq,unsigned long& i) +{ + vector *result = new vector; + string cmd = "",param; + + while(cmd != "{" && isize()) + parse_line((*seq)[i++],cmd,param); + + int brackets = 1; + + while(isize()) + { + parse_line((*seq)[i],cmd,param); + if(cmd == "{") brackets++; + if(cmd == "}") brackets--; + if(brackets == 0) return(result); + + result->push_back((*seq)[i]); + i++; + } + return result; +} diff --git a/arts/runtime/structurebuilder_impl.cc b/arts/runtime/structurebuilder_impl.cc deleted file mode 100644 index 43e5485c..00000000 --- a/arts/runtime/structurebuilder_impl.cc +++ /dev/null @@ -1,347 +0,0 @@ - /* - - Copyright (C) 2000,2001 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "artsbuilder.h" -#include "artsflow.h" -#include "connect.h" -#include "debug.h" -#include "flowsystem.h" -#include "stdsynthmodule.h" -#include "dynamicrequest.h" -#include "dynamicskeleton.h" -#include "startupmanager.h" -#include - -//#define STRUCTBUILDER_DEBUG 1 - -using namespace Arts; -using namespace std; - -class StructureBuilder_impl : virtual public StructureBuilder_skel { -protected: - list factories; -public: - void addFactory(ObjectFactory factory); - Object createObject(StructureDesc structure); - ModuleDef createTypeInfo(StructureDesc structure); -}; - -REGISTER_IMPLEMENTATION(StructureBuilder_impl); - -typedef DynamicSkeleton SynthModule_dskel; - -class Structure_impl : virtual public SynthModule_dskel, - virtual public StdSynthModule { -protected: - list structureObjects; - - struct ForwardMethod { - string method; - Object destObject; - string destMethod; - }; - - list forwardMethods; - -public: - Structure_impl(StructureDesc structure, list& factories); - void streamInit(); - void streamEnd(); - - void process(long methodID, Buffer *request, Buffer *result); -}; - -void StructureBuilder_impl::addFactory(ObjectFactory factory) -{ - factories.push_back(factory); -} - -ModuleDef StructureBuilder_impl::createTypeInfo(StructureDesc structure) -{ - ModuleDef md; - InterfaceDef id; - -/* convert structure to InterfaceDef id */ - md.moduleName = id.name = structure.name(); - id.inheritedInterfaces.push_back("Arts::SynthModule"); - - vector *otherInterfaces = structure.inheritedInterfaces(); - vector::iterator ii; - for(ii = otherInterfaces->begin(); ii != otherInterfaces->end(); ii++) - id.inheritedInterfaces.push_back(*ii); - delete otherInterfaces; - - vector *ports = structure.ports(); - vector::iterator pi; - for(pi = ports->begin(); pi != ports->end(); pi++) - { - const Arts::PortType& type = pi->type(); - - // if we inherited the port from a parent interface, we don't need to - // list it in our interface description - if(pi->inheritedInterface().empty()) - { - AttributeDef ad; - ad.name = pi->name(); - - // This is a little tricky, as input ports (which are bringing data - // from outside into the structure) are saved as output ports (and - // output ports as input ports). - ad.flags = AttributeType( - ((type.direction == input)?streamOut:streamIn) | - ((type.connType == conn_stream)?attributeStream:attributeAttribute) - ); - ad.type = type.dataType; - - id.attributes.push_back(ad); - } - } - delete ports; - - md.interfaces.push_back(id); - - return md; -} - -namespace Arts { -static class StructureBuilderCleanUp : public StartupClass { -public: - vector types; - void startup() { }; - void shutdown() { - vector::iterator i; - for(i = types.begin(); i != types.end(); i++) - Dispatcher::the()->interfaceRepo().removeModule(*i); - types.clear(); - } - virtual ~StructureBuilderCleanUp() {} -} structureBuilderCleanUp; -} - -Object StructureBuilder_impl::createObject(StructureDesc structure) -{ - ModuleDef md = createTypeInfo(structure); - - // FIXME: find some faster way of ensuring type consistency than creating - // the thing from scratch every time - structureBuilderCleanUp.types.push_back(Dispatcher::the()->interfaceRepo().insertModule(md)); - Object obj = Object::_from_base(new Structure_impl(structure, factories)); - return obj; -} - -Structure_impl::Structure_impl(StructureDesc structureDesc, - list& factories) - : SynthModule_dskel(structureDesc.name()) -{ - map moduleMap; - vector *modules = structureDesc.modules(); - vector::iterator mi; - - // create each object - for(mi = modules->begin(); mi != modules->end(); mi++) - { - ModuleDesc& md = *mi; - -#ifdef STRUCTBUILDER_DEBUG - cout << "create " << md.name() << endl; -#endif - Object o = Object::null(); //SubClass(md.name()); - - Object_skel *skel = 0; - skel = ObjectManager::the()->create(md.name()); - if(skel) o = Object::_from_base(skel); - -#ifdef STRUCTBUILDER_DEBUG - if(o.isNull()) cout << "no local creator for " << md.name() << endl; -#endif - list::iterator fi = factories.begin(); - while(o.isNull() && fi != factories.end()) - { - o = fi->createObject(md.name()); - fi++; - } - -#ifdef STRUCTBUILDER_DEBUG - if(o.isNull()) cout << "no remote creator for " << md.name() << endl; -#endif - assert(!o.isNull()); - moduleMap[md.ID()] = o; - structureObjects.push_back(o); - } - - // connect objects and set values - for(mi = modules->begin(); mi != modules->end(); mi++) - { - Object& object = moduleMap[mi->ID()]; - - vector *ports = mi->ports(); - vector::iterator pi; - - for(pi = ports->begin(); pi != ports->end(); pi++) - { - PortDesc& pd = *pi; - const Arts::PortType& ptype = pd.type(); - - if(pd.hasValue()) - { - // set values -#ifdef STRUCTBUILDER_DEBUG - cout << "value " << mi->name() << "." << pi->name() << endl; -#endif - - if(ptype.connType == conn_property) - { - DynamicRequest req(object); - req.method("_set_"+pi->name()); - req.param(pd.value()); - - bool requestOk = req.invoke(); - arts_assert(requestOk); - } - else - { - if(ptype.dataType == "float") - setValue(object,pi->name(),pd.floatValue()); - else - arts_warning("unexpected property type %s", - ptype.dataType.c_str()); - //setStringValue(object,pd.stringValue()); - } - } - else if(pd.isConnected() && ptype.direction == output) - { - // create connections - - vector *connections = pd.connections(); - vector::iterator ci; - - for(ci = connections->begin(); ci != connections->end(); ci++) - { - if(!ci->parent().isNull()) // structureport otherwise - { - Object& dest = moduleMap[ci->parent().ID()]; -#ifdef STRUCTBUILDER_DEBUG - cout << "connect " << mi->name() << "." << pi->name() - << " to " << ci->parent().name() - << "." << ci->name() << endl; -#endif - connect(object,pd.name(),dest,ci->name()); - } - } - delete connections; - } - } - delete ports; - } - delete modules; - - // create ports (should be done via dynamic impl class...) - - vector *ports = structureDesc.ports(); - vector::iterator pi; - - for(pi = ports->begin(); pi != ports->end(); pi++) - { - Arts::StructurePortDesc& pd = *pi; - if(pd.isConnected()) - { - // create connections - - vector *connections = pd.connections(); - vector::iterator ci; - - for(ci = connections->begin(); ci != connections->end(); ci++) - { - Object& dest = moduleMap[ci->parent().ID()]; -#ifdef STRUCTBUILDER_DEBUG - cout << "virtualize " << pi->name() - << " to " << ci->parent().name() << "." << ci->name() - << endl; -#endif - - _node()->virtualize(pd.name(),dest._node(),ci->name()); - - if(pd.type().connType == conn_property) - { - ForwardMethod fm; - fm.method = "_set_"+pd.name(); - fm.destObject = dest; - fm.destMethod = "_set_"+ci->name(); - forwardMethods.push_back(fm); - } - } - delete connections; - } - } - delete ports; -} - -void Structure_impl::streamInit() -{ - list::iterator i; - -#ifdef STRUCTBUILDER_DEBUG - cout << "vstructure: got streamInit()" << endl; -#endif - - for(i=structureObjects.begin(); i != structureObjects.end(); i++) - { - if(i->_base()->_isCompatibleWith("Arts::SynthModule")) - i->_node()->start(); - } -} - -void Structure_impl::streamEnd() -{ - list::iterator i; - -#ifdef STRUCTBUILDER_DEBUG - cout << "vstructure: got streamEnd()" << endl; -#endif - - for(i=structureObjects.begin(); i != structureObjects.end(); i++) - if(i->_base()->_isCompatibleWith("Arts::SynthModule")) - i->_node()->stop(); -} - -void Structure_impl::process(long methodID, Buffer *request, Buffer *result) -{ - const MethodDef& methodDef = getMethodDef(methodID); - - arts_debug("Structure_impl: got method, method ID=%ld name='%s'", - methodID, methodDef.name.c_str()); - - list::iterator fi; - for(fi = forwardMethods.begin(); fi != forwardMethods.end(); fi++) - { - if(fi->method == methodDef.name) - { - Any a; - a.type = methodDef.signature[0].type; - - while(request->remaining() > 0) - a.value.push_back(request->readByte()); - - DynamicRequest(fi->destObject).method(fi->destMethod).param(a).invoke(); - } - } -} diff --git a/arts/runtime/structurebuilder_impl.cpp b/arts/runtime/structurebuilder_impl.cpp new file mode 100644 index 00000000..43e5485c --- /dev/null +++ b/arts/runtime/structurebuilder_impl.cpp @@ -0,0 +1,347 @@ + /* + + Copyright (C) 2000,2001 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "artsbuilder.h" +#include "artsflow.h" +#include "connect.h" +#include "debug.h" +#include "flowsystem.h" +#include "stdsynthmodule.h" +#include "dynamicrequest.h" +#include "dynamicskeleton.h" +#include "startupmanager.h" +#include + +//#define STRUCTBUILDER_DEBUG 1 + +using namespace Arts; +using namespace std; + +class StructureBuilder_impl : virtual public StructureBuilder_skel { +protected: + list factories; +public: + void addFactory(ObjectFactory factory); + Object createObject(StructureDesc structure); + ModuleDef createTypeInfo(StructureDesc structure); +}; + +REGISTER_IMPLEMENTATION(StructureBuilder_impl); + +typedef DynamicSkeleton SynthModule_dskel; + +class Structure_impl : virtual public SynthModule_dskel, + virtual public StdSynthModule { +protected: + list structureObjects; + + struct ForwardMethod { + string method; + Object destObject; + string destMethod; + }; + + list forwardMethods; + +public: + Structure_impl(StructureDesc structure, list& factories); + void streamInit(); + void streamEnd(); + + void process(long methodID, Buffer *request, Buffer *result); +}; + +void StructureBuilder_impl::addFactory(ObjectFactory factory) +{ + factories.push_back(factory); +} + +ModuleDef StructureBuilder_impl::createTypeInfo(StructureDesc structure) +{ + ModuleDef md; + InterfaceDef id; + +/* convert structure to InterfaceDef id */ + md.moduleName = id.name = structure.name(); + id.inheritedInterfaces.push_back("Arts::SynthModule"); + + vector *otherInterfaces = structure.inheritedInterfaces(); + vector::iterator ii; + for(ii = otherInterfaces->begin(); ii != otherInterfaces->end(); ii++) + id.inheritedInterfaces.push_back(*ii); + delete otherInterfaces; + + vector *ports = structure.ports(); + vector::iterator pi; + for(pi = ports->begin(); pi != ports->end(); pi++) + { + const Arts::PortType& type = pi->type(); + + // if we inherited the port from a parent interface, we don't need to + // list it in our interface description + if(pi->inheritedInterface().empty()) + { + AttributeDef ad; + ad.name = pi->name(); + + // This is a little tricky, as input ports (which are bringing data + // from outside into the structure) are saved as output ports (and + // output ports as input ports). + ad.flags = AttributeType( + ((type.direction == input)?streamOut:streamIn) | + ((type.connType == conn_stream)?attributeStream:attributeAttribute) + ); + ad.type = type.dataType; + + id.attributes.push_back(ad); + } + } + delete ports; + + md.interfaces.push_back(id); + + return md; +} + +namespace Arts { +static class StructureBuilderCleanUp : public StartupClass { +public: + vector types; + void startup() { }; + void shutdown() { + vector::iterator i; + for(i = types.begin(); i != types.end(); i++) + Dispatcher::the()->interfaceRepo().removeModule(*i); + types.clear(); + } + virtual ~StructureBuilderCleanUp() {} +} structureBuilderCleanUp; +} + +Object StructureBuilder_impl::createObject(StructureDesc structure) +{ + ModuleDef md = createTypeInfo(structure); + + // FIXME: find some faster way of ensuring type consistency than creating + // the thing from scratch every time + structureBuilderCleanUp.types.push_back(Dispatcher::the()->interfaceRepo().insertModule(md)); + Object obj = Object::_from_base(new Structure_impl(structure, factories)); + return obj; +} + +Structure_impl::Structure_impl(StructureDesc structureDesc, + list& factories) + : SynthModule_dskel(structureDesc.name()) +{ + map moduleMap; + vector *modules = structureDesc.modules(); + vector::iterator mi; + + // create each object + for(mi = modules->begin(); mi != modules->end(); mi++) + { + ModuleDesc& md = *mi; + +#ifdef STRUCTBUILDER_DEBUG + cout << "create " << md.name() << endl; +#endif + Object o = Object::null(); //SubClass(md.name()); + + Object_skel *skel = 0; + skel = ObjectManager::the()->create(md.name()); + if(skel) o = Object::_from_base(skel); + +#ifdef STRUCTBUILDER_DEBUG + if(o.isNull()) cout << "no local creator for " << md.name() << endl; +#endif + list::iterator fi = factories.begin(); + while(o.isNull() && fi != factories.end()) + { + o = fi->createObject(md.name()); + fi++; + } + +#ifdef STRUCTBUILDER_DEBUG + if(o.isNull()) cout << "no remote creator for " << md.name() << endl; +#endif + assert(!o.isNull()); + moduleMap[md.ID()] = o; + structureObjects.push_back(o); + } + + // connect objects and set values + for(mi = modules->begin(); mi != modules->end(); mi++) + { + Object& object = moduleMap[mi->ID()]; + + vector *ports = mi->ports(); + vector::iterator pi; + + for(pi = ports->begin(); pi != ports->end(); pi++) + { + PortDesc& pd = *pi; + const Arts::PortType& ptype = pd.type(); + + if(pd.hasValue()) + { + // set values +#ifdef STRUCTBUILDER_DEBUG + cout << "value " << mi->name() << "." << pi->name() << endl; +#endif + + if(ptype.connType == conn_property) + { + DynamicRequest req(object); + req.method("_set_"+pi->name()); + req.param(pd.value()); + + bool requestOk = req.invoke(); + arts_assert(requestOk); + } + else + { + if(ptype.dataType == "float") + setValue(object,pi->name(),pd.floatValue()); + else + arts_warning("unexpected property type %s", + ptype.dataType.c_str()); + //setStringValue(object,pd.stringValue()); + } + } + else if(pd.isConnected() && ptype.direction == output) + { + // create connections + + vector *connections = pd.connections(); + vector::iterator ci; + + for(ci = connections->begin(); ci != connections->end(); ci++) + { + if(!ci->parent().isNull()) // structureport otherwise + { + Object& dest = moduleMap[ci->parent().ID()]; +#ifdef STRUCTBUILDER_DEBUG + cout << "connect " << mi->name() << "." << pi->name() + << " to " << ci->parent().name() + << "." << ci->name() << endl; +#endif + connect(object,pd.name(),dest,ci->name()); + } + } + delete connections; + } + } + delete ports; + } + delete modules; + + // create ports (should be done via dynamic impl class...) + + vector *ports = structureDesc.ports(); + vector::iterator pi; + + for(pi = ports->begin(); pi != ports->end(); pi++) + { + Arts::StructurePortDesc& pd = *pi; + if(pd.isConnected()) + { + // create connections + + vector *connections = pd.connections(); + vector::iterator ci; + + for(ci = connections->begin(); ci != connections->end(); ci++) + { + Object& dest = moduleMap[ci->parent().ID()]; +#ifdef STRUCTBUILDER_DEBUG + cout << "virtualize " << pi->name() + << " to " << ci->parent().name() << "." << ci->name() + << endl; +#endif + + _node()->virtualize(pd.name(),dest._node(),ci->name()); + + if(pd.type().connType == conn_property) + { + ForwardMethod fm; + fm.method = "_set_"+pd.name(); + fm.destObject = dest; + fm.destMethod = "_set_"+ci->name(); + forwardMethods.push_back(fm); + } + } + delete connections; + } + } + delete ports; +} + +void Structure_impl::streamInit() +{ + list::iterator i; + +#ifdef STRUCTBUILDER_DEBUG + cout << "vstructure: got streamInit()" << endl; +#endif + + for(i=structureObjects.begin(); i != structureObjects.end(); i++) + { + if(i->_base()->_isCompatibleWith("Arts::SynthModule")) + i->_node()->start(); + } +} + +void Structure_impl::streamEnd() +{ + list::iterator i; + +#ifdef STRUCTBUILDER_DEBUG + cout << "vstructure: got streamEnd()" << endl; +#endif + + for(i=structureObjects.begin(); i != structureObjects.end(); i++) + if(i->_base()->_isCompatibleWith("Arts::SynthModule")) + i->_node()->stop(); +} + +void Structure_impl::process(long methodID, Buffer *request, Buffer *result) +{ + const MethodDef& methodDef = getMethodDef(methodID); + + arts_debug("Structure_impl: got method, method ID=%ld name='%s'", + methodID, methodDef.name.c_str()); + + list::iterator fi; + for(fi = forwardMethods.begin(); fi != forwardMethods.end(); fi++) + { + if(fi->method == methodDef.name) + { + Any a; + a.type = methodDef.signature[0].type; + + while(request->remaining() > 0) + a.value.push_back(request->readByte()); + + DynamicRequest(fi->destObject).method(fi->destMethod).param(a).invoke(); + } + } +} diff --git a/arts/runtime/structures_impl.cc b/arts/runtime/structures_impl.cc deleted file mode 100644 index 7c5a5e05..00000000 --- a/arts/runtime/structures_impl.cc +++ /dev/null @@ -1,1421 +0,0 @@ -#include "artsbuilder.h" -#include "weakreference.h" -#include "moduleinfo.h" -#include "compatibility.h" -#include "sequenceutils.h" -#include -#include - -using namespace std; -using namespace Arts; - -typedef WeakReference PortDesc_wref; -typedef WeakReference ModuleDesc_wref; -typedef WeakReference StructureDesc_wref; - -class PortDesc_impl :virtual public Arts::PortDesc_skel { -protected: - string _name; - PortType _type; - vector _connections; - ModuleDesc_wref _parent; - bool _isConnected; - bool _hasValue; - Any _value; - long _ID; - long _oldID; - list oldConnections; - - void removeNullConnections(); - -public: - ~PortDesc_impl(); - - inline PortDesc self() { return PortDesc::_from_base(_copy()); } - void constructor(ModuleDesc parent, const string& name, const PortType& type); - - void disconnectAll(); - long ID(); - ModuleDesc parent(); - string name(); - PortType type(); - bool isConnected(); - bool hasValue(); - void hasValue(bool newvalue); - vector *connections(); - float floatValue(); - void floatValue( float _new_value ); - - string stringValue(); - void stringValue( const string& _new_value ); - - Any value(); - void value( const Any& _new_value ); - - bool connectTo( PortDesc port ); - void internalConnectInput( PortDesc port ); - void disconnectFrom( PortDesc port ); - - void loadFromList(const vector& list); - vector *saveToList(); - - void internalReConnect( const vector& allports ); - long internalOldID(); -}; - -class ModuleDesc_impl : virtual public ModuleDesc_skel { -private: - long _ID; - StructureDesc_wref _parent; - string _name; - long _x, _y; - vector _ports; - long collectPorts( const Arts::ModuleInfo& info ); - - bool _isInterface, _isStructure; - - inline ModuleDesc self() { return ModuleDesc::_from_base(_copy()); } - -public: - long ID(); - StructureDesc parent(); - string name(); - vector *ports(); - long height(); - long width(); - long x(); - long y(); - bool moveTo( long x, long y ); - void constructor( StructureDesc parent, const ModuleInfo& info ); - - void loadFromList(const vector& list); - vector *saveToList(); - - ~ModuleDesc_impl(); - - bool isInterface(); - bool isStructure(); - Arts::PortDesc findPort(const string& name); -}; - -class StructureDesc_impl : virtual public Arts::StructureDesc_skel { -protected: - bool _valid; - vector _modules; - vector _ports; /* only structure ports which are part of the interface */ - vector _inheritedInterfaces; - long nextID; - ModuleInfo _externalInterface; - - inline StructureDesc self() { return StructureDesc::_from_base(_copy()); } -public: - string name(); - void name(const string& newName); - - vector *saveToList(); - void loadFromList(const vector& list); - vector *modules(); - vector *ports(); - vector *inheritedInterfaces(); - - void clear(); - long obtainID(); - long width(); - long height(); - bool valid(); - - ModuleDesc createModuleDesc( const ModuleInfo& info ); - ModuleDesc createModuleDesc( const string& name ); - void freeModuleDesc(ModuleDesc moduledesc); - - // external interface - StructurePortDesc createStructurePortDesc(const PortType& type, const string& name); - void freeStructurePortDesc(StructurePortDesc portdesc); - void moveStructurePortDesc(StructurePortDesc portdesc, long newposition); - - ModuleInfo externalInterface(); - - void addInheritedInterface(const string& iface); - void removeInheritedInterface(const string& iface); - - StructureDesc_impl(); - ~StructureDesc_impl(); -}; - -class StructurePortDesc_impl : - virtual public PortDesc_impl, - virtual public StructurePortDesc_skel -{ -protected: - StructureDesc_wref _parentStructure; - long _x, _y, _position; - string _inheritedInterface; - - inline StructurePortDesc self() { - return StructurePortDesc::_from_base(_copy()); - } -public: - void constructor(StructureDesc parent, const string& name, - const PortType& type); - ~StructurePortDesc_impl(); - - long x(); - long y(); - long position(); - void lowerPosition(); - void raisePosition(); - void rename(const string& newname); - string inheritedInterface(); - void inheritedInterface(const string& iface); - - void internalSetPosition(long position); - StructureDesc parentStructure(); - bool moveTo( long X, long Y ); - - void loadFromList(const vector& list); - vector *saveToList(); -}; - -REGISTER_IMPLEMENTATION(PortDesc_impl); -REGISTER_IMPLEMENTATION(ModuleDesc_impl); -REGISTER_IMPLEMENTATION(StructureDesc_impl); -REGISTER_IMPLEMENTATION(StructurePortDesc_impl); - -/* -#include "structures.h" -*/ -#include "debug.h" -#include -#include - -#define dname(dir) ((dir)==Arts::input?"input":"output") -#define pstat \ - printf("port name %s, direction %s, id %d\n",_Name.c_str(),dname(_Type.direction),_ID); - -void PortDesc_impl::constructor(ModuleDesc parent, const string& name, - const PortType& type) -{ -#if 0 - if(parent) - { - char * pname = parent->Name(); - describe("PortDesc."+string(pname)+string(".")+name); - } - else - { - describe("PortDesc.Structure."+name); - } -#endif - _name = name; - _type = type; - _parent = parent; - _isConnected = false; - _hasValue = false; - _value.type = _type.dataType; - - if(!parent.isNull()) - { - StructureDesc sd = parent.parent(); - _ID = sd.obtainID(); - } - // else: assume that some smart object which derives from us will set the ID accordingly - // -> for instance StructurePortDesc_impl does so -} - -#if 0 /* PORT */ -void PortDesc_impl::cleanUp() -{ - disconnectAll(); - delete _Connections; -} -#endif - -/* - * This is new and related to weak references, it purges all null references from _connections - */ -void PortDesc_impl::removeNullConnections() -{ - vector::iterator i = _connections.begin(); - - while(i != _connections.end()) - { - PortDesc pd = *i; - if(pd.isNull()) - { - _connections.erase(i); - i = _connections.begin(); - printf("removeNullConnections() removed something (shouldn't happen)\n"); - } - else i++; - } - - _isConnected = !_connections.empty(); -} - -void PortDesc_impl::disconnectAll() -{ - // disconnect all connected ports - while(!_connections.empty()) - { - PortDesc pd = _connections.front(); - - if(pd.isNull()) // weak references can automatically disappear - _connections.erase(_connections.begin()); - else - pd.disconnectFrom(self()); - } -} - -PortDesc_impl::~PortDesc_impl() -{ -} - -// Implementation for interface PortDesc -long PortDesc_impl::ID() -{ - return _ID; -} - -ModuleDesc PortDesc_impl::parent() -{ - return _parent; -} - -string PortDesc_impl::name() -{ - return _name; -} - -PortType PortDesc_impl::type() -{ - return _type; -} - -bool PortDesc_impl::isConnected() -{ - if(_isConnected) removeNullConnections(); - return _isConnected; -} - -bool PortDesc_impl::hasValue() -{ - return _hasValue; -} - -void PortDesc_impl::hasValue(bool newvalue) -{ - if(_hasValue != newvalue) - { - assert(newvalue == false); - _hasValue = newvalue; - } -} - -vector *PortDesc_impl::connections() -{ - vector::iterator i; - vector *result = new vector; - - for(i = _connections.begin(); i != _connections.end(); i++) - { - PortDesc pd = *i; - if(!pd.isNull()) result->push_back(pd); - } - return result; -} - -float PortDesc_impl::floatValue() -{ - assert(_hasValue); - assert(_type.dataType == "float"); - - Buffer b; - b.write(_value.value); - return b.readFloat(); -} - -void PortDesc_impl::floatValue( float _new_value ) -{ - assert(!_isConnected); - assert(_type.direction == Arts::input); - assert(_type.dataType == "float"); - assert(_value.type == "float"); - - Buffer b; - b.writeFloat(_new_value); - b.read(_value.value, b.size()); - _hasValue = true; -} - -string PortDesc_impl::stringValue() -{ - assert(_hasValue); - assert(_type.dataType == "string"); - assert(_value.type == "string"); - - string result; - Buffer b; - b.write(_value.value); - b.readString(result); - return result; -} - -void PortDesc_impl::stringValue( const string& _new_value ) -{ - assert(!_isConnected); // shouldn't happen, but check anyway - assert(_type.direction == Arts::input); - assert(_type.dataType == "string"); - - Buffer b; - b.writeString(_new_value); - b.read(_value.value, b.size()); - _hasValue = true; -} - -Any PortDesc_impl::value() -{ - assert(_hasValue); - return _value; -} - -void PortDesc_impl::value( const Any& _new_value ) -{ - _value = _new_value; - _hasValue = true; -} - -bool PortDesc_impl::connectTo( PortDesc port ) -{ - removeNullConnections(); - - // check if we are already connected to that port: - - unsigned long i; - for(i=0;i<_connections.size();i++) - { - PortDesc pd = _connections[i]; - if(pd.ID() == port.ID()) return true; - } - - const PortType& rType = port.type(); - - // only stream or event channels may be connected - if( _type.connType != rType.connType ) - return false; - - // TODO: eventually check conditions when it is legal to connect property - // ports, and when it is insane (_Type.connType == Arts::property) - // - // for incoming structure ports, for instance, it is perfectly allright - - // only same data type connections allowed - if( _type.dataType != rType.dataType ) - return false; - - // only opposite directions - if( _type.direction == rType.direction ) - return false; - - // always first connect the input port to the output port and - // then the other direction - - if( _type.direction == Arts::input ) - { - if(!_isConnected || _type.isMultiPort) - { - assert(_connections.empty() || _type.isMultiPort); - _connections.push_back(port); - - port.internalConnectInput(self()); - - _isConnected = true; - _hasValue = false; - return true; - } - } - if( _type.direction == Arts::output ) - return port.connectTo(self()); - - return false; -} - -void PortDesc_impl::internalConnectInput( PortDesc port ) -{ - _connections.push_back(port); - _isConnected = true; -} - -void PortDesc_impl::disconnectFrom( PortDesc port ) -{ - removeNullConnections(); - - unsigned long found = 0; - - artsdebug("port %ld disconnecting from port %ld\n",ID(),port.ID()); - - vector::iterator i = _connections.begin(); - while(!found && i != _connections.end()) - { - Arts::PortDesc other = *i; - if(!other.isNull() && other.ID() == port.ID()) - { - _connections.erase(i); - i = _connections.begin(); - found++; - } - else i++; - } - - _isConnected = !_connections.empty(); - - ModuleDesc parent = _parent; - if(parent.isNull()) - artsdebug("_Parent = , isConnected = %d\n",_isConnected); - else - artsdebug("_Parent = %s, isConnected = %d\n",parent.name().c_str(),_isConnected); - - if(found) - port.disconnectFrom(self()); -} - -// Implementation for interface ModuleDesc -long ModuleDesc_impl::ID() -{ - return _ID; -} - -StructureDesc ModuleDesc_impl::parent() -{ - return _parent; -} - -string ModuleDesc_impl::name() -{ - return _name; -} - -vector *ModuleDesc_impl::ports() -{ - return new vector(_ports); -} - -long ModuleDesc_impl::x() -{ - return _x; -} - -long ModuleDesc_impl::y() -{ - return _y; -} - -long ModuleDesc_impl::width() -{ - assert(false); - return 0; -} - -long ModuleDesc_impl::height() -{ - assert(false); - return 0; -} - - -bool ModuleDesc_impl::moveTo( long x, long y ) -{ - // FIXME: collision checking! - _x = x; - _y = y; - - return(true); -} - - -// Implementation for interface StructureDesc -long StructureDesc_impl::width() -{ - assert(false); - return 0; -} - -long StructureDesc_impl::height() -{ - assert(false); - return 0; -} - -/* - * Query the module for it's paramenters - */ - -void ModuleDesc_impl::constructor( StructureDesc parent, - const Arts::ModuleInfo& info ) -{ - _name = info.name; - _x = -1; // no position assigned - _y = -1; - _ID = parent.obtainID(); - _parent = parent; - _isInterface = info.isInterface; - _isStructure = info.isStructure; - - collectPorts(info); -} - -ModuleDesc_impl::~ModuleDesc_impl() -{ -} - -bool ModuleDesc_impl::isInterface() -{ - return _isInterface; -} - -bool ModuleDesc_impl::isStructure() -{ - return _isStructure; -} - - -PortDesc ModuleDesc_impl::findPort(const string& name) -{ - vector::iterator p; - - for(p = _ports.begin(); p != _ports.end(); p++) - { - if(name == p->name()) return *p; - } - - return PortDesc::null(); -} - -long ModuleDesc_impl::collectPorts( const Arts::ModuleInfo& info ) -{ - vector::const_iterator i; - vector::const_iterator ni = info.portnames.begin(); - long portcount = 0; - - for(i=info.ports.begin(); i != info.ports.end(); i++) - { - const PortType& porttype = *i; - const string& portname = *ni++; - - artsdebug("#%d: %s\n",portcount,portname.c_str()); - - PortDesc pd(self(),portname,porttype); - _ports.push_back(pd); - portcount++; - } - return(portcount); -} - -ModuleDesc StructureDesc_impl::createModuleDesc( const ModuleInfo& info ) -{ - Arts::ModuleDesc result = createModuleDesc(info.name); - - assert(!result.isNull()); - return result; -} - -ModuleDesc StructureDesc_impl::createModuleDesc( const string& name ) -{ - /* FIXME: need new comment - * to create a representation of a specified synth module, we - * - * - create an instance of this synth module by contacting the - * module server and telling him to do so (result is a C++ class) - * - * - create an instance of a ModuleDesc, and tell it to query the - * module for it's parameters (result is a CORBA object) - * - * - destroy the synth module (C++ class) again and return a reference - * to the CORBA object - */ -/* - ModuleServer *MS_SynthModule; - MS_SynthModule = (ModuleServer *)SynthModule::get_MS(); - - SynthModule *m = (SynthModule *)MS_SynthModule->getModule(name); -*/ -#if 0 - Arts::ModuleInfo_var info = ModuleBroker->lookupModule(name); - if(!info) return 0; -#endif - const Arts::ModuleInfo& info = makeModuleInfo(name); - Arts::ModuleDesc moduledesc = ModuleDesc(self(),info); - _modules.push_back(moduledesc); - return moduledesc; -} - -void StructureDesc_impl::freeModuleDesc(ModuleDesc moduledesc) -{ - vector::iterator i; - - for(i=_modules.begin();i != _modules.end(); i++) - { - Arts::ModuleDesc current = *i; - - if(current.ID() == moduledesc.ID()) - { - _modules.erase(i); // will get freed automagically - return; - } - } -} - -vector *StructureDesc_impl::modules() -{ - vector *retval = new vector(_modules); - return(retval); -} - -void StructureDesc_impl::addInheritedInterface(const string& iface) -{ - _inheritedInterfaces.push_back(iface); -} - -void StructureDesc_impl::removeInheritedInterface(const string& iface) -{ - vector newII; - vector::iterator ii; - - for(ii = _inheritedInterfaces.begin(); ii != _inheritedInterfaces.end(); ii++) - if(*ii != iface) - newII.push_back(*ii); - - _inheritedInterfaces = newII; -} - -vector *StructureDesc_impl::inheritedInterfaces() -{ - return new vector(_inheritedInterfaces); -} - -StructureDesc_impl::StructureDesc_impl() -{ - arts_debug("PORT: created structuredesc_impl"); - nextID = 0; - _valid = true; - _externalInterface.name = "unknown"; // FIXME - _externalInterface.isStructure = true; - _externalInterface.isInterface = false; -} - -StructureDesc_impl::~StructureDesc_impl() -{ - artsdebug("StructureDesc released...\n"); -} - -long StructureDesc_impl::obtainID() -{ - return(nextID++); -} - -bool StructureDesc_impl::valid() -{ - return(_valid); -} - -void StructureDesc_impl::clear() -{ - _modules.clear(); - _ports.clear(); - _inheritedInterfaces.clear(); - _valid = true; -} - -// "file" management - -vector *PortDesc_impl::saveToList() -{ - vector *list = new vector; - - sqprintf(list,"id=%ld",_ID); - if(_hasValue) - { - if(_type.dataType == "string") - { - sqprintf(list,"string_data=%s",stringValue().c_str()); - } - else if(_type.dataType == "float") - { - sqprintf(list,"audio_data=%2.5f",floatValue()); - } - else - { - Buffer b; - _value.writeType(b); - sqprintf(list,"any_data=%s",b.toString("value").c_str()); - } - } - - if(_isConnected) - { - vector::iterator i; - - for(i=_connections.begin();i != _connections.end(); i++) - { - Arts::PortDesc port = *i; - if(!port.isNull()) sqprintf(list,"connect_to=%ld",port.ID()); - } - } - return list; -} - -vector *ModuleDesc_impl::saveToList() -{ - vector *list = new vector; - vector::iterator i; - - sqprintf(list,"id=%ld",_ID); - sqprintf(list,"x=%ld",_x); - sqprintf(list,"y=%ld",_y); - for(i=_ports.begin();i != _ports.end();i++) - { - PortDesc pd = *i; - sqprintf(list,"port=%s",pd.name().c_str()); - - vector *portlist = pd.saveToList(); - addSubStringSeq(list,portlist); - delete portlist; - } - return list; -} - -vector *StructureDesc_impl::saveToList() -{ - vector *list = new vector; - vector::iterator mi; - vector::iterator pi; - vector::iterator ii; - - sqprintf(list,"name=%s",_externalInterface.name.c_str()); - for(mi=_modules.begin();mi != _modules.end();mi++) - { - ModuleDesc md = *mi; - sqprintf(list,"module=%s",md.name().c_str()); - - vector *modulelist = md.saveToList(); - addSubStringSeq(list,modulelist); - delete modulelist; - } - for(pi=_ports.begin(); pi!=_ports.end(); pi++) - { - Arts::StructurePortDesc spd = *pi; - sqprintf(list,"structureport"); - - vector *portlist= spd.saveToList(); - addSubStringSeq(list,portlist); - delete portlist; - } - for(ii=_inheritedInterfaces.begin(); ii != _inheritedInterfaces.end(); ii++) - sqprintf(list,"interface=%s",ii->c_str()); - - return list; -} - -void PortDesc_impl::internalReConnect( const vector& allports ) -{ - vector::const_iterator i; - - for(i=allports.begin(); i != allports.end(); i++) - { - PortDesc pd = (*i); - long oid = pd.internalOldID(); - - if(find(oldConnections.begin(),oldConnections.end(),oid) - != oldConnections.end()) - { - connectTo(pd); - } - } -} - -long PortDesc_impl::internalOldID() -{ - return _oldID; -} - -void PortDesc_impl::loadFromList(const vector& list) -{ - unsigned long i; - string cmd,param; - for(i=0;i& list) -{ - artsdebug("mlist-----------\n"); - unsigned long i; - string cmd, param; - for(i=0;i cmd was %s\n",cmd.c_str()); - if(cmd == "port") - { - string portName = - OldFormatTranslator::newPortName(_name,param); - PortDesc pd = PortDesc::null(); - vector::iterator pi; - - for(pi=_ports.begin(); pi != _ports.end(); pi++) - { - artsdebug("pdi = %s, portName = %s\n",pi->name().c_str(), - portName.c_str()); - if(pi->name() == portName) pd = *pi; - } - assert(!pd.isNull()); - - vector *plist = getSubStringSeq(&list,i); - pd.loadFromList(*plist); - delete plist; - } else if(cmd == "x") { - _x = atol(param.c_str()); - artsdebug("X set to %ld (param was %s)\n",_x,param.c_str()); - } else if(cmd == "y") { - _y = atol(param.c_str()); - artsdebug("Y set to %ld (param was %s)\n",_y,param.c_str()); - } - } - } - artsdebug("-----------mlist\n"); -} - -void StructureDesc_impl::loadFromList(const vector& list) -{ - string cmd,param; - unsigned long i; - vector allports; - - clear(); - _externalInterface.name = (const char *)"unknown"; - - artsdebug("loadFromList; listlen = %ld\n",list.size()); - for(i=0;i cmd was %s\n",cmd.c_str()); - if(cmd == "module") - { - string newName = OldFormatTranslator::newModuleName(param); - ModuleDesc md = createModuleDesc(newName); - - vector *mlist = getSubStringSeq(&list,i); - - if(!md.isNull()) - { - md.loadFromList(*mlist); - - // PORT: order changed - vector *pd = md.ports(); - vector::iterator pi; - for(pi = pd->begin(); pi != pd->end();pi++) - allports.push_back(*pi); - - delete pd; - } - else - { - // module couldn't be found - _valid = false; - } - delete mlist; - } - else if(cmd == "name") - { - _externalInterface.name = param; - } - else if(cmd == "interface") - { - _inheritedInterfaces.push_back(param); - } - else if(cmd == "structureport") - { - // just to have valid values to pass to the new (to be loaded) - // port: - PortType type; - type.direction = Arts::input; - type.dataType = "float"; - type.connType = Arts::conn_stream; - type.isMultiPort = false; - - StructurePortDesc spd = - createStructurePortDesc(type,"unknown"); - - vector *splist = getSubStringSeq(&list,i); - spd.loadFromList(*splist); - delete splist; - - // yes; this is a port as well - allports.push_back(spd); - } - } - } - - for(i=0;iX()*1000+p->Y(); - if(p.type().direction == Arts::input) result += 5000000; - - return result; -} - -bool extint_port_compare(StructurePortDesc p1, StructurePortDesc p2) -{ - long p1s = extint_pscore(p1); - long p2s = extint_pscore(p2); - - artsdebug("compare; [%s] = %d ; [%s] = %d\n", p1.name().c_str(),p1s, - p2.name().c_str(),p2s); - return (p1s < p2s); -// return -1; - //if(p1s == p2s) return 0; - //return 1; -} - -ModuleInfo StructureDesc_impl::externalInterface() -{ - ModuleInfo result = _externalInterface; - vector sorted_ports = _ports; - vector::iterator p; - unsigned long l; -/* PORT: - for(l=0;l<_Ports->length();l++) sorted_ports.push_back((*_Ports)[l]); -*/ - sort(sorted_ports.begin(),sorted_ports.end(),extint_port_compare); - - l = 0; - for(p=sorted_ports.begin();p != sorted_ports.end();p++) - { - string pname = p->name(); - PortType ptype = p->type(); - - if(ptype.direction == Arts::input) - ptype.direction = Arts::output; - else - ptype.direction = Arts::input; - - artsdebug("externalInterface; sorted ports: %d => %s\n",l,pname.c_str()); - result.ports.push_back(ptype); - result.portnames.push_back(pname); - l++; - } - return result; -} - -vector *StructureDesc_impl::ports() -{ - return new vector(_ports); -} - -StructurePortDesc StructureDesc_impl::createStructurePortDesc( - const Arts::PortType& type, const string& name) -{ - artsdebug("creating new port %s\n",name.c_str()); - StructurePortDesc port(self(), name, type); - _ports.push_back(port); - - // set the Position (put it at the end of the ports) - unsigned long i, count = 0; - for(i=0;i<_ports.size();i++) - { - if(_ports[i].type().direction == type.direction) count++; - } - assert(count > 0); // we just inserted one ;) - port.internalSetPosition(count-1); - return port; -} - -void StructureDesc_impl::freeStructurePortDesc(StructurePortDesc portdesc) -{ - vector::iterator i; - - for(i=_ports.begin(); i != _ports.end(); i++) - { - if(i->ID() == portdesc.ID()) - { - _ports.erase(i); - return; - } - } -} - -void StructureDesc_impl::moveStructurePortDesc(StructurePortDesc - portdesc, long newposition) -{ - const Arts::PortType& type = portdesc.type(); - - unsigned long i; - long count = 0; - for(i=0;i<_ports.size();i++) - { - if(_ports[i].type().direction == type.direction) count++; - } - - if(newposition < 0) newposition = 0; - if(newposition > count-1) newposition = count-1; - - if(newposition == portdesc.position()) return; - - int delta, lower, upper; - - if(newposition > portdesc.position()) - { - // if the port gets a higher position, move all ports that - // are between it's current position and its new position down one - lower = portdesc.position(); - upper = newposition; - delta = -1; - } - else - { - // if the port gets a lower position, move all ports that - // are between it's current position and its new position up one - lower = newposition; - upper = portdesc.position(); - delta = 1; - } - - for(i=0;i<_ports.size();i++) - { - StructurePortDesc pd = _ports[i]; - - if(pd.type().direction == type.direction) - { - if(pd.ID() != portdesc.ID() && - pd.position() >= lower && pd.position() <= upper) - { - pd.internalSetPosition(pd.position()+delta); - } - } - - } - portdesc.internalSetPosition(newposition); -} - -void StructurePortDesc_impl::constructor(StructureDesc parent, - const string& name, const PortType& type) -{ - PortDesc_impl::constructor(ModuleDesc::null(),name,type); - _parentStructure = parent; - _ID = parent.obtainID(); - _x = 0; - _y = 0; - _position = 0; -} - -StructurePortDesc_impl::~StructurePortDesc_impl() -{ - // this destructor is required to make some compilers (egcs-1.1.2) compile -} - -long StructurePortDesc_impl::x() -{ - return _x; -} - -long StructurePortDesc_impl::y() -{ - return _y; -} - -long StructurePortDesc_impl::position() -{ - return _position; -} - -void StructurePortDesc_impl::lowerPosition() -{ - StructureDesc parent = _parentStructure; // weak reference - - if(!parent.isNull()) - parent.moveStructurePortDesc(self(), _position-1); -} - -void StructurePortDesc_impl::raisePosition() -{ - StructureDesc parent = _parentStructure; // weak reference - - if(!parent.isNull()) - parent.moveStructurePortDesc(self(), _position+1); -} - -void StructurePortDesc_impl::rename(const string& newname) -{ - _name = newname; -} - -void StructurePortDesc_impl::inheritedInterface(const string& iface) -{ - _inheritedInterface = iface; -} - -string StructurePortDesc_impl::inheritedInterface() -{ - return _inheritedInterface; -} - -// only used by the structure to reorder the ports -void StructurePortDesc_impl::internalSetPosition(long position) -{ - _position = position; -} - -StructureDesc StructurePortDesc_impl::parentStructure() -{ - return _parentStructure; -} - -bool StructurePortDesc_impl::moveTo( long X, long Y ) -{ - // FIXME: check space - _x = X; - _y = Y; - - return true; -} - -/* - override load & save behaviour this kind of port requires that we save the type - of the port as well, that means all of the porttype: - - enum PortDirection {input, output}; - enum PortDataType {audio_data, string_data}; - enum PortConnType {stream, event, property}; - struct PortType { - PortDirection direction; - PortDataType dataType; - PortConnType connType; - }; - - so when saved, it will look like that: - - { - name=fasel - x=4 - y=2 - type - { - direction=input/output - datatype=audio/string - conntype=stream/event/property - } - data - { - [original port saves here] - } - } -*/ - -PortType loadTypeFromList(const vector& list) -{ - unsigned long i,loadstate = 0; - string cmd,param; - Arts::PortType result; - - for(i=0;i cmd was %s\n",cmd.c_str()); - if(cmd == "direction") - { - if(param == "input") { - result.direction = Arts::input; - } - else if(param == "output") { - result.direction = Arts::output; - } - else assert(false); - - loadstate += 1; - } else if(cmd == "datatype") { - if(param == "audio") { - result.dataType = "float"; - } - else if(param == "string") { - result.dataType = "string"; - } - else assert(false); - - loadstate += 100; - } else if(cmd == "conntype") { - if(param == "stream") { - result.connType = Arts::conn_stream; - } - else if(param == "event") { - result.connType = Arts::conn_event; - } - else if(param == "property") { - result.connType = Arts::conn_property; - artsdebug("got property stuff\n"); - } - else assert(false); - - loadstate += 10000; - } - } - } - assert(loadstate == 10101); // should see every member exactly once - result.isMultiPort = false; - return result; -} - -void StructurePortDesc_impl::loadFromList(const vector& list) -{ - artsdebug("structureportlist-----------\n"); - unsigned long i; - string cmd,param; - vector *typelist = 0, *datalist = 0; - bool haveType = false, haveData = false; - // need both to do restore, type first - - for(i=0;i cmd was %s\n",cmd.c_str()); - if(cmd == "type") - { - assert(!haveType); // only allowed once - haveType = true; - typelist = getSubStringSeq(&list,i); - } else if(cmd == "data") { - assert(!haveData); // only allowed once - haveData = true; - datalist = getSubStringSeq(&list,i); - } else if(cmd == "x") { - _x = atol(param.c_str()); - artsdebug("X set to %ld (param was %s)\n",_x,param.c_str()); - } else if(cmd == "y") { - _y = atol(param.c_str()); - artsdebug("Y set to %ld (param was %s)\n",_y,param.c_str()); - } else if(cmd == "position") { - _position = atol(param.c_str()); - artsdebug("Position set to %ld (param was %s)\n",_position, - param.c_str()); - } else if(cmd == "name") { - _name = param; - artsdebug("Name set to %s\n",_name.c_str()); - } else if(cmd == "interface") { - _inheritedInterface = param; - artsdebug("Interface set to %s\n",_inheritedInterface.c_str()); - } - } - } - assert(haveType && haveData); - - _type = loadTypeFromList(*typelist); - - if(_type.connType == Arts::conn_property) artsdebug("have property here\n"); - PortDesc_impl::loadFromList(*datalist); - - delete typelist; - delete datalist; - artsdebug("-----------structureportlist\n"); -} - -vector *saveTypeToList(const PortType& type) -{ - vector *list = new vector; - - switch(type.direction) - { - case Arts::input: sqprintf(list,"direction=input"); - break; - case Arts::output: sqprintf(list,"direction=output"); - break; - default: assert(false); // should never happen! - } - if(type.dataType == "float") - { - sqprintf(list,"datatype=audio"); - } - else if(type.dataType == "string") - { - sqprintf(list,"datatype=string"); - } - else - { - assert(false); // should never happen! - } - switch(type.connType) - { - case Arts::conn_stream: sqprintf(list,"conntype=stream"); - break; - case Arts::conn_event: sqprintf(list,"conntype=event"); - break; - case Arts::conn_property: sqprintf(list,"conntype=property"); - break; - default: assert(false); // should never happen! - } - - return list; -} - -vector *StructurePortDesc_impl::saveToList() -{ - vector *list = new vector; - sqprintf(list,"name=%s",_name.c_str()); - sqprintf(list,"x=%ld",_x); - sqprintf(list,"y=%ld",_y); - sqprintf(list,"position=%ld",_position); - - if(!_inheritedInterface.empty()) - sqprintf(list, "interface=%s",_inheritedInterface.c_str()); - - sqprintf(list,"type"); - - vector *typelist = saveTypeToList(_type); - addSubStringSeq(list,typelist); - delete typelist; - - sqprintf(list,"data"); - - vector *portlist = PortDesc_impl::saveToList(); - addSubStringSeq(list,portlist); - delete portlist; - - return list; -} diff --git a/arts/runtime/structures_impl.cpp b/arts/runtime/structures_impl.cpp new file mode 100644 index 00000000..7c5a5e05 --- /dev/null +++ b/arts/runtime/structures_impl.cpp @@ -0,0 +1,1421 @@ +#include "artsbuilder.h" +#include "weakreference.h" +#include "moduleinfo.h" +#include "compatibility.h" +#include "sequenceutils.h" +#include +#include + +using namespace std; +using namespace Arts; + +typedef WeakReference PortDesc_wref; +typedef WeakReference ModuleDesc_wref; +typedef WeakReference StructureDesc_wref; + +class PortDesc_impl :virtual public Arts::PortDesc_skel { +protected: + string _name; + PortType _type; + vector _connections; + ModuleDesc_wref _parent; + bool _isConnected; + bool _hasValue; + Any _value; + long _ID; + long _oldID; + list oldConnections; + + void removeNullConnections(); + +public: + ~PortDesc_impl(); + + inline PortDesc self() { return PortDesc::_from_base(_copy()); } + void constructor(ModuleDesc parent, const string& name, const PortType& type); + + void disconnectAll(); + long ID(); + ModuleDesc parent(); + string name(); + PortType type(); + bool isConnected(); + bool hasValue(); + void hasValue(bool newvalue); + vector *connections(); + float floatValue(); + void floatValue( float _new_value ); + + string stringValue(); + void stringValue( const string& _new_value ); + + Any value(); + void value( const Any& _new_value ); + + bool connectTo( PortDesc port ); + void internalConnectInput( PortDesc port ); + void disconnectFrom( PortDesc port ); + + void loadFromList(const vector& list); + vector *saveToList(); + + void internalReConnect( const vector& allports ); + long internalOldID(); +}; + +class ModuleDesc_impl : virtual public ModuleDesc_skel { +private: + long _ID; + StructureDesc_wref _parent; + string _name; + long _x, _y; + vector _ports; + long collectPorts( const Arts::ModuleInfo& info ); + + bool _isInterface, _isStructure; + + inline ModuleDesc self() { return ModuleDesc::_from_base(_copy()); } + +public: + long ID(); + StructureDesc parent(); + string name(); + vector *ports(); + long height(); + long width(); + long x(); + long y(); + bool moveTo( long x, long y ); + void constructor( StructureDesc parent, const ModuleInfo& info ); + + void loadFromList(const vector& list); + vector *saveToList(); + + ~ModuleDesc_impl(); + + bool isInterface(); + bool isStructure(); + Arts::PortDesc findPort(const string& name); +}; + +class StructureDesc_impl : virtual public Arts::StructureDesc_skel { +protected: + bool _valid; + vector _modules; + vector _ports; /* only structure ports which are part of the interface */ + vector _inheritedInterfaces; + long nextID; + ModuleInfo _externalInterface; + + inline StructureDesc self() { return StructureDesc::_from_base(_copy()); } +public: + string name(); + void name(const string& newName); + + vector *saveToList(); + void loadFromList(const vector& list); + vector *modules(); + vector *ports(); + vector *inheritedInterfaces(); + + void clear(); + long obtainID(); + long width(); + long height(); + bool valid(); + + ModuleDesc createModuleDesc( const ModuleInfo& info ); + ModuleDesc createModuleDesc( const string& name ); + void freeModuleDesc(ModuleDesc moduledesc); + + // external interface + StructurePortDesc createStructurePortDesc(const PortType& type, const string& name); + void freeStructurePortDesc(StructurePortDesc portdesc); + void moveStructurePortDesc(StructurePortDesc portdesc, long newposition); + + ModuleInfo externalInterface(); + + void addInheritedInterface(const string& iface); + void removeInheritedInterface(const string& iface); + + StructureDesc_impl(); + ~StructureDesc_impl(); +}; + +class StructurePortDesc_impl : + virtual public PortDesc_impl, + virtual public StructurePortDesc_skel +{ +protected: + StructureDesc_wref _parentStructure; + long _x, _y, _position; + string _inheritedInterface; + + inline StructurePortDesc self() { + return StructurePortDesc::_from_base(_copy()); + } +public: + void constructor(StructureDesc parent, const string& name, + const PortType& type); + ~StructurePortDesc_impl(); + + long x(); + long y(); + long position(); + void lowerPosition(); + void raisePosition(); + void rename(const string& newname); + string inheritedInterface(); + void inheritedInterface(const string& iface); + + void internalSetPosition(long position); + StructureDesc parentStructure(); + bool moveTo( long X, long Y ); + + void loadFromList(const vector& list); + vector *saveToList(); +}; + +REGISTER_IMPLEMENTATION(PortDesc_impl); +REGISTER_IMPLEMENTATION(ModuleDesc_impl); +REGISTER_IMPLEMENTATION(StructureDesc_impl); +REGISTER_IMPLEMENTATION(StructurePortDesc_impl); + +/* +#include "structures.h" +*/ +#include "debug.h" +#include +#include + +#define dname(dir) ((dir)==Arts::input?"input":"output") +#define pstat \ + printf("port name %s, direction %s, id %d\n",_Name.c_str(),dname(_Type.direction),_ID); + +void PortDesc_impl::constructor(ModuleDesc parent, const string& name, + const PortType& type) +{ +#if 0 + if(parent) + { + char * pname = parent->Name(); + describe("PortDesc."+string(pname)+string(".")+name); + } + else + { + describe("PortDesc.Structure."+name); + } +#endif + _name = name; + _type = type; + _parent = parent; + _isConnected = false; + _hasValue = false; + _value.type = _type.dataType; + + if(!parent.isNull()) + { + StructureDesc sd = parent.parent(); + _ID = sd.obtainID(); + } + // else: assume that some smart object which derives from us will set the ID accordingly + // -> for instance StructurePortDesc_impl does so +} + +#if 0 /* PORT */ +void PortDesc_impl::cleanUp() +{ + disconnectAll(); + delete _Connections; +} +#endif + +/* + * This is new and related to weak references, it purges all null references from _connections + */ +void PortDesc_impl::removeNullConnections() +{ + vector::iterator i = _connections.begin(); + + while(i != _connections.end()) + { + PortDesc pd = *i; + if(pd.isNull()) + { + _connections.erase(i); + i = _connections.begin(); + printf("removeNullConnections() removed something (shouldn't happen)\n"); + } + else i++; + } + + _isConnected = !_connections.empty(); +} + +void PortDesc_impl::disconnectAll() +{ + // disconnect all connected ports + while(!_connections.empty()) + { + PortDesc pd = _connections.front(); + + if(pd.isNull()) // weak references can automatically disappear + _connections.erase(_connections.begin()); + else + pd.disconnectFrom(self()); + } +} + +PortDesc_impl::~PortDesc_impl() +{ +} + +// Implementation for interface PortDesc +long PortDesc_impl::ID() +{ + return _ID; +} + +ModuleDesc PortDesc_impl::parent() +{ + return _parent; +} + +string PortDesc_impl::name() +{ + return _name; +} + +PortType PortDesc_impl::type() +{ + return _type; +} + +bool PortDesc_impl::isConnected() +{ + if(_isConnected) removeNullConnections(); + return _isConnected; +} + +bool PortDesc_impl::hasValue() +{ + return _hasValue; +} + +void PortDesc_impl::hasValue(bool newvalue) +{ + if(_hasValue != newvalue) + { + assert(newvalue == false); + _hasValue = newvalue; + } +} + +vector *PortDesc_impl::connections() +{ + vector::iterator i; + vector *result = new vector; + + for(i = _connections.begin(); i != _connections.end(); i++) + { + PortDesc pd = *i; + if(!pd.isNull()) result->push_back(pd); + } + return result; +} + +float PortDesc_impl::floatValue() +{ + assert(_hasValue); + assert(_type.dataType == "float"); + + Buffer b; + b.write(_value.value); + return b.readFloat(); +} + +void PortDesc_impl::floatValue( float _new_value ) +{ + assert(!_isConnected); + assert(_type.direction == Arts::input); + assert(_type.dataType == "float"); + assert(_value.type == "float"); + + Buffer b; + b.writeFloat(_new_value); + b.read(_value.value, b.size()); + _hasValue = true; +} + +string PortDesc_impl::stringValue() +{ + assert(_hasValue); + assert(_type.dataType == "string"); + assert(_value.type == "string"); + + string result; + Buffer b; + b.write(_value.value); + b.readString(result); + return result; +} + +void PortDesc_impl::stringValue( const string& _new_value ) +{ + assert(!_isConnected); // shouldn't happen, but check anyway + assert(_type.direction == Arts::input); + assert(_type.dataType == "string"); + + Buffer b; + b.writeString(_new_value); + b.read(_value.value, b.size()); + _hasValue = true; +} + +Any PortDesc_impl::value() +{ + assert(_hasValue); + return _value; +} + +void PortDesc_impl::value( const Any& _new_value ) +{ + _value = _new_value; + _hasValue = true; +} + +bool PortDesc_impl::connectTo( PortDesc port ) +{ + removeNullConnections(); + + // check if we are already connected to that port: + + unsigned long i; + for(i=0;i<_connections.size();i++) + { + PortDesc pd = _connections[i]; + if(pd.ID() == port.ID()) return true; + } + + const PortType& rType = port.type(); + + // only stream or event channels may be connected + if( _type.connType != rType.connType ) + return false; + + // TODO: eventually check conditions when it is legal to connect property + // ports, and when it is insane (_Type.connType == Arts::property) + // + // for incoming structure ports, for instance, it is perfectly allright + + // only same data type connections allowed + if( _type.dataType != rType.dataType ) + return false; + + // only opposite directions + if( _type.direction == rType.direction ) + return false; + + // always first connect the input port to the output port and + // then the other direction + + if( _type.direction == Arts::input ) + { + if(!_isConnected || _type.isMultiPort) + { + assert(_connections.empty() || _type.isMultiPort); + _connections.push_back(port); + + port.internalConnectInput(self()); + + _isConnected = true; + _hasValue = false; + return true; + } + } + if( _type.direction == Arts::output ) + return port.connectTo(self()); + + return false; +} + +void PortDesc_impl::internalConnectInput( PortDesc port ) +{ + _connections.push_back(port); + _isConnected = true; +} + +void PortDesc_impl::disconnectFrom( PortDesc port ) +{ + removeNullConnections(); + + unsigned long found = 0; + + artsdebug("port %ld disconnecting from port %ld\n",ID(),port.ID()); + + vector::iterator i = _connections.begin(); + while(!found && i != _connections.end()) + { + Arts::PortDesc other = *i; + if(!other.isNull() && other.ID() == port.ID()) + { + _connections.erase(i); + i = _connections.begin(); + found++; + } + else i++; + } + + _isConnected = !_connections.empty(); + + ModuleDesc parent = _parent; + if(parent.isNull()) + artsdebug("_Parent = , isConnected = %d\n",_isConnected); + else + artsdebug("_Parent = %s, isConnected = %d\n",parent.name().c_str(),_isConnected); + + if(found) + port.disconnectFrom(self()); +} + +// Implementation for interface ModuleDesc +long ModuleDesc_impl::ID() +{ + return _ID; +} + +StructureDesc ModuleDesc_impl::parent() +{ + return _parent; +} + +string ModuleDesc_impl::name() +{ + return _name; +} + +vector *ModuleDesc_impl::ports() +{ + return new vector(_ports); +} + +long ModuleDesc_impl::x() +{ + return _x; +} + +long ModuleDesc_impl::y() +{ + return _y; +} + +long ModuleDesc_impl::width() +{ + assert(false); + return 0; +} + +long ModuleDesc_impl::height() +{ + assert(false); + return 0; +} + + +bool ModuleDesc_impl::moveTo( long x, long y ) +{ + // FIXME: collision checking! + _x = x; + _y = y; + + return(true); +} + + +// Implementation for interface StructureDesc +long StructureDesc_impl::width() +{ + assert(false); + return 0; +} + +long StructureDesc_impl::height() +{ + assert(false); + return 0; +} + +/* + * Query the module for it's paramenters + */ + +void ModuleDesc_impl::constructor( StructureDesc parent, + const Arts::ModuleInfo& info ) +{ + _name = info.name; + _x = -1; // no position assigned + _y = -1; + _ID = parent.obtainID(); + _parent = parent; + _isInterface = info.isInterface; + _isStructure = info.isStructure; + + collectPorts(info); +} + +ModuleDesc_impl::~ModuleDesc_impl() +{ +} + +bool ModuleDesc_impl::isInterface() +{ + return _isInterface; +} + +bool ModuleDesc_impl::isStructure() +{ + return _isStructure; +} + + +PortDesc ModuleDesc_impl::findPort(const string& name) +{ + vector::iterator p; + + for(p = _ports.begin(); p != _ports.end(); p++) + { + if(name == p->name()) return *p; + } + + return PortDesc::null(); +} + +long ModuleDesc_impl::collectPorts( const Arts::ModuleInfo& info ) +{ + vector::const_iterator i; + vector::const_iterator ni = info.portnames.begin(); + long portcount = 0; + + for(i=info.ports.begin(); i != info.ports.end(); i++) + { + const PortType& porttype = *i; + const string& portname = *ni++; + + artsdebug("#%d: %s\n",portcount,portname.c_str()); + + PortDesc pd(self(),portname,porttype); + _ports.push_back(pd); + portcount++; + } + return(portcount); +} + +ModuleDesc StructureDesc_impl::createModuleDesc( const ModuleInfo& info ) +{ + Arts::ModuleDesc result = createModuleDesc(info.name); + + assert(!result.isNull()); + return result; +} + +ModuleDesc StructureDesc_impl::createModuleDesc( const string& name ) +{ + /* FIXME: need new comment + * to create a representation of a specified synth module, we + * + * - create an instance of this synth module by contacting the + * module server and telling him to do so (result is a C++ class) + * + * - create an instance of a ModuleDesc, and tell it to query the + * module for it's parameters (result is a CORBA object) + * + * - destroy the synth module (C++ class) again and return a reference + * to the CORBA object + */ +/* + ModuleServer *MS_SynthModule; + MS_SynthModule = (ModuleServer *)SynthModule::get_MS(); + + SynthModule *m = (SynthModule *)MS_SynthModule->getModule(name); +*/ +#if 0 + Arts::ModuleInfo_var info = ModuleBroker->lookupModule(name); + if(!info) return 0; +#endif + const Arts::ModuleInfo& info = makeModuleInfo(name); + Arts::ModuleDesc moduledesc = ModuleDesc(self(),info); + _modules.push_back(moduledesc); + return moduledesc; +} + +void StructureDesc_impl::freeModuleDesc(ModuleDesc moduledesc) +{ + vector::iterator i; + + for(i=_modules.begin();i != _modules.end(); i++) + { + Arts::ModuleDesc current = *i; + + if(current.ID() == moduledesc.ID()) + { + _modules.erase(i); // will get freed automagically + return; + } + } +} + +vector *StructureDesc_impl::modules() +{ + vector *retval = new vector(_modules); + return(retval); +} + +void StructureDesc_impl::addInheritedInterface(const string& iface) +{ + _inheritedInterfaces.push_back(iface); +} + +void StructureDesc_impl::removeInheritedInterface(const string& iface) +{ + vector newII; + vector::iterator ii; + + for(ii = _inheritedInterfaces.begin(); ii != _inheritedInterfaces.end(); ii++) + if(*ii != iface) + newII.push_back(*ii); + + _inheritedInterfaces = newII; +} + +vector *StructureDesc_impl::inheritedInterfaces() +{ + return new vector(_inheritedInterfaces); +} + +StructureDesc_impl::StructureDesc_impl() +{ + arts_debug("PORT: created structuredesc_impl"); + nextID = 0; + _valid = true; + _externalInterface.name = "unknown"; // FIXME + _externalInterface.isStructure = true; + _externalInterface.isInterface = false; +} + +StructureDesc_impl::~StructureDesc_impl() +{ + artsdebug("StructureDesc released...\n"); +} + +long StructureDesc_impl::obtainID() +{ + return(nextID++); +} + +bool StructureDesc_impl::valid() +{ + return(_valid); +} + +void StructureDesc_impl::clear() +{ + _modules.clear(); + _ports.clear(); + _inheritedInterfaces.clear(); + _valid = true; +} + +// "file" management + +vector *PortDesc_impl::saveToList() +{ + vector *list = new vector; + + sqprintf(list,"id=%ld",_ID); + if(_hasValue) + { + if(_type.dataType == "string") + { + sqprintf(list,"string_data=%s",stringValue().c_str()); + } + else if(_type.dataType == "float") + { + sqprintf(list,"audio_data=%2.5f",floatValue()); + } + else + { + Buffer b; + _value.writeType(b); + sqprintf(list,"any_data=%s",b.toString("value").c_str()); + } + } + + if(_isConnected) + { + vector::iterator i; + + for(i=_connections.begin();i != _connections.end(); i++) + { + Arts::PortDesc port = *i; + if(!port.isNull()) sqprintf(list,"connect_to=%ld",port.ID()); + } + } + return list; +} + +vector *ModuleDesc_impl::saveToList() +{ + vector *list = new vector; + vector::iterator i; + + sqprintf(list,"id=%ld",_ID); + sqprintf(list,"x=%ld",_x); + sqprintf(list,"y=%ld",_y); + for(i=_ports.begin();i != _ports.end();i++) + { + PortDesc pd = *i; + sqprintf(list,"port=%s",pd.name().c_str()); + + vector *portlist = pd.saveToList(); + addSubStringSeq(list,portlist); + delete portlist; + } + return list; +} + +vector *StructureDesc_impl::saveToList() +{ + vector *list = new vector; + vector::iterator mi; + vector::iterator pi; + vector::iterator ii; + + sqprintf(list,"name=%s",_externalInterface.name.c_str()); + for(mi=_modules.begin();mi != _modules.end();mi++) + { + ModuleDesc md = *mi; + sqprintf(list,"module=%s",md.name().c_str()); + + vector *modulelist = md.saveToList(); + addSubStringSeq(list,modulelist); + delete modulelist; + } + for(pi=_ports.begin(); pi!=_ports.end(); pi++) + { + Arts::StructurePortDesc spd = *pi; + sqprintf(list,"structureport"); + + vector *portlist= spd.saveToList(); + addSubStringSeq(list,portlist); + delete portlist; + } + for(ii=_inheritedInterfaces.begin(); ii != _inheritedInterfaces.end(); ii++) + sqprintf(list,"interface=%s",ii->c_str()); + + return list; +} + +void PortDesc_impl::internalReConnect( const vector& allports ) +{ + vector::const_iterator i; + + for(i=allports.begin(); i != allports.end(); i++) + { + PortDesc pd = (*i); + long oid = pd.internalOldID(); + + if(find(oldConnections.begin(),oldConnections.end(),oid) + != oldConnections.end()) + { + connectTo(pd); + } + } +} + +long PortDesc_impl::internalOldID() +{ + return _oldID; +} + +void PortDesc_impl::loadFromList(const vector& list) +{ + unsigned long i; + string cmd,param; + for(i=0;i& list) +{ + artsdebug("mlist-----------\n"); + unsigned long i; + string cmd, param; + for(i=0;i cmd was %s\n",cmd.c_str()); + if(cmd == "port") + { + string portName = + OldFormatTranslator::newPortName(_name,param); + PortDesc pd = PortDesc::null(); + vector::iterator pi; + + for(pi=_ports.begin(); pi != _ports.end(); pi++) + { + artsdebug("pdi = %s, portName = %s\n",pi->name().c_str(), + portName.c_str()); + if(pi->name() == portName) pd = *pi; + } + assert(!pd.isNull()); + + vector *plist = getSubStringSeq(&list,i); + pd.loadFromList(*plist); + delete plist; + } else if(cmd == "x") { + _x = atol(param.c_str()); + artsdebug("X set to %ld (param was %s)\n",_x,param.c_str()); + } else if(cmd == "y") { + _y = atol(param.c_str()); + artsdebug("Y set to %ld (param was %s)\n",_y,param.c_str()); + } + } + } + artsdebug("-----------mlist\n"); +} + +void StructureDesc_impl::loadFromList(const vector& list) +{ + string cmd,param; + unsigned long i; + vector allports; + + clear(); + _externalInterface.name = (const char *)"unknown"; + + artsdebug("loadFromList; listlen = %ld\n",list.size()); + for(i=0;i cmd was %s\n",cmd.c_str()); + if(cmd == "module") + { + string newName = OldFormatTranslator::newModuleName(param); + ModuleDesc md = createModuleDesc(newName); + + vector *mlist = getSubStringSeq(&list,i); + + if(!md.isNull()) + { + md.loadFromList(*mlist); + + // PORT: order changed + vector *pd = md.ports(); + vector::iterator pi; + for(pi = pd->begin(); pi != pd->end();pi++) + allports.push_back(*pi); + + delete pd; + } + else + { + // module couldn't be found + _valid = false; + } + delete mlist; + } + else if(cmd == "name") + { + _externalInterface.name = param; + } + else if(cmd == "interface") + { + _inheritedInterfaces.push_back(param); + } + else if(cmd == "structureport") + { + // just to have valid values to pass to the new (to be loaded) + // port: + PortType type; + type.direction = Arts::input; + type.dataType = "float"; + type.connType = Arts::conn_stream; + type.isMultiPort = false; + + StructurePortDesc spd = + createStructurePortDesc(type,"unknown"); + + vector *splist = getSubStringSeq(&list,i); + spd.loadFromList(*splist); + delete splist; + + // yes; this is a port as well + allports.push_back(spd); + } + } + } + + for(i=0;iX()*1000+p->Y(); + if(p.type().direction == Arts::input) result += 5000000; + + return result; +} + +bool extint_port_compare(StructurePortDesc p1, StructurePortDesc p2) +{ + long p1s = extint_pscore(p1); + long p2s = extint_pscore(p2); + + artsdebug("compare; [%s] = %d ; [%s] = %d\n", p1.name().c_str(),p1s, + p2.name().c_str(),p2s); + return (p1s < p2s); +// return -1; + //if(p1s == p2s) return 0; + //return 1; +} + +ModuleInfo StructureDesc_impl::externalInterface() +{ + ModuleInfo result = _externalInterface; + vector sorted_ports = _ports; + vector::iterator p; + unsigned long l; +/* PORT: + for(l=0;l<_Ports->length();l++) sorted_ports.push_back((*_Ports)[l]); +*/ + sort(sorted_ports.begin(),sorted_ports.end(),extint_port_compare); + + l = 0; + for(p=sorted_ports.begin();p != sorted_ports.end();p++) + { + string pname = p->name(); + PortType ptype = p->type(); + + if(ptype.direction == Arts::input) + ptype.direction = Arts::output; + else + ptype.direction = Arts::input; + + artsdebug("externalInterface; sorted ports: %d => %s\n",l,pname.c_str()); + result.ports.push_back(ptype); + result.portnames.push_back(pname); + l++; + } + return result; +} + +vector *StructureDesc_impl::ports() +{ + return new vector(_ports); +} + +StructurePortDesc StructureDesc_impl::createStructurePortDesc( + const Arts::PortType& type, const string& name) +{ + artsdebug("creating new port %s\n",name.c_str()); + StructurePortDesc port(self(), name, type); + _ports.push_back(port); + + // set the Position (put it at the end of the ports) + unsigned long i, count = 0; + for(i=0;i<_ports.size();i++) + { + if(_ports[i].type().direction == type.direction) count++; + } + assert(count > 0); // we just inserted one ;) + port.internalSetPosition(count-1); + return port; +} + +void StructureDesc_impl::freeStructurePortDesc(StructurePortDesc portdesc) +{ + vector::iterator i; + + for(i=_ports.begin(); i != _ports.end(); i++) + { + if(i->ID() == portdesc.ID()) + { + _ports.erase(i); + return; + } + } +} + +void StructureDesc_impl::moveStructurePortDesc(StructurePortDesc + portdesc, long newposition) +{ + const Arts::PortType& type = portdesc.type(); + + unsigned long i; + long count = 0; + for(i=0;i<_ports.size();i++) + { + if(_ports[i].type().direction == type.direction) count++; + } + + if(newposition < 0) newposition = 0; + if(newposition > count-1) newposition = count-1; + + if(newposition == portdesc.position()) return; + + int delta, lower, upper; + + if(newposition > portdesc.position()) + { + // if the port gets a higher position, move all ports that + // are between it's current position and its new position down one + lower = portdesc.position(); + upper = newposition; + delta = -1; + } + else + { + // if the port gets a lower position, move all ports that + // are between it's current position and its new position up one + lower = newposition; + upper = portdesc.position(); + delta = 1; + } + + for(i=0;i<_ports.size();i++) + { + StructurePortDesc pd = _ports[i]; + + if(pd.type().direction == type.direction) + { + if(pd.ID() != portdesc.ID() && + pd.position() >= lower && pd.position() <= upper) + { + pd.internalSetPosition(pd.position()+delta); + } + } + + } + portdesc.internalSetPosition(newposition); +} + +void StructurePortDesc_impl::constructor(StructureDesc parent, + const string& name, const PortType& type) +{ + PortDesc_impl::constructor(ModuleDesc::null(),name,type); + _parentStructure = parent; + _ID = parent.obtainID(); + _x = 0; + _y = 0; + _position = 0; +} + +StructurePortDesc_impl::~StructurePortDesc_impl() +{ + // this destructor is required to make some compilers (egcs-1.1.2) compile +} + +long StructurePortDesc_impl::x() +{ + return _x; +} + +long StructurePortDesc_impl::y() +{ + return _y; +} + +long StructurePortDesc_impl::position() +{ + return _position; +} + +void StructurePortDesc_impl::lowerPosition() +{ + StructureDesc parent = _parentStructure; // weak reference + + if(!parent.isNull()) + parent.moveStructurePortDesc(self(), _position-1); +} + +void StructurePortDesc_impl::raisePosition() +{ + StructureDesc parent = _parentStructure; // weak reference + + if(!parent.isNull()) + parent.moveStructurePortDesc(self(), _position+1); +} + +void StructurePortDesc_impl::rename(const string& newname) +{ + _name = newname; +} + +void StructurePortDesc_impl::inheritedInterface(const string& iface) +{ + _inheritedInterface = iface; +} + +string StructurePortDesc_impl::inheritedInterface() +{ + return _inheritedInterface; +} + +// only used by the structure to reorder the ports +void StructurePortDesc_impl::internalSetPosition(long position) +{ + _position = position; +} + +StructureDesc StructurePortDesc_impl::parentStructure() +{ + return _parentStructure; +} + +bool StructurePortDesc_impl::moveTo( long X, long Y ) +{ + // FIXME: check space + _x = X; + _y = Y; + + return true; +} + +/* + override load & save behaviour this kind of port requires that we save the type + of the port as well, that means all of the porttype: + + enum PortDirection {input, output}; + enum PortDataType {audio_data, string_data}; + enum PortConnType {stream, event, property}; + struct PortType { + PortDirection direction; + PortDataType dataType; + PortConnType connType; + }; + + so when saved, it will look like that: + + { + name=fasel + x=4 + y=2 + type + { + direction=input/output + datatype=audio/string + conntype=stream/event/property + } + data + { + [original port saves here] + } + } +*/ + +PortType loadTypeFromList(const vector& list) +{ + unsigned long i,loadstate = 0; + string cmd,param; + Arts::PortType result; + + for(i=0;i cmd was %s\n",cmd.c_str()); + if(cmd == "direction") + { + if(param == "input") { + result.direction = Arts::input; + } + else if(param == "output") { + result.direction = Arts::output; + } + else assert(false); + + loadstate += 1; + } else if(cmd == "datatype") { + if(param == "audio") { + result.dataType = "float"; + } + else if(param == "string") { + result.dataType = "string"; + } + else assert(false); + + loadstate += 100; + } else if(cmd == "conntype") { + if(param == "stream") { + result.connType = Arts::conn_stream; + } + else if(param == "event") { + result.connType = Arts::conn_event; + } + else if(param == "property") { + result.connType = Arts::conn_property; + artsdebug("got property stuff\n"); + } + else assert(false); + + loadstate += 10000; + } + } + } + assert(loadstate == 10101); // should see every member exactly once + result.isMultiPort = false; + return result; +} + +void StructurePortDesc_impl::loadFromList(const vector& list) +{ + artsdebug("structureportlist-----------\n"); + unsigned long i; + string cmd,param; + vector *typelist = 0, *datalist = 0; + bool haveType = false, haveData = false; + // need both to do restore, type first + + for(i=0;i cmd was %s\n",cmd.c_str()); + if(cmd == "type") + { + assert(!haveType); // only allowed once + haveType = true; + typelist = getSubStringSeq(&list,i); + } else if(cmd == "data") { + assert(!haveData); // only allowed once + haveData = true; + datalist = getSubStringSeq(&list,i); + } else if(cmd == "x") { + _x = atol(param.c_str()); + artsdebug("X set to %ld (param was %s)\n",_x,param.c_str()); + } else if(cmd == "y") { + _y = atol(param.c_str()); + artsdebug("Y set to %ld (param was %s)\n",_y,param.c_str()); + } else if(cmd == "position") { + _position = atol(param.c_str()); + artsdebug("Position set to %ld (param was %s)\n",_position, + param.c_str()); + } else if(cmd == "name") { + _name = param; + artsdebug("Name set to %s\n",_name.c_str()); + } else if(cmd == "interface") { + _inheritedInterface = param; + artsdebug("Interface set to %s\n",_inheritedInterface.c_str()); + } + } + } + assert(haveType && haveData); + + _type = loadTypeFromList(*typelist); + + if(_type.connType == Arts::conn_property) artsdebug("have property here\n"); + PortDesc_impl::loadFromList(*datalist); + + delete typelist; + delete datalist; + artsdebug("-----------structureportlist\n"); +} + +vector *saveTypeToList(const PortType& type) +{ + vector *list = new vector; + + switch(type.direction) + { + case Arts::input: sqprintf(list,"direction=input"); + break; + case Arts::output: sqprintf(list,"direction=output"); + break; + default: assert(false); // should never happen! + } + if(type.dataType == "float") + { + sqprintf(list,"datatype=audio"); + } + else if(type.dataType == "string") + { + sqprintf(list,"datatype=string"); + } + else + { + assert(false); // should never happen! + } + switch(type.connType) + { + case Arts::conn_stream: sqprintf(list,"conntype=stream"); + break; + case Arts::conn_event: sqprintf(list,"conntype=event"); + break; + case Arts::conn_property: sqprintf(list,"conntype=property"); + break; + default: assert(false); // should never happen! + } + + return list; +} + +vector *StructurePortDesc_impl::saveToList() +{ + vector *list = new vector; + sqprintf(list,"name=%s",_name.c_str()); + sqprintf(list,"x=%ld",_x); + sqprintf(list,"y=%ld",_y); + sqprintf(list,"position=%ld",_position); + + if(!_inheritedInterface.empty()) + sqprintf(list, "interface=%s",_inheritedInterface.c_str()); + + sqprintf(list,"type"); + + vector *typelist = saveTypeToList(_type); + addSubStringSeq(list,typelist); + delete typelist; + + sqprintf(list,"data"); + + vector *portlist = PortDesc_impl::saveToList(); + addSubStringSeq(list,portlist); + delete portlist; + + return list; +} diff --git a/audiofile_artsplugin/CMakeLists.txt b/audiofile_artsplugin/CMakeLists.txt index 90c863d6..baf94bf3 100644 --- a/audiofile_artsplugin/CMakeLists.txt +++ b/audiofile_artsplugin/CMakeLists.txt @@ -27,7 +27,7 @@ link_directories( tde_add_library( arts_audiofile SHARED AUTOMOC SOURCES - audiofilearts.cc audiofilePlayObjectI.cpp + audiofilearts.cpp audiofilePlayObjectI.cpp VERSION 0.0.0 LINK mcop kmedia2_idl soundserver_idl artsflow artsflow_idl ${AUDIOFILE_LIBRARIES} @@ -36,7 +36,7 @@ tde_add_library( arts_audiofile SHARED AUTOMOC add_custom_command( OUTPUT - audiofilearts.cc audiofilearts.h + audiofilearts.cpp audiofilearts.h audiofilearts.mcoptype audiofilearts.mcopclass COMMAND ${ARTS_MCOPIDL_EXECUTABLE} -t -I${ARTS_INCLUDEDIR} ${CMAKE_CURRENT_SOURCE_DIR}/audiofilearts.idl diff --git a/audiofile_artsplugin/Makefile.am b/audiofile_artsplugin/Makefile.am index c5209797..e15e310b 100644 --- a/audiofile_artsplugin/Makefile.am +++ b/audiofile_artsplugin/Makefile.am @@ -4,14 +4,14 @@ noinst_HEADERS = audiofilePlayObjectI.h lib_LTLIBRARIES = libarts_audiofile.la libarts_audiofile_la_COMPILE_FIRST = audiofilearts.h -libarts_audiofile_la_SOURCES = audiofilearts.cc audiofilePlayObjectI.cpp +libarts_audiofile_la_SOURCES = audiofilearts.cpp audiofilePlayObjectI.cpp libarts_audiofile_la_LDFLAGS = $(all_libraries) -module -no-undefined libarts_audiofile_la_LIBADD = -lkmedia2_idl -lsoundserver_idl -lartsflow -laudiofile libarts_audiofile_la_METASOURCES = AUTO audiofilearts.mcopclass: audiofilearts.h audiofilearts.mcoptype: audiofilearts.h -audiofilearts.cc audiofilearts.h: $(srcdir)/audiofilearts.idl $(MCOPIDL) +audiofilearts.cpp audiofilearts.h: $(srcdir)/audiofilearts.idl $(MCOPIDL) $(MCOPIDL) -t -I$(kde_includes)/arts $(srcdir)/audiofilearts.idl mcoptypedir = $(libdir)/mcop @@ -20,4 +20,4 @@ mcoptype_DATA = audiofilearts.mcoptype audiofilearts.mcopclass mcopclassdir = $(libdir)/mcop/Arts mcopclass_DATA = audiofilePlayObject.mcopclass -CLEANFILES=audiofilearts.h audiofilearts.cc audiofilearts.mcopclass audiofilearts.mcoptype +CLEANFILES=audiofilearts.h audiofilearts.cpp audiofilearts.mcopclass audiofilearts.mcoptype diff --git a/doc/artsbuilder/faq.docbook b/doc/artsbuilder/faq.docbook index 8bb7ae4c..65a14c87 100644 --- a/doc/artsbuilder/faq.docbook +++ b/doc/artsbuilder/faq.docbook @@ -414,7 +414,7 @@ Short answer: no, &arts; will not work if you compile it with gcc-3.0. Long answer: In the official release, there are two gcc-3.0 bugs which affect &arts;. The first, gcc-3.0 bug c++/2733 is relatively harmless (and has to do -with problems with the asm statement). It breaks compilation of convert.cc. It +with problems with the asm statement). It breaks compilation of convert.cpp. It has been fixed in the gcc-3.0 CVS, and will no longer be a problem with gcc-3.0.1 and higher. A workaround has also been added to the CVS version of KDE/aRts. @@ -1018,7 +1018,7 @@ succeeds, which eventually leads to consuming all CPU power and reporting might get supplied with wrong information how much to write. Artsd will then stop with an assertion like: -artsd: audiosubsys.cc:458: void Arts::AudioSubSystem::handleIO(int): +artsd: audiosubsys.cpp:458: void Arts::AudioSubSystem::handleIO(int): Assertion `len == can_write' failed. Aborted diff --git a/doc/artsbuilder/helping.docbook b/doc/artsbuilder/helping.docbook index 72b2ff2b..dc635701 100644 --- a/doc/artsbuilder/helping.docbook +++ b/doc/artsbuilder/helping.docbook @@ -224,7 +224,7 @@ written. Source files should have no capitalization in the name. They should have the name of the class when they implement a single class. Their -extension is .cc if they refer to +extension is .cpp if they refer to &Qt;/&GUI; independent code, and .cpp if they refer to &Qt;/&GUI; dependant code. Implementation files for interfaces should be called diff --git a/doc/artsbuilder/mcop.docbook b/doc/artsbuilder/mcop.docbook index f140bff9..59d9a011 100644 --- a/doc/artsbuilder/mcop.docbook +++ b/doc/artsbuilder/mcop.docbook @@ -1093,7 +1093,7 @@ interface Hello { You pass that through the &IDL; compiler by calling mcopidl hello.idl, which will in turn generate -hello.cc and hello.h. To +hello.cpp and hello.h. To implement it, you need to define a C++-class that inherits the skeleton: @@ -1991,7 +1991,7 @@ objects and the CORBA interface look natural, but it didn't, because CORBA knew nothing at all about streams. &MCOP; does. Look at the code (something like -simplesoundserver_impl.cc). Way better! Streams +simplesoundserver_impl.cpp). Way better! Streams can be declared in the interface of modules, and implemented in a natural looking way. diff --git a/mpeglib/lib/splay/huffmantable.cpp b/mpeglib/lib/splay/huffmantable.cpp index 223e6069..16fde4af 100644 --- a/mpeglib/lib/splay/huffmantable.cpp +++ b/mpeglib/lib/splay/huffmantable.cpp @@ -2,7 +2,7 @@ (C) 1997 by Jung woo-jae */ -// Huffmantable.cc +// Huffmantable.cpp // It contains initialized huffman table for MPEG layer 3 diff --git a/mpeglib/lib/splay/mpeglayer1.cpp b/mpeglib/lib/splay/mpeglayer1.cpp index 2d939d9d..ec5ef907 100644 --- a/mpeglib/lib/splay/mpeglayer1.cpp +++ b/mpeglib/lib/splay/mpeglayer1.cpp @@ -2,7 +2,7 @@ (C) 1997 by Jung woo-jae */ -// Mpeglayer1.cc +// Mpeglayer1.cpp // It's for MPEG Layer 1 diff --git a/mpeglib/lib/splay/mpeglayer2.cpp b/mpeglib/lib/splay/mpeglayer2.cpp index 1b907a07..a5a809b6 100644 --- a/mpeglib/lib/splay/mpeglayer2.cpp +++ b/mpeglib/lib/splay/mpeglayer2.cpp @@ -2,7 +2,7 @@ (C) 1997 by Jung woo-jae */ -// Mpeglayer2.cc +// Mpeglayer2.cpp // It's for MPEG Layer 2 diff --git a/mpeglib/lib/splay/mpeglayer3.cpp b/mpeglib/lib/splay/mpeglayer3.cpp index 3abed128..3752859a 100644 --- a/mpeglib/lib/splay/mpeglayer3.cpp +++ b/mpeglib/lib/splay/mpeglayer3.cpp @@ -2,7 +2,7 @@ (C) 1997 by Jung woo-jae */ -// Mpeglayer3.cc +// Mpeglayer3.cpp // It's for MPEG Layer 3 // I've made array of superior functions for speed. // Extend TO_FOUR_THIRDS to negative. diff --git a/mpeglib/lib/splay/mpegtable.cpp b/mpeglib/lib/splay/mpegtable.cpp index be539ddd..f602166e 100644 --- a/mpeglib/lib/splay/mpegtable.cpp +++ b/mpeglib/lib/splay/mpegtable.cpp @@ -2,7 +2,7 @@ (C) 1997 by Jung woo-jae */ -// Mpegtable.cc +// Mpegtable.cpp // It has tables for MPEG layer 1, 2 and a part of layer 3 diff --git a/mpeglib/lib/splay/mpegtoraw.cpp b/mpeglib/lib/splay/mpegtoraw.cpp index 93143bbe..d114eba9 100644 --- a/mpeglib/lib/splay/mpegtoraw.cpp +++ b/mpeglib/lib/splay/mpegtoraw.cpp @@ -2,7 +2,7 @@ (C) 1997 by Jung woo-jae */ -// Mpegtoraw.cc +// Mpegtoraw.cpp // Server which get mpeg format and put raw format. diff --git a/mpeglib_artsplug/CMakeLists.txt b/mpeglib_artsplug/CMakeLists.txt index 3a9fbd8c..c64b7320 100644 --- a/mpeglib_artsplug/CMakeLists.txt +++ b/mpeglib_artsplug/CMakeLists.txt @@ -31,8 +31,8 @@ link_directories( tde_add_library( arts_mpeglib SHARED SOURCES - decoderBaseObject.cc - splayPlayObject.cc + decoderBaseObject.cpp + splayPlayObject.cpp decoderBaseObject_impl.cpp oggPlayObject_impl.cpp mpgPlayObject_impl.cpp @@ -49,7 +49,7 @@ tde_add_library( arts_mpeglib SHARED add_custom_command( OUTPUT - decoderBaseObject.cc decoderBaseObject.h + decoderBaseObject.cpp decoderBaseObject.h COMMAND ${ARTS_MCOPIDL_EXECUTABLE} -I${ARTS_INCLUDEDIR} ${CMAKE_CURRENT_SOURCE_DIR}/decoderBaseObject.idl DEPENDS decoderBaseObject.idl @@ -60,7 +60,7 @@ add_custom_command( tde_add_library( arts_splay SHARED SOURCES - splayPlayObject.cc + splayPlayObject.cpp splayPlayObject_impl.cpp VERSION 0.0.0 LINK mpeg-shared ${ARTS_LIBRARIES} @@ -69,7 +69,7 @@ tde_add_library( arts_splay SHARED add_custom_command( OUTPUT - splayPlayObject.cc splayPlayObject.h + splayPlayObject.cpp splayPlayObject.h COMMAND ${ARTS_MCOPIDL_EXECUTABLE} -I${ARTS_INCLUDEDIR} ${CMAKE_CURRENT_SOURCE_DIR}/splayPlayObject.idl DEPENDS splayPlayObject.idl diff --git a/mpeglib_artsplug/Makefile.am b/mpeglib_artsplug/Makefile.am index 1fe9b85e..190d42f5 100644 --- a/mpeglib_artsplug/Makefile.am +++ b/mpeglib_artsplug/Makefile.am @@ -19,9 +19,9 @@ EXTRA_DIST = doemacs \ BUILT_SOURCES = decoderBaseObject.h \ - decoderBaseObject.cc \ + decoderBaseObject.cpp \ splayPlayObject.h \ - splayPlayObject.cc + splayPlayObject.cpp noinst_HEADERS = mp3PlayObject_impl.h \ @@ -45,10 +45,10 @@ INCLUDES = -I../mpeglib/lib -I$(srcdir)/../mpeglib/lib $(ARTS_INCLUDES) $(all lib_LTLIBRARIES = libarts_mpeglib.la \ libarts_splay.la -decoderBaseObject.cc decoderBaseObject.h : $(srcdir)/decoderBaseObject.idl +decoderBaseObject.cpp decoderBaseObject.h : $(srcdir)/decoderBaseObject.idl $(MCOPIDL) -I$(kde_includes)/arts $(srcdir)/decoderBaseObject.idl -splayPlayObject.cc splayPlayObject.h : $(srcdir)/splayPlayObject.idl +splayPlayObject.cpp splayPlayObject.h : $(srcdir)/splayPlayObject.idl $(MCOPIDL) -I$(kde_includes)/arts $(srcdir)/splayPlayObject.idl mpeglibartsplugdir = $(includedir)/mpeglib_artsplug @@ -62,8 +62,8 @@ mpeglibartsplug_HEADERS = decoderBaseObject_impl.h \ -libarts_mpeglib_la_SOURCES = decoderBaseObject.cc \ - splayPlayObject.cc \ +libarts_mpeglib_la_SOURCES = decoderBaseObject.cpp \ + splayPlayObject.cpp \ decoderBaseObject_impl.cpp \ oggPlayObject_impl.cpp \ mpgPlayObject_impl.cpp \ @@ -82,7 +82,7 @@ libarts_mpeglib_la_LDFLAGS = $(all_libraries) \ libarts_mpeglib_la_LIBADD = $(top_builddir)/mpeglib/lib/libmpeg.la \ $(LIB_ARTS) -libarts_splay_la_SOURCES = splayPlayObject.cc \ +libarts_splay_la_SOURCES = splayPlayObject.cpp \ splayPlayObject_impl.cpp libarts_splay_la_LDFLAGS = $(all_libraries) \ diff --git a/mpeglib_artsplug/doemacs b/mpeglib_artsplug/doemacs index a875517d..3d3a296e 100644 --- a/mpeglib_artsplug/doemacs +++ b/mpeglib_artsplug/doemacs @@ -4,7 +4,7 @@ A=`find . | grep -v moc > flist.txt` A=`grep "\.cpp$" flist.txt >cpp.txt` A=`grep "\.h$" flist.txt >h.txt` A=`grep "\.c$" flist.txt >c.txt` -A=`grep "\.cc$" flist.txt >cc.txt` +A=`grep "\.cpp$" flist.txt >cc.txt` A=`grep "\.idl$" flist.txt >idl.txt` A=`grep "\.defs$" flist.txt >defs.txt` C=`cat c.txt` diff --git a/mpg123_artsplugin/Makefile.am b/mpg123_artsplugin/Makefile.am index 15cf345b..b4d94619 100644 --- a/mpg123_artsplugin/Makefile.am +++ b/mpg123_artsplugin/Makefile.am @@ -6,14 +6,14 @@ noinst_HEADERS = mpg123PlayObject_impl.h lib_LTLIBRARIES = libmpg123arts.la libmpg123arts_la_COMPILE_FIRST = mpg123arts.h -libmpg123arts_la_SOURCES = mpg123arts.cc mpg123PlayObject_impl.cpp dxhead.c +libmpg123arts_la_SOURCES = mpg123arts.cpp mpg123PlayObject_impl.cpp dxhead.c libmpg123arts_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined libmpg123arts_la_LIBADD = -lkmedia2_idl -lsoundserver_idl -lartsflow mpg123/libmpg123.la libmpg123arts_la_METASOURCES = AUTO mpg123arts.mcoptype: mpg123arts.h mpg123arts.mcopclass: mpg123arts.h -mpg123arts.cc mpg123arts.h: $(srcdir)/mpg123arts.idl $(MCOPIDL) +mpg123arts.cpp mpg123arts.h: $(srcdir)/mpg123arts.idl $(MCOPIDL) $(MCOPIDL) -t -I$(kde_includes)/arts $(srcdir)/mpg123arts.idl mcoptypedir = $(libdir)/mcop diff --git a/noatun/Makefile.am b/noatun/Makefile.am index 5a3075ce..f0d4de33 100644 --- a/noatun/Makefile.am +++ b/noatun/Makefile.am @@ -21,7 +21,7 @@ noatun20update_LDADD = $(LIB_QT) messages: $(EXTRACTRC) `find . -name "*.rc" -o -name "*.ui"` > rc.cpp - $(XGETTEXT) rc.cpp `find . -name "*.cc" -o -name "*.cpp" -o -name "*.h"` -o $(podir)/noatun.pot + $(XGETTEXT) rc.cpp `find . -o -name "*.cpp" -o -name "*.h"` -o $(podir)/noatun.pot api: $(mkinstalldirs) $(top_builddir)/noatun/apidocs/libnoatun diff --git a/noatun/library/noatunarts/CMakeLists.txt b/noatun/library/noatunarts/CMakeLists.txt index fa0aa905..1fd853e4 100644 --- a/noatun/library/noatunarts/CMakeLists.txt +++ b/noatun/library/noatunarts/CMakeLists.txt @@ -27,7 +27,7 @@ link_directories( tde_add_library( noatunarts SHARED AUTOMOC SOURCES - noatunarts.cc fft.c Equalizer_impl.cpp + noatunarts.cpp fft.c Equalizer_impl.cpp FFTScopes.cpp StereoEffectStack_impl.cpp StereoVolumeControl_impl.cpp Session_impl.cpp LINK @@ -38,7 +38,7 @@ tde_add_library( noatunarts SHARED AUTOMOC add_custom_command( OUTPUT - noatunarts.cc noatunarts.h + noatunarts.cpp noatunarts.h COMMAND ${ARTS_MCOPIDL_EXECUTABLE} -t -I${ARTS_INCLUDEDIR} ${CMAKE_CURRENT_SOURCE_DIR}/noatunarts.idl DEPENDS noatunarts.idl diff --git a/noatun/library/noatunarts/Equalizer_impl.cpp b/noatun/library/noatunarts/Equalizer_impl.cpp index 552c3f91..40bcd35f 100644 --- a/noatun/library/noatunarts/Equalizer_impl.cpp +++ b/noatun/library/noatunarts/Equalizer_impl.cpp @@ -184,7 +184,7 @@ public: while (left -#include -#include -#include -#include -#include "debug.h" -#include -#include - -using namespace Arts; - -class ExtraStereo_impl : virtual public ExtraStereo_skel, - virtual public StdSynthModule -{ - float _intensity; -// StereoEffectGUI mStereoEffectGUI; -public: - float intensity() { return _intensity; } - void intensity(float newValue) { - _intensity = newValue; -// cout << " **** INTENSITY = " << newValue << endl; - } - - ExtraStereo_impl() : _intensity(2.0) - { -// mStereoEffectGUI = DynamicCast(server.createObject("Arts::ExtraStereo")); -// DynamicRequest(mStereoEffectGUI).method("_set_effect").param(*this).invoke(); - - } - void calculateBlock(unsigned long samples) - { - unsigned long i; - - for(i = 0; i < samples; i++) - { - float average = (inleft[i] + inright[i]) / 2.0; - - float outleftnew = average + (inleft[i] - average) * _intensity; - if(outleftnew > 1.0) outleft[i] = 1.0; - else if(outleftnew < -1.0) outleft[i] = -1.0; - else outleft[i] = outleftnew; - - float outrightnew = average + (inright[i] - average) * _intensity; - if(outrightnew > 1.0) outright[i] = 1.0; - else if(outrightnew < -1.0) outright[i] = -1.0; - else outright[i] = outrightnew; - } - } -}; - - -class VoiceRemoval_impl : virtual public VoiceRemoval_skel, - virtual public StdSynthModule -{ -public: - - VoiceRemoval_impl() - { - - } - // This is based on the work of Anders Carlsson - void calculateBlock(unsigned long samples) - { - for (unsigned i = 0; i < samples; i++) - { - float outleftnew=inleft[i]-inright[i]; - float outrightnew=inright[i]-inleft[i]; - - if (inleft[i] < -1.0) outleftnew = -1.0; - else if (inleft[i] > 1.0) outleftnew = 1.0; - - if (inright[i] < -1.0) outrightnew = -1.0; - else if (inright[i] > 1.0) outrightnew = 1.0; - outleft[i] = outleftnew; - outright[i] = outrightnew; - } - - } -}; - -class RawWriter_impl : virtual public RawWriter_skel, - virtual public StdSynthModule -{ - int mFd; -public: - RawWriter_impl() - { - std::string file=getenv("HOME"); - file.append("/arts-write.raw"); - mFd=::open(file.c_str(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); - } - ~RawWriter_impl() - { - ::close(mFd); - } - // This is based on the work of Anders Carlsson - void calculateBlock(unsigned long samples) - { - for (unsigned i = 0; i < samples; i++) - { - outleft[i]=inleft[i]; - outright[i]=inright[i]; - } - unsigned char *buffer=new unsigned char[samples*4]; - convert_stereo_2float_i16le(samples, - inleft, inright, buffer); - ::write(mFd, (const void*)buffer, samples*4); - delete [] buffer; - } -}; - -class ExtraStereoGuiFactory_impl : public ExtraStereoGuiFactory_skel -{ -public: - Widget createGui(Object object) - { - arts_return_val_if_fail(!object.isNull(), Arts::Widget::null()); - - ExtraStereo e = DynamicCast(object); - arts_return_val_if_fail(!e.isNull(), Arts::Widget::null()); - - HBox hbox; - hbox.width(80); - hbox.height(80); - hbox.show(); - - - Poti intense; - intense.caption("Intensity"); - intense.color("red"); - intense.min(0); - intense.max(5); - intense.value(e.intensity()); - intense.parent(hbox); - intense.show(); - connect(intense,"value_changed", e, "intensity"); - - hbox._addChild(intense,"intensityWidget"); - - return hbox; - } -}; - - -REGISTER_IMPLEMENTATION(ExtraStereo_impl); -REGISTER_IMPLEMENTATION(VoiceRemoval_impl); -REGISTER_IMPLEMENTATION(RawWriter_impl); -REGISTER_IMPLEMENTATION(ExtraStereoGuiFactory_impl); - - diff --git a/noatun/modules/artseffects/extrastereo_impl.cpp b/noatun/modules/artseffects/extrastereo_impl.cpp new file mode 100644 index 00000000..3dc92705 --- /dev/null +++ b/noatun/modules/artseffects/extrastereo_impl.cpp @@ -0,0 +1,153 @@ +#include "artsgui.h" +#include "artseffects.h" +#include "stdsynthmodule.h" +#include +#include +#include +#include +#include +#include "debug.h" +#include +#include + +using namespace Arts; + +class ExtraStereo_impl : virtual public ExtraStereo_skel, + virtual public StdSynthModule +{ + float _intensity; +// StereoEffectGUI mStereoEffectGUI; +public: + float intensity() { return _intensity; } + void intensity(float newValue) { + _intensity = newValue; +// cout << " **** INTENSITY = " << newValue << endl; + } + + ExtraStereo_impl() : _intensity(2.0) + { +// mStereoEffectGUI = DynamicCast(server.createObject("Arts::ExtraStereo")); +// DynamicRequest(mStereoEffectGUI).method("_set_effect").param(*this).invoke(); + + } + void calculateBlock(unsigned long samples) + { + unsigned long i; + + for(i = 0; i < samples; i++) + { + float average = (inleft[i] + inright[i]) / 2.0; + + float outleftnew = average + (inleft[i] - average) * _intensity; + if(outleftnew > 1.0) outleft[i] = 1.0; + else if(outleftnew < -1.0) outleft[i] = -1.0; + else outleft[i] = outleftnew; + + float outrightnew = average + (inright[i] - average) * _intensity; + if(outrightnew > 1.0) outright[i] = 1.0; + else if(outrightnew < -1.0) outright[i] = -1.0; + else outright[i] = outrightnew; + } + } +}; + + +class VoiceRemoval_impl : virtual public VoiceRemoval_skel, + virtual public StdSynthModule +{ +public: + + VoiceRemoval_impl() + { + + } + // This is based on the work of Anders Carlsson + void calculateBlock(unsigned long samples) + { + for (unsigned i = 0; i < samples; i++) + { + float outleftnew=inleft[i]-inright[i]; + float outrightnew=inright[i]-inleft[i]; + + if (inleft[i] < -1.0) outleftnew = -1.0; + else if (inleft[i] > 1.0) outleftnew = 1.0; + + if (inright[i] < -1.0) outrightnew = -1.0; + else if (inright[i] > 1.0) outrightnew = 1.0; + outleft[i] = outleftnew; + outright[i] = outrightnew; + } + + } +}; + +class RawWriter_impl : virtual public RawWriter_skel, + virtual public StdSynthModule +{ + int mFd; +public: + RawWriter_impl() + { + std::string file=getenv("HOME"); + file.append("/arts-write.raw"); + mFd=::open(file.c_str(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); + } + ~RawWriter_impl() + { + ::close(mFd); + } + // This is based on the work of Anders Carlsson + void calculateBlock(unsigned long samples) + { + for (unsigned i = 0; i < samples; i++) + { + outleft[i]=inleft[i]; + outright[i]=inright[i]; + } + unsigned char *buffer=new unsigned char[samples*4]; + convert_stereo_2float_i16le(samples, + inleft, inright, buffer); + ::write(mFd, (const void*)buffer, samples*4); + delete [] buffer; + } +}; + +class ExtraStereoGuiFactory_impl : public ExtraStereoGuiFactory_skel +{ +public: + Widget createGui(Object object) + { + arts_return_val_if_fail(!object.isNull(), Arts::Widget::null()); + + ExtraStereo e = DynamicCast(object); + arts_return_val_if_fail(!e.isNull(), Arts::Widget::null()); + + HBox hbox; + hbox.width(80); + hbox.height(80); + hbox.show(); + + + Poti intense; + intense.caption("Intensity"); + intense.color("red"); + intense.min(0); + intense.max(5); + intense.value(e.intensity()); + intense.parent(hbox); + intense.show(); + connect(intense,"value_changed", e, "intensity"); + + hbox._addChild(intense,"intensityWidget"); + + return hbox; + } +}; + + +REGISTER_IMPLEMENTATION(ExtraStereo_impl); +REGISTER_IMPLEMENTATION(VoiceRemoval_impl); +REGISTER_IMPLEMENTATION(RawWriter_impl); +REGISTER_IMPLEMENTATION(ExtraStereoGuiFactory_impl); + + diff --git a/noatun/modules/artseffects/extrastereogui_impl.cc b/noatun/modules/artseffects/extrastereogui_impl.cc deleted file mode 100644 index 92148ba0..00000000 --- a/noatun/modules/artseffects/extrastereogui_impl.cc +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -#include "extrastereogui_impl.h" - -namespace Arts { - -ExtraStereoGUI_impl::ExtraStereoGUI_impl() : TQWidget(0) -{ - (new TQHBoxLayout(this))->setAutoAdd(true); - mSlider=new TQSlider(0,100,10, 0,Qt::Horizontal, this); - mSlider->show(); - show(); -} - -void ExtraStereoGUI_impl::changeSlider(int v) -{ - effect.intensity((float)v/100.0); -} - -void ExtraStereoGUI_impl::setEffect(StereoEffect newEffect) -{ - effect = DynamicCast(newEffect); -} - -REGISTER_IMPLEMENTATION(ExtraStereoGUI_impl); - -}; - diff --git a/noatun/modules/artseffects/extrastereogui_impl.cpp b/noatun/modules/artseffects/extrastereogui_impl.cpp new file mode 100644 index 00000000..92148ba0 --- /dev/null +++ b/noatun/modules/artseffects/extrastereogui_impl.cpp @@ -0,0 +1,28 @@ +#include +#include +#include "extrastereogui_impl.h" + +namespace Arts { + +ExtraStereoGUI_impl::ExtraStereoGUI_impl() : TQWidget(0) +{ + (new TQHBoxLayout(this))->setAutoAdd(true); + mSlider=new TQSlider(0,100,10, 0,Qt::Horizontal, this); + mSlider->show(); + show(); +} + +void ExtraStereoGUI_impl::changeSlider(int v) +{ + effect.intensity((float)v/100.0); +} + +void ExtraStereoGUI_impl::setEffect(StereoEffect newEffect) +{ + effect = DynamicCast(newEffect); +} + +REGISTER_IMPLEMENTATION(ExtraStereoGUI_impl); + +}; + diff --git a/noatun/modules/winskin/vis/CMakeLists.txt b/noatun/modules/winskin/vis/CMakeLists.txt index 25b86e8a..fc206056 100644 --- a/noatun/modules/winskin/vis/CMakeLists.txt +++ b/noatun/modules/winskin/vis/CMakeLists.txt @@ -27,7 +27,7 @@ link_directories( tde_add_library( winskinvis SHARED AUTOMOC SOURCES - winskinvis.cc + winskinvis.cpp winSkinFFT_impl.cpp realFFT.cpp realFFTFilter.cpp visQueue.cpp LINK @@ -37,7 +37,7 @@ tde_add_library( winskinvis SHARED AUTOMOC add_custom_command( OUTPUT - winskinvis.cc winskinvis.h + winskinvis.cpp winskinvis.h COMMAND ${ARTS_MCOPIDL_EXECUTABLE} -t -I${ARTS_INCLUDEDIR} ${CMAKE_CURRENT_SOURCE_DIR}/winskinvis.idl DEPENDS winskinvis.idl diff --git a/noatun/modules/winskin/vis/Makefile.am b/noatun/modules/winskin/vis/Makefile.am index b72036d3..473da0cb 100644 --- a/noatun/modules/winskin/vis/Makefile.am +++ b/noatun/modules/winskin/vis/Makefile.am @@ -1,15 +1,15 @@ INCLUDES= -I$(kde_includes)/arts $(all_includes) KDE_OPTIONS = nofinal -DISTCLEANFILES = winskinvis.h winskinvis.cc +DISTCLEANFILES = winskinvis.h winskinvis.cpp winskinvis.mcopclass: winskinvis.h winskinvis.mcoptype: winskinvis.h -winskinvis.cc winskinvis.h : $(srcdir)/winskinvis.idl +winskinvis.cpp winskinvis.h : $(srcdir)/winskinvis.idl $(MCOPIDL) -t -I$(kde_includes)/arts $(srcdir)/winskinvis.idl lib_LTLIBRARIES = libwinskinvis.la -libwinskinvis_la_SOURCES= winskinvis.cc \ +libwinskinvis_la_SOURCES= winskinvis.cpp \ winSkinFFT_impl.cpp realFFT.cpp \ realFFTFilter.cpp visQueue.cpp @@ -18,7 +18,7 @@ libwinskinvis_la_LDFLAGS= $(all_libraries) -avoid-version \ -no-undefined libwinskinvis_la_LIBADD = -lkmedia2_idl -lsoundserver_idl -lartsflow -lartsflow_idl -lmcop -libwinskinvis_la_COMPILE_FIRST = winskinvis.cc +libwinskinvis_la_COMPILE_FIRST = winskinvis.cpp libwinskinvis_la_METASOURCES = AUTO diff --git a/oggvorbis_artsplugin/CMakeLists.txt b/oggvorbis_artsplugin/CMakeLists.txt index fbc2db3e..bfb00773 100644 --- a/oggvorbis_artsplugin/CMakeLists.txt +++ b/oggvorbis_artsplugin/CMakeLists.txt @@ -27,7 +27,7 @@ link_directories( tde_add_kpart( liboggarts AUTOMOC SOURCES - oggarts.cc oggPlayObject_impl.cpp + oggarts.cpp oggPlayObject_impl.cpp VERSION 0.0.0 LINK mcop kmedia2_idl soundserver_idl artsflow artsflow_idl ${ARTS_LIBRARIES} @@ -37,7 +37,7 @@ tde_add_kpart( liboggarts AUTOMOC add_custom_command( OUTPUT - oggarts.cc oggarts.h + oggarts.cpp oggarts.h oggarts.mcoptype oggarts.mcopclass COMMAND ${ARTS_MCOPIDL_EXECUTABLE} -t -I${ARTS_INCLUDEDIR} ${CMAKE_CURRENT_SOURCE_DIR}/oggarts.idl diff --git a/oggvorbis_artsplugin/Makefile.am b/oggvorbis_artsplugin/Makefile.am index aeec6205..d562eb8b 100644 --- a/oggvorbis_artsplugin/Makefile.am +++ b/oggvorbis_artsplugin/Makefile.am @@ -6,14 +6,14 @@ noinst_HEADERS = oggPlayObject_impl.h lib_LTLIBRARIES = liboggarts.la liboggarts_la_COMPILE_FIRST = oggarts.h -liboggarts_la_SOURCES = oggarts.cc oggPlayObject_impl.cpp +liboggarts_la_SOURCES = oggarts.cpp oggPlayObject_impl.cpp liboggarts_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined liboggarts_la_LIBADD = -lkmedia2_idl -lsoundserver_idl -lartsflow -lvorbisfile -lvorbis -logg liboggarts_la_METASOURCES = AUTO oggarts.mcopclass: oggarts.h oggarts.mcoptype: oggarts.h -oggarts.cc oggarts.h: $(srcdir)/oggarts.idl $(MCOPIDL) +oggarts.cpp oggarts.h: $(srcdir)/oggarts.idl $(MCOPIDL) $(MCOPIDL) -t -I$(kde_includes)/arts $(srcdir)/oggarts.idl mcoptypedir = $(libdir)/mcop diff --git a/tdemid/README b/tdemid/README index c391c24c..a9b806d8 100644 --- a/tdemid/README +++ b/tdemid/README @@ -64,7 +64,7 @@ Index and do a 'make' . Simple , isn't it ? By default it will use the external midi device, if you want to use another - one (fm, awe, or anything else), edit the file main.cc and change the value + one (fm, awe, or anything else), edit the file main.cpp and change the value of DEFAULT_DEVICE to the one you want, or specify the -d option as in : consoletdemid -d 1 mymidifile.mid @@ -73,7 +73,7 @@ Index ----------------- No installing of consoleKMid is actually done, just copy the consoleKMid file yourself to where you want (usually /usr/local/bin ). To use the fm device, - you should specify in fmout.cc the path to where the fm patches are installed + you should specify in fmout.cpp the path to where the fm patches are installed ( /etc by default) 5. Running @@ -92,7 +92,7 @@ Index consoletdemid -M /opt/kde/share/apps/tdemid/maps/YamahaPSS790.map mymidifile - You can also edit main.cc in the player directory and change the value of + You can also edit main.cpp in the player directory and change the value of DEFAULT_MAP to whatever you want, so that you don't need to specify the -M option each time you run consoletdemid. diff --git a/tdemid/slman.cpp b/tdemid/slman.cpp index ca441850..7f63368b 100644 --- a/tdemid/slman.cpp +++ b/tdemid/slman.cpp @@ -1,6 +1,6 @@ /************************************************************************** - slman.cc - SongList Manager, which holds a set of collections (SongLists) + slman.cpp - SongList Manager, which holds a set of collections (SongLists) Copyright (C) 1997,98 Antonio Larrosa Jimenez This program is free software; you can redistribute it and/or modify diff --git a/tdemid/songlist.cpp b/tdemid/songlist.cpp index cc2572d8..01a03a94 100644 --- a/tdemid/songlist.cpp +++ b/tdemid/songlist.cpp @@ -1,6 +1,6 @@ /************************************************************************** - songlist.cc - class SongList, which holds a list of songs (collection) + songlist.cpp - class SongList, which holds a list of songs (collection) Copyright (C) 1997,98 Antonio Larrosa Jimenez This program is free software; you can redistribute it and/or modify diff --git a/xine_artsplugin/CMakeLists.txt b/xine_artsplugin/CMakeLists.txt index 1013d3a9..0b647c96 100644 --- a/xine_artsplugin/CMakeLists.txt +++ b/xine_artsplugin/CMakeLists.txt @@ -33,7 +33,7 @@ link_directories( tde_add_library( arts_xine SHARED AUTOMOC SOURCES - xinePlayObject.cc + xinePlayObject.cpp xinePlayObject_impl.cpp audio_fifo_out.c VERSION 0.0.0 @@ -45,7 +45,7 @@ tde_add_library( arts_xine SHARED AUTOMOC add_custom_command( OUTPUT - xinePlayObject.cc xinePlayObject.h + xinePlayObject.cpp xinePlayObject.h COMMAND ${ARTS_MCOPIDL_EXECUTABLE} -I${ARTS_INCLUDEDIR} ${CMAKE_CURRENT_SOURCE_DIR}/xinePlayObject.idl DEPENDS xinePlayObject.idl diff --git a/xine_artsplugin/Makefile.am b/xine_artsplugin/Makefile.am index 395873b5..753ca766 100644 --- a/xine_artsplugin/Makefile.am +++ b/xine_artsplugin/Makefile.am @@ -4,7 +4,7 @@ AM_CFLAGS = -U__STRICT_ANSI__ lib_LTLIBRARIES = libarts_xine.la -libarts_xine_la_SOURCES = xinePlayObject.cc \ +libarts_xine_la_SOURCES = xinePlayObject.cpp \ xinePlayObject_impl.cpp \ audio_fifo_out.c libarts_xine_la_LDFLAGS = $(all_libraries) -module -no-undefined -pthread @@ -14,7 +14,7 @@ libarts_xine_la_LIBADD = $(XINE_LIBS) $(LIBPTHREAD) $(LIB_X11) $(LIB_XEXT) $(LIB libarts_xine_la_METASOURCES = AUTO $(srcdir)/xinePlayObject_impl.cpp: xinePlayObject.h -xinePlayObject.cc xinePlayObject.h: $(srcdir)/xinePlayObject.idl +xinePlayObject.cpp xinePlayObject.h: $(srcdir)/xinePlayObject.idl $(MCOPIDL) -I$(kde_includes)/arts $(srcdir)/xinePlayObject.idl noinst_HEADERS = xinePlayObject_impl.h audio_fifo_out.h -- cgit v1.2.1