--- linuxsampler/trunk/src/engines/sfz/sfz.h 2010/05/30 11:40:31 2101 +++ linuxsampler/trunk/src/engines/sfz/sfz.h 2011/08/01 19:08:09 2224 @@ -3,7 +3,7 @@ * LinuxSampler - modular, streaming capable sampler * * * * Copyright (C) 2008 Anders Dahnielson * - * Copyright (C) 2009 - 2010 Anders Dahnielson and Grigor Iliev * + * Copyright (C) 2009 - 2011 Anders Dahnielson and Grigor Iliev * * * * 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 * @@ -47,17 +47,20 @@ class Group; class Instrument; class File; + class LookupTable; class Sample : public LinuxSampler::SampleFileBase { public: - Sample(String File, bool DontClose = false) : LinuxSampler::SampleFileBase(File, DontClose) { } + Sample(String File, bool DontClose = false, uint offset = 0): LinuxSampler::SampleFileBase(File, DontClose) { + Offset = offset; + } virtual ~Sample() { } }; // Enumerations enum sw_vel_t { VEL_CURRENT, VEL_PREVIOUS }; enum off_mode_t { OFF_FAST, OFF_NORMAL }; - enum loop_mode_t { NO_LOOP, ONE_SHOT, LOOP_CONTINUOUS, LOOP_SUSTAIN }; + enum loop_mode_t { NO_LOOP, ONE_SHOT, LOOP_CONTINUOUS, LOOP_SUSTAIN, LOOP_UNSET }; enum curve_t { GAIN, POWER }; enum filter_t { LPF_1P, HPF_1P, BPF_1P, BRF_1P, APF_1P, LPF_2P, HPF_2P, BPF_2P, BRF_2P, PKF_2P, @@ -69,7 +72,7 @@ class SampleManager : public LinuxSampler::SampleManager { public: - Sample* FindSample(std::string samplePath); + Sample* FindSample(std::string samplePath, int offset); protected: virtual void OnSampleInUse(Sample* pSample) { @@ -237,6 +240,20 @@ EG(); }; + class LFO + { + public: + float freq; // 0 to 20 Hz + uint wave; // 0 to 4294967296 + float delay; // 0 to 100 seconds + float volume; // -144 to 6 dB + int pitch; // -9600 to 9600 cents + int cutoff; // -9600 to 9600 cents + float resonance; // 0 to 40 dB + float pan; // -100 to 100 % + LFO(); + }; + // Fixed size array with copy-on-write semantics template class Array @@ -297,7 +314,7 @@ int lovel; int hivel; Array locc; Array hicc; int lobend; int hibend; - int lobpm; int hibpm; + float lobpm; float hibpm; int lochanaft; int hichanaft; int lopolyaft; int hipolyaft; int loprog; int hiprog; @@ -320,7 +337,7 @@ trigger_t trigger; uint group; - optional off_by; + uint off_by; off_mode_t off_mode; Array on_locc; Array on_hicc; @@ -366,6 +383,8 @@ filter_t fil_type; filter_t fil2_type; optional cutoff; optional cutoff2; Array cutoff_oncc; Array cutoff2_oncc; + int cutoff_cc; // TODO: this is just a temporary fix to avoid + // looping through the cutoff_oncc array Array cutoff_smoothcc; Array cutoff2_smoothcc; Array cutoff_stepcc; Array cutoff2_stepcc; Array cutoff_curvecc; Array cutoff2_curvecc; @@ -393,23 +412,29 @@ //Deprecated (from version 1) float ampeg_delay, ampeg_start, ampeg_attack, ampeg_hold, ampeg_decay, ampeg_sustain, ampeg_release; + float ampeg_vel2delay, ampeg_vel2attack, ampeg_vel2hold, ampeg_vel2decay, ampeg_vel2sustain, ampeg_vel2release; float fileg_delay, fileg_start, fileg_attack, fileg_hold, fileg_decay, fileg_sustain, fileg_release; + float fileg_vel2delay, fileg_vel2attack, fileg_vel2hold, fileg_vel2decay, fileg_vel2sustain, fileg_vel2release; float pitcheg_delay, pitcheg_start, pitcheg_attack, pitcheg_hold, pitcheg_decay, pitcheg_sustain, pitcheg_release; + float pitcheg_vel2delay, pitcheg_vel2attack, pitcheg_vel2hold, pitcheg_vel2decay, pitcheg_vel2sustain, pitcheg_vel2release; + int fileg_depth, pitcheg_depth; float amplfo_delay, amplfo_fade, amplfo_freq, amplfo_depth; float fillfo_delay, fillfo_fade, fillfo_freq, fillfo_depth; float pitchlfo_delay, pitchlfo_fade, pitchlfo_freq; int pitchlfo_depth; + Array pitchlfo_depthcc; // envelope generators LinuxSampler::ArrayList eg; + + // low frequency oscillators + LinuxSampler::ArrayList lfos; }; class Query { public: - Query(const Instrument& instrument); - Region* next(); uint8_t chan; // MIDI channel - uint8_t key; // MIDI note TODO: or controller + uint8_t key; // MIDI note uint8_t vel; // MIDI velocity int bend; // MIDI pitch bend uint8_t bpm; // host BPM @@ -423,9 +448,13 @@ bool* sw; // state of region key switches, 128 possible values uint8_t last_sw_key; // last key pressed in the key switch range uint8_t prev_sw_key; // previous note value + + void search(const Instrument* pInstrument); + void search(const Instrument* pInstrument, int triggercc); + Region* next(); private: - std::vector::const_iterator i; - std::vector::const_iterator regions_end; + LinuxSampler::ArrayList* pRegionList; + int regionIndex; }; ///////////////////////////////////////////////////////////// @@ -452,15 +481,10 @@ uint GetLoopEnd(); uint GetLoopCount(); - /// Return true if region is triggered by key + /// Return true if region is triggered by key. Region is + /// assumed to come from a search in the lookup table. bool OnKey(const Query& q); - /// Return true if region is triggered by control change - bool OnControl(uint8_t chan, uint8_t cont, uint8_t val, - int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, - uint8_t prog, float rand, trigger_t trig, uint8_t* cc, - float timer, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key); - /// Return an articulation for the current state Articulation* GetArticulation(int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, uint8_t* cc); @@ -492,13 +516,16 @@ /// List of Regions belonging to this Instrument std::vector regions; - friend class sfz::File; + friend class File; + friend class Query; private: std::string name; std::vector KeyBindings; std::vector KeySwitchBindings; SampleManager* pSampleManager; + LookupTable* pLookupTable; + LookupTable* pLookupTableCC[128]; }; ///////////////////////////////////////////////////////////// @@ -543,6 +570,7 @@ int parseKey(const std::string& value); EG& eg(int x); EGNode& egnode(int x, int y); + LFO& lfo(int x); std::string currentDir; /// Pointer to the Instrument belonging to this file