OSDN Git Service

各トラックリストブロックで開始時刻をそろえるようにした
authorstarg <starg@users.osdn.me>
Wed, 24 Aug 2016 13:51:46 +0000 (22:51 +0900)
committerstarg <starg@users.osdn.me>
Wed, 24 Aug 2016 13:51:46 +0000 (22:51 +0900)
include/ir2midi/context.hpp
src/ir2midi/context.cpp
src/ir2midi/ir2midi.cpp

index e122e0e..b808938 100644 (file)
@@ -23,8 +23,8 @@ class TrackCompilerContext final
 {
 public:
     void EnterBlock();
-    void SaveTime();
-    void RestoreTime();
+    int GetLastTime();
+    void SetTime(int t);
     void UpdateTime(int relativeTime);
     void PushEvent(int relativeTime, const MIDI::MIDIEvent::EventType& ev);
     void SortEvents();
@@ -34,7 +34,6 @@ private:
     std::vector<AbsoluteMIDIEvent> m_Events;
     int m_BaseTimeForCurrentBlock = 0;
     int m_LastEventTime = 0;
-    int m_PrevLastEventTime = 0;
 };
 
 class IIR2MIDICompiler
index 7362803..4a8e5d4 100644 (file)
@@ -14,14 +14,15 @@ void TrackCompilerContext::EnterBlock()
     m_BaseTimeForCurrentBlock = m_LastEventTime;
 }
 
-void TrackCompilerContext::SaveTime()
+int TrackCompilerContext::GetLastTime()
 {
-    m_PrevLastEventTime = m_LastEventTime;
+    return m_LastEventTime;
 }
 
-void TrackCompilerContext::RestoreTime()
+void TrackCompilerContext::SetTime(int t)
 {
-    m_LastEventTime = m_PrevLastEventTime;
+    m_LastEventTime = t;
+    m_BaseTimeForCurrentBlock = t;
 }
 
 void TrackCompilerContext::UpdateTime(int relativeTime)
index debc350..8279f4c 100644 (file)
@@ -1,5 +1,7 @@
 
+#include <algorithm>
 #include <exception>
+#include <vector>
 
 #include <boost/variant.hpp>
 
@@ -124,17 +126,19 @@ void IR2MIDICompiler::operator()(const IR::TrackList& ir)
 {
     CheckForUnprocessedAttributes(ir.Attributes);
 
+    int lastTime = 0;
+
     for (auto&& i : ir.Tracks)
     {
         CheckForUnprocessedAttributes(i.Attributes);
         EnsureTrackInitialized(i.Number);
 
-        GetTrackContext(i.Number).SaveTime();
+        lastTime = std::max(GetTrackContext(i.Number).GetLastTime(), lastTime);
     }
 
     for (auto&& i : ir.Tracks)
     {
-        GetTrackContext(i.Number).RestoreTime();
+        GetTrackContext(i.Number).SetTime(lastTime);
 
         for (auto&& j : i.Items)
         {