KIK01 Proto 08

Dependencies:   AverageMCP3008 VoltageMonitor mbed-rtos mbed mcp3008

Fork of KIK01_Proto07 by Ryo Od

Revision:
25:b4977c7e0db7
Parent:
24:e9fbadd15e90
--- a/EnvelopeAR.h	Thu Sep 28 01:21:04 2017 +0000
+++ b/EnvelopeAR.h	Thu Sep 28 02:32:53 2017 +0000
@@ -5,10 +5,22 @@
  *
  */
 
- #ifndef _ENVELOPE_AR_H_
- #define _ENVELOPE_AR_H_
- 
- class EnvelopeAR
+#ifndef _ENVELOPE_AR_H_
+#define _ENVELOPE_AR_H_
+
+class EnvelopeParam
+{
+public:
+    int attack;
+    int release;
+    float v0;
+    float v1;
+    float v2;
+    float attackTauRatio;
+    float releaseTauRatio;
+};
+
+class EnvelopeAR
 {
 public:
     EnvelopeAR(int _attack, int _release, float _v0, float _v1, float _v2, float _attackTauRatio=0.36f, float _releaseTauRatio=0.36f) :
@@ -17,11 +29,24 @@
         v1(_v1),
         v2(_v2),
         attackTauRatio(_attackTauRatio),
-        releaseTauRatio(_releaseTauRatio) {
+        releaseTauRatio(_releaseTauRatio)
+    {
         setAttack(_attack);
         setRelease(_release);
     }
 
+    EnvelopeAR(const EnvelopeParam& param) :
+        amplitude(param.v0),
+        v0(param.v0),
+        v1(param.v1),
+        v2(param.v2),
+        attackTauRatio(param.attackTauRatio),
+        releaseTauRatio(param.releaseTauRatio)
+    {
+        setAttack(param.attack);
+        setRelease(param.release);
+    }
+
     ~EnvelopeAR() {}
 
     void setAttack(int _attack) {
@@ -86,6 +111,16 @@
         return amplitude;
     }
     
+    void setParam(const EnvelopeParam& param) {
+        setV0(param.v0);
+        setV1(param.v1);
+        setV2(param.v2);
+        setAttackTauRatio(param.attackTauRatio);
+        setReleaseTauRatio(param.releaseTauRatio);
+        setAttack(param.attack);
+        setRelease(param.release);
+    }
+
     float getAmplitude(int tick) {
         if (tick <= attack) {
             // attackの処理
@@ -111,16 +146,4 @@
     float releaseTauRatio;
 };
 
-class EnvelopeParam
-{
-public:
-    int attack;
-    int release;
-    float v0;
-    float v1;
-    float v2;
-    float attackTauRatio;
-    float releaseTauRatio;
-};
-
 #endif //_ENVELOPE_AR_H_