-
Notifications
You must be signed in to change notification settings - Fork 12
/
channel.py
1324 lines (1005 loc) · 35.6 KB
/
channel.py
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
# PyFLP - An FL Studio project file (.flp) parser
# Copyright (C) 2022 demberto
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version. This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details. You should have received a copy of the
# GNU General Public License along with this program. If not, see
# <https://www.gnu.org/licenses/>.
"""Contains the types used by the channels and channel rack."""
from __future__ import annotations
import collections
import enum
import pathlib
import sys
from typing import DefaultDict, List, Tuple, cast
if sys.version_info >= (3, 8):
from typing import Final, SupportsIndex
else:
from typing_extensions import Final, SupportsIndex
if sys.version_info >= (3, 9):
from collections.abc import Iterator, Sequence
else:
from typing import Sequence, Iterator
import colour
from ._descriptors import EventProp, FlagProp, KWProp, NestedProp, StructProp
from ._events import (
DATA,
DWORD,
TEXT,
WORD,
AnyEvent,
BoolEvent,
EventEnum,
F32Event,
I8Event,
I32Event,
StructBase,
StructEventBase,
U8Event,
U16Event,
U16TupleEvent,
U32Event,
)
from ._models import ModelReprMixin, MultiEventModel, SingleEventModel
from .controller import RemoteController
from .exceptions import ModelNotFound, NoModelsFound, PropertyCannotBeSet
from .plugin import (
BooBass,
BooBassEvent,
PluginID,
PluginProp,
VSTPlugin,
VSTPluginEvent,
)
__all__ = [
"ArpDirection",
"Automation",
"Channel",
"Instrument",
"Layer",
"ChannelRack",
"ChannelNotFound",
"DeclickMode",
"LFOShape",
"ReverbType",
"FX",
"Reverb",
"Delay",
"Envelope",
"LFO",
"Tracking",
"Keyboard",
"LevelAdjusts",
"StretchMode",
"Time",
"TimeStretching",
"Polyphony",
"Playback",
"ChannelType",
]
class ChannelNotFound(ModelNotFound, KeyError):
pass
class _DelayStruct(StructBase):
PROPS = dict.fromkeys(("feedback", "pan", "pitch_shift", "echoes", "time"), "i")
class _EnvelopeLFOStruct(StructBase): # 2.5.0+
PROPS = {
"flags": "i", # 4
"envelope.enabled": "i", # 8
"envelope.predelay": "i", # 12
"envelope.attack": "i", # 16
"envelope.hold": "i", # 20
"envelope.decay": "i", # 24
"envelope.sustain": "i", # 28
"envelope.release": "i", # 32
"_u20": 20, # 52
"lfo.shape": "i", # 56
"envelope.attack_tension": "i", # 60
"envelope.sustain_tension": "i", # 64
"envelope.release_tension": "i", # 68
}
class _LevelAdjustsStruct(StructBase):
PROPS = {"pan": "I", "volume": "I", "_u4": 4, "mod_x": "I", "mod_y": "I"}
class _LevelsStruct(StructBase):
PROPS = {"pan": "I", "volume": "I", "pitch_shift": "I", "_u12": 12}
class _ParametersStruct(StructBase):
PROPS = {
"_u40": 40, # 40
"arp.direction": "I", # 44
"arp.range": "I", # 48
"arp.chord": "I", # 52
"arp.time": "f", # 56
"arp.gate": "f", # 60
"arp.slide": "bool", # 61
"_u22": 22, # 83
"content.declick_mode": "B", # 84
"_u8": 8, # 92
"arp.repeat": "I", # 96 4.5.2+
"_u12": 12, # 108
"stretching.mode": "i", # 112
"_u38": 36, # 148
"playback.start_offset": "I", # 152
"_u6": 6, # 158
}
class _PolyphonyStruct(StructBase):
PROPS = {"max": "I", "slide": "I", "flags": "B"}
class _TrackingStruct(StructBase):
PROPS = {"middle_value": "i", "pan": "i", "mod_x": "i", "mod_y": "i"}
class DelayEvent(StructEventBase):
STRUCT = _DelayStruct
class EnvelopeLFOEvent(StructEventBase):
STRUCT = _EnvelopeLFOStruct
class LevelAdjustsEvent(StructEventBase):
STRUCT = _LevelAdjustsStruct
class LevelsEvent(StructEventBase):
STRUCT = _LevelsStruct
class ParametersEvent(StructEventBase):
STRUCT = _ParametersStruct
class PolyphonyEvent(StructEventBase):
STRUCT = _PolyphonyStruct
class TrackingEvent(StructEventBase):
STRUCT = _TrackingStruct
@enum.unique
class ChannelID(EventEnum):
IsEnabled = (0, BoolEvent)
_VolByte = (2, U8Event)
_PanByte = (3, U8Event)
Zipped = (15, BoolEvent)
# _19 = (19, BoolEvent)
PingPongLoop = (20, BoolEvent)
Type = (21, U8Event)
RoutedTo = (22, I8Event)
# FXProperties = 27
IsLocked = (32, BoolEvent) #: 12.3+
New = (WORD, U16Event)
FreqTilt = (WORD + 5, U16Event)
FXFlags = (WORD + 6, U16Event)
Cutoff = (WORD + 7, U16Event)
_VolWord = (WORD + 8, U16Event)
_PanWord = (WORD + 9, U16Event)
Preamp = (WORD + 10, U16Event) #: 1.2.12+
FadeOut = (WORD + 11, U16Event) #: 1.7.6+
FadeIn = (WORD + 12, U16Event)
# DotNote = WORD + 13
# DotPitch = WORD + 14
# DotMix = WORD + 15
Resonance = (WORD + 19, U16Event)
# _LoopBar = WORD + 20
StereoDelay = (WORD + 21, U16Event) #: 1.3.56+
Pogo = (WORD + 22, U16Event)
# DotReso = WORD + 23
# DotCutOff = WORD + 24
# ShiftDelay = WORD + 25
# Dot = WORD + 27
# DotRel = WORD + 32
# DotShift = WORD + 28
Children = (WORD + 30, U16Event) #: 3.4.0+
Swing = (WORD + 33, U16Event)
# Echo = DWORD + 2
RingMod = (DWORD + 3, U16TupleEvent)
CutGroup = (DWORD + 4, U16TupleEvent)
RootNote = (DWORD + 7, U32Event)
# _MainResoCutOff = DWORD + 9
# DelayModXY = DWORD + 10
Reverb = (DWORD + 11, U32Event) #: 1.4.0+
StretchTime = (DWORD + 12, F32Event) #: 5.0+
FineTune = (DWORD + 14, I32Event)
SamplerFlags = (DWORD + 15, U32Event)
LayerFlags = (DWORD + 16, U32Event)
GroupNum = (DWORD + 17, I32Event)
AUSampleRate = (DWORD + 25, U32Event)
_Name = TEXT
SamplePath = TEXT + 4
Delay = (DATA + 1, DelayEvent)
Parameters = (DATA + 7, ParametersEvent)
EnvelopeLFO = (DATA + 10, EnvelopeLFOEvent)
Levels = (DATA + 11, LevelsEvent)
# _Filter = DATA + 12
Polyphony = (DATA + 13, PolyphonyEvent)
Tracking = (DATA + 20, TrackingEvent)
LevelAdjusts = (DATA + 21, LevelAdjustsEvent)
@enum.unique
class DisplayGroupID(EventEnum):
Name = TEXT + 39 #: 3.4.0+
@enum.unique
class RackID(EventEnum):
Swing = (11, U8Event)
_FitToSteps = (13, U8Event)
WindowHeight = (DWORD + 5, U32Event)
@enum.unique
class ArpDirection(enum.IntEnum):
"""Used by :attr:`Arp.direction`."""
Off = 0
Up = 1
Down = 2
UpDownBounce = 3
UpDownSticky = 4
Random = 5
@enum.unique
class _LFOFlags(enum.IntFlag):
TempoSync = 1 << 1
Unknown = 1 << 2 # Occurs for volume envlope only.
Retrig = 1 << 5
@enum.unique
class LFOShape(enum.IntEnum):
"""Used by :attr:`LFO.shape`."""
Sine = 0
Triangle = 1
Pulse = 2
@enum.unique
class _PolyphonyFlags(enum.IntFlag):
None_ = 0
Mono = 1 << 0
Porta = 1 << 1
# Unknown
U1 = 1 << 2
U2 = 1 << 3
U3 = 1 << 4
U4 = 1 << 5
U5 = 1 << 6
U6 = 1 << 7
@enum.unique
class ReverbType(enum.IntEnum):
"""Used by :attr:`Reverb.type`."""
A = 0
B = 65536
# The type of a channel may decide how a certain event is interpreted. An
# example of this is `ChannelID.Levels` event, which is used for storing
# volume, pan and pich bend range of any channel other than automations. In
# automations it is used for **Min** and **Max** knobs.
@enum.unique
class ChannelType(enum.IntEnum): # cuz Type would be a super generic name
"""An internal marker used to indicate the type of a channel."""
Sampler = 0
"""Used exclusively for the inbuilt Sampler."""
Native = 2
"""Used by audio clips and other native FL Studio synths."""
Layer = 3 # 3.4.0+
Instrument = 4
Automation = 5 # 5.0+
class _FXFlags(enum.IntFlag):
FadeStereo = 1 << 0
Reverse = 1 << 1
Clip = 1 << 2
SwapStereo = 1 << 8
class _LayerFlags(enum.IntFlag):
Random = 1 << 0
Crossfade = 1 << 1
class _SamplerFlags(enum.IntFlag):
Resample = 1 << 0
LoadRegions = 1 << 1
LoadSliceMarkers = 1 << 2
UsesLoopPoints = 1 << 3
KeepOnDisk = 1 << 8
@enum.unique
class StretchMode(enum.IntEnum):
Stretch = -1
Resample = 0
E3Generic = 1
E3Mono = 2
SliceStretch = 3
SliceMap = 4
Auto = 5
E2Generic = 6
E2Transient = 7
E2Mono = 8
E2Speech = 9
@enum.unique
class DeclickMode(enum.IntEnum):
OutOnly = 0
TransientNoBleeding = 1
Transient = 2
Generic = 3
Smooth = 4
Crossfade = 5
class DisplayGroup(MultiEventModel, ModelReprMixin):
def __repr__(self):
if self.name is None:
return "Unnamed display group"
return f"Display group {self.name}"
name = EventProp[str](DisplayGroupID.Name)
class Arp(SingleEventModel, ModelReprMixin):
"""Used by :class:`Sampler`: and :class:`Instrument`.
![](https://bit.ly/3Lbk7Yi)
"""
chord = StructProp[int]()
"""Index of the selected arpeggio chord."""
direction = StructProp[ArpDirection]()
gate = StructProp[float]()
"""Delay between two successive notes played."""
range = StructProp[int]()
"""Range (in octaves)."""
repeat = StructProp[int]()
"""Number of times a note is repeated.
*New in FL Studio v4.5.2*.
"""
slide = StructProp[bool]()
"""Whether arpeggio will slide between notes."""
time = StructProp[float]()
"""Delay between two successive notes played."""
class Delay(SingleEventModel, ModelReprMixin):
"""Echo delay / fat mode section.
Used by :class:`Sampler` and :class:`Instrument`.
![](https://bit.ly/3RyzbBD)
"""
# is_fat_mode: Optional[bool] = None #: 3.4.0+
# is_ping_pong: Optional[bool] = None #: 1.7.6+
# mod_x: Optional[int] = None
# mod_y: Optional[int] = None
echoes = StructProp[int]()
"""Number of echoes generated for each note.
| Min | Max |
|-----|-----|
| 1 | 10 |
"""
feedback = StructProp[int]()
"""Factor with which the volume of every next echo is multiplied.
Defaults to minimum value.
| Type | Value | Representation |
|------|-------|----------------|
| Min | 0 | 0% |
| Max | 25600 | 200% |
"""
pan = StructProp[int]()
"""
| Type | Value | Representation |
|---------|-------|----------------|
| Min | -6400 | 100% left |
| Max | 6400 | 100% right |
| Default | 0 | Centred |
"""
pitch_shift = StructProp[int]()
"""Pitch shift (in cents).
| Min | Max | Default |
|-------|-------|---------|
| -1200 | 1200 | 0 |
"""
time = StructProp[int]()
"""Tempo-synced delay time. PPQ dependant.
| Type | Value | Representation |
|---------|-----------|----------------|
| Min | 0 | 0:00 |
| Max | PPQ * 4 | 8:00 |
| Default | PPQ * 3/2 | 3:00 |
"""
class LevelAdjusts(SingleEventModel, ModelReprMixin):
"""Used by :class:`Layer`, :class:`Instrument` and :class:`Sampler`.
![](https://bit.ly/3xkKeGn)
*New in FL Studio v3.3.0*.
"""
mod_x = StructProp[int]()
mod_y = StructProp[int]()
pan = StructProp[int]()
volume = StructProp[int]()
class Time(MultiEventModel, ModelReprMixin):
"""Used by :class:`Sampler` and :class:`Instrument`.
![](https://bit.ly/3xjxUGG)
"""
swing = EventProp[int](ChannelID.Swing)
# gate: int
# shift: int
# is_full_porta: bool
class Reverb(SingleEventModel, ModelReprMixin):
"""Precalculated reverb used by :class:`Sampler`.
![](https://bit.ly/3L9N4nj)
*New in FL Studio v1.4.0*.
"""
@property
def type(self) -> ReverbType | None:
if self._event:
return ReverbType.B if self._event.value >= ReverbType.B else ReverbType.A
@type.setter
def type(self, value: ReverbType):
if self.mix is None:
raise PropertyCannotBeSet(ChannelID.Reverb)
self._event.value = value.value + self.mix
@property
def mix(self) -> int | None:
"""Mix % (wet). Defaults to minimum value.
| Min | Max |
|-----|-----|
| 0 | 256 |
"""
if self._event:
return self._event.value - self.type
@mix.setter
def mix(self, value: int):
if self._event is None:
raise PropertyCannotBeSet(ChannelID.Reverb)
self._event.value += value
class FX(MultiEventModel, ModelReprMixin):
"""Pre-calculated effects used by :class:`Sampler`.
![](https://bit.ly/3U3Ys8l)
![](https://bit.ly/3qvdBSN)
See Also:
:attr:`Sampler.fx`
"""
boost = EventProp[int](ChannelID.Preamp)
"""Pre-amp gain. Defaults to minimum value.
| Min | Max |
|-----|-----|
| 0 | 256 |
*New in FL Studio v1.2.12*.
"""
clip = FlagProp(_FXFlags.Clip, ChannelID.FXFlags)
"""Whether output is clipped at 0dB for :attr:`boost`."""
cutoff = EventProp[int](ChannelID.Cutoff)
"""Filter Mod X. Defaults to maximum value.
| Min | Max |
|-----|------|
| 16 | 1024 |
"""
fade_in = EventProp[int](ChannelID.FadeIn)
"""Quick fade-in. Defaults to minimum value.
| Min | Max |
|-----|------|
| 0 | 1024 |
"""
fade_out = EventProp[int](ChannelID.FadeOut)
"""Quick fade-out. Defaults to minimum value.
| Min | Max |
|-----|------|
| 0 | 1024 |
*New in FL Studio v1.7.6*.
"""
fade_stereo = FlagProp(_FXFlags.FadeStereo, ChannelID.FXFlags)
freq_tilt = EventProp[int](ChannelID.FreqTilt)
"""Shifts the frequency balance. Bi-polar.
| Min | Max | Default |
|-----|-----|---------|
| 0 | 256 | 128 |
"""
pogo = EventProp[int](ChannelID.Pogo)
"""Pitch bend effect. Bipolar.
| Min | Max | Default |
|-----|-----|---------|
| 0 | 512 | 256 |
"""
ringmod = EventProp[Tuple[int, int]](ChannelID.RingMod)
"""Ring modulation returned as a tuple of `(mix, frequency)`.
Limits for both:
| Min | Max | Default |
|-----|-----|---------|
| 0 | 256 | 128 |
"""
resonance = EventProp[int](ChannelID.Resonance)
"""Filter Mod Y. Defaults to minimum value.
| Min | Max |
|-----|------|
| 0 | 640 |
"""
reverb = NestedProp[Reverb](Reverb, ChannelID.Reverb)
reverse = FlagProp(_FXFlags.Reverse, ChannelID.FXFlags)
"""Whether sample is reversed or not."""
stereo_delay = EventProp[int](ChannelID.StereoDelay)
"""
| Min | Max | Default |
|-----|------|---------|
| 0 | 4096 | 2048 |
*New in FL Studio v1.3.56*.
"""
swap_stereo = FlagProp(_FXFlags.SwapStereo, ChannelID.FXFlags)
"""Whether left and right channels are swapped or not."""
class Envelope(SingleEventModel, ModelReprMixin):
"""A PAHDSR envelope for various :class:`Sampler` paramters.
![](https://bit.ly/3d9WCCh)
See Also:
:attr:`Sampler.envelopes`
*New in FL Studio v2.5.0*.
"""
enabled = StructProp[bool](prop="envelope.enabled")
"""Whether envelope section is enabled."""
predelay = StructProp[int](prop="envelope.predelay")
"""Linear. Defaults to minimum value.
| Type | Value | Mix (wet) |
|------|-------|-----------|
| Min | 100 | 0% |
| Max | 65536 | 100% |
"""
attack = StructProp[int](prop="envelope.attack")
"""Linear.
| Type | Value | Mix (wet) |
|---------|-------|-----------|
| Min | 100 | 0% |
| Max | 65536 | 100% |
| Default | 20000 | 31% |
"""
hold = StructProp[int](prop="envelope.hold")
"""Linear.
| Type | Value | Mix (wet) |
|---------|-------|-----------|
| Min | 100 | 0% |
| Max | 65536 | 100% |
| Default | 20000 | 31% |
"""
decay = StructProp[int](prop="envelope.decay")
"""Linear.
| Type | Value | Mix (wet) |
|---------|-------|-----------|
| Min | 100 | 0% |
| Max | 65536 | 100% |
| Default | 30000 | 46% |
"""
sustain = StructProp[int](prop="envelope.sustain")
"""Linear.
| Type | Value | Mix (wet) |
|---------|-------|-----------|
| Min | 0 | 0% |
| Max | 128 | 100% |
| Default | 50 | 39% |
"""
release = StructProp[int](prop="envelope.release")
"""Linear.
| Type | Value | Mix (wet) |
|---------|-------|-----------|
| Min | 100 | 0% |
| Max | 65536 | 100% |
| Default | 20000 | 31% |
"""
attack_tension = StructProp[int](prop="envelope.attack_tension")
"""Linear.
| Type | Value | Mix (wet) |
|---------|-------|-----------|
| Min | -128 | -100% |
| Max | 128 | 100% |
| Default | 0 | 0% |
*New in FL Studio v3.5.4*.
"""
sustain_tension = StructProp[int](prop="envelope.sustain_tension")
"""Linear.
| Type | Value | Mix (wet) |
|---------|-------|-----------|
| Min | -128 | -100% |
| Max | 128 | 100% |
| Default | 0 | 0% |
*New in FL Studio v3.5.4*.
"""
release_tension = StructProp[int](prop="envelope.release_tension")
"""Linear.
| Type | Value | Mix (wet) |
|---------|-------|-----------|
| Min | -128 | -100% |
| Max | 128 | 100% |
| Default | -101 | -79% |
*New in FL Studio v3.5.4*.
"""
class LFO(SingleEventModel, ModelReprMixin):
"""A basic LFO for certain :class:`Sampler` parameters.
![](https://bit.ly/3RG5Jtw)
See Also:
:attr:`Sampler.lfos`
*New in FL Studio v2.5.0*.
"""
# amount: Optional[int] = None
# attack: Optional[int] = None
# predelay: Optional[int] = None
# speed: Optional[int] = None
is_synced = FlagProp(_LFOFlags.TempoSync)
"""Whether LFO is synced with tempo."""
is_retrig = FlagProp(_LFOFlags.Retrig)
"""Whether LFO phase is in global / retriggered mode."""
shape = StructProp[LFOShape](prop="lfo.shape")
"""Sine, triangle or pulse. Default: Sine."""
class Polyphony(SingleEventModel, ModelReprMixin):
"""Used by :class:`Sampler` and :class:`Instrument`.
![](https://bit.ly/3DlvWcl)
"""
is_mono = FlagProp(_PolyphonyFlags.Mono)
"""Whether monophonic mode is enabled or not."""
is_porta = FlagProp(_PolyphonyFlags.Porta)
"""*New in FL Studio v3.3.0*."""
max = StructProp[int]()
"""Max number of voices."""
slide = StructProp[int]()
"""Portamento time.
| Type | Value | Representation |
|---------|-------|-----------------|
| Min | 0 | 0:00 |
| Max | 1660 | 8:00 (8 steps) |
| Default | 820 | 0:12 (1/2 step) |
*New in FL Studio v3.3.0*.
"""
class Tracking(SingleEventModel, ModelReprMixin):
"""Used by :class:`Sampler` and :class:`Instrument`.
![](https://bit.ly/3DmveM8)
*New in FL Studio v3.3.0*.
"""
middle_value = StructProp[int]()
"""Note index. Min: C0 (0), Max: B10 (131)."""
mod_x = StructProp[int]()
"""Bipolar.
| Min | Max | Default |
|------|-----|---------|
| -256 | 256 | 0 |
"""
mod_y = StructProp[int]()
"""Bipolar.
| Min | Max | Default |
|------|-----|---------|
| -256 | 256 | 0 |
"""
pan = StructProp[int]()
"""Bipolar.
| Min | Max | Default |
|------|-----|---------|
| -256 | 256 | 0 |
"""
class Keyboard(MultiEventModel, ModelReprMixin):
"""Used by :class:`Sampler` and :class:`Instrument`.
![](https://bit.ly/3qwIK8r)
*New in FL Studio v1.3.56*.
"""
fine_tune = EventProp[int](ChannelID.FineTune)
"""-100 to +100 cents."""
# TODO Return this as a note name, like `Note.key`
root_note = EventProp[int](ChannelID.RootNote, default=60)
"""Min - 0 (C0), Max - 131 (B10)."""
# main_pitch_enabled = StructProp[bool](ChannelID.Parameters)
# """Whether triggered note is affected by changes to `project.main_pitch`."""
# added_to_key = StructProp[bool](ChannelID.Parameters)
# """Whether root note should be added to triggered note instead of pitch.
#
# *New in FL Studio v3.4.0*.
# """
# note_range: tuple[int] - Should be a 2-short or 2-byte tuple
class Playback(MultiEventModel, ModelReprMixin):
"""Used by :class:`Sampler`.
![](https://bit.ly/3xjSypY)
"""
ping_pong_loop = EventProp[bool](ChannelID.PingPongLoop)
start_offset = StructProp[int](ChannelID.Parameters, prop="playback.start_offset")
"""Linear. Defaults to minimum value.
| Type | Value | Representation |
|------|------------|----------------|
| Min | 0 | 0% |
| Max | 1072693248 | 100% |
"""
use_loop_points = FlagProp(_SamplerFlags.UsesLoopPoints, ChannelID.SamplerFlags)
class TimeStretching(MultiEventModel, ModelReprMixin):
"""Used by :class:`Sampler`.
![](https://bit.ly/3eIAjnG)
*New in FL Studio v5.0*.
"""
mode = StructProp[StretchMode](ChannelID.Parameters, prop="stretching.mode")
# multiplier: Optional[int] = None
# pitch: Optional[int] = None
time = EventProp[float](ChannelID.StretchTime)
class Content(MultiEventModel, ModelReprMixin):
"""Used by :class:`Sampler`."""
declick_mode = StructProp[DeclickMode](
ChannelID.Parameters, prop="content.declick_mode"
)
keep_on_disk = FlagProp(_SamplerFlags.KeepOnDisk, ChannelID.SamplerFlags)
load_regions = FlagProp(_SamplerFlags.LoadRegions, ChannelID.SamplerFlags)
load_slices = FlagProp(_SamplerFlags.LoadSliceMarkers, ChannelID.SamplerFlags)
resample = FlagProp(_SamplerFlags.Resample, ChannelID.SamplerFlags)
class Channel(MultiEventModel, SupportsIndex):
"""Represents a channel in the channel rack."""
def __repr__(self):
if self.display_name is None:
return f"Unnamed {type(self).__name__.lower()} #{self.iid}"
return f"{type(self).__name__} {self.display_name!r} #{self.iid}"
def __index__(self):
return cast(int, self.iid)
color = EventProp[colour.Color](PluginID.Color)
"""Defaults to #5C656A (granite gray).
Values below 20 for any color component (R, G or B) are ignored by FL.
"""
controllers = KWProp[List[RemoteController]]()
internal_name = EventProp[str](PluginID.InternalName)
"""Internal name of the channel.
The value of this depends on the type of `plugin`:
* Native (stock) plugin: Empty *afaik*.
* VST instruments: "Fruity Wrapper".
See Also:
:attr:`name`
"""
# TODO Add link to GIF from docs once Bitly quota is available again.
enabled = EventProp[bool](ChannelID.IsEnabled)
group = KWProp[DisplayGroup]()
"""Display group / filter under which this channel is grouped."""
icon = EventProp[int](PluginID.Icon)
iid = EventProp[int](ChannelID.New)
keyboard = NestedProp(Keyboard, ChannelID.FineTune, ChannelID.RootNote)
locked = EventProp[bool](ChannelID.IsLocked)
"""![](https://bit.ly/3BOBc7j)"""
name = EventProp[str](PluginID.Name, ChannelID._Name)
"""The name associated with a channel.
It's value depends on the type of plugin:
* Native (stock): User-given name, None if not given one.
* VST instrument: The name obtained from the VST or the user-given name.
See Also:
:attr:`internal_name` and :attr:`display_name`.
"""
@property
def pan(self) -> int | None:
"""
| Min | Max | Default |
|-----|-------|---------|
| 0 | 12800 | 6400 |
""" # noqa
if ChannelID.Levels in self._events:
return cast(LevelsEvent, self._events[ChannelID.Levels][0])["pan"]
for id in (ChannelID._PanWord, ChannelID._PanByte):
events = self._events.get(id)
if events is not None:
return events[0].value
@pan.setter
def pan(self, value: int) -> None:
if self.pan is None:
raise AttributeError
events = self._events.get(ChannelID.Levels)
if events is not None:
cast(LevelsEvent, events[0])["pan"] = value
return
for id in (ChannelID._PanWord, ChannelID._PanByte):
events = self._events.get(id)
if events is not None:
events[0].value = value
@property
def volume(self) -> int | None:
"""
| Min | Max | Default |
|-----|-------|---------|
| 0 | 12800 | 10000 |
""" # noqa
if ChannelID.Levels in self._events:
return cast(LevelsEvent, self._events[ChannelID.Levels][0])["volume"]