I don't know the exact dependency either, but I have some theories:
The highest safe level (that is, the highest level at which the instrument will not fizzle or backfire) is likely calculated the same way as the highest safe spell level. For instance, at level 8, 2nd level spells can be safely cast at power 6 and 3rd at power 4. Specifically, the highest safe level is at most equal to the caster's level minus the level requirement of the item plus one; it's also affected by your Music level. My guess is that Music is used in place of both the spellbook skill and the realm skill here.
The actual power level at which the spell will be cast is random; it can be up to 2 higher than the highest safe level, I believe; it can also be lower. Note that, if a higher level is chosen, it is possible for the spell to fizzle, or, if allowed for the spell, backfire. For example, the Piercing Pipes (Shrill Sound, which is a level 2 spell) will always have a chance of backfiring when used until you are level 9 with enough Music skill. Unfortunately, I don't know the exact Music skill required here. A spell will never be cast at a power level below 1 or above 7.
Note that a music skill of 100 is not enough to make level 7 spell instruments 100% reliable; you need to be at least bard level 24 and somehow have a music skill that's over 100.
Gadgets work the same way as instruments, except that Engineering is used in place of Music and gadgets, unlike instruments, can be used while silenced or in anti-magic zones.
If you want to see the actual power levels, turn on verbose combat messages (or whatever the option is called), and you will see a message like "Piercing Pipes has the effect of Shrill Sound(5)" when used; the (5) indicates the power level.