Skip to main content
Topic: Set Midi Volume (Read 16283 times) previous topic - next topic

Set Midi Volume

Windows Media Player can wreck havoc on volume settings, so I thought a User Tool might fix things.

Copy the code and save it in your Scripts folder as: MidiVol.vbs
Code: (MidiVol.vbs) [Select · Download]
'Set MIDI Volume, Ver 1.01, Rick G.
For Each e In WScript.Arguments
  If IsNumeric(e) Then SetMidi e: WScript.Quit
Next
WScript.Echo "Argument: 0 - 100 required."

Sub SetMidi(volume)
  Set o = CreateObject("WMPlayer.OCX")
  o.settings.volume = volume
  o.settings.balance = 0
  With CreateObject("Scripting.FileSystemObject")
    f = .BuildPath(.GetSpecialFolder(2), "MidiVol.mid")
    .CreateTextFile(f, 1).Write _
      "MThd" & String(3, 0) & Chr(6) & String(5, 0) & "0"
    o.URL = f ' open, wait while Transitioning
    Do: WScript.Sleep 100: Loop While o.playState = 9
    o.close: .DeleteFile f ' settings now pertain to MIDI
  End With
End Sub '<eof>
Copy this and add it to: nwc2UserTools.ini
Code: (nwc2UserTools.ini) [Select · Download]
Set Midi Volume='wscript scripts\midivol.vbs <PROMPT:(0 - 100) =#[0,100]>'
Quote from: Set Midi Volume
'wscript scripts\midivol.vbs <PROMPT:(0 - 100) =#[0,100]>'

NWC's prompt mechanism makes a perfect front end, remembering the settings that WMP ignores.

Windows Media Player 7+ is required. It will harmlessly err if not present.
Tested on Win98SE and WinXP(Home Edition).

After some argument checking, the program opens WMP, writes a tiny MIDI file to %TEMP%, which is loaded into WMP, then deleted. This is needed to tell WMP to change the MIDI settings. Loading a wav file here will change the Wave settings. Balance is set to mid-range since I can't imagine why it should be anything else for NoteWorthy.

You can also create a ShortCut to this and hard code a volume setting into the Target: field.

If opinions are favorable, I could move this to the Tips area.

Edited on: 2007-02-14
Ver 1.1:
  • Shortened arg check. Replaced MsgBox with Echo so that program can be used in a console window.
  • Moved settings to top of function. WMP stores them until media is loaded.
  • Shortened dummy MIDI file. WMP just needs the header. MIDI events are not needed.
Moved original version to: here
Registered user since 1996

Re: Set Midi Volume

Reply #1
Rick
Worked like a charm on XP Pro , actually is XP tablet pc edition. Looks lie a winner from here.

Keith
Illigitimi Non Carborundum

 

Re: Set Midi Volume

Reply #2
Original version as posted on: 2007-02-11 09:03 am
Code: [Select · Download]
Option Explicit 'Ver 1.0, Rick G.
Const Title = "Set Midi Volume"
If WScript.Arguments.Count Then
  If IsNumeric(WScript.Arguments(0)) Then
    SetMidi WScript.Arguments(0)
  End If
Else
  MsgBox "Argument: 0 - 100 required.",, Title
End If

Sub SetMidi(volume) ' requires wmp 7+
  Dim f, o: Set o = CreateObject("WMPlayer.OCX")
  With CreateObject("Scripting.FileSystemObject")
    f = .BuildPath(.GetSpecialFolder(2), .GetTempName & ".mid")
    .CreateTextFile(f, 1).Write _
    "MThd" & db("00 00 00 06 00 00 00 01 00 C0") & _
    "MTrk" & db("00 00 00 09 86 00 90 47 00 00 FF 2F 00")
    o.URL = f ' open, wait while Transitioning
    Do: WScript.Sleep 100: Loop While o.playState = 9
    ' setting now pertain to MIDI
    o.settings.volume = volume
    o.settings.balance = 0
    o.close: .DeleteFile f
  End With
End Sub
Function db(s) ' debug in, binary out
  For Each s In Split(s): db = db & Chr("&h" & s): Next
End Function
Registered user since 1996