Skip to content

Commit

Permalink
BROKEN: add more channel editing to music player
Browse files Browse the repository at this point in the history
Ch1+Ch2 duty cycle in progress, Noise set to-do
Bug: holding up/down eventually crashes, in BGB and VBA, even on the Tempo's dummy case
  • Loading branch information
roukaour committed Aug 4, 2017
1 parent c1afdda commit fc47ea3
Showing 1 changed file with 106 additions and 52 deletions.
158 changes: 106 additions & 52 deletions musicplayer.asm
Expand Up @@ -411,13 +411,96 @@ SongEditor:
jp SongEditor

.up:
; for ch1/ch2: next duty cycle
; for wave: next waveform
; for noise: next noise set
; for pitch: increase pitch transposition
ld a, [wChannelSelector]
cp MP_EDIT_PITCH
jr z, .up_pitch
cp MP_EDIT_WAVE
jp nz, SongEditor
ld hl, .up_jumptable
rst JumpTable

.up_jumptable
dw .up_ch1_2 ; MP_EDIT_CH1
dw .up_ch1_2 ; MP_EDIT_CH2
dw .up_wave ; MP_EDIT_WAVE
dw .up_noise ; MP_EDIT_NOISE
dw .up_pitch ; MP_EDIT_PITCH
dw SongEditor ; MP_EDIT_TEMPO

.down:
; for ch1/ch2: previous duty cycle
; for wave: previous waveform
; for noise: previous noise set
; for pitch: decrease pitch transposition
ld a, [wChannelSelector]
ld hl, .down_jumptable
rst JumpTable

.down_jumptable:
dw .down_ch1_2 ; MP_EDIT_CH1
dw .down_ch1_2 ; MP_EDIT_CH2
dw .down_wave ; MP_EDIT_WAVE
dw .down_noise ; MP_EDIT_NOISE
dw .down_pitch ; MP_EDIT_PITCH
dw SongEditor ; MP_EDIT_TEMPO

.start:
; toggle piano roll info overlay
ld hl, wSongInfoSwitch
ld a, [hl]
xor 1
ld [hl], a
call DrawPianoRollOverlay
jp SongEditor

.select_b:
; exit song editor
call ClearChannelSelector
xor a ; ld a, MP_EDIT_CH1
ld [wChannelSelector], a
call DrawPitchTransposition
call DrawTempoAdjustment
jp MusicPlayerLoop

.up_ch1_2:
; next duty cycle
ld a, [wChannelSelector]
ld [wTmpCh], a
call GetDutyCycleAddr
ld a, [hl]
lb bc, %11000000, %01000000
and b
cp b
ld a, [hl]
jr nz, .no_ch1_2_overflow
sub c
and %00111111
.no_ch1_2_overflow
add c
jr .change_ch1_2

.down_ch1_2:
; previous duty cycle
ld a, [wChannelSelector]
ld [wTmpCh], a
call GetDutyCycleAddr
ld a, [hl]
lb bc, %11000000, %01000000
and b
and a
ld a, [hl]
jr nz, .no_ch1_2_underflow
add c
and %00111111
.no_ch1_2_underflow
sub c
.change_ch1_2:
ld [hl], a
ld [wCurTrackDuty], a
jp SongEditor

.up_wave:
; next waveform
ld a, [Channel3Intensity]
and $f
inc a
Expand All @@ -426,14 +509,8 @@ SongEditor:
xor a
jr .change_wave

.down:
; for wave: previous waveform
; for pitch: decrease pitch transposition
ld a, [wChannelSelector]
cp MP_EDIT_PITCH
jr z, .down_pitch
cp MP_EDIT_WAVE
jp nz, SongEditor
.down_wave:
; previous waveform
ld a, [Channel3Intensity]
and $f
dec a
Expand All @@ -450,7 +527,15 @@ SongEditor:
farcall ReloadWaveform
jp SongEditor

; TODO: up/down for noise adjusts MusicNoiseSampleSet
.up_noise:
; next noise set
.down_noise:
; previous noise set
jp SongEditor

.up_pitch:
; increase pitch transposition
ld a, [wPitchTransposition]
inc a
cp MAX_PITCH_TRANSPOSITION + 1
Expand All @@ -459,6 +544,7 @@ SongEditor:
jr .change_pitch

.down_pitch:
; decrease pitch transposition
ld a, [wPitchTransposition]
dec a
cp -(MAX_PITCH_TRANSPOSITION + 1)
Expand All @@ -473,24 +559,6 @@ SongEditor:
call DelayFrame
jp SongEditor

.start:
; toggle piano roll info overlay
ld hl, wSongInfoSwitch
ld a, [hl]
xor 1
ld [hl], a
call DrawPianoRollOverlay
jp SongEditor

.select_b:
; exit song editor
call ClearChannelSelector
xor a ; ld a, MP_EDIT_CH1
ld [wChannelSelector], a
call DrawPitchTransposition
call DrawTempoAdjustment
jp MusicPlayerLoop

AdjustTempo:
ld a, 1
ld [wAdjustingTempo], a
Expand Down Expand Up @@ -1372,25 +1440,17 @@ endr
ret

GetPitchAddr:
ld a, [wTmpCh]
add a
ld hl, PitchAddrs
ld c, a
ld b, 0
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
ret

PitchAddrs:
dw Channel1Pitch
dw Channel2Pitch
dw Channel3Pitch
ld hl, Channel1Pitch
jr _GetChannelMemberAddr

GetOctaveAddr:
ld a, [wTmpCh]
ld hl, Channel1Octave
jr _GetChannelMemberAddr

GetDutyCycleAddr:
ld hl, Channel1DutyCycle
_GetChannelMemberAddr:
ld a, [wTmpCh]
ld bc, Channel2 - Channel1
jp AddNTimes

Expand All @@ -1400,12 +1460,6 @@ GetIntensityAddr:
ld bc, 2
jp AddNTimes

GetDutyCycleAddr:
ld a, [wTmpCh]
ld hl, Channel1DutyCycle
ld bc, Channel2 - Channel1
jp AddNTimes

GetSongInfo:
ld a, [wSongSelection]
ld b, a
Expand Down

0 comments on commit fc47ea3

Please sign in to comment.