Created
March 3, 2014 12:50
-
-
Save jpenca/9324287 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// MDSampleSlicer.m | |
// MachineDrumFramework | |
// | |
// Created by Jakob Penca on 02/03/14. | |
// Copyright (c) 2014 Jakob Penca. All rights reserved. | |
// | |
#import "MDSampleSlicer.h" | |
#import "MDMath.h" | |
#import "MDParameterLock.h" | |
@implementation MDSampleSlicer | |
- (id)init | |
{ | |
if(self = [super init]) | |
{ | |
_length = 16; | |
_sampleLength = 16; | |
_stepInterval = 1; | |
_generateLocks = YES; | |
} | |
return self; | |
} | |
- (void)slice | |
{ | |
if(!self.pattern) return; | |
int patternLength = self.pattern.length; | |
if(_offset >= patternLength) return; | |
patternLength = MIN(patternLength, _offset + _length); | |
int numSlices = _sampleLength / _stepInterval; | |
int sliceLen = 128/numSlices; | |
int sliceIdx = 0; | |
for(int stepIdx = _offset; stepIdx < patternLength; stepIdx+=_stepInterval) | |
{ | |
if(_generateLocks) | |
{ | |
int innerSliceIdx = sliceIdx; | |
if(_direction == MDSamplerSlicerDirectionBackward) | |
{ | |
innerSliceIdx = (numSlices-1) - sliceIdx; | |
} | |
if(_randomPlacement > 0 && mdmath_rand(0, 1) <= _randomPlacement) | |
{ | |
innerSliceIdx = mdmath_randi(0, numSlices-1); | |
} | |
int strt = mdmath_map(innerSliceIdx, 0, numSlices, 0, 128); | |
int stop = strt + sliceLen; | |
strt = mdmath_clamp(strt, 0, 127); | |
stop = mdmath_clamp(stop, 0, 127); | |
if(_sliceReverse > 0 && mdmath_rand(0, 1) <= _sliceReverse) | |
{ | |
int tmp = strt; | |
strt = stop; | |
stop = tmp; | |
} | |
MDParameterLock *lock = [MDParameterLock lockForTrack:_trackIdx param:4 step:stepIdx value:strt]; | |
[self.pattern setLock:lock setTrigIfNone:YES]; | |
lock = [MDParameterLock lockForTrack:_trackIdx param:5 step:stepIdx value:stop]; | |
[self.pattern setLock:lock setTrigIfNone:YES]; | |
sliceIdx++; | |
sliceIdx = mdmath_wrap(sliceIdx, 0, numSlices-1); | |
} | |
else | |
{ | |
[self.pattern setTrigAtTrack:_trackIdx step:stepIdx toValue:YES]; | |
} | |
} | |
} | |
@end |
yep, md1_53-sysex-0_8 is the one I have.
Very good then. I asked the elektron these days if there was any update, but are still waiting for answer.
I saw that you made interesting applications for Elektron gear, very nice.
Just my curiosity by a developer, you're using openFrameworks?
thanks..
I always meant to start with OF but never really got around to it.. doing iOS dev mostly, and using cocos2d / raw OpenGL for graphics..
a port of the Elektron stuff to OF would be interesting!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your addon manual you refer for sysex, is this md1_53-sysex-0_8?
Or Elektron have made some update?