#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import "TuneView.h"
#import "TunePlayer.h"
#import "TuneParser.h"

@class Tune;
@class Playlist;
@class EditABCController;
@class TuneSettingsController;

@interface TuneViewController : UIViewController <UIScrollViewDelegate, UIActionSheetDelegate, 
#if __IPHONE_3_2
  UIPopoverControllerDelegate, 
#endif
  MFMailComposeViewControllerDelegate, TuneParserDelegate>
{
  UIScrollView *scrollView;
  IBOutlet UIView *mainView;
  IBOutlet UIToolbar *toolbar;
  IBOutlet UIBarButtonItem *rewindButton;
  IBOutlet UIBarButtonItem *playButton;
  IBOutlet UIBarButtonItem *pauseButton;
  IBOutlet UIBarButtonItem *emailButton;
  IBOutlet UIBarButtonItem *abcButton;
  EditABCController *editController;
  BOOL showingABC;
  TuneSettingsController *settingsController;
  BOOL showingSettings;

	TuneView *tuneView;
  Tune *tune;
  Playlist *playlist;
  NSInteger currentPage;
  NSString *savedDots;
  BOOL barsHidden;
  NSMutableArray *playItems;
  NSMutableArray *stopItems;
  int numTunes;
  int numPages;
  NSMutableArray *parsedTunes;
  UIActionSheet *saveChangesSheet;
  UIActionSheet *multipleTunesSheet;

#if __IPHONE_3_2
  IBOutlet UIBarButtonItem *editButton;
  UIActionSheet*       activeActionSheet;
  UIBarButtonItem*     activeBarButtonItem;
  UIPopoverController* activePopoverController;
  UIActionSheet*       rotateActionSheet;
  UIBarButtonItem*     rotateBarButtonItem;
  NSArray*             rotatePassthroughViews;
  UIViewController*    rotateViewController;
#endif
}

@property(retain) id<TuneViewDelegate> tuneViewDelegate;
@property(retain,readwrite) Tune *tune;
@property(retain,readwrite) Playlist *playlist;
@property(retain,readwrite) NSString *savedDots;

- (id)initWithTune:(Tune *)tune;

- (void)editABC;
- (void)showMusic;
- (void)showABC;
- (void)hideSettings;
- (void)viewTapped:(id)sender;
- (void)viewDoubleTapped:(id)sender;
- (void)finishedPlaying:(id)sender;

- (IBAction)startPlaying:(id)sender;
- (IBAction)stopPlaying:(id)sender;
- (IBAction)pausePlaying:(id)sender;
- (IBAction)rewindPlaying:(id)sender;
- (IBAction)showSettings:(id)sender;
- (IBAction)emailTune:(id)sender;
- (IBAction)zoomToFit:(id)sender;

- (void)showPage:(NSInteger)page;
- (IBAction)prevTune:(id)sender;
- (IBAction)nextTune:(id)sender;

#if __IPHONE_3_2
- (IBAction)tunesPressed:(id)sender;
- (IBAction)tunebooksPressed:(id)sender;
- (IBAction)searchPressed:(id)sender;
- (IBAction)managePressed:(id)sender;
- (IBAction)settingsPressed:(id)sender;
- (IBAction)editPressed:(id)sender;

- (void)showTune:(Tune *)tune;
- (void)showTune:(Tune *)tune fromPlayList:(Playlist *)playlist;
- (void)dotsChanged;

- (void)presentPopoverController:(UIBarButtonItem *)item controller:(UIViewController*)controller;
- (void)dismissPopoverController;
#endif

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;     // return a view that will be scaled. if delegate returns nil, nothing happens
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale; // scale between minimum and maximum. called after any 'bounce' animations
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;

- (void)displayComposerSheet;
- (void)launchMailAppOnDevice;

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error;

- (void) parsedTune:(TuneParser *)parser tune:(Tune *)tune;

@end
