@@ -22,7 +22,7 @@ pub const MAX_SAMPLE_RATE: f32 = 384_000.0;
2222
2323/// All the possible types allowed in an Opcode
2424#[ allow( non_camel_case_types) ]
25- #[ derive( Debug , Clone ) ]
25+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
2626pub enum OpcodeType {
2727 i8( Option < i8 > ) ,
2828 u8( Option < u8 > ) ,
@@ -43,17 +43,41 @@ pub type OpcodeMap = HashMap<String, Opcode>;
4343/// Allows playing samples with loops defined in the unlooped mode.
4444///
4545/// - info: [loop_mode](https://sfzformat.com/opcodes/loop_mode)
46- #[ derive( Debug , Clone , PartialEq ) ]
46+ #[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
4747#[ allow( non_camel_case_types) ]
4848pub enum loop_mode {
49+ /// no looping will be performed. Sample will play straight from start to end,
50+ /// or until note off, whatever reaches first.
51+ ///
52+ /// This is the default.
4953 no_loop,
54+
55+ /// sample will play from start to end, ignoring note off. This is commonly
56+ /// used for drums. This mode is engaged automatically if the count opcode
57+ /// is defined.
5058 one_shot,
59+
60+ /// once the player reaches sample loop point, the loop will play until note
61+ /// expiration. This includes looping during the release phase.
5162 loop_continuous,
63+
64+ /// the player will play the loop while the note is held, by keeping it
65+ /// depressed or by using the sustain pedal (CC64). During the release phase,
66+ /// there’s no looping.
5267 loop_sustain,
5368}
69+
70+ // IMPROVE: `no_loop` for samples without a loop defined,
71+ // `loop_continuous` for samples with defined loop(s).
72+ impl Default for loop_mode {
73+ fn default ( ) -> loop_mode {
74+ Self :: no_loop
75+ }
76+ }
77+
5478impl loop_mode {
5579 /// Constructor from the variant name, as a string
56- pub fn from_str ( name : & str ) -> Option < Self > {
80+ pub fn from_name ( name : & str ) -> Option < Self > {
5781 match name {
5882 "no_loop" => Some ( Self :: no_loop) ,
5983 "one_shot" => Some ( Self :: one_shot) ,
@@ -67,18 +91,38 @@ impl loop_mode {
6791/// Sets the trigger which will be used for the sample to play.
6892///
6993/// - info: [trigger](https://sfzformat.com/opcodes/trigger)
70- #[ derive( Debug , Clone , PartialEq ) ]
94+ #[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
7195#[ allow( non_camel_case_types) ]
7296pub enum trigger {
97+ /// (Default): Region will play on note-on.
7398 attack,
99+
100+ /// Region will play on note-off or sustain pedal off. The velocity used to
101+ /// play the note-off sample is the velocity value of the corresponding
102+ /// (previous) note-on message.
74103 release,
104+
105+ /// Region will play on note-on, but if there’s no other note going on
106+ /// (comoonly used for or first note in a legato phrase).
75107 first,
108+
109+ /// Region will play on note-on, but only if there’s a note going on
110+ /// (notes after first note in a legato phrase).
76111 legato,
112+
113+ /// Region will play on note-off. Ignores sustain pedal.
77114 release_key, // aria
78115}
116+
117+ impl Default for trigger {
118+ fn default ( ) -> trigger {
119+ Self :: attack
120+ }
121+ }
122+
79123impl trigger {
80124 /// Constructor from the variant name, as a string
81- pub fn from_str ( name : & str ) -> Option < Self > {
125+ pub fn from_name ( name : & str ) -> Option < Self > {
82126 match name {
83127 "attack" => Some ( Self :: attack) ,
84128 "release" => Some ( Self :: release) ,
@@ -93,7 +137,7 @@ impl trigger {
93137/// Allows you to choose which type of filter you use if not specified
94138///
95139/// - info: [fil_type](https://sfzformat.com/opcodes/fil_type)
96- #[ derive( Debug , Clone , PartialEq ) ]
140+ #[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
97141#[ allow( non_camel_case_types) ]
98142pub enum fil_type {
99143 /// One-pole low pass filter (6dB/octave)
@@ -108,6 +152,8 @@ pub enum fil_type {
108152
109153 /// Two-pole low pass filter (12dB/octave)
110154 ///
155+ /// This is the default.
156+ ///
111157 /// - version: v1
112158 lpf_2p,
113159
@@ -211,9 +257,16 @@ pub enum fil_type {
211257 /// - version: ARIA
212258 peq,
213259}
260+
261+ impl Default for fil_type {
262+ fn default ( ) -> fil_type {
263+ Self :: lpf_2p
264+ }
265+ }
266+
214267impl fil_type {
215268 /// Constructor from the variant name, as a string
216- pub fn from_str ( name : & str ) -> Option < Self > {
269+ pub fn from_name ( name : & str ) -> Option < Self > {
217270 match name {
218271 "lpf_1p" => Some ( Self :: lpf_1p) ,
219272 "hpf_1p" => Some ( Self :: hpf_1p) ,
0 commit comments