root/trunk/libjdkmidi/trunk/include/jdkmidi/sysex.h

Revision 552, 3.4 kB (checked in by jeffk@…, 8 months ago)

formatting fixed

Line 
1/*
2 *  libjdkmidi-2004 C++ Class Library for MIDI
3 *
4 *  Copyright (C) 2004  J.D. Koftinoff Software, Ltd.
5 *  www.jdkoftinoff.com
6 *  jeffk@jdkoftinoff.com
7 *
8 *  *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 ***
9 *
10 *  This program is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License as published by
12 *  the Free Software Foundation; either version 2 of the License, or
13 *  (at your option) any later version.
14 *
15 *  This program is distributed in the hope that it will be useful,
16 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 *  GNU General Public License for more details.
19 *
20 *  You should have received a copy of the GNU General Public License
21 *  along with this program; if not, write to the Free Software
22 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23*/
24/*
25** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd.
26**
27** All rights reserved.
28**
29** No one may duplicate this source code in any form for any reason
30** without the written permission given by J.D. Koftinoff Software, Ltd.
31**
32*/
33
34#ifndef JDKMIDI_SYSEX_H
35#define JDKMIDI_SYSEX_H
36
37#include "jdkmidi/midi.h"
38
39namespace jdkmidi
40{
41
42  class  MIDISystemExclusive
43  {
44    public:
45      MIDISystemExclusive ( int size=384 );
46     
47      MIDISystemExclusive ( const MIDISystemExclusive &e );
48     
49     
50      MIDISystemExclusive (
51        unsigned char *buf_,
52        int max_len_,
53        int cur_len_,
54        bool deletable_
55      )
56      {
57        buf=buf_;
58        max_len=max_len_;
59        cur_len=cur_len_;
60        chk_sum=0;
61        deletable=deletable_;
62      }
63     
64      virtual ~MIDISystemExclusive();
65     
66      void Clear()
67      {
68        cur_len=0;
69        chk_sum=0;
70      }
71      void ClearChecksum()
72      {
73        chk_sum=0;
74      }
75     
76      void PutSysByte ( unsigned char b ) // does not add to chksum
77      {
78        if ( cur_len<max_len )
79          buf[cur_len++]=b;
80      }
81     
82      void PutByte ( unsigned char b )
83      {
84        PutSysByte ( b );
85        chk_sum+=b;
86      }
87     
88      void PutEXC()
89      {
90        PutSysByte ( SYSEX_START );
91      }
92      void PutEOX()
93      {
94        PutSysByte ( SYSEX_END );
95      }
96     
97      // low nibble first
98      void PutNibblizedByte ( unsigned char b )
99      {
100        PutByte ( ( unsigned char ) ( b&0xf ) );
101        PutByte ( ( unsigned char ) ( b>>4 ) );
102      }
103     
104      // high nibble first
105      void PutNibblizedByte2 ( unsigned char b )
106      {
107        PutByte ( ( unsigned char ) ( b>>4 ) );
108        PutByte ( ( unsigned char ) ( b&0xf ) );
109      }
110     
111      void PutChecksum()
112      {
113        PutByte ( ( unsigned char ) ( chk_sum&0x7f ) );
114      }
115     
116      unsigned char GetChecksum() const
117      {
118        return ( unsigned char ) ( chk_sum&0x7f );
119      }
120     
121      int  GetLength() const
122      {
123        return cur_len;
124      }
125     
126      unsigned char GetData ( int i ) const
127      {
128        return buf[i];
129      }
130     
131      bool IsFull() const
132      {
133        return cur_len>=max_len;
134      }
135     
136      unsigned char *GetBuf()
137      {
138        return buf;
139      }
140     
141      const unsigned char *GetBuf() const
142      {
143        return buf;
144      }
145     
146    private:
147   
148      unsigned char *buf;
149      int max_len;
150      int cur_len;
151      unsigned char  chk_sum;
152      bool deletable;
153  };
154}
155
156#endif
157
Note: See TracBrowser for help on using the browser.