]> git.treefish.org Git - seamulator.git/blobdiff - src/dot.cpp
make some noise
[seamulator.git] / src / dot.cpp
diff --git a/src/dot.cpp b/src/dot.cpp
new file mode 100644 (file)
index 0000000..d052a24
--- /dev/null
@@ -0,0 +1,43 @@
+#include "dot.h"
+
+Dot::Dot(const SurfacePoint& point, double frequency) :
+    m_point{point},
+    m_frequency{frequency}
+{
+    m_noise.noteOn(frequency, 1.0);
+//    m_noise.setFrequency(frequency);
+}
+
+void Dot::advance(double deltaT)
+{
+//    std::lock_guard<std::mutex> lock{m_mutex};
+
+    //deltaT *= 10;
+    
+    auto posBefore = m_pos;
+
+    m_vel += -std::pow(m_frequency / 440.0, 2.0) * 1.0 * ( m_pos - m_point.getHeight() ) * deltaT;
+    m_vel -= m_vel * 0.01 * deltaT;
+    m_pos += m_vel * deltaT;
+
+    const auto absVel = std::fabs(m_vel);
+    m_maxAbsVel = std::max(absVel, m_maxAbsVel);
+
+    //std::cout << m_pos << std::endl;
+    
+    if (posBefore * m_pos < 0.0) {
+// //        std::cout << m_vel / m_maxVel << std::endl;
+        m_noise.noteOn(m_pos >= 0 ? m_frequency : m_frequency*0.5, absVel / m_maxAbsVel);
+//         //m_noise.pluck(absVel / m_maxAbsVel);
+//         m_noise.controlChange(4, 1.0 * absVel / m_maxAbsVel);
+    }
+
+//    m_noise.controlChange(128, 128.0 * absVel / m_maxAbsVel);
+}
+
+stk::StkFloat Dot::tick()
+{
+//    std::lock_guard<std::mutex> lock{m_mutex};
+
+    return m_noise.tick();
+}