- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
void MSSequencerPatternCopyToMusicTrack(MSSequencerPatternRef self, MusicTrack track)
{
// Get signature and length of pattern
TimeSignature sign = MSSequencerPatternGetTimeSignature(self);
CABarBeatTime length = pattern_barbeat_duration_without_mutes(self);
CABarBeatTime insert = CABarBeatTime(1, 1);
// Get muted beats
CFRange *mutedBeats = (CFRange*)CFDataGetBytePtr(self->mutedBeats);
CFIndex mutedCount = CFDataGetLength(self->mutedBeats) / sizeof(CFRange);
// Copy with muted regions
if (mutedCount > 0)
{
// Clear output track
MSSequencerTrackClear(self->parent, track);
// Copy phrase by phrase
for (int i = 0; i < mutedCount; ++i)
{
CFRange muteRange = mutedBeats[i];
CFIndex beatsCount = (sign.numerator * sign.denominator);
if ((beatsCount * (i + 1)) > muteRange.location + muteRange.length)
{
if (muteRange.length > 0)
{
// Copy beats before mute range
if (muteRange.location > (beatsCount * i))
{
CFIndex start = (beatsCount * i);
CFIndex end = muteRange.location;
insert = copy_beats_to_track_from_beat_to_beat(self, track, sign, insert, start, end);
}
// Copy beats after range
{
CFIndex start = (muteRange.location + muteRange.length);
CFIndex end = (beatsCount * (i + 1));
insert = copy_beats_to_track_from_beat_to_beat(self, track, sign, insert, start, end);
}
}
else
{
// Copy without mutes
CFIndex start = (beatsCount * i);
CFIndex end = (beatsCount * (i + 1));
insert = copy_beats_to_track_from_beat_to_beat(self, track, sign, insert, start, end);
}
}
else
{
// Copy beats
CFIndex firstBeat = (muteRange.location + muteRange.length) % beatsCount;
CABarBeatTime start = CABarBeatTimeAddBeats(CABarBeatTime(1, 1), sign, (beatsCount * i) + firstBeat);
CABarBeatTime end = CABarBeatTimeAddBeats(start, sign, (beatsCount - muteRange.length));
copy_beats_from_pattern_to_track(self, track, start, end, insert);
//CFLog("start: {%i, %i}, end: {%i, %i}, insert: {%i, %i}", (int)start.bar, (int)start.beat, (int)end.bar, (int)end.beat, (int)insert.bar, (int)insert.beat);
// Update insert time
insert = CABarBeatTimeAddBeats(insert, sign, (beatsCount - muteRange.length));
}
}
}
// Copy without muted regions
else
{
copy_beats_from_pattern_to_track(self, track, insert, length, insert);
}
//CAShow(track);
}