|
@@ -40,6 +40,7 @@
|
40
|
40
|
#include "cmMidi.h"
|
41
|
41
|
#include "cmProc2.h"
|
42
|
42
|
#include "cmVectOpsTemplateMain.h"
|
|
43
|
+#include "cmMidiPort.h"
|
43
|
44
|
|
44
|
45
|
/*
|
45
|
46
|
About variables:
|
|
@@ -982,6 +983,239 @@ struct cmDspClass_str* cmSigGenClassCons( cmDspCtx_t* ctx )
|
982
|
983
|
//==========================================================================================================================================
|
983
|
984
|
enum
|
984
|
985
|
{
|
|
986
|
+ kDeviceMiId,
|
|
987
|
+ kPortMiId,
|
|
988
|
+ kSmpIdxMiId,
|
|
989
|
+ kStatusMiId,
|
|
990
|
+ kD0MiId,
|
|
991
|
+ kD1MiId
|
|
992
|
+};
|
|
993
|
+
|
|
994
|
+
|
|
995
|
+cmDspClass_t _cmMidiInDC;
|
|
996
|
+
|
|
997
|
+typedef struct
|
|
998
|
+{
|
|
999
|
+ cmDspInst_t inst;
|
|
1000
|
+ unsigned midiSymId;
|
|
1001
|
+ unsigned prevSmpIdx;
|
|
1002
|
+} cmDspMidiIn_t;
|
|
1003
|
+
|
|
1004
|
+cmDspInst_t* _cmDspMidiInAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
|
|
1005
|
+{
|
|
1006
|
+ cmDspVarArg_t args[] =
|
|
1007
|
+ {
|
|
1008
|
+ { "device", kDeviceMiId, 0, 0, kOutDsvFl | kUIntDsvFl, "MIDI device" },
|
|
1009
|
+ { "port", kPortMiId, 0, 0, kOutDsvFl | kUIntDsvFl, "MIDI device port"},
|
|
1010
|
+ { "smpidx", kSmpIdxMiId, 0, 0, kOutDsvFl | kUIntDsvFl, "Message time tag as sample index."},
|
|
1011
|
+ { "status", kStatusMiId, 0, 0, kOutDsvFl | kUIntDsvFl, "MIDI status" },
|
|
1012
|
+ { "d0", kD0MiId, 0, 0, kOutDsvFl | kUIntDsvFl, "MIDI channel message d0" },
|
|
1013
|
+ { "d1", kD1MiId, 0, 0, kOutDsvFl | kUIntDsvFl, "MIDI channel message d1" },
|
|
1014
|
+ { NULL, 0, 0, 0, 0 }
|
|
1015
|
+ };
|
|
1016
|
+
|
|
1017
|
+ cmDspMidiIn_t* p = cmDspInstAlloc(cmDspMidiIn_t,ctx,classPtr,args,instSymId,id,storeSymId,va_cnt,vl);
|
|
1018
|
+
|
|
1019
|
+ p->midiSymId = cmDspSysAssignInstAttrSymbolStr( ctx->dspH, &p->inst, "_midi" );
|
|
1020
|
+
|
|
1021
|
+ return &p->inst;
|
|
1022
|
+}
|
|
1023
|
+
|
|
1024
|
+cmDspRC_t _cmDspMidiInReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
1025
|
+{
|
|
1026
|
+ cmDspRC_t rc = kOkDspRC;
|
|
1027
|
+ cmDspMidiIn_t* p = (cmDspMidiIn_t*)inst;
|
|
1028
|
+ cmDspApplyAllDefaults(ctx,inst);
|
|
1029
|
+ p->prevSmpIdx = 0;
|
|
1030
|
+ return rc;
|
|
1031
|
+}
|
|
1032
|
+
|
|
1033
|
+cmDspRC_t _cmDspMidiInRecvFunc( cmDspCtx_t* ctx, struct cmDspInst_str* inst, unsigned attrSymId, const cmDspValue_t* value )
|
|
1034
|
+{
|
|
1035
|
+ cmDspMidiIn_t* p = (cmDspMidiIn_t*)inst;
|
|
1036
|
+
|
|
1037
|
+ if( attrSymId == p->midiSymId )
|
|
1038
|
+ {
|
|
1039
|
+ cmMidiPacket_t* pkt = (cmMidiPacket_t*)(value->u.m.u.vp);
|
|
1040
|
+ unsigned i;
|
|
1041
|
+
|
|
1042
|
+ cmDspSetUInt(ctx, inst, kDeviceMiId, pkt->devIdx);
|
|
1043
|
+ cmDspSetUInt(ctx, inst, kPortMiId, pkt->portIdx);
|
|
1044
|
+
|
|
1045
|
+ for(i=0; i<pkt->msgCnt; ++i)
|
|
1046
|
+ {
|
|
1047
|
+ cmMidiMsg* m = pkt->msgArray + i;
|
|
1048
|
+ unsigned deltaSmpCnt = floor((m->deltaUs * cmDspSampleRate(ctx)) / 1000000.0);
|
|
1049
|
+
|
|
1050
|
+ if( p->prevSmpIdx == 0 )
|
|
1051
|
+ p->prevSmpIdx = ctx->cycleCnt * cmDspSamplesPerCycle(ctx);
|
|
1052
|
+ else
|
|
1053
|
+ p->prevSmpIdx += deltaSmpCnt;
|
|
1054
|
+
|
|
1055
|
+ cmDspSetUInt(ctx, inst, kSmpIdxMiId, p->prevSmpIdx );
|
|
1056
|
+ cmDspSetUInt(ctx, inst, kD1MiId, m->d1 );
|
|
1057
|
+ cmDspSetUInt(ctx, inst, kD0MiId, m->d0 );
|
|
1058
|
+ cmDspSetUInt(ctx, inst, kStatusMiId, m->status );
|
|
1059
|
+ }
|
|
1060
|
+ }
|
|
1061
|
+
|
|
1062
|
+ return kOkDspRC;
|
|
1063
|
+}
|
|
1064
|
+
|
|
1065
|
+struct cmDspClass_str* cmMidiInClassCons( cmDspCtx_t* ctx )
|
|
1066
|
+{
|
|
1067
|
+ cmDspClassSetup(&_cmMidiInDC,ctx,"MidiIn",
|
|
1068
|
+ NULL,
|
|
1069
|
+ _cmDspMidiInAlloc,
|
|
1070
|
+ NULL,
|
|
1071
|
+ _cmDspMidiInReset,
|
|
1072
|
+ NULL,
|
|
1073
|
+ NULL,
|
|
1074
|
+ NULL,
|
|
1075
|
+ _cmDspMidiInRecvFunc,
|
|
1076
|
+ "Midi input port");
|
|
1077
|
+
|
|
1078
|
+ return &_cmMidiInDC;
|
|
1079
|
+}
|
|
1080
|
+
|
|
1081
|
+//==========================================================================================================================================
|
|
1082
|
+enum
|
|
1083
|
+{
|
|
1084
|
+ kDeviceMoId,
|
|
1085
|
+ kPortMoId,
|
|
1086
|
+ kStatusMoId,
|
|
1087
|
+ kD0MoId,
|
|
1088
|
+ kD1MoId
|
|
1089
|
+};
|
|
1090
|
+
|
|
1091
|
+cmDspClass_t _cmMidiOutDC;
|
|
1092
|
+
|
|
1093
|
+typedef struct
|
|
1094
|
+{
|
|
1095
|
+ cmDspInst_t inst;
|
|
1096
|
+ unsigned devIdx;
|
|
1097
|
+ unsigned portIdx;
|
|
1098
|
+} cmDspMidiOut_t;
|
|
1099
|
+
|
|
1100
|
+cmDspRC_t _cmDspMidiOutSetDevice( cmDspCtx_t* ctx, cmDspMidiOut_t* p, const cmChar_t* deviceStr )
|
|
1101
|
+{
|
|
1102
|
+ cmDspRC_t rc = kOkDspRC;
|
|
1103
|
+
|
|
1104
|
+ if( deviceStr != NULL )
|
|
1105
|
+ if((p->devIdx = cmMpDeviceNameToIndex(deviceStr)) == cmInvalidIdx )
|
|
1106
|
+ rc = cmDspInstErr(ctx,&p->inst,kInvalidArgDspRC,"The MIDI device '%s' could not be found.",cmStringNullGuard(deviceStr));
|
|
1107
|
+
|
|
1108
|
+ return rc;
|
|
1109
|
+}
|
|
1110
|
+
|
|
1111
|
+cmDspRC_t _cmDspMidiOutSetPort( cmDspCtx_t* ctx, cmDspMidiOut_t* p, const cmChar_t* portStr )
|
|
1112
|
+{
|
|
1113
|
+ cmDspRC_t rc = kOkDspRC;
|
|
1114
|
+
|
|
1115
|
+ if( portStr == NULL )
|
|
1116
|
+ return rc;
|
|
1117
|
+
|
|
1118
|
+ if( p->devIdx == cmInvalidIdx )
|
|
1119
|
+ rc = cmDspInstErr(ctx,&p->inst,kInvalidArgDspRC,"The MIDI port cannot be set until the MIDI device is set.");
|
|
1120
|
+ else
|
|
1121
|
+ {
|
|
1122
|
+ if((p->portIdx = cmMpDevicePortNameToIndex(p->devIdx,kOutMpFl,portStr)) == cmInvalidIdx )
|
|
1123
|
+ rc = cmDspInstErr(ctx,&p->inst,kInvalidArgDspRC,"The MIDI port '%s' could not be found on device '%s'.",cmStringNullGuard(portStr),cmStringNullGuard(cmMpDeviceName(p->devIdx)));
|
|
1124
|
+ }
|
|
1125
|
+
|
|
1126
|
+ return rc;
|
|
1127
|
+}
|
|
1128
|
+
|
|
1129
|
+cmDspInst_t* _cmDspMidiOutAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
|
|
1130
|
+{
|
|
1131
|
+ cmDspVarArg_t args[] =
|
|
1132
|
+ {
|
|
1133
|
+ { "device", kDeviceMoId, 0, 0, kInDsvFl | kStrzDsvFl | kReqArgDsvFl, "MIDI device name"},
|
|
1134
|
+ { "port", kPortMoId, 0, 0, kInDsvFl | kStrzDsvFl | kReqArgDsvFl, "MIDI port name"},
|
|
1135
|
+ { "status", kStatusMoId, 0, 0, kInDsvFl | kUIntDsvFl, "MIDI status" },
|
|
1136
|
+ { "d0", kD0MoId, 0, 0, kInDsvFl | kUIntDsvFl, "MIDI channel message d0" },
|
|
1137
|
+ { "d1", kD1MoId, 0, 0, kInDsvFl | kUIntDsvFl, "MIDI channel message d1" },
|
|
1138
|
+ { NULL, 0, 0, 0, 0 }
|
|
1139
|
+ };
|
|
1140
|
+
|
|
1141
|
+ cmDspMidiOut_t* p = cmDspInstAlloc(cmDspMidiOut_t,ctx,classPtr,args,instSymId,id,storeSymId,va_cnt,vl);
|
|
1142
|
+
|
|
1143
|
+ p->devIdx = cmInvalidIdx;
|
|
1144
|
+ p->portIdx = cmInvalidIdx;
|
|
1145
|
+
|
|
1146
|
+ cmDspSetDefaultUInt(ctx,&p->inst, kStatusMoId, 0, 0 );
|
|
1147
|
+ cmDspSetDefaultUInt(ctx,&p->inst, kD0MoId, 0, 0 );
|
|
1148
|
+ cmDspSetDefaultUInt(ctx,&p->inst, kD1MoId, 0, 0 );
|
|
1149
|
+
|
|
1150
|
+ return &p->inst;
|
|
1151
|
+}
|
|
1152
|
+
|
|
1153
|
+cmDspRC_t _cmDspMidiOutReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
1154
|
+{
|
|
1155
|
+ cmDspRC_t rc = kOkDspRC;
|
|
1156
|
+ cmDspMidiOut_t* p = (cmDspMidiOut_t*)inst;
|
|
1157
|
+
|
|
1158
|
+ cmDspApplyAllDefaults(ctx,inst);
|
|
1159
|
+
|
|
1160
|
+ _cmDspMidiOutSetDevice(ctx,p,cmDspStrcz(inst,kDeviceMoId));
|
|
1161
|
+ _cmDspMidiOutSetPort( ctx,p,cmDspStrcz(inst,kPortMoId));
|
|
1162
|
+
|
|
1163
|
+ return rc;
|
|
1164
|
+}
|
|
1165
|
+
|
|
1166
|
+cmDspRC_t _cmDspMidiOutRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
|
1167
|
+{
|
|
1168
|
+ cmDspMidiOut_t* p = (cmDspMidiOut_t*)inst;
|
|
1169
|
+
|
|
1170
|
+ switch( evt->dstVarId )
|
|
1171
|
+ {
|
|
1172
|
+ case kDeviceMoId:
|
|
1173
|
+ _cmDspMidiOutSetDevice(ctx, p, cmDsvStrcz(evt->valuePtr) );
|
|
1174
|
+ break;
|
|
1175
|
+
|
|
1176
|
+ case kPortMoId:
|
|
1177
|
+ _cmDspMidiOutSetPort(ctx, p, cmDsvStrcz(evt->valuePtr) );
|
|
1178
|
+ break;
|
|
1179
|
+
|
|
1180
|
+ case kStatusMoId:
|
|
1181
|
+ if( p->devIdx != cmInvalidIdx && p->portIdx != cmInvalidIdx )
|
|
1182
|
+ {
|
|
1183
|
+ unsigned status = cmDsvGetUInt(evt->valuePtr);
|
|
1184
|
+ unsigned d0 = cmDspUInt(inst,kD0MoId);
|
|
1185
|
+ unsigned d1 = cmDspUInt(inst,kD1MoId);
|
|
1186
|
+ if( cmMpDeviceSend( p->devIdx, p->portIdx, status, d0, d1 ) != kOkMpRC )
|
|
1187
|
+ cmDspInstErr(ctx,inst,kInvalidArgDspRC,"MIDI send failed.");
|
|
1188
|
+ }
|
|
1189
|
+ break;
|
|
1190
|
+
|
|
1191
|
+ default:
|
|
1192
|
+ cmDspSetEvent(ctx,inst,evt);
|
|
1193
|
+ break;
|
|
1194
|
+ }
|
|
1195
|
+
|
|
1196
|
+
|
|
1197
|
+ return kOkDspRC;
|
|
1198
|
+}
|
|
1199
|
+
|
|
1200
|
+struct cmDspClass_str* cmMidiOutClassCons( cmDspCtx_t* ctx )
|
|
1201
|
+{
|
|
1202
|
+ cmDspClassSetup(&_cmMidiOutDC,ctx,"MidiOut",
|
|
1203
|
+ NULL,
|
|
1204
|
+ _cmDspMidiOutAlloc,
|
|
1205
|
+ NULL,
|
|
1206
|
+ _cmDspMidiOutReset,
|
|
1207
|
+ NULL,
|
|
1208
|
+ _cmDspMidiOutRecv,
|
|
1209
|
+ NULL,
|
|
1210
|
+ NULL,
|
|
1211
|
+ "Midi input port");
|
|
1212
|
+
|
|
1213
|
+ return &_cmMidiOutDC;
|
|
1214
|
+}
|
|
1215
|
+
|
|
1216
|
+//==========================================================================================================================================
|
|
1217
|
+enum
|
|
1218
|
+{
|
985
|
1219
|
kChAiId,
|
986
|
1220
|
kGainAiId,
|
987
|
1221
|
kOutAiId
|
|
@@ -2980,7 +3214,7 @@ cmDspRC_t _cmDspWaveTableReadAudioFile( cmDspCtx_t* ctx, cmDspWaveTable_t* p, un
|
2980
|
3214
|
|
2981
|
3215
|
cmDspRC_t _cmDspWaveTableInitAudioFile( cmDspCtx_t* ctx, cmDspWaveTable_t* p )
|
2982
|
3216
|
{
|
2983
|
|
- cmDspRC_t rc;
|
|
3217
|
+ cmDspRC_t rc = kOkDspRC;
|
2984
|
3218
|
cmAudioFileH_t afH;
|
2985
|
3219
|
cmRC_t afRC;
|
2986
|
3220
|
cmAudioFileInfo_t afInfo;
|
|
@@ -2992,7 +3226,7 @@ cmDspRC_t _cmDspWaveTableInitAudioFile( cmDspCtx_t* ctx, cmDspWaveTable_t* p )
|
2992
|
3226
|
// if the file name is valid
|
2993
|
3227
|
if( fn == NULL || strlen(fn)==0 )
|
2994
|
3228
|
{
|
2995
|
|
- cmDspInstErr(ctx,&p->inst,kVarNotValidDspRC,"Audio file loading was requested for the wave table but no file name was given.");
|
|
3229
|
+ rc = cmDspInstErr(ctx,&p->inst,kVarNotValidDspRC,"Audio file loading was requested for the wave table but no file name was given.");
|
2996
|
3230
|
goto errLabel;
|
2997
|
3231
|
}
|
2998
|
3232
|
|
|
@@ -3468,7 +3702,7 @@ cmDspRC_t _cmSprintfGetInputTypes( cmDspCtx_t* ctx, cmDspClass_t* classPtr, cons
|
3468
|
3702
|
snprintf(fmtArray[j].label,kSprintfLabelCharCnt,"in-%i",j);
|
3469
|
3703
|
|
3470
|
3704
|
fmtArray[j].label[kSprintfLabelCharCnt]=0;
|
3471
|
|
- fmtArray[j].label[kSprintfDocCharCnt] = 0;
|
|
3705
|
+ fmtArray[j].doc[kSprintfDocCharCnt] = 0;
|
3472
|
3706
|
|
3473
|
3707
|
switch( fmt[ i + fn - 1 ] )
|
3474
|
3708
|
{
|
|
@@ -4942,6 +5176,8 @@ cmDspClassConsFunc_t _cmDspClassBuiltInArray[] =
|
4942
|
5176
|
cmCounterClassCons,
|
4943
|
5177
|
|
4944
|
5178
|
cmPhasorClassCons,
|
|
5179
|
+ cmMidiOutClassCons,
|
|
5180
|
+ cmMidiInClassCons,
|
4945
|
5181
|
cmAudioInClassCons,
|
4946
|
5182
|
cmAudioOutClassCons,
|
4947
|
5183
|
cmAudioFileOutClassCons,
|
|
@@ -5018,6 +5254,7 @@ cmDspClassConsFunc_t _cmDspClassBuiltInArray[] =
|
5018
|
5254
|
cmScFolClassCons,
|
5019
|
5255
|
cmScModClassCons,
|
5020
|
5256
|
cmGSwitchClassCons,
|
|
5257
|
+ cmScaleRangeClassCons,
|
5021
|
5258
|
|
5022
|
5259
|
NULL,
|
5023
|
5260
|
};
|