From c94556d4a1c3c16d8fc6e9ba4a59944ecb7bd442 Mon Sep 17 00:00:00 2001 From: kevin Date: Fri, 11 Nov 2022 13:13:35 -0500 Subject: [PATCH] cwCmInterface,cwScoreFollower : Initial commit. Not yet included in build. --- Makefile.am | 7 ++- cwCmInterface.cpp | 110 +++++++++++++++++++++++++++++++++++++ cwCmInterface.h | 19 +++++++ cwScoreFollower.cpp | 130 ++++++++++++++++++++++++++++++++++++++++++++ cwScoreFollower.h | 21 +++++++ 5 files changed, 285 insertions(+), 2 deletions(-) create mode 100644 cwCmInterface.cpp create mode 100644 cwCmInterface.h create mode 100644 cwScoreFollower.cpp create mode 100644 cwScoreFollower.h diff --git a/Makefile.am b/Makefile.am index f801fad..169b209 100644 --- a/Makefile.am +++ b/Makefile.am @@ -64,8 +64,11 @@ libcwSRC += src/libcw/cwIo.cpp src/libcw/cwIoTest.cpp src/libcw/cwIoMinTest.cp libcwHDR += src/libcw/cwIoMidiRecordPlay.h src/libcw/cwIoAudioRecordPlay.h src/libcw/cwIoAudioMidiApp.h src/libcw/cwIoFlow.h libcwSRC += src/libcw/cwIoMidiRecordPlay.cpp src/libcw/cwIoAudioRecordPlay.cpp src/libcw/cwIoAudioMidiApp.cpp src/libcw/cwIoFlow.cpp -libcwHDR += src/libcw/cwIoPresetSelApp.h src/libcw/cwPianoScore.h src/libcw/cwPresetSel.h -libcwSRC += src/libcw/cwIoPresetSelApp.cpp src/libcw/cwPianoScore.cpp src/libcw/cwPresetSel.cpp +libcwHDR += src/libcw/cwIoPresetSelApp.h src/libcw/cwPianoScore.h src/libcw/cwPresetSel.h +libcwSRC += src/libcw/cwIoPresetSelApp.cpp src/libcw/cwPianoScore.cpp src/libcw/cwPresetSel.cpp + +# libcwHDR += src/libcw/cwCmInterface.h src/libcw/cwScoreFollower.h +# libcwSRC += src/libcw/cwCmInterface.cpp src/libcw/cwScoreFollower.cpp endif diff --git a/cwCmInterface.cpp b/cwCmInterface.cpp new file mode 100644 index 0000000..9830499 --- /dev/null +++ b/cwCmInterface.cpp @@ -0,0 +1,110 @@ +#include "cwCommon.h" +#include "cwLog.h" +#include "cwCommonImpl.h" +#include "cwMem.h" +#include "cwCmInterface.h" + +#include "cmGlobal.h" +#include "cmFloatTypes.h" +#include "cmRpt.h" +#include "cmErr.h" +#include "cmCtx.h" +#include "cmMem.h" +#include "cmMallocDebug.h" +#include "cmLinkedHeap.h" +#include "cmTime.h" +#include "cmMidi.h" +#include "cmSymTbl.h" +#include "cmScore.h" +#include "cmText.h" +#include "cmFileSys.h" + +extern "C" { + void _cm_print_info( void* arg, const char* text ) + { + cwLogInfo(text); + } + + void _cm_print_error( void* arg, const char* text ) + { + cwLogError(cw::kOpFailRC,text); + } +} + +namespace cw +{ + namespace cm + { + typedef struct cm_str + { + ::cmCtx_t ctx; + } cm_t; + + cm_t* _handleToPtr( handle_t h ) + { return handleToPtr(h); } + + rc_t _destroy( cm_t* p ) + { + if( p != nullptr ) + { + cmTsFinalize(); + cmFsFinalize(); + cmMdReport( kIgnoreNormalMmFl ); + cmMdFinalize(); + + mem::release(p); + } + return kOkRC; + } + } +} + +cw::rc_t cw::cm::create( handle_t& hRef ) +{ + rc_t rc = kOkRC; + cm_t* p = nullptr; + bool memDebugFl = 0; //cmDEBUG_FL; + unsigned memGuardByteCnt = memDebugFl ? 8 : 0; + unsigned memAlignByteCnt = 16; + unsigned memFlags = memDebugFl ? kTrackMmFl | kDeferFreeMmFl | kFillUninitMmFl : 0; + const cmChar_t* appTitle = "cwtest"; + + if((rc = destroy(hRef)) != kOkRC ) + return rc; + + p = mem::allocZ(); + + cmCtxSetup(&p->ctx,appTitle,_cm_print_info,_cm_print_error,NULL,memGuardByteCnt,memAlignByteCnt,memFlags); + + cmMdInitialize( memGuardByteCnt, memAlignByteCnt, memFlags, &p->ctx.rpt ); + + cmFsInitialize( &p->ctx, appTitle); + + cmTsInitialize( &p->ctx ); + + return rc; +} + +cw::rc_t cw::cm::destroy( handle_t& hRef ) +{ + rc_t rc = kOkRC; + cm_t* p = nullptr; + if( !hRef.isValid() ) + return rc; + + p = _handleToPtr(hRef); + + if((rc = _destroy(p)) != kOkRC ) + return rc; + + hRef.clear(); + return rc; + +} + +::cmCtx_t* cw::cm::context( handle_t h ) +{ + cm_t* p = _handleToPtr(h); + return &p->ctx; +} + diff --git a/cwCmInterface.h b/cwCmInterface.h new file mode 100644 index 0000000..557eac5 --- /dev/null +++ b/cwCmInterface.h @@ -0,0 +1,19 @@ +#ifndef cwCmInterface_h +#define cwCmInterface_h + +namespace cw +{ + namespace cm { + + extern "C" { struct cmCtx_str; } + + typedef handle< struct cm_str > handle_t; + + rc_t create( handle_t& hRef ); + rc_t destroy( handle_t& hRef ); + ::cmCtx_t* context( handle_t h ); + } +} + + +#endif diff --git a/cwScoreFollower.cpp b/cwScoreFollower.cpp new file mode 100644 index 0000000..92e4caa --- /dev/null +++ b/cwScoreFollower.cpp @@ -0,0 +1,130 @@ +#include "cwCommon.h" +#include "cwLog.h" +#include "cwCommonImpl.h" +#include "cwMem.h" +#include "cwText.h" +#include "cwObject.h" +#include "cwMidi.h" +#include "cwScoreFollower.h" + +#include "cmGlobal.h" +#include "cmFloatTypes.h" +#include "cmRpt.h" +#include "cmErr.h" +#include "cmCtx.h" +#include "cmTime.h" +#include "cmMidi.h" +#include "cmSymTbl.h" +#include "cmScore.h" + +namespace cw +{ + namespace score_follower + { + + typedef struct score_follower_str + { + unsigned search_area_locN; + unsigned key_wnd_locN; + char* score_csv_fname; + + + } score_follower_t; + + score_follower_t* _handleToPtr( handle_t h ) + { return handleToPtr(h); } + + + rc_t _parse_cfg( score_follower_t* p, const object_t* cfg ) + { + rc_t rc = kOkRC; + + const char* score_csv_fname; + + if((rc = cfg->getv("score_csv_fname", score_csv_fname, + "search_area_locN", p->search_area_locN, + "key_wnd_locN", p->key_wnd_locN )) != kOkRC ) + { + rc = cwLogError(kInvalidArgRC, "Score follower argument parsing failed."); + goto errLabel; + } + + if((app->score_csv_fname = filesys::expandPath( score_csv_fname )) == nullptr ) + { + rc = cwLogError(kOpFailRC,"Score follower score file expansion failed."); + goto errLabel; + } + + errLabel: + return rc; + } + + rc_t _destroy( score_follower_t* p) + { + mem::release(p->score_csv_fname); + mem::release(p); + return kOkRC; + } + } +} + +cw::rc_t cw::score_follower::create( handle_t& hRef, const object_t* cfg, double srate ) +{ + rc_t rc = kOkRC; + score_follower_t* p = nullptr; + + if((rc = destroy(hRef)) != kOkRC ) + return rc; + + p = mem::allocZ(); + + if((rc = _parse_cfg(p,cfg)) != kOkRC ) + goto errLabel; + + cmScRC_t cmScoreInitialize( cmCtx_t* ctx, cmScH_t* hp, const cmChar_t* fn, double srate, const unsigned* dynRefArray, unsigned dynRefCnt, cmScCb_t cbFunc, void* cbArg, cmSymTblH_t stH ); + + //cmRC_t cmScMatcherInit( cmScMatcher* p, double srate, cmScH_t scH, unsigned scWndN, unsigned midiWndN, cmScMatcherCb_t cbFunc, void* cbArg ); + + + + hRef.set(p); + + errLabel: + if( rc != kOkRC ) + { + _destroy(p); + cwLogError(rc,"Score follower create failed."); + } + + return rc; +} + +cw::rc_t cw::score_follower::destroy( handle_t& hRef ) +{ + rc_t rc = kOkRC; + score_follower_t* p = nullptr; + + if( !hRef.isValid() ) + return rc; + + p = _handleToPtr(hRef); + + if((rc = _destroy(p)) != kOkRC ) + return rc; + + hRef.clear(); + return rc; +} + +cw::rc_t cw::score_follower::reset( handle_t h, unsigned loc ) +{ + rc_t rc = kOkRC; + return rc; +} + +cw::rc_t cw::score_follower::exec( handle_t h, unsigned smpIdx, unsigned muid, unsigned status, uint8_t d0, uint8_t d1, unsigned* scLocIdxPtr ) +{ + rc_t rc = kOkRC; + return rc; + +} diff --git a/cwScoreFollower.h b/cwScoreFollower.h new file mode 100644 index 0000000..a32d635 --- /dev/null +++ b/cwScoreFollower.h @@ -0,0 +1,21 @@ +#ifndef cwScoreFollower_h +#define cwScoreFollower_h + +namespace cw +{ + namespace score_follower + { + typedef handle< struct score_follower_str > handle_t; + + rc_t create( handle_t& hRef, const object_t* cfg, double srate ); + + rc_t destroy( handle_t& hRef ); + + rc_t reset( handle_t h, unsigned loc ); + + rc_t exec( handle_t h, unsigned smpIdx, unsigned muid, unsigned status, uint8_t d0, uint8_t d1, unsigned* scLocIdxPtr ); + } +} + + +#endif