home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / PlayerPRO 4.5.8 / PlayerPRO 4.5.8 Dev.Kit / MADH Library 4.5 / BeOS Examples / mainMADSimple.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-25  |  3.1 KB  |  162 lines  |  [TEXT/EDIT]

  1. #include <Application.h>
  2. #include <View.h>
  3. #include <Window.h>
  4. #include <Bitmap.h>
  5. #include <fcntl.h>
  6. #include <debugger.h>
  7.  
  8. #include "RDriver.h"
  9. #include "mainMADSimple.h"
  10.  
  11. //---------------------------------------------
  12.  
  13. class MADWindow : public BWindow {
  14.  
  15. public:
  16.                 MADWindow(BRect frame);
  17.                 void MessageReceived(BMessage *msg);
  18.                 
  19. virtual    bool    QuitRequested();
  20. };
  21.  
  22. //---------------------------------------------
  23.  
  24. class MADView : public BView {
  25.  
  26. public:
  27.                 MADView(BRect frame, char *name); 
  28. virtual    void    AttachedToWindow();
  29. virtual    void    Draw(BRect updateRect);
  30. };
  31.  
  32. //---------------------------------------------
  33.  
  34. main()
  35. {
  36.     MyApp* curApp = new MyApp('SNPL');
  37.     
  38.     curApp->Run();
  39.     
  40.     delete curApp;
  41.  
  42.     return 0;
  43. }
  44. //---------------------------------------------
  45.  
  46.  
  47. MyApp::MyApp( ulong signature) : BApplication(signature)
  48. {
  49.     MADDriverSettings    init;
  50.     
  51.     init.numChn                        = 4;
  52.     init.outPutBits                 = 16;
  53.     init.outPutRate                    = 44100L << 16L;
  54.     init.outPutMode                    = DeluxeStereoOutPut;
  55.     init.driverMode                    = BeOSSoundDriver;
  56.     init.antiAliasing                = false;
  57.     init.repeatMusic                = true;
  58.     init.Interpolation                = true;
  59.     init.MicroDelay                    = true;
  60.     init.MicroDelaySize             = 50;
  61.     init.surround                     = false;
  62.     init.sysMemory                    = false;
  63.     init.Reverb                        = false;
  64.     init.ReverbSize                    = 45;
  65.     init.ReverbStrength                = 60;
  66.     init.TickRemover                = true;
  67.  
  68.     myMADDriverClass = new MADDriverClass( &init);
  69.     
  70.     
  71.     
  72.     MADWindow        *aWindow;
  73.     MADView            *aView;
  74.     BRect            aRect;
  75.  
  76.     // set up a rectangle and instantiate a new window
  77.     aRect.Set(40, 40, 400, 80);
  78.     aWindow = new MADWindow(aRect);
  79.     
  80.     // set up a rectangle and instantiate a new view
  81.     // view rect should be same size as window rect but with left top at (0, 0)
  82.     aRect.OffsetTo(B_ORIGIN);
  83.     aView = new MADView(aRect, "MADText");
  84.     
  85.     // add view to window
  86.     aWindow->AddChild(aView);
  87.     
  88.     // make window visible
  89.     aWindow->Show();
  90. }
  91.  
  92. MyApp::~MyApp()
  93. {
  94.     delete myMADDriverClass;
  95. }
  96.  
  97. /* Files dropped on the application will end up here */
  98.  
  99. void MyApp::RefsReceived (BMessage * message)
  100. {
  101.     for (int cnt = 0; ; cnt++)
  102.     {
  103.         if (message->HasRef("refs", cnt))
  104.         {
  105.             record_ref refs = message->FindRef("refs", cnt);
  106.             
  107.             if (does_ref_conform(refs, "File"))
  108.             {
  109.                 BFile file(refs);
  110.                 myMADDriverClass->LoadMusic(file);
  111.             }
  112.         }
  113.         else break;
  114.     }
  115. }
  116.  
  117. //-----------------------------------------------------
  118.  
  119. MADWindow::MADWindow(BRect frame)
  120.                 : BWindow(frame, "MADDriver", B_TITLED_WINDOW, B_NOT_RESIZABLE)
  121. {
  122. }
  123.  
  124. void MADWindow::MessageReceived(BMessage *msg)
  125. {
  126.     if (msg->what == B_SIMPLE_DATA)
  127.     {
  128.         BMessage* msg2 = new BMessage( msg);
  129.         msg2->what = B_REFS_RECEIVED;
  130.         be_app->PostMessage(msg2);
  131.     }
  132.     else BWindow::MessageReceived( msg);
  133. }
  134.  
  135. bool MADWindow::QuitRequested()
  136. {
  137.     be_app->PostMessage(B_QUIT_REQUESTED);
  138.     return(TRUE);
  139. }
  140.  
  141.  
  142. //------------------------------------------------------
  143.  
  144. MADView::MADView(BRect rect, char *name)
  145.               : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW)
  146. {
  147. }
  148.  
  149.  
  150. void MADView::AttachedToWindow()
  151. {
  152.     SetFontName("Times New Roman");
  153.     SetFontSize(18);
  154. }
  155.  
  156.  
  157. void MADView::Draw(BRect)
  158. {
  159.     MovePenTo(BPoint(10, 30));
  160.     DrawString("Drag a MADH music on this window!");
  161. }
  162.