Play button for Midi Files not working
Hy,
I try to make an instrument where I can play my midi files. I tried and found some code and testet it but I had no luck. Here is a code I found but if I press the play button nothing happens. The midi files are loaded.
on ui_control ($play) if ($play = 1) end if end on on listener $cur_listener_id := $NI_CALLBACK_ID if ($play = 1) if ($mf_length = -1) mf_get_last($TRACK_IDX) $mf_length := mf_get_pos() end if if ($prev_ext_song_pos = $NI_SONG_POSITION) $cur_song_pos := $cur_song_pos + $LISTENER_BEAT_LENGTH_TICKS else $cur_song_pos := $NI_SONG_POSITION end if $prev_ext_song_pos := $NI_SONG_POSITION mf_get_next_at($TRACK_IDX, $cur_song_pos mod $mf_length) $end_of_beat := $cur_song_pos mod $mf_length + $LISTENER_BEAT_LENGTH_TICKS $last_pos := $cur_song_pos mod $mf_length while (mf_get_pos() < $end_of_beat and $play = 1 and $cur_listener_id = $NI_CALLBACK_ID) if (mf_get_command() = 0) $end_of_beat := $end_of_beat mod $mf_length mf_get_first($TRACK_IDX) $diff := $mf_length - $last_pos + mf_get_pos() else $diff := mf_get_pos() - $last_pos end if if (ticks_to_ms($diff) > 0) wait_ticks($diff) end if if ($play = 1) play_note(mf_get_byte_one(),mf_get_byte_two(),0,0) end if $last_pos := mf_get_pos() mf_get_next($TRACK_IDX) end while end if end on
Can you help me please?
Thanks a lot
Kind Regards Roman
Comments
-
UI Control Play Button: This part of the code is listening for button presses on the play button (
$play
).on ui_control ($play) if ($play = 1) end if end on
This section of code doesn't seem to be doing anything. When the play button is pressed (
$play = 1
), there is no action inside the if statement.Listener Callback: This block of code runs on every beat and is attempting to sequence the playback of MIDI notes:
on listener ... end on
Based on the code you've shown, here are some potential issues:
- Play Button Does Nothing: As mentioned above, there's no action in the
$play
UI control block. You probably need to initialize or set some variables there to signal the listener callback to start playing. - Initial Values: Before using certain variables, you should ensure that they are initialized to appropriate values. For example, variables like
$mf_length
,$cur_song_pos
,$prev_ext_song_pos
, etc., might not have been initialized. - Listener Triggering: The listener callback triggers on every beat. If there is no song playing or if KONTAKT's host transport (DAW transport) isn't running, the listener might not get called.
To troubleshoot and fix:
- Make sure that KONTAKT's transport or your DAW's transport is running when you press play. The listener callback is dependent on it.
- Make sure the play button sets up necessary variables. For example:
on ui_control ($play) if ($play = 1) $mf_length := -1 $cur_song_pos := 0 $prev_ext_song_pos := 0 ... [other initializations] ... end if end on
- Ensure that your MIDI files are loaded correctly and that the
$TRACK_IDX
is referencing the correct track. - If you're still having issues, consider adding some debug messages to your script using the
message
function to trace the flow of your script and understand where it might be breaking. For example:
message("Play button pressed")
or
message("In listener callback")
Make sure you're not getting any error messages in KONTAKT. If there are errors, they can give you more insights into what's going wrong.
0 - Play Button Does Nothing: As mentioned above, there's no action in the
Categories
- All Categories
- 19 Welcome
- 1.4K Hangout
- 60 NI News
- 762 Tech Talks
- 4K Native Access
- 16.3K Komplete
- 2K Komplete General
- 4.3K Komplete Kontrol
- 5.6K Kontakt
- 1.6K Reaktor
- 374 Battery 4
- 831 Guitar Rig & FX
- 423 Massive X & Synths
- 1.2K Other Software & Hardware
- 5.6K Maschine
- 7.1K Traktor
- 7.1K Traktor Software & Hardware
- Check out everything you can do
- Create an account
- See member benefits
- Answer questions
- Ask the community
- See product news
- Connect with creators