VERSION 5.00
Begin VB.Form frmMode 
   BorderStyle     =   4  'Fixed ToolWindow
   Caption         =   "Choose Mode and Options"
   ClientHeight    =   6000
   ClientLeft      =   5220
   ClientTop       =   4110
   ClientWidth     =   4455
   ControlBox      =   0   'False
   Icon            =   "frmMode.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   6000
   ScaleWidth      =   4455
   Begin VB.CheckBox Check1 
      Caption         =   "Show Character on main screen (SAPI4 only)"
      Height          =   255
      Left            =   360
      TabIndex        =   18
      ToolTipText     =   "Display the animated character on the main screen"
      Top             =   3480
      Value           =   1  'Checked
      Width           =   3735
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Help"
      Height          =   375
      Left            =   1560
      TabIndex        =   17
      ToolTipText     =   "Mode help"
      Top             =   5520
      Width           =   1215
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Reset VH"
      Height          =   375
      Left            =   3000
      TabIndex        =   1
      ToolTipText     =   "Resets all of VH's settings, in case they get corrupted"
      Top             =   5520
      Width           =   1215
   End
   Begin VB.Frame Frame3 
      Caption         =   "Synthesized Speech"
      Height          =   1200
      Left            =   480
      TabIndex        =   6
      Top             =   1680
      Width           =   3495
      Begin VB.OptionButton Option9 
         Caption         =   "SAPI5 (new speech without characters)"
         Height          =   255
         Left            =   240
         TabIndex        =   9
         ToolTipText     =   "Use newer SAPI5 synthesized speech system"
         Top             =   840
         Width           =   3135
      End
      Begin VB.OptionButton Option8 
         Caption         =   "SAPI4 (recommended - speech with characters)"
         Height          =   375
         Left            =   240
         TabIndex        =   8
         ToolTipText     =   "Use standard SAPI4 synthesized speech system"
         Top             =   480
         Value           =   -1  'True
         Width           =   3135
      End
      Begin VB.OptionButton Option7 
         Caption         =   "Off"
         Height          =   255
         Left            =   240
         TabIndex        =   7
         ToolTipText     =   "Turn off synthesized speech"
         Top             =   240
         Width           =   2295
      End
   End
   Begin VB.CheckBox Check3 
      Caption         =   "Enable Speech Recognition (SAPI4 only)"
      Height          =   255
      Left            =   360
      TabIndex        =   11
      ToolTipText     =   "Enable support for speech recognition"
      Top             =   3240
      Value           =   1  'Checked
      Width           =   3735
   End
   Begin VB.Frame Frame2 
      Caption         =   "Mode"
      Height          =   855
      Left            =   480
      TabIndex        =   3
      Top             =   720
      Width           =   3495
      Begin VB.OptionButton Option6 
         Caption         =   "Self Hypnosis/Recreational"
         Height          =   255
         Left            =   600
         TabIndex        =   5
         ToolTipText     =   "Use recreational presets"
         Top             =   480
         Width           =   2535
      End
      Begin VB.OptionButton Option5 
         Caption         =   "Hypnotherapy/Professional"
         Height          =   255
         Left            =   600
         TabIndex        =   4
         ToolTipText     =   "Use professional presets"
         Top             =   240
         Width           =   2415
      End
   End
   Begin VB.CommandButton Command3 
      Caption         =   "OK"
      Default         =   -1  'True
      Height          =   375
      Left            =   120
      TabIndex        =   0
      Top             =   5520
      Width           =   1215
   End
   Begin VB.Frame Frame1 
      Caption         =   "System Tray Icon"
      Height          =   1335
      Left            =   1080
      TabIndex        =   12
      Top             =   3960
      Width           =   2415
      Begin VB.OptionButton Option3 
         Caption         =   "Minimize and close to tray"
         Height          =   255
         Left            =   120
         TabIndex        =   15
         ToolTipText     =   "Show system tray icon when program is minimized and closed"
         Top             =   720
         Width           =   2175
      End
      Begin VB.OptionButton Option4 
         Caption         =   "Tray icon always visible"
         Height          =   255
         Left            =   120
         TabIndex        =   16
         ToolTipText     =   "Always show system tray icon"
         Top             =   960
         Width           =   2055
      End
      Begin VB.OptionButton Option2 
         Caption         =   "Minimize to tray"
         Height          =   255
         Left            =   120
         TabIndex        =   14
         ToolTipText     =   "Show system tray icon only when program is minimized"
         Top             =   480
         Value           =   -1  'True
         Width           =   1455
      End
      Begin VB.OptionButton Option1 
         Caption         =   "Off"
         Height          =   255
         Left            =   120
         TabIndex        =   13
         ToolTipText     =   "Turn off system tray icon"
         Top             =   240
         Width           =   855
      End
   End
   Begin VB.CheckBox Check2 
      Caption         =   "Background Picture on main screen"
      Height          =   255
      Left            =   360
      TabIndex        =   10
      ToolTipText     =   "Enable the background picture on the main screen"
      Top             =   3000
      Value           =   1  'Checked
      Width           =   3735
   End
   Begin VB.Label Label1 
      Alignment       =   2  'Center
      Caption         =   "Please choose a mode for Virtual Hypnotist to run in, depending on your intended use, and select some other options:"
      Height          =   615
      Left            =   120
      TabIndex        =   2
      Top             =   120
      Width           =   4215
   End
End
Attribute VB_Name = "frmMode"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Virtual Hypnotist
'©2003-2008 FollowTheWatch Software
'http://vhypno.sourceforge.net
'http://sourceforge.net/projects/vhypno
'Contact - followthewatch55@yahoo.com

'This program is free software; you can redistribute it and/or
'modify it under the terms of the GNU General Public License
'as published by the Free Software Foundation; either version 2
'of the License, or (at your option) any later version.

'This program is distributed in the hope that it will be useful,
'but WITHOUT ANY WARRANTY; without even the implied warranty of
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'GNU General Public License for more details.

'You should have received a copy of the GNU General Public License
'along with this program; if not, write to the Free Software
'Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

Option Explicit
Private NoDialog As Boolean

Private Sub Command1_Click()
If MsgBox("Are you sure you want to erase Virtual Hypnotist's saved settings?" + vbCrLf + "Note: the program will exit afterwards - you will need to run it again", vbYesNo + vbExclamation + vbDefaultButton2, "Virtual Hypnotist") = vbNo Then Exit Sub

On Error Resume Next

'erase settings files
Dim fs, f, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.deletefile(App.path + "\settings.dat", True)
Set f = fs.deletefile(App.path + "\vh.ini", True)

'exit app
Unload frmMain
End Sub

Private Sub Command2_Click()
If ExceptionHandlers = True Then On Error GoTo ErrorHandler

Shell "hh " + App.path + "\vh.chm::/modes.html", vbNormalFocus
Exit Sub

ErrorHandler:
err.Source = "Mode Dialog - Command2"
   Call ErrorReport("An error occurred while loading Windows HTML Help.", vbExclamation)
  
End Sub

Private Sub Command3_Click()
'Test SAPI4 first
If Option8.value = True And SAPI4_On = False Then
    If TestSAPI4 = False Then Exit Sub
End If

If ExceptionHandlers = True Then On Error GoTo ErrorHandler
If Option5.value = True Then ModeVal = 1
If Option6.value = True Then ModeVal = 2
If ModeVal = 0 Then MsgBox "Please select a mode", vbExclamation: Exit Sub

Dim SkipModeBox As Boolean
Dim tempval As Integer
Dim i As Integer
SkipModeBox = True

'turn on SAPI4 if speech off or switch from SAPI5 to SAPI4
If Option8.value = True And MainScreenOn = True And (SynthSpeech = False Or UseSAPI5 = True) Then
    Set frmMain.Agent1 = New Agent
    Set frmMain.DSS = New DirectSS
    SAPI4_On = True
    SynthSpeech = True
    frmSession.chkTextOnly.value = 0
    If UseSAPI5 = True Then
        UseSAPI5 = False
        frmSession.sliderVoiceVolume.min = 1
        frmSession.sliderVoiceVolume.max = 65535
        'reset values
        frmSession.sliderVoiceVolume.value = 32767
        frmSession.sliderVoiceSpeed.max = 250
        frmSession.sliderVoiceSpeed.value = 100
        frmSession.sliderVoiceSpeed.min = 50
        frmSession.sliderVoicePitch.max = 400
        frmSession.sliderVoicePitch.value = 75
        frmSession.sliderVoicePitch.min = 50
        Set frmMain.Voice5 = Nothing
    End If
    CharacterFile = "angie.acs"
    
    Call frmSession.LoadSAPI
    frmSession.chkEnableChar.value = 1
    frmSession.SkipChar = True
    For i = 0 To (frmSession.fileCharacter.ListCount - 1)
        If LCase$(frmSession.fileCharacter.List(i)) = LCase$(CharacterFile) Then frmSession.fileCharacter.ListIndex = i
    Next i
    frmSession.SkipChar = False
    Call frmSession.fileCharacter_Click
End If

'turn on SAPI5 if speech off
If Option9.value = True And SynthSpeech = False And MainScreenOn = True Then
    SynthSpeech = True
    frmSession.chkTextOnly.value = 0
    UseSAPI5 = True
    Set frmMain.Voice5 = New SpVoice
    m_speakFlags = SVSFlagsAsync Or SVSFPurgeBeforeSpeak Or SVSFIsXML
    EngineName = "Microsoft Mary"
    CharacterFile = ""
    Call frmSession.LoadSAPI
End If

'turn off SAPI4
If Option7.value = True And SynthSpeech = True And UseSAPI5 = False And MainScreenOn = True Then
    SynthSpeech = False
    frmMain.Agent1.Characters.Unload "Hypnotist"
    Set Char = Nothing
    Set frmMain.Agent1 = Nothing
    Set frmMain.DSS = Nothing
    SAPI4_On = False
    frmSession.chkTextOnly.value = 1
End If

'turn off SAPI5
If Option7.value = True And SynthSpeech = True And UseSAPI5 = True And MainScreenOn = True Then
    SynthSpeech = False
    UseSAPI5 = False
    Set frmMain.Voice5 = Nothing
    frmSession.chkTextOnly.value = 1
End If

'switch from SAPI4 to SAPI5
If Option9.value = True And SynthSpeech = True And UseSAPI5 = False And MainScreenOn = True Then
    frmMain.Agent1.Characters.Unload "Hypnotist"
    Set Char = Nothing
    Set frmMain.Agent1 = Nothing
    Set frmMain.DSS = Nothing
    SAPI4_On = False
    frmSession.chkTextOnly.value = 0
    UseSAPI5 = True
    Set frmMain.Voice5 = New SpVoice
    m_speakFlags = SVSFlagsAsync Or SVSFPurgeBeforeSpeak Or SVSFIsXML
    EngineName = "Microsoft Mary"
    'convert values
    frmSession.sliderVoiceVolume.value = frmSession.sliderVoiceVolume.value / 655
    frmSession.sliderVoiceVolume.min = 1
    frmSession.sliderVoiceVolume.max = 100
    frmSession.sliderVoiceSpeed.min = -10
    tempval = frmSession.sliderVoiceSpeed.value - 100 'shift values over
    If tempval <= 0 Then frmSession.sliderVoiceSpeed.value = tempval / 5
    If tempval > 0 Then frmSession.sliderVoiceSpeed.value = tempval / 15
    frmSession.sliderVoiceSpeed.value = frmSession.sliderVoiceSpeed.value - 5
    frmSession.sliderVoiceSpeed.max = 10
    frmSession.sliderVoicePitch.min = -10
    tempval = frmSession.sliderVoicePitch.value - 100 'shift values over
    If tempval <= 0 Then frmSession.sliderVoicePitch.value = tempval / 5
    If tempval > 0 Then frmSession.sliderVoicePitch.value = tempval / 30
    frmSession.sliderVoicePitch.max = 10
    Call frmSession.LoadSAPI
End If

If MainScreenOn = False Then
    If Option7.value = False Then SynthSpeech = True Else SynthSpeech = False
End If
BackScreen = Check2.value
EnableSpeechRec = Check3.value
ShowCharacter = Check1.value

If SystemTrayIcon = 3 And MainScreenOn = True Then frmMain.Tray.Remove

If Option1.value = True Then SystemTrayIcon = 0
If Option2.value = True Then SystemTrayIcon = 1
If Option3.value = True Then SystemTrayIcon = 2
If Option4.value = True Then
    SystemTrayIcon = 3
    Set frmMain.Tray.Icon = frmMain.Icon
    frmMain.Tray.Tooltip = frmMain.Caption
    frmMain.Tray.Add
End If

WriteINIString 1, "settings", "skipmodebox", LTrim$(Str$(Abs(Int(SkipModeBox))))
WriteINIString 1, "settings", "mode", LTrim$(Str$(ModeVal))
WriteINIString 1, "settings", "loadspeechsystem", LTrim$(Str$(Abs(Int(SynthSpeech))))
WriteINIString 1, "settings", "backgroundpic", LTrim$(Str$(Abs(Int(BackScreen))))
WriteINIString 1, "settings", "systemtrayicon", LTrim$(Str$(SystemTrayIcon))
WriteINIString 1, "settings", "speechrecognition", LTrim$(Str$(Abs(Int(EnableSpeechRec))))
WriteINIString 1, "settings", "sapi5", LTrim$(Str$(Abs(Int(UseSAPI5))))
WriteINIString 1, "settings", "showcharacter", LTrim$(Str$(Abs(Int(ShowCharacter))))

If MainScreenOn = True Then frmMain.Show: Me.Hide
If MainScreenOn = False Then frmUser.Show: Me.Hide

Exit Sub
ErrorHandler:
err.Source = "Mode Dialog - Command3"
Call ErrorReport("An error occurred while switching modes.", vbInformation)
End Sub

Private Sub Form_Activate()
'If Running = False Then Unload frmMain
If MainScreenOn = True Then
    If SynthSpeech = False Then Option7.value = True
    If SynthSpeech = True And UseSAPI5 = False Then Option8.value = True
    If SynthSpeech = True And UseSAPI5 = True Then Option9.value = True
    If BackScreen = True Then Check2.value = 1
    If BackScreen = False Then Check2.value = 0
    If EnableSpeechRec = True Then Check3.value = 1
    If EnableSpeechRec = False Then Check3.value = 0
    If SystemTrayIcon = 0 Then Option1.value = True
    If SystemTrayIcon = 1 Then Option2.value = True
    If SystemTrayIcon = 2 Then Option3.value = True
    If SystemTrayIcon = 3 Then Option4.value = True
    If ModeVal = 1 Then Option5.value = True
    If ModeVal = 2 Then Option6.value = True
    If ShowCharacter = True Then Check1.value = 1
    If ShowCharacter = False Then Check1.value = 0
End If

End Sub

Private Sub Form_Load()
Me.Left = (ScreenX / 2) - (Me.Width / 2)
Me.top = (ScreenY / 2) - (Me.Height / 2)
NoDialog = True
'Call Option8_Click
End Sub

Private Sub Option8_Click()
Call TestSAPI4
End Sub

Private Sub Option9_Click()
If ExceptionHandlers = True Then On Error GoTo ErrorHandler
Set frmMain.Voice5 = New SpVoice
Set frmMain.Voice5 = Nothing
Exit Sub

ErrorHandler:
Call ErrorReport("The SAPI5 speech engine is not available.", vbInformation)
Option7.value = True
End Sub

Private Function TestSAPI4() As Boolean
If ExceptionHandlers = True Then On Error GoTo ErrorHandler
Set frmMain.DSS = New DirectSS
Set frmMain.Agent1 = New Agent
Set frmMain.DSS = Nothing
Set frmMain.Agent1 = Nothing
NoDialog = False
TestSAPI4 = True
Exit Function

ErrorHandler:
If NoDialog = False Then Call ErrorReport("The SAPI4 speech engine is not available. Please choose 'Off' under Synthesized Speech.", vbInformation)
Option7.value = True
NoDialog = False
TestSAPI4 = False
End Function
