2121#include " ../../domain/midi_cc_data.hpp"
2222#include " ../../domain/pitch_bend_data.hpp"
2323#include " ../position.hpp"
24+ #include " property_service.hpp"
2425
2526#include < algorithm>
2627#include < cmath> // For std::sin and M_PI
@@ -34,7 +35,8 @@ namespace noteahead {
3435
3536static const auto TAG = " AutomationService" ;
3637
37- AutomationService::AutomationService ()
38+ AutomationService::AutomationService (std::shared_ptr<PropertyService> propertyService) :
39+ m_propertyService { propertyService }
3840{
3941}
4042
@@ -416,9 +418,9 @@ AutomationService::EventList AutomationService::renderMidiCcToEventsByLine(size_
416418 totalModulation = modulationValue * modulation.amplitude / 100.0 ; // Amplitude is a percentage
417419 }
418420 totalModulation += modulation.offset / 100.0 ;
419- interpolatedValue += interpolatedValue * totalModulation ;
421+ interpolatedValue += totalModulation * m_propertyService-> maxValue (automation. controller ()) ;
420422
421- const auto clampedValue = std::clamp (static_cast <int >(std::round (interpolatedValue)), 0 , 127 ); // MIDI CC value range
423+ const auto clampedValue = std::clamp (static_cast <int >(std::round (interpolatedValue)), 0 , m_propertyService-> maxValue (automation. controller ()) ); // MIDI CC value range
422424 events.push_back (std::make_shared<Event>(tick, MidiCcData { track, column, automation.controller (), static_cast <uint8_t >(clampedValue) }));
423425 }
424426 }
@@ -473,7 +475,7 @@ AutomationService::EventList AutomationService::renderPitchBendToEventsByLine(si
473475 totalModulation = modulationValue * modulation.amplitude / 100.0 ; // Amplitude is a percentage
474476 }
475477 totalModulation += modulation.offset / 100.0 ;
476- interpolatedValue += interpolatedValue * totalModulation ;
478+ interpolatedValue += totalModulation * 100.0 ;
477479
478480 const auto percentage = std::clamp (static_cast <int >(std::round (interpolatedValue)), -100 , 100 );
479481 events.push_back (std::make_shared<Event>(tick, PitchBendData { track, column, static_cast <double >(percentage) }));
@@ -548,9 +550,9 @@ AutomationService::EventList AutomationService::renderMidiCcToEventsByColumn(siz
548550 totalModulation = modulationValue * modulation.amplitude / 100.0 ;
549551 }
550552 totalModulation += modulation.offset / 100.0 ;
551- interpolatedValue += interpolatedValue * totalModulation ;
553+ interpolatedValue += totalModulation * m_propertyService-> maxValue (automation. controller ()) ;
552554
553- const auto clampedValue = std::clamp (static_cast <int >(std::round (interpolatedValue)), 0 , 127 ); // MIDI CC value range
555+ const auto clampedValue = std::clamp (static_cast <int >(std::round (interpolatedValue)), 0 , m_propertyService-> maxValue (automation. controller ()) ); // MIDI CC value range
554556 if (!prevValue || *prevValue != clampedValue) {
555557 events.push_back (std::make_shared<Event>(tick + line * ticksPerLine, MidiCcData { track, column, automation.controller (), static_cast <uint8_t >(clampedValue) }));
556558 prevValue = clampedValue;
@@ -595,7 +597,7 @@ AutomationService::EventList AutomationService::renderPitchBendToEventsByColumn(
595597 totalModulation = modulationValue * modulation.amplitude / 100.0 ;
596598 }
597599 totalModulation += modulation.offset / 100.0 ;
598- interpolatedValue += interpolatedValue * totalModulation ;
600+ interpolatedValue += totalModulation * 100.0 ;
599601
600602 const auto percentage = std::clamp (static_cast <int >(std::round (interpolatedValue)), -100 , 100 );
601603 const double minDiff = 200.0 / 16383 ;
0 commit comments