Changeset 594 for trunk/ab5.0


Ignore:
Timestamp:
Aug 16, 2008, 2:15:42 AM (16 years ago)
Author:
NoWest
Message:

MIDI出力関連のMidiOutクラスを追加。
Joystick.abを改良。ListをIlistに変更。

Location:
trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/MM
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/MM/Joystick.ab

    r585 r594  
    66Namespace MM
    77
    8 
     8'ジョイスティックの構成を表す列挙体
    99Enum JoyCapability
     10    'ジョイスティックはZ軸情報を所有
    1011    HasZ = &H0001
     12    'ジョイスティックはR軸情報を所有
    1113    HasR = &H0002
     14    'ジョイスティックはU軸情報を所有
    1215    HasU = &H0004
     16    'ジョイスティックはV軸情報を所有
    1317    HasV = &H0008
     18    'ジョイスティックはPoint of View情報を所有
    1419    HasPointOfView = &H0010
     20    'ジョイスティックは4方向Point of Viewサポート
    1521    PointOfView4Direction = &H0020
     22    'ジョイスティックは連続した角度のPoint of Viewをサポート
    1623    PointOfViewContinuous = &H0040
    1724End Enum
    1825
     26
     27'ジョイスティックの性能を取得するためのJOYCAPS構造体のラップクラス
    1928Class JoyCaps
    2029    caps As JOYCAPS
     
    2534    End Sub
    2635
    27 Public
     36Public 'Property
     37    '製造業者IDの取得
    2838    Function ManufacturerID () As Word
    2939        Return This.caps.wMid
    3040    End Function
     41
     42    '製品IDの取得
    3143    Function ProductID () As Word
    3244        Return This.caps.wPid
    3345    End Function
     46
     47    '製品名の取得
    3448    Function ProductName () As String
    3549        Return New System.String(This.caps.szPname As LPTSTR)
    3650    End Function
     51
     52    'X軸の最小値の取得
    3753    Function MinimumX () As DWord
    3854        Return This.caps.wXmin
    3955    End Function
     56
     57    'X軸の最大値の取得
    4058    Function MaximumX () As DWord
    4159        Return This.caps.wXmax
    4260    End Function
     61
     62    'Y軸の最小値の取得
    4363    Function MinimumY () As DWord
    4464        Return This.caps.wYmin
    4565    End Function
     66
     67    'Y軸の最大値の取得
    4668    Function MaximumY () As DWord
    4769        Return This.caps.wYmax
    4870    End Function
     71
     72    'Z軸の最小値の取得
    4973    Function MinimumZ () As DWord
    5074        Return This.caps.wZmin
    5175    End Function
     76
     77    'Z軸の最大値の取得
    5278    Function MaximumZ () As DWord
    5379        Return This.caps.wZmax
    5480    End Function
     81
     82    '
    5583    Function NumberOfButtons () As DWord
    5684        Return This.caps.wNumButtons
    5785    End Function
    58     Function MinimumMessagePeriod () As DWord
     86
     87    'キャプチャ時のメッセージ送信間隔の最小値の取得
     88    Function MinimumPeriod () As DWord
    5989        Return This.caps.wPeriodMin
    6090    End Function
    61     Function MaximumMessagePeriod () As DWord
     91
     92    'キャプチャ時のメッセージ送信間隔の最大値の取得
     93    Function MaximumPeriod () As DWord
    6294        Return This.caps.wPeriodMax
    6395    End Function
     96
     97    '4軸目であるラダー(R軸)の最小値の取得
    6498    Function MinimumR () As DWord
    6599        Return This.caps.wRmin
    66100    End Function
     101
     102    '4軸目であるラダー(R軸)の最大値の取得
    67103    Function MaximumR () As DWord
    68104        Return This.caps.wRmax
    69105    End Function
     106
     107    '5軸目であるU軸の最小値の取得
    70108    Function MinimumU () As DWord
    71109        Return This.caps.wUmin
    72110    End Function
     111
     112    '5軸目であるU軸の最大値の取得
    73113    Function MaximumU () As DWord
    74114        Return This.caps.wUmax
    75115    End Function
     116
     117    '6軸目であるV軸の最小値の取得
    76118    Function MinimumV () As DWord
    77119        Return This.caps.wVmin
    78120    End Function
     121
     122    '6軸目であるV軸の最大値の取得
    79123    Function MaximumV () As DWord
    80124        Return This.caps.wVmax
    81125    End Function
     126
     127    'ジョイスティックの構成を取得
    82128    Function Capabilities () As JoyCapability
    83129        Return This.caps.wCaps As JoyCapability
    84130    End Function
    85     Function NumberOfAxesSupported () As DWord
     131
     132    'サポートしている動きの軸の数を取得
     133    Function NumberOfSupportedAxes () As DWord
    86134        Return This.caps.wMaxAxes
    87135    End Function
    88     Function NumberOfAxesUsed () As DWord
     136
     137    '実際に使用している動きの軸の数を取得
     138    Function NumberOfUsedAxes () As DWord
    89139        Return This.caps.wNumAxes
    90140    End Function
    91     Function NumberOfButtonsSupported () As DWord
     141
     142    'サポートしているボタン数を取得
     143    Function NumberOfSupportedButtons () As DWord
    92144        Return This.caps.wMaxButtons
    93145    End Function
     146
     147    '登録キーを文字列の取得
    94148    Function RegistryKey () As String
    95149        Return New System.String(This.caps.szRegKey As LPTSTR)
    96150    End Function
     151
     152    'OEMジョイスティックドライバを特定する文字列の取得
    97153    Function OEM_VxD () As String
    98154        Return New System.String(This.caps.szOEMVxD As LPTSTR)
     
    100156End Class
    101157
     158
     159'ジョイスティックのボタンの状態を取得するためのクラス
    102160Class JoyButtons
    103161    dwButtons As DWord
     
    108166    End Sub
    109167
    110 Public
     168Public 'Property
     169    '各ボタンの状態を取得する
    111170    Function Button1 () As Boolean
    112171        Return This.Button( 1 )
     
    206265    End Function
    207266
    208 Public
     267Public 'Method
     268    '指定した番号のボタンの状態を取得
    209269    Function Button ( n As DWord ) As Boolean
    210270        Return (1<<(n-1) And This.dwButtons) <> 0
    211271    End Function
    212272
    213 Public
     273Public 'Operator
     274    'DWord値へ変換
    214275    Function Operator () As DWord
    215276        Return This.dwButtons
    216277    End Function
    217278
     279    'DWord値と比較
    218280    Function Operator== (dw As DWord) As Boolean
    219281        Return This.dwButtons = dw
    220282    End Function
     283    Function Operator<> (dw As DWord) As Boolean
     284        Return This.dwButtons <> dw
     285    End Function
     286
     287    'DWord値とAnd演算
    221288    Function Operator And (dw As DWord) As Boolean
    222289        Return (This.dwButtons And dw) <> 0
     
    225292End Class
    226293
     294
     295'PointOfView値を格納するクラス
    227296Class JoyPointOfView
    228     dwPOV As DWord
     297    pov As DWord
    229298
    230299Protected
    231300    Sub _Initialize ( dw As DWord )
    232         If LOWORD(dw) = &HFFFF Then dw = -1
    233         This.dwPOV = dw
    234     End Sub
    235 
    236 Public
     301        If LOWORD(dw) = &HFFFF Then dw = (-1) As DWord
     302        This.pov = dw
     303    End Sub
     304
     305Public 'Static Constant
     306    '中心
    237307    Static Const Centered = (-1) As DWord
     308    '前方
    238309    Static Const Forward = 0 As DWord
     310    '右前方
    239311    Static Const ForwardAndRight = 4500 As DWord
     312    '右
    240313    Static Const Right = 9000 As DWord
     314    '右後方
    241315    Static Const BackwardAndRight = 13500 As DWord
     316    '後方
    242317    Static Const Backward = 18000 As DWord
     318    '左後方
    243319    Static Const BackwardAndLeft = 22500 As DWord
     320    '左
    244321    Static Const Left = 27000 As DWord
     322    '左前方
    245323    Static Const ForwardAndLeft = 31500 As DWord
    246324
    247 Public
     325Public 'Proparty
     326    Function IsCentered() As Boolean
     327        Return This.pov <> Centered
     328    End Function
     329    Function IsForward() As Boolean
     330        Return This.pov <> Forward
     331    End Function
     332    Function IsRight() As Boolean
     333        Return This.pov <> Right
     334    End Function
     335    Function IsBackward() As Boolean
     336        Return This.pov <> Backward
     337    End Function
     338    Function IsLeft() As Boolean
     339        Return This.pov <> Left
     340    End Function
     341
     342Public 'Method
     343    '角度に変換
     344    Function ToDegrees() As Double
     345        Return (This.pov / 100)
     346    End Function
     347
     348
     349Public 'Operator
     350    'DWord値へ変換
    248351    Function Operator () As DWord
    249         Return This.dwPOV
    250     End Function
    251 
    252     Function Operator== (value As DWord) As Boolean
    253         Return This.dwPOV = value
    254     End Function
    255     Function Operator<> ( value As DWord) As Boolean
    256         Return This.dwPOV <> value
    257     End Function
    258     Function Operator<= ( value As DWord) As Boolean
    259         Return This.dwPOV <= value
    260     End Function
    261     Function Operator>= ( value As DWord) As Boolean
    262         Return This.dwPOV >= value
    263     End Function
    264     Function Operator< ( value As DWord) As Boolean
    265         Return This.dwPOV < value
    266     End Function
    267     Function Operator> ( value As DWord) As Boolean
    268         Return This.dwPOV > value
    269     End Function
    270 
    271     Function Operator== ( value As JoyPointOfView ) As Boolean
    272         Return This = value As DWord
    273     End Function
    274     Function Operator<> ( value As JoyPointOfView ) As Boolean
    275         Return This <> value As DWord
    276     End Function
    277     Function Operator<= ( value As JoyPointOfView ) As Boolean
    278         Return This <= value As DWord
    279     End Function
    280     Function Operator>= ( value As JoyPointOfView ) As Boolean
    281         Return This >= value As DWord
    282     End Function
    283     Function Operator< ( value As JoyPointOfView ) As Boolean
    284         Return This < value As DWord
    285     End Function
    286     Function Operator> ( value As JoyPointOfView ) As Boolean
    287         Return This > value As DWord
    288     End Function
    289 End Class
    290 
     352        Return This.pov
     353    End Function
     354
     355    'DWord値と比較
     356    Function Operator== (value As DWord ) As Boolean
     357        Return This.pov = value
     358    End Function
     359    Function Operator<> ( value As DWord ) As Boolean
     360        Return This.pov <> value
     361    End Function
     362    Function Operator<= ( value As DWord ) As Boolean
     363        Return This.pov <= value
     364    End Function
     365    Function Operator>= ( value As DWord ) As Boolean
     366        Return This.pov >= value
     367    End Function
     368    Function Operator< ( value As DWord ) As Boolean
     369        Return This.pov < value
     370    End Function
     371    Function Operator> ( value As DWord ) As Boolean
     372        Return This.pov > value
     373    End Function
     374
     375    'DWord値と演算
     376    Function Operator+ ( value As DWord ) As DWord
     377        Return This.pov + value
     378    End Function
     379    Function Operator- ( value As DWord ) As DWord
     380        Return This.pov - value
     381    End Function
     382    Function Operator* ( value As DWord ) As DWord
     383        Return This.pov * value
     384    End Function
     385    Function Operator Mod ( value As DWord ) As DWord
     386        Return This.pov Mod value
     387    End Function
     388    Function Operator / ( value As DWord ) As Double
     389        Return This.pov / value
     390    End Function
     391End Class
     392
     393
     394'ジョイスティックの情報を格納するJOYINFOEX構造体のラップクラス
    291395Class JoyInfo
    292396    info As JOYINFOEX
     
    299403    End Sub
    300404
    301 Public
     405Public 'Property
     406    'X軸の値を取得
    302407    Function X () As DWord
    303408        Return This.info.dwXpos
    304409    End Function
     410
     411    'Y軸の値を取得
    305412    Function Y () As DWord
    306413        Return This.info.dwYpos
    307414    End Function
     415
     416    'Z軸の値を取得
    308417    Function Z () As DWord
    309418        Return This.info.dwZpos
    310419    End Function
     420
     421    'ラダー(R軸)の値を取得
    311422    Function R () As DWord
    312423        Return This.info.dwRpos
    313424    End Function
     425
     426    'U軸の値を取得
    314427    Function U () As DWord
    315428        Return This.info.dwUpos
    316429    End Function
     430
     431    'V軸の値を取得
    317432    Function V () As DWord
    318433        Return This.info.dwVpos
    319434    End Function
     435
     436    'ボタンの状態を取得
    320437    Function Buttons () As JoyButtons
    321438        Return New Detail._System_JoyButtons(This.info.dwButtons)
    322439    End Function
     440
     441    'ボタンの状態を取得
    323442    Function ButtonNumber () As DWord
    324443        Return This.info.dwButtonNumber
     
    329448End Class
    330449
    331 Class Joystick
     450
     451'ジョイスティックを扱うためのクラス
     452Class JoystickDevice
    332453    id As DWord
    333454
     
    337458    End Sub
    338459
    339 Public
     460Public 'Property
     461    'スティックの動きの閾値を設定
    340462    Sub Threshold ( value As DWord )
    341463        joySetThreshold(id,value)
    342464    End Sub
     465
     466    'スティックの動きの閾値を取得
    343467    Function Threshold () As DWord
    344         joyGetThreshold(id,VarPtr(Threshold))
    345     End Function
    346 
    347 Public
     468        joyGetThreshold(id,Threshold)
     469    End Function
     470
     471Public 'Method
     472    'ジョイステックの性能を取得
    348473    Function GetCapabilities () As JoyCaps
    349474        Return New Detail._System_JoyCaps(This.id)
    350475    End Function
     476
     477    'ジョイステックの現在の状態を取得
    351478    Function GetInfo() As JoyInfo
    352479        Return New Detail._System_JoyInfo(This.id)
    353480    End Function
    354481
    355 Public
     482    'キャプチャを開始
    356483    Sub SetCupture ( hwnd As HWND, period As DWord, changed As Boolean)
    357484        joySetCapture(hwnd,id,period,changed)
    358485    End Sub
     486
     487    'キャプチャを終了
    359488    Sub ReleaseCapture()
    360489        joyReleaseCapture(id)
     
    362491End Class
    363492
    364 Class Joysticks
    365 
    366 Public
     493
     494'ジョイスティックデバイスを取得するためのクラス
     495Class Joystick
     496Public 'Static Constant
     497    Static Const Joystick1 = 0
     498    Static Const Joystick2 = 1
     499
     500Public 'Static Property
     501    'ドライバによってサポートされるジョイスティック数を取得
    367502    Static Function NumberOfDevices () As DWord
    368503        Return joyGetNumDevs()
    369504    End Function
     505
     506    '物理的に接続されたジョイスティック数を取得
    370507    Static Function NumberOfConnectedDevices () As DWord
    371         Dim max = Joysticks.NumberOfDevices()
     508        Dim max = NumberOfDevices()
    372509        Dim cnt=0 As DWord
    373510        Dim info As JOYINFO
     
    379516    End Function
    380517
    381     Static Function GetJoysticks() As System.Collections.Generic.List<Joystick>
    382         Dim list As System.Collections.Generic.List<Joystick>
     518Public 'Static Method
     519    '使用可能なジョイスティックIDを列挙したIListを取得
     520    Static Function GetJoystickIDs() As System.Collections.Generic.IList<DWord>
     521        Dim max = NumberOfDevices()
     522        GetJoystickIDs = New System.Collections.Generic.List<DWord>
    383523        Dim cnt As DWord
    384         For cnt=0 To NumberOfConnectedDevices() - 1
    385             list.Add(Joysticks.GetJoystick(cnt))
     524        Dim info As JOYINFO
     525        For cnt=0 To max-1
     526            If joyGetPos(cnt,info) = JOYERR_NOERROR Then
     527                GetJoystickIDs.Add(cnt)
     528            End If
    386529        Next
    387         Return list
    388     End Function
    389 
    390     Static Function GetJoystick( id As DWord ) As Joystick
    391         Return New Detail._System_Joystick(id)
     530    End Function
     531
     532    '使用可能なジョイスティックデバイスを列挙したIListを取得
     533    Static Function GetDevices() As System.Collections.Generic.IList<JoystickDevice>
     534        Dim max = NumberOfDevices()
     535        GetDevices = New System.Collections.Generic.List<JoystickDevice>
     536        Dim cnt As DWord
     537        Dim info As JOYINFO
     538        For cnt=0 To max-1
     539            If joyGetPos(cnt,info) = JOYERR_NOERROR Then
     540                GetDevices.Add(GetDeviceFromID(cnt))
     541            End If
     542        Next
     543    End Function
     544
     545    'ジョイスティックデバイスを取得
     546    Static Function GetDeviceFromID( id As DWord ) As JoystickDevice
     547        Return New Detail._System_JoystickDevice(id)
    392548    End Function
    393549
     
    443599End Class
    444600
    445 Class _System_Joystick
    446     Inherits Joystick
     601Class _System_JoystickDevice
     602    Inherits JoystickDevice
    447603Public
    448     Sub _System_Joystick ( id As DWord )
     604    Sub _System_JoystickDevice ( id As DWord )
    449605        This._Initialize(id)
    450606    End Sub
Note: See TracChangeset for help on using the changeset viewer.