-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGHL_Preview.lua
More file actions
3368 lines (2811 loc) · 145 KB
/
GHL_Preview.lua
File metadata and controls
3368 lines (2811 loc) · 145 KB
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
version_num="1.5.2"
imgScale=1024/1024
diffNames={"Easy","Medium","Hard","Expert"}
movequant=10
quants={1/32,1/24,1/16,1/12,1/8,1/6,1/4,1/3,1/2,1,2,4}
-- highway rendering vars
midiHash=""
beatHash=""
eventsHash=""
trackSpeed=1.85
inst=1 -- Guitar 3x2 (GHL)
diff=4 -- Expert
pR={
{{58,64}}, -- Normal notes = Easy
{{70,76}}, -- Normal notes = Medium
{{82,88}}, -- Normal notes = Hard
{{94,100}} -- Normal notes = Expert
}
-- Rastrea el proyecto actual
local currentProject = reaper.EnumProjects(-1)
-- Variables globales
local notesPlayed = 0 -- Contador de notas que han tocado el recogedor
local totalNotes = 0 -- Total de notas en la canción
local countedNoteTimes = {} -- Tabla para almacenar los tiempos de notas que ya han sido contados
local prevCurBeat = 0 -- Para detectar cambios en el tiempo actual
local lastPlayPosition = 0 -- Para detectar retrocesos en la canción
-- Variables para los botones de interacción
local difficultyButtons = {}
local speedButtons = {}
local offsetButtons = {}
local mouseDown = false
-- Variables para el visualizador de letras
local vocalsTrack = nil
local phrases = {}
local currentPhrase = 1
local phraseMarkerNote = 105 -- Nota MIDI para el marcador de frases
local showLyrics = true -- Controla si se muestra el visualizador de letras
local showNotesHUD = true -- Controla si se muestra el visualizador de líneas de notas
-- Colores para las letras
local textColorInactive = {r = 0.15, g = 0.9, b = 0.0, a = 1.0} -- Verde
local textColorActive = {r = 0.0, g = 1.0, b = 1.0, a = 1.0} -- Azul
local textColorSung = {r = 0.1176471, g = 0.5647059, b = 1.0, a = 1.0} -- Azul claro para letras ya cantadas
local bgColorLyrics = {r = 0.15, g = 0.15, b = 0.25, a = 0.8} -- Fondo para letras
-- Color para la próxima frase (notas con tono)
local textColorNextPhrase = {r = 0.0, g = 1.0, b = 0.5, a = 1.0} -- Verde más claro para próxima frase
-- Color para letras sin tono (marcadas con #)
local textColorToneless = {r = 0.55, g = 0.55, b = 0.55, a = 1.0} -- Gris para letras sin tono
local textColorTonelessActive = {r = 1.0, g = 1.0, b = 1.0, a = 1.0} -- Blanco puro para letras sin tono activas
local textColorTonelessSung = {r = 0.75, g = 0.75, b = 0.75, a = 1.0} -- Blanco puro para letras sin tono ya cantadas
-- Colores en la sección de colores al inicio del script
local textColorHeroPower = {r = 1.0, g = 1.0, b = 0.15, a = 1.0} -- Amarillo para letras con Hero Power
local textColorHeroPowerActive = {r = 1.0, g = 0.5, b = 0.3, a = 1.0} -- Amarillo brillante para letras Hero Power activas
local textColorHeroPowerSung = {r = 0.9764706, g = 0.8999952, b = 0.5372549, a = 1.0} -- Amarillo más oscuro para letras Hero Power ya cantadas
-- Variables configurables para ajustar la posición y tamaño del visualizador de letras
local lyricsConfig = {
height = 110, -- Altura total del visualizador
bottomMargin = 30, -- Margen inferior (negativo = se superpone con el borde)
phraseHeight = 35, -- Altura de cada frase (reducida ligeramente)
phraseSpacing = 1, -- Espacio entre frases
bgOpacity = 0.8, -- Opacidad del fondo (0.0 - 1.0)
fontSize = { -- Tamaños de fuente
current = 24, -- Tamaño para frase actual
next = 22 -- Tamaño para próxima frase
}
}
-- Variables para el visualizador de secciones
local eventsTrack = nil
local sections = {}
local currentSection = 1
local eventsHash = "" -- Detecta cambios en la pista EVENTS
local showSections = true -- Controla si se muestra el visualizador de secciones
local sectionDisplayConfig = {
width = 150, -- Ancho del recuadro de sección
height = 40, -- Altura del recuadro
xOffset = 20, -- Posición X desde el borde izquierdo
yOffset = -40, -- Posición Y; -40 pixeles por encima del borde superior del HUD vocal
fontSize = 20, -- Tamaño de la fuente
fadeTime = 2.0, -- Tiempo en segundos antes de la siguiente sección para empezar a desvanecer
bgColor = {r = 0.15, g = 0.15, b = 0.25, a = 0.9}, -- Color de fondo
textColor = {r = 0.9, g = 0.9, b = 1.0, a = 1.0} -- Color del texto
}
-- Detecta cambios en la pista de voces
local vocalsHash = ""
-- Rastrea el tiempo anterior
local lastBeatTime = 0
force_strum_marker_expert=102 -- Force Strum marker
force_strum_marker_hard=90 -- Force Strum marker
force_strum_marker_medium=78 -- Force Strum marker
force_strum_marker_easy=66 -- Force Strum marker
hopo_marker_expert=101 -- Hopo marker
hopo_marker_hard=89 -- Hopo marker
hopo_marker_medium=77 -- Hopo marker
hopo_marker_easy=65 -- Hopo marker
HP=116 -- Hero Power note
offset=0.0
notes={}
beatLines={}
eventsData={}
trackRange={0,0}
curBeat=0
curBeatLine=1
curEvent=1
curNote=1
nxoff=178 -- X offset
nxm=0.15 -- X mult of offset
nyoff=150.5 -- Y offset
nsm=0.046 -- Scale multiplier
lastCursorTime=reaper.TimeMap2_timeToQN(reaper.EnumProjects(-1),reaper.GetCursorPosition())
showHelp=false
local function rgb2num(r, g, b)
g = g * 256
b = b * 256 * 256
return r + g + b
end
function toFractionString(number)
if number<1 then
return string.format('1/%d', math.floor(1/number))
else
return string.format('%d',number)
end
end
-- Esto soluciona el "-0.00" en el botón del Offset
function formatNumber(number, precision)
-- Si el número está muy cerca de cero
if math.abs(number) < 0.005 then
return string.format("%."..precision.."f", 0)
else
return string.format("%."..precision.."f", number)
end
end
function getNoteIndex(time, lane)
for i, note in ipairs(notes) do
if note[1] == time and note[3] == lane then
return i
end
end
return -1
end
function findTrack(trackName)
local numTracks = reaper.CountTracks(0)
for i = 0, numTracks - 1 do
local track = reaper.GetTrack(0, i)
local _, currentTrackName = reaper.GetSetMediaTrackInfo_String(track, "P_NAME", "", false)
if currentTrackName == trackName then
return track
end
end
return nil
end
-- Función para dibujar los botones de dificultad
function drawDifficultyButtons()
local buttonWidth = 80
local buttonHeight = 30
local startX = gfx.w - (buttonWidth * 4 + 15) -- posición inicial X
local startY = 5 -- Posición Y
local spacing = 5 -- Espacio entre botones
difficultyButtons = {} -- reinicia la tabla de botones
for i = 1, 4 do
local x = startX + (i-1) * (buttonWidth + spacing)
local y = startY
local isSelected = (i == diff)
-- Guarda información del botón para detección de clics
difficultyButtons[i] = {x = x, y = y, width = buttonWidth, height = buttonHeight}
-- Dibuja el fondo del botón
if isSelected then
gfx.r, gfx.g, gfx.b = 0.3, 0.7, 1.0 -- Color para botón seleccionado
else
gfx.r, gfx.g, gfx.b = 0.2, 0.2, 0.3 -- Color para botones no seleccionados
end
gfx.rect(x, y, buttonWidth, buttonHeight, 1) -- Dibuja el fondo
-- Dibuja el borde
gfx.r, gfx.g, gfx.b = 0.8, 0.8, 0.9
gfx.rect(x, y, buttonWidth, buttonHeight, 0) -- Dibuja el borde
-- Dibuja el texto
gfx.r, gfx.g, gfx.b = 1, 1, 1
gfx.setfont(1, "SDK_JP_Web 85W", 18) -- Genshin Impact font
local textW, textH = gfx.measurestr(diffNames[i])
local textX = x + (buttonWidth - textW) / 2
local textY = y + (buttonHeight - textH) / 2
gfx.x, gfx.y = textX, textY
gfx.drawstr(diffNames[i])
end
end
-- Variables globales para rastrear qué botones están siendo presionados
local activeButtons = {
speed = {left = false, right = false},
offset = {left = false, right = false}
}
-- Función mejorada para dibujar flechas de alta calidad
local function drawHDArrow(x, y, isLeftArrow, radius, isActive)
-- Guardar estado original
local orig_a = gfx.a
-- Color base de la flecha según estado
if isActive then
gfx.r, gfx.g, gfx.b = 1, 1, 0.7 -- Flecha amarilla brillante cuando está presionada
else
gfx.r, gfx.g, gfx.b = 1, 1, 1 -- Flecha blanca normal
end
-- Escala y dimensiones
local arrowWidth = radius * 0.6
local arrowLength = radius * 0.9
-- Coordenadas base para la flecha
local points = {}
if isLeftArrow then
-- Punta de la flecha a la izquierda
points = {
{x - arrowLength * 0.6, y}, -- Punta
{x + arrowLength * 0.4, y - arrowWidth}, -- Esquina superior derecha
{x + arrowLength * 0.2, y - arrowWidth * 0.5}, -- Punto de control superior
{x + arrowLength * 0.2, y + arrowWidth * 0.5}, -- Punto de control inferior
{x + arrowLength * 0.4, y + arrowWidth} -- Esquina inferior derecha
}
else
-- Punta de la flecha a la derecha
points = {
{x + arrowLength * 0.6, y}, -- Punta
{x - arrowLength * 0.4, y - arrowWidth}, -- Esquina superior izquierda
{x - arrowLength * 0.2, y - arrowWidth * 0.5}, -- Punto de control superior
{x - arrowLength * 0.2, y + arrowWidth * 0.5}, -- Punto de control inferior
{x - arrowLength * 0.4, y + arrowWidth} -- Esquina inferior izquierda
}
end
-- Técnica multi-paso para crear una flecha suave
-- 1. Dibujar el cuerpo principal de la flecha con antialiasing
gfx.a = 1.0 -- Opacidad completa para el cuerpo principal
gfx.triangle(points[1][1], points[1][2],
points[2][1], points[2][2],
points[5][1], points[5][2], 1) -- Triángulo principal con fill
-- 2. Dibujar los bordes con líneas más finas para suavizar
gfx.a = 0.8
-- Línea de punta a esquina superior
gfx.line(points[1][1], points[1][2], points[2][1], points[2][2], 0.5)
-- Línea de punta a esquina inferior
gfx.line(points[1][1], points[1][2], points[5][1], points[5][2], 0.5)
-- Línea de base (conectando las esquinas)
gfx.line(points[2][1], points[2][2], points[5][1], points[5][2], 0.5)
-- 3. Añadir resalte para dar efecto 3D
gfx.a = 0.4
if isLeftArrow then
gfx.line(points[1][1] + 1, points[1][2] - 1, points[2][1] - 1, points[2][2] + 1, 0.5)
else
gfx.line(points[1][1] - 1, points[1][2] - 1, points[2][1] + 1, points[2][2] + 1, 0.5)
end
-- 4. Añadir brillo adicional en el borde de ataque
if isActive then
gfx.a = 0.5
gfx.r, gfx.g, gfx.b = 1, 1, 0.5
if isLeftArrow then
gfx.line(points[1][1], points[1][2] - 1, points[1][1], points[1][2] + 1, 1)
else
gfx.line(points[1][1], points[1][2] - 1, points[1][1], points[1][2] + 1, 1)
end
end
-- Restaurar opacidad original
gfx.a = orig_a
end
-- Función para dibujar los controles de Highway Speed con botones circulares mejorados
function drawSpeedControls()
local buttonRadius = 12 -- Radio del círculo
local spacing = 5
local textStartX = 12
local speedTextY = 113 -- Posición Y
local leftButtonX = 145 -- Posición X del primer botón
local rightButtonX = leftButtonX + (buttonRadius * 2) + spacing
speedButtons = {}
-- Highway Speed (texto)
gfx.r, gfx.g, gfx.b = 0.77, 0.81, 0.96
gfx.setfont(1, "SDK_JP_Web 85W", 25) -- Genshin Impact font
gfx.x, gfx.y = textStartX, speedTextY
gfx.drawstr("Speed: " .. formatNumber(trackSpeed, 2))
-- Función auxiliar para dibujar un botón circular con flecha HD
local function drawCircleButton(x, y, isLeftArrow, isActive)
-- Fondo del círculo (más brillante si está activo)
if isActive then
gfx.r, gfx.g, gfx.b = 0.3, 0.5, 0.7 -- Color azul cuando está presionado
else
gfx.r, gfx.g, gfx.b = 0.2, 0.2, 0.3 -- Color normal
end
gfx.circle(x, y, buttonRadius, 1)
-- Borde del círculo
gfx.r, gfx.g, gfx.b = 0.8, 0.8, 0.9
gfx.circle(x, y, buttonRadius, 0)
-- Dibujar la flecha HD
drawHDArrow(x, y, isLeftArrow, buttonRadius, isActive)
-- Efecto de brillo adicional cuando está activo
if isActive then
-- Guardar la opacidad actual
local orig_a = gfx.a
-- Establecer opacidad para el halo
gfx.a = 0.3 -- Semi-transparente
gfx.r, gfx.g, gfx.b = 1, 1, 0.5
gfx.circle(x, y, buttonRadius * 1.2, 0) -- Halo exterior
-- Restaurar la opacidad original
gfx.a = orig_a
end
end
-- Dibujar botón para disminuir (izquierda) con estado activo
drawCircleButton(leftButtonX + buttonRadius, speedTextY + buttonRadius, true, activeButtons.speed.left)
-- Dibujar botón para aumentar (derecha) con estado activo
drawCircleButton(rightButtonX + buttonRadius, speedTextY + buttonRadius, false, activeButtons.speed.right)
-- Guardar las coordenadas para la detección de clics
speedButtons[1] = {
x = leftButtonX,
y = speedTextY,
width = buttonRadius * 2,
height = buttonRadius * 2,
action = "decrease",
centerX = leftButtonX + buttonRadius,
centerY = speedTextY + buttonRadius,
radius = buttonRadius
}
speedButtons[2] = {
x = rightButtonX,
y = speedTextY,
width = buttonRadius * 2,
height = buttonRadius * 2,
action = "increase",
centerX = rightButtonX + buttonRadius,
centerY = speedTextY + buttonRadius,
radius = buttonRadius
}
end
-- Función para dibujar los controles de Offset con botones circulares mejorados
function drawOffsetControls()
local buttonRadius = 12 -- Radio del círculo
local spacing = 5
local textStartX = 12
local offsetTextY = 140 -- Ajustado para estar debajo de Speed
local leftButtonX = 160 -- Posición X del primer botón
local rightButtonX = leftButtonX + (buttonRadius * 2) + spacing
offsetButtons = {}
-- Offset (texto)
gfx.r, gfx.g, gfx.b = 0.77, 0.81, 0.96
gfx.setfont(1, "SDK_JP_Web 85W", 25) -- Genshin Impact font
gfx.x, gfx.y = textStartX, offsetTextY
gfx.drawstr("Offset: " .. formatNumber(offset, 2))
-- Función auxiliar para dibujar un botón circular con flecha HD
local function drawCircleButton(x, y, isLeftArrow, isActive)
-- Fondo del círculo (más brillante si está activo)
if isActive then
gfx.r, gfx.g, gfx.b = 0.3, 0.5, 0.7 -- Color azul cuando está presionado
else
gfx.r, gfx.g, gfx.b = 0.2, 0.2, 0.3 -- Color normal
end
gfx.circle(x, y, buttonRadius, 1)
-- Borde del círculo
gfx.r, gfx.g, gfx.b = 0.8, 0.8, 0.9
gfx.circle(x, y, buttonRadius, 0)
-- Dibujar la flecha HD
drawHDArrow(x, y, isLeftArrow, buttonRadius, isActive)
-- Efecto de brillo adicional cuando está activo
if isActive then
-- Guardar la opacidad actual
local orig_a = gfx.a
-- Establecer opacidad para el halo
gfx.a = 0.3 -- Semi-transparente
gfx.r, gfx.g, gfx.b = 1, 1, 0.5
gfx.circle(x, y, buttonRadius * 1.2, 0) -- Halo exterior
-- Restaurar la opacidad original
gfx.a = orig_a
end
end
-- Dibujar botón para disminuir (izquierda) con estado activo
drawCircleButton(leftButtonX + buttonRadius, offsetTextY + buttonRadius, true, activeButtons.offset.left)
-- Dibujar botón para aumentar (derecha) con estado activo
drawCircleButton(rightButtonX + buttonRadius, offsetTextY + buttonRadius, false, activeButtons.offset.right)
-- Guardar las coordenadas para la detección de clics
offsetButtons[1] = {
x = leftButtonX,
y = offsetTextY,
width = buttonRadius * 2,
height = buttonRadius * 2,
action = "decrease",
centerX = leftButtonX + buttonRadius,
centerY = offsetTextY + buttonRadius,
radius = buttonRadius
}
offsetButtons[2] = {
x = rightButtonX,
y = offsetTextY,
width = buttonRadius * 2,
height = buttonRadius * 2,
action = "increase",
centerX = rightButtonX + buttonRadius,
centerY = offsetTextY + buttonRadius,
radius = buttonRadius
}
end
-- No olvides incluir la función para detectar clics en círculos
function isPointInCircle(x, y, button)
local dx = x - button.centerX
local dy = y - button.centerY
return (dx*dx + dy*dy) <= (button.radius * button.radius)
end
-- Función para dibujar un botón para activar/desactivar letras
function drawLyricsToggleButton()
local buttonWidth = 120
local buttonHeight = 30
local x = 12
local y = 175 -- Posicionado debajo de los controles de offset
-- Dibuja el fondo del botón
if showLyrics then
gfx.r, gfx.g, gfx.b = 0.3, 0.7, 1.0 -- Color azul claro para activado
else
gfx.r, gfx.g, gfx.b = 0.2, 0.2, 0.3 -- Color gris oscuro para desactivado
end
gfx.rect(x, y, buttonWidth, buttonHeight, 1) -- dibuja el fondo
-- Dibuja el borde
gfx.r, gfx.g, gfx.b = 0.8, 0.8, 0.9
gfx.rect(x, y, buttonWidth, buttonHeight, 0) -- dibuja el borde
-- Dibuja el texto
gfx.r, gfx.g, gfx.b = 1, 1, 1
gfx.setfont(1, "SDK_JP_Web 85W", 18) -- Genshin Impact font
local buttonText = showLyrics and "Lyrics: ON" or "Lyrics: OFF"
local textW, textH = gfx.measurestr(buttonText)
local textX = x + (buttonWidth - textW) / 2
local textY = y + (buttonHeight - textH) / 2
gfx.x, gfx.y = textX, textY
gfx.drawstr(buttonText)
-- Guarda información del botón para detección de clics
return {x = x, y = y, width = buttonWidth, height = buttonHeight}
end
-- Función para dibujar un botón para activar/desactivar el HUD de notas
function drawNotesHUDToggleButton()
local buttonWidth = 120
local buttonHeight = 30
local x = 12
local y = 215 -- Posicionado debajo del botón de Lyrics
-- Dibuja el fondo del botón
if showNotesHUD then
gfx.r, gfx.g, gfx.b = 0.3, 0.7, 1.0 -- Color azul claro para activado
else
gfx.r, gfx.g, gfx.b = 0.2, 0.2, 0.3 -- Color gris oscuro para desactivado
end
gfx.rect(x, y, buttonWidth, buttonHeight, 1) -- dibuja el fondo
-- Dibuja el borde
gfx.r, gfx.g, gfx.b = 0.8, 0.8, 0.9
gfx.rect(x, y, buttonWidth, buttonHeight, 0) -- dibuja el borde
-- Dibuja el texto
gfx.r, gfx.g, gfx.b = 1, 1, 1
gfx.setfont(1, "SDK_JP_Web 85W", 18) -- Genshin Impact font
local buttonText = showNotesHUD and "Vocal HUD: ON " or "Vocal HUD: OFF"
local textW, textH = gfx.measurestr(buttonText)
local textX = x + (buttonWidth - textW) / 2
local textY = y + (buttonHeight - textH) / 2
gfx.x, gfx.y = textX, textY
gfx.drawstr(buttonText)
-- Guarda información del botón para detección de clics
return {x = x, y = y, width = buttonWidth, height = buttonHeight}
end
-- Modificar la función handleMouseClick para actualizar los estados activos
function handleMouseClick(x, y)
-- Comprobar botones de dificultad
for i, button in ipairs(difficultyButtons) do
if x >= button.x and x <= button.x + button.width and
y >= button.y and y <= button.y + button.height then
if diff ~= i then
diff = i
midiHash = ""
updateMidi()
end
return true
end
end
-- Comprobar botones de velocidad
for i, button in ipairs(speedButtons) do
if isPointInCircle(x, y, button) then
if button.action == "decrease" then
activeButtons.speed.left = true
if trackSpeed > 0.25 then
trackSpeed = trackSpeed - 0.05
end
elseif button.action == "increase" then
activeButtons.speed.right = true
trackSpeed = trackSpeed + 0.05
end
return true
end
end
-- Comprobar botones de offset
for i, button in ipairs(offsetButtons) do
if isPointInCircle(x, y, button) then
if button.action == "decrease" then
activeButtons.offset.left = true
offset = offset - 0.01
elseif button.action == "increase" then
activeButtons.offset.right = true
offset = offset + 0.01
end
return true
end
end
-- Comprobar botón de lyrics
local lyricsButton = drawLyricsToggleButton()
if x >= lyricsButton.x and x <= lyricsButton.x + lyricsButton.width and
y >= lyricsButton.y and y <= lyricsButton.y + lyricsButton.height then
showLyrics = not showLyrics
if showLyrics and #phrases == 0 then
parseVocals()
end
return true
end
-- Comprobar botón de Notes HUD
local notesHUDButton = drawNotesHUDToggleButton()
if x >= notesHUDButton.x and x <= notesHUDButton.x + notesHUDButton.width and
y >= notesHUDButton.y and y <= notesHUDButton.y + notesHUDButton.height then
showNotesHUD = not showNotesHUD
return true
end
return false
end
-- Añadir función para restablecer estados activos cuando se suelta el clic
function handleMouseRelease()
activeButtons.speed.left = false
activeButtons.speed.right = false
activeButtons.offset.left = false
activeButtons.offset.right = false
end
gfx.clear = rgb2num(35, 38, 52) -- Background color
gfx.init("GHL Preview", 700, 700, 0, 1211, 43) -- Alto, Ancho, Eje X, Eje Y
local script_folder = string.gsub(debug.getinfo(1).source:match("@?(.*[\\|/])"),"\\","/")
highway = gfx.loadimg(1,script_folder.."assets/highway.png")
white_note = gfx.loadimg(7, script_folder.."assets/white_note.png")
black_note = gfx.loadimg(8, script_folder.."assets/black_note.png")
square_note = gfx.loadimg(9, script_folder.."assets/square_note.png") -- (nota de acorde de cejilla)
open_note = gfx.loadimg(10, script_folder.."assets/open_note.png")
white_hopo_notee = gfx.loadimg(11, script_folder.."assets/white_note_hopo.png")
black_hopo_notee = gfx.loadimg(12, script_folder.."assets/black_note_hopo.png")
square_hopo_notee = gfx.loadimg(13, script_folder.."assets/square_note_hopo.png")
hero_icon = gfx.loadimg(14, script_folder.."assets/hero_icon.png")
open_note_herocollect = gfx.loadimg(15, script_folder.."assets/open_note_herocollect.png")
instrumentTracks={
{"Guitar 3x2",findTrack("PART GUITAR GHL")}
}
function parseNotes(take)
notes = {}
heropower_phrases = {}
hopomark_expert = {}
hopomark_hard = {}
hopomark_medium = {}
hopomark_easy = {}
force_strum_markers_expert = {}
force_strum_markers_hard = {}
force_strum_markers_medium = {}
force_strum_markers_easy = {}
_, notecount = reaper.MIDI_CountEvts(take)
-- Margen pequeño para evitar conflictos en los límites
local MARGIN = 0.001 -- Ajusta este valor según necesites
-- Primera pasada: Recopilar todos los marcadores y notas
for i = 0, notecount - 1 do
_, _, _, spos, epos, _, pitch, _ = reaper.MIDI_GetNote(take, i)
ntime = reaper.MIDI_GetProjQNFromPPQPos(take, spos)
nend = reaper.MIDI_GetProjQNFromPPQPos(take, epos)
if pitch == hopo_marker_expert then
-- Añadir marcador con margen pequeño al final
table.insert(hopomark_expert, {ntime, nend - MARGIN}) -- Hopo marker (Expert)
elseif pitch == hopo_marker_hard then
table.insert(hopomark_hard, {ntime, nend - MARGIN}) -- Hopo marker (Hard)
elseif pitch == hopo_marker_medium then
table.insert(hopomark_medium, {ntime, nend - MARGIN}) -- Hopo marker (Medium)
elseif pitch == hopo_marker_easy then
table.insert(hopomark_easy, {ntime, nend - MARGIN}) -- Hopo marker (Easy)
elseif pitch == force_strum_marker_expert then
table.insert(force_strum_markers_expert, {ntime, nend - MARGIN}) -- Force Strum (Expert)
elseif pitch == force_strum_marker_hard then
table.insert(force_strum_markers_hard, {ntime, nend - MARGIN}) -- Force Strum (Hard)
elseif pitch == force_strum_marker_medium then
table.insert(force_strum_markers_medium, {ntime, nend - MARGIN}) -- Force Strum (Medium)
elseif pitch == force_strum_marker_easy then
table.insert(force_strum_markers_easy, {ntime, nend - MARGIN}) -- Force Strum (Easy)
elseif pitch == HP then
table.insert(heropower_phrases, {ntime, nend - MARGIN}) -- Hero Power marker
elseif pitch >= pR[diff][1][1] and pitch <= pR[diff][1][2] then
lane = pitch - pR[diff][1][1]
noteIndex = getNoteIndex(ntime, lane)
if noteIndex ~= -1 then
notes[noteIndex][2] = nend - ntime
else
-- Inicializar nota con valores por defecto
-- (tiempo, duración, carril, sustain, square, heropower, hopo)
table.insert(notes, {ntime, nend - ntime, lane, false, false, false, false})
end
end
end
-- Detectar acordes de cejilla (notas square)
local function isWhite(lane)
return lane >= 1 and lane <= 3
end
local function isBlack(lane)
return lane >= 4 and lane <= 6
end
local function isChordOfFret1(lane1, lane2)
return (lane1 == 1 and lane2 == 4) or (lane1 == 4 and lane2 == 1)
end
local function isChordOfFret2(lane1, lane2)
return (lane1 == 2 and lane2 == 5) or (lane1 == 5 and lane2 == 2)
end
local function isChordOfFret3(lane1, lane2)
return (lane1 == 3 and lane2 == 6) or (lane1 == 6 and lane2 == 3)
end
for i = 1, #notes do
for j = i + 1, #notes do
if notes[i][1] == notes[j][1] and notes[i][3] ~= notes[j][3] then
local lane1, lane2 = notes[i][3], notes[j][3]
if isWhite(lane1) and isBlack(lane2) or isWhite(lane2) and isBlack(lane1) then
if isChordOfFret1(lane1, lane2) or isChordOfFret2(lane1, lane2) or isChordOfFret3(lane1, lane2) then
notes[i][5] = true
notes[j][5] = true
end
end
end
end
end
-- Identificar el estado de notas Hero Power
if #heropower_phrases > 0 then
for i = 1, #notes do
local noteTime = notes[i][1]
for j = 1, #heropower_phrases do
local markerStart = heropower_phrases[j][1]
local markerEnd = heropower_phrases[j][2]
if noteTime >= markerStart and noteTime <= markerEnd then
notes[i][6] = true -- Marcar como Hero Power
break
end
end
end
end
-- Seleccionar los marcadores para la dificultad actual
local force_strum_markers = {}
local hopo_markers = {}
if diff == 4 then -- Expert
force_strum_markers = force_strum_markers_expert
hopo_markers = hopomark_expert
elseif diff == 3 then -- Hard
force_strum_markers = force_strum_markers_hard
hopo_markers = hopomark_hard
elseif diff == 2 then -- Medium
force_strum_markers = force_strum_markers_medium
hopo_markers = hopomark_medium
elseif diff == 1 then -- Easy
force_strum_markers = force_strum_markers_easy
hopo_markers = hopomark_easy
end
-- Para cada nota:
-- 1. Verificar si está bajo algún marcador Force Strum
-- 2. Si no, verificar si está bajo algún marcador HOPO
for i = 1, #notes do
local noteTime = notes[i][1]
local isForceStrum = false
local isHopo = false
-- Primero revisar si está bajo Force Strum
for _, marker in ipairs(force_strum_markers) do
local markerStart = marker[1]
local markerEnd = marker[2]
if noteTime >= markerStart and noteTime <= markerEnd then
isForceStrum = true
break
end
end
-- Si no es Force Strum, revisar si es HOPO
if not isForceStrum then
for _, marker in ipairs(hopo_markers) do
local markerStart = marker[1]
local markerEnd = marker[2]
if noteTime >= markerStart and noteTime <= markerEnd then
isHopo = true
break
end
end
end
-- Establecer el estado final de la nota
notes[i][7] = isHopo
end
-- Ordenar las notas para garantizar visualización correcta
table.sort(notes, function(a, b) return a[1] < b[1] end)
end
function updateMidi()
instrumentTracks={
{"Guitar 3x2", findTrack("PART GUITAR GHL")}
}
if instrumentTracks[inst][2] then
local numItems = reaper.CountTrackMediaItems(instrumentTracks[inst][2])
for i = 0, numItems-1 do
local item = reaper.GetTrackMediaItem(instrumentTracks[inst][2], i)
local take = reaper.GetActiveTake(item)
local _,hash=reaper.MIDI_GetHash(take,true)
if midiHash~=hash then
parseNotes(take)
curNote=1
for i=1,#notes do
curNote=i
if notes[i][1]+notes[i][2]>=curBeat then
break
end
end
-- Resetear los contadores cuando cambia el MIDI
notesPlayed = 0
totalNotes = 0
countedNoteTimes = {}
prevCurBeat = 0
lastPlayPosition = curBeat
midiHash=hash
end
end
else
midiHash=""
notes={}
-- Resetear los contadores cuando no hay MIDI
notesPlayed = 0
totalNotes = 0
countedNoteTimes = {}
prevCurBeat = 0
lastPlayPosition = 0
end
end
-- Función para reiniciar el estado cuando cambia el proyecto
function resetState()
-- Reiniciar variables de tracks
vocalsTrack = nil
instrumentTracks = {
{"Guitar 3x2", nil}
}
-- Reiniciar variables de datos
midiHash = ""
vocalsHash = ""
notes = {}
phrases = {}
beatLines = {}
eventsTrack = nil
sections = {}
currentSection = 1
eventsHash = ""
-- Reiniciar estados
curNote = 1
curBeatLine = 1
currentPhrase = 1
-- También reiniciar estas variables específicas de letras
lastBeatTime = 0
-- Reinicializar rango del proyecto si hay un proyecto abierto
if isProjectOpen() then
trackRange = {
reaper.TimeMap2_timeToQN(0, 0),
reaper.TimeMap2_timeToQN(0, reaper.GetProjectLength(0))
}
else
trackRange = {0, 0}
end
end
-- Función de seguridad para comprobar si una pista sigue siendo válida
function isTrackValid(track)
if track == nil then return false end
-- Uso de pcall para capturar errores al intentar acceder a la pista
local success, _ = pcall(function()
reaper.GetTrackGUID(track)
end)
return success
end
-- Función para comprobar si hay algún proyecto abierto
function isProjectOpen()
local proj = reaper.EnumProjects(-1)
return proj ~= nil
end
-- Función para verificar si la pista PART VOCALS sigue siendo válida
function checkVocalsTrack()
-- Si la pista PART VOCALS no está definida o no es válida, se resetea
if not vocalsTrack or not isTrackValid(vocalsTrack) then
vocalsTrack = nil
return false
end
return true
end
-- Estructura para una frase de letras
function createPhrase(startTime, endTime)
return {
startTime = startTime,
endTime = endTime,
lyrics = {},
currentLyric = 1
}
end
-- Función completa createLyric con soporte para Hero Power
function createLyric(text, startTime, endTime, pitch, hasHeroPower)
-- Procesar el texto
local processedText = text
local originalText = text -- Guardar el texto original para referencia
-- Detectar si es una letra sin tono (#)
local hasTonelessMarker = processedText:match("#") ~= nil or processedText:match("%^") ~= nil
-- Análisis de conectores en el texto ORIGINAL
-- Buscar todos los posibles patrones de conector al final
local connectsWithNext = false
if originalText:match("%-$") or originalText:match("%+$") or originalText:match("=$") or
originalText:match("%-#$") or originalText:match("%+#$") or originalText:match("=#$") or
originalText:match("%-%^$") or originalText:match("=^$") then
connectsWithNext = true
end
-- Buscar todos los posibles patrones de conector al principio
local connectsWithPrevious = false
if originalText:match("^%-") or originalText:match("^%+") or originalText:match("^=") or
originalText:match("^%-#") or originalText:match("^%+#") or originalText:match("^=#") then
connectsWithPrevious = true
end
-- Busca patrones específicos para tratamiento especial
-- Detectar signos = (que serán visibles como -)
local hasVisibleEquals = processedText:match("=") ~= nil
-- Guardar posiciones donde hay signos = (para no eliminarlos después)
local equalsPositions = {}
local i = 1
while true do
i = string.find(processedText, "=", i)
if i == nil then break end
equalsPositions[i] = true
i = i + 1
end
-- Procesamiento del texto para visualización
-- Convertir = a - (estos guiones serán visibles)
processedText = processedText:gsub("=", "-")
-- Convertir =^ a -
-- processedText = processedText:gsub("=^", "-")
-- Eliminar todos los marcadores #
processedText = processedText:gsub("#", "")
-- Eliminar todos los marcadores ^
processedText = processedText:gsub("%^", "")
-- Eliminar todos los marcadores §
processedText = processedText:gsub("%§", "_")
-- Eliminar todos los símbolos +
processedText = processedText:gsub("%+", "")
-- Eliminar el nombre de la pista
processedText = processedText:gsub("PART VOCALS", "")
-- Eliminar el nombre del charter de la pista
processedText = processedText:gsub("GHCripto", "") -- Omite el evento de texto de Copyright (de quien hizo el chart Vocal)
-- Eliminar todo el texto entre corchetes, incluyendo los corchetes
processedText = processedText:gsub("%[.-%]", "")
-- Eliminar guiones originales (que no eran =)
-- Hacer esto carácter por carácter para preservar los guiones que eran =
local result = ""
for j = 1, #processedText do
local char = processedText:sub(j, j)
if char == "-" and not equalsPositions[j] then
-- Omitir guiones originales
else
result = result .. char
end
end
processedText = result
-- Elimina espacios extras que pudieran quedar después de eliminar el texto entre corchetes
processedText = processedText:gsub("^%s+", ""):gsub("%s+$", ""):gsub("%s+", " ")