-
Notifications
You must be signed in to change notification settings - Fork 13
/
channel.py
1090 lines (819 loc) · 28.9 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 sys
from typing import DefaultDict, List, Tuple, cast
if sys.version_info >= (3, 8):
from typing import SupportsIndex
else:
from typing_extensions import SupportsIndex
if sys.version_info >= (3, 9):
from collections.abc import Iterator, Sequence
else:
from typing import Sequence, Iterator
import colour
from ._base import (
DATA,
DWORD,
TEXT,
WORD,
AnyEvent,
BoolEvent,
EventEnum,
EventProp,
F32Event,
FlagProp,
I8Event,
I32Event,
IterProp,
KWProp,
ModelReprMixin,
MultiEventModel,
NestedProp,
SingleEventModel,
StructBase,
StructEventBase,
StructProp,
U8Event,
U16Event,
U16TupleEvent,
U32Event,
)
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",
"LFOShape",
"ReverbType",
"FX",
"Reverb",
"Delay",
"Envelope",
"LFO",
"Tracking",
"Keyboard",
"LevelAdjusts",
"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
"_u31": 31, # 92
"arp.repeat": "I", # 96 4.5.2+
"_u62": 62, # 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)
UsesLoopPoints = (19, BoolEvent)
Type = (21, U8Event)
RoutedTo = (22, I8Event)
# FXProperties = 27
IsLocked = (32, BoolEvent) #: 12.3+
New = (WORD, U16Event)
# Fx = WORD + 5
# FadeStereo = WORD + 6
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+
# Fx3 = WORD + 22
# 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
# FxSine = DWORD + 3
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)
@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 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."""
feedback = StructProp[int]()
"""Factor with which the volume of every next echo is multiplied."""
pan = StructProp[int]()
pitch_shift = StructProp[int]()
time = StructProp[int]()
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.
.. image:: img/channel/fx/boost.png
| Min | Max |
|-----|-----|
| 0 | 256 |
*New in FL Studio v1.2.12*.
"""
cutoff = EventProp[int](ChannelID.Cutoff)
"""Filter Mod X. Defaults to maximum value.
.. image:: img/channel/fx/cutoff.png
| Min | Max |
|-----|------|
| 0 | 1024 |
"""
fade_in = EventProp[int](ChannelID.FadeIn)
"""Quick fade-in. Defaults to minimum value.
.. image:: img/channel/fx/fade-in.png
| Min | Max |
|-----|------|
| 0 | 1024 |
"""
fade_out = EventProp[int](ChannelID.FadeOut)
"""Quick fade-out. Defaults to minimum value.
.. image:: img/channel/fx/fade-out.png
| Min | Max |
|-----|------|
| 0 | 1024 |
*New in FL Studio v1.7.6*.
"""
resonance = EventProp[int](ChannelID.Resonance)
"""Filter Mod Y. Defaults to minimum value.
.. image:: img/channel/fx/resonance.png
| Min | Max |
|-----|------|
| 0 | 1024 |
"""
reverb = NestedProp[Reverb](Reverb, ChannelID.Reverb)
stereo_delay = EventProp[int](ChannelID.StereoDelay)
""".. image:: img/channel/fx/stereo-delay.png
*New in FL Studio v1.3.56*.
"""
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)
is_porta = FlagProp(_PolyphonyFlags.Porta)
"""*New in FL Studio v3.3.0*."""
max = StructProp[int]()
slide = StructProp[int]()
"""*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]()
mod_x = StructProp[int]()
mod_y = StructProp[int]()
pan = StructProp[int]()
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."""
root_note = EventProp[int](ChannelID.RootNote)
"""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` and :class:`Instrument`.
![](https://bit.ly/3xjSypY)
"""
# ping_pong_loop: bool
# start_offset: int
use_loop_points = EventProp[bool](ChannelID.UsesLoopPoints)
class TimeStretching(MultiEventModel, ModelReprMixin):
"""Used by :class:`Sampler`.
![](https://bit.ly/3eIAjnG)
*New in FL Studio v5.0*.
"""
# mode: enum (new modes added in FL Studio v7.0.0)
# multiplier: Optional[int] = None
# pitch: Optional[int] = None
time = EventProp[float](ChannelID.StretchTime)
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)
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: The factory name of the plugin.
* VST instruments: "Fruity Wrapper".
See Also:
:attr:`name`
"""
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)
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 | 10000 |
""" # 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"]
for id in (ChannelID._VolWord, ChannelID._VolByte):
events = self._events.get(id)
if events is not None:
return events[0].value
@volume.setter
def volume(self, value: int) -> None:
if self.volume is None:
raise AttributeError
events = self._events.get(ChannelID.Levels)
if events is not None:
cast(LevelsEvent, events[0])["volume"] = value
for id in (ChannelID._VolWord, ChannelID._VolByte):
events = self._events.get(id)
if events is not None:
events[0].value = value
# If the channel is not zipped, underlying event is not stored.
@property
def zipped(self) -> bool:
"""Whether the channel is in zipped state.
![](https://bit.ly/3S2imib)
"""
if ChannelID.Zipped in self._events:
return self._events[ChannelID.Zipped][0].value
return False
@property
def display_name(self) -> str | None:
"""The name of the channel that will be displayed in FL Studio."""
return self.name or self.internal_name
class Automation(Channel):
"""Represents an automation clip present in the channel rack.
![](https://bit.ly/3RXQhIN)
"""
class Layer(Channel, Sequence[Channel]):
"""Represents a layer channel present in the channel rack.
![](https://bit.ly/3S2MLgf)
*New in FL Studio v3.4.0*.
"""
def __getitem__(self, index: str | SupportsIndex):
"""Returns a child channel with an IID / index of :attr:`~Channel.iid`.
Args:
index (str | SupportsIndex): An IID or a zero based index of the child
channel.
Raises:
ChannelNotFound: A child channel with the specific index or IID
couldn't be found. This exception derives from `KeyError` as well.
"""
for idx, child in enumerate(self):
if index in (idx, child.iid):
return child
raise ChannelNotFound(index)
def __iter__(self) -> Iterator[Channel]:
if ChannelID.Children in self._events:
for event in self._events[ChannelID.Children]:
yield self._kw["channels"][event.value]
def __len__(self):
"""Returns the number of channels whose parent this layer is."""
return len(self._events.get(ChannelID.Children, []))
flags = EventProp[int](ChannelID.LayerFlags) # TODO
class _SamplerInstrument(Channel):
arp = NestedProp(Arp, ChannelID.Parameters)
delay = NestedProp(Delay, ChannelID.Delay)
flags = EventProp[int](ChannelID.SamplerFlags) # TODO
insert = EventProp[int](ChannelID.RoutedTo)
"""The index of the :class:`Insert` the channel is routed to. Min = -1."""
level_adjusts = NestedProp(LevelAdjusts, ChannelID.LevelAdjusts)
polyphony = NestedProp(Polyphony, ChannelID.Polyphony)
stretching = NestedProp(TimeStretching, ChannelID.StretchTime)
time = NestedProp(Time, ChannelID.Swing)
tracking = IterProp(ChannelID.Tracking, Tracking)
class Instrument(_SamplerInstrument):
"""Represents a native or a 3rd party plugin loaded in a channel."""
plugin = PluginProp({VSTPluginEvent: VSTPlugin, BooBassEvent: BooBass})
"""The plugin loaded into the channel."""
# TODO New in FL Studio v1.4.0 & v1.5.23: Sampler spectrum views
class Sampler(_SamplerInstrument):
"""Represents the native Sampler, either as a clip or a channel.
![](https://bit.ly/3DlHPiI)
"""
def __repr__(self):
return f"{repr(self.sample_path) or 'Empty'} {super().__repr__()}"
au_sample_rate = EventProp[int](ChannelID.AUSampleRate)
"""AU-format sample specific."""
cut_group = EventProp[Tuple[int, int]](ChannelID.CutGroup)
"""Cut group in the form of (Cut self, cut by)."""
# FL's interface doesn't have an envelope for panning, but still stores
# the default values in event data.
envelopes = IterProp(ChannelID.EnvelopeLFO, Envelope)
"""One each for Volume, Panning, Mod X, Mod Y and Pitch :class:`Envelope`."""
fx = NestedProp(
FX,
ChannelID.Cutoff,
ChannelID.FadeIn,
ChannelID.FadeOut,
ChannelID.Preamp,
ChannelID.Resonance,
ChannelID.StereoDelay,
)
lfos = IterProp(ChannelID.EnvelopeLFO, LFO)
"""One each for Volume, Panning, Mod X, Mod Y and Pitch :class:`LFO`."""
@property
def pitch_shift(self) -> int | None:
"""-4800 to +4800 cents.
Raises:
PropertyCannotBeSet: When a `ChannelID.Levels` event is not found.
"""
if ChannelID.Levels in self._events:
return cast(LevelsEvent, self._events[ChannelID.Levels][0])["pitch_shift"]
@pitch_shift.setter
def pitch_shift(self, value: int):
try:
event = self._events[ChannelID.Levels][0]
except KeyError as exc:
raise PropertyCannotBeSet(ChannelID.Levels) from exc
else:
cast(LevelsEvent, event)["pitch_shift"] = value
playback = NestedProp[Playback](Playback, ChannelID.UsesLoopPoints)
sample_path = EventProp[str](ChannelID.SamplePath)
"""Absolute path of a sample file on the disk.
Contains the string `%FLStudioFactoryData%` for stock samples.
"""
class ChannelRack(MultiEventModel, Sequence[Channel]):
"""Represents the channel rack, contains all :class:`Channel`s.
![](https://bit.ly/3RXR50h)
"""
def __repr__(self) -> str:
return f"ChannelRack - {len(self)} channels"
def __getitem__(self, index: str | SupportsIndex):
"""Gets a channel from the rack based on its IID or index.
Args:
index (str | SupportsIndex): Compared with :attr:`Channel.iid` if
a string or the index of the order in which channels are found.