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

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

@interface TextLayer : CALayer
{
  UITextAlignment alignment;
}

@property (nonatomic) UITextAlignment alignment;

@end

@interface TuneViewController : UIViewController <UIScrollViewDelegate, UIActionSheetDelegate, 
#if TARGET_IPAD
  UIPopoverControllerDelegate, 
#endif
  MFMailComposeViewControllerDelegate, UIPrintInteractionControllerDelegate, TuneViewDelegate, TuneParserDelegate>
{
  UIScrollView *scrollView;
  IBOutlet UIView *mainView;
  IBOutlet UIToolbar *toolbar;
  IBOutlet UIBarButtonItem *rewindButton;
  IBOutlet UIBarButtonItem *playButton;
  IBOutlet UIBarButtonItem *pauseButton;
  IBOutlet UIBarButtonItem *emailButton;
  IBOutlet UIBarButtonItem *abcButton;
  IBOutlet UIBarButtonItem *printButton;
  IBOutlet UIBarButtonItem *printSpacer;
  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 TARGET_IPAD
  IBOutlet UIBarButtonItem *editButton;
  UIActionSheet*       activeActionSheet;
  UIBarButtonItem*     activeBarButtonItem;
  UIPopoverController* activePopoverController;
  UIActionSheet*       rotateActionSheet;
  UIBarButtonItem*     rotateBarButtonItem;
  NSArray*             rotatePassthroughViews;
  UIViewController*    rotateViewController;
  UIImageView* background;
#endif

  TextLayer* messageLayer;
}

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

- (id)initWithTune:(Tune *)tune;
- (id)initWithTune:(Tune *)tune fromPlayList:(Playlist *)playlist;

- (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)printTune:(id)sender;
- (IBAction)zoomToFit:(id)sender;

- (IBAction)prevTune:(id)sender;
- (IBAction)nextTune:(id)sender;

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

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

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

- (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
