diff data/midi/MIDIEvent.h @ 1057:5c5d4863b428 tonioni

Merge from cxx11 branch
author Chris Cannam
date Mon, 23 Mar 2015 11:26:28 +0000
parents cc27f35aa75c
children 48e9f538e6e9
line wrap: on
line diff
--- a/data/midi/MIDIEvent.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/midi/MIDIEvent.h	Mon Mar 23 11:26:28 2015 +0000
@@ -25,6 +25,8 @@
 #include <QString>
 #include <string>
 #include <iostream>
+#include <stdexcept>
+
 #include "base/Debug.h"
 
 typedef unsigned char MIDIByte;
@@ -118,16 +120,22 @@
 {
 public:
     MIDIEvent(unsigned long deltaTime,
-              MIDIByte eventCode,
-              MIDIByte data1 = 0,
-              MIDIByte data2 = 0) :
+              int eventCode,
+              int data1 = 0,
+              int data2 = 0) :
 	m_deltaTime(deltaTime),
 	m_duration(0),
-	m_eventCode(eventCode),
-	m_data1(data1),
-	m_data2(data2),
 	m_metaEventCode(0)
-    { }
+    {
+        if (eventCode < 0 || eventCode > 0xff ||
+            data1 < 0 || data1 > 0xff ||
+            data2 < 0 || data2 > 0xff) {
+            throw std::domain_error("not all args within byte range");
+        }
+        m_eventCode = MIDIByte(eventCode);
+        m_data1 = MIDIByte(data1);
+        m_data2 = MIDIByte(data2);
+    }
 
     MIDIEvent(unsigned long deltaTime,
               MIDIByte eventCode,