Skip to content

Commit c267d2c

Browse files
committed
[chore] added some comments
1 parent b308767 commit c267d2c

File tree

5 files changed

+41
-5
lines changed

5 files changed

+41
-5
lines changed

example/midi_play.dart

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'package:tekartik_midi/midi_player_base.dart';
1313
class _MidiPlayer extends MidiPlayerBase {
1414
@override
1515
void rawPlayEvent(PlayableEvent event) {
16+
// ignore: avoid_print
1617
print(event);
1718
}
1819

lib/midi_file_player.dart

+7
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ import 'package:tekartik_common_utils/list_utils.dart';
77

88
import 'midi.dart';
99

10+
/// Playable event
1011
class PlayableEvent {
12+
/// in millis
1113
final num timestamp; // ms
14+
/// The event to play
1215
final MidiEvent midiEvent;
1316

17+
/// Constructor
1418
PlayableEvent(this.timestamp, this.midiEvent);
1519

1620
@override
@@ -21,10 +25,13 @@ class PlayableEvent {
2125

2226
/// Prepare located events
2327
class LocatedTrackPlayer {
28+
/// The track
2429
MidiTrack track;
2530

31+
/// Constructor
2632
LocatedTrackPlayer(this.track);
2733

34+
/// List of located events
2835
List<LocatedEvent> get preLocatedEvents {
2936
var events = <LocatedEvent>[];
3037
var currentTime = 0;

lib/midi_player_base.dart

+2
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,12 @@ abstract class MidiPlayerBase {
417417
}
418418
}
419419

420+
/// Get the total duration of the file
420421
num get totalDurationMs {
421422
return _midiFilePlayer!.totalDurationMs;
422423
}
423424

425+
/// Get the current position in the file
424426
num get currentAbsoluteMs {
425427
if (!_isPlaying) {
426428
return 0;

lib/src/buffer/midi_buffer.dart

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
abstract class Buffer {
1+
abstract class _Buffer {
22
late List<int> _data;
33
int _position = 0;
44

@@ -19,7 +19,9 @@ abstract class Buffer {
1919
}
2020
}
2121

22-
class InBuffer extends Buffer {
22+
/// Input buffer
23+
class InBuffer extends _Buffer {
24+
/// Constructor
2325
InBuffer(List<int> data) {
2426
_data = data;
2527
}
@@ -29,37 +31,46 @@ class InBuffer extends Buffer {
2931

3032
//int operator [](int index) => _data[index];
3133

34+
/// Get the next byte and advance the position
3235
int next() {
3336
return _data[_position++];
3437
}
3538

39+
/// Skip [count] bytes
3640
void skip(int count) {
3741
_position += count;
3842
}
3943
}
4044

41-
class OutBuffer extends Buffer {
45+
/// Output buffer
46+
class OutBuffer extends _Buffer {
4247
@override
4348
int get length => _position;
4449

50+
/// Constructor
4551
OutBuffer(int size) {
4652
_data = List<int>.filled(size, 0);
4753
}
4854

55+
/// Restart the buffer
4956
void restart() {
5057
_position = 0;
5158
}
5259

60+
/// Add a byte
5361
void add(int value) {
5462
_data[_position++] = value;
5563
}
5664

65+
/// get the remaining count
5766
int get remainingAvailable => _data.length - _position;
5867

68+
/// Check if there is enough space
5969
bool hasAvailable(int size) {
6070
return remainingAvailable >= size;
6171
}
6272

73+
/// Check if the data is equal to the list
6374
bool equalsList(List<int> data) {
6475
if (length == data.length) {
6576
for (var i = 0; i < length; i++) {

lib/src/midi/event.dart

+17-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class TrackEvent {
2828
final int deltaTime;
2929
final MidiEvent midiEvent;
3030

31+
/// Constructor
3132
TrackEvent(this.deltaTime, this.midiEvent);
3233

3334
@override
@@ -85,32 +86,40 @@ abstract class MidiEvent {
8586
/// Meta command.
8687
static const int cmdMetaEvent = 0xFF;
8788

89+
/// Constructor
8890
MidiEvent();
8991

92+
/// Constructor with command
9093
MidiEvent.withParam(this.command);
9194

9295
/// Compute command from an event type and a channel
9396
static int commandChannel(int eventType, int channel) {
9497
return ((eventType << 4) | (channel & 0xF));
9598
}
9699

100+
/// Get the event type
97101
@Deprecated('use commandGetEventType')
98102
static int commandGetCommand(int command) => commandGetEventType(command);
99103

104+
/// Get the event type
100105
static int commandGetEventType(int command) {
101106
return ((command & 0xF0) >> 4);
102107
}
103108

109+
/// Get the channel
104110
static int commandGetChannel(int command) {
105111
// (command & 0xF)
106112
return (command & 0xF);
107113
}
108114

115+
/// Get the event type
109116
int get eventType => commandGetEventType(command);
110117

118+
/// Get the event type
111119
@Deprecated('user event type instead')
112120
int get codeCommand => eventType;
113121

122+
/// Base command
114123
factory MidiEvent.base(int command) {
115124
MidiEvent event;
116125

@@ -174,19 +183,25 @@ abstract class MidiEvent {
174183

175184
/// Channel event.
176185
abstract class ChannelEvent extends MidiEvent {
186+
/// Channel
177187
int get channel => MidiEvent.commandGetChannel(command);
178188

189+
/// Constructor
179190
ChannelEvent();
180191

181-
ChannelEvent.withParam(int comand, int channel)
182-
: super.withParam(MidiEvent.commandChannel(comand, channel));
192+
/// Constructor with command and channel
193+
ChannelEvent.withParam(int command, int channel)
194+
: super.withParam(MidiEvent.commandChannel(command, channel));
183195
}
184196

197+
/// Param1ByteEvent
185198
abstract class Param1ByteEvent extends ChannelEvent {
186199
int? _param1;
187200

201+
/// Constructor
188202
Param1ByteEvent();
189203

204+
/// Constructor with command, channel and param1
190205
Param1ByteEvent.withParam(super.command, super.channel, this._param1)
191206
: super.withParam();
192207

0 commit comments

Comments
 (0)