From 775e39edab4f2ee94c2ca74d6090a634612efba2 Mon Sep 17 00:00:00 2001
From: Per Lindgren <per.lindgren@ltu.se>
Date: Sun, 17 May 2020 23:19:27 +0200
Subject: [PATCH] midi log works 2

---
 .vscode/settings.json      | 70 +++++++++++++++++++++++++++++++++++++-
 Source/PluginEditor.cpp    |  7 ++--
 Source/PluginProcessor.cpp | 38 +++++++++++++++------
 Source/PluginProcessor.h   |  1 +
 4 files changed, 101 insertions(+), 15 deletions(-)

diff --git a/.vscode/settings.json b/.vscode/settings.json
index c44c0e6..a16ca39 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -3,6 +3,74 @@
         "mylog"
     ],
     "files.associations": {
-        "*.mm": "cpp"
+        "*.mm": "cpp",
+        "cctype": "cpp",
+        "clocale": "cpp",
+        "cmath": "cpp",
+        "csignal": "cpp",
+        "cstdarg": "cpp",
+        "cstddef": "cpp",
+        "cstdio": "cpp",
+        "cstdlib": "cpp",
+        "cstring": "cpp",
+        "ctime": "cpp",
+        "cwchar": "cpp",
+        "cwctype": "cpp",
+        "array": "cpp",
+        "atomic": "cpp",
+        "hash_map": "cpp",
+        "hash_set": "cpp",
+        "bit": "cpp",
+        "*.tcc": "cpp",
+        "bitset": "cpp",
+        "chrono": "cpp",
+        "cinttypes": "cpp",
+        "codecvt": "cpp",
+        "complex": "cpp",
+        "condition_variable": "cpp",
+        "cstdint": "cpp",
+        "deque": "cpp",
+        "list": "cpp",
+        "map": "cpp",
+        "set": "cpp",
+        "unordered_map": "cpp",
+        "unordered_set": "cpp",
+        "vector": "cpp",
+        "exception": "cpp",
+        "algorithm": "cpp",
+        "functional": "cpp",
+        "iterator": "cpp",
+        "memory": "cpp",
+        "memory_resource": "cpp",
+        "numeric": "cpp",
+        "optional": "cpp",
+        "random": "cpp",
+        "ratio": "cpp",
+        "regex": "cpp",
+        "string": "cpp",
+        "string_view": "cpp",
+        "system_error": "cpp",
+        "tuple": "cpp",
+        "type_traits": "cpp",
+        "utility": "cpp",
+        "fstream": "cpp",
+        "future": "cpp",
+        "initializer_list": "cpp",
+        "iomanip": "cpp",
+        "iosfwd": "cpp",
+        "iostream": "cpp",
+        "istream": "cpp",
+        "limits": "cpp",
+        "mutex": "cpp",
+        "new": "cpp",
+        "ostream": "cpp",
+        "shared_mutex": "cpp",
+        "sstream": "cpp",
+        "stdexcept": "cpp",
+        "streambuf": "cpp",
+        "thread": "cpp",
+        "typeinfo": "cpp",
+        "valarray": "cpp",
+        "variant": "cpp"
     }
 }
\ No newline at end of file
diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp
index 4148313..220bce3 100644
--- a/Source/PluginEditor.cpp
+++ b/Source/PluginEditor.cpp
@@ -33,7 +33,8 @@ void Test2AudioProcessorEditor::paint(juce::Graphics &g)
 
   g.setColour(juce::Colours::white);
   g.setFont(15.0f);
-  g.drawFittedText("Hello Per6!", getLocalBounds(), juce::Justification::centred, 1);
+  g.drawFittedText("Hello Per 10 !", getLocalBounds(), juce::Justification::centred, 1);
+  g.drawFittedText("Hello Per 10 !", getLocalBounds(), juce::Justification::centred, 1);
   if (processor.m_flogger)
     processor.m_flogger->logMessage("paint called");
 }
@@ -45,6 +46,6 @@ void Test2AudioProcessorEditor::resized()
 
   auto bounds = getLocalBounds();
 
-  //if (m_flogger)
-  //  m_flogger->logMessage(bounds.toString());
+  if (processor.m_flogger)
+    processor.m_flogger->logMessage(bounds.toString());
 }
diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp
index df4da31..9612e86 100644
--- a/Source/PluginProcessor.cpp
+++ b/Source/PluginProcessor.cpp
@@ -23,6 +23,9 @@ Test2AudioProcessor::Test2AudioProcessor()
 #endif
 {
     m_flogger = std::unique_ptr<juce::FileLogger>(juce::FileLogger::createDateStampedLogger("foo", "mylog", ".txt", "Welcome to plugin"));
+
+    position = 0;
+
     if (m_flogger)
         m_flogger->logMessage("PluginProcessor");
 }
@@ -153,22 +156,35 @@ void Test2AudioProcessor::processBlock(juce::AudioBuffer<float> &buffer, juce::M
         // ..do something to the data...
     }
 
-    // auto iterator = midiMessages.Iterator;
-    auto iterator = juce::MidiBuffer::Iterator(midiMessages);
-    juce::MidiMessage msg;
-    int sampleNum;
-
-    while (iterator.getNextEvent(msg, sampleNum))
+    for (const auto metadata : midiMessages)
     {
+        auto msg = metadata.getMessage();
         if (msg.isController())
         {
-            //const auto *name = msg.getDescription();
-            //::MidiMessage::getControllerName(msg.getControllerNumber());
-            //const auto *name = juce::MidiMessage::getControllerName(msg.getControllerNumber());
+            if (msg.getRawData()[1] == 30)
+            {
+                switch (msg.getRawData()[2])
+                {
+                case 1:
+                    position--;
+                    break;
+                case 127:
+                    position++;
+                    break;
+                }
+            };
             if (m_flogger)
+            {
                 m_flogger->logMessage(msg.getDescription());
-        }
-    }
+                m_flogger->logMessage("pos " + std::to_string(position));
+                //for (int i = 0; i < msg.getRawDataSize(); i++)
+                //{
+                //    juce::uint8 val = msg.getRawData()[i];
+                //    m_flogger->logMessage(std::to_string(val));
+                //};
+            };
+        };
+    };
 }
 
 //==============================================================================
diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h
index baae61b..06e1bb4 100644
--- a/Source/PluginProcessor.h
+++ b/Source/PluginProcessor.h
@@ -54,6 +54,7 @@ public:
   void setStateInformation(const void *data, int sizeInBytes) override;
 
   std::unique_ptr<juce::FileLogger> m_flogger;
+  int position;
 
 private:
   //==============================================================================
-- 
GitLab