Midi tuning

This commit is contained in:
adrienmalin 2018-12-31 23:05:56 +01:00
parent 6993e4bd92
commit b904924241
9 changed files with 61 additions and 42 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ export_presets.cfg
# Mono-specific ignores # Mono-specific ignores
.mono/ .mono/
midi/FluidR3 GM.sf2

View File

@ -35,8 +35,7 @@ const SCORES = [
const LINES_CLEARED_NAMES = ["", "SINGLE", "DOUBLE", "TRIPLE", "TETRIS"] const LINES_CLEARED_NAMES = ["", "SINGLE", "DOUBLE", "TRIPLE", "TETRIS"]
const T_SPIN_NAMES = ["", "T-SPIN", "MINI T-SPIN"] const T_SPIN_NAMES = ["", "T-SPIN", "MINI T-SPIN"]
const MIDI_MOVE_CHANNELS = [7, 8, 9, 11] const MIDI_MOVE_CHANNELS = [] #[7, 8, 9, 11, 12]
const MIDI_LINE_CLEAR_CHANNELS = [2, 6, 10]
var next_piece = random_piece() var next_piece = random_piece()
var current_piece var current_piece
@ -89,6 +88,7 @@ func new_piece():
current_piece = next_piece current_piece = next_piece
current_piece.translation = START_POSITION current_piece.translation = START_POSITION
current_piece.emit_trail(true) current_piece.emit_trail(true)
update_ghost_piece()
autoshift_action = "" autoshift_action = ""
update_ghost_piece() update_ghost_piece()
next_piece = random_piece() next_piece = random_piece()
@ -185,7 +185,7 @@ func rotate(direction):
func move_midi(): func move_midi():
for channel_id in MIDI_MOVE_CHANNELS: for channel_id in MIDI_MOVE_CHANNELS:
$MidiPlayer.channel_status[channel_id].pan = current_piece.translation.x / 10.0 $MidiPlayer.channel_status[channel_id].pan = current_piece.translation.x / 10.0
mute_midi_channel(MIDI_MOVE_CHANNELS, false) $MidiPlayer.mute_midi_channels(MIDI_MOVE_CHANNELS, false)
$MidiPlayer/MoveDelay.start() $MidiPlayer/MoveDelay.start()
func update_ghost_piece(): func update_ghost_piece():
@ -232,13 +232,18 @@ func update_score():
score += 100 * s score += 100 * s
goal -= s goal -= s
print(T_SPIN_NAMES[current_piece.t_spin], ' ', LINES_CLEARED_NAMES[lines_to_clear.size()], " Score ", score) print(T_SPIN_NAMES[current_piece.t_spin], ' ', LINES_CLEARED_NAMES[lines_to_clear.size()], " Score ", score)
mute_midi_channel(MIDI_LINE_CLEAR_CHANNELS, false)
$MidiPlayer.play_now()
if lines_to_clear.size() == Tetromino.NB_MINOES: if lines_to_clear.size() == Tetromino.NB_MINOES:
$MidiPlayer/LineLcearDelay.wait_time = 1.71 for channel in $MidiPlayer.line_clear_notes:
$MidiPlayer.channel_status[channel].vomume = 127
$MidiPlayer/LineCLearTimer.wait_time = 0.86
else: else:
$MidiPlayer/LineLcearDelay.wait_time = 0.86 for channel in $MidiPlayer.line_clear_notes:
$MidiPlayer/LineLcearDelay.start() $MidiPlayer.channel_status[channel].vomume = 100
$MidiPlayer/LineCLearTimer.wait_time = 0.43
$MidiPlayer.mute_midi_channels($MidiPlayer.line_clear_notes, false)
$MidiPlayer.play_line_clear()
$MidiPlayer/LineCLearTimer.start()
if goal <= 0: if goal <= 0:
new_level() new_level()
else: else:
@ -271,9 +276,9 @@ func resume():
playing = true playing = true
$DropTimer.start() $DropTimer.start()
$LockDelay.start() $LockDelay.start()
$MidiPlayer.play() $MidiPlayer.resume()
mute_midi_channel(MIDI_MOVE_CHANNELS, true) $MidiPlayer.mute_midi_channels(MIDI_MOVE_CHANNELS, true)
mute_midi_channel(MIDI_LINE_CLEAR_CHANNELS, true) $MidiPlayer.mute_midi_channels($MidiPlayer.line_clear_notes, true)
print("RESUME") print("RESUME")
func pause(): func pause():
@ -293,13 +298,11 @@ func game_over():
func _notification(what): func _notification(what):
if what == MainLoop.NOTIFICATION_WM_FOCUS_OUT: if what == MainLoop.NOTIFICATION_WM_FOCUS_OUT:
pause() pause()
if what == MainLoop.NOTIFICATION_WM_FOCUS_IN:
func mute_midi_channel(channels, muted): resume()
for channel_id in channels:
$MidiPlayer.channel_mute[channel_id] = muted
func _on_MoveDelay_timeout(): func _on_MoveDelay_timeout():
mute_midi_channel(MIDI_MOVE_CHANNELS, true) $MidiPlayer.mute_midi_channels(MIDI_MOVE_CHANNELS, true)
func _on_LineLcearDelay_timeout(): func _on_LineCLearTimer_timeout():
mute_midi_channel(MIDI_LINE_CLEAR_CHANNELS, true) $MidiPlayer.mute_midi_channels($MidiPlayer.line_clear_notes, true)

View File

@ -33,8 +33,8 @@ data = {
script = ExtResource( 2 ) script = ExtResource( 2 )
_sections_unfolded = [ "Cell", "Transform" ] _sections_unfolded = [ "Cell", "Transform" ]
__meta__ = { __meta__ = {
"_editor_clip_": 0, "_editor_clip_": 1,
"_editor_floor_": Vector3( 0, 3, 0 ) "_editor_floor_": Vector3( 0, 1, 0 )
} }
[node name="DropTimer" type="Timer" parent="." index="0"] [node name="DropTimer" type="Timer" parent="." index="0"]
@ -89,15 +89,17 @@ mesh = SubResource( 1 )
[node name="GhostPiece" parent="." index="8" instance=ExtResource( 5 )] [node name="GhostPiece" parent="." index="8" instance=ExtResource( 5 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 5, 0, 0 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 5, 20, 0 )
_sections_unfolded = [ "Transform" ] _sections_unfolded = [ "Pause", "Transform" ]
[node name="MidiPlayer" parent="." index="9" instance=ExtResource( 6 )] [node name="MidiPlayer" parent="." index="9" instance=ExtResource( 6 )]
file = "res://midi/Tetris - Song A.mid" file = "res://midi/Tetris - Song A.mid"
channel_mute = [ false, true, false, false, false, false, false, true, true, true, true, false, false, false, false, false ]
volume_db = -3 volume_db = -3
loop = true loop = true
soundfont = "res://midi/TimGM6mb.sf2" loop_start = 2
soundfont = "res://midi/FluidR3 GM.sf2"
[node name="MoveDelay" type="Timer" parent="MidiPlayer" index="1"] [node name="MoveDelay" type="Timer" parent="MidiPlayer" index="1"]
@ -106,11 +108,11 @@ wait_time = 0.1
one_shot = true one_shot = true
autostart = false autostart = false
[node name="LineLcearDelay" type="Timer" parent="MidiPlayer" index="2"] [node name="LineCLearTimer" type="Timer" parent="MidiPlayer" index="2"]
process_mode = 1 process_mode = 1
wait_time = 0.86 wait_time = 1.41
one_shot = false one_shot = true
autostart = false autostart = false
[connection signal="timeout" from="DropTimer" to="." method="_on_DropTimer_timeout"] [connection signal="timeout" from="DropTimer" to="." method="_on_DropTimer_timeout"]
@ -125,6 +127,6 @@ autostart = false
[connection signal="timeout" from="MidiPlayer/MoveDelay" to="." method="_on_MoveDelay_timeout"] [connection signal="timeout" from="MidiPlayer/MoveDelay" to="." method="_on_MoveDelay_timeout"]
[connection signal="timeout" from="MidiPlayer/LineLcearDelay" to="." method="_on_LineLcearDelay_timeout"] [connection signal="timeout" from="MidiPlayer/LineCLearTimer" to="." method="_on_LineCLearTimer_timeout"]

View File

@ -132,7 +132,7 @@ lod_min_hysteresis = 0.0
lod_max_distance = 0.0 lod_max_distance = 0.0
lod_max_hysteresis = 0.0 lod_max_hysteresis = 0.0
emitting = false emitting = false
amount = 20 amount = 4
lifetime = 0.1 lifetime = 0.1
one_shot = false one_shot = false
preprocess = 0.0 preprocess = 0.0

View File

@ -23,7 +23,7 @@ params_point_size = 1.0
params_billboard_mode = 0 params_billboard_mode = 0
params_grow = false params_grow = false
params_use_alpha_scissor = false params_use_alpha_scissor = false
albedo_color = Color( 0.601563, 0.775878, 1, 0.00392157 ) albedo_color = Color( 0.601563, 0.775878, 1, 0.0196078 )
metallic = 0.68 metallic = 0.68
metallic_specular = 1.0 metallic_specular = 1.0
metallic_texture_channel = 0 metallic_texture_channel = 0

View File

@ -89,7 +89,7 @@ adjustment_contrast = 1.0
adjustment_saturation = 0.34 adjustment_saturation = 0.34
_sections_unfolded = [ "Adjustments", "Ambient Light", "Background", "Fog", "Resource" ] _sections_unfolded = [ "Adjustments", "Ambient Light", "Background", "Fog", "Resource" ]
[node name="WorldEnvironment" type="WorldEnvironment" index="0"] [node name="WorldEnvironment" type="WorldEnvironment"]
environment = SubResource( 2 ) environment = SubResource( 2 )

View File

@ -38,7 +38,9 @@ var audio_stream_players = []
var _used_program_numbers = [] var _used_program_numbers = []
var play_later_events = {2: {}, 6:{}, 10:{}} var line_clear_notes = {2: {}, 6: {}}
var line_clear_notes_to_stop
var paused_position = 0
signal changed_tempo( tempo ) signal changed_tempo( tempo )
signal appeared_lyric( lyric ) signal appeared_lyric( lyric )
@ -47,6 +49,7 @@ signal appeared_cue_point( cue_point )
signal looped signal looped
func _ready( ): func _ready( ):
self._prepare_to_play( )
if self.playing: if self.playing:
self.play( ) self.play( )
@ -184,7 +187,6 @@ func _init_channel( ):
@param from_position @param from_position
""" """
func play( from_position = 0 ): func play( from_position = 0 ):
self._prepare_to_play( )
self.playing = true self.playing = true
self.seek( from_position ) self.seek( from_position )
@ -276,13 +278,13 @@ func _process_track( ):
match event.type: match event.type:
SMF.MIDIEventType.note_off: SMF.MIDIEventType.note_off:
if event_chunk.channel_number in line_clear_notes:
line_clear_notes[event_chunk.channel_number].erase(event.note)
self._process_track_event_note_off( channel, event ) self._process_track_event_note_off( channel, event )
if event_chunk.channel_number in play_later_events:
play_later_events[event_chunk.channel_number].erase(event.note)
SMF.MIDIEventType.note_on: SMF.MIDIEventType.note_on:
if event_chunk.channel_number in line_clear_notes:
line_clear_notes[event_chunk.channel_number][event.note] = event
self._process_track_event_note_on( channel, event ) self._process_track_event_note_on( channel, event )
if event_chunk.channel_number in play_later_events:
play_later_events[event_chunk.channel_number][event.note] = event
SMF.MIDIEventType.program_change: SMF.MIDIEventType.program_change:
channel.program = event.number channel.program = event.number
SMF.MIDIEventType.control_change: SMF.MIDIEventType.control_change:
@ -295,11 +297,6 @@ func _process_track( ):
_: _:
# 無視 # 無視
pass pass
func play_now():
for channel in play_later_events:
for note in play_later_events[channel]:
_process_track_event_note_on( channel_status[channel], play_later_events[channel][note] )
func _process_track_event_note_off( channel, event ): func _process_track_event_note_off( channel, event ):
var key_number = event.note + self.key_shift var key_number = event.note + self.key_shift
@ -409,3 +406,19 @@ func get_now_playing_polyphony( ):
if audio_stream_player.playing: if audio_stream_player.playing:
polyphony += 1 polyphony += 1
return polyphony return polyphony
func resume():
play(position)
func play_line_clear():
line_clear_notes_to_stop = {2: {}, 6:{}}
for channel in line_clear_notes:
for note in line_clear_notes[channel]:
_process_track_event_note_on(channel_status[channel], line_clear_notes[channel][note])
line_clear_notes_to_stop[channel][note] = line_clear_notes[channel][note]
func mute_midi_channels(channels, muted):
for channel_id in channels:
channel_mute[channel_id] = muted

Binary file not shown.

View File

@ -52,6 +52,6 @@ rotate_clockwise=[ Object(InputEventJoypadButton,"resource_local_to_scene":false
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":88,"unicode":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":88,"unicode":0,"echo":false,"script":null)
] ]
rotate_counterclockwise=[ Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":0,"pressure":0.0,"pressed":false,"script":null) rotate_counterclockwise=[ Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":0,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777224,"unicode":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777221,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":90,"unicode":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":90,"unicode":0,"echo":false,"script":null)
] ]