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

[89e097]: / PlayerPRO 6 / Plug-ins / Instruments Import-Export Plugs / MINs / PPMINsPlug.m  Maximize  Restore  History

Download this file

294 lines (250 with data), 8.4 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

//

// PPMINsPlug.m

// PPMacho

//

// Created by C.W. Betts on 9/21/14.

//

//

#import "PPMINsPlug.h"

#include <PlayerPROCore/PlayerPROCore.h>

#import <PlayerPROKit/PlayerPROKit.h>

#define BYTESWAP_STRIDE 8

@interface PPInstrumentObject (private)

- (InstrData)theInstrument;

@end

static inline void ByteswapsData(sData *toswap)

{

MADBE32(&toswap->size);

MADBE16(&toswap->c2spd);

MADBE32(&toswap->loopBeg);

MADBE32(&toswap->loopSize);

}

static inline void ByteswapsData32(sData32 *toswap)

{

MADBE32(&toswap->size);

MADBE16(&toswap->c2spd);

MADBE32(&toswap->loopBeg);

MADBE32(&toswap->loopSize);

}

static inline void ByteswapInstrument(InstrData *toswap)

{

MADBE16(&toswap->MIDIType);

MADBE16(&toswap->MIDI);

MADBE16(&toswap->firstSample);

MADBE16(&toswap->numSamples);

MADBE16(&toswap->volFade);

for (int i = 0; i < 12; i++) {

MADBE16(&toswap->pannEnv[i].pos);

MADBE16(&toswap->pannEnv[i].val);

MADBE16(&toswap->pitchEnv[i].pos);

MADBE16(&toswap->pitchEnv[i].val);

MADBE16(&toswap->volEnv[i].pos);

MADBE16(&toswap->volEnv[i].val);

}

}

static inline OSErr TestMINS(const InstrData *CC)

{

if (CC->type == 0 && CC->numSamples >= 0 && CC->numSamples < MAXSAMPLE)

return MADNoErr;

else

return MADFileNotSupportedByThisPlug;

}

@implementation PPMINsPlug

- (BOOL)hasUIForExport

{

return NO;

}

- (BOOL)hasUIForImport

{

return NO;

}

- (instancetype)initForPlugIn

{

return self = [self init];

}

- (BOOL)canImportInstrumentAtURL:(NSURL *)sampleURL

{

NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingFromURL:sampleURL error:NULL];

if (!readHandle) {

return NO;

}

size_t inOutCount = sizeof(InstrData);

//void *theSound = malloc(inOutCount);

NSMutableData *theSound = [[readHandle readDataOfLength:inOutCount] mutableCopy];

ByteswapInstrument(theSound.mutableBytes);

return TestMINS(theSound.bytes) == MADNoErr;

}

-(BOOL)importInstrumentAtURL:(NSURL *)sampleURL instrument:(out PPInstrumentObject *__autoreleasing *)outHeader driver:(PPDriver *)driver error:(NSError * _Nullable __autoreleasing * _Nonnull)error

{

NSError *otherErr = nil;

NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingFromURL:sampleURL error:&otherErr];

if (!readHandle) {

if (error) {

*error = [NSError errorWithDomain:PPMADErrorDomain code:MADReadingErr userInfo:@{NSUnderlyingErrorKey: otherErr}];

}

return NO;

}

PPInstrumentObject *InsHeader = [PPInstrumentObject new];

[InsHeader resetInstrument];

size_t inOutCount = sizeof(InstrData);

NSMutableData *aHeader = [[readHandle readDataOfLength:inOutCount] mutableCopy];

if (aHeader.length != inOutCount) {

if (error) {

*error = [NSError errorWithDomain:PPMADErrorDomain code:MADIncompatibleFile userInfo:nil];

}

return NO;

}

ByteswapInstrument(aHeader.mutableBytes);

const InstrData *ourData = aHeader.bytes;

{

InsHeader.name = [NSString stringWithCString:ourData->name encoding:NSMacOSRomanStringEncoding];

memcpy(InsHeader.what, ourData->what, 96);

for (int i = 0; i < 12; i++) {

[InsHeader replaceObjectInPanningEnvelopeAtIndex:i withObject:[[PPEnvelopeObject alloc] initWithEnvRec:ourData->pannEnv[i]]];

[InsHeader replaceObjectInVolumeEnvelopeAtIndex:i withObject:[[PPEnvelopeObject alloc] initWithEnvRec:ourData->volEnv[i]]];

[InsHeader replaceObjectInPitchEnvelopeAtIndex:i withObject:[[PPEnvelopeObject alloc] initWithEnvRec:ourData->pitchEnv[i]]];

}

InsHeader.volumeType = ourData->volType;

InsHeader.panningType = ourData->pannType;

InsHeader.volumeSize = ourData->volSize;

InsHeader.panningSize = ourData->pannSize;

InsHeader.pitchSize = ourData->pitchSize;

InsHeader.volumeSustain = ourData->volSus;

InsHeader.volumeBegin = ourData->volBeg;

InsHeader.volumeEnd = ourData->volEnd;

InsHeader.panningSustain = ourData->pannSus;

InsHeader.panningBegin = ourData->pannBeg;

InsHeader.panningEnd = ourData->pannEnd;

InsHeader.pitchSustain = ourData->pitchSus;

InsHeader.pitchBegin = ourData->pitchBeg;

InsHeader.pitchEnd = ourData->pitchEnd;

InsHeader.volumeFadeOut = ourData->volFade;

InsHeader.vibratoDepth = ourData->vibDepth;

InsHeader.vibratoRate = ourData->vibRate;

InsHeader.MIDI = ourData->MIDI;

switch (ourData->MIDIType) {

case 0:

default:

InsHeader.MIDIOut = NO;

InsHeader.soundOut = YES;

break;

case 1:

InsHeader.MIDIOut = YES;

InsHeader.soundOut = NO;

break;

case 2:

InsHeader.MIDIOut = YES;

InsHeader.soundOut = YES;

break;

case 3:

InsHeader.MIDIOut = NO;

InsHeader.soundOut = NO;

break;

}

}

for (int x = 0; x < ourData->numSamples; x++) {

sData *curData = MADCreateSampleRaw();

inOutCount = sizeof(sData32);

aHeader = [[readHandle readDataOfLength:inOutCount] mutableCopy];

if (aHeader.length != inOutCount) {

if (error) {

*error = [NSError errorWithDomain:PPMADErrorDomain code:MADIncompatibleFile userInfo:nil];

}

return NO;

}

ByteswapsData(aHeader.mutableBytes);

memcpy(curData, aHeader.bytes, inOutCount);

inOutCount = curData->size;

// Don't leak.

free(curData->data); curData->data = NULL;

curData->data = malloc(inOutCount);

NSData *sampData = [readHandle readDataOfLength:inOutCount];

if (sampData.length != inOutCount) {

if (error) {

*error = [NSError errorWithDomain:PPMADErrorDomain code:MADIncompatibleFile userInfo:nil];

}

return NO;

}

memcpy(curData->data, sampData.bytes, inOutCount);

#if __LITTLE_ENDIAN__

if (curData->amp == 16) {

short *shortPtr = (short*)curData->data;

dispatch_apply((curData->size / 2) / BYTESWAP_STRIDE, dispatch_get_global_queue(0, 0), ^(size_t i) {

size_t j = i * BYTESWAP_STRIDE;

MADBE16(&shortPtr[j+0]);

MADBE16(&shortPtr[j+1]);

MADBE16(&shortPtr[j+2]);

MADBE16(&shortPtr[j+3]);

MADBE16(&shortPtr[j+4]);

MADBE16(&shortPtr[j+5]);

MADBE16(&shortPtr[j+6]);

MADBE16(&shortPtr[j+7]);

});

for (int ll = (curData->size / 2) - ((curData->size / 2) % BYTESWAP_STRIDE); ll < curData->size / 2; ll++) {

MADBE16(&shortPtr[ll]);

}

}

#endif

[InsHeader addSampleObject:[[PPSampleObject alloc] initWithSData:curData]];

free(curData->data);

free(curData);

}

*outHeader = InsHeader;

return YES;

}

- (BOOL)exportInstrument:(PPInstrumentObject *)InsHeader toURL:(NSURL *)sampleURL driver:(PPDriver *)driver error:(NSError * _Nullable __autoreleasing * _Nonnull)error

{

NSError *otherErr = nil;

NSFileHandle *fileHand = [NSFileHandle fileHandleForWritingToURL:sampleURL error:&otherErr];

if (fileHand == nil) {

if (error) {

*error = [NSError errorWithDomain:PPMADErrorDomain code:MADWritingErr userInfo:@{NSUnderlyingErrorKey: otherErr}];

}

return NO;

}

size_t inOutCount = sizeof(InstrData);

InstrData *tempIns = malloc(inOutCount);

InstrData headerData = [InsHeader theInstrument];

memcpy(tempIns, &headerData, sizeof(InstrData));

ByteswapInstrument(tempIns);

[fileHand writeData:[NSData dataWithBytesNoCopy:tempIns length:inOutCount]];

for (PPSampleObject *samp in [InsHeader samples]) {

sData32 toWrite = {0};

toWrite.amp = samp.amplitude;

toWrite.c2spd = samp.c2spd;

toWrite.loopBeg = samp.loopBegin;

toWrite.loopSize = samp.loopSize;

toWrite.loopType = samp.loopType;

toWrite.realNote = samp.realNote;

toWrite.stereo = samp.stereo;

toWrite.vol = samp.volume;

toWrite.size = (int)[samp.data length];

strlcpy(toWrite.name, [samp.name cStringUsingEncoding:NSMacOSRomanStringEncoding], sizeof(toWrite.name));

ByteswapsData32(&toWrite);

[fileHand writeData:[NSData dataWithBytes:&toWrite length:sizeof(sData32)]];

NSMutableData *sDataData = [samp.data mutableCopy];

#if __LITTLE_ENDIAN__

if (samp.amplitude == 16) {

short *shortPtr = (short*)sDataData.mutableBytes;

dispatch_apply((sDataData.length / 2) / BYTESWAP_STRIDE, dispatch_get_global_queue(0, 0), ^(size_t i) {

size_t j = i * BYTESWAP_STRIDE;

MADBE16(&shortPtr[j+0]);

MADBE16(&shortPtr[j+1]);

MADBE16(&shortPtr[j+2]);

MADBE16(&shortPtr[j+3]);

MADBE16(&shortPtr[j+4]);

MADBE16(&shortPtr[j+5]);

MADBE16(&shortPtr[j+6]);

MADBE16(&shortPtr[j+7]);

});

for (NSInteger i = (sDataData.length / 2) - ((sDataData.length / 2) % BYTESWAP_STRIDE); i < sDataData.length / 2; i++) {

MADBE16(&shortPtr[i]);

}

}

#endif

[fileHand writeData:sDataData];

}

[fileHand closeFile];

return YES;

}

@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