sgl 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. data/ChangeLog +234 -0
  2. data/Manifest.txt +94 -0
  3. data/Rakefile +16 -5
  4. data/examples/cocoa1-basic.rb +14 -0
  5. data/examples/cocoa10-transparent.rb +26 -0
  6. data/examples/cocoa11-application.rb +13 -0
  7. data/examples/cocoa2-draw.rb +23 -0
  8. data/examples/cocoa3-affine.rb +29 -0
  9. data/examples/cocoa4-font.rb +24 -0
  10. data/examples/cocoa5-image.rb +22 -0
  11. data/examples/cocoa6-sound.rb +24 -0
  12. data/examples/cocoa7-movie.rb +40 -0
  13. data/examples/cocoa8-movieoverlay.rb +42 -0
  14. data/examples/cocoa9-streaming.rb +40 -0
  15. data/examples/opengl1-basic.rb +14 -0
  16. data/examples/opengl11-application.rb +13 -0
  17. data/examples/opengl2-draw.rb +23 -0
  18. data/examples/opengl3-affine.rb +29 -0
  19. data/examples/sample1.rb +11 -0
  20. data/examples/sample10.rb +16 -0
  21. data/examples/sample11.rb +22 -0
  22. data/examples/sample11a.rb +33 -0
  23. data/examples/sample12.rb +30 -0
  24. data/examples/sample12a.rb +35 -0
  25. data/examples/sample13.rb +116 -0
  26. data/examples/sample15.rb +24 -0
  27. data/examples/sample16.rb +31 -0
  28. data/examples/sample16a.rb +35 -0
  29. data/examples/sample6.rb +18 -0
  30. data/examples/sample7.rb +16 -0
  31. data/examples/sample9.rb +20 -0
  32. data/examples/sgl-sound1.rb +6 -0
  33. data/examples/sgl-sound2.rb +19 -0
  34. data/examples/sine.ogg +0 -0
  35. data/examples/testgl.rb +169 -0
  36. data/lib/sgl/bass-api.rb +202 -0
  37. data/lib/sgl/bass-sample.rb +106 -0
  38. data/lib/sgl/bass.rb +46 -0
  39. data/lib/sgl/cocoa-app.rb +43 -0
  40. data/lib/sgl/cocoa-color.rb +65 -0
  41. data/lib/sgl/cocoa-draw.rb +72 -0
  42. data/lib/sgl/cocoa-event.rb +229 -0
  43. data/lib/sgl/cocoa-media.rb +144 -0
  44. data/lib/sgl/cocoa-notuse.rb +493 -0
  45. data/lib/sgl/cocoa-window.rb +203 -0
  46. data/lib/sgl/cocoa.rb +8 -0
  47. data/lib/sgl/notuse-objs.rb +358 -0
  48. data/lib/sgl/opengl-app.rb +38 -0
  49. data/lib/sgl/opengl-color.rb +44 -0
  50. data/lib/sgl/opengl-draw.rb +260 -0
  51. data/lib/sgl/opengl-event.rb +325 -0
  52. data/lib/sgl/opengl-modules.rb +22 -0
  53. data/lib/sgl/opengl-window.rb +224 -0
  54. data/lib/sgl/opengl.rb +7 -0
  55. data/lib/sgl/sgl-basic.rb +61 -0
  56. data/lib/sgl/sgl-button.rb +135 -0
  57. data/lib/sgl/sgl-client.rb +21 -0
  58. data/lib/sgl/sgl-color.rb +82 -0
  59. data/lib/sgl/sgl-connect.rb +9 -0
  60. data/lib/sgl/sgl-objlib.rb +0 -0
  61. data/lib/sgl/sgl-objs.rb +0 -0
  62. data/lib/sgl/sgl-server.rb +58 -0
  63. data/lib/sgl/sgl-sound.rb +24 -0
  64. data/lib/sgl/sgl-spring.rb +216 -0
  65. data/lib/sgl/sgl-timer.rb +72 -0
  66. data/lib/sgl/sgl.rb +5 -0
  67. data/lib/sgl/version.rb +2 -2
  68. data/scripts/makemanifest.rb +20 -0
  69. data/test/test_bass.rb +27 -0
  70. data/test/test_cocoa_app.rb +5 -5
  71. data/test/test_helper.rb +9 -1
  72. data/test/test_module_ruby16.rb +22 -21
  73. data/test/test_opengl_app.rb +4 -5
  74. data/test/test_opengl_basic.rb +3 -4
  75. data/test/test_opengl_fullscreen.rb +4 -6
  76. data/test/test_opengl_novice.rb +3 -6
  77. data/test/test_sgl.rb +4 -27
  78. data/test/test_sound.rb +15 -0
  79. data/website/challenge1.html +91 -0
  80. data/website/challenge1.txt +30 -0
  81. data/website/challenge2.html +144 -0
  82. data/website/challenge2.txt +73 -0
  83. data/website/challenge3.html +63 -0
  84. data/website/challenge3.txt +15 -0
  85. data/website/cocoa.html +88 -0
  86. data/website/cocoa.txt +35 -0
  87. data/website/description.html +138 -0
  88. data/website/description.txt +90 -0
  89. data/website/exercise1.html +264 -0
  90. data/website/exercise1.txt +192 -0
  91. data/website/exercise2.html +683 -0
  92. data/website/exercise2.txt +597 -0
  93. data/website/exhibition.html +84 -0
  94. data/website/exhibition.txt +24 -0
  95. data/website/howto.html +134 -0
  96. data/website/howto.txt +56 -0
  97. data/website/index.html +17 -9
  98. data/website/index.txt +13 -4
  99. data/website/sound.html +141 -0
  100. data/website/sound.txt +87 -0
  101. data/website/stylesheets/grade.png +0 -0
  102. data/website/stylesheets/screen.css +21 -20
  103. metadata +109 -3
@@ -0,0 +1,202 @@
1
+ # Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
2
+ # License: Ruby License
3
+
4
+ module Bass
5
+ # ============================================================
6
+ # Define result codes.
7
+ BASS_OK = 0 # all is OK
8
+ BASS_ERROR_MEM = 1 # memory error
9
+ BASS_ERROR_FILEOPEN = 2 # can't open the file
10
+ BASS_ERROR_DRIVER = 3 # can't find a free/valid driver
11
+ BASS_ERROR_BUFLOST = 4 # the sample buffer was lost - please report this!
12
+ BASS_ERROR_HANDLE = 5 # invalid handle
13
+ BASS_ERROR_FORMAT = 6 # unsupported format
14
+ BASS_ERROR_POSITION = 7 # invalid playback position
15
+ BASS_ERROR_INIT = 8 # BASS_Init has not been successfully called
16
+ BASS_ERROR_START = 9 # BASS_Start has not been successfully called
17
+ BASS_ERROR_INITCD = 10 # can't initialize CD
18
+ BASS_ERROR_CDINIT = 11 # BASS_CDInit has not been successfully called
19
+ BASS_ERROR_NOCD = 12 # no CD in drive
20
+ BASS_ERROR_CDTRACK = 13 # can't play the selected CD track
21
+ BASS_ERROR_ALREADY = 14 # already initialized
22
+ BASS_ERROR_CDVOL = 15 # CD has no volume control
23
+ BASS_ERROR_NOPAUSE = 16 # not paused
24
+ BASS_ERROR_NOTAUDIO = 17 # not an audio track
25
+ BASS_ERROR_NOCHAN = 18 # can't get a free channel
26
+ BASS_ERROR_ILLTYPE = 19 # an illegal type was specified
27
+ BASS_ERROR_ILLPARAM = 20 # an illegal parameter was specified
28
+ BASS_ERROR_NO3D = 21 # no 3D support
29
+ BASS_ERROR_NOEAX = 22 # no EAX support
30
+ BASS_ERROR_DEVICE = 23 # illegal device number
31
+ BASS_ERROR_NOPLAY = 24 # not playing
32
+ BASS_ERROR_FREQ = 25 # illegal sample rate
33
+ BASS_ERROR_NOA3D = 26 # A3D.DLL is not installed
34
+ BASS_ERROR_NOTFILE = 27 # the stream is not a file stream (WAV/MP3/MP2/MP1/OGG)
35
+ BASS_ERROR_NOHW = 29 # no hardware voices available
36
+ BASS_ERROR_NOSYNC = 30 # synchronizers have been disabled
37
+ BASS_ERROR_EMPTY = 31 # the MOD music has no sequence data
38
+ BASS_ERROR_NONET = 32 # no internet connection could be opened
39
+ BASS_ERROR_CREATE = 33 # couldn't create the file
40
+ BASS_ERROR_NOFX = 34 # effects are not enabled
41
+ BASS_ERROR_PLAYING = 35 # the channel is playing
42
+ BASS_ERROR_NOOGG = 36 # OGG.DLL/VORBIS.DLL could not be loaded
43
+ BASS_ERROR_UNKNOWN = -1 # some other mystery error
44
+
45
+ # Device setup flags
46
+ BASS_DEVICE_8BITS = 1 # use 8 bit resolution, else 16 bit
47
+ BASS_DEVICE_MONO = 2 # use mono, else stereo
48
+ BASS_DEVICE_3D = 4 # enable 3D functionality
49
+
50
+ # If the BASS_DEVICE_3D flag is not specified when initilizing BASS,
51
+ # then the 3D flags (BASS_SAMPLE_3D and BASS_MUSIC_3D) are ignored when
52
+ # loading/creating a sample/stream/music.
53
+ BASS_DEVICE_A3D = 8 # enable A3D functionality
54
+ BASS_DEVICE_NOSYNC = 16 # disable synchronizers
55
+ BASS_DEVICE_LEAVEVOL = 32 # leave the volume as it is
56
+ BASS_DEVICE_OGG = 64 # enable OGG support (requires OGG.DLL & VORBIS.DLL)
57
+
58
+ # DirectSound interfaces (for use with BASS_GetDSoundObject)
59
+ BASS_OBJECT_DS = 1 # IDirectSound
60
+ BASS_OBJECT_DS3DL = 2 # IDirectSound3DListener
61
+
62
+ # Music flags
63
+ BASS_MUSIC_RAMP = 1 # normal ramping
64
+ BASS_MUSIC_RAMPS = 2 # sensitive ramping
65
+ # Ramping doesn't take a lot of extra processing and improves '
66
+ # the sound quality by removing 'clicks'. Sensitive ramping will
67
+ # leave sharp attacked samples, unlike normal ramping.
68
+ BASS_MUSIC_LOOP = 4 # loop music
69
+ BASS_MUSIC_FT2MOD = 16 # play .MOD as FastTracker 2 does
70
+ BASS_MUSIC_PT1MOD = 32 # play .MOD as ProTracker 1 does
71
+ BASS_MUSIC_MONO = 64 # force mono mixing (less CPU usage)
72
+ BASS_MUSIC_3D = 128 # enable 3D functionality
73
+ BASS_MUSIC_POSRESET = 256 # stop all notes when moving position
74
+ BASS_MUSIC_SURROUND = 512 # surround sound
75
+ BASS_MUSIC_SURROUND2 = 1024 # surround sound (mode 2)
76
+ BASS_MUSIC_STOPBACK = 2048 # stop the music on a backwards jump effect
77
+ BASS_MUSIC_FX = 4096 # enable DX8 effects
78
+ BASS_MUSIC_CALCLEN = 8192 # calculate playback length
79
+
80
+ BASS_SAMPLE_8BITS = 1 # 8 bit, else 16 bit
81
+ BASS_SAMPLE_MONO = 2 # mono, else stereo
82
+ BASS_SAMPLE_LOOP = 4 # looped
83
+ BASS_SAMPLE_3D = 8 # 3D functionality enabled
84
+ BASS_SAMPLE_SOFTWARE = 16 # it's NOT using hardware mixing'
85
+ BASS_SAMPLE_MUTEMAX = 32 # muted at max distance (3D only)
86
+ BASS_SAMPLE_VAM = 64 # uses the DX7 voice allocation & management
87
+ BASS_SAMPLE_FX = 128 # the DX8 effects are enabled
88
+ BASS_SAMPLE_OVER_VOL = 0x10000 # override lowest volume
89
+ BASS_SAMPLE_OVER_POS = 0x20000 # override longest playing
90
+ BASS_SAMPLE_OVER_DIST = 0x30000 # override furthest from listener (3D only)
91
+
92
+ BASS_MP3_HALFRATE = 0x10000 # reduced quality MP3/MP2/MP1 (half sample rate)
93
+ BASS_MP3_SETPOS = 0x20000 # enable seeking on the MP3/MP2/MP1/OGG
94
+
95
+ BASS_STREAM_AUTOFREE = 0x40000 # automatically free the stream when it stop/ends
96
+ BASS_STREAM_RESTRATE = 0x80000 # restrict the download rate of internet file streams
97
+ BASS_STREAM_BLOCK = 0x100000 # download/play internet file stream (MPx/OGG) in small blocks
98
+
99
+ BASS_CDID_IDENTITY = 0
100
+ BASS_CDID_UPC = 1
101
+
102
+ # ============================================================
103
+ # Load API.
104
+
105
+ def api(func, input, output)
106
+ return Win32API.new('bass', func, input, output)
107
+ end
108
+ module_function :api
109
+
110
+ BASS_GetVersion = api('BASS_GetVersion', 'V', 'L')
111
+ BASS_GetDeviceDescription = api('BASS_GetDeviceDescription', 'IP', 'I')
112
+ BASS_SetBufferLength = api('BASS_SetBufferLength', 'L', 'V')
113
+ BASS_SetGlobalVolumes = api('BASS_SetGlobalVolumes', 'III', 'V')
114
+ BASS_GetGlobalVolumes = api('BASS_GetGlobalVolumes', 'PPP', 'V')
115
+ BASS_SetLogCurves = api('BASS_SetLogCurves', 'II', 'V')
116
+ BASS_Set3DAlgorithm = api('BASS_Set3DAlgorithm', 'L', 'V')
117
+ BASS_ErrorGetCode = api('BASS_ErrorGetCode', 'V', 'I')
118
+ BASS_Init = api('BASS_Init', 'ILLP', 'I')
119
+ BASS_Free = api('BASS_Free', 'V', 'V')
120
+ BASS_GetDSoundObject = api('BASS_GetDSoundObject', 'L', 'P')
121
+ BASS_GetInfo = api('BASS_GetInfo', 'P', 'V')
122
+ BASS_GetCPU = api('BASS_GetCPU', 'V', 'L')
123
+ BASS_Start = api('BASS_Start', 'V', 'I')
124
+ BASS_Stop = api('BASS_Stop', 'V', 'I')
125
+ BASS_Pause = api('BASS_Pause', 'V', 'I')
126
+ BASS_SetVolume = api('BASS_SetVolume', 'L', 'I')
127
+ BASS_GetVolume = api('BASS_GetVolume', 'V', 'I')
128
+ BASS_Set3DFactors = api('BASS_Set3DFactors', 'LLL', 'I')
129
+ BASS_Get3DFactors = api('BASS_Get3DFactors', 'PPP', 'I')
130
+ BASS_Set3DPosition = api('BASS_Set3DPosition', 'PPPP', 'I')
131
+ BASS_Get3DPosition = api('BASS_Get3DPosition', 'PPPP', 'I')
132
+ BASS_Apply3D = api('BASS_Apply3D', 'V', 'I')
133
+ BASS_SetEAXParameters = api('BASS_SetEAXParameters', 'ILLL', 'I')
134
+ BASS_GetEAXParameters = api('BASS_GetEAXParameters', 'PPPP', 'I')
135
+ #BASS_SetA3DResManager = api('BASS_SetA3DResManager', 'L', 'I')
136
+ #BASS_GetA3DResManager = api('BASS_GetA3DResManager', 'V', 'L')
137
+ #BASS_SetA3DHFAbsorbtion = api('BASS_SetA3DHFAbsorbtion', 'L', 'I')
138
+ #BASS_GetA3DHFAbsorbtion = api('BASS_GetA3DHFAbsorbtion', 'P', 'I')
139
+ BASS_MusicLoad = api('BASS_MusicLoad', 'IPLLL', 'L')
140
+ BASS_MusicFree = api('BASS_MusicFree', 'P', 'V')
141
+ BASS_MusicGetName = api('BASS_MusicGetName', 'P', 'P')
142
+ BASS_MusicGetLength = api('BASS_MusicGetLength', 'PI', 'L')
143
+ BASS_MusicPreBuf = api('BASS_MusicPreBuf', 'P', 'I')
144
+ BASS_MusicPlay = api('BASS_MusicPlay', 'P', 'I')
145
+ BASS_MusicPlayEx = api('BASS_MusicPlayEx', 'PLII', 'I')
146
+ BASS_MusicSetAmplify = api('BASS_MusicSetAmplify', 'PL', 'I')
147
+ BASS_MusicSetPanSep = api('BASS_MusicSetPanSep', 'PL', 'I')
148
+ BASS_MusicSetPositionScaler = api('BASS_MusicSetPositionScaler', 'PL', 'I')
149
+ BASS_SampleLoad = api('BASS_SampleLoad', 'IPLLLL', 'L')
150
+ BASS_SampleCreate = api('BASS_SampleCreate', 'LLLL', 'L')
151
+ BASS_SampleCreateDone = api('BASS_SampleCreateDone', 'V', 'P')
152
+ BASS_SampleFree = api('BASS_SampleFree', 'P', 'V')
153
+ BASS_SampleGetInfo = api('BASS_SampleGetInfo', 'PP', 'I')
154
+ BASS_SampleSetInfo = api('BASS_SampleSetInfo', 'PP', 'I')
155
+ BASS_SamplePlay = api('BASS_SamplePlay', 'L', 'L')
156
+ BASS_SamplePlayEx = api('BASS_SamplePlayEx', 'PLIIII', 'L')
157
+ BASS_SamplePlay3D = api('BASS_SamplePlay3D', 'PPPP', 'P')
158
+ BASS_SamplePlay3DEx = api('BASS_SamplePlay3DEx', 'PPPPLIII', 'P')
159
+ BASS_SampleStop = api('BASS_SampleStop', 'P', 'I')
160
+ BASS_StreamCreate = api('BASS_StreamCreate', 'LLPL', 'P')
161
+ BASS_StreamCreateFile = api('BASS_StreamCreateFile', 'IPLLL', 'P')
162
+ BASS_StreamCreateURL = api('BASS_StreamCreateURL', 'PLP', 'P')
163
+ BASS_StreamFree = api('BASS_StreamFree', 'P', 'V')
164
+ BASS_StreamGetLength = api('BASS_StreamGetLength', 'P', 'L')
165
+ BASS_StreamPreBuf = api('BASS_StreamPreBuf', 'P', 'I')
166
+ BASS_StreamPlay = api('BASS_StreamPlay', 'PIL', 'I')
167
+ BASS_StreamGetFilePosition = api('BASS_StreamGetFilePosition', 'PL', 'L')
168
+ BASS_CDInit = api('BASS_CDInit', 'P', 'I')
169
+ BASS_CDFree = api('BASS_CDFree', 'V', 'V')
170
+ BASS_CDInDrive = api('BASS_CDInDrive', 'V', 'I')
171
+ BASS_CDGetID = api('BASS_CDGetID', 'L', 'P')
172
+ BASS_CDGetTracks = api('BASS_CDGetTracks', 'V', 'L')
173
+ BASS_CDPlay = api('BASS_CDPlay', 'LII', 'I')
174
+ BASS_CDGetTrackLength = api('BASS_CDGetTrackLength', 'L', 'L')
175
+ BASS_ChannelIsActive = api('BASS_ChannelIsActive', 'P', 'I')
176
+ BASS_ChannelGetFlags = api('BASS_ChannelGetFlags', 'L', 'L')
177
+ BASS_ChannelStop = api('BASS_ChannelStop', 'L', 'I')
178
+ BASS_ChannelPause = api('BASS_ChannelPause', 'L', 'I')
179
+ BASS_ChannelResume = api('BASS_ChannelResume', 'L', 'I')
180
+ BASS_ChannelSetAttributes = api('BASS_ChannelSetAttributes', 'LIII', 'I')
181
+ BASS_ChannelGetAttributes = api('BASS_ChannelGetAttributes', 'LPPP', 'I')
182
+ BASS_ChannelSet3DAttributes = api('BASS_ChannelSet3DAttributes', 'LILLIII', 'I')
183
+ BASS_ChannelGet3DAttributes = api('BASS_ChannelGet3DAttributes', 'LPPPPPP', 'I')
184
+ BASS_ChannelSet3DPosition = api('BASS_ChannelSet3DPosition', 'LPPP', 'I')
185
+ BASS_ChannelGet3DPosition = api('BASS_ChannelGet3DPosition', 'LPPP', 'I')
186
+ BASS_ChannelSetPosition = api('BASS_ChannelSetPosition', 'LL', 'I')
187
+ BASS_ChannelGetPosition = api('BASS_ChannelGetPosition', 'L', 'L')
188
+ BASS_ChannelGetLevel = api('BASS_ChannelGetLevel', 'L', 'L')
189
+ BASS_ChannelGetData = api('BASS_ChannelGetData', 'LPL', 'L')
190
+ BASS_ChannelSetSync = api('BASS_ChannelSetSync', 'LLLPL', 'P')
191
+ BASS_ChannelRemoveSync = api('BASS_ChannelRemoveSync', 'LP', 'I')
192
+ BASS_ChannelSetDSP = api('BASS_ChannelSetDSP', 'LPL', 'P')
193
+ BASS_ChannelRemoveDSP = api('BASS_ChannelRemoveDSP', 'LP', 'I')
194
+ BASS_ChannelSetFX = api('BASS_ChannelSetFX', 'LL', 'P')
195
+ BASS_ChannelRemoveFX = api('BASS_ChannelRemoveFX', 'LP', 'I')
196
+ BASS_ChannelSetEAXMix = api('BASS_ChannelSetEAXMix', 'LL', 'I')
197
+ BASS_ChannelGetEAXMix = api('BASS_ChannelGetEAXMix', 'LP', 'I')
198
+ BASS_ChannelSetLink = api('BASS_ChannelSetLink', 'LL', 'I')
199
+ BASS_ChannelRemoveLink = api('BASS_ChannelRemoveLink', 'LL', 'I')
200
+ BASS_FXSetParameters = api('BASS_FXSetParameters', 'PP', 'I')
201
+ BASS_FXGetParameters = api('BASS_FXGetParameters', 'PP', 'I')
202
+ end
@@ -0,0 +1,106 @@
1
+ # Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
2
+ # License: Ruby License
3
+
4
+ require "Win32API"
5
+ require "singleton"
6
+
7
+ module Bass
8
+ class Sample
9
+ def initialize(file)
10
+ @base = 60
11
+ @bass = Bass::BassLib.instance
12
+ @hsample = SampleLoader.instance.get(file)
13
+ get_sample_info
14
+ end
15
+
16
+ attr_accessor :base
17
+
18
+ def play(note = 60, volume = -1, pan = -101)
19
+ sfreq = @freq * mtof(note) / mtof(@base)
20
+ playEx(0, sfreq, volume, pan)
21
+ end
22
+
23
+ private
24
+
25
+ # Get information of the sample.
26
+ #
27
+ # typedef struct {
28
+ # DWORD freq;
29
+ # DWORD volume;
30
+ # int pan;
31
+ # DWORD flags;
32
+ # DWORD length;
33
+ # DWORD max;
34
+ # DWORD mode3d;
35
+ # float mindist;
36
+ # float maxdist;
37
+ # DWORD iangle;
38
+ # DWORD oangle;
39
+ # DWORD outvol;
40
+ # DWORD vam;
41
+ # DWORD priority;
42
+ # } BASS_SAMPLE;
43
+ def get_sample_info
44
+ info = ' ' * 1024
45
+ BASS_SampleGetInfo.call(@hsample, info)
46
+ @freq, @volume, @pan, @flags, @length, @max, @mode3d, @mindist, @maxdist,
47
+ @iangle, @oangle, @outvol, @vam, @priority = info.unpack("SSiSSSSffSSSSS")
48
+ end
49
+
50
+ # �O������J
51
+ # freq The sample rate. 100(min)-100000(max), -1 = use sample's default.
52
+ # volume The volume... 0(silent)-100(max), -1 = use sample's default.
53
+ # pan The panning position. -100(left)-100(right), -101 = use sample's default.
54
+ # loop TRUE = Loop the sample. -1 = use sample's default.
55
+ def playEx(start = 0, freq = -1, volume = -1, pan = -101, loop = -1)#:nodoc:
56
+ # We have to check the paramterers for SamplePlayEx.
57
+ freq = freq.to_i
58
+ freq = 100 if freq < 100 && freq != -1
59
+ freq = 100000 if 100000 < freq
60
+ volume = volume.to_i
61
+ volume = 0 if volume < -1
62
+ volume = 100 if 100 < volume
63
+ pan = pan.to_i
64
+ pan = -100 if pan < -101
65
+ pan = 100 if 100 < pan
66
+ ch = BASS_SamplePlayEx.call(@hsample, start, freq, volume, pan, loop)
67
+ @bass.add_playing_channel(ch)
68
+ return ch
69
+ end
70
+
71
+ # midi note to frequency
72
+ def mtof(note)
73
+ return mtof(0) if note < 0
74
+ return mtof(127) if 127 < note
75
+ return 8.17579891564 * Math.exp(0.0577622650 * note)
76
+ end
77
+
78
+ # frequency to midi note
79
+ def ftom(f)
80
+ return f > 0 ? 17.3123405046 * Math.log(0.12231220585 * f) : -1500
81
+ end
82
+ end
83
+
84
+ # private internal Class
85
+ class SampleLoader #:nodoc:
86
+ include Singleton
87
+
88
+ MAX_SIMULTANEOUS_PLAYBACKS = 1000
89
+
90
+ def initialize
91
+ @samples = {}
92
+ end
93
+
94
+ def load(f)
95
+ @samples[f] = load_file(f) if @samples[f].nil?
96
+ return @samples[f]
97
+ end
98
+
99
+ alias get load
100
+
101
+ def load_file(file)
102
+ return BASS_SampleLoad.call(0, file, 0, 0,
103
+ MAX_SIMULTANEOUS_PLAYBACKS, 0)
104
+ end
105
+ end
106
+ end
data/lib/sgl/bass.rb ADDED
@@ -0,0 +1,46 @@
1
+ # Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
2
+ # License: Ruby License
3
+
4
+ require 'Win32API'
5
+ require 'singleton'
6
+ require 'sgl/bass-sample'
7
+ require 'sgl/bass-api'
8
+
9
+ module Bass
10
+ at_exit { BASS_Free.call }
11
+
12
+ class BassLib
13
+ include Singleton
14
+
15
+ def initialize
16
+ #ret = Bass::BASS_Init.call(-1, 44100, BASS_DEVICE_OGG, 0)
17
+ ret = Bass::BASS_Init.call(-1, 44100, 0, 0)
18
+ ver = Bass::BASS_GetVersion.call
19
+ ret = Bass::BASS_Start.call
20
+ @playing_channel = []
21
+ end
22
+
23
+ def add_playing_channel(ch)
24
+ @playing_channel << ch
25
+ end
26
+
27
+ def stop_all
28
+ @playing_channel.each {|ch|
29
+ ret = Bass::BASS_ChannelStop.call(ch)
30
+ }
31
+ @playing_channel = []
32
+ end
33
+ end
34
+
35
+ # class << Bass
36
+ # def init(a, b, c, d) BASS_Init.call(a, b, c, d) end
37
+ # def start() BASS_Start.call() end
38
+ # def errorGetCode() BASS_ErrorGetCode.call() end
39
+ # def getVersion() BASS_GetVersion.call() end
40
+ # def free() BASS_Free.call() end
41
+ # def sampleLoad(a, b, c, d, e, f) BASS_SampleLoad.call(a, b, c, d, e, f) end
42
+ # def samplePlay(a) BASS_SamplePlay.call(a) end
43
+ # def samplePlayEx(a, b, c, d, e, f) BASS_SamplePlayEx.call(a, b, c, d, e, f) end
44
+ # end
45
+ #at_exit { Bass.free; }
46
+ end
@@ -0,0 +1,43 @@
1
+ # Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
2
+ # License: Ruby License
3
+
4
+ require "osx/cocoa"
5
+ require "sgl/sgl-color"
6
+ require "sgl/cocoa-event"
7
+ require "sgl/cocoa-window"
8
+ require "sgl/cocoa-draw"
9
+ require "sgl/cocoa-color"
10
+ require "sgl/cocoa-media"
11
+
12
+ module SGL
13
+ class Application
14
+ def initialize
15
+ initialize_cocoa
16
+ initialize_window
17
+ initialize_color
18
+ initialize_event
19
+ end
20
+
21
+ def initialize_cocoa
22
+ OSX.ruby_thread_switcher_start(0.001, 0.01)
23
+ Thread.abort_on_exception = true
24
+
25
+ @app = OSX::NSApplication.sharedApplication
26
+ mainmenu = OSX::NSMenu.alloc.init
27
+ @app.setMainMenu(mainmenu)
28
+ end
29
+ private :initialize_cocoa
30
+
31
+ def run
32
+ OSX.NSApp.run
33
+ OSX::NSEvent.stopPeriodicEvents
34
+ end
35
+
36
+ def stop
37
+ close_window
38
+ OSX.NSApp.stop(nil)
39
+ OSX::NSEvent.startPeriodicEventsAfterDelay(0.01, :withPeriod, 0.01)
40
+ end
41
+ end
42
+ end
43
+
@@ -0,0 +1,65 @@
1
+ # Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
2
+ # License: Ruby License
3
+
4
+ module SGL
5
+ def background(*a) $__a__.background(*a); end
6
+ def backgroundHSV(*a) $__a__.backgroundHSV(*a); end
7
+ def color(*a) $__a__.color(*a); end
8
+ def colorHSV(*a) $__a__.colorHSV(*a); end
9
+
10
+ class Application
11
+ def initialize_color
12
+ @bg_color = @cur_color = nil
13
+ @rgb = ColorTranslatorRGB.new(100, 100, 100, 100)
14
+ @hsv = ColorTranslatorHSV.new(100, 100, 100, 100)
15
+ end
16
+ private :initialize_color
17
+ attr_reader :cur_color
18
+
19
+ def background(x, y=nil, z=nil, a=nil)
20
+ @bg_color = @rgb.norm(x,y,z,a)
21
+ end
22
+
23
+ def backgroundHSV(x, y=nil, z=nil, a=nil)
24
+ @bg_color = @hsv.norm(x,y,z,a)
25
+ end
26
+
27
+ def color(x, y=nil, z=nil, a=nil)
28
+ @cur_color = @rgb.norm(x,y,z,a)
29
+ set_cur_color
30
+ end
31
+
32
+ def colorHSV(x, y=nil, z=nil, a=nil)
33
+ @cur_color = @hsv.norm(x,y,z,a)
34
+ set_cur_color
35
+ end
36
+
37
+ # called from cocoa-media
38
+ # Since thie method called from NSFont, this should be public.
39
+ def make_cur_color
40
+ make_color(*@cur_color)
41
+ end
42
+
43
+ def get_cur_color_alpha
44
+ @cur_color[3]
45
+ end
46
+
47
+ # private
48
+ def set_cur_color
49
+ set_color(*@cur_color)
50
+ end
51
+
52
+ def set_cur_bg
53
+ set_color(*@bg_color)
54
+ end
55
+
56
+ def set_color(*a)
57
+ make_color(*a).set if @win
58
+ end
59
+
60
+ def make_color(r, g, b, a)
61
+ OSX::NSColor.colorWithDeviceRed(r, :green, g, :blue, b, :alpha, a)
62
+ end
63
+ private :set_cur_color, :set_cur_bg, :set_color, :make_color
64
+ end
65
+ end
@@ -0,0 +1,72 @@
1
+ # Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
2
+ # License: Ruby License
3
+
4
+ module SGL
5
+ module FrameTranslator
6
+ def to_xywh(a,b,c,d)
7
+ [[a, c].min, [b, d].min, (a - c).abs, (b - d).abs]
8
+ end
9
+ private :to_xywh
10
+ end
11
+
12
+ def point(*a) $__a__.point(*a); end
13
+ def lineWidth(*a) $__a__.lineWidth(*a); end
14
+ def line(*a) $__a__.line(*a); end
15
+ def rect(*a) $__a__.rect(*a); end
16
+ def circle(*a) $__a__.circle(*a); end
17
+ def rotateZ(*a) $__a__.rotateZ(*a); end
18
+ def translate(*a) $__a__.translate(*a); end
19
+ def scale(*a) $__a__.scale(*a); end
20
+ def reset(*a) $__a__.reset(*a); end
21
+
22
+ class Application
23
+ include FrameTranslator
24
+
25
+ def point(a,b)
26
+ line(a,b,a,b)
27
+ end
28
+
29
+ def lineWidth(w)
30
+ OSX::NSBezierPath.setDefaultLineWidth(w)
31
+ end
32
+
33
+ def line(a,b,c,d)
34
+ #OSX::NSBezierPath.strokeLine({:fromPoint=>OSX::NSPoint.new(a, b),
35
+ # :toPoint=>OSX::NSPoint.new(c, d)})
36
+ OSX::NSBezierPath.strokeLineFromPoint(OSX::NSPoint.new(a, b),
37
+ :toPoint, OSX::NSPoint.new(c, d))
38
+ end
39
+
40
+ def rect(a,b,c,d)
41
+ rect = OSX::NSRect.new(*to_xywh(a, b, c, d))
42
+ OSX::NSBezierPath.bezierPathWithRect(rect).fill
43
+ end
44
+
45
+ def circle(x, y, r)
46
+ rect = OSX::NSRect.new(x - r, y - r, 2*r, 2*r)
47
+ OSX::NSBezierPath.bezierPathWithOvalInRect(rect).fill
48
+ end
49
+
50
+ def rotateZ(deg)
51
+ af = OSX::NSAffineTransform.transform
52
+ af.rotateByDegrees(deg)
53
+ af.concat
54
+ end
55
+
56
+ def translate(x, y)
57
+ af = OSX::NSAffineTransform.transform
58
+ af.translateXBy(x, :yBy, y)
59
+ af.concat
60
+ end
61
+
62
+ def scale(x, y=nil)
63
+ af = OSX::NSAffineTransform.transform
64
+ y ? af.scaleXBy(x, :yBy, y) : af.scaleBy(x)
65
+ af.concat
66
+ end
67
+
68
+ def reset
69
+ OSX::NSAffineTransform.transform.set
70
+ end
71
+ end
72
+ end