forked from reaper-oss/sws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sws_extension.cpp
1284 lines (1188 loc) · 40.1 KB
/
sws_extension.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************
/ sws_extension.cpp
/
/ Copyright (c) 2013 and later Tim Payne (SWS), Jeffos
/
/
/ Permission is hereby granted, free of charge, to any person obtaining a copy
/ of this software and associated documentation files (the "Software"), to deal
/ in the Software without restriction, including without limitation the rights to
/ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
/ of the Software, and to permit persons to whom the Software is furnished to
/ do so, subject to the following conditions:
/
/ The above copyright notice and this permission notice shall be included in all
/ copies or substantial portions of the Software.
/
/ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
/ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
/ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
/ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
/ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
/ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
/ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
/ OTHER DEALINGS IN THE SOFTWARE.
/
******************************************************************************/
#include "stdafx.h"
#include "version.h"
#include "Console/Console.h"
#include "Freeze/Freeze.h"
#include "MarkerActions/MarkerActions.h"
#include "Snapshots/SnapshotClass.h"
#include "Snapshots/Snapshots.h"
#include "Zoom.h"
#include "Misc/Misc.h"
#include "Misc/RecCheck.h"
#include "Misc/Adam.h"
#include "Color/Color.h"
#include "Color/Autocolor.h"
#include "MarkerList/MarkerListClass.h"
#include "MarkerList/MarkerList.h"
#include "TrackList/TracklistFilter.h"
#include "TrackList/Tracklist.h"
#include "Projects/ProjectMgr.h"
#include "Projects/ProjectList.h"
#include "SnM/SnM.h"
#include "SnM/SnM_CSurf.h"
#include "SnM/SnM_Dlg.h"
#include "SnM/SnM_Util.h"
#include "Padre/padreActions.h"
#include "Fingers/FNG_client.h"
#include "Autorender/Autorender.h"
#include "IX/IX.h"
#include "Breeder/BR.h"
#include "Wol/wol.h"
#include "nofish/nofish.h"
#include "snooks/snooks.h"
#define LOCALIZE_IMPORT_PREFIX "sws_"
#ifdef LOCALIZE_IMPORT_PREFIX
#include "./reaper/localize-import.h"
#endif
#include "./reaper/localize.h"
REAPER_PLUGIN_HINSTANCE g_hInst = NULL;
HWND g_hwndParent = NULL;
bool g_bInitDone = false;
#ifdef ACTION_DEBUG
void freeCmdFilesValue(WDL_String* p) {delete p;}
static WDL_IntKeyedArray<WDL_String*> g_cmdFiles(freeCmdFilesValue);
#endif
static WDL_IntKeyedArray<COMMAND_T*> g_commands; // no valdispose (cmds can be allocated in different ways)
int g_iFirstCommand = 0;
int g_iLastCommand = 0;
bool hookCommandProc(int iCmd, int flag)
{
static WDL_PtrList<const char> sReentrantCmds;
// for Xen extensions
g_KeyUpUndoHandler=0;
// "Hack" to make actions will #s less than 1000 work with SendMessage (AHK)
// no recursion check here: handled by REAPER
if (iCmd < 1000)
return KBD_OnMainActionEx(iCmd, 0, 0, 0, g_hwndParent, NULL) ? true : false; // C4800
// Special case for checking recording
if (iCmd == 1013 && !RecordInputCheck())
return true;
if (BR_GlobalActionHook(iCmd, 0, 0, 0, 0))
return true;
// Ignore commands that don't have anything to do with us from this point forward
if (COMMAND_T* cmd = SWSGetCommandByID(iCmd))
{
// For continuous actions
if (BR_SwsActionHook(cmd, flag, NULL))
return true;
if (!cmd->uniqueSectionId && cmd->accel.accel.cmd==iCmd && cmd->doCommand)
{
if (sReentrantCmds.Find(cmd->id)<0)
{
sReentrantCmds.Add(cmd->id);
cmd->fakeToggle = !cmd->fakeToggle;
#ifndef BR_DEBUG_PERFORMANCE_ACTIONS
cmd->doCommand(cmd);
#else
CommandTimer(cmd);
#endif
sReentrantCmds.Delete(sReentrantCmds.Find(cmd->id));
return true;
}
#ifdef _SWS_DEBUG
else
{
OutputDebugString("hookCommandProc - recursive action: ");
OutputDebugString(cmd->id);
OutputDebugString("\n");
}
#endif
}
}
return false;
}
bool hookCommandProc2(KbdSectionInfo* sec, int cmdId, int val, int valhw, int relmode, HWND hwnd)
{
static WDL_PtrList<const char> sReentrantCmds;
if (BR_GlobalActionHook(cmdId, val, valhw, relmode, hwnd))
return true;
// Ignore commands that don't have anything to do with us from this point forward
if (COMMAND_T* cmd = SWSGetCommandByID(cmdId))
{
if (cmd->uniqueSectionId==sec->uniqueID && cmd->accel.accel.cmd==cmdId)
{
// job for hookCommandProc?
// note: we could perform cmd->doCommand() here, but we'd loose the "flag" param value
if (cmd->doCommand)
return false;
if (cmd->onAction)
{
// For continuous actions
if (BR_SwsActionHook(cmd, relmode, hwnd))
return true;
if (sReentrantCmds.Find(cmd->id)<0)
{
sReentrantCmds.Add(cmd->id);
cmd->fakeToggle = !cmd->fakeToggle;
#ifndef BR_DEBUG_PERFORMANCE_ACTIONS
cmd->onAction(cmd, val, valhw, relmode, hwnd);
#else
CommandTimer(cmd, val, valhw, relmode, hwnd, true);
#endif
sReentrantCmds.Delete(sReentrantCmds.Find(cmd->id));
return true;
}
#ifdef _SWS_DEBUG
else
{
OutputDebugString("hookCommandProc2 - recursive action: ");
OutputDebugString(cmd->id);
OutputDebugString("\n");
}
#endif
}
}
}
return false;
}
// just a dummy example, not used ATM (commented in the entry point)
void hookPostCommandProc(int iCmd, int flag)
{
WDL_FastString str;
str.SetFormatted(512, "hookPostCommandProc: %s, flag=%d\r\n", kbd_getTextFromCmd(iCmd, NULL), flag);
ShowConsoleMsg(str.Get());
}
// Returns:
// -1 = action does not belong to this extension, or does not toggle
// 0 = action belongs to this extension and is currently set to "off"
// 1 = action belongs to this extension and is currently set to "on"
int toggleActionHook(int iCmd)
{
static WDL_PtrList<const char> sReentrantCmds;
if (COMMAND_T* cmd = SWSGetCommandByID(iCmd))
{
if (cmd->accel.accel.cmd==iCmd && cmd->getEnabled)
{
if (sReentrantCmds.Find(cmd->id) == -1)
{
sReentrantCmds.Add(cmd->id);
int state = cmd->getEnabled(cmd);
sReentrantCmds.Delete(sReentrantCmds.Find(cmd->id));
return state;
}
#ifdef _SWS_DEBUG
else
{
OutputDebugString("toggleActionHook - recursive action: ");
OutputDebugString(cmd->id);
OutputDebugString("\n");
}
#endif
}
}
return -1;
}
// 1) Get command ID from Reaper
// 2) Add keyboard accelerator (with localized action name) and add to the "action" list
int SWSRegisterCmd(COMMAND_T* pCommand, const char* cFile, int cmdId, bool localize)
{
if (!pCommand || !pCommand->id || !pCommand->accel.desc || (!pCommand->doCommand && !pCommand->onAction)) return 0;
// localized action name, if needed
const char* defaultName = pCommand->accel.desc;
if (localize) pCommand->accel.desc = GetLocalizedActionName(pCommand->accel.desc); // no alloc + no-op when no LangPack file is defined
if (!pCommand->uniqueSectionId && pCommand->doCommand)
{
if (!cmdId) cmdId = plugin_register("command_id", (void*)pCommand->id);
if (cmdId)
{
pCommand->accel.accel.cmd = cmdId; // need to this before registering "gaccel"
cmdId = (plugin_register("gaccel", &pCommand->accel) ? cmdId : 0);
}
}
else if (pCommand->onAction)
{
static custom_action_register_t s;
memset(&s, 0, sizeof(custom_action_register_t));
s.idStr = pCommand->id;
s.name = pCommand->accel.desc;
s.uniqueSectionId = pCommand->uniqueSectionId;
cmdId = plugin_register("custom_action", (void*)&s); // will re-use the known cmd ID, if any
}
else
cmdId = 0;
pCommand->accel.accel.cmd = cmdId;
// now that it is registered, restore the default action name
if (pCommand->accel.desc != defaultName) pCommand->accel.desc = defaultName;
if (!cmdId) return 0;
if (!g_iFirstCommand || g_iFirstCommand > cmdId) g_iFirstCommand = cmdId;
if (cmdId > g_iLastCommand) g_iLastCommand = cmdId;
g_commands.Insert(cmdId, pCommand);
#ifdef ACTION_DEBUG
g_cmdFiles.Insert(cmdId, new WDL_String(cFile));
#endif
return pCommand->accel.accel.cmd;
}
// For each item in table call SWSRegisterCommand
int SWSRegisterCmds(COMMAND_T* pCommands, const char* cFile, bool localize)
{
int i = 0;
while(pCommands[i].id != LAST_COMMAND)
SWSRegisterCmd(&pCommands[i++], cFile, 0, localize);
return 1;
}
// Make and register a dynamic action (created/removed at runtime)
// If cmdId==0, get command ID from Reaper (use the provided cmdId otherwise)
// Note: SWSFreeUnregisterDynamicCmd() can be used to free/unregister such an action
int SWSCreateRegisterDynamicCmd(int uniqueSectionId, int cmdId, void(*doCommand)(COMMAND_T*), void(*onAction)(COMMAND_T*, int, int, int, HWND), int(*getEnabled)(COMMAND_T*), const char* cID, const char* cDesc, const char* cMenu, INT_PTR user, const char* cFile, bool localize)
{
COMMAND_T* ct = new COMMAND_T;
memset(ct, 0, sizeof(COMMAND_T));
ct->uniqueSectionId = uniqueSectionId;
ct->accel.desc = _strdup(cDesc);
ct->id = _strdup(cID);
ct->doCommand = doCommand;
ct->onAction = onAction;
ct->getEnabled = getEnabled;
ct->user = user;
ct->menuText = cMenu;
return SWSRegisterCmd(ct, cFile, cmdId, localize);
}
bool SWSFreeUnregisterDynamicCmd(int id)
{
if (COMMAND_T* ct = SWSUnregisterCmd(id))
{
free((void*)ct->accel.desc);
free((void*)ct->id);
DELETE_NULL(ct);
return true;
}
return false;
}
// Returns the COMMAND_T entry (so it can be freed if necessary)
COMMAND_T* SWSUnregisterCmd(int id)
{
if (COMMAND_T* ct = g_commands.Get(id, NULL))
{
if (!ct->uniqueSectionId && ct->doCommand)
{
plugin_register("-gaccel", &ct->accel);
/* this is no-op ATM
plugin_register("-command_id", &id);
*/
}
else if (ct->onAction)
{
static custom_action_register_t s;
s.idStr = ct->id;
s.uniqueSectionId = ct->uniqueSectionId;
plugin_register("-custom_action", (void*)&s);
}
g_commands.Delete(id);
#ifdef ACTION_DEBUG
g_cmdFiles.Delete(id);
#endif
return ct;
}
return NULL;
}
void UnregisterAllCmds() {
for (int i=g_iFirstCommand; i<=g_iLastCommand; i++)
SWSUnregisterCmd(i);
}
#ifdef ACTION_DEBUG
void ActionsList(COMMAND_T*)
{
// Output sws_actions.csv
char cBuf[512];
strncpy(cBuf, get_ini_file(), 256);
char* pC = strrchr(cBuf, PATH_SLASH_CHAR);
if (pC)
{
strcpy(pC+1, "sws_actions.csv");
FILE* f = fopenUTF8(cBuf, "w");
fputs("Action,File,CmdID,CmdStr\n", f);
if (f)
{
for (int i = 0; i < g_commands.GetSize(); i++)
{
if (COMMAND_T* cmd = g_commands.Enumerate(i, NULL, NULL))
{
WDL_String* pFn = g_cmdFiles.Get(cmd->accel.accel.cmd, NULL);
snprintf(cBuf, sizeof(cBuf), "\"%s\",%s,%d,_%s\n", cmd->accel.desc, pFn ? pFn->Get() : "", cmd->accel.accel.cmd, cmd->id);
fputs(cBuf, f);
}
}
fclose(f);
}
}
}
#endif
//JFB questionnable func: ok most of the time but, for ex.,
// 2 different cmds can share the same function pointer cmd->doCommand
int SWSGetCommandID(void (*cmdFunc)(COMMAND_T*), INT_PTR user, const char** pMenuText)
{
for (int i=0; i<g_commands.GetSize(); i++)
{
if (COMMAND_T* cmd = g_commands.Enumerate(i, NULL, NULL))
{
if (cmd->doCommand == cmdFunc && cmd->user == user)
{
if (pMenuText)
*pMenuText = cmd->menuText;
return cmd->accel.accel.cmd;
}
}
}
return 0;
}
COMMAND_T* SWSGetCommandByID(int cmdId) {
if (cmdId >= g_iFirstCommand && cmdId <= g_iLastCommand) // not enough to ensure it is a SWS action
return g_commands.Get(cmdId, NULL);
return NULL;
}
int IsSwsAction(const char* _actionName)
{
if (_actionName)
if (const char* p = strstr(_actionName, ": ")) // no strchr() here: make sure p[2] is not out of bounds
if (const char* tag = strstr(_actionName, "SWS")) // make sure it is a SWS tag
if (tag < p) // make really sure
return ((int)(p+2-_actionName));
return 0;
}
HMENU SWSCreateMenuFromCommandTable(COMMAND_T pCommands[], HMENU hMenu, int* iIndex)
{
int i = 0;
if (iIndex)
i = *iIndex;
while (pCommands[i].id != LAST_COMMAND && pCommands[i].id != SWS_ENDSUBMENU)
{
const char* name = pCommands[i].menuText;
if (name && *name)
{
if (!hMenu)
hMenu = CreatePopupMenu();
if (pCommands[i].id == SWS_STARTSUBMENU)
{
i++;
HMENU hSubMenu = SWSCreateMenuFromCommandTable(pCommands, NULL, &i);
AddSubMenu(hMenu, hSubMenu, __localizeFunc(name,"sws_menu",0));
}
else
AddToMenu(hMenu, __localizeFunc(name,"sws_menu",0), pCommands[i].accel.accel.cmd);
}
i++;
}
if (iIndex)
*iIndex = i;
return hMenu;
}
// This function creates the extension menu (flag==0) and handles checking menu items (flag==1).
// Reaper automatically checks menu items of customized menus using toggleActionHook above,
// but since we can't tell if a menu is customized we always check either way.
static void swsMenuHook(const char* menustr, HMENU hMenu, int flag)
{
if (flag == 1)
{
// Handle checked menu items
// Go through every menu item - see if it exists in the table, then check if necessary
MENUITEMINFO mi={sizeof(MENUITEMINFO),};
mi.fMask = MIIM_ID | MIIM_SUBMENU;
for (int i = 0; i < GetMenuItemCount(hMenu); i++)
{
GetMenuItemInfo(hMenu, i, true, &mi);
if (mi.hSubMenu)
swsMenuHook(menustr, mi.hSubMenu, flag);
else if (mi.wID >= (UINT)g_iFirstCommand && mi.wID <= (UINT)g_iLastCommand) {
if (COMMAND_T* t = g_commands.Get(mi.wID, NULL))
CheckMenuItem(hMenu, i, MF_BYPOSITION | (t->getEnabled && t->getEnabled(t) ? MF_CHECKED : MF_UNCHECKED));
}
}
}
else if (!strcmp(menustr, "Main extensions"))
SWSCreateExtensionsMenu(hMenu);
}
// Fake control surface to get a low priority periodic time slice from Reaper
// and callbacks for some "track params have changed"
class SWSTimeSlice : public IReaperControlSurface
{
public:
const char *GetTypeString() { return ""; }
const char *GetDescString() { return ""; }
const char *GetConfigString() { return ""; }
bool m_bChanged;
int m_iACIgnore;
SWSTimeSlice() : m_bChanged(false), m_iACIgnore(0) {}
void Run() // BR: Removed some stuff from here and made it use plugin_register("timer"/"-timer") - it's the same thing as this but it enables us to remove unused stuff completely
{ // I guess we could do the rest too (and add user options to enable where needed)...
SNM_CSurfRun();
ZoomSlice();
MiscSlice();
if (m_bChanged)
{
m_bChanged = false;
ScheduleTracklistUpdate();
g_pMarkerList->Update();
UpdateSnapshotsDialog();
ProjectListUpdate();
}
}
void SetPlayState(bool play, bool pause, bool rec)
{
SNM_CSurfSetPlayState(play, pause, rec);
AWDoAutoGroup(rec);
ItemPreviewPlayState(play, rec);
BR_CSurf_SetPlayState(play, pause, rec);
}
// This is our only notification of active project tab change, so update everything
void SetTrackListChange()
{
m_bChanged = true;
AutoColorTrack(false);
AutoColorMarkerRegion(false);
SNM_CSurfSetTrackListChange();
m_iACIgnore = GetNumTracks() + 1;
}
// For every SetTrackListChange we get NumTracks+1 SetTrackTitle calls, but we only
// want to call AutoColorRun once, so ignore those n+1.
// However, we still need to trap track name changes with no track list change.
void SetTrackTitle(MediaTrack *tr, const char *c)
{
ScheduleTracklistUpdate();
if (!m_iACIgnore)
{
AutoColorTrack(false);
SNM_CSurfSetTrackTitle();
}
else
m_iACIgnore--;
}
void OnTrackSelection(MediaTrack *tr) // 3 problems with this (last check v5.0pre28): doesn't work if Mixer option "Scroll view when tracks activated" is disabled
{ // gets called before CSurf->Extended(CSURF_EXT_SETLASTTOUCHEDTRACK)
// only gets called when track is selected by clicking it in TCP/MCP (and not when track is selected via action)...bug or feature?
// while OnTrackSelection appears to be broken, putting this in SetSurfaceSelected() would mean it gets called multiple times (because SetSurfaceSelected() gets called once for each track whose
// selection state changed, and then once more for every track in the project). We could theoretically try and deduct when SetSurfaceSelected() got called the last time (but it's arguable if we could
// do this with 100% accuracy because when only master track is selected, SetSurfaceSelected() gets called only once, and in case new track is inserted, it gets called 3 times for the last track (once for unselecting
// prior to inserting new track, once for new track's selection state, and then once more when it iterates through all tracks)
//
// Besides these complications, it would also mean we would have to check all of these things a lot of times, thus clogging the Csurf just to execute one simple thing. So just leave it here and hope the
// OnTrackSelection() gets fixed at some point :)
BR_CSurf_OnTrackSelection(tr);
}
void SetSurfaceSelected(MediaTrack *tr, bool bSel) { ScheduleTracklistUpdate(); UpdateSnapshotsDialog(true); }
void SetSurfaceMute(MediaTrack *tr, bool mute) { ScheduleTracklistUpdate(); UpdateTrackMute(); }
void SetSurfaceSolo(MediaTrack *tr, bool solo) { ScheduleTracklistUpdate(); UpdateTrackSolo(); }
void SetSurfaceRecArm(MediaTrack *tr, bool arm) { ScheduleTracklistUpdate(); UpdateTrackArm(); }
int Extended(int call, void *parm1, void *parm2, void *parm3)
{
BR_CSurf_Extended(call, parm1, parm2, parm3);
SNM_CSurfExtended(call, parm1, parm2, parm3);
return 0;
}
};
// WDL Stuff
bool WDL_STYLE_GetBackgroundGradient(double *gradstart, double *gradslope) { return false; }
bool WDL_STYLE_AllowSliderMouseWheel() { return true; }
LICE_IBitmap *WDL_STYLE_GetSliderBitmap2(bool vert) { return NULL; }
int WDL_STYLE_GetSliderDynamicCenterPos() { return 500; }
int WDL_STYLE_GetSysColor(int i)
{
int col = GSC_mainwnd(i);
// check & "fix" 3D colors that aren't distinguished in many themes..
#ifdef _WIN32
if (i == COLOR_3DSHADOW || i == COLOR_3DLIGHT || i == COLOR_3DHILIGHT)
#else
if (i == COLOR_3DSHADOW || i == COLOR_3DHILIGHT)
#endif
{
int col3ds,col3dl,bgcol=GSC_mainwnd(COLOR_WINDOW);
ColorTheme* ct = SNM_GetColorTheme();
if (ct)
{
col3dl = ct->io_3d[0];
col3ds = ct->io_3d[1];
if (i == COLOR_3DSHADOW) col = col3ds;
else col = col3dl;
}
else
{
col3dl = GSC_mainwnd(COLOR_3DHILIGHT);
col3ds = GSC_mainwnd(COLOR_3DSHADOW);
}
if (col3ds == col3dl || col3ds == bgcol || col3dl == bgcol)
{
int colDelta = SNM_3D_COLORS_DELTA * (i == COLOR_3DSHADOW ? -1 : 1);
col = RGB(
BOUNDED(LICE_GETR(bgcol) + colDelta, 0, 0xFF),
BOUNDED(LICE_GETG(bgcol) + colDelta, 0, 0xFF),
BOUNDED(LICE_GETB(bgcol) + colDelta, 0, 0xFF));
}
}
return col;
}
int WDL_STYLE_WantGlobalButtonBorders() { return 0; }
bool WDL_STYLE_WantGlobalButtonBackground(int *col) { return false; }
void WDL_STYLE_ScaleImageCoords(int *x, int *y) { }
// Main DLL entry point
SWSTimeSlice* g_ts=NULL;
void ErrMsg(const char* errmsg, bool wantblabla=true)
{
if (errmsg && *errmsg && (!IsREAPER || IsREAPER())) // don't display any message if loaded from ReaMote
{
WDL_FastString msg(errmsg);
if (wantblabla)
{
// reversed insertion
msg.Insert(" ", 0);
msg.Insert(__LOCALIZE("Hint:","sws_mbox"), 0);
msg.Insert("\r\n", 0);
msg.Insert(__LOCALIZE("An error occured during the SWS extension initialization.","sws_mbox"), 0);
}
MessageBox(Splash_GetWnd&&Splash_GetWnd()?Splash_GetWnd():NULL, msg.Get(), __LOCALIZE("SWS - Error","sws_mbox"), MB_OK);
}
}
// IMPAPI: maps mandatory API functions, i.e. forces users to upgrade REAPER if these functions are not found
// IMPAP_OPT: maps optional API functions. Such function pointers will be NULL otherwise.
#define IMPAPI(x) if (!errcnt && !((*(void **)&(x)) = (void *)rec->GetFunc(#x))) errcnt++;
#define IMPAP_OPT(x) *((void **)&(x)) = (void *)rec->GetFunc(#x);
#define ERR_RETURN(a) { ErrMsg(a); goto error; }
extern "C"
{
REAPER_PLUGIN_DLL_EXPORT int REAPER_PLUGIN_ENTRYPOINT(REAPER_PLUGIN_HINSTANCE hInstance, reaper_plugin_info_t *rec)
{
if (!rec)
{
error:
if (plugin_register)
{
UnregisterAllCmds();
plugin_register("-hookcommand2", (void*)hookCommandProc2);
plugin_register("-hookcommand", (void*)hookCommandProc);
// plugin_register("-hookpostcommand", (void*)hookPostCommandProc);
plugin_register("-toggleaction", (void*)toggleActionHook);
plugin_register("-hookcustommenu", (void*)swsMenuHook);
if (g_ts) { plugin_register("-csurf_inst", g_ts); DELETE_NULL(g_ts); }
UnregisterExportedFuncs();
}
if (g_bInitDone) // no granularity here, but it'd be an internal error anyway
{
ColorExit();
AutorenderExit();
SnapshotsExit();
TrackListExit();
MarkerListExit();
MarkerActionsExit();
AutoColorExit();
ProjectListExit();
ProjectMgrExit();
XenakiosExit();
ConsoleExit();
FreezeExit();
MiscExit();
FNGExtensionExit();
PadreExit();
SNM_Exit();
BR_Exit();
}
return 0; // makes REAPER unloading us
}
if (rec->caller_version != REAPER_PLUGIN_VERSION)
ERR_RETURN("Wrong REAPER_PLUGIN_VERSION!")
g_hInst = hInstance;
g_hwndParent = rec->hwnd_main;
if (!rec->GetFunc)
ERR_RETURN("Null rec->GetFunc ptr.")
#ifdef _SWS_LOCALIZATION
IMPORT_LOCALIZE_RPLUG(rec);
#endif
// Mandatory API functions
int errcnt=0; // IMPAPI failed if >0
IMPAPI(plugin_register); // keep those first
IMPAPI(IsREAPER);
IMPAPI(AddExtensionsMainMenu);
IMPAPI(AddMediaItemToTrack);
IMPAPI(AddProjectMarker);
IMPAPI(AddProjectMarker2);
IMPAPI(AddTakeToMediaItem);
/* deprecated
IMPAPI(AddTempoTimeSigMarker);
*/
IMPAPI(adjustZoom);
IMPAPI(ApplyNudge);
IMPAPI(AttachWindowTopmostButton);
IMPAPI(AttachWindowResizeGrip);
IMPAPI(AudioAccessorValidateState);
IMPAPI(Audio_Init); // v5.111+
IMPAPI(Audio_Quit); // v5.111+
IMPAPI(Audio_RegHardwareHook);
/* unused
IMPAPI(Audio_RegHardwareHook);
*/
IMPAPI(ColorToNative)
IMPAPI(CoolSB_GetScrollInfo);
IMPAPI(CoolSB_SetScrollInfo);
IMPAPI(CountActionShortcuts);
IMPAPI(CountAutomationItems);
IMPAPI(CountEnvelopePoints); // v5pre4+
IMPAPI(CountEnvelopePointsEx) // v5.40+
IMPAPI(CountMediaItems); // O(N): should be banned from the extension, ideally -- don't use it in loops, at least
IMPAPI(CountProjectMarkers);
IMPAPI(CountSelectedMediaItems); // O(MN): should be banned from the extension, ideally -- don't use it in loops, at least
IMPAPI(CountSelectedTracks); // exclude master + O(N): should be banned from the extension, ideally -- don't use it in loops, at least
IMPAPI(CountTakeEnvelopes) // v5pre12+ -- O(N): don't use it in loops
IMPAPI(CountTakes);
IMPAPI(CountTCPFXParms);
IMPAPI(CountTempoTimeSigMarkers);
IMPAPI(CountTracks);
IMPAPI(CountTrackMediaItems);
IMPAPI(CountTrackEnvelopes);
IMPAPI(CreateLocalOscHandler);
IMPAPI(CreateNewMIDIItemInProj);
IMPAPI(CreateTakeAudioAccessor);
IMPAPI(CreateTrackAudioAccessor);
IMPAPI(CreateTrackSend); // v5.15pre1+
IMPAPI(CSurf_FlushUndo);
IMPAPI(CSurf_GoEnd);
IMPAPI(CSurf_OnMuteChange);
IMPAPI(CSurf_OnPanChange);
IMPAPI(CSurf_OnPlayRateChange);
IMPAPI(CSurf_OnSelectedChange);
IMPAPI(CSurf_OnTrackSelection);
IMPAPI(CSurf_OnVolumeChange);
IMPAPI(CSurf_OnWidthChange);
IMPAPI(CSurf_TrackFromID);
IMPAPI(CSurf_TrackToID);
IMPAPI(DB2SLIDER);
IMPAPI(DeleteEnvelopePointRange); // v5pre5+
IMPAPI(DeleteEnvelopePointRangeEx); // v5.4pre3+
IMPAPI(DeleteActionShortcut);
IMPAPI(DeleteProjectMarker);
IMPAPI(DeleteProjectMarkerByIndex);
IMPAPI(DeleteTakeStretchMarkers);
IMPAPI(DeleteTempoTimeSigMarker); // v5pre4+
IMPAPI(DeleteTrack);
IMPAPI(DeleteTrackMediaItem);
IMPAPI(DestroyAudioAccessor);
IMPAPI(DestroyLocalOscHandler);
IMPAPI(DoActionShortcutDialog);
IMPAPI(Dock_UpdateDockID);
IMPAPI(DockIsChildOfDock);
IMPAPI(DockWindowActivate);
IMPAPI(DockWindowAdd);
IMPAPI(DockWindowAddEx);
IMPAPI(DockWindowRefresh);
IMPAPI(DockWindowRemove);
IMPAPI(EnsureNotCompletelyOffscreen);
IMPAPI(EnumProjectMarkers);
IMPAPI(EnumProjectMarkers2);
IMPAPI(EnumProjectMarkers3);
IMPAPI(EnumProjects);
IMPAPI(Envelope_Evaluate); // v5pre4+
IMPAPI(Envelope_SortPoints); // v5pre4+
IMPAPI(Envelope_SortPointsEx) // v5.4pre3+
IMPAPI(file_exists);
IMPAPI(format_timestr);
IMPAPI(format_timestr_pos);
IMPAPI(format_timestr_len);
IMPAPI(FreeHeapPtr);
IMPAPI(GetActionShortcutDesc);
IMPAPI(GetActiveTake);
IMPAPI(GetAllProjectPlayStates); // v5.111+
IMPAPI(GetAppVersion);
IMPAPI(GetAudioAccessorEndTime);
IMPAPI(GetAudioAccessorHash);
IMPAPI(GetAudioAccessorSamples);
IMPAPI(GetAudioAccessorStartTime);
IMPAPI(GetColorThemeStruct);
IMPAPI(GetContextMenu);
IMPAPI(GetCurrentProjectInLoadSave);
IMPAPI(GetCursorContext);
IMPAPI(GetCursorContext2);
IMPAPI(GetCursorPosition);
IMPAPI(GetCursorPositionEx);
IMPAPI(GetEnvelopeName);
IMPAPI(GetEnvelopePoint); // v5pre4
IMPAPI(GetEnvelopePointEx); // v5.40+
IMPAPI(GetEnvelopePointByTime); // v5pre4
IMPAPI(GetEnvelopePointByTimeEx); // v5.40+
IMPAPI(GetEnvelopeScalingMode); // v5pre13+
IMPAPI(GetEnvelopeStateChunk);
IMPAPI(GetExePath);
IMPAPI(GetFocusedFX);
IMPAPI(GetFXEnvelope); // v5pre5+
IMPAPI(GetGlobalAutomationOverride);
IMPAPI(GetHZoomLevel);
IMPAPI(GetIconThemePointer);
IMPAPI(GetIconThemeStruct);
IMPAPI(GetInputChannelName);
IMPAPI(GetItemEditingTime2);
IMPAPI(GetLastMarkerAndCurRegion); // v4.60+
IMPAPI(GetLastTouchedFX);
IMPAPI(GetLastTouchedTrack);
IMPAPI(GetMainHwnd);
IMPAPI(GetMasterMuteSoloFlags);
IMPAPI(GetMasterTrackVisibility);
IMPAPI(GetMasterTrack);
IMPAPI(GetMediaItem); // O(N): should be banned from the extension, ideally
IMPAPI(GetMediaItem_Track);
IMPAPI(GetMediaItemInfo_Value);
IMPAPI(GetMediaItemNumTakes);
IMPAPI(GetMediaItemTake);
IMPAPI(GetMediaItemTakeByGUID);
IMPAPI(GetMediaItemTake_Item);
IMPAPI(GetMediaItemTake_Source);
IMPAPI(GetMediaItemTake_Track);
IMPAPI(GetMediaItemTakeInfo_Value);
IMPAPI(GetMediaItemTrack);
IMPAPI(GetMediaSourceFileName);
IMPAPI(GetMediaSourceType);
IMPAPI(GetMediaTrackInfo_Value);
/* deprecated, no-op
IMPAPI(get_midi_config_var);
*/
IMPAPI(GetMouseModifier);
IMPAPI(GetNumTracks);
IMPAPI(GetOutputChannelName);
IMPAPI(GetPeakFileName);
IMPAPI(GetPeaksBitmap);
IMPAPI(GetPlayPosition);
IMPAPI(GetPlayPosition2);
IMPAPI(GetPlayPositionEx);
IMPAPI(GetPlayPosition2Ex);
IMPAPI(GetPlayState);
IMPAPI(GetPlayStateEx);
IMPAPI(GetProjectLength);
IMPAPI(GetProjectPath);
IMPAPI(GetProjectStateChangeCount);
IMPAPI(GetProjectTimeSignature2);
IMPAPI(GetResourcePath);
IMPAPI(GetSelectedEnvelope);
IMPAPI(GetSelectedMediaItem); // O(MN): should be banned from the extension, ideally
IMPAPI(GetSelectedTrack); // exclude master + O(N): should be banned from the extension, ideally
IMPAPI(GetSelectedTrackEnvelope);
IMPAPI(GetSet_ArrangeView2);
IMPAPI(GetSetAutomationItemInfo);
IMPAPI(GetSetEnvelopeState);
IMPAPI(GetSetMediaItemInfo);
IMPAPI(GetSetMediaItemTakeInfo);
IMPAPI(GetSetMediaItemTakeInfo_String);
IMPAPI(GetMediaSourceLength); // v5.0pre3+
IMPAPI(GetSetMediaTrackInfo);
IMPAPI(GetSetMediaTrackInfo_String);
IMPAPI(GetSetObjectState);
IMPAPI(GetSetObjectState2);
IMPAPI(GetSetProjectNotes); // v5.15pre1+
IMPAPI(GetSetRepeat);
IMPAPI(GetSetTrackGroupMembership); // v5.21pre5+
IMPAPI(GetSetTrackGroupMembershipHigh); // v5.70+
IMPAPI(GetTempoTimeSigMarker);
IMPAPI(GetTakeEnvelopeByName);
IMPAPI(GetTakeName);
IMPAPI(GetTakeStretchMarker);
IMPAPI(GetSetTrackSendInfo);
IMPAPI(GetSetTrackState);
IMPAPI(GetSet_LoopTimeRange);
IMPAPI(GetSet_LoopTimeRange2);
IMPAPI(GetSubProjectFromSource);
IMPAPI(GetTake);
IMPAPI(GetTakeEnvelope); // v5pre12+
IMPAPI(GetTakeNumStretchMarkers);
IMPAPI(GetTCPFXParm);
IMPAPI(GetToggleCommandState);
IMPAPI(GetToggleCommandState2);
IMPAPI(GetToggleCommandStateEx);
IMPAPI(GetSelectedEnvelope);
IMPAPI(GetToggleCommandStateThroughHooks);
IMPAPI(GetTooltipWindow);
IMPAPI(GetTrack);
IMPAPI(GetTrackAutomationMode);
IMPAPI(GetTrackGUID);
IMPAPI(GetTrackEnvelope);
IMPAPI(GetTrackEnvelopeByName);
IMPAPI(GetTrackInfo);
IMPAPI(GetTrackMediaItem);
IMPAPI(GetTrackMIDINoteNameEx);
IMPAPI(GetTrackNumMediaItems);
IMPAPI(GetTrackNumSends);
IMPAPI(GetTrackStateChunk);
IMPAPI(GetTrackUIVolPan);
IMPAPI(GetUserInputs);
IMPAPI(get_config_var);
IMPAPI(get_ini_file);
IMPAPI(GR_SelectColor);
IMPAPI(GSC_mainwnd);
IMPAPI(guidToString);
IMPAPI(Help_Set);
IMPAPI(InsertAutomationItem);
IMPAPI(InsertMedia);
IMPAPI(InsertEnvelopePoint); // v5pre4+
IMPAPI(InsertEnvelopePointEx); // v5.4pre3+
IMPAPI(InsertTrackAtIndex);
IMPAPI(IsMediaExtension);
IMPAPI(IsMediaItemSelected);
IMPAPI(IsProjectDirty);
IMPAPI(IsTrackVisible);
IMPAPI(kbd_enumerateActions);
IMPAPI(kbd_formatKeyName);
IMPAPI(kbd_getCommandName);
IMPAPI(kbd_getTextFromCmd);
IMPAPI(KBD_OnMainActionEx);
IMPAPI(kbd_reprocessMenu);
IMPAPI(kbd_RunCommandThroughHooks);
IMPAPI(kbd_translateAccelerator);
IMPAPI(Main_OnCommand);
IMPAPI(Main_OnCommandEx);
IMPAPI(Main_openProject);
IMPAPI(MainThread_LockTracks);
IMPAPI(MainThread_UnlockTracks);
IMPAPI(MarkProjectDirty);
IMPAPI(Master_GetPlayRate);
IMPAPI(Master_GetPlayRateAtTime);
IMPAPI(MIDI_CountEvts);
IMPAPI(MIDI_DeleteCC);
IMPAPI(MIDI_DeleteEvt);
IMPAPI(MIDI_DeleteNote);
IMPAPI(MIDI_DeleteTextSysexEvt);
IMPAPI(MIDI_EnumSelCC);
IMPAPI(MIDI_EnumSelEvts);
IMPAPI(MIDI_EnumSelNotes);
IMPAPI(MIDI_EnumSelTextSysexEvts);
IMPAPI(MIDI_eventlist_Create);
IMPAPI(MIDI_eventlist_Destroy);
IMPAPI(MIDI_GetCC);
IMPAPI(MIDI_GetEvt);
IMPAPI(MIDI_GetNote);
IMPAPI(MIDI_GetPPQPos_EndOfMeasure);
IMPAPI(MIDI_GetPPQPos_StartOfMeasure);
IMPAPI(MIDI_GetPPQPosFromProjTime);
IMPAPI(MIDI_GetProjTimeFromPPQPos);
IMPAPI(MIDI_GetTextSysexEvt);
IMPAPI(MIDI_InsertCC);
IMPAPI(MIDI_InsertEvt);
IMPAPI(MIDI_InsertNote);
IMPAPI(MIDI_InsertTextSysexEvt);
IMPAPI(MIDI_SetCC);
IMPAPI(MIDI_SetEvt);
IMPAPI(MIDI_SetItemExtents); // v5.0pre (no data on exact build in whatsnew, but I'm pretty sure I never saw this in v4)
IMPAPI(MIDI_SetNote);
IMPAPI(MIDI_SetTextSysexEvt);
IMPAPI(MIDIEditor_GetActive);
IMPAPI(MIDIEditor_GetMode);
IMPAPI(MIDIEditor_GetSetting_int);
IMPAPI(MIDIEditor_GetTake);
IMPAPI(MIDIEditor_LastFocused_OnCommand);
IMPAPI(MIDIEditor_OnCommand);
IMPAPI(mkpanstr);
IMPAPI(mkvolpanstr);
IMPAPI(mkvolstr);
IMPAPI(MoveEditCursor);
IMPAPI(MoveMediaItemToTrack);
IMPAPI(OnColorThemeOpenFile); // v5.0pre21+
IMPAPI(OnPauseButton);
IMPAPI(OnPauseButtonEx);
IMPAPI(OnPlayButton);
IMPAPI(OnPlayButtonEx);
IMPAPI(OnStopButton);
IMPAPI(OnStopButtonEx);
IMPAPI(NamedCommandLookup);
IMPAPI(parse_timestr_len);
IMPAPI(parse_timestr_pos);
IMPAPI(PCM_Sink_CreateEx);
IMPAPI(PCM_Source_CreateFromFile);
IMPAPI(PCM_Source_CreateFromFileEx);
IMPAPI(PCM_Source_CreateFromSimple);
IMPAPI(PCM_Source_CreateFromType);
IMPAPI(PCM_Source_GetSectionInfo);
IMPAPI(PlayPreview);
IMPAPI(PlayPreviewEx);
IMPAPI(PlayTrackPreview);
IMPAPI(PlayTrackPreview2Ex);
IMPAPI(plugin_getFilterList);
IMPAPI(plugin_getImportableProjectFilterList);
IMPAPI(PreventUIRefresh);
IMPAPI(projectconfig_var_addr);
IMPAPI(projectconfig_var_getoffs);
IMPAPI(realloc_cmd_ptr); // v5.965+
IMPAPI(RefreshToolbar);
IMPAPI(RefreshToolbar2); // v5pre8+
#ifdef _WIN32
IMPAPI(RemoveXPStyle);
#endif
IMPAPI(RenderFileSection);
IMPAPI(Resample_EnumModes);