unit uMbrTradutor;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, mbrPlay{, mbrPort};

type
  TForm1 = class(TForm)
    e_texto: TEdit;
    b_compilar: TButton;
    Memo1: TMemo;
    Label1: TLabel;
    c_base: TComboBox;
    b_falar: TButton;
    b_parar: TButton;
    Button1: TButton;
    e_tradutor: TEdit;
    e_excessao: TEdit;
    Button2: TButton;
    procedure FormCreate(Sender: TObject);
    procedure b_pararClick(Sender: TObject);
    procedure b_falarClick(Sender: TObject);
    procedure c_baseSelect(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure b_compilarClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function DatabaseCallback(lpszID: PChar;
                          dwUserData: pointer): Bool ; stdcall {cdecl};
begin
     TComboBox(dwUserData^).Items.Add(String(lpszID));
     DatabaseCallback:=true;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
   sBuffer: array [0..250] of char;
   pError: pchar;
begin
    MBR_RegEnumDatabaseCallback (@DatabaseCallback, longint(@c_base));
    if c_base.Items.Count = 0 then
        begin
             MessageBox (Form1.Handle, 'Não há bases MBROLA registradas',
                         'Use Mbrola Control Panel para configurar', IDOK);
             Close;
        end
    else
        begin
            c_base.itemindex := MBR_RegIdxGetDefaultDatabase();
            if (Mbr_SetDatabase (PChar(c_base.Text)) <> 0) then
                begin
                    pError := @sBuffer[1];
                    Mbr_LastError (pError, 250);
                    MessageBox (Form1.Handle, pError, 'Erro', IDOK);
                end;
        end;
end;

procedure TForm1.b_pararClick(Sender: TObject);
begin
     MBR_Stop;
end;

procedure TForm1.b_falarClick(Sender: TObject);
var
     pText: array [0..250] of char;
begin
     if (Mbr_Play (
                   //'C:\Program Files\Mbrola Tools\br1\TEST\Euler.pho',
                   // MBR_BYFILE or MBR_WAIT,

                   pchar (Memo1.text),
                   0,
                   PChar(''),
                   0) <> 0) then
          begin
              Mbr_LastError (pText,250);
              if copy (strPas(pText), 1, 9) <> 'Cancelled' then
                  MessageBox (Form1.Handle, pText, 'Erro', IDOK);
          end;
end;

procedure TForm1.c_baseSelect(Sender: TObject);
var
   sBuffer: array [0..250] of char;
   pError: pchar;
begin
     if (Mbr_SetDatabase(PChar(c_base.Text)) <> 0) then
         begin
              pError := @sBuffer[1];
              Mbr_LastError(pError,250);
              MessageBox(Form1.Handle,pError,'Error',IDOK);
         end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
(*
    libMemTradutor;
    if not inicTradutor (e_tradutor.Text) then
        showMessage ('Erro na base do compilador')
    else
        if not carregaExcessoes (e_excessao.Text) then
            showMessage ('Erro da base de excessoes');
*)
end;

procedure TForm1.b_compilarClick(Sender: TObject);
var fonemas: string;
begin
(*
     compilaFonemas (e_texto.Text, fonemas);
     if length (fonemas) > 0 then
         memo1.SetTextBuf(@fonemas[1]);
*)
end;

end.

