OSDN Git Service

ブロックを含むフレーズの音のタイミングがずれていたのを修正
authorstarg <starg@users.osdn.me>
Tue, 23 Aug 2016 20:45:34 +0000 (05:45 +0900)
committerstarg <starg@users.osdn.me>
Tue, 23 Aug 2016 20:45:34 +0000 (05:45 +0900)
同一のトラックリストに同じトラック番号が複数あった場合、それらが同時に演奏されるように変更

include/ir2midi/context.hpp
src/ir2midi/context.cpp
src/ir2midi/ir2midi.cpp

index 734341d..dc414a3 100644 (file)
@@ -23,6 +23,8 @@ class TrackCompilerContext final
 {
 public:
     void EnterBlock();
+    void SaveTime();
+    void RestoreTime();
     void PushEvent(int relativeTime, const MIDI::MIDIEvent::EventType& ev);
     void SortEvents();
     const std::vector<AbsoluteMIDIEvent>& GetEvents() const;
@@ -31,6 +33,7 @@ private:
     std::vector<AbsoluteMIDIEvent> m_Events;
     int m_BaseTimeForCurrentBlock = 0;
     int m_LastEventTime = 0;
+    int m_PrevLastEventTime = 0;
 };
 
 class IIR2MIDICompiler
index 504bd60..8734a22 100644 (file)
@@ -14,10 +14,20 @@ void TrackCompilerContext::EnterBlock()
     m_BaseTimeForCurrentBlock = m_LastEventTime;
 }
 
+void TrackCompilerContext::SaveTime()
+{
+    m_PrevLastEventTime = m_LastEventTime;
+}
+
+void TrackCompilerContext::RestoreTime()
+{
+    m_LastEventTime = m_PrevLastEventTime;
+}
+
 void TrackCompilerContext::PushEvent(int relativeTime, const MIDI::MIDIEvent::EventType& ev)
 {
     m_LastEventTime = m_BaseTimeForCurrentBlock + relativeTime;
-    m_Events.push_back(AbsoluteMIDIEvent{m_BaseTimeForCurrentBlock + relativeTime, ev});
+    m_Events.push_back(AbsoluteMIDIEvent{m_LastEventTime, ev});
 }
 
 void TrackCompilerContext::SortEvents()
index b429962..7d6d861 100644 (file)
@@ -128,9 +128,17 @@ void IR2MIDICompiler::operator()(const IR::TrackList& ir)
         CheckForUnprocessedAttributes(i.Attributes);
         EnsureTrackInitialized(i.Number);
 
+        GetTrackContext(i.Number).SaveTime();
+    }
+
+    for (auto&& i : ir.Tracks)
+    {
+        GetTrackContext(i.Number).RestoreTime();
+
         for (auto&& j : i.Items)
         {
             CheckForUnprocessedAttributes(j.Attributes);
+            GetTrackContext(i.Number).EnterBlock();
             CompileBlock(i.Number, j.Block);
         }
     }
@@ -197,8 +205,6 @@ bool IR2MIDICompiler::CompileTrackBlock(const std::string& trackBlockName)
 
 void IR2MIDICompiler::CompileBlock(int trackNumber, IR::BlockReference blockRef)
 {
-    GetTrackContext(trackNumber).EnterBlock();
-
     const auto& block = m_IR.Blocks.at(blockRef.ID);
     CheckForUnprocessedAttributes(block.Attributes);