summaryrefslogtreecommitdiffabout
path: root/lib/message.cc
Unidiff
Diffstat (limited to 'lib/message.cc') (more/less context) (show whitespace changes)
-rw-r--r--lib/message.cc1
1 files changed, 1 insertions, 0 deletions
diff --git a/lib/message.cc b/lib/message.cc
index 8f9e68a..6a5cfd6 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -1,98 +1,99 @@
1#include <algorithm> 1#include <algorithm>
2#include <iterator> 2#include <iterator>
3#include <cassert>
3#include <midillo/message.h> 4#include <midillo/message.h>
4#include <midillo/util.h> 5#include <midillo/util.h>
5#include <midillo/exception.h> 6#include <midillo/exception.h>
6 7
7namespace midillo { 8namespace midillo {
8 using std::copy; 9 using std::copy;
9 using std::ostream_iterator; 10 using std::ostream_iterator;
10 11
11 unsigned long message_t::calculate_save_size(int& rs) const { 12 unsigned long message_t::calculate_save_size(int& rs) const {
12 unsigned long rv = 0; 13 unsigned long rv = 0;
13 if(status!=rs) { 14 if(status!=rs) {
14 ++rv; 15 ++rv;
15 rs = status; 16 rs = status;
16 }else if((status&status_event_bits)==status_system) { 17 }else if((status&status_event_bits)==status_system) {
17 rs = -1; 18 rs = -1;
18 ++rv; // XXX: is it really needed? 19 ++rv; // XXX: is it really needed?
19 } 20 }
20 switch(status&status_event_bits) { 21 switch(status&status_event_bits) {
21 case status_note_off: 22 case status_note_off:
22 case status_note_on: 23 case status_note_on:
23 case status_polyphonic_key_pressure: // aka status_aftertouch 24 case status_polyphonic_key_pressure: // aka status_aftertouch
24 case status_control_change: 25 case status_control_change:
25 case status_pitch_wheel_change: 26 case status_pitch_wheel_change:
26 rv += 2; break; 27 rv += 2; break;
27 case status_program_change: 28 case status_program_change:
28 case status_channel_pressure: 29 case status_channel_pressure:
29 ++rv; break; 30 ++rv; break;
30 case status_system: 31 case status_system:
31 switch(status&status_system_bits) { 32 switch(status&status_system_bits) {
32 case status_system_sysex: 33 case status_system_sysex:
33 case status_system_end_of_sysex: 34 case status_system_end_of_sysex:
34 rv += data.size()+1; break; 35 rv += data.size()+1; break;
35 case status_system_MTC_quarter_frame: 36 case status_system_MTC_quarter_frame:
36 case status_system_song_select: 37 case status_system_song_select:
37 ++rv; break; 38 ++rv; break;
38 case status_system_song_position_pointer: 39 case status_system_song_position_pointer:
39 rv += 2; break; 40 rv += 2; break;
40 case status_system_tune_request: 41 case status_system_tune_request:
41 case status_system_timing_clock: // aka status_system_midi_clock 42 case status_system_timing_clock: // aka status_system_midi_clock
42 case status_system_midi_tick: 43 case status_system_midi_tick:
43 case status_system_start: // aka status_system_midi_start 44 case status_system_start: // aka status_system_midi_start
44 case status_system_stop: // aka status_system_midi_stop 45 case status_system_stop: // aka status_system_midi_stop
45 case status_system_continue: // aka status_system_midi_continue 46 case status_system_continue: // aka status_system_midi_continue
46 case status_system_active_sense: 47 case status_system_active_sense:
47 break; /* XXX: ensure there is no data? */ 48 break; /* XXX: ensure there is no data? */
48 case status_system_meta: // also reset, but not for the purpose of midi file 49 case status_system_meta: // also reset, but not for the purpose of midi file
49 ++rv; 50 ++rv;
50 rv += calcVLsize(data.size()); 51 rv += calcVLsize(data.size());
51 rv += data.size(); 52 rv += data.size();
52 break; 53 break;
53 default: 54 default:
54 throw exception(CODEPOINT,"Internal error"); 55 throw exception(CODEPOINT,"Internal error");
55 break; 56 break;
56 } 57 }
57 break; 58 break;
58 default: 59 default:
59 throw exception(CODEPOINT,"Internal error"); 60 throw exception(CODEPOINT,"Internal error");
60 break; 61 break;
61 } 62 }
62 return rv; 63 return rv;
63 } 64 }
64 65
65 void message_t::save(int& rs,ostream& s) const { 66 void message_t::save(int& rs,ostream& s) const {
66 if(status!=rs) { 67 if(status!=rs) {
67 s.put(status); 68 s.put(status);
68 if(!s.good()) 69 if(!s.good())
69 throw exception_output_error(CODEPOINT,"Error writing midi status byte"); 70 throw exception_output_error(CODEPOINT,"Error writing midi status byte");
70 rs = status; 71 rs = status;
71 }else if((status&status_event_bits)==status_system) { 72 }else if((status&status_event_bits)==status_system) {
72 rs = -1; 73 rs = -1;
73 s.put(status); // XXX: is it really needed? 74 s.put(status); // XXX: is it really needed?
74 if(!s.good()) 75 if(!s.good())
75 throw exception_output_error(CODEPOINT,"Error writing midi system status byte"); 76 throw exception_output_error(CODEPOINT,"Error writing midi system status byte");
76 } 77 }
77 switch(status&status_event_bits) { 78 switch(status&status_event_bits) {
78 case status_note_off: 79 case status_note_off:
79 case status_note_on: 80 case status_note_on:
80 case status_polyphonic_key_pressure: // aka status_aftertouch 81 case status_polyphonic_key_pressure: // aka status_aftertouch
81 case status_control_change: 82 case status_control_change:
82 case status_pitch_wheel_change: 83 case status_pitch_wheel_change:
83 save_data(s,2); break; 84 save_data(s,2); break;
84 case status_program_change: 85 case status_program_change:
85 case status_channel_pressure: 86 case status_channel_pressure:
86 save_data(s,1); break; 87 save_data(s,1); break;
87 case status_system: 88 case status_system:
88 switch(status&status_system_bits) { 89 switch(status&status_system_bits) {
89 case status_system_sysex: 90 case status_system_sysex:
90 case status_system_end_of_sysex: 91 case status_system_end_of_sysex:
91 save_sysex(s); break; 92 save_sysex(s); break;
92 case status_system_MTC_quarter_frame: 93 case status_system_MTC_quarter_frame:
93 case status_system_song_select: 94 case status_system_song_select:
94 save_data(s,1); break; 95 save_data(s,1); break;
95 case status_system_song_position_pointer: 96 case status_system_song_position_pointer:
96 save_data(s,2); break; 97 save_data(s,2); break;
97 case status_system_tune_request: 98 case status_system_tune_request:
98 case status_system_timing_clock: // aka status_system_midi_clock 99 case status_system_timing_clock: // aka status_system_midi_clock