Join/Login

Business Software

Open Source Software

For Vendors

Blog

About

More

Articles

Create

SourceForge Podcast

Site Documentation

Subscribe to our Newsletter

Support Request

For Vendors Help Create Join Login

Business Software

Open Source Software

SourceForge Podcast

Resources

Articles

Case Studies

Blog

Menu

Help

Create

Join

Login

Home

Browse

PlayerPro music editor and SoundTracker

Code

PlayerPro music editor and SoundTracker Code

Play SoundTracker media on your computer.

Brought to you by: madd_the_sane, rossetantoine, sandrobilbeisi

Summary

Files

Reviews

Support

Mailing Lists

Tickets ▾

Bugs

Support Requests

Patches

Feature Requests

News

Discussion

Code

Menu ▾ ▴

Browse Commits

Fork

Merge Requests 0

Branches

master

Classic

NSPreferences

PP5-CPlusPlusRewrite

PPPcmd

PlayerPRO5

SDLAudio

XPCMIDI

XPCMIDI-noObjC

audioToolbox-plugrewrite

More Branches

Tags

5.10-Developer-Preview-1

5.10-Developer-Preview-2

5.10-Developer-Preview-3

5.10-Developer-Preview-4

5.10-Developer-Preview-5

5.10-Developer-Preview-6

5.10-Developer-Preview-7

PP6-pre_split

PPlayer-1.0

PPlayer-1.0.1

More Tags

[b65532]: / PlayerPROKit / PPSampleObject.m  Maximize  Restore  History

Download this file

429 lines (369 with data), 10.1 kB

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

//

// PPInstrumentObject.m

// PPMacho

//

// Created by C.W. Betts on 1/10/13.

//

//

#include <PlayerPROCore/PlayerPROCore.h>

#import "PPSampleObject.h"

#import "PPSampleObject_PPKPrivate.h"

#if TARGET_OS_OSX

#import "PPPasteboardHandling.h"

#endif

#define LOOPBEGINKEY @"Loop Begin"

#define LOOPSIZEKEY @"Loop Size"

#define VOLUMEKEY @"Volume"

#define C2SPDKEY @"c2spd"

#define LOOPTYPEKEY @"Loop Type"

#define AMPLITUDEKEY @"Amplitude"

#define RELATIVENOTEKEY @"Relative Note"

#define NAMEKEY @"Name"

#define STEREOKEY @"Stereo"

#define DATAKEY @"Data"

#define SAMPLEINDEXKEY @"Sample Index"

#define INSTRUMENTINDEXKEY @"Instrument Index"

@implementation PPSampleObject

{

@private

sData theSample;

sData *sampleWriteTo;

}

@synthesize theSample;

@synthesize name = _name;

@synthesize data = _data;

- (NSString*)name

{

if (!_name) {

_name = [[NSString alloc] initWithCString:sampleWriteTo->name encoding:NSMacOSRomanStringEncoding];

}

return _name;

}

- (void)setName:(NSString *)name

{

char theName[32] = {0};

NSData *tmpCStr = [name dataUsingEncoding:NSMacOSRomanStringEncoding allowLossyConversion:YES];

NSInteger cStrLen = [tmpCStr length];

if (cStrLen > sizeof(theName) - 1) {

cStrLen = sizeof(theName) - 1;

}

[tmpCStr getBytes:theName length:cStrLen];

strlcpy(sampleWriteTo->name, theName, sizeof(sampleWriteTo->name));

_name = [[NSString alloc] initWithCString:sampleWriteTo->name encoding:NSMacOSRomanStringEncoding];

}

- (NSData*)data

{

if (!_data) {

_data = [[NSData alloc] initWithBytesNoCopy:sampleWriteTo->data length:sampleWriteTo->size freeWhenDone:NO];

}

if (!_data) {

_data = [[NSData alloc] init];

}

return _data;

}

- (void)setData:(NSData *)data

{

_data = nil;

NSInteger dataSize2 = [data length];

sampleWriteTo->size = (int)dataSize2;

if (sampleWriteTo->data) {

free(sampleWriteTo->data);

sampleWriteTo->data = NULL;

}

if (dataSize2 == 0) {

sampleWriteTo->data = NULL;

_data = [[NSData alloc] init];

return;

}

sampleWriteTo->data = malloc(dataSize2);

[data getBytes:sampleWriteTo->data length:dataSize2];

_data = [[NSData alloc] initWithBytesNoCopy:sampleWriteTo->data length:sampleWriteTo->size freeWhenDone:NO];

}

#if TARGET_OS_OSX

NSString * const kPPKSamplePasteboardUTI = @"net.sourceforge.playerpro.sData";

static NSArray *UTIArray;

static dispatch_once_t initUTIOnceToken;

static const dispatch_block_t initUTIArray = ^{

UTIArray = @[kPPKSamplePasteboardUTI];

};

+ (NSArray *)readableTypesForPasteboard:(NSPasteboard *)pasteboard

{

dispatch_once(&initUTIOnceToken, initUTIArray);

return UTIArray;

}

- (NSArray *)writableTypesForPasteboard:(NSPasteboard *)pasteboard

{

dispatch_once(&initUTIOnceToken, initUTIArray);

return UTIArray;

}

- (id)pasteboardPropertyListForType:(NSString *)type

{

if ([type isEqualToString:kPPKSamplePasteboardUTI])

return [NSKeyedArchiver archivedDataWithRootObject:self];

else

return nil;

}

+ (NSPasteboardReadingOptions)readingOptionsForType:(NSString *)type pasteboard:(NSPasteboard *)pasteboard

{

if ([type isEqualToString:kPPKSamplePasteboardUTI])

return NSPasteboardReadingAsKeyedArchive;

else

return NSPasteboardReadingAsData;

}

#endif

- (void)setToSDataPointer:(inout sData *)theData

{

if (theData->data) {

free(theData->data);

theData->data = NULL;

}

NSData *currentData = [self.data mutableCopy];

self.data = nil;

memmove(theData, sampleWriteTo, sizeof(sData));

sampleWriteTo = theData;

self.data = currentData;

}

- (instancetype)initWithSDataPointer:(inout sData *)theData

{

if (self = [self initWithSData:theData]) {

self.data = nil;

sampleWriteTo = theData;

}

return self;

}

- (sData)theSample

{

return *sampleWriteTo;

}

- (void)setAmplitude:(MADByte)amplitude

{

sampleWriteTo->amp = amplitude;

}

- (MADByte)amplitude

{

return sampleWriteTo->amp;

}

- (void)setLoopSize:(int)loopSize

{

sampleWriteTo->loopSize = loopSize;

}

- (int)loopSize

{

return sampleWriteTo->loopSize;

}

- (void)setLoopBegin:(int)loopBegin

{

sampleWriteTo->loopBeg = loopBegin;

}

- (int)loopBegin

{

return sampleWriteTo->loopBeg;

}

- (void)setC2spd:(unsigned short)c2spd

{

sampleWriteTo->c2spd = c2spd;

}

- (unsigned short)c2spd

{

return sampleWriteTo->c2spd;

}

- (void)setLoopType:(MADLoopType)loopType

{

sampleWriteTo->loopType = loopType;

}

- (MADLoopType)loopType

{

return sampleWriteTo->loopType;

}

- (void)setRelativeNote:(char)relativeNote

{

sampleWriteTo->relNote = relativeNote;

}

- (char)relativeNote

{

return sampleWriteTo->relNote;

}

- (MADByte)volume

{

return sampleWriteTo->vol;

}

- (void)setVolume:(MADByte)avolume

{

sampleWriteTo->vol = avolume;

}

- (BOOL)isStereo

{

return sampleWriteTo->stereo;

}

- (void)setStereo:(BOOL)astereo

{

sampleWriteTo->stereo = astereo;

}

- (int)dataSize

{

return (int)[self.data length];

}

- (instancetype)init

{

return [self initWithSData:NULL];

}

- (instancetype)initWithSData:(sData *)theData

{

if (self = [super init]) {

if (!theData) {

strcpy(theSample.name, "");

theSample.data = NULL;

theSample.size = 0;

theSample.loopType = 0;

theSample.c2spd = NOFINETUNE;

theSample.amp = 8;

theSample.vol = 64;

theSample.stereo = FALSE;

theSample.loopBeg = 0;

theSample.loopSize = 0;

theSample.relNote = 0;

sampleWriteTo = &theSample;

} else {

theSample = *theData;

theSample.data = NULL;

sampleWriteTo = &theSample;

self.data = [[NSData alloc] initWithBytes:theData->data length:theData->size];

}

}

return self;

}

- (void)dealloc

{

if (sampleWriteTo->data) {

free(sampleWriteTo->data);

sampleWriteTo->data = NULL;

}

}

- (sData *)createSData

{

sData *toReturn = malloc(sizeof(sData));

memcpy(toReturn, sampleWriteTo, sizeof(sData));

char theName[32] = {0};

NSData *tmpCStr = [_name dataUsingEncoding:NSMacOSRomanStringEncoding allowLossyConversion:YES];

NSInteger cStrLen = [tmpCStr length];

if (cStrLen > sizeof(theName) - 1) {

cStrLen = sizeof(theName) - 1;

}

[tmpCStr getBytes:theName length:cStrLen];

tmpCStr = nil;

strlcpy(toReturn->name, theName, sizeof(toReturn->name));

NSInteger dataSize2 = [_data length];

toReturn->size = (int)dataSize2;

toReturn->data = malloc(dataSize2);

[_data getBytes:toReturn->data length:dataSize2];

return toReturn;

}

- (BOOL)isBlankSample

{

if (self.name && ![self.name isEqualToString:@""]) {

return NO;

}

if (self.data && ([self.data length] != 0)) {

return NO;

}

return YES;

}

- (NSRange)loop

{

if (sampleWriteTo->loopSize == 0) {

return NSMakeRange(NSNotFound, 0);

}

return NSMakeRange(sampleWriteTo->loopBeg, sampleWriteTo->loopSize);

}

- (void)setLoop:(NSRange)loop

{

if (loop.location == NSNotFound) {

sampleWriteTo->loopBeg = 0;

sampleWriteTo->loopSize = 0;

} else {

sampleWriteTo->loopBeg = (int)loop.location;

sampleWriteTo->loopSize = (int)loop.length;

}

}

- (NSString*)description

{

return [NSString stringWithFormat:@"%@: size: %ld stereo: %@ Loop type: %d start: %d size: %d volume: %d amp: %d", self.name, (long)[self.data length], self.stereo ? @"Yes": @"No", self.loopType, self.loopBegin, self.loopSize, self.volume, self.amplitude];

}

#pragma mark KVO/KVC helpers

+ (NSSet*)keyPathsForValuesAffectingTheSample

{

return [NSSet setWithObjects:@"loopBegin", @"loopSize", @"volume", @"c2spd", @"loopType", @"amplitude", @"relativeNote", @"name", @"stereo", @"data", nil];

}

+ (NSSet*)keyPathsForValuesAffectingBlankSample

{

return [NSSet setWithObjects:@"name", @"data", nil];

}

+ (NSSet*)keyPathsForValuesAffectingLoop

{

return [NSSet setWithObjects:@"loopBegin", @"loopSize", nil];

}

+ (NSSet*)keyPathsForValuesAffectingLoopBegin

{

return [NSSet setWithObjects:@"loop", nil];

}

+ (NSSet*)keyPathsForValuesAffectingLoopSize

{

return [NSSet setWithObjects:@"loop", nil];

}

#pragma mark NSCopying implementation

- (id)copyWithZone:(NSZone *)zone

{

PPSampleObject *obj;

if ((obj = [[[self class] allocWithZone:zone] init])) {

obj.name = self.name;

obj.data = self.data;

obj.amplitude = self.amplitude;

obj.volume = self.volume;

obj.stereo = self.stereo;

obj.c2spd = self.c2spd;

obj.loopType = self.loopType;

obj.relativeNote = self.relativeNote;

obj.loop = self.loop;

}

return obj;

}

#pragma mark NSCoding implementation

+ (BOOL)supportsSecureCoding

{

return YES;

}

- (void)encodeWithCoder:(NSCoder *)aCoder

{

[aCoder encodeObject:self.name forKey:NAMEKEY];

[aCoder encodeObject:self.data forKey:DATAKEY];

[aCoder encodeInt:sampleWriteTo->loopBeg forKey:LOOPBEGINKEY];

[aCoder encodeInt:sampleWriteTo->loopSize forKey:LOOPSIZEKEY];

[aCoder encodeObject:@(sampleWriteTo->vol) forKey:VOLUMEKEY];

[aCoder encodeObject:@(sampleWriteTo->c2spd) forKey:C2SPDKEY];

[aCoder encodeObject:@(sampleWriteTo->loopType) forKey:LOOPTYPEKEY];

[aCoder encodeObject:@(sampleWriteTo->amp) forKey:AMPLITUDEKEY];

[aCoder encodeObject:@(sampleWriteTo->relNote) forKey:RELATIVENOTEKEY];

[aCoder encodeBool:sampleWriteTo->stereo forKey:STEREOKEY];

[aCoder encodeInteger:self.sampleIndex forKey:SAMPLEINDEXKEY];

[aCoder encodeInteger:self.instrumentIndex forKey:INSTRUMENTINDEXKEY];

}

- (instancetype)initWithCoder:(NSCoder *)aDecoder

{

if (self = [super init]) {

sampleWriteTo = &theSample;

self.name = [aDecoder decodeObjectForKey:NAMEKEY];

self.data = [aDecoder decodeObjectForKey:DATAKEY];

self.loopBegin = [aDecoder decodeIntForKey:LOOPBEGINKEY];

self.loopSize = [aDecoder decodeIntForKey:LOOPSIZEKEY];

self.volume = [[aDecoder decodeObjectForKey:VOLUMEKEY] unsignedCharValue];

self.c2spd = [[aDecoder decodeObjectForKey:C2SPDKEY] unsignedShortValue];

self.loopType = [[aDecoder decodeObjectForKey:LOOPTYPEKEY] unsignedCharValue];

self.amplitude = [[aDecoder decodeObjectForKey:AMPLITUDEKEY] unsignedCharValue];

self.relativeNote = [[aDecoder decodeObjectForKey:RELATIVENOTEKEY] charValue];

self.stereo = [aDecoder decodeBoolForKey:STEREOKEY];

self.sampleIndex = [aDecoder decodeIntegerForKey:SAMPLEINDEXKEY];

self.instrumentIndex = [aDecoder decodeIntegerForKey:INSTRUMENTINDEXKEY];

}

return self;

}

@end

SourceForge

Create a Project

Open Source Software

Business Software

Top Downloaded Projects

Company

About

Team

SourceForge Headquarters
225 Broadway Suite 1600
San Diego, CA 92101
+1 (858) 422-6466

Resources

Support

Site Documentation

Site Status

SourceForge Reviews

© 2025 Slashdot Media. All Rights Reserved.

Terms Privacy Opt Out Advertise

×
Want the latest updates on software, tech news, and AI?

Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.

Submit