Playlist Generator
1.0
|
00001 // 00002 // EchonestPlaylistParameterViewController.m 00003 // Playlist2 00004 // 00005 // Created by Max Woolf on 10/12/2011. 00006 // Copyright (c) 2011 __MyCompanyName__. All rights reserved. 00007 // 00008 00009 #import "EchonestPlaylistParameterViewController.h" 00010 #import "MBProgressHUD.h" 00011 #import "ReadPlaylistSuggestions.h" 00012 #import "DisplayPlaylistViewController.h" 00013 #import "AnalysedPlaylistConnection.h" 00014 00015 @implementation EchonestPlaylistParameterViewController 00016 @synthesize trackWasIdentified; 00017 - (void)didReceiveMemoryWarning 00018 { 00019 // Releases the view if it doesn't have a superview. 00020 [super didReceiveMemoryWarning]; 00021 00022 // Release any cached data, images, etc that aren't in use. 00023 } 00024 00025 #pragma mark - Initialisation 00026 -(void)setTrackID:(NSString *)inputID 00027 { 00028 if(songID != inputID) 00029 { 00030 songID = inputID; 00031 } 00032 } 00033 00034 -(void)setDictionaryData:(NSDictionary *)inputDict 00035 { 00036 if(analysisData != inputDict) 00037 { 00038 analysisData = inputDict; 00039 } 00040 } 00041 00042 #pragma mark - Value Changes 00043 -(IBAction)tracksStepperValueChange:(id)sender 00044 { 00045 //Cast value to make int, gets rid of those pesky decimals 00046 numberOfTracks = (int)tracksStepper.value; 00047 [tracksButton setTitle:[NSString stringWithFormat:@"%i", numberOfTracks]forState:UIControlStateNormal]; 00048 } 00049 00050 -(IBAction)danceSliderValueChange:(id)sender 00051 { 00052 danceability = danceSlider.value; 00053 } 00054 -(IBAction)varietySliderValueChange:(id)sender 00055 { 00056 variety = varietySlider.value; 00057 } 00058 00059 #pragma mark - Generation 00060 -(void)buttonPressed:(id)sender 00061 { 00062 HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view]; 00063 [self.navigationController.view addSubview:HUD]; 00064 [HUD setMode:MBProgressHUDModeIndeterminate]; 00065 [HUD setLabelText:@"Please Wait"]; 00066 [HUD show:YES]; 00067 if(trackWasIdentified) 00068 { 00069 //Run a similar connection on the identified track ID 00070 connection = [[EchonestSimilarConnection alloc] initWithRequest:nil delegate:self trackID:songID danceability:danceability variety:variety numberOfTracks:numberOfTracks]; 00071 [connection start]; 00072 }else{ 00073 //Run a connection based on the musical data collection 00074 connection = [[AnalysedPlaylistConnection alloc] initWithDanceability:[analysisData valueForKey:@"Danceability"] energy:[analysisData valueForKey:@"Energy"] tempo:[analysisData valueForKey:@"Tempo"] key:[analysisData valueForKey:@"Key"] mode:[analysisData valueForKey:@"Mode"] results:[NSString stringWithFormat:@"%i",numberOfTracks] delegate:self]; 00075 [connection start]; 00076 } 00077 00078 } 00079 00080 #pragma mark - URL Connection Delegate 00081 //Wait for response! 00082 - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { 00083 //Just initate the NSData regardless of who made the request. 00084 [receivedData setLength:0]; 00085 } 00086 00087 - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 00088 { 00089 NSLog(@"%@", [error localizedDescription]); 00090 } 00091 00092 - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)d { 00093 ReadPlaylistSuggestions *jsonReader = [[ReadPlaylistSuggestions alloc] initWithJsonData:d]; 00094 DisplayPlaylistViewController *playlistVC = [[DisplayPlaylistViewController alloc] initWithArtistArray:[jsonReader getArtistList] tracksArray:[jsonReader getTrackList]]; 00095 [self.navigationController pushViewController:playlistVC animated:YES]; 00096 [HUD removeFromSuperview]; 00097 } 00098 00099 #pragma mark - View lifecycle 00100 00101 - (void)viewDidLoad 00102 { 00103 //If the track wasn't identified, get rid of the settings. 00104 if(!trackWasIdentified) 00105 { 00106 [slidersView setAlpha:0]; 00107 } 00108 numberOfTracks = 10; 00109 [super viewDidLoad]; 00110 // Do any additional setup after loading the view from its nib. 00111 } 00112 00113 - (void)viewDidUnload 00114 { 00115 [super viewDidUnload]; 00116 // Release any retained subviews of the main view. 00117 // e.g. self.myOutlet = nil; 00118 } 00119 00120 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 00121 { 00122 // Return YES for supported orientations 00123 return (interfaceOrientation == UIInterfaceOrientationPortrait); 00124 } 00125 00126 @end