home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 14 / MA_Cover_14.iso / source / c / pegase_src / display.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-14  |  8.8 KB  |  364 lines

  1. /*
  2. **
  3. ** Display.cpp
  4. **
  5. ** (c) 1999 Didier Levet
  6. **
  7. ** Fonctions d'affichage
  8. **
  9. **
  10. */
  11.  
  12. #ifndef  CLIB_EXEC_PROTOS_H
  13. #include <clib/exec_protos.h>
  14. #endif
  15.  
  16. #ifndef  CLIB_INTUITION_PROTOS_H
  17. #include <clib/intuition_protos.h>
  18. #endif
  19.  
  20. #ifndef  CLASS_DISPLAY_HPP
  21. #include "Display.hpp"
  22. #endif
  23.  
  24. #ifndef _FILEINFOS_CLASS_HPP
  25. #include "FileInfosC.hpp"
  26. #endif
  27.  
  28. #ifndef  _PEGASE_HPP
  29. #include "Pegase.hpp"
  30. #endif
  31.  
  32. //========== Localisation.
  33.  
  34. #define CATCOMP_ARRAY
  35. #ifndef  PEGASE_H
  36. #include "Pegase.h"                     // Localisation.
  37. #endif
  38.  
  39.  
  40. static const char _CatName[] = "Pegase.catalog";
  41. extern const char *_verstr_;
  42.  
  43.  
  44. //----------------------------------------------------------------------------------------------------
  45. //=========================================== Localisation ===========================================
  46. //----------------------------------------------------------------------------------------------------
  47.  
  48. extern struct Library *LocaleBase;
  49.  
  50. static LocalStrings local;
  51.  
  52.  
  53. /// LocalStrings::LocalStrings()
  54. /****** class LocalStrings/CONSTRUCTOR **************************************
  55. *
  56. *   NAME
  57. *   LocalStrings::LocalStrings -- Constructeur
  58. *
  59. *   SYNOPSIS
  60. *   LocalStrings::LocalStrings()
  61. *
  62. *   LocalStrings::LocalStrings();
  63. *
  64. *   FUNCTION
  65. *   Initialise le catalogue.
  66. *
  67. *   BUGS
  68. *
  69. *****************************************************************************
  70. *
  71. */
  72.  
  73.  
  74. LocalStrings::LocalStrings() : pLocaleBase(NULL), pCatalog(NULL)
  75. {
  76.     if (::LocaleBase)
  77.         if ((pLocaleBase = ::OpenLocale(NULL)) != NULL)
  78.             pCatalog = ::OpenCatalogA(pLocaleBase, (STRPTR) ::_CatName, NULL);
  79. }
  80. ///
  81. /// LocalStrings::~LocalStrings()
  82. /****** class LocalStrings/DESTRUCTOR ***************************************
  83. *
  84. *   NAME
  85. *   LocalStrings::~LocalStrings -- Destructeur
  86. *
  87. *   SYNOPSIS
  88. *   LocalStrings::~LocalStrings()
  89. *
  90. *   LocalStrings::~LocalStrings();
  91. *
  92. *   FUNCTION
  93. *   Libère les ressources utilisées par la localisation.
  94. *
  95. *   BUGS
  96. *
  97. *****************************************************************************
  98. *
  99. */
  100.  
  101.  
  102. LocalStrings::~LocalStrings()
  103. {
  104.     if (::LocaleBase)
  105.     {
  106.         if (pCatalog)    ::CloseCatalog(pCatalog);
  107.         if (pLocaleBase) ::CloseLocale(pLocaleBase);
  108.     }
  109. }
  110. ///
  111. /// GetString()
  112. /****** Pegase/GetString ****************************************************
  113. *
  114. *   NAME
  115. *   GetString -- Obtenir la traduction d'une chaîne.
  116. *
  117. *   SYNOPSIS
  118. *   string = GetString(iStringID)
  119. *
  120. *   const char * GetString(long);
  121. *
  122. *   FUNCTION
  123. *   Retourne la chaîne localisée associée à l'identificateur passé en
  124. *   paramètre. Si la chaîne localisée n'existe pas, la chaîne originale
  125. *   est renvoyée à la place.
  126. *
  127. *   INPUTS
  128. *   iStringID - Numéro d'identification de la chaîne à retourner.
  129. *
  130. *   RESULT
  131. *   string - Chaîne localisée, ou chaîne originale.
  132. *
  133. *   NOTES
  134. *   Les chaînes originales sont en anglais.
  135. *
  136. *****************************************************************************
  137. *
  138. */
  139.  
  140.  
  141. STRING GetString(long iStringID)
  142. {
  143.     const int NUMSTRINGS = sizeof(CatCompArray)/sizeof(CatCompArray[0]);
  144.  
  145.     const struct CatCompArrayType *p = CatCompArray;
  146.  
  147.     for (int i = 0; i<NUMSTRINGS; i++, p++)
  148.     {
  149.         if (p->cca_ID == iStringID)
  150.         {
  151.             return local.read(iStringID, p->cca_Str);
  152.         }
  153.     }
  154.     return "<bad string ID>";
  155. }
  156. ///
  157.  
  158.  
  159. //----------------------------------------------------------------------------------------------------
  160. //========================================= class CLIDisplay =========================================
  161. //----------------------------------------------------------------------------------------------------
  162.  
  163. CLIDisplay::CLIDisplay()
  164. {
  165.     char buffer[256];
  166.     BPTR std_out;
  167.  
  168.     // buffer[0] == 0 && IoErr() == 209 : CON:
  169.     // buffer[0] == 0 && IoErr() == 0   : NIL:
  170.     // name defined   && IoErr() == 0   : FileName
  171.  
  172.     if ( (std_out = Output()) )
  173.     {
  174.         if ( (NameFromFH(std_out, buffer, 255) != DOSFALSE && buffer[0] != 0) || IoErr() == 0)
  175.             bDisableAnim = TRUE;
  176.     }
  177. }
  178.  
  179.  
  180. void Display::PrintErrorMsg(STRING msg)
  181. {
  182.     out() << ::GetString(MSG_ERROR_TXT) << " : " << msg << endl;
  183. }
  184.  
  185.  
  186. void Display::PrintDOSError(int errCode)
  187. {
  188.     char buffer[81];
  189.     ::Fault(errCode, NULL, buffer, sizeof(buffer));
  190.     PrintErrorMsg(buffer);
  191. }
  192.  
  193.  
  194. void Display::DisplayBanner()
  195. {
  196.     out() << endl << &_verstr_[6] << "\n";
  197.     out() << "© 1998-1999 Didier 'kakace' Levet\n";
  198.     out() << "----------------------------------------\n" << endl;
  199. }
  200.  
  201.  
  202. void Display::ShowConfig(const PegaseConfigC& rCfg)
  203. {
  204.     if (rCfg.IsVerbose())
  205.     {
  206.         out() << endl << ::GetString(MSG_DISPSETTINGS_SETUP_TXT) << " :\n";
  207.         out() << ::GetString(MSG_DISPSETTINGS_SOURCE_TXT) << " = ";
  208.  
  209.         // Afficher chaque fichier à encoder.
  210.  
  211.         if (rCfg.CurrentIndex())
  212.         {
  213.             ULONG iIndex = 0;
  214.  
  215.             out() << rCfg[iIndex++] << "\n";
  216.             for (; iIndex < rCfg.CurrentIndex(); ++iIndex)
  217.                 out() << " + " << rCfg[iIndex] << "\n";
  218.         }
  219.         else out() << "<" << ::GetString(MSG_NONE_TXT) << ">\n";
  220.  
  221.         out() << ::GetString(MSG_DISPSETTINGS_DEST_TXT) << " = " << rCfg.GetDestination() << "\n";
  222.         out() << ::GetString(MSG_DISPSETTINGS_PATTERN_TXT) << " = " << rCfg.GetPattern() << endl;
  223.  
  224.         ShowEncodingInfos(&rCfg);
  225.         out() << endl;
  226.     }
  227. }
  228.  
  229.  
  230. void Display::ShowEncodingInfos(const EncoderConfigC *pConfig)
  231. {
  232.     const char *yes = ::GetString(MSG_YES_TXT);
  233.     const char *no  = ::GetString(MSG_NO_TXT);
  234.     STRING s;
  235.  
  236.     // Afficher les réglages généraux.
  237.  
  238.     out() << ::GetString(MSG_ENCODING_MODE_TXT) << " ";
  239.     out() << ::GetString(MSG_DISPSETTINGS_LAYER_TXT) << " " << pConfig->GetLayer() + 1 << ", ";
  240.     out() << pConfig->GetBitRate() << " Kbits/s (" << pConfig->GetSampleFreq() << " Hz) ";
  241.  
  242.     switch (pConfig->GetEncodingMode())
  243.     {
  244.         case STEREO:
  245.             s = ::GetString(MSG_DISPSETTINGS_STEREO_TXT);
  246.             break;
  247.         case MONO:
  248.             s = ::GetString(MSG_DISPSETTINGS_MONO_TXT);
  249.             break;
  250.         case JOINTSTEREO:
  251.             s = ::GetString(MSG_DISPSETTINGS_JOINTSTEREO_TXT);
  252.             break;
  253.     }
  254.  
  255.     out() << s << endl;
  256.  
  257.     if (pConfig->IsCopyrighted() | pConfig->IsOriginal() | pConfig->IsCRC())
  258.     {
  259.         out() << ::GetString(MSG_DISPSETTINGS_FLAGS_TXT) << " ";
  260.         if (pConfig->IsCopyrighted()) out() << ::GetString(MSG_DISPSETTINGS_COPYRIGHT_TXT) << " ";
  261.         if (pConfig->IsOriginal())    out() << ::GetString(MSG_DISPSETTINGS_ORIGINAL_TXT) << " ";
  262.         if (pConfig->IsCRC())         out() << ::GetString(MSG_DISPSETTINGS_CRC_TXT) << " ";
  263.         out() << endl;
  264.     }
  265. }
  266.  
  267.  
  268. void Display::ShowCurrentJob(const FileInfosC *fi)
  269. {
  270.     u_Time t;
  271.  
  272.     out() << "\n==================================================\n";
  273.     out() << ::GetString(MSG_ENCODING_TXT) << " " << fi->NodeName() << " [" << fi->GetAudioName() << "]\n";
  274.     out() << ::GetString(MSG_DESTINATION_TXT) << " = " << fi->GetOutputName() << "\n";
  275.     out() << fi->GetNumFrames() << " " << ::GetString(MSG_DISPSETTINGS_SAMPLES_TXT) << ", ";
  276.     out() << ((fi->GetNumChannels() == 2) ? ::GetString(MSG_DISPSETTINGS_STEREO_TXT)
  277.                                          : ::GetString(MSG_DISPSETTINGS_MONO_TXT));
  278.     t = fi->GetTime();
  279.     if (t.iTime == 0x5858)
  280.     {
  281.         out() << " (--:--)" << endl;
  282.     }
  283.     else
  284.     {
  285.         out() << " (" << (short) t.sTime.bMinutes;
  286.         out() << ( (t.sTime.bSecondes < 10) ? ":0" : ":");
  287.         out() << (short) t.sTime.bSecondes << ")" << endl;
  288.     }
  289. }
  290.  
  291.  
  292. int Display::UpdateProgression(ULONG val, FileInfosC *fi)
  293. {
  294.     static int frame_cnt = 0;
  295.  
  296.     if (bDisableAnim == FALSE)
  297.     {
  298.         if (val == 0)
  299.         {
  300.             if (++mDotsDelay > 200)
  301.             {
  302.                 mDotsDelay = 0;
  303.                 out() << '.';
  304.             }
  305.         }
  306.         else
  307.         {
  308.             for (; mAnimVal <= val; mAnimVal += 2)
  309.             {
  310.                 if (mAnimVal % 10)  out() << '.';
  311.                 else                out() << mAnimVal << '%';
  312.             }
  313.         }
  314.         out().flush();
  315.     }
  316.  
  317.     int user_break = 0;
  318.  
  319.     if (++frame_cnt == CHECK_BREAK_DELAY) {
  320.         if ( (user_break = ::CheckSignal(SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D)) )
  321.         {
  322.             fi->SetIoError(IOERR_INTERNAL, ERROR_BREAK);
  323.         }
  324.         frame_cnt = 0;
  325.     }
  326.  
  327.     return user_break;
  328. }
  329.  
  330.  
  331. WBDisplay::WBDisplay()
  332. {
  333.     char window_specs[128];
  334.     const char *window_name = "CON:0/15/640/220/Pegase/AUTO/CLOSE/WAIT";
  335.  
  336.     if (!((struct Process *) ::FindTask(NULL))->pr_CLI)
  337.     {
  338.         // Lire la variable d'environnement
  339.  
  340.         if (::GetVar("PEGASE_WBCONSOLE", window_specs, sizeof(window_specs), GVF_GLOBAL_ONLY) > 0 && ::IoErr() < 128)
  341.         {
  342.             window_name = window_specs;     // Variable trouvée, et non tronquée.
  343.         }
  344.  
  345.         // Ouvrir la fenêtre de console.
  346.  
  347.         if ( (ostr = new ofstream) )
  348.             ostr->open(window_name);
  349.     }
  350.  
  351.     bFromWB = TRUE;
  352. }
  353.  
  354.  
  355. WBDisplay::~WBDisplay()
  356. {
  357.     if (ostr)
  358.     {
  359.         ostr->flush();
  360.         delete ostr;
  361.     }
  362. }
  363.  
  364.