/[svn]/linuxsampler/trunk/src/engines/sfz/sfz.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/sfz/sfz.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2299 by iliev, Sun Dec 11 20:50:31 2011 UTC revision 3291 by persson, Sat Jun 24 12:56:44 2017 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2008 Anders Dahnielson <anders@dahnielson.com>          *   *   Copyright (C) 2008 Anders Dahnielson <anders@dahnielson.com>          *
6   *   Copyright (C) 2009 - 2011 Anders Dahnielson and Grigor Iliev          *   *   Copyright (C) 2009 - 2016 Anders Dahnielson and Grigor Iliev          *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 32  Line 32 
32  #include "../../common/File.h"  #include "../../common/File.h"
33  #include "../../common/Path.h"  #include "../../common/Path.h"
34  #include "LookupTable.h"  #include "LookupTable.h"
35    #include "../../common/global_private.h"
36    
37  namespace sfz  namespace sfz
38  {  {
# Line 66  namespace sfz Line 67  namespace sfz
67      }      }
68    
69      /////////////////////////////////////////////////////////////      /////////////////////////////////////////////////////////////
70      // class optional      // class Script
71    
72      const optional_base::nothing_t optional_base::nothing;      Script::Script(LinuxSampler::Path path) : m_path(path) {
73        }
74    
75        Script::Script(String path) : m_path(LinuxSampler::Path::fromUnknownFS(path)) {
76        }
77    
78        Script::~Script() {
79        }
80    
81        String Script::Name() const {
82            return m_path.getName();
83        }
84    
85        Script::Language_t Script::Language() {
86            return LANGUAGE_NKSP;
87        }
88    
89        String Script::GetSourceCode() {
90            std::ifstream f(m_path.toNativeFSPath().c_str());
91            std::string s;
92            // reserve required space on string object
93            f.seekg(0, std::ios::end);
94            s.reserve(f.tellg());
95            f.seekg(0, std::ios::beg);
96            // read entire content from file and assign it to string object
97            s.assign((std::istreambuf_iterator<char>(f)),
98                      std::istreambuf_iterator<char>());
99            return s;
100        }
101    
102      /////////////////////////////////////////////////////////////      /////////////////////////////////////////////////////////////
103      // class Articulation      // class Articulation
# Line 108  namespace sfz Line 137  namespace sfz
137    
138      Sample* Region::GetSample(bool create)      Sample* Region::GetSample(bool create)
139      {      {
140          if(pSample == NULL && create) {          if (pSample == NULL && create) {
141              uint i = offset ? *offset : 0;              uint i = offset ? *offset : 0;
142              int e = end ? *end : -2;              Sample* sf = GetInstrument()->GetSampleManager()->FindSample(sample, i, end);
             Sample* sf = GetInstrument()->GetSampleManager()->FindSample(sample, i, e);  
143              if (sf != NULL) pSample = sf; // Reuse already created sample              if (sf != NULL) pSample = sf; // Reuse already created sample
144              else pSample = new Sample(sample, false, i, e);              else pSample = new Sample(sample, false, i, end);
145              GetInstrument()->GetSampleManager()->AddSampleConsumer(pSample, this);              GetInstrument()->GetSampleManager()->AddSampleConsumer(pSample, this);
146          }          }
147          return pSample;          return pSample;
# Line 170  namespace sfz Line 198  namespace sfz
198      }      }
199    
200      bool Region::HasLoop() {      bool Region::HasLoop() {
201          bool b = loop_mode == ::sfz::LOOP_UNSET ? pSample->GetLoops() :          bool b = loop_mode == LOOP_UNSET ? pSample->GetLoops() :
202              (loop_mode == ::sfz::LOOP_CONTINUOUS || loop_mode == ::sfz::LOOP_SUSTAIN);              (loop_mode == LOOP_CONTINUOUS || loop_mode == LOOP_SUSTAIN);
203          return b && GetLoopStart() && GetLoopEnd() && GetLoopEnd() > GetLoopStart();          return b && GetLoopEnd() > GetLoopStart();
204      }      }
205    
206      uint Region::GetLoopStart() {      uint Region::GetLoopStart() {
# Line 257  namespace sfz Line 285  namespace sfz
285      }      }
286    
287      /////////////////////////////////////////////////////////////      /////////////////////////////////////////////////////////////
288      // class Group      // class ContainerDefinition
289    
290      Group::Group() :      ContainerDefinition::ContainerDefinition(section_type type)
         id(0)  
291      {      {
292          Reset();          Reset();
293            level = type;
294      }      }
295    
296      Group::~Group()      ContainerDefinition::~ContainerDefinition()
297      {      {
298      }      }
299    
300      void      void
301      Group::Reset()      ContainerDefinition::Reset()
302      {      {
303          // This is where all the default values are set.          // This is where all the default values are set.
304    
# Line 306  namespace sfz Line 334  namespace sfz
334          off_mode = OFF_FAST;          off_mode = OFF_FAST;
335    
336          // sample player          // sample player
337          count.unset();          count = optional<int>::nothing;
338          delay.unset(); delay_random.unset();          delay = optional<float>::nothing;
339          delay_beats.unset(); stop_beats.unset();          delay_random = optional<float>::nothing;
340          delay_samples.unset();          delay_beats = optional<int>::nothing;
341          end.unset();          stop_beats = optional<int>::nothing;
342          loop_crossfade.unset();          delay_samples = optional<int>::nothing;
343          offset.unset(); offset_random.unset();          end = 0;
344            loop_crossfade = optional<float>::nothing;
345            offset = optional<uint>::nothing;
346            offset_random = optional<int>::nothing;
347          loop_mode = LOOP_UNSET;          loop_mode = LOOP_UNSET;
348          loop_start.unset(); loop_end.unset();          loop_start = optional<int>::nothing;
349          sync_beats.unset(); sync_offset.unset();          loop_end = optional<int>::nothing;
350            sync_beats = optional<int>::nothing;
351            sync_offset = optional<int>::nothing;
352    
353          // amplifier          // amplifier
354          volume = 0;          volume = 0;
# Line 323  namespace sfz Line 356  namespace sfz
356          volume_curvecc.clear();          volume_curvecc.clear();
357          volume_smoothcc.clear();          volume_smoothcc.clear();
358          volume_stepcc.clear();          volume_stepcc.clear();
359            amplitude = 100;
360          pan = 0;          pan = 0;
361          pan_oncc.clear();          pan_oncc.clear();
362          pan_curvecc.clear();          pan_curvecc.clear();
# Line 361  namespace sfz Line 395  namespace sfz
395    
396          // filter          // filter
397          fil_type = LPF_2P;          fil_type = LPF_2P;
398          cutoff.unset();          cutoff = optional<float>::nothing;
399          cutoff_chanaft = 0;          cutoff_chanaft = 0;
400          cutoff_polyaft = 0;          cutoff_polyaft = 0;
401          resonance = 0;          resonance = 0;
# Line 371  namespace sfz Line 405  namespace sfz
405          fil_random = 0;          fil_random = 0;
406    
407          fil2_type = LPF_2P;          fil2_type = LPF_2P;
408          cutoff2.unset();          cutoff2 = optional<float>::nothing;
409          cutoff2_chanaft = 0;          cutoff2_chanaft = 0;
410          cutoff2_polyaft = 0;          cutoff2_polyaft = 0;
411          resonance2 = 0;          resonance2 = 0;
# Line 558  namespace sfz Line 592  namespace sfz
592          pitchlfo_freqcc.clear();          pitchlfo_freqcc.clear();
593      }      }
594    
595      Region*      void ContainerDefinition::CopyValuesToDefinition(Definition* definition)
     Group::RegionFactory()  
596      {      {
597          // This is where the current group setting are copied to the new region.          // This is where the current settings are copied to the new definition.
   
         Region* region = new Region();  
   
         region->id = id++;  
598    
599          // sample definition          // sample definition
600          region->sample = sample;          definition->sample = sample;
601    
602          // input control          // input control
603          region->lochan = lochan;          definition->lochan = lochan;
604          region->hichan = hichan;          definition->hichan = hichan;
605          region->lokey = lokey;          definition->lokey = lokey;
606          region->hikey = hikey;          definition->hikey = hikey;
607          region->lovel = lovel;          definition->lovel = lovel;
608          region->hivel = hivel;          definition->hivel = hivel;
609          region->locc = locc;          definition->locc = locc;
610          region->hicc = hicc;          definition->hicc = hicc;
611          region->lobend = lobend;          definition->lobend = lobend;
612          region->hibend = hibend;          definition->hibend = hibend;
613          region->lobpm = lobpm;          definition->lobpm = lobpm;
614          region->hibpm = hibpm;          definition->hibpm = hibpm;
615          region->lochanaft = lochanaft;          definition->lochanaft = lochanaft;
616          region->hichanaft = hichanaft;          definition->hichanaft = hichanaft;
617          region->lopolyaft = lopolyaft;          definition->lopolyaft = lopolyaft;
618          region->hipolyaft = hipolyaft;          definition->hipolyaft = hipolyaft;
619          region->loprog = loprog;          definition->loprog = loprog;
620          region->hiprog = hiprog;          definition->hiprog = hiprog;
621          region->lorand = lorand;          definition->lorand = lorand;
622          region->hirand = hirand;          definition->hirand = hirand;
623          region->lotimer = lotimer;          definition->lotimer = lotimer;
624          region->hitimer = hitimer;          definition->hitimer = hitimer;
625          region->seq_length = seq_length;          definition->seq_length = seq_length;
626          region->seq_position = seq_position;          definition->seq_position = seq_position;
627          region->start_locc = start_locc;          definition->start_locc = start_locc;
628          region->start_hicc = start_hicc;          definition->start_hicc = start_hicc;
629          region->stop_locc = stop_locc;          definition->stop_locc = stop_locc;
630          region->stop_hicc = stop_hicc;          definition->stop_hicc = stop_hicc;
631          region->sw_lokey = sw_lokey;          definition->sw_lokey = sw_lokey;
632          region->sw_hikey = sw_hikey;          definition->sw_hikey = sw_hikey;
633          region->sw_last = sw_last;          definition->sw_last = sw_last;
634          region->sw_down = sw_down;          definition->sw_down = sw_down;
635          region->sw_up = sw_up;          definition->sw_up = sw_up;
636          region->sw_previous = sw_previous;          definition->sw_previous = sw_previous;
637          region->sw_vel = sw_vel;          definition->sw_vel = sw_vel;
638          region->trigger = trigger;          definition->trigger = trigger;
639          region->group = group;          definition->group = group;
640          region->off_by = off_by;          definition->off_by = off_by;
641          region->off_mode = off_mode;          definition->off_mode = off_mode;
642          region->on_locc = on_locc;          definition->on_locc = on_locc;
643          region->on_hicc = on_hicc;          definition->on_hicc = on_hicc;
644    
645          // sample player          // sample player
646          region->count = count;          definition->count = count;
647          region->delay = delay;          definition->delay = delay;
648          region->delay_random = delay_random;          definition->delay_random = delay_random;
649          region->delay_oncc = delay_oncc;          definition->delay_oncc = delay_oncc;
650          region->delay_beats = delay_beats;          definition->delay_beats = delay_beats;
651          region->stop_beats = stop_beats;          definition->stop_beats = stop_beats;
652          region->delay_samples = delay_samples;          definition->delay_samples = delay_samples;
653          region->delay_samples_oncc = delay_samples_oncc;          definition->delay_samples_oncc = delay_samples_oncc;
654          region->end = end;          definition->end = end;
655          region->loop_crossfade = loop_crossfade;          definition->loop_crossfade = loop_crossfade;
656          region->offset = offset;          definition->offset = offset;
657          region->offset_random = offset_random;          definition->offset_random = offset_random;
658          region->offset_oncc = offset_oncc;          definition->offset_oncc = offset_oncc;
659          region->loop_mode = loop_mode;          definition->loop_mode = loop_mode;
660          region->loop_start = loop_start;          definition->loop_start = loop_start;
661          region->loop_end = loop_end;          definition->loop_end = loop_end;
662          region->sync_beats = sync_beats;          definition->sync_beats = sync_beats;
663          region->sync_offset = sync_offset;          definition->sync_offset = sync_offset;
664    
665          // amplifier          // amplifier
666          region->volume = volume;          definition->volume = volume;
667          region->volume_oncc = volume_oncc;          definition->volume_oncc = volume_oncc;
668          region->volume_curvecc = volume_curvecc;          definition->volume_curvecc = volume_curvecc;
669          region->volume_smoothcc = volume_smoothcc;          definition->volume_smoothcc = volume_smoothcc;
670          region->volume_stepcc = volume_stepcc;          definition->volume_stepcc = volume_stepcc;
671          region->pan = pan;          definition->amplitude = amplitude;
672          region->pan_oncc = pan_oncc;          definition->pan = pan;
673          region->pan_curvecc = pan_curvecc;          definition->pan_oncc = pan_oncc;
674          region->pan_smoothcc = pan_smoothcc;          definition->pan_curvecc = pan_curvecc;
675          region->pan_stepcc = pan_stepcc;          definition->pan_smoothcc = pan_smoothcc;
676          region->width = width;          definition->pan_stepcc = pan_stepcc;
677          region->position = position;          definition->width = width;
678          region->amp_keytrack = amp_keytrack;          definition->position = position;
679          region->amp_keycenter = amp_keycenter;          definition->amp_keytrack = amp_keytrack;
680          region->amp_veltrack = amp_veltrack;          definition->amp_keycenter = amp_keycenter;
681          region->amp_velcurve = amp_velcurve;          definition->amp_veltrack = amp_veltrack;
682          region->amp_random = amp_random;          definition->amp_velcurve = amp_velcurve;
683          region->rt_decay = rt_decay;          definition->amp_random = amp_random;
684          region->gain_oncc = gain_oncc;          definition->rt_decay = rt_decay;
685          region->xfin_lokey = xfin_lokey;          definition->gain_oncc = gain_oncc;
686          region->xfin_hikey = xfin_hikey;          definition->xfin_lokey = xfin_lokey;
687          region->xfout_lokey = xfout_lokey;          definition->xfin_hikey = xfin_hikey;
688          region->xfout_hikey = xfout_hikey;          definition->xfout_lokey = xfout_lokey;
689          region->xf_keycurve = xf_keycurve;          definition->xfout_hikey = xfout_hikey;
690          region->xfin_lovel = xfin_lovel;          definition->xf_keycurve = xf_keycurve;
691          region->xfin_hivel = xfin_lovel;          definition->xfin_lovel = xfin_lovel;
692          region->xfout_lovel = xfout_lovel;          definition->xfin_hivel = xfin_lovel;
693          region->xfout_hivel = xfout_hivel;          definition->xfout_lovel = xfout_lovel;
694          region->xf_velcurve = xf_velcurve;          definition->xfout_hivel = xfout_hivel;
695          region->xfin_locc = xfin_locc;          definition->xf_velcurve = xf_velcurve;
696          region->xfin_hicc = xfin_hicc;          definition->xfin_locc = xfin_locc;
697          region->xfout_locc = xfout_locc;          definition->xfin_hicc = xfin_hicc;
698          region->xfout_hicc = xfout_hicc;          definition->xfout_locc = xfout_locc;
699          region->xf_cccurve = xf_cccurve;          definition->xfout_hicc = xfout_hicc;
700            definition->xf_cccurve = xf_cccurve;
701    
702          // pitch          // pitch
703          region->transpose = transpose;          definition->transpose = transpose;
704          region->tune = tune;          definition->tune = tune;
705          region->pitch_keycenter = pitch_keycenter;          definition->pitch_keycenter = pitch_keycenter;
706          region->pitch_keytrack = pitch_keytrack;          definition->pitch_keytrack = pitch_keytrack;
707          region->pitch_veltrack = pitch_veltrack;          definition->pitch_veltrack = pitch_veltrack;
708          region->pitch_random = pitch_random;          definition->pitch_random = pitch_random;
709          region->bend_up = bend_up;          definition->bend_up = bend_up;
710          region->bend_down = bend_down;          definition->bend_down = bend_down;
711          region->bend_step = bend_step;          definition->bend_step = bend_step;
712                    
713          region->pitch_oncc     = pitch_oncc;          definition->pitch_oncc     = pitch_oncc;
714          region->pitch_smoothcc = pitch_smoothcc;          definition->pitch_smoothcc = pitch_smoothcc;
715          region->pitch_curvecc  = pitch_curvecc;          definition->pitch_curvecc  = pitch_curvecc;
716          region->pitch_stepcc   = pitch_stepcc;          definition->pitch_stepcc   = pitch_stepcc;
717    
718          // filter          // filter
719          region->fil_type = fil_type;          definition->fil_type = fil_type;
720          region->cutoff = cutoff;          definition->cutoff = cutoff;
721          region->cutoff_oncc = cutoff_oncc;          definition->cutoff_oncc = cutoff_oncc;
722          region->cutoff_smoothcc = cutoff_smoothcc;          definition->cutoff_smoothcc = cutoff_smoothcc;
723          region->cutoff_stepcc = cutoff_stepcc;          definition->cutoff_stepcc = cutoff_stepcc;
724          region->cutoff_curvecc = cutoff_curvecc;          definition->cutoff_curvecc = cutoff_curvecc;
725          region->cutoff_chanaft = cutoff_chanaft;          definition->cutoff_chanaft = cutoff_chanaft;
726          region->cutoff_polyaft = cutoff_polyaft;          definition->cutoff_polyaft = cutoff_polyaft;
727          region->resonance = resonance;          definition->resonance = resonance;
728          region->resonance_oncc = resonance_oncc;          definition->resonance_oncc = resonance_oncc;
729          region->resonance_smoothcc = resonance_smoothcc;          definition->resonance_smoothcc = resonance_smoothcc;
730          region->resonance_stepcc = resonance_stepcc;          definition->resonance_stepcc = resonance_stepcc;
731          region->resonance_curvecc = resonance_curvecc;          definition->resonance_curvecc = resonance_curvecc;
732          region->fil_keytrack = fil_keytrack;          definition->fil_keytrack = fil_keytrack;
733          region->fil_keycenter = fil_keycenter;          definition->fil_keycenter = fil_keycenter;
734          region->fil_veltrack = fil_veltrack;          definition->fil_veltrack = fil_veltrack;
735          region->fil_random = fil_random;          definition->fil_random = fil_random;
736    
737          region->fil2_type = fil2_type;          definition->fil2_type = fil2_type;
738          region->cutoff2 = cutoff2;          definition->cutoff2 = cutoff2;
739          region->cutoff2_oncc = cutoff2_oncc;          definition->cutoff2_oncc = cutoff2_oncc;
740          region->cutoff2_smoothcc = cutoff2_smoothcc;          definition->cutoff2_smoothcc = cutoff2_smoothcc;
741          region->cutoff2_stepcc = cutoff2_stepcc;          definition->cutoff2_stepcc = cutoff2_stepcc;
742          region->cutoff2_curvecc = cutoff2_curvecc;          definition->cutoff2_curvecc = cutoff2_curvecc;
743          region->cutoff2_chanaft = cutoff2_chanaft;          definition->cutoff2_chanaft = cutoff2_chanaft;
744          region->cutoff2_polyaft = cutoff2_polyaft;          definition->cutoff2_polyaft = cutoff2_polyaft;
745          region->resonance2 = resonance2;          definition->resonance2 = resonance2;
746          region->resonance2_oncc = resonance2_oncc;          definition->resonance2_oncc = resonance2_oncc;
747          region->resonance2_smoothcc = resonance2_smoothcc;          definition->resonance2_smoothcc = resonance2_smoothcc;
748          region->resonance2_stepcc = resonance2_stepcc;          definition->resonance2_stepcc = resonance2_stepcc;
749          region->resonance2_curvecc = resonance2_curvecc;          definition->resonance2_curvecc = resonance2_curvecc;
750          region->fil2_keytrack = fil2_keytrack;          definition->fil2_keytrack = fil2_keytrack;
751          region->fil2_keycenter = fil2_keycenter;          definition->fil2_keycenter = fil2_keycenter;
752          region->fil2_veltrack = fil2_veltrack;          definition->fil2_veltrack = fil2_veltrack;
753          region->fil2_random = fil2_random;          definition->fil2_random = fil2_random;
754    
755          // per voice equalizer          // per voice equalizer
756          region->eq1_freq = eq1_freq;          definition->eq1_freq = eq1_freq;
757          region->eq2_freq = eq2_freq;          definition->eq2_freq = eq2_freq;
758          region->eq3_freq = eq3_freq;          definition->eq3_freq = eq3_freq;
759          region->eq1_freq_oncc = eq1_freq_oncc;          definition->eq1_freq_oncc = eq1_freq_oncc;
760          region->eq2_freq_oncc = eq2_freq_oncc;          definition->eq2_freq_oncc = eq2_freq_oncc;
761          region->eq3_freq_oncc = eq3_freq_oncc;          definition->eq3_freq_oncc = eq3_freq_oncc;
762          region->eq1_vel2freq = eq1_vel2freq;          definition->eq1_vel2freq = eq1_vel2freq;
763          region->eq2_vel2freq = eq2_vel2freq;          definition->eq2_vel2freq = eq2_vel2freq;
764          region->eq3_vel2freq = eq3_vel2freq;          definition->eq3_vel2freq = eq3_vel2freq;
765          region->eq1_bw = eq1_bw;          definition->eq1_bw = eq1_bw;
766          region->eq2_bw = eq2_bw;          definition->eq2_bw = eq2_bw;
767          region->eq3_bw = eq3_bw;          definition->eq3_bw = eq3_bw;
768          region->eq1_bw_oncc = eq1_bw_oncc;          definition->eq1_bw_oncc = eq1_bw_oncc;
769          region->eq2_bw_oncc = eq2_bw_oncc;          definition->eq2_bw_oncc = eq2_bw_oncc;
770          region->eq3_bw_oncc = eq3_bw_oncc;          definition->eq3_bw_oncc = eq3_bw_oncc;
771          region->eq1_gain = eq1_gain;          definition->eq1_gain = eq1_gain;
772          region->eq2_gain = eq2_gain;          definition->eq2_gain = eq2_gain;
773          region->eq3_gain = eq3_gain;          definition->eq3_gain = eq3_gain;
774          region->eq1_gain_oncc = eq1_gain_oncc;          definition->eq1_gain_oncc = eq1_gain_oncc;
775          region->eq2_gain_oncc = eq2_gain_oncc;          definition->eq2_gain_oncc = eq2_gain_oncc;
776          region->eq3_gain_oncc = eq3_gain_oncc;          definition->eq3_gain_oncc = eq3_gain_oncc;
777          region->eq1_vel2gain = eq1_vel2gain;          definition->eq1_vel2gain = eq1_vel2gain;
778          region->eq2_vel2gain = eq2_vel2gain;          definition->eq2_vel2gain = eq2_vel2gain;
779          region->eq3_vel2gain = eq3_vel2gain;          definition->eq3_vel2gain = eq3_vel2gain;
780    
781          // envelope generator          // envelope generator
782          region->eg = eg;          definition->eg = eg;
783    
784          // deprecated          // deprecated
785          region->ampeg_delay    = ampeg_delay;          definition->ampeg_delay    = ampeg_delay;
786          region->ampeg_start    = ampeg_start;          definition->ampeg_start    = ampeg_start;
787          region->ampeg_attack   = ampeg_attack;          definition->ampeg_attack   = ampeg_attack;
788          region->ampeg_hold     = ampeg_hold;          definition->ampeg_hold     = ampeg_hold;
789          region->ampeg_decay    = ampeg_decay;          definition->ampeg_decay    = ampeg_decay;
790          region->ampeg_sustain  = ampeg_sustain;          definition->ampeg_sustain  = ampeg_sustain;
791          region->ampeg_release  = ampeg_release;          definition->ampeg_release  = ampeg_release;
792    
793          region->ampeg_vel2delay   = ampeg_vel2delay;          definition->ampeg_vel2delay   = ampeg_vel2delay;
794          region->ampeg_vel2attack  = ampeg_vel2attack;          definition->ampeg_vel2attack  = ampeg_vel2attack;
795          region->ampeg_vel2hold    = ampeg_vel2hold;          definition->ampeg_vel2hold    = ampeg_vel2hold;
796          region->ampeg_vel2decay   = ampeg_vel2decay;          definition->ampeg_vel2decay   = ampeg_vel2decay;
797          region->ampeg_vel2sustain = ampeg_vel2sustain;          definition->ampeg_vel2sustain = ampeg_vel2sustain;
798          region->ampeg_vel2release = ampeg_vel2release;          definition->ampeg_vel2release = ampeg_vel2release;
799                    
800          region->ampeg_delaycc   = ampeg_delaycc;          definition->ampeg_delaycc   = ampeg_delaycc;
801          region->ampeg_startcc   = ampeg_startcc;          definition->ampeg_startcc   = ampeg_startcc;
802          region->ampeg_attackcc  = ampeg_attackcc;          definition->ampeg_attackcc  = ampeg_attackcc;
803          region->ampeg_holdcc    = ampeg_holdcc;          definition->ampeg_holdcc    = ampeg_holdcc;
804          region->ampeg_decaycc   = ampeg_decaycc;          definition->ampeg_decaycc   = ampeg_decaycc;
805          region->ampeg_sustaincc = ampeg_sustaincc;          definition->ampeg_sustaincc = ampeg_sustaincc;
806          region->ampeg_releasecc = ampeg_releasecc;          definition->ampeg_releasecc = ampeg_releasecc;
807    
808          region->fileg_delay    = fileg_delay;          definition->fileg_delay    = fileg_delay;
809          region->fileg_start    = fileg_start;          definition->fileg_start    = fileg_start;
810          region->fileg_attack   = fileg_attack;          definition->fileg_attack   = fileg_attack;
811          region->fileg_hold     = fileg_hold;          definition->fileg_hold     = fileg_hold;
812          region->fileg_decay    = fileg_decay;          definition->fileg_decay    = fileg_decay;
813          region->fileg_sustain  = fileg_sustain;          definition->fileg_sustain  = fileg_sustain;
814          region->fileg_release  = fileg_release;          definition->fileg_release  = fileg_release;
815          region->fileg_depth    = fileg_depth;          definition->fileg_depth    = fileg_depth;
816    
817          region->fileg_vel2delay   = fileg_vel2delay;          definition->fileg_vel2delay   = fileg_vel2delay;
818          region->fileg_vel2attack  = fileg_vel2attack;          definition->fileg_vel2attack  = fileg_vel2attack;
819          region->fileg_vel2hold    = fileg_vel2hold;          definition->fileg_vel2hold    = fileg_vel2hold;
820          region->fileg_vel2decay   = fileg_vel2decay;          definition->fileg_vel2decay   = fileg_vel2decay;
821          region->fileg_vel2sustain = fileg_vel2sustain;          definition->fileg_vel2sustain = fileg_vel2sustain;
822          region->fileg_vel2release = fileg_vel2release;          definition->fileg_vel2release = fileg_vel2release;
823                    
824          region->fileg_delay_oncc   = fileg_delay_oncc;          definition->fileg_delay_oncc   = fileg_delay_oncc;
825          region->fileg_start_oncc   = fileg_start_oncc;          definition->fileg_start_oncc   = fileg_start_oncc;
826          region->fileg_attack_oncc  = fileg_attack_oncc;          definition->fileg_attack_oncc  = fileg_attack_oncc;
827          region->fileg_hold_oncc    = fileg_hold_oncc;          definition->fileg_hold_oncc    = fileg_hold_oncc;
828          region->fileg_decay_oncc   = fileg_decay_oncc;          definition->fileg_decay_oncc   = fileg_decay_oncc;
829          region->fileg_sustain_oncc = fileg_sustain_oncc;          definition->fileg_sustain_oncc = fileg_sustain_oncc;
830          region->fileg_release_oncc = fileg_release_oncc;          definition->fileg_release_oncc = fileg_release_oncc;
831          region->fileg_depth_oncc   = fileg_depth_oncc;          definition->fileg_depth_oncc   = fileg_depth_oncc;
832    
833          region->pitcheg_delay    = pitcheg_delay;          definition->pitcheg_delay    = pitcheg_delay;
834          region->pitcheg_start    = pitcheg_start;          definition->pitcheg_start    = pitcheg_start;
835          region->pitcheg_attack   = pitcheg_attack;          definition->pitcheg_attack   = pitcheg_attack;
836          region->pitcheg_hold     = pitcheg_hold;          definition->pitcheg_hold     = pitcheg_hold;
837          region->pitcheg_decay    = pitcheg_decay;          definition->pitcheg_decay    = pitcheg_decay;
838          region->pitcheg_sustain  = pitcheg_sustain;          definition->pitcheg_sustain  = pitcheg_sustain;
839          region->pitcheg_release  = pitcheg_release;          definition->pitcheg_release  = pitcheg_release;
840          region->pitcheg_depth    = pitcheg_depth;          definition->pitcheg_depth    = pitcheg_depth;
841    
842          region->pitcheg_vel2delay   = pitcheg_vel2delay;          definition->pitcheg_vel2delay   = pitcheg_vel2delay;
843          region->pitcheg_vel2attack  = pitcheg_vel2attack;          definition->pitcheg_vel2attack  = pitcheg_vel2attack;
844          region->pitcheg_vel2hold    = pitcheg_vel2hold;          definition->pitcheg_vel2hold    = pitcheg_vel2hold;
845          region->pitcheg_vel2decay   = pitcheg_vel2decay;          definition->pitcheg_vel2decay   = pitcheg_vel2decay;
846          region->pitcheg_vel2sustain = pitcheg_vel2sustain;          definition->pitcheg_vel2sustain = pitcheg_vel2sustain;
847          region->pitcheg_vel2release = pitcheg_vel2release;          definition->pitcheg_vel2release = pitcheg_vel2release;
848                    
849          region->pitcheg_delay_oncc   = pitcheg_delay_oncc;          definition->pitcheg_delay_oncc   = pitcheg_delay_oncc;
850          region->pitcheg_start_oncc   = pitcheg_start_oncc;          definition->pitcheg_start_oncc   = pitcheg_start_oncc;
851          region->pitcheg_attack_oncc  = pitcheg_attack_oncc;          definition->pitcheg_attack_oncc  = pitcheg_attack_oncc;
852          region->pitcheg_hold_oncc    = pitcheg_hold_oncc;          definition->pitcheg_hold_oncc    = pitcheg_hold_oncc;
853          region->pitcheg_decay_oncc   = pitcheg_decay_oncc;          definition->pitcheg_decay_oncc   = pitcheg_decay_oncc;
854          region->pitcheg_sustain_oncc = pitcheg_sustain_oncc;          definition->pitcheg_sustain_oncc = pitcheg_sustain_oncc;
855          region->pitcheg_release_oncc = pitcheg_release_oncc;          definition->pitcheg_release_oncc = pitcheg_release_oncc;
856          region->pitcheg_depth_oncc   = pitcheg_depth_oncc;          definition->pitcheg_depth_oncc   = pitcheg_depth_oncc;
857    
858          region->amplfo_delay     = amplfo_delay;          definition->amplfo_delay     = amplfo_delay;
859          region->amplfo_fade      = amplfo_fade;          definition->amplfo_fade      = amplfo_fade;
860          region->amplfo_freq      = amplfo_freq;          definition->amplfo_freq      = amplfo_freq;
861          region->amplfo_depth     = amplfo_depth;          definition->amplfo_depth     = amplfo_depth;
862                    
863          region->amplfo_delay_oncc = amplfo_delay_oncc;          definition->amplfo_delay_oncc = amplfo_delay_oncc;
864          region->amplfo_fade_oncc  = amplfo_fade_oncc;          definition->amplfo_fade_oncc  = amplfo_fade_oncc;
865          region->amplfo_depthcc   = amplfo_depthcc;          definition->amplfo_depthcc   = amplfo_depthcc;
866          region->amplfo_freqcc    = amplfo_freqcc;          definition->amplfo_freqcc    = amplfo_freqcc;
867    
868          region->fillfo_delay     = fillfo_delay;          definition->fillfo_delay     = fillfo_delay;
869          region->fillfo_fade      = fillfo_fade;          definition->fillfo_fade      = fillfo_fade;
870          region->fillfo_freq      = fillfo_freq;          definition->fillfo_freq      = fillfo_freq;
871          region->fillfo_depth     = fillfo_depth;          definition->fillfo_depth     = fillfo_depth;
872                    
873          region->fillfo_delay_oncc = fillfo_delay_oncc;          definition->fillfo_delay_oncc = fillfo_delay_oncc;
874          region->fillfo_fade_oncc  = fillfo_fade_oncc;          definition->fillfo_fade_oncc  = fillfo_fade_oncc;
875          region->fillfo_depthcc   = fillfo_depthcc;          definition->fillfo_depthcc   = fillfo_depthcc;
876          region->fillfo_freqcc    = fillfo_freqcc;          definition->fillfo_freqcc    = fillfo_freqcc;
877    
878          region->pitchlfo_delay   = pitchlfo_delay;          definition->pitchlfo_delay   = pitchlfo_delay;
879          region->pitchlfo_fade    = pitchlfo_fade;          definition->pitchlfo_fade    = pitchlfo_fade;
880          region->pitchlfo_freq    = pitchlfo_freq;          definition->pitchlfo_freq    = pitchlfo_freq;
881          region->pitchlfo_depth   = pitchlfo_depth;          definition->pitchlfo_depth   = pitchlfo_depth;
882                    
883          region->pitchlfo_delay_oncc = pitchlfo_delay_oncc;          definition->pitchlfo_delay_oncc = pitchlfo_delay_oncc;
884          region->pitchlfo_fade_oncc  = pitchlfo_fade_oncc;          definition->pitchlfo_fade_oncc  = pitchlfo_fade_oncc;
885          region->pitchlfo_depthcc = pitchlfo_depthcc;          definition->pitchlfo_depthcc = pitchlfo_depthcc;
886          region->pitchlfo_freqcc  = pitchlfo_freqcc;          definition->pitchlfo_freqcc  = pitchlfo_freqcc;
887                    
888          region->eg = eg;          definition->eg = eg;
889          region->lfos = lfos;          definition->lfos = lfos;
   
         return region;  
890      }      }
891    
892      /////////////////////////////////////////////////////////////      /////////////////////////////////////////////////////////////
893      // class File      // class File
894    
895        const std::string File::MACRO_NAME_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
896        const std::string File::MACRO_VALUE_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_. /\\";
897    
898      File::File(std::string file, SampleManager* pSampleManager) :      File::File(std::string file, SampleManager* pSampleManager) :
899          _current_section(GROUP),          _current_section(GLOBAL),
900            id(0),
901          default_path(""),          default_path(""),
902          octave_offset(0),          octave_offset(0),
903          note_offset(0)          note_offset(0)
904      {      {
905          _instrument = new Instrument(LinuxSampler::Path::getBaseName(file), pSampleManager);          _instrument = new Instrument(LinuxSampler::Path::getBaseName(file), pSampleManager);
906          _current_group = new Group();          ContainerDefinition* defaultGlobalContainer = new ContainerDefinition(ContainerDefinition::GLOBAL);
907          pCurDef = _current_group;          _current_containers.push(defaultGlobalContainer);
908          enum token_type_t { HEADER, OPCODE };          pCurDef = defaultGlobalContainer;
         token_type_t token_type;  
         std::string token_string;  
   
         std::ifstream fs(file.c_str());  
         currentDir = LinuxSampler::Path::stripLastName(file);  
         std::string token;  
         std::string line;  
         currentLine = 0;  
909    
910          while (std::getline(fs, line))          parseFile(file,pSampleManager);
         {  
             currentLine++;  
             // COMMENT  
             std::string::size_type slash_index = line.find("//");  
             if (slash_index != std::string::npos)  
                 line.resize(slash_index);  
   
             // DEFINITION  
             std::stringstream linestream(line);  
             while (linestream >> token)  
             {  
                 if (token[0] == '<' and token[token.size()-1] == '>')  
                 {  
                     // HEAD  
                     if (!token_string.empty())  
                     {  
                         switch (token_type)  
                         {  
                         case HEADER:  
                             push_header(token_string);  
                             break;  
                         case OPCODE:  
                             push_opcode(token_string);  
                             break;  
                         }  
                         token_string.erase();  
                     }  
                     token_string.append(token);  
                     token_type = HEADER;  
                 }  
                 else if (token.find('=') != std::string::npos)  
                 {  
                     // HEAD  
                     if (!token_string.empty())  
                     {  
                         switch (token_type)  
                         {  
                         case HEADER:  
                             push_header(token_string);  
                             break;  
                         case OPCODE:  
                             push_opcode(token_string);  
                             break;  
                         }  
                         token_string.erase();  
                     }  
                     token_string.append(token);  
                     token_type = OPCODE;  
                 }  
                 else  
                 {  
                     // TAIL  
                     token_string.append(" ");  
                     token_string.append(token);  
                 }  
             }  
   
             // EOL  
             if (!token_string.empty())  
             {  
                 switch (token_type)  
                 {  
                 case HEADER:  
                     push_header(token_string);  
                     break;  
                 case OPCODE:  
                     push_opcode(token_string);  
                     break;  
                 }  
                 token_string.erase();  
             }  
         }  
911    
912          std::set<float*> velcurves;          std::set<float*> velcurves;
913          for (int i = 0; i < _instrument->regions.size(); i++) {          for (int i = 0; i < _instrument->regions.size(); i++) {
# Line 1014  namespace sfz Line 966  namespace sfz
966                          velcurve[v] = v * v / (127.0 * 127.0);                          velcurve[v] = v * v / (127.0 * 127.0);
967                      }                      }
968                  }                  }
   
                 // apply amp_veltrack  
                 float offset = -pRegion->amp_veltrack;  
                 if (offset <= 0) offset += 100;  
                 for (int v = 0 ; v < 128 ; v++) {  
                     velcurve[v] = (offset + pRegion->amp_veltrack * velcurve[v]) / 100;  
                 }  
969              }              }
970          }          }
971    
# Line 1146  namespace sfz Line 1091  namespace sfz
1091          }          }
1092      }      }
1093    
1094        void File::parseFile(std::string file, SampleManager* pSampleManager){
1095            enum token_type_t { HEADER, OPCODE };
1096            token_type_t token_type = (token_type_t) -1;
1097            std::string token_string;
1098    
1099            std::ifstream fs(file.c_str());
1100            currentDir = LinuxSampler::Path::stripLastName(file);
1101            std::string token;
1102            std::string line;
1103            currentLine = 0;
1104    
1105            while (std::getline(fs, line))
1106            {
1107                currentLine++;
1108                // COMMENT
1109                std::string::size_type slash_index = line.find("//");
1110                if (slash_index != std::string::npos)
1111                    line.resize(slash_index);
1112    
1113                // #include
1114                if (line.find("#include ") == 0) {
1115                    size_t fname_start = line.find("\"");
1116                    if (fname_start == std::string::npos) continue;
1117    
1118                    size_t fname_end = line.find("\"", fname_start + 1);
1119                    if (fname_end == std::string::npos || fname_start == fname_end)
1120                        continue;
1121                    std::string fname = line.substr(fname_start + 1, fname_end - fname_start - 1);
1122    
1123                    if (!currentDir.empty() && !LinuxSampler::Path(fname).isAbsolute())
1124                        fname = currentDir + LinuxSampler::File::DirSeparator + fname;
1125    
1126                    std::string cd = currentDir; // backup current dir
1127                    int cl = currentLine;
1128                    parseFile(fname, pSampleManager);
1129                    currentDir = cd; // restore currentDir (since altered by parsefile())
1130                    currentLine = cl;
1131                    continue;
1132                }
1133                // #define
1134                else if (line.find("#define") == 0)
1135                {
1136                    
1137                    size_t varname_start = line.find_first_not_of("\t ", std::strlen("#define"));
1138                    size_t varname_end = line.find_first_of("\t ", varname_start + 1);
1139                    size_t value_start = line.find_first_not_of("\t ", varname_end + 1);
1140                    
1141                    std::string varname = line.substr(varname_start, varname_end - varname_start);
1142                    std::string value = line.substr(value_start, std::string::npos);
1143                    
1144                    if (varname.size() == 0 || value.size() == 0)
1145                    {
1146                        std::cerr << "sfz error: Malformed #define statement on line " << currentLine << std::endl;
1147                        continue;
1148                    }
1149                    
1150                    // Deal with DOS EOLs
1151                    if (value[value.size() - 1] == '\r')
1152                    {
1153                        value.erase(value.size() - 1);
1154                    }
1155                    
1156                    // Check varname
1157                    if (varname[0] != '$')
1158                    {
1159                        std::cerr << "sfz error: Macro name '" << varname;
1160                        std::cerr << "' doesn't start with '$'." << std::endl;
1161                        continue;
1162                    }
1163                    // Invalid chars
1164                    if (varname.find_first_not_of(MACRO_NAME_CHARS, 1) != std::string::npos)
1165                    {
1166                        std::cerr << "sfz error: Macro name '" << varname;
1167                        std::cerr << "' contains invalid characters." << std::endl;
1168                    }
1169                    
1170                    // Check value
1171                    // Match alphanumeric, underscore, and decimal point.
1172                    if (value.find_first_not_of(MACRO_VALUE_CHARS) != std::string::npos)
1173                    {
1174                        std::cerr << "sfz error: Macro value '" << value;
1175                        std::cerr << "' contains invalid characters." << std::endl;
1176                        continue;
1177                    }
1178                    
1179                    _defined_macros[varname] = value;
1180                    
1181                    continue;
1182                }
1183                // script=path/to/scriptfile
1184                else if (line.find("script") == 0) {
1185                    size_t eq = line.find_first_of("=");
1186                    if (eq == std::string::npos) {
1187                        std::cerr << "sfz error: opcode 'script' misses '=' character\n";
1188                        continue;
1189                    }
1190                    std::string value = trim( line.substr(eq+1, std::string::npos) );
1191                    if (value.empty()) {
1192                        std::cerr << "sfz error: empty path assigned to opcode 'script'\n";
1193                        continue;
1194                    }
1195                    LinuxSampler::Path path = LinuxSampler::Path::fromUnknownFS(value);
1196                    if (!currentDir.empty() && !path.isAbsolute())
1197                        path = LinuxSampler::Path::fromUnknownFS(currentDir) + path;
1198                    LinuxSampler::File file(path);
1199                    if (!file.Exist()) {
1200                        std::cerr << "sfz error: script file '" << value << "' does not exist\n";
1201                        continue;
1202                    }
1203                    if (!file.IsFile()) {
1204                        std::cerr << "sfz error: script '" << value << "' is not a file\n";
1205                        continue;
1206                    }
1207                    Script script(path);
1208                    _instrument->scripts.push_back(script);
1209    
1210                    continue;
1211                }
1212    
1213                // DEFINITION
1214                std::stringstream linestream(line);
1215                int spaces = 0;
1216                while (linestream >> token)
1217                {
1218                    linestream >> std::noskipws;
1219                    if (token[0] == '<') {
1220                        std::string::size_type p = token.find('>', 1);
1221                        if (p != std::string::npos && p < (token.size() - 1)) {
1222                            linestream.seekg(p + 1 - token.size(), std::stringstream::cur);
1223                            token.erase(p + 1);
1224                        }
1225                    }
1226                    if (token[0] == '<' && token[token.size()-1] == '>')
1227                    {
1228                        // HEAD
1229                        if (!token_string.empty())
1230                        {
1231                            switch (token_type)
1232                            {
1233                            case HEADER:
1234                                push_header(token_string);
1235                                break;
1236                            case OPCODE:
1237                                push_opcode(token_string);
1238                                break;
1239                            }
1240                            token_string.erase();
1241                        }
1242                        token_string.append(token);
1243                        token_type = HEADER;
1244                    }
1245                    else if (token.find('=') != std::string::npos)
1246                    {
1247                        // HEAD
1248                        if (!token_string.empty())
1249                        {
1250                            switch (token_type)
1251                            {
1252                            case HEADER:
1253                                push_header(token_string);
1254                                break;
1255                            case OPCODE:
1256                                push_opcode(token_string);
1257                                break;
1258                            }
1259                            token_string.erase();
1260                        }
1261                        token_string.append(token);
1262                        token_type = OPCODE;
1263                    }
1264                    else
1265                    {
1266                        // TAIL
1267                        token_string.append(spaces, ' ');
1268                        token_string.append(token);
1269                    }
1270                    spaces = 0;
1271                    while (isspace(linestream.peek())) {
1272                        linestream.ignore();
1273                        spaces++;
1274                    }
1275                }
1276    
1277                // EOL
1278                if (!token_string.empty())
1279                {
1280                    switch (token_type)
1281                    {
1282                    case HEADER:
1283                        push_header(token_string);
1284                        break;
1285                    case OPCODE:
1286                        push_opcode(token_string);
1287                        break;
1288                    }
1289                    token_string.erase();
1290                }
1291            }
1292        }
1293    
1294      File::~File()      File::~File()
1295      {      {
1296          delete _current_group;          for (int i = 0; i < _current_containers.size(); i++)
1297            {
1298                delete _current_containers.top();
1299                _current_containers.pop();
1300            }
1301          delete _instrument;          delete _instrument;
1302      }      }
1303    
# Line 1213  namespace sfz Line 1362  namespace sfz
1362      void      void
1363      File::push_header(std::string token)      File::push_header(std::string token)
1364      {      {
1365          if (token == "<group>")          if (token == "<global>" ||
1366                token == "<master>" ||
1367                token == "<group>")
1368          {          {
1369              _current_section = GROUP;              ContainerDefinition::section_type level = ContainerDefinition::GLOBAL; // initialized only to avoid an irrelevant compiler warning
1370              _current_group->Reset();  
1371              pCurDef = _current_group;              if (token == "<global>")
1372                {
1373                    _current_section = GLOBAL;
1374                    level = ContainerDefinition::GLOBAL;
1375                }
1376                else if (token == "<master>")
1377                {
1378                    _current_section = MASTER;
1379                    level = ContainerDefinition::MASTER;
1380                }
1381                else if (token == "<group>")
1382                {
1383                    _current_section = GROUP;
1384                    level = ContainerDefinition::GROUP;
1385                }
1386    
1387                ContainerDefinition* newContainer = new ContainerDefinition(level);
1388                
1389                while (_current_containers.size() > 0 && _current_containers.top()->level <= level)
1390                {
1391                    delete _current_containers.top();
1392                    _current_containers.pop();
1393                }
1394                
1395                //If the new header is a <global>, there won't be anything left in _current_containers
1396                //to copy from.
1397                if (_current_containers.size() > 0)
1398                {
1399                    _current_containers.top()->CopyValuesToDefinition(newContainer);
1400                }
1401                _current_containers.push(newContainer);
1402                pCurDef = newContainer;
1403          }          }
1404          else if (token == "<region>")          else if (token == "<region>")
1405          {          {
1406              _current_section = REGION;              _current_section = REGION;
1407              _current_region = _current_group->RegionFactory();              _current_region = new Region();
1408                _current_region->id = id++;
1409                _current_containers.top()->CopyValuesToDefinition(_current_region);
1410              pCurDef = _current_region;              pCurDef = _current_region;
1411              _instrument->regions.push_back(_current_region);              _instrument->regions.push_back(_current_region);
1412              _current_region->SetInstrument(_instrument);              _current_region->SetInstrument(_instrument);
# Line 1258  namespace sfz Line 1442  namespace sfz
1442          std::string value = token.substr(delimiter_index + 1);          std::string value = token.substr(delimiter_index + 1);
1443          int x, y, z;          int x, y, z;
1444                    
1445            // Apply macros
1446            size_t macro_start = 0;
1447            size_t macro_end = 0;
1448            std::string macro_value;
1449            while ((macro_start = value.find("$", macro_start + macro_value.size())) != std::string::npos)
1450            {
1451                macro_end = value.find_first_not_of(MACRO_NAME_CHARS, macro_start + 1);
1452                size_t macro_len = macro_end - macro_start;
1453                std::string macro_name = value.substr(macro_start, macro_len);
1454                if (_defined_macros.count(macro_name) != 0)
1455                {
1456                    macro_value = _defined_macros[macro_name];
1457                    value.replace(macro_start, macro_len, macro_value);
1458                }
1459                else
1460                {
1461                    std::cerr << "Macro '" << macro_name << "' referenced on line ";
1462                    std::cerr << currentLine << " is undefined." << std::endl;
1463                    return;
1464                }
1465            }
1466            
1467          if (_current_section == CURVE) {          if (_current_section == CURVE) {
1468              if (sscanf(key.c_str(), "v%d", &x)) {              if (sscanf(key.c_str(), "v%d", &x)) {
1469                  if (x < 0 || x > 127) {                  if (x < 0 || x > 127) {
# Line 1276  namespace sfz Line 1482  namespace sfz
1482          {          {
1483              std::string path = default_path + value;              std::string path = default_path + value;
1484              #ifndef WIN32              #ifndef WIN32
1485              for (int i = 0; i < path.length(); i++) if( path[i] == '\\') path[i] = '/';              for (int i = 0; i < path.length(); i++) if (path[i] == '\\') path[i] = '/';
1486                bool absolute = path[0] == '/';
1487                #else
1488                bool absolute = path[0] == '/' || path[0] == '\\' ||
1489                    (path.length() >= 2 && isalpha(path[0]) && path[1] == ':');
1490              #endif              #endif
1491              path = currentDir + LinuxSampler::File::DirSeparator + path; // TODO: check for absolute path              if (!absolute) path = currentDir + LinuxSampler::File::DirSeparator + path;
   
1492              if(pCurDef) pCurDef->sample = path;              if(pCurDef) pCurDef->sample = path;
1493              return;              return;
1494          }          }
# Line 1291  namespace sfz Line 1500  namespace sfz
1500              {              {
1501              case CONTROL:              case CONTROL:
1502                  default_path = value;                  default_path = value;
1503                    break;
1504                default:
1505                    ; // noop
1506              }              }
1507              return;              return;
1508          }          }
# Line 1300  namespace sfz Line 1512  namespace sfz
1512              {              {
1513              case CONTROL:              case CONTROL:
1514                  octave_offset = ToInt(value);                  octave_offset = ToInt(value);
1515                    break;
1516                default:
1517                    ; // noop
1518              }              }
1519              return;              return;
1520          }          }
# Line 1309  namespace sfz Line 1524  namespace sfz
1524              {              {
1525              case CONTROL:              case CONTROL:
1526                  note_offset = ToInt(value);                  note_offset = ToInt(value);
1527                    break;
1528                default:
1529                    ; // noop
1530              }              }
1531              return;              return;
1532          }          }
# Line 1393  namespace sfz Line 1611  namespace sfz
1611    
1612          // amplifier          // amplifier
1613          else if ("volume"   == key) pCurDef->volume = ToFloat(value);          else if ("volume"   == key) pCurDef->volume = ToFloat(value);
1614            else if ("amplitude" == key) pCurDef->amplitude = ToFloat(value);
1615          else if ("pan"      == key) pCurDef->pan = ToFloat(value);          else if ("pan"      == key) pCurDef->pan = ToFloat(value);
1616          else if ("width"    == key) pCurDef->width = ToFloat(value);          else if ("width"    == key) pCurDef->width = ToFloat(value);
1617          else if ("position" == key) pCurDef->position = ToFloat(value);          else if ("position" == key) pCurDef->position = ToFloat(value);
# Line 1709  namespace sfz Line 1928  namespace sfz
1928              if (key_cc.size() > 3 && !strcmp(key_cc.c_str() + (key_cc.size() - 3), "_on")) {              if (key_cc.size() > 3 && !strcmp(key_cc.c_str() + (key_cc.size() - 3), "_on")) {
1929                  key_cc = key_cc.substr(0, key_cc.size() - 3);                  key_cc = key_cc.substr(0, key_cc.size() - 3);
1930              }              }
1931              int num_cc = ToInt(key.substr(delimiter_index + 2));              
1932                // Apply macros
1933                std::string num_cc_str = key.substr(delimiter_index + 2);
1934                
1935                if (num_cc_str[0] == '$')
1936                {
1937                    if (_defined_macros.count(num_cc_str) == 0)
1938                    {
1939                        std::cerr << "Macro '" << value << "' referenced on line ";
1940                        std::cerr << currentLine << " is undefined." << std::endl;
1941                        return;
1942                    }
1943                    
1944                    num_cc_str = _defined_macros[num_cc_str];
1945                }
1946    
1947                int num_cc = ToInt(num_cc_str);
1948                if (num_cc < 0 || num_cc > 127) {
1949                    std::cerr << "sfz: WARNING: CC " << num_cc << " of opcode '" << key;
1950                    std::cerr << "' is an invalid MIDI controller number." << std::endl;
1951                }
1952    
1953              // input controls              // input controls
1954              if ("lo" == key_cc) pCurDef->locc.set(num_cc, ToInt(value));              if ("lo" == key_cc) pCurDef->locc.set(num_cc, ToInt(value));
# Line 1811  namespace sfz Line 2050  namespace sfz
2050              else if ("volume_curve" == key_cc) pCurDef->volume_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) );              else if ("volume_curve" == key_cc) pCurDef->volume_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) );
2051              else if ("volume_smooth" == key_cc) pCurDef->volume_smoothcc.add( CC(num_cc, 0, -1, check(key, 0.0f, 100000.0f /* max? */, ToFloat(value))) );              else if ("volume_smooth" == key_cc) pCurDef->volume_smoothcc.add( CC(num_cc, 0, -1, check(key, 0.0f, 100000.0f /* max? */, ToFloat(value))) );
2052              else if ("volume_step" == key_cc) pCurDef->volume_stepcc.add( CC(num_cc, 0, -1, 0, check(key, -20.0f, 20.0f, ToFloat(value))) );              else if ("volume_step" == key_cc) pCurDef->volume_stepcc.add( CC(num_cc, 0, -1, 0, check(key, -20.0f, 20.0f, ToFloat(value))) );
2053              else if ("pan" == key_cc) pCurDef->pan_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) );              else if ("pan" == key_cc) pCurDef->pan_oncc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) );
2054              else if ("pan_curve" == key_cc) pCurDef->pan_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) );              else if ("pan_curve" == key_cc) pCurDef->pan_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) );
2055              else if ("pan_smooth" == key_cc) pCurDef->pan_smoothcc.add( CC(num_cc, 0, -1, check(key, 0.0f, 100000.0f /* max? */, ToFloat(value))) );              else if ("pan_smooth" == key_cc) pCurDef->pan_smoothcc.add( CC(num_cc, 0, -1, check(key, 0.0f, 100000.0f /* max? */, ToFloat(value))) );
2056              else if ("pan_step" == key_cc) pCurDef->pan_stepcc.add( CC(num_cc, 0, -1, 0, check(key, -100.0f, 100.0f, ToFloat(value))) );              else if ("pan_step" == key_cc) pCurDef->pan_stepcc.add( CC(num_cc, 0, -1, 0, check(key, -100.0f, 100.0f, ToFloat(value))) );
2057                else if ("set_" == key_cc) _instrument->initialCCValues[num_cc] = (num_cc < 128) ? check(key, 0, 127, ToInt(value)) : ToInt(value);
2058              else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;              else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl;
2059          }          }
2060    
# Line 1873  namespace sfz Line 2113  namespace sfz
2113      }      }
2114    
2115      EG::EG() :      EG::EG() :
2116          sustain(0), loop(0), loop_count(0), amplitude(0), pan(0), pan_curve(-1),          sustain(0), loop(0), loop_count(0), amplitude(0), volume(-200), /* less than -144 dB is considered unset */
2117          cutoff(0), pitch(0), resonance(0), volume(-200) /* less than -144 dB is considered unset */          cutoff(0), pitch(0), resonance(0), pan(0), pan_curve(-1)
2118      { }      { }
2119            
2120      void EG::Copy(const EG& eg) {      void EG::Copy(const EG& eg) {
# Line 1901  namespace sfz Line 2141  namespace sfz
2141          pan_curvecc    = eg.pan_curvecc;          pan_curvecc    = eg.pan_curvecc;
2142      }      }
2143            
2144      LFO::LFO(): freq (-1),/* -1 is used to determine whether the LFO was initialized */      LFO::LFO():
2145                  fade(0), phase(0), wave(0), delay(0), pitch(0), cutoff(0), resonance(0), pan(0), volume(0) {          delay(0),
2146                    freq(-1), /* -1 is used to determine whether the LFO was initialized */
2147            fade(0), phase(0), wave(0), volume(0), pitch(0), cutoff(0), resonance(0), pan(0)
2148        {
2149      }      }
2150        
2151      void LFO::Copy(const LFO& lfo) {      void LFO::Copy(const LFO& lfo) {
2152          EqSmoothStepImpl::Copy(static_cast<const EqSmoothStepImpl>(lfo));          EqSmoothStepImpl::Copy(static_cast<const EqSmoothStepImpl>(lfo));
2153                    

Legend:
Removed from v.2299  
changed lines
  Added in v.3291

  ViewVC Help
Powered by ViewVC