A class that converts byte streams into MIDI messages, and stores them in a FIFO. This is useful if you wish to read MIDI messages via polling instead of interrupts. The class supports every type of MIDI message, and System Realtime messages can be interleaved with regular ones.

Committer:
Padman
Date:
Thu Aug 04 12:15:36 2016 +0000
Revision:
2:cbd43ba7f842
Parent:
0:69cbdcd5d770
Further API documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Padman 0:69cbdcd5d770 1
Padman 0:69cbdcd5d770 2 /**
Padman 0:69cbdcd5d770 3 * @file Buffer.cpp
Padman 0:69cbdcd5d770 4 * @brief Software Buffer - Templated Ring Buffer for most data types
Padman 0:69cbdcd5d770 5 * @author sam grove
Padman 0:69cbdcd5d770 6 * @version 1.0
Padman 0:69cbdcd5d770 7 * @see
Padman 0:69cbdcd5d770 8 *
Padman 0:69cbdcd5d770 9 * Copyright (c) 2013
Padman 0:69cbdcd5d770 10 *
Padman 0:69cbdcd5d770 11 * Licensed under the Apache License, Version 2.0 (the "License");
Padman 0:69cbdcd5d770 12 * you may not use this file except in compliance with the License.
Padman 0:69cbdcd5d770 13 * You may obtain a copy of the License at
Padman 0:69cbdcd5d770 14 *
Padman 0:69cbdcd5d770 15 * http://www.apache.org/licenses/LICENSE-2.0
Padman 0:69cbdcd5d770 16 *
Padman 0:69cbdcd5d770 17 * Unless required by applicable law or agreed to in writing, software
Padman 0:69cbdcd5d770 18 * distributed under the License is distributed on an "AS IS" BASIS,
Padman 0:69cbdcd5d770 19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Padman 0:69cbdcd5d770 20 * See the License for the specific language governing permissions and
Padman 0:69cbdcd5d770 21 * limitations under the License.
Padman 0:69cbdcd5d770 22 */
Padman 0:69cbdcd5d770 23
Padman 0:69cbdcd5d770 24 #include "MyBuffer.h"
Padman 0:69cbdcd5d770 25
Padman 0:69cbdcd5d770 26 template <class T>
Padman 0:69cbdcd5d770 27 MyBuffer<T>::MyBuffer(uint32_t size)
Padman 0:69cbdcd5d770 28 {
Padman 0:69cbdcd5d770 29 _buf = new T [size];
Padman 0:69cbdcd5d770 30 _size = size;
Padman 0:69cbdcd5d770 31 clear();
Padman 0:69cbdcd5d770 32
Padman 0:69cbdcd5d770 33 return;
Padman 0:69cbdcd5d770 34 }
Padman 0:69cbdcd5d770 35
Padman 0:69cbdcd5d770 36 template <class T>
Padman 0:69cbdcd5d770 37 MyBuffer<T>::~MyBuffer()
Padman 0:69cbdcd5d770 38 {
Padman 0:69cbdcd5d770 39 delete [] _buf;
Padman 0:69cbdcd5d770 40
Padman 0:69cbdcd5d770 41 return;
Padman 0:69cbdcd5d770 42 }
Padman 0:69cbdcd5d770 43
Padman 0:69cbdcd5d770 44 template <class T>
Padman 0:69cbdcd5d770 45 uint32_t MyBuffer<T>::getSize()
Padman 0:69cbdcd5d770 46 {
Padman 0:69cbdcd5d770 47 return this->_size;
Padman 0:69cbdcd5d770 48 }
Padman 0:69cbdcd5d770 49
Padman 0:69cbdcd5d770 50 template <class T>
Padman 0:69cbdcd5d770 51 void MyBuffer<T>::clear(void)
Padman 0:69cbdcd5d770 52 {
Padman 0:69cbdcd5d770 53 _wloc = 0;
Padman 0:69cbdcd5d770 54 _rloc = 0;
Padman 0:69cbdcd5d770 55 memset(_buf, 0, _size);
Padman 0:69cbdcd5d770 56
Padman 0:69cbdcd5d770 57 return;
Padman 0:69cbdcd5d770 58 }
Padman 0:69cbdcd5d770 59
Padman 0:69cbdcd5d770 60 template <class T>
Padman 0:69cbdcd5d770 61 uint32_t MyBuffer<T>::peek(char c)
Padman 0:69cbdcd5d770 62 {
Padman 0:69cbdcd5d770 63 return 1;
Padman 0:69cbdcd5d770 64 }
Padman 0:69cbdcd5d770 65
Padman 0:69cbdcd5d770 66 // make the linker aware of some possible types
Padman 0:69cbdcd5d770 67 template class MyBuffer<uint8_t>;
Padman 0:69cbdcd5d770 68 template class MyBuffer<int8_t>;
Padman 0:69cbdcd5d770 69 template class MyBuffer<uint16_t>;
Padman 0:69cbdcd5d770 70 template class MyBuffer<int16_t>;
Padman 0:69cbdcd5d770 71 template class MyBuffer<uint32_t>;
Padman 0:69cbdcd5d770 72 template class MyBuffer<int32_t>;
Padman 0:69cbdcd5d770 73 template class MyBuffer<uint64_t>;
Padman 0:69cbdcd5d770 74 template class MyBuffer<int64_t>;
Padman 0:69cbdcd5d770 75 template class MyBuffer<char>;
Padman 0:69cbdcd5d770 76 template class MyBuffer<wchar_t>;