From e3ff4828b0021978e30e55ca05caf9312ab4beba Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 21 Feb 2024 07:49:28 -0500 Subject: [PATCH] cwMidiDevice,cwMidiFileDev : Added midi::file_dev.msg_count() and midi::device.loadMsgPacket(). --- cwMidiDevice.cpp | 35 ++++++++++++++++++++++++++++++++++- cwMidiDevice.h | 2 ++ cwMidiFileDev.cpp | 13 +++++++++++++ cwMidiFileDev.h | 2 ++ 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/cwMidiDevice.cpp b/cwMidiDevice.cpp index 7e364cc..3abdc49 100644 --- a/cwMidiDevice.cpp +++ b/cwMidiDevice.cpp @@ -511,13 +511,46 @@ cw::rc_t cw::midi::device::openMidiFile( handle_t h, unsigned devIdx, unsigned p errLabel: return rc; +} +cw::rc_t cw::midi::device::loadMsgPacket( handle_t h, const packet_t& pkt ) +{ + rc_t rc = kOkRC; + device_t* p = _handleToPtr(h); + + if( _devIdxToFileDevIdx(p,pkt.devIdx) == kInvalidIdx ) + { + cwLogError(kInvalidArgRC,"The device index %i does not identify a valid file device.",pkt.devIdx); + goto errLabel; + } + + if((rc = load_messages( p->fileDevH, pkt.portIdx, pkt.msgArray, pkt.msgCnt)) != kOkRC ) + goto errLabel; + +errLabel: + return rc; +} + +unsigned cw::midi::device::msgCount( handle_t h, unsigned devIdx, unsigned portIdx ) +{ + device_t* p = _handleToPtr(h); + + if(_devIdxToFileDevIdx(p,devIdx) == kInvalidIdx ) + { + cwLogError(kInvalidArgRC,"The device index %i does not identify a valid file device.",devIdx); + goto errLabel; + } + + return msg_count( p->fileDevH, portIdx); + +errLabel: + return 0; } cw::rc_t cw::midi::device::seekToMsg( handle_t h, unsigned devIdx, unsigned portIdx, unsigned msgIdx ) { rc_t rc = kOkRC; - device_t* p = _handleToPtr(h); + device_t* p = _handleToPtr(h); if(_devIdxToFileDevIdx(p,devIdx) == kInvalidIdx ) { diff --git a/cwMidiDevice.h b/cwMidiDevice.h index 4fa87f8..7461356 100644 --- a/cwMidiDevice.h +++ b/cwMidiDevice.h @@ -52,6 +52,8 @@ namespace cw rc_t sendData( handle_t h, unsigned devIdx, unsigned portIdx, const uint8_t* dataPtr, unsigned byteCnt ); rc_t openMidiFile( handle_t h, unsigned devIdx, unsigned portIdx, const char* fname ); + rc_t loadMsgPacket(handle_t h, const packet_t& pkt ); // Note: Set devIdx/portIdx via pkt.devIdx/pkt.portIdx + unsigned msgCount( handle_t h, unsigned devIdx, unsigned portIdx ); rc_t seekToMsg( handle_t h, unsigned devIdx, unsigned portIdx, unsigned msgIdx ); rc_t setEndMsg( handle_t h, unsigned devIdx, unsigned portidx, unsigned msgIdx ); diff --git a/cwMidiFileDev.cpp b/cwMidiFileDev.cpp index 9e448af..44947cb 100644 --- a/cwMidiFileDev.cpp +++ b/cwMidiFileDev.cpp @@ -716,6 +716,19 @@ errLabel: return rc; } +unsigned cw::midi::device::file_dev::msg_count( handle_t h, unsigned file_idx ) +{ + file_dev_t* p = _handleToPtr(h); + rc_t rc; + + if((rc = _validate_file_existence(p,file_idx)) != kOkRC ) + goto errLabel; + + return p->msgN; + +errLabel: + return 0; +} cw::rc_t cw::midi::device::file_dev::seek_to_msg_index( handle_t h, unsigned file_idx, unsigned msg_idx ) { diff --git a/cwMidiFileDev.h b/cwMidiFileDev.h index 9973a06..08e6e13 100644 --- a/cwMidiFileDev.h +++ b/cwMidiFileDev.h @@ -66,6 +66,8 @@ namespace cw } exec_result_t; + unsigned msg_count( handle_t h, unsigned file_idx ); + // Set the next msg to be returned. rc_t seek_to_msg_index( handle_t h, unsigned file_idx, unsigned msg_idx ); rc_t set_end_msg_index( handle_t h, unsigned file_idx, unsigned msg_idx );