Skip to content

Commit

Permalink
Refinements every little where
Browse files Browse the repository at this point in the history
  • Loading branch information
nevyn committed May 18, 2008
1 parent 5d09c68 commit f9db1c4
Show file tree
Hide file tree
Showing 11 changed files with 480 additions and 100 deletions.
1 change: 1 addition & 0 deletions CfxrDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@class Sound;
@interface CfxrDocument : NSPersistentDocument {
IBOutlet NSArrayController *soundsController;
IBOutlet NSTableView *soundsTable;
}

-(IBAction)generateSound:(id)sender;
Expand Down
21 changes: 16 additions & 5 deletions CfxrDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ - (NSString *)windowNibName
- (void)windowControllerDidLoadNib:(NSWindowController *)windowController
{
[super windowControllerDidLoadNib:windowController];
if([[soundsController arrangedObjects] count] == 0)
if([Sound countInContext:[self managedObjectContext]] == 0)
[self generateSoundFromCategory:@"Empty"];

[Playback playback]; // Nudge Playback class to have it initialize
// Sort by inverse index by default
NSSortDescriptor* sortDescriptor = [[NSSortDescriptor alloc]
initWithKey: @"index" ascending: NO
selector:@selector(compare:)];
[soundsController setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
[sortDescriptor release];

soundsTable.delegate = self;
}

-(IBAction)generateSound:(id)sender;
Expand All @@ -40,11 +46,11 @@ -(Sound*)generateSoundFromCategory:(NSString*)category;
inManagedObjectContext:[self managedObjectContext]];
[sound generateParamsFromCategory:category];

const int n = [[soundsController arrangedObjects] count] + 1;
sound.name = [NSString stringWithFormat:@"%03d %@", n, category];
sound.name = category;

[soundsController setSelectedObjects:[NSArray arrayWithObject:sound]];
[[Playback playback] play:sound];
[soundsController rearrangeObjects];
return sound;
}

Expand All @@ -55,5 +61,10 @@ -(IBAction)play:(id)sender;

}

- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
{
[self play:nil];
}


@end
Binary file modified CfxrDocument.xcdatamodel/elements
Binary file not shown.
Binary file modified CfxrDocument.xcdatamodel/layout
Binary file not shown.
444 changes: 364 additions & 80 deletions English.lproj/CfxrDocument.xib

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions Playback.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ -(id)init;
-(Sound*)playingSound; { return ps; };
-(void)setPlayingSound:(Sound*)newPs; {
[newPs retain]; [ps release]; ps = newPs;
sound_vol = ps.volume.floatValue;

}

-(void)play:(Sound*)sound;
Expand Down Expand Up @@ -277,7 +277,7 @@ -(void) synthSample:(int)length :(float*)buffer :(FILE*)file;
}
ssample=ssample/8*master_vol;

ssample*=2.0f*sound_vol;
ssample*=2.0f*ps.sound_vol;

if(buffer!=NULL)
{
Expand All @@ -294,11 +294,11 @@ -(void) synthSample:(int)length :(float*)buffer :(FILE*)file;
if(ssample<-1.0f) ssample=-1.0f;
filesample+=ssample;
fileacc++;
if(wav_freq==44100 || fileacc==2)
if(ps.wav_freq==44100 || fileacc==2)
{
filesample/=fileacc;
fileacc=0;
if(wav_bits==16)
if(ps.wav_bits==16)
{
short isample=(short)(filesample*32000);
fwrite(&isample, 1, 2, file);
Expand Down Expand Up @@ -360,13 +360,13 @@ -(bool)exportWAV:(char*)filename;
fwrite(&word, 1, 2, foutput); // compression code
word=1;
fwrite(&word, 1, 2, foutput); // channels
dword=wav_freq;
dword=ps.wav_freq;
fwrite(&dword, 1, 4, foutput); // sample rate
dword=wav_freq*wav_bits/8;
dword=ps.wav_freq*ps.wav_bits/8;
fwrite(&dword, 1, 4, foutput); // bytes/sec
word=wav_bits/8;
word=ps.wav_bits/8;
fwrite(&word, 1, 2, foutput); // block align
word=wav_bits;
word=ps.wav_bits;
fwrite(&word, 1, 2, foutput); // bits per sample

fwrite("data", 4, 1, foutput); // "data"
Expand All @@ -387,10 +387,10 @@ -(bool)exportWAV:(char*)filename;
// seek back to header and write size info
fseek(foutput, 4, SEEK_SET);
dword=0;
dword=foutstream_datasize-4+file_sampleswritten*wav_bits/8;
dword=foutstream_datasize-4+file_sampleswritten*ps.wav_bits/8;
fwrite(&dword, 1, 4, foutput); // remaining file size
fseek(foutput, foutstream_datasize, SEEK_SET);
dword=file_sampleswritten*wav_bits/8;
dword=file_sampleswritten*ps.wav_bits/8;
fwrite(&dword, 1, 4, foutput); // chunk size (data)
fclose(foutput);

Expand Down
8 changes: 7 additions & 1 deletion Sound+legacyAccessors.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
@property (retain) NSNumber * lowpassFilterCutoffSweep;
@property (retain) NSNumber * lowpassFilterResonance;
@property (retain) NSNumber * minFrequencyCutoff;
@property (retain) NSString * name;
@property (retain) NSNumber * waveType;
@property (retain) NSNumber * phaserOffset;
@property (retain) NSNumber * phaserSweep;
Expand All @@ -39,9 +38,16 @@
@property (retain) NSNumber * vibratoDepth;
@property (retain) NSNumber * vibratoSpeed;
@property (retain) NSNumber * volume;
@property (retain) NSString * name;
@property (retain) NSNumber * index;
@property (retain) NSNumber * rating;


@property (assign) float sound_vol;

@property (assign) int wave_type; // waveType
@property (assign) int wav_bits;
@property (assign) int wav_freq;
@property (assign) float p_base_freq; // startFrequency
@property (assign) float p_freq_limit; // minFrequencyCutoff
@property (assign) float p_freq_ramp; // slide
Expand Down
40 changes: 37 additions & 3 deletions Sound+legacyAccessors.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"p_pha_ramp": "phaserSweep",
"p_repeat_speed": "repeatSpeed",
"p_arp_speed": "changeSpeed",
"p_arp_mod": "changeAmount"
"p_arp_mod": "changeAmount",
"sound_vol": "volume"
}
for legacyValue in legacyMap:
Expand Down Expand Up @@ -62,7 +63,6 @@ @implementation Sound (LegacyAccessors)
@dynamic lowpassFilterCutoffSweep;
@dynamic lowpassFilterResonance;
@dynamic minFrequencyCutoff;
@dynamic name;
@dynamic phaserOffset;
@dynamic phaserSweep;
@dynamic repeatSpeed;
Expand All @@ -77,17 +77,51 @@ @implementation Sound (LegacyAccessors)
@dynamic volume;
@dynamic waveType;

// Todo: Wave type
@dynamic name;
@dynamic index;
@dynamic rating;

-(int)wave_type;
{
return [self.waveType intValue];
}

-(void)setWave_type:(int)waveType;
{
self.waveType = [NSNumber numberWithInt:waveType];
}

-(float)sound_vol;
{
return [self.volume floatValue]/100;
}

-(void)setSound_vol:(float)newVol;
{
self.volume = [NSNumber numberWithInt:newVol*100.0];
}

-(int)wav_bits;
{
return [self.bitDepth intValue];
}

-(void)setWav_bits:(int)w;
{
self.bitDepth = [NSNumber numberWithInt:w];
}

-(int)wav_freq;
{
return [self.sampleRate intValue];
}

-(void)setWav_freq:(int)w;
{
self.sampleRate = [NSNumber numberWithInt:w];
}

/// GENERATED:
-(float)p_duty_ramp;
{
return [self.dutySweep floatValue];
Expand Down
2 changes: 2 additions & 0 deletions Sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
@interface Sound : NSManagedObject {
bool filter_on;// = false
}
+(NSInteger)countInContext:(NSManagedObjectContext*)ctx;
+(NSInteger)highestIndexInContext:(NSManagedObjectContext*)ctx;

-(void)generateParamsFromCategory:(NSString*)templateName;

Expand Down
43 changes: 42 additions & 1 deletion Sound.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,49 @@
#import "common.h"

@implementation Sound
// todo: srand(time(NULL));
+(NSInteger)countInContext:(NSManagedObjectContext*)moc;
{
NSEntityDescription *entityDescription = [NSEntityDescription
entityForName:@"Sound" inManagedObjectContext:moc];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity:entityDescription];

NSArray *array = [moc executeFetchRequest:request error:nil];
if (array == nil)
{
return 0;
}
return [array count];
}

+(NSInteger)highestIndexInContext:(NSManagedObjectContext*)moc;
{
NSEntityDescription *entityDescription = [NSEntityDescription
entityForName:@"Sound" inManagedObjectContext:moc];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity:entityDescription];

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]
initWithKey:@"index" ascending:NO];
[request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
[sortDescriptor release];

[request setFetchLimit:1];

NSArray *array = [moc executeFetchRequest:request error:nil];
if (array == nil)
{
return 1;
}
Sound *s = [array objectAtIndex:0];
return s.index.intValue;
}


- (void)awakeFromInsert
{
self.index = [NSNumber numberWithInt:[Sound highestIndexInContext:[self managedObjectContext]]+1];
}
-(void)generateParamsFromCategory:(NSString*)templateName;
{
if([@"Pickup/coin" isEqualToString:templateName]) {
Expand Down
1 change: 1 addition & 0 deletions main.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@

int main(int argc, char *argv[])
{
srand(time(NULL));
return NSApplicationMain(argc, (const char **) argv);
}

0 comments on commit f9db1c4

Please sign in to comment.