From 2c1be3cf846110dc72d5162ee4e233f0b8785d75 Mon Sep 17 00:00:00 2001
From: Kevin Larke <kevin@larke.org>
Date: Thu, 9 Apr 2015 13:11:26 -0700
Subject: [PATCH] Added cmDspUi2 two-dimensional drag UI control.

---
 cmMsgProtocol.h  |  1 +
 dsp/cmDspClass.h |  1 +
 dsp/cmDspUi.c    | 21 +++++++++++++++++++++
 3 files changed, 23 insertions(+)

diff --git a/cmMsgProtocol.h b/cmMsgProtocol.h
index b6b8f72..18128c4 100644
--- a/cmMsgProtocol.h
+++ b/cmMsgProtocol.h
@@ -23,6 +23,7 @@ extern "C" {
     kScoreDuiId,       // ui<--eng create a score control
     kTakeSeqBldrDuiId, // ui<--eng create a take sequence builder
     kTakeSeqRendDuiId, // ui<--eng create a take sequence renderer
+    kTwodDuiId,        // ui<--eng create a 2d control
     kNumberDuiId,      // ui<--eng create a number box
     kTextDuiId,        // ui<--eng create a text entry control
     kFnameDuiId,       // ui<--eng create a file/directory picker control
diff --git a/dsp/cmDspClass.h b/dsp/cmDspClass.h
index 820aa32..224dfb0 100644
--- a/dsp/cmDspClass.h
+++ b/dsp/cmDspClass.h
@@ -405,6 +405,7 @@ extern "C" {
   cmDspRC_t  cmDspUiScoreCreate(       cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned scFileVarId,  unsigned selVarId, unsigned smpIdxVarId, unsigned pitchVarId, unsigned velVarId, unsigned locIdxVarIdx, unsigned evtIdxVarIdx, unsigned dynLvlVarIdx, unsigned valTypeVarIdx, unsigned valueVarIdx );
   cmDspRC_t  cmDspUiTakeSeqBldrCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned fileNameVarId, unsigned ptrVarId, unsigned selVarId, unsigned refreshVarId );
   cmDspRC_t  cmDspUiTakeSeqRendCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned ptrVarId,      unsigned refreshVarId, unsigned selVarId  );
+  cmDspRC_t  cmDspUi2dCreate(          cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned xVarId,        unsigned yVarId,       unsigned radiusVarId, unsigned angleVarId);
 
   cmDspRC_t  cmDspUiNewColumn(        cmDspCtx_t* ctx, unsigned colW );
   cmDspRC_t  cmDspUiInsertHorzBorder( cmDspCtx_t* ctx );
diff --git a/dsp/cmDspUi.c b/dsp/cmDspUi.c
index 8eb388e..4297c7f 100644
--- a/dsp/cmDspUi.c
+++ b/dsp/cmDspUi.c
@@ -457,6 +457,27 @@ cmDspRC_t  cmDspUiTakeSeqRendCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigne
   return rc;
 }
 
+cmDspRC_t  cmDspUi2dCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned xVarId, unsigned yVarId, unsigned radiusVarId, unsigned angleVarId)
+{
+  cmDspRC_t    rc;
+  unsigned     arr[] = { xVarId, yVarId, radiusVarId, angleVarId  };
+  cmDspValue_t v;
+  unsigned     vn    = sizeof(arr)/sizeof(arr[0]);
+  cmDsvSetUIntMtx(&v,arr,vn,1);
+
+  // tell the UI to create a sequence render  control
+  if((rc = _cmDspUiMsg( ctx, kUiSelAsId, kTwodDuiId, 0, inst, cmInvalidId, &v )) != kOkDspRC )
+    return cmDspInstErr(ctx,inst,kUiEleCreateFailDspRC,"2-d UI element create failed.");
+
+  // Setting kUiDsvFl will cause variable values to be sent to the UI whenever they change.
+  cmDspInstVarSetFlags( ctx, inst, xVarId,      kUiDsvFl );
+  cmDspInstVarSetFlags( ctx, inst, yVarId,      kUiDsvFl );
+  cmDspInstVarSetFlags( ctx, inst, radiusVarId, kUiDsvFl );
+  cmDspInstVarSetFlags( ctx, inst, angleVarId,  kUiDsvFl );
+
+  return rc;
+}
+
 
 cmDspRC_t  cmDspUiNewColumn(    cmDspCtx_t* ctx, unsigned colW )
 {