YSE sound engine  1.0
cross platform sound engine
 All Classes Namespaces Functions Pages
synthInterface.hpp
1 /*
2  ==============================================================================
3 
4  synthInterface.h
5  Created: 6 Jul 2014 10:02:00pm
6  Author: yvan
7 
8  ==============================================================================
9 */
10 
11 #ifndef SYNTHINTERFACE_HPP_INCLUDED
12 #define SYNTHINTERFACE_HPP_INCLUDED
13 
14 #include "../classes.hpp"
15 #include "../headers/defines.hpp"
16 #include "dspVoice.hpp"
17 #include <string>
18 
19 namespace YSE {
20  // don't mind this (it's needed for friend declaration)
21  namespace MIDI {
22  class fileImpl;
23  }
24 
25  namespace SYNTH {
26 
27  class API samplerConfig {
28  public:
29  samplerConfig();
30 
31  samplerConfig & name(const char * name);
32  samplerConfig & file(const char * file);
33 
34  // the midi channel for which to accepts events (default to 0, which is omni)
36 
37  // the note to map the default playing speed to (default = 60)
38  samplerConfig & root(U8 rootNote);
39 
40  // the lowest and highest note this sample should play (default 0 - 128)
41  samplerConfig & range(U8 low, U8 high);
42 
43  // attack time, release time and maximum length in seconds
44  // default is 0, 0.1, 10
45  samplerConfig & envelope(Flt attack, Flt release, Flt maxLength);
46 
47  const std::string & name() const { return _name; }
48  const std::string & file() const { return _file; }
49  U8 channel () const { return _channel ; }
50  U8 root () const { return _rootNote ; }
51  U8 lowestNote () const { return _lowestNote ; }
52  U8 highestNote () const { return _highestNote; }
53  Flt attackTime () const { return _attackTime ; }
54  Flt releaseTime() const { return _releaseTime; }
55  Flt maxLength () const { return _maxLength ; }
56 
57 
58  private:
59  std::string _name;
60  std::string _file;
61  U8 _channel ;
62  U8 _rootNote ;
63  U8 _lowestNote ;
64  U8 _highestNote;
65  Flt _attackTime ;
66  Flt _releaseTime;
67  Flt _maxLength ;
68  };
69 
70  class API interfaceObject {
71  public:
73  ~interfaceObject();
74 
75  // Sound interfaces cannot be copied. The implementation needs access to the
76  // interface object. To do this, the address of the interface must not change.
77  interfaceObject(const interfaceObject&) = delete;
78 
79  interfaceObject & create();
80  interfaceObject & addVoices(const samplerConfig & voice, int numVoices);
81  interfaceObject & addVoices(dspVoice * voice, int numVoices, int channel, int lowestNote=0, int highestNote=128);
82 
83  // sounds are recognized by the name you give them in a samplerConfig
84  // when you add them
85  interfaceObject & removeSound(const std::string & name);
86 
87  interfaceObject & noteOn (int channel, int noteNumber, float velocity);
88  interfaceObject & noteOff(int channel, int noteNumber);
89 
90  interfaceObject & pitchWheel(int channel , int value);
91  interfaceObject & controller(int channel, int number , int value);
92  interfaceObject & aftertouch(int channel, int noteNumber, int value);
93  interfaceObject & sustain (int channel, bool value);
94  interfaceObject & sostenuto (int channel, bool value);
95  interfaceObject & softPedal (int channel, bool value);
96 
97  // pass 0 as channel to turn off all notes on all channels
98  interfaceObject & allNotesOff(int channel);
99 
100  int getNumVoices() { return numVoices; }
101 
102  private:
103  implementationObject * pimpl;
104  int numVoices;
105  friend class implementationObject;
106  friend class SOUND::interfaceObject;
107  friend class MIDI::fileImpl;
108  };
109 
110  }
111 }
112 
113 
114 
115 #endif // SYNTHINTERFACE_H_INCLUDED
116 
Channels are used to control groups of sounds simultaniously.
A sound object is needed for every kind of sound you want to use.