Transposing Chords.

KMCMDS
KMCMDS Member Posts: 3 Newcomer

This is probably really simple. Apologies in advance for my lack of knowledge.

I'm making a simple instrument for my friend that plays specific chords on specific keys.

If you think - it works like XFER Cthulu - but with way less functionality and comically bad MSpaint graphics.

The way I've gone about it but using switches to change between different sets of chords that are pre-set on each key. For Example:

if ($switch1 = 1)
if($EVENT_NOTE = 0 or $EVENT_NOTE = 12 or $EVENT_NOTE = 24 or $EVENT_NOTE = 36 or $EVENT_NOTE = 48 or $EVENT_NOTE = 60 or $EVENT_NOTE = 72 or $EVENT_NOTE = 84 or $EVENT_NOTE = 96 or $EVENT_NOTE = 108 or $EVENT_NOTE = 120)
message ("AM")
 play_note($EVENT_NOTE+7,$EVENT_VELOCITY,0,-1)
 play_note($EVENT_NOTE+16,$EVENT_VELOCITY,0,-1)
end if
end if

So I want to add a transpose menu or knob. Ideally one that shows what key you're transposing to.

I've tried using the "Transpose" factory script, both on a new script tab and within the main script. Both don't work as I hoped - but suspect I'm missing something.

When Transpose script is on the main script, the only note that transposes is the note pressed (the "chord" stays the same) and while on a new script tab - everything transposes but it doubles up everything (polyphony jumps to 6 instead of three in the above example)

I'm also sure I'm going about this a really roundabout way by writing this as an "if $Event_Note = x)" type thing - Perhaps I should be using a table or array or some clever math that's beyond me?

Again, apologies for the lack of understanding - however would really appreciate a point in the right direction if anyone has any ideas.

Best Answer

  • EvilDragon
    EvilDragon Moderator Posts: 1,023 mod
    Answer ✓

    Hmmm it seems to me you're trying to repeat what Harmonize - Tonal script is already doing. Did you try that one out?

    When you open that script's edit view, you will see $MAPPING_STYLE constant, you can set it to 1 if you don't want to play the "too jazzy" notes" that are out of scale you select. Plus it already has a selection of scales in there.

    Plus, you can load the transpose script in the script slot preceeding the Harmonize Tonal script, if you want. But it already has a key and a scale so that might not be necessary.

Answers

  • Matt_NI
    Matt_NI Administrator Posts: 1,110 admin

    @EvilDragon Any pointers on this one by any chance?

  • EvilDragon
    EvilDragon Moderator Posts: 1,023 mod

    I'd like to have more info about how you structured your UI so that a more all-encompassing solution could be had.

    Your example code could've been much more simplified, for example you could use if ($EVENT_NOTE mod 12 = 0) to test if what is played is a C. You also don't test if generated note is outside of MIDI note range (0, 127), so in an extreme case, your instrument would throw a script warning. Nothing dangerous, just not nice to see by the user.

  • KMCMDS
    KMCMDS Member Posts: 3 Newcomer

    Hey @EvilDragon

    Many thanks for taking the time to look at this; your posts on this and other forums have helped me out so much on other insts so thank you! 

    Firstly - that's perfect on the "Mod 12" - that saves loads of time! I thought there'd be a better way to do that! Is there a similar trick to declare all the black keys and ignore them?

    Re the UI - it's very basic - Here’s where I’m at (thanks to your switch function on another post btw ;) I've not added the extra chords for the other switches yet as wanted to get the transpose thing working first but they will likely just be expansions on the first set of chords (i.e adding a lower octave on the root etc)

    on init
    make_perfview
    set_ui_height_px(537)
    set_ui_width_px(700)
    set_control_par_str ($INST_WALLPAPER_ID,$CONTROL_PAR_PICTURE,"background2")
    
    declare ui_menu $transpose
    add_menu_item ($transpose, "A minor",0)
    add_menu_item ($transpose, "A# minor",1)
    add_menu_item ($transpose, "B minor",2)
    add_menu_item ($transpose, "C minor",3)
    add_menu_item ($transpose, "C# minor",4)
    add_menu_item ($transpose, "D minor",5)
    add_menu_item ($transpose, "D# minor",6)
    add_menu_item ($transpose, "E minor",7)
    add_menu_item ($transpose, "F minor",8)
    add_menu_item ($transpose, "F# minor",9)
    add_menu_item ($transpose, "G minor",10)
    add_menu_item ($transpose, "G# minor",11)
    
    declare $concat_it
    declare $concat_offset
    declare $string_it
    declare $list_it
    declare $preproc_i
    declare $sel_tab
    make_instr_persistent($sel_tab)
    
    declare %switches[3]
      declare ui_button $switch0
                   set_control_par (get_ui_id ($switch0),$CONTROL_PAR_POS_X,0)
    		set_control_par (get_ui_id ($switch0),$CONTROL_PAR_POS_Y,207)
    		set_control_par_str (get_ui_id ($switch0),$CONTROL_PAR_PICTURE, "switch")
      declare ui_button $switch1
       	       set_control_par (get_ui_id ($switch1),$CONTROL_PAR_POS_X,100)
    		set_control_par (get_ui_id ($switch1),$CONTROL_PAR_POS_Y,207)
    		set_control_par_str (get_ui_id ($switch1),$CONTROL_PAR_PICTURE, "switch")
      declare ui_button $switch2
                   set_control_par (get_ui_id ($switch2),$CONTROL_PAR_POS_X,200)
    		set_control_par (get_ui_id ($switch2),$CONTROL_PAR_POS_Y,207)
    		set_control_par_str (get_ui_id ($switch2),$CONTROL_PAR_PICTURE, "switch")
    	
      $preproc_i := 0
      while ($preproc_i<=2)
        %Switches[$preproc_i] := get_ui_id($switch0)+$preproc_i
        inc($preproc_i)
      end while
      declare $_i
    end on
    
    function ChangeTab
      $_i := 0
      while ($_i<3)
        if ($_i=$sel_tab)
          set_control_par(%switches[$_i],$CONTROL_PAR_VALUE,1)
        else
          set_control_par(%switches[$_i],$CONTROL_PAR_VALUE,0)
        end if
        inc($_i)
      end while
    end function
    
    on persistence_changed
      call ChangeTab
    end on
    
    on ui_control($switch0)
      $sel_tab := 0
      call ChangeTab
    end on
    
    on ui_control($switch1)
      $sel_tab := 1
      call ChangeTab
    end on
    
    on ui_control($switch2)
      $sel_tab := 2
      call ChangeTab
    end on
    
    on note
    
     {chord selection 1}
    
    if ($switch0 = 1)
    if($EVENT_NOTE mod 12 = 0)
    message ("c")
     play_note($EVENT_NOTE+7,$EVENT_VELOCITY,0,-1)
     play_note($EVENT_NOTE+16,$EVENT_VELOCITY,0,-1)
    end if
    
     if($EVENT_NOTE mod 12 = 2)
    message ("dm")
     play_note($EVENT_NOTE+7,$EVENT_VELOCITY,0,-1)
     play_note($EVENT_NOTE+15,$EVENT_VELOCITY,0,-1)
     end if
    
     if($EVENT_NOTE mod 12 = 4)
    message ("em")
     play_note($EVENT_NOTE+7,$EVENT_VELOCITY,0,-1)
     play_note($EVENT_NOTE+15,$EVENT_VELOCITY,0,-1)
     end if
    
     if($EVENT_NOTE mod 12 = 5)
    message ("f")
     play_note($EVENT_NOTE+7,$EVENT_VELOCITY,0,-1)
     play_note($EVENT_NOTE+16,$EVENT_VELOCITY,0,-1)
     end if
    
     if($EVENT_NOTE mod 12 = 7)
    message ("g")
     play_note($EVENT_NOTE+7,$EVENT_VELOCITY,0,-1)
     play_note($EVENT_NOTE+16,$EVENT_VELOCITY,0,-1)
     end if
    
    if($EVENT_NOTE mod 12 = 9)
    message ("am")
     play_note($EVENT_NOTE+7,$EVENT_VELOCITY,0,-1)
     play_note($EVENT_NOTE+15,$EVENT_VELOCITY,0,-1)
     end if
    
    if($EVENT_NOTE mod 12 = 11)
    message ("bm")
     play_note($EVENT_NOTE+7,$EVENT_VELOCITY,0,-1)
     play_note($EVENT_NOTE+15,$EVENT_VELOCITY,0,-1)
     end if
    
    if ($EVENT_NOTE = 1 or $EVENT_NOTE = 13 or $EVENT_NOTE = 25 or $EVENT_NOTE = 37 or $EVENT_NOTE = 49 or $EVENT_NOTE = 61 or $EVENT_NOTE = 73 or $EVENT_NOTE = 85 or $EVENT_NOTE = 97 or $EVENT_NOTE = 109 or $EVENT_NOTE = 121 or $EVENT_NOTE = 3 or $EVENT_NOTE = 15 or $EVENT_NOTE = 27 or $EVENT_NOTE = 39 or $EVENT_NOTE = 51 or $EVENT_NOTE = 63 or $EVENT_NOTE = 75 or $EVENT_NOTE = 87 or $EVENT_NOTE = 99 or $EVENT_NOTE = 111 or $EVENT_NOTE = 123 or $EVENT_NOTE = 6 or $EVENT_NOTE = 18 or $EVENT_NOTE = 30 or $EVENT_NOTE = 42 or $EVENT_NOTE = 54 or $EVENT_NOTE = 66 or $EVENT_NOTE = 78 or $EVENT_NOTE = 90 or $EVENT_NOTE = 102 or $EVENT_NOTE = 114 or $EVENT_NOTE = 126 or $EVENT_NOTE = 8 or $EVENT_NOTE = 20 or $EVENT_NOTE = 32 or $EVENT_NOTE = 44 or $EVENT_NOTE = 56 or $EVENT_NOTE = 68 or $EVENT_NOTE = 80 or $EVENT_NOTE = 92 or $EVENT_NOTE = 104 or $EVENT_NOTE = 116 or $EVENT_NOTE = 10 or $EVENT_NOTE = 22 or $EVENT_NOTE = 34 or $EVENT_NOTE = 46 or $EVENT_NOTE = 58 or $EVENT_NOTE = 70 or $EVENT_NOTE = 82 or $EVENT_NOTE = 94 or $EVENT_NOTE = 106 or $EVENT_NOTE = 118)
    message ("toojazzy")
    ignore_event($EVENT_ID)
    end if
    end if
    
    end on
    

    You'll see I've added a simple menu - What I'd like to do is when the user selects say “A#m” it pushes everything up +1semi. Or “Cm” and it pushes everything up +3semis etc. 

    As mentioned I got close with the factory transpose script but it doesn’t seem to transpose the additional notes added - just the note played or something else odd.

    Again, thanks for your time!

  • EvilDragon
    EvilDragon Moderator Posts: 1,023 mod
    Answer ✓

    Hmmm it seems to me you're trying to repeat what Harmonize - Tonal script is already doing. Did you try that one out?

    When you open that script's edit view, you will see $MAPPING_STYLE constant, you can set it to 1 if you don't want to play the "too jazzy" notes" that are out of scale you select. Plus it already has a selection of scales in there.

    Plus, you can load the transpose script in the script slot preceeding the Harmonize Tonal script, if you want. But it already has a key and a scale so that might not be necessary.

  • KMCMDS
    KMCMDS Member Posts: 3 Newcomer

    Ahhhh yeah you're absolutely right - the harmonize tonal script looks like the one I need. I hadn't spotted that one. It's got way more functionality than I would need so will be digging in and butchering it a bit but definitely a better starting point! Thanks again.

Back To Top