Author Topic: Direct bass : Vb.net (vb2008, vb2010, vb6, vc#, vc++, devC++, delphi, AutoIt)  (Read 183385 times)

sak2005

  • Posts: 1007
Tip: How to create F# Form Application ::) Get full project : Clickhere

1. Open new Console application
2. Open properties project and changing.. Output type to.. Windows Application
3. Addded Type class MainForm to empty project
4. References System windows form (Open)
5. Added sub new fuction and add construct operators
6. Created and add controls to the mainform

Example:
Code: [Select]
#light

//using namespace
open System
open System.IO
open System.Data
open System.Drawing
open System.Threading
open System.Windows.Forms
open System.ComponentModel
open System.Runtime.InteropServices

//created Module
module BASS =         
  module private Imported =
     [<DllImport( "bass.dll", CharSet=CharSet.Auto, EntryPoint="BASS_Init")>]
     extern bool _Init(int device, int freq, int flags, IntPtr win, IntPtr clsid)
     [<DllImport( "bass.dll", CharSet=CharSet.Auto, EntryPoint="BASS_StreamCreateFile")>]
     extern int _StreamCreateFile(bool mem, string file, int64 offset, int64 length, int flags)
     [<DllImport( "bass.dll", CharSet=CharSet.Auto, EntryPoint="BASS_ChannelPlay")>]
     extern bool _ChannelPlay(int handle, bool restart)
     [<DllImport( "bass.dll", CharSet=CharSet.Auto, EntryPoint="BASS_StreamFree")>]
     extern bool _StreamFree(int handle)
     [<DllImport( "bass.dll", CharSet=CharSet.Auto, EntryPoint="BASS_Free")>]
     extern bool _Free()
     
  let BASS_Init(device, freq, flags, win) =
      Imported._Init(device, freq, flags, win, IntPtr.Zero)
  let BASS_StreamCreateFile(file, offset, length, flags) =
      Imported._StreamCreateFile(false, file, offset, length, flags)
  let BASS_ChannelPlay(handle, restart) =
      Imported._ChannelPlay(handle, restart)
  let BASS_Free() =
      Imported._Free()
  let BASS_StreamFree(handle) =
      Imported._StreamFree(handle)
  //end module
 
//created Form
type MainForm =
     inherit Form
     val mutable components : System.ComponentModel.IContainer
     val mutable ofdOpen : System.Windows.Forms.OpenFileDialog
     val mutable btnLoad : System.Windows.Forms.Button
     val mutable strm : int
     val mutable file : string 
   
     override this.Dispose (disposing) =
           if disposing && (this.components <> null) then
              this.components.Dispose ()
           base.Dispose (disposing)
     
     member this.InitializeComponent () =
            this.components <- new System.ComponentModel.Container ()
            this.ofdOpen <- new System.Windows.Forms.OpenFileDialog ()
            this.btnLoad <- new System.Windows.Forms.Button ()
            this.SuspendLayout ()
            // OpenFileDialog
            this.ofdOpen.Filter <- "Media Files(*.wav;*.mp3)|.*wav;*.mp3"
            // Button1
            this.btnLoad.Name <- "Button1"
            this.btnLoad.Text <- "Load"
            this.btnLoad.Size <- new Size(60, 25)
            this.btnLoad.Location <- new Point(5, 185)
            this.btnLoad.Cursor <- Cursors.Hand
            this.btnLoad.Click.AddHandler(new System.EventHandler (fun s e -> this.btnLoad_Click(s, e)))
            // Form1
            this.Name <- "Form1"
            this.Text <- "F#FormApp"
            this.StartPosition <- FormStartPosition.CenterScreen
            this.AutoSizeMode <- AutoSizeMode.GrowAndShrink
            this.MaximizeBox <- false
            this.AutoScaleDimensions <- new System.Drawing.SizeF (6.0f, 13.0f)
            this.AutoScaleMode <- System.Windows.Forms.AutoScaleMode.Font
            this.ClientSize <- new System.Drawing.Size (267, 220)
            this.Controls.Add(this.btnLoad)
            this.FormClosing.AddHandler(new System.Windows.Forms.FormClosingEventHandler (fun s e -> this.MainForm_FormClosing(s, e)))
            this.ResumeLayout (false)
   
     member this.btnLoad_Click (sender : System.Object, e : EventArgs) =
            if this.ofdOpen.ShowDialog() = DialogResult.OK then
               if this.strm <> 0 then BASS.BASS_StreamFree(this.strm)|>ignore
               this.file <- this.ofdOpen.FileName
               this.strm <- BASS.BASS_StreamCreateFile(this.file, int64(0), int64(0), 0x80000000 ||| 4)
               BASS.BASS_ChannelPlay(this.strm, false)|>ignore
     
     member this.MainForm_FormClosing (sender : System.Object, e : FormClosingEventArgs) =
            BASS.BASS_Free()|>ignore
             
     new () as this =
          {
              components = null;
              ofdOpen = null;
              btnLoad = null;
              strm = 0;
              file = "";
          }
              then
              this.InitializeComponent()
              BASS.BASS_Init(-1, 44100, 0, this.Handle)|>ignore
              //end Form

//create startup
[<STAThread>]
let main() =
    Application.EnableVisualStyles()
    Application.SetCompatibleTextRenderingDefault(false)
    Application.Run(new MainForm())
[<STAThread>]
main()
//ens startup

« Last Edit: 5 Oct '17 - 20:16 by sak2005 »

sak2005

  • Posts: 1007
Tip: How to  Create F# Library ::)

The Module has 2 modules is MainModule and SubModule

In the module has Type is class , and has 2 classes is ClassForm and ClassLibrary

For this example codes , using module for call bass APIs and using class type for methods bass.

If created library dlls , must using namespace, if not then get error! open system fail.

SampleCode:
Code: [Select]
namespace FSharp.Library1 //Must using namespace.

open System
open System.Runtime.InteropServices

//Call bass APIs
module private BASS =
   [<DllImport("bass.dll", CharSet=CharSet.Auto, EntryPoint="BASS_Init")>]
     extern bool _Init(int device, int freq, int iflags, IntPtr win, IntPtr clsid)
   [<DllImport("bass.dll", CharSet=CharSet.Auto, EntryPoint="BASS_StreamCreateFile")>]
     extern int _StreamCreateFile(bool mem, string file, int64 offset, int64 length, int bflags)
   [<DllImport("bass.dll", CharSet=CharSet.Auto, EntryPoint="BASS_ChannelPlay")>]
     extern bool _ChannelPlay(int handle, bool restart)
   [<DllImport("bass.dll", CharSet=CharSet.Auto, EntryPoint="BASS_ChannelBytes2Seconds")>]
     extern double _ChannelBytes2Seconds(int handle, int64 lenpos)
   [<DllImport("bass.dll", CharSet=CharSet.Auto, EntryPoint="BASS_ChannelGetLength")>]
     extern int64 _ChannelGetLength(int handle, int mode)
   [<DllImport("bass.dll", CharSet=CharSet.Auto, EntryPoint="BASS_ChannelGetPosition")>]
     extern int64 _ChannelGetPosition(int handle, int mode)
   
//Bass class.
type public Bass() =     
     inherit Object()
       
     member this.BASS_Init(device:int, freq:int, iflags:int, win:IntPtr):bool=
            BASS._Init(device, freq, iflags, win, IntPtr.Zero) 
     member this.BASS_StreamCreateFile(file:string, offset:int64, length:int64, bflags:int):int=
            BASS._StreamCreateFile(false, file, offset, length, bflags ||| 0x80000000)
     member this.BASS_ChannelPlay(handle:int, restart:bool):bool=
            BASS._ChannelPlay(handle, restart)

Example:
Code: [Select]
// Console Application

open System
open FSharp.Library1 //References Dll.
     
let bass = new Bass() //Created Instance.

let bl = bass.BASS_Init(-1, 44100, 0, IntPtr.Zero)
let ch = bass.BASS_StreamCreateFile("sound.mp3", int64(0), int64(0), 0)
let pl = bass.BASS_ChannelPlay(ch, false)
let vk = Console.ReadKey()
« Last Edit: 9 Oct '17 - 17:35 by sak2005 »

sak2005

  • Posts: 1007
Tip: F# EventHandler and other Events ::)

Example:
Code: [Select]
//Console Application
open System

//Event class
type ShowNumber(num : int) = class
     inherit EventArgs()
     let mutable _num = num
     let numChanged = new Event<unit>() //created event
     member this.NumChanged = numChanged.Publish //exposed event handler
     member this.Num
        with get() = _num //get OldNum
        and set(value) =
           _num <- value    //if set NewNum, will event
           numChanged.Trigger() //invokes event handler
end         

//Test
let p = new ShowNumber(0) //created new instance and set args value OldNum
printfn "-- Name changed! Old num: %i" p.Num //show old num
p.NumChanged.Add(fun () ->
printfn "-- Name changed! New name: %i" p.Num) //event for show new num
p.Num <- 100 //set new num
let vk = Console.ReadKey()
« Last Edit: 10 Oct '17 - 17:24 by sak2005 »

sak2005

  • Posts: 1007
Tip : Properties F# and C#

Code: [Select]
//Console Application
open System

//properties class type
let mutable _num = 0
type Number1 =
 member this.Num with get()= _num
                  and set(value)= _num <- value

//method class type
type Number2(num : int)=
     let mutable _num = num
     member this.Num with get()= _num
                      and set(value)= _num <- value

Code: [Select]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    #region number class
    sealed class Number
    {
        private static int _num;
        public static int Num
        {
            get
            {
                return _num;
            }
            set
            {
                _num = value;
            }
        }

        public static int ShowNum(int num)
        {
            var n = Num = num;
            return n;
        }
    }
    #endregion
}
« Last Edit: 10 Oct '17 - 20:53 by sak2005 »

sak2005

  • Posts: 1007
Tip: Method function F# and C#

Code: [Select]
//Console Application

//Test
 let n = new Number2(100) //set return value 
  let ShowNumber = //method function
      Console.WriteLine(n.Num)
      Console.ReadKey()

Code: [Select]
//Console Application
class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("old num: " + Number.ShowNum(0));
            int n = Number.Num = 100;
            Console.WriteLine("new num: " + Number.ShowNum(n));
            Console.ReadKey();
        }
    }

Note:
If ีusing type()= then is class
If using type = then is properties method
« Last Edit: 10 Oct '17 - 20:59 by sak2005 »

sak2005

  • Posts: 1007
Tip F#: Sub method and Function method ???

Code: [Select]
let mymethod() = //this's sub method, no return

Code: [Select]
let mymethod() : int = //this's function method, had return

sak2005

  • Posts: 1007
Tip: Created Sub new in the Class ::)

Example:
Code: [Select]
//f# console application
open System

//class
type MyType(name) =
    let mutable name = name
    do
        () // do some side effect
    member self.DoSomething() =
        ()
    member self.PropName
        with get() = name
        and set value =
            name <- value
   
    new() = new MyType("default name") //sub new

//Test
let mytype = new MyType("Hello")
Console.WriteLine(mytype.PropName)
let vk = Console.ReadKey()
« Last Edit: 10 Oct '17 - 23:34 by sak2005 »

sak2005

  • Posts: 1007
Tip: F# Bass method , properties and events (Form Application)::)

namespace BassPlayer

open System
open System.Drowing
open System.Windows.Forms

type Form1() as this =
        inherit Form()
       //define controls here
       //define Bass APIs here
       //define Bass constructors here
       //define Bass properties here
       //define Bass methods here
       //define Bass events here
       //define Program startup here

---------------------------------------------------------------------------------

Download: F# WinForms - Visual Studio 2010 Clickhere
« Last Edit: 12 Oct '17 - 18:00 by sak2005 »

sak2005

  • Posts: 1007
Some sample codes with methods Bass is.. Init , StreamCreateFile , ChannelPly and Setposition

Code: [Select]
[<DllImport("bass", CharSet=CharSet.Auto, EntryPoint="BASS_Init")>]
static extern bool _Init(int device, int freq, int iflags, IntPtr win, IntPtr clsid)

[<DllImport("bass", CharSet=CharSet.Auto, EntryPoint="BASS_StreamCreateFile")>]
static extern int _StreamCreateFile(bool mem, string file, int64 offset, int64 length, int bflags)

[<DllImport("bass", CharSet=CharSet.Auto)>]
static extern bool BASS_ChannelPlay(int handle, bool restart)

member this.BASS_Init(device: int, freq: int, iflags: int, win: IntPtr): bool =
            _Init(device, freq, iflags, win, IntPtr.Zero)

member this.BASS_StreamCreateFile(file: string, offset: int64, length: int64, bflags: int): int =
            _StreamCreateFile(false, file, offset, length, bflags ||| 0x80000000)

Code: [Select]
member this.SetPosition(pos: double): bool =
            BASS_ChannelSetPosition(chan, BASS_ChannelSeconds2Bytes(chan, pos), 0)
« Last Edit: 12 Oct '17 - 23:13 by sak2005 »

sak2005

  • Posts: 1007
Some sample codes with properties Bass is.. Duration , MaxPosition and CurrentPosition ::)

Code: [Select]
member this.Duration: double =
           BASS_ChannelBytes2Seconds(chan, BASS_ChannelGetLength(chan, 0))
member this.MaxPosition: double =
           this.Duration
member form.CurrentPosition: double =
           BASS_ChannelBytes2Seconds(chan, BASS_ChannelGetPosition(chan, 0))
member this.VuLeft: int =
           BASS_ChannelGetLevel(chan) &&& 65535
member this.VuRight: int =
           (BASS_ChannelGetLevel(chan)>>>16) &&& 65535
member this.CPU: string =
           BASS_GetCPU().ToString("#0.00")
« Last Edit: 12 Oct '17 - 23:18 by sak2005 »

sak2005

  • Posts: 1007
Tip F#: Some code Bass Active Status and bool IsPlaying ::)

Code: [Select]
member this.Status = //return string 
   match BASS_ChannelIsActive(chan) with
       | 1 -> "Playing"
       | 2 -> "Stalled"
       | 3 -> "Pause"
       | _ -> "Stopped"
   
member this.IsPlaying = //return bool
   match BASS_ChannelIsActive(chan) with
       | 1 -> true
       | _ -> false
« Last Edit: 12 Oct '17 - 23:52 by sak2005 »

sak2005

  • Posts: 1007
Tip F#: Learn more with some keyword is.. let and member ::)

If create function in Form or type class then using.. member

let is constructor operater variable, easy using with console app

for example : with codes that error and no error

Code: [Select]
type MainForm() as this =
let _chan = 0
member this.chan with get() = _chan
 //--------------------------------------------       
member this.Button1_Click(e)
this.chan = BASS_StreamCreateFile(file, ---) //error!, chan will return bool

type MainForm() as this =
let mutable _chan = 0

member this.chan with get() = _chan
//---------------------------------------------
member this.Button1_Click(e)
this.chan <-  BASS_StreamCreateFile(file, ---) //no error, chan will return int

Learn more: Microsoft Visual F# Programming Clickhere
« Last Edit: 13 Oct '17 - 09:01 by sak2005 »

sak2005

  • Posts: 1007
Tip F#: How to shared or static Class ::)

Code: [Select]
namespace FSharp.BassLib

open System
open System.Drawing
open System.Windows.Forms
open System.Runtime.InteropServices

[<AbstractClass; Sealed>] //attribute class
type public Bass() =
     inherit Object()
     [<DllImport("bass", CharSet=CharSet.Auto, EntryPoint="BASS_PluginLoad")>]
     static extern int _PluginLoad(string file, int bflags)
     [<DllImport("bass", CharSet=CharSet.Auto)>]
     static extern bool BASS_PluginFree(int bflags)
     [<DllImport("bass", CharSet=CharSet.Auto, EntryPoint="BASS_Init")>]
     static extern bool _Init(int device, int freq, int iflags, IntPtr win, IntPtr clsid)
     [<DllImport("bass", CharSet=CharSet.Auto)>]
     static extern bool BASS_StreamFree(int handle)
     [<DllImport("bass", CharSet=CharSet.Auto, EntryPoint="BASS_StreamCreateFile")>]
     static extern int _StreamCreateFile(bool mem, string file, int64 offset, int64 length, int bflags)
     [<DllImport("bass", CharSet=CharSet.Auto, EntryPoint="BASS_ChannelPlay")>]
     static extern bool _ChannelPlay(int handle, bool restart)
     [<DllImport("bass", CharSet=CharSet.Auto)>]
     static extern bool BASS_ChannelPause(int handle)
     [<DllImport("bass", CharSet=CharSet.Auto)>]
     static extern bool BASS_ChannelStop(int handle)
     [<DllImport("bass", CharSet=CharSet.Auto)>]
     static extern bool BASS_Free()
     [<DllImport("bass", CharSet=CharSet.Auto)>]
     static extern int BASS_ChannelIsActive(int handle)
     [<DllImport("bass", CharSet=CharSet.Auto)>]
     static extern double BASS_ChannelBytes2Seconds(int handle, int64 lenpos)
     [<DllImport("bass", CharSet=CharSet.Auto)>]
     static extern int64 BASS_ChannelGetLength(int handle, int mode)
     [<DllImport("bass", CharSet=CharSet.Auto)>]
     static extern int64 BASS_ChannelGetPosition(int handle, int mode)
     [<DllImport("bass", CharSet=CharSet.Auto)>]
     static extern int64 BASS_ChannelSeconds2Bytes(int handle, double pos)
     [<DllImport("bass", CharSet=CharSet.Auto)>]
     static extern bool BASS_ChannelSetPosition(int handle, int64 pos)
     [<DllImport("bass", CharSet=CharSet.Auto)>]
     static extern int BASS_ChannelGetLevel(int handle)
     
     static let mutable _chan = 0
     static member chan with get() = _chan //operate return of StreamCreateFile
                         and set(v)= _chan <- v
     static member Duration with get()= BASS_ChannelBytes2Seconds(Bass.chan, BASS_ChannelGetLength(Bass.chan, 0))
     static member MaxPosition with get () = BASS_ChannelBytes2Seconds(Bass.chan, BASS_ChannelGetLength(Bass.chan, 0)) 
     static member CurrentPosition with get () =  BASS_ChannelBytes2Seconds(Bass.chan, BASS_ChannelGetPosition(Bass.chan, 0)) 
     static member BASS_PluginLoad(file: string, bflags: int): int =
      _PluginLoad(file, 0x80000000)
     static member BASS_Init(device: int, freq: int, iflags: int, win: IntPtr): bool =
      _Init(device, freq, iflags, win, IntPtr.Zero)
     static member BASS_StreamCreateFile(file: string, offset: int64, length: int64, bflags: int): int =
      _StreamCreateFile(false, file, offset, length, bflags ||| 0x80000000)
     static member BASS_ChannelPlay(handle: int, restart: bool): bool =   
      Bass.chan <- handle
      _ChannelPlay(Bass.chan, restart) 

Example: Test with Console App
Code: [Select]
namespace FSharp.Console1

open System
open System.Collections.Generic

open FSharp.BassLib

module MyConsole =
 
 let bl = Bass.BASS_Init(-1, 44100, 0, IntPtr.Zero)     
 Bass.chan <- Bass.BASS_StreamCreateFile("sound.mp3", int64(0), int64(0), 0)
 let pl = Bass.BASS_ChannelPlay(Bass.chan, false)
 Console.WriteLine("   Init: " + bl.ToString())
 Console.WriteLine(" Stream: " + Bass.chan.ToString())
 Console.WriteLine(" Length: " + Bass.Duration.ToString())
 Console.WriteLine("Playing: " + pl.ToString())
 let vk = Console.ReadKey()
« Last Edit: 13 Oct '17 - 19:29 by sak2005 »

sak2005

  • Posts: 1007
Tip C#: Advance EventHandler, Using.. Event class and Thread ::)

Part1: Constructors
Code: [Select]
using System;
using System.Windows.Forms;
using System.Threading;
using Microsoft.VisualBasic;
using System.Runtime.InteropServices;
namespace BassLib
{
    public class BassClass : object
    {
        #region Bass APIs
        [DllImport("bass", CharSet = CharSet.Auto, EntryPoint = "BASS_PluginLoad")]
        private static extern int _PluginLoad(string file, int iflags);
        [DllImport("bass", CharSet = CharSet.Auto, EntryPoint = "BASS_PluginFree")]
        private static extern bool _PluginFree(int fhandle);
        [DllImport("bass", CharSet = CharSet.Auto, EntryPoint = "BASS_Init")]
        private static extern bool _Init(int device, int freq, int iflags, IntPtr win, IntPtr clsid);
        [DllImport("bass", CharSet = CharSet.Auto, EntryPoint = "BASS_StreamFree")]
        private static extern bool _StreamFree(int handle);
        [DllImport("bass", CharSet = CharSet.Auto, EntryPoint = "BASS_StreamCreateFile")]
        private static extern int _StreamCreateFile(bool mem, string file, long offset, long length, int bflags);
        [DllImport("bass", CharSet = CharSet.Auto, EntryPoint = "BASS_ChannelPlay")]
        private static extern bool _ChannelPlay(int handle, bool restart);
        [DllImport("bass", CharSet = CharSet.Auto, EntryPoint = "BASS_ChannelPause")]
        private static extern bool _ChannelPause(int handle);
        [DllImport("bass", CharSet = CharSet.Auto, EntryPoint = "BASS_ChannelStop")]
        private static extern bool _ChannelStop(int handle);
        [DllImport("bass", CharSet = CharSet.Auto, EntryPoint = "BASS_Free")]
        private static extern bool _Free();
        [DllImport("bass", CharSet = CharSet.Auto, EntryPoint = "BASS_ChannelIsActive")]
        private static extern int _ChannelIsActive(int handle);
        [DllImport("bass", CharSet = CharSet.Auto, EntryPoint = "BASS_ChannelBytes2Seconds")]
        private static extern double _ChannelBytes2Seconds(int handle, long lenpos);
        [DllImport("bass", CharSet = CharSet.Auto, EntryPoint = "BASS_ChannelGetLength")]
        private static extern long _ChannelGetLength(int handle, int mode);
        [DllImport("bass", CharSet = CharSet.Auto, EntryPoint = "BASS_ChannelGetPosition")]
        private static extern long _ChannelGetPosition(int handle, int mode);
        [DllImport("bass", CharSet = CharSet.Auto, EntryPoint = "BASS_ChannelSeconds2Bytes")]
        private static extern long _ChannelSeconds2Bytes(int handle, double pos);
        [DllImport("bass", CharSet = CharSet.Auto, EntryPoint = "BASS_ChannelSetPosition")]
        private static extern bool _ChannelSetPosition(int handle, long pos, int mode);
        [DllImport("bass", CharSet = CharSet.Auto, EntryPoint = "BASS_ChannelGetLevel")]
        private static extern int _ChannelGetLevel(int handle);
        [DllImport("bass", CharSet = CharSet.Auto, EntryPoint = "BASS_GetCPU")]
        private static extern float _GetCPU();
        #endregion
       
        #region Bass Constructors
        private Thread thread = null;
        private static double _pos;
        private static int sflag;
        private static int _strm;
       
        public BassClass() : base()
        {
            Control.CheckForIllegalCrossThreadCalls = false;
            this.thread = new Thread(new ThreadStart(OnPositionChanged));
            this.thread.IsBackground = true;
            this.thread.Priority = ThreadPriority.Lowest;
            this.thread.Start();
            BassClass._strm = 0;
            BassClass.sflag = 0;
            BassClass._pos = (double)0;
        }
        #endregion
        ~BassClass()
        {
            if(this.strm!=0)
            this.BASS_Free();
        }

sak2005

  • Posts: 1007
Part2: Methods and Properties
Code: [Select]
#region Bass methods
        public int BASS_PluginLoad(string file)
        {
            return BassClass._PluginLoad(file, -2147483648);
        }
        public bool BASS_PluginFree(int fhandle)
        {
            return BassClass._PluginFree(fhandle);
        }
        public bool BASS_Init(int device, int freq, int iflags, IntPtr win)
        {
             return BassClass._Init(device, freq, iflags, win, IntPtr.Zero);
        }
        public bool BASS_StreamFree(int handle)
        {
            var bl = false;
            if (handle != 0)
            {
                bl = BassClass._StreamFree(this.strm);
            }
            return bl;
        }
        public int BASS_StreamCreateFile(string file, long offset, long length, int bflags)
        {
           BassClass.sflag = bflags;
            var result = 0;
            this.strm = BassClass._StreamCreateFile(false, file, offset, length, sflag | -2147483648);
            if (this.strm != 0)
            {result = this.strm;}
            else{Interaction.MsgBox("Error! file not support.");}
            return result;
        }
        public bool BASS_ChannelPlay(int handle, bool restart)
        {
            var bl = false;
            if (handle != 0)
            {
               
                bl = BassClass._ChannelPlay(this.strm, restart);
            }
            return bl;
        }
        public bool BASS_ChannelPause(int handle)
        {
            var bl = false;
            if (handle != 0)
            {
                bl = BassClass._ChannelPause(this.strm);
            }
            return bl;
        }
        public bool BASS_ChannelStop(int handle)
        {
            var bl = false;
            if (handle != 0)
            {
                this.SetPosition((double)0);
                bl = BassClass._ChannelStop(this.strm);
            }
            return bl;
        }
        public bool BASS_Free()
        {
            var bl = false;
            if (this.strm != 0)
            {
                bl = BassClass._Free();
            }
            return bl;
        }
        public int BASS_ChannelIsActive(int handle)
        {
            var res = 0;
            if (handle != 0)
            {
                res = BassClass._ChannelIsActive(this.strm);
            }
            return res;
        }
        public double BASS_ChannelBytes2Seconds(int handle, long lenpos)
        {
            var result = (double)0;
            if (handle != 0)
            {
               result = BassClass._ChannelBytes2Seconds(this.strm, lenpos);
            }
            return result;
        }
        public long BASS_ChannelGetLength(int handle)
        {
            var result = (long)0;
            if (handle != 0)
            {
                result = BassClass._ChannelGetLength(this.strm, 0);
            }
            return result;
        }
        public long BASS_ChannelGetPosition(int handle)
        {
            var result = (long)0;
            if (handle != 0)
            {
                result = BassClass._ChannelGetPosition(this.strm, 0);
            }
            return result;
        }
        public long BASS_ChannelSeconds2Bytes(int handle, double pos)
        {
            var result = (long)0;
            if (handle != 0)
            {
                result = BassClass._ChannelSeconds2Bytes(this.strm, pos);
            }
            return result;
        }
        public bool BASS_ChannelSetPosition(int handle, long pos, int mode)
        {
            var result = false;
            if (handle != 0)
            {
                return BassClass._ChannelSetPosition(this.strm, pos, mode);
            }
            return result;
        }
        public int BASS_ChannelGetLevel(int handle)
        {
            var result = 0;
            if (handle != 0)
            {
                result = BassClass._ChannelGetLevel(this.strm);
            }
            return result;
        }
        public float BASS_GetCPU()
        {
            var result = (float)0;
            if (this.strm != 0)
            {
                result = BassClass._GetCPU();
            }
            return result;
        }
        public bool SetPosition(double pos)
        {
            return BASS_ChannelSetPosition(this.strm, BASS_ChannelSeconds2Bytes(this.strm, pos), 0);
        }
        #endregion
       
        #region Bass Properties
        private double pos
        {
            get
            {
                return BassClass._pos;
            }
            set
            {
                BassClass._pos = value;
            }
        }
        private int strm
        {
            get
            {
                return BassClass._strm;
            }
            set
            {
                BassClass._strm = value;
            }
        }
        public double Duration
        {
            get
            {
                return this.BASS_ChannelBytes2Seconds(this.strm, BASS_ChannelGetLength(this.strm));
            }
        }
        public double MaxPosition
        {
            get
            {
                return this.Duration;
            }
        }
        public double CurrentPosition
        {
            get
            {
                 return this.BASS_ChannelBytes2Seconds(this.strm, BASS_ChannelGetPosition(this.strm));
            }
        }
        public bool IsPlaying
        {
            get
            {
                if (this.BASS_ChannelIsActive(this.strm) == 1)
                {
                    return true;
                }
                return false;
            }
        }
        public string Status
        {
            get
            {
                var str = "";
                switch(this.BASS_ChannelIsActive(this.strm))
                {
                    case 1:
                        str = "Playing";
                        break;
                    case 2:
                        str = "Stalled";
                        break;
                    case 3:
                        str = "Paused";
                        break;
                    default:
                        str = "Stopped";
                        break;
                }
                return str;
            }
        }
        public string CPU
        {
            get
            {
                return this.BASS_GetCPU().ToString("#0.00");
            }
        }
        public int VuLeft
        {
            get
            {
                var res = 0;
                if (IsPlaying)
                {
                    res = this.BASS_ChannelGetLevel(this.strm) & 65535;
                }
                else
                {
                    return 0;
                }
                return res;
            }
        }
        public int VuRight
        {
            get
            {
                var res = 0;
                if (IsPlaying)
                {
                    res = (this.BASS_ChannelGetLevel(this.strm)>>16) & 65535;
                }
                else
                {
                    return 0;
                }
                return res;
            }
        }
        #endregion
« Last Edit: 18 Oct '17 - 09:36 by sak2005 »

sak2005

  • Posts: 1007
Part3: On Event
Code: [Select]
private void OnPositionChanged()
        {
           lio:
            do
            {
              if (this.CurrentPosition < this.Duration)
               {
                   this.pos = this.CurrentPosition;
                   PositionChanged(new PositionChangedEventArgs(this.pos));
               }
               else
               {
                   if (BassClass.sflag == 4)
                   {
                       this.SetPosition((double)0);
                       goto lio;
                   } 
                   this.BASS_ChannelStop(this.strm);
               }
               Thread.Sleep(50);
               Application.DoEvents();
            } while(true);
        }
        public event PositionChangedEventHandler PositionChanged;
} //end class
« Last Edit: 19 Oct '17 - 07:19 by sak2005 »

sak2005

  • Posts: 1007
Event class:
Code: [Select]
public class PositionChangedEventArgs : EventArgs
    {
        private double _pos = (double)0;
        public PositionChangedEventArgs(double pos) : base()
        {
            _pos = pos;
        }
        public double CurrentPos
        {
            get
            {
                try
                {
                    return _pos;
                }
                catch
                {
                    return (double)0;
                }
            }
        }
    }
    public delegate void PositionChangedEventHandler(PositionChangedEventArgs e);
} // end namespace
« Last Edit: 19 Oct '17 - 07:20 by sak2005 »

sak2005

  • Posts: 1007
Example: BassPlayer Form Application
Code: [Select]
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using BassLib;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        private BassClass Bass = new BassClass();
        private int chan;
        public Form1()
        {
            InitializeComponent();
            Bass.PositionChanged +=new PositionChangedEventHandler(Bass_PositionChanged);
            this.chan = 0;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Bass.BASS_Init(-1,44100,0,this.Handle);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (chan != 0) { Bass.BASS_StreamFree(chan); }
                chan = Bass.BASS_StreamCreateFile(openFileDialog1.FileName, 0, 0, 0 | 4 );
                label3.Text = TimeSpan.FromSeconds(Bass.Duration).ToString().Substring(0, 8);
                trackBar1.Maximum = (int)Bass.MaxPosition;
                button2_Click(sender, e);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Bass.BASS_ChannelPlay(chan, false);
        }
        private void Bass_PositionChanged(PositionChangedEventArgs e)
        {
            label1.Text = TimeSpan.FromSeconds(e.CurrentPos).ToString().Substring(0, 8);
            trackBar1.Value = (int)e.CurrentPos;
            label2.Text = Bass.Status;
            label4.Text = Bass.CPU;
            progressBar1.Value = Bass.VuLeft;
            progressBar2.Value = Bass.VuRight;
        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            Bass.SetPosition((double) trackBar1.Value);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Bass.BASS_ChannelPause(chan);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Bass.BASS_ChannelStop(chan);
        }
    }
}

sak2005

  • Posts: 1007
BOO programming with Creatting BassLib Class ::)

Code: [Select]
#BASS.boo

namespace BassLib

import System
import System.Threading
import System.Windows.Forms
import System.Runtime.InteropServices

class BASS(object):
   #region constructors
   private thread as Thread
   private chan as int
   private duration as double
   private maxPosition as double
   private currentposition as double
   private pos as double
   private sflag as int
   
   public def constructor():
     Control.CheckForIllegalCrossThreadCalls = false
     self.thread = Thread(ThreadStart(OnPositionChanged))
     self.chan = 0
     self.duration = 0.0
     self.maxPosition = 0.0
     self.currentposition = 0.0
     self.pos = 0.0
     self.sflag = 0
     self.thread.IsBackground = true
     self.thread.Priority = ThreadPriority.Lowest
     self.thread.Start()
 
   def destructor():
     if (self.chan != 0):
       self.thread.Abort()
       self.thread.Join(0)
       self.BASS_Free()
   #endregion
   
   #region APIs
   [DllImport("bass.dll", CharSet:CharSet.Auto, EntryPoint:"BASS_PluginLoad")]
   private static def _PluginLoad(file as String, bflags as int)as int :
      pass
   [DllImport("bass.dll", CharSet:CharSet.Auto, EntryPoint:"BASS_PluginFree")]
   private static def _PluginFree(fhandle as int)as bool :
      pass
   [DllImport("bass.dll", CharSet:CharSet.Auto, EntryPoint:"BASS_Init")]
   private static def _Init(device as int, freq as int, iflags as int, win as System.IntPtr, clsid as System.IntPtr)as bool:
      pass
   [DllImport("bass.dll", CharSet:CharSet.Auto, EntryPoint:"BASS_StreamFree")]
   private static def _StreamFree(handle as int)as bool :
      pass
   [DllImport("bass.dll", CharSet:CharSet.Auto, EntryPoint:"BASS_StreamCreateFile")]
   private static def _StreamCreateFile(mem as bool, file as string, offset as long, length as long, bflags as int)as int:
      pass
   [DllImport("bass.dll", CharSet:CharSet.Auto, EntryPoint:"BASS_ChannelPlay")]
   private static def _ChannelPlay(handle as int, restart as bool)as bool :
      pass
   [DllImport("bass.dll", CharSet:CharSet.Auto, EntryPoint:"BASS_ChannelPause")]
   private static def _ChannelPause(handle as int)as bool:
      pass
   [DllImport("bass.dll", CharSet:CharSet.Auto, EntryPoint:"BASS_ChannelStop")]
   private static def _ChannelStop(handle as int)as bool:
      pass
   [DllImport("bass.dll", CharSet:CharSet.Auto, EntryPoint:"BASS_Free")]
   private static def _Free()as bool:
      pass
   [DllImport("bass.dll", CharSet:CharSet.Auto, EntryPoint:"BASS_ChannelIsActive")]
   private static def _ChannelIsActive(handle as int)as int:
      pass
   [DllImport("bass.dll", CharSet:CharSet.Auto, EntryPoint:"BASS_ChannelBytes2Seconds")]
   private static def _ChannelBytes2Seconds(handle as int, lenpos as long)as double:
      pass
   [DllImport("bass.dll", CharSet:CharSet.Auto, EntryPoint:"BASS_ChannelGetLength")]
   private static def _ChannelGetLength(handle as int, mode as int)as long:
      pass
   [DllImport("bass.dll", CharSet:CharSet.Auto, EntryPoint:"BASS_ChannelGetPosition")]
   private static def _ChannelGetPosition(handle as int, mode as int)as long:
      pass
   [DllImport("bass.dll", CharSet:CharSet.Auto, EntryPoint:"BASS_ChannelSeconds2Bytes")]
   private static def _ChannelSeconds2Bytes(handle as int, pos as double)as long:
      pass
   [DllImport("bass.dll", CharSet:CharSet.Auto, EntryPoint:"BASS_ChannelSetPosition")]
   private static def _ChannelSetPosition(handle as int, pos as long, mode as int)as bool:
      pass   
   [DllImport("bass.dll", CharSet:CharSet.Auto, EntryPoint:"BASS_GetCPU")]
   private static def _GetCPU()as single :
      pass
   [DllImport("bass.dll", CharSet:CharSet.Auto, EntryPoint:"BASS_ChannelGetLevel")]
   private static def _ChannelGetLevel(handle as int)as int:
      pass
   #endregion
   
   #region methods
   def BASS_PluginLoad(file as String)as int:
       try:
          return BASS._PluginLoad(file, -2147483648L)
       except e:
          return 0
   def BASS_PluginFree(fhandle as int)as bool:
       try:
          return BASS._PluginFree(fhandle)
       except e:
          return false
   def BASS_Init(device as int, freq as int, iflags as int, win as System.IntPtr)as bool:
       try:
          return BASS._Init(device, freq, iflags, win, IntPtr.Zero)
       except e:
          return false
   def BASS_StreamFree(handle as int)as bool:
       try:
          return BASS._StreamFree(self.chan)
       except e:
          return false
   def BASS_StreamCreateFile(file as string, offset as long, length as long, bflags as int)as int:
       sflag = bflags
       try:
          self.chan = BASS._StreamCreateFile(false, file, offset, length, bflags | -2147483648L)
          return self.chan
       except e:
          return 0
   def BASS_ChannelPlay(handle as int, restart as bool)as bool:
       try:
          return BASS._ChannelPlay(self.chan , restart)
       except e:
          return false
   def BASS_ChannelPause(handle as int)as bool:
       try:
          return BASS._ChannelPause(self.chan)
       except e:
          return false
   def BASS_ChannelStop(handle as int)as bool:
       try:
          self.SetPosition(0.0)
          return BASS._ChannelStop(self.chan)
       except e:
          return false
   def BASS_ChannelIsActive(handle as int)as int:
       try:
          return BASS._ChannelIsActive(self.chan)
       except e:
          return 0
   def SetPosition(pos as double)as bool:
       try:
          return BASS._ChannelSetPosition(self.chan, BASS._ChannelSeconds2Bytes(self.chan, pos), 0)
       except e:
          return false
   def BASS_Free()as bool :
       try:
          return BASS._Free()
       except e:
          return false
   #endregion
   #region properties
   Duration as double:
     get:
       try:
         self.duration = BASS._ChannelBytes2Seconds(self.chan, BASS._ChannelGetLength(self.chan, 0))
         return self.duration
       except:
         return 0.0
   MaxPosition as double:
     get:
       try: 
         return self.Duration
       except e:
        return 0.0
   CurrentPosition as double:
     get:
       try:   
         self.currentposition = BASS._ChannelBytes2Seconds(self.chan, BASS._ChannelGetPosition(self.chan, 0))
         return self.currentposition
       except e:
      return 0.0
   IsPlaing as bool:
     get:
       try:
         if(self.BASS_ChannelIsActive(self.chan)==1):
            return true
         else:
            return false
       except e:
            return false
   CPU as string:
     get:
       try:   
         return BASS._GetCPU().ToString("#0.00")
       except e:
        return '0.00'
   VuLeft as int:
     get:
        if(self.IsPlaing):
          try:
            return BASS._ChannelGetLevel(self.chan)& 65535
          except e:
          return 0 
        else:
           return 0
   VuRight as int:
     get:
        if(self.IsPlaing):
          try:   
            return (BASS._ChannelGetLevel(self.chan)>>16)& 65535
          except e:
          return 0
        else:
           return 0
   Status as string:
     get:
       try: 
         if self.BASS_ChannelIsActive(self.chan)==1:
            return "Playing"
         elif self.BASS_ChannelIsActive(self.chan)==2:             
            return "Stalled"
         elif self.BASS_ChannelIsActive(self.chan)==3:             
            return "Paused"
         else:
            return "Stopped"
       except e:
            return 'Error!'
   #endregion
   #region on event handler
   private def OnPositionChanged()as void:
     try:
       while true:
         :LIN
         if (self.CurrentPosition < self.Duration):
             self.PositionChanged(BassLib.PositionChangedEventArgs(self.currentposition))
         else :
            if(self.sflag != 4):
               self.BASS_ChannelStop(chan)
               Thread.Sleep(50)
               Application.DoEvents()
            else:
               self.SetPosition(0.0)
               goto LIN
     except e:
      return
   #endregion
   #region event handle
   public event PositionChanged as PositionChangedEventHandler
   #endregion

#region handle delegate
public callable PositionChangedEventHandler(e as BassLib.PositionChangedEventArgs)as void
#endregion 

#region eventargs class
class PositionChangedEventArgs(EventArgs):
  private _pos as double
  public def constructor(pos as double):
    self._pos = pos
   CurrentPos as double:
    get:
     try:
      return self._pos
     except e:
      return 0.0
#endregion
« Last Edit: 24 Oct '17 - 08:59 by sak2005 »

sak2005

  • Posts: 1007
Example: BOO MainForm Designer ::)

Code: [Select]
#MainForm.Designer.boo

namespace BooBassPlayerFormApplication

import System
import System.ComponentModel
import System.Windows.Forms

partial class MainForm(Form):
   
   private components as IContainer = null
   private lblDuration as System.Windows.Forms.Label = null
   private lblPosition as System.Windows.Forms.Label = null
   private lblStatus as System.Windows.Forms.Label = null
   private lblCpu as System.Windows.Forms.Label = null
   private btnLoad as System.Windows.Forms.Button = null
   private btnPlay as System.Windows.Forms.Button = null
   private btnPause as System.Windows.Forms.Button = null
   private btnStop as System.Windows.Forms.Button = null
   private trackPos as System.Windows.Forms.TrackBar = null
   private pBarL as System.Windows.Forms.ProgressBar = null
   private pBarR as System.Windows.Forms.ProgressBar = null
   
   protected override def Dispose(disposing as bool) as void:
    try:
     if disposing:
     if components is not null:
           components.Dispose()
     super(disposing)
    except e:
       return
   
   private def InitializeComponent()as void:
//Label1
   self.lblPosition = System.Windows.Forms.Label()
   self.lblPosition.Text = "00:00:00"
   self.lblPosition.Location = System.Drawing.Point(4, 0)
   self.Controls.Add(lblPosition)
   //Label2
   self.lblStatus = System.Windows.Forms.Label()
   self.lblStatus.Text = "Stopped"
   self.lblStatus.Location = System.Drawing.Point(120, 0)
   self.Controls.Add(lblStatus)
   //Label3
   self.lblDuration = System.Windows.Forms.Label()
   self.lblDuration.Text = "00:00:00"
   self.lblDuration.Location = System.Drawing.Point(248, 0)
   self.Controls.Add(lblDuration)
   //Label4
   self.lblCpu = System.Windows.Forms.Label()
   self.lblCpu.Text = "0.00"
   self.lblCpu.Location = System.Drawing.Point(130, 60)
   self.Controls.Add(lblCpu)
   //Button1
   self.btnLoad = System.Windows.Forms.Button()
   self.btnLoad.Text = 'Load'
   self.btnLoad.Cursor = Cursors.Hand
   self.btnLoad.Size = System.Drawing.Size(60, 23)
   self.btnLoad.Location = System.Drawing.Point(5, 105)
   self.btnLoad.Click += System.EventHandler(btnLoad_Click)
   self.Controls.Add(btnLoad)
   //Button2
   self.btnPlay = System.Windows.Forms.Button()
   self.btnPlay.Text = 'Play'
   self.btnPlay.Cursor = Cursors.Hand
   self.btnPlay.Size = System.Drawing.Size(60, 23)
   self.btnPlay.Location = System.Drawing.Point(80, 105)
   self.btnPlay.Click += System.EventHandler(btnPlay_Click)
   self.Controls.Add(btnPlay)
   //Button3
   self.btnPause = System.Windows.Forms.Button()
   self.btnPause.Text = 'Pause'
   self.btnPause.Cursor = Cursors.Hand
   self.btnPause.Size = System.Drawing.Size(60, 23)
   self.btnPause.Location = System.Drawing.Point(160, 105)
   self.btnPause.Click += System.EventHandler(btnPause_Click)
   self.Controls.Add(btnPause)
   //Button4
   self.btnStop = System.Windows.Forms.Button()
   self.btnStop.Text = 'Stop'
   self.btnStop.Cursor = Cursors.Hand
   self.btnStop.Size = System.Drawing.Size(60, 23)
   self.btnStop.Location = System.Drawing.Point(235, 105)
   self.btnStop.Click += System.EventHandler(btnStop_Click)
   self.Controls.Add(btnStop)
   //TrackBer1
   self.trackPos = System.Windows.Forms.TrackBar()
   self.trackPos.Size = System.Drawing.Size(300, 20)
   self.trackPos.Location = System.Drawing.Point(0, 20)
   self.trackPos.Scroll += System.EventHandler(trackPos_Scroll)
   self.Controls.Add(trackPos)
   //ProgreaaBar1
   self.pBarL = System.Windows.Forms.ProgressBar()
   self.pBarL.Maximum = 32768
   self.pBarL.RightToLeft = System.Windows.Forms.RightToLeft.Yes
   self.pBarL.RightToLeftLayout = true
   self.pBarL.Size = System.Drawing.Size(145, 12)
   self.pBarL.Location = System.Drawing.Point(5, 85)
   self.Controls.Add(pBarL)
   //ProgressBar2
   self.pBarR = System.Windows.Forms.ProgressBar()
   self.pBarR.Maximum = 32768
   self.pBarR.Size = System.Drawing.Size(145, 12)
   self.pBarR.Location = System.Drawing.Point(150, 85)
   self.Controls.Add(pBarR)
   // Form1
   self.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
   self.Text = 'BOO Bass Player'
   self.Name = 'MainForm'
   self.ClientSize = System.Drawing.Size(300, 135)
   self.MaximizeBox = false
   self.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink
   self.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
   self.Load += System.EventHandler(self_Load)
   self.FormClosing += System.Windows.Forms.FormClosingEventHandler(self_Closing)
   self.ResumeLayout(false)

Code: [Select]
#MainForm.boo

namespace BooBassPlayerFormApplication

import System
import System.Windows.Forms
import BassLib

partial class MainForm(Form):
   
   public ofd as OpenFileDialog = null
   public Bass as BASS = null
   public fplug as int
   public chan as int
 
   public def constructor():
      self.ofd = System.Windows.Forms.OpenFileDialog()
      self.ofd.Filter = "Media Files|*.*"
      self.Bass = BassLib.BASS()
      self.fplug = 0
      self.chan = 0
      self.Bass.PositionChanged += BassLib.PositionChangedEventHandler(Bass_PositionChanged)
     
      InitializeComponent()
             
   private def self_Load(sender as object, e as System.EventArgs)as void:
      self.Bass.BASS_Init(-1, 44100, 0, self.Handle)
      self.Bass.BASS_PluginLoad("bass_aac.dll")
   
   private def btnLoad_Click(sender as object, e as System.EventArgs)as void:
     try:   
       if(self.ofd.ShowDialog()== DialogResult.OK):
          if(self.chan != 0): self.Bass.BASS_StreamFree(self.chan)
          self.chan = self.Bass.BASS_StreamCreateFile(self.ofd.FileName, 0, 0, 0 | 4)
         if(self.chan != 0):
            self.Text = System.IO.Path.GetFileName(self.ofd.FileName)
            self.lblDuration.Text = TimeSpan.FromSeconds(self.Bass.Duration).ToString().Substring(0, 8)
            self.trackPos.Maximum = Convert.ToInt32(self.Bass.MaxPosition)
            btnPlay_Click(sender, e)
         else:
        MessageBox.Show("Error! file not support.")
       else:
      return
     except e:
      return
   private def btnPlay_Click(sender as object, e as System.EventArgs)as void:
     try:         
       self.Bass.BASS_ChannelPlay(self.chan, false)
     except e:
       return
   private def btnPause_Click(sender as object, e as System.EventArgs)as void:
     try:     
       self.Bass.BASS_ChannelPause(self.chan)
     except e:
       return
   private def btnStop_Click(sender as object, e as System.EventArgs)as void:
     try:     
       self.Bass.BASS_ChannelStop(self.chan)
     except e:
       return
   private def trackPos_Scroll(sender as object, e as System.EventArgs)as void:
     try:     
       self.Bass.SetPosition(Convert.ToDouble(self.trackPos.Value))
     except e:
       return
   private def Bass_PositionChanged(e as BassLib.PositionChangedEventArgs)as void:
     try:     
       self.trackPos.Value = Convert.ToInt32(e.CurrentPos)
       self.lblPosition.Text = TimeSpan.FromSeconds(e.CurrentPos).ToString().Substring(0, 8)
       self.lblStatus.Text = self.Bass.Status
       self.lblCpu.Text = self.Bass.CPU
       self.pBarL.Value = self.Bass.VuLeft
       self.pBarR.Value = self.Bass.VuRight
     except e:
       return
   private def self_Closing(sender as Object, e as FormClosingEventArgs)as void:
     try:      
       self.Bass.BASS_PluginFree(fplug)
       self.Bass.BASS_Free()
     except e:
       return
#startup
[STAThread]
public def Main(argv as (string)) as void:
  Application.EnableVisualStyles()
  Application.SetCompatibleTextRenderingDefault(false)
  Application.Run(MainForm() as Form)

SharpDevelop Program Editor: Clickhere
Learn more: Boo Language Programming Clickhere
YouTube Sak2005 Programmer: Clickhere
« Last Edit: 24 Oct '17 - 09:22 by sak2005 »

sak2005

  • Posts: 1007
Boo Lang Programming Creatting EQualizer Using Bass.Net.dll ::) 

Code: [Select]
//MainForm.Designer.boo
namespace BassNetPlayerFormApp

import System.ComponentModel
import System.Drawing
import System.Windows.Forms

partial class MainForm(Form):
  private components as System.ComponentModel.IContainer = null
  private ofd as OpenFileDialog = null
  private btnLoad as Button = null
  private btnPlay as Button = null
  private btnPause as Button = null
  private btnStop as Button = null
  private lblPosition as Label = null
  private lblStatus as Label = null
  private lblDuration as Label = null
  private lblCpu as Label = null
  private lblFreq0 as Label = null
  private lblFreq1 as Label = null
  private lblFreq2 as Label = null
  private lblFreq3 as Label = null
  private lblFreq4 as Label = null
  private trackEQ0 as TrackBar = null
  private trackEQ1 as TrackBar = null
  private trackEQ2 as TrackBar = null
  private trackEQ3 as TrackBar = null
  private trackEQ4 as TrackBar = null
  private trackPos as TrackBar = null
  private chkBox as CheckBox = null
 
  protected override def Dispose(disposing as bool) as void:
    if disposing:
       if components is not null:
        components.Dispose()
    super(disposing)

  private def InitializeComponent()as void:
    self.ofd = OpenFileDialog()
    self.btnLoad = Button()
    self.btnPlay = Button()
    self.btnPause = Button()
    self.btnStop = Button()
    self.lblPosition = Label()
    self.lblStatus = Label()
    self.lblDuration = Label()
    self.lblCpu = Label()
    self.lblFreq0 = Label()
    self.lblFreq1 = Label()
    self.lblFreq2 = Label()
    self.lblFreq3 = Label()
    self.lblFreq4 = Label()
    self.trackEQ0 = TrackBar()
    self.trackEQ1 = TrackBar()
    self.trackEQ2 = TrackBar()
    self.trackEQ3 = TrackBar()
    self.trackEQ4 = TrackBar()
    self.trackPos = TrackBar()
    self.chkBox = CheckBox()
    self.SuspendLayout()
    //Button1
    self.btnLoad.Text = 'Load'
    self.btnLoad.Location = Point(5, 175)
    self.btnLoad.Width = 55
    self.btnLoad.Cursor = Cursors.Hand
    self.btnLoad.Click += EventHandler(self.btnLoad_Click)
    //Button2
    self.btnPlay.Text = 'Play'
    self.btnPlay.Location = Point(60, 175)
    self.btnPlay.Width = 55
    self.btnPlay.Cursor = Cursors.Hand
    self.btnPlay.Click += EventHandler(self.btnPlay_Click)
    //Button3
    self.btnPause.Text = 'Pause'
    self.btnPause.Location = Point(115, 175)
    self.btnPause.Width = 55
    self.btnPause.Cursor = Cursors.Hand
    self.btnPause.Click += EventHandler(self.btnPause_Click)
    //Button4
    self.btnStop.Text = 'Stop'
    self.btnStop.Location = Point(170, 175)
    self.btnStop.Width = 55
    self.btnStop.Cursor = Cursors.Hand
    self.btnStop.Click += EventHandler(self.btnStop_Click)
    //TrackBar1
    self.trackEQ0.Location = Point(15, 20)
    self. trackEQ0.Size = Size(23, 100)
    self.trackEQ0.Minimum = -15
    self.trackEQ0.Maximum = 15
    self.trackEQ0.TickFrequency = 3
    self.trackEQ0.Orientation = Orientation.Vertical
    self.trackEQ0.TickStyle = TickStyle.Both
    self.trackEQ0.Scroll += EventHandler(self.trackEQ0_Scroll)
    //TrackBar2
    self.trackEQ1.Location = Point(55, 20)
    self.trackEQ1.Size = Size(23, 100)
    self.trackEQ1.Minimum = -15
    self.trackEQ1.Maximum = 15
    self.trackEQ1.TickFrequency = 3
    self.trackEQ1.Orientation = Orientation.Vertical
    self.trackEQ1.TickStyle = TickStyle.Both
    self.trackEQ1.Scroll += EventHandler(self.trackEQ1_Scroll)
    //TrackBar3
    self.trackEQ2.Location = Point(95, 20)
    self.trackEQ2.Size = Size(23, 100)
    self.trackEQ2.Minimum = -15
    self.trackEQ2.Maximum = 15
    self.trackEQ2.TickFrequency = 3
    self.trackEQ2.Orientation = Orientation.Vertical
    self.trackEQ2.TickStyle = TickStyle.Both
    self.trackEQ2.Scroll += EventHandler(self.trackEQ2_Scroll)
    //TrackBar4
    self.trackEQ3.Location = Point(135, 20)
    self.trackEQ3.Size = Size(23, 100)
    self.trackEQ3.Minimum = -15
    self.trackEQ3.Maximum = 15
    self.trackEQ3.TickFrequency = 3
    self.trackEQ3.Orientation = Orientation.Vertical
    self.trackEQ3.TickStyle = TickStyle.Both
    self.trackEQ3.Scroll += EventHandler(self.trackEQ3_Scroll)
    //TrackBar5
    self.trackEQ4.Location = Point(175, 20)
    self.trackEQ4.Size = Size(23, 100)
    self.trackEQ4.Minimum = -15
    self.trackEQ4.Maximum = 15
    self.trackEQ4.TickFrequency = 3
    self.trackEQ4.Orientation = Orientation.Vertical
    self.trackEQ4.TickStyle = TickStyle.Both
    self.trackEQ4.Scroll += EventHandler(self.trackEQ4_Scroll)
    //TrackBar6
    self.trackPos.Location = Point(5, 135)
    self.trackPos.Size = Size(220, 23)
    self.trackPos.Scroll += EventHandler(self.trackPos_Scroll)
    //CheckBox1
    self.chkBox.Location = Point(85, 0)
    self.chkBox.Text = 'EQ ON'
    self.chkBox.CheckedChanged += EventHandler(self.chkBox_CheckedChanged)
    //Form1
    self.AutoScaleDimensions = SizeF(6.0, 13.0)
    self.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
    self.AutoSizeMode = AutoSizeMode.GrowAndShrink
    self.MaximizeBox = false
    self.StartPosition = FormStartPosition.CenterScreen
    self.Text = 'Boo BassPlayer'
    self.ClientSize = Size(230, 210)
    self.Controls.Add(self.btnLoad)
    self.Controls.Add(self.btnPlay)
    self.Controls.Add(self.btnPause)
    self.Controls.Add(self.btnStop)
    self.Controls.Add(self.trackEQ0)
    self.Controls.Add(self.trackEQ1) 
    self.Controls.Add(self.trackEQ2)     
    self.Controls.Add(self.trackEQ3)     
    self.Controls.Add(self.trackEQ4)     
    self.Controls.Add(self.trackPos)
    self.Controls.Add(self.chkBox)
    self.Load += EventHandler(self.Form_Load)
    self.FormClosing += FormClosingEventHandler(self.Form_Closing)
    self.ResumeLayout(false)
    self.PerformLayout()

Code: [Select]
//MainForm.boo
namespace BassNetPlayerFormApp

import System
import System.Collections
import System.Drawing
import System.Windows.Forms
import Un4seen.Bass

partial class MainForm(Form):
  private eqParamsUpdate as EventHandler = null //handler delegate
  public fxEQ as (int)
  public strm as int
 
  public def constructor():
     self.fxEQ = (0,1,2,3,4)
     self.strm = 0
     self.eqParamsUpdate = EventHandler(updateParamsEq)
     InitializeComponent()
   
  private def Form_Load(sender as object, e as EventArgs)as void:
     BassNet.Registration('', '')
     Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, self.Handle)
     Bass.BASS_PluginLoad('bass_aac.dll')
   
  private def btnLoad_Click(sender as object, e as EventArgs)as void:
     if(self.ofd.ShowDialog()== DialogResult.OK):
        self.strm = Bass.BASS_StreamCreateFile(self.ofd.FileName, 0, 0, BASSFlag.BASS_DEFAULT)
        self.trackPos.Maximum = Convert.ToInt32( Bass.BASS_ChannelBytes2Seconds(self.strm, Bass.BASS_ChannelGetLength(self.strm, BASSMode.BASS_POS_BYTES)))
        chkBox_CheckedChanged(sender, e)
        btnPlay_Click(sender, e)
     
  private def btnPlay_Click(sender as object, e as EventArgs)as void:
        Bass.BASS_ChannelPlay(self.strm, false)
 
  private def btnPause_Click(sender as object, e as EventArgs)as void:
        Bass.BASS_ChannelPause(self.strm)
 
  private def btnStop_Click(sender as object, e as EventArgs)as void:
        Bass.BASS_ChannelSetPosition(self.strm, 0.0)
        Bass.BASS_ChannelStop(self.strm)
 
  private def Form_Closing(sender as object, e as FormClosingEventArgs)as void:
        Bass.BASS_Free() 

  private def trackPos_Scroll(sender as object, e as EventArgs)as void:
        Bass.BASS_ChannelSetPosition(self.strm, Bass.BASS_ChannelSeconds2Bytes(self.strm, Convert.ToDouble(self.trackPos.Value)), BASSMode.BASS_POS_BYTES) 

  private def trackEQ0_Scroll(sender as object, e as EventArgs)as void:
        BassEQ.SetParamsEq(fxEQ[0], 100, trackEQ0.Value)

  private def trackEQ1_Scroll(sender as object, e as EventArgs)as void:
        BassEQ.SetParamsEq(fxEQ[1], 500, trackEQ1.Value)

  private def trackEQ2_Scroll(sender as object, e as EventArgs)as void:
        BassEQ.SetParamsEq(fxEQ[2], 1000, trackEQ2.Value)

  private def trackEQ3_Scroll(sender as object, e as EventArgs)as void:
        BassEQ.SetParamsEq(fxEQ[3], 4000, trackEQ3.Value)

  private def trackEQ4_Scroll(sender as object, e as EventArgs)as void:
        BassEQ.SetParamsEq(fxEQ[4], 8000, trackEQ4.Value)

  private def chkBox_CheckedChanged(sender as object, e as EventArgs)as void:
        if(self.chkBox.Checked):
           i as int
           for i in range(5): //addFX
              fxEQ[i] = BassEQ.SetFxEq(self.strm, BASSFXType.BASS_FX_DX8_PARAMEQ)
              updateParamsEq(sender, e)
        else:
           x as int
           for x in range(5): //removeFX
              BassEQ.RemoveFxEq(self.strm, self.fxEQ[x])
       
  private def updateParamsEq(sender as object, e as EventArgs)as void:
        trackEQ0_Scroll(sender, e)
        trackEQ1_Scroll(sender, e)
        trackEQ2_Scroll(sender, e)
        trackEQ3_Scroll(sender, e)
        trackEQ4_Scroll(sender, e)

[STAThread]
public def Main(argv as (string)) as void:
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(false)
Application.Run(MainForm()as Form)

class BassEQ(object):
  private static par as BASS_DX8_PARAMEQ
  public def constructor():
  self.par= BASS_DX8_PARAMEQ()
  public static def SetFxEq(handle as int, fxTypes as BASSFXType)as int:
    self.par= BASS_DX8_PARAMEQ()
    res as int = Bass.BASS_ChannelSetFX(handle, fxTypes, 0)
    par.fBandwidth = 18.0F
    par.fCenter = 80.0F
    par.fGain = 0.0F
    if(Bass.BASS_FXSetParameters(res, par)):
    return res
    else:
    return 0
  public static def SetParamsEq(fx as int, center as int, gain as int)as bool:
    self.par= BASS_DX8_PARAMEQ()
    par.fBandwidth = 18.0
    par.fCenter = Convert.ToSingle(center)
    par.fGain = Convert.ToSingle(gain)
    bl = Bass.BASS_FXSetParameters(fx, par)
    if(bl):
    return bl
    else:
    return false
  public static def RemoveFxEq(handle as int, fx as int)as bool:
      bl as bool = false
      bl= Bass.BASS_ChannelRemoveFX(handle, fx)
      if(bl):
      return bl
      else:
      return false

« Last Edit: 25 Oct '17 - 10:05 by sak2005 »

sak2005

  • Posts: 1007
Boo BassPeakEq Class Shared Library sample ::)

Code: [Select]
//BassPeakEq.boo Shared Library
namespace BassNetPlayerFormApp

import System
import Un4seen.Bass

public class BassPeakEq(object):
  #region constructors
  private static par as AddOn.Fx.BASS_BFX_PEAKEQ
 
  static def constructor():
    par = AddOn.Fx.BASS_BFX_PEAKEQ()
 
  public static def PeakEqInit()as bool:
  return AddOn.Fx.BassFx.LoadMe()
  #endregion
 
  #region methods
  public static def SetFxEq(handle as int, fxTypes as BASSFXType)as int:
    fx as int = Bass.BASS_ChannelSetFX(handle, fxTypes, 0)
    par.fBandwidth = 1.0F
    par.fCenter = 1000.0F
    par.fGain = 0.0F
    if(Bass.BASS_FXSetParameters(fx, par)):
       return fx
    else:
       return 0
 
  public static def SetParamsEq(fx as int, center as int, gain as int)as bool:
    par.fBandwidth = 1.0F
    par.fCenter = Convert.ToSingle(center)
    par.fGain = Convert.ToSingle(gain)
    par.lChannel = AddOn.Fx.BASSFXChan.BASS_BFX_CHANALL
    bl as bool = Bass.BASS_FXSetParameters(fx, par)
    if(bl):
       return bl
    else:
       return false
 
  public static def RemoveFxEq(handle as int, fx as int)as bool:
    bl as bool = Bass.BASS_ChannelRemoveFX(handle, fx)
    if(bl):
       return bl
    else:
       return false
  #endregion

Example:
Code: [Select]
//MainForm.boo
namespace BassNetPlayerFormApp

import System
import System.Collections
import System.Drawing
import System.Windows.Forms
import Un4seen.Bass

partial class MainForm(Form):
  private eqParamsUpdate as EventHandler = null //handler delegate
 
  public fxEQ as (int)
  public strm as int
 
  public def constructor():
   
    self.fxEQ = (0,1,2,3,4)
    self.strm = 0
    self.eqParamsUpdate = EventHandler(updateParamsEq)
   
    InitializeComponent()
   
  private def Form_Load(sender as object, e as EventArgs)as void:
    BassNet.Registration('', '')
    Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, self.Handle)
    Bass.BASS_PluginLoad('bass_aac.dll')
    BassPeakEq.PeakEqInit()
 
  private def btnLoad_Click(sender as object, e as EventArgs)as void:
    if(self.ofd.ShowDialog()== DialogResult.OK):
       if(self.strm != 0): Bass.BASS_StreamFree(self.strm)
       self.strm = Bass.BASS_StreamCreateFile(self.ofd.FileName, 0, 0, BASSFlag.BASS_DEFAULT)
       self.trackPos.Maximum = Convert.ToInt32( Bass.BASS_ChannelBytes2Seconds(self.strm, Bass.BASS_ChannelGetLength(self.strm, BASSMode.BASS_POS_BYTES)))
       chkBox_CheckedChanged(sender, e)
       btnPlay_Click(sender, e)
     
  private def btnPlay_Click(sender as object, e as EventArgs)as void:
    Bass.BASS_ChannelPlay(self.strm, false)
 
  private def btnPause_Click(sender as object, e as EventArgs)as void:
    Bass.BASS_ChannelPause(self.strm)
 
  private def btnStop_Click(sender as object, e as EventArgs)as void:
    Bass.BASS_ChannelSetPosition(self.strm, 0.0)
    Bass.BASS_ChannelStop(self.strm)
 
  private def Form_Closing(sender as object, e as FormClosingEventArgs)as void:
    Bass.BASS_Free() 

  private def trackPos_Scroll(sender as object, e as EventArgs)as void:
    Bass.BASS_ChannelSetPosition(self.strm, Bass.BASS_ChannelSeconds2Bytes(self.strm, Convert.ToDouble(self.trackPos.Value)), BASSMode.BASS_POS_BYTES) 

  private def trackEQ0_Scroll(sender as object, e as EventArgs)as void:
    BassPeakEq.SetParamsEq(fxEQ[0], 100, trackEQ0.Value)
               
  private def trackEQ1_Scroll(sender as object, e as EventArgs)as void:
    BassPeakEq.SetParamsEq(fxEQ[1], 500, trackEQ1.Value)
               
  private def trackEQ2_Scroll(sender as object, e as EventArgs)as void:
    BassPeakEq.SetParamsEq(fxEQ[2], 1000, trackEQ2.Value)
               
  private def trackEQ3_Scroll(sender as object, e as EventArgs)as void:
    BassPeakEq.SetParamsEq(fxEQ[3], 4000, trackEQ3.Value)
               
  private def trackEQ4_Scroll(sender as object, e as EventArgs)as void:
    BassPeakEq.SetParamsEq(fxEQ[4], 8000, trackEQ4.Value)
                 
  private def chkBox_CheckedChanged(sender as object, e as EventArgs)as void:
    if(self.chkBox.Checked):
      i as int
      for i in range(5): //addFX
        fxEQ[i] = BassPeakEq.SetFxEq(self.strm, BASSFXType.BASS_FX_BFX_PEAKEQ)
        updateParamsEq(sender, e)
    else:
      x as int
      for x in range(5): //removeFX
        BassPeakEq.RemoveFxEq(self.strm, self.fxEQ[x])
       
  private def updateParamsEq(sender as object, e as EventArgs)as void:
    trackEQ0_Scroll(sender, e)
    trackEQ1_Scroll(sender, e)
    trackEQ2_Scroll(sender, e)
    trackEQ3_Scroll(sender, e)
    trackEQ4_Scroll(sender, e)
             
[STAThread]
public def Main(argv as (string)) as void:
  Application.EnableVisualStyles()
  Application.SetCompatibleTextRenderingDefault(false)
  Application.Run(MainForm()as Form)
« Last Edit: 26 Oct '17 - 03:29 by sak2005 »

sak2005

  • Posts: 1007
Boo 2IN1 BASS EQualizer class Shred library ::)

Code: [Select]
//BassEq.boo 2In1 Shared Library
namespace BassNetPlayerFormApp

import System
import Un4seen.Bass

public class BassEq(object):
  #region constructors
  private static dx8par as BASS_DX8_PARAMEQ = null
  private static peakpar as AddOn.Fx.BASS_BFX_PEAKEQ = null
  private static sFxType as BASSFXType
  private static fx as int
  static def constructor():
    fx = 0
  def destructor():
     AddOn.Fx.BassFx.FreeMe()
     dx8par = null
     peakpar = null
  #endregion
 
  #region methods
  public static def EqInit()as bool:
     return AddOn.Fx.BassFx.LoadMe()
 
  public static def SetFxEq(handle as int, fxTypes as BASSFXType)as int:
    sFxType = fxTypes
    if(sFxType == BASSFXType.BASS_FX_DX8_PARAMEQ):
      dx8par = BASS_DX8_PARAMEQ()
      fx = Bass.BASS_ChannelSetFX(handle, sFxType, 0)
      dx8par.fBandwidth = 18.0F
      dx8par.fCenter = 100.0F
      dx8par.fGain = 0.0F
      if(Bass.BASS_FXSetParameters(fx, dx8par)):
        return fx
      else:
        return 0
    elif(sFxType == BASSFXType.BASS_FX_BFX_PEAKEQ):
      peakpar = AddOn.Fx.BASS_BFX_PEAKEQ()
      fx = Bass.BASS_ChannelSetFX(handle, sFxType, 0)
      peakpar.fBandwidth = 18.0F
      peakpar.fCenter = 100.0F
      peakpar.fGain = 0.0F
      if(Bass.BASS_FXSetParameters(fx, peakpar)):
        return fx
      else:
        return 0
    else:
      return 0
 
  public static def SetParamsEq(fx as int, center as int, gain as int)as bool:
    if(sFxType == BASSFXType.BASS_FX_DX8_PARAMEQ):
      dx8par = BASS_DX8_PARAMEQ()
      dx8par.fBandwidth = 18.0F
      dx8par.fCenter = Convert.ToSingle(center)
      dx8par.fGain = Convert.ToSingle(gain)
      bl as bool = Bass.BASS_FXSetParameters(fx, dx8par)
      if(bl):
         return bl
      else:
         return false
    elif(sFxType == BASSFXType.BASS_FX_BFX_PEAKEQ):
      peakpar = AddOn.Fx.BASS_BFX_PEAKEQ()
      peakpar.fBandwidth = 1.0F
      peakpar.fCenter = Convert.ToSingle(center)
      peakpar.fGain = Convert.ToSingle(gain)
      bx as bool = Bass.BASS_FXSetParameters(fx, peakpar)
      if(bx):
        return bl
      else:
        return false
    else:
      return false
 
  public static def RemoveFxEq(handle as int, fx as int)as bool:
    bl as bool = Bass.BASS_ChannelRemoveFX(handle, fx)
    if(bl):
       return bl
    else:
       return false
  #endregion
« Last Edit: 27 Oct '17 - 06:03 by sak2005 »

sak2005

  • Posts: 1007
Tip Boo: Direct Video Player Class ::)

Code: [Select]
namespace DShowLib

import System
import System.Threading
import System.Windows.Forms
import System.Runtime.InteropServices
import DirectShowLib //References DirectShowLib-2005.dll

class DShow(object):
 #region constructors
 private thread as Thread
 private gb as IGraphBuilder
 private ba as IBasicAudio
 private bv as IBasicVideo
 private mc as IMediaControl
 private ev as IMediaEvent
 private mp as IMediaPosition
 private vw as IVideoWindow
 public def constructor():
  Control.CheckForIllegalCrossThreadCalls = false
  self.thread = Thread(ThreadStart(OnPositionChanged))
  self.thread.IsBackground = true
  self.thread.Priority = ThreadPriority.Lowest
  self.gb = null
  self.ba = null
  self.bv = null
  self.mc = null
  self.ev = null
  self.mp = null
  self.vw = null
  self.thread.Start()
 def destructor():
  self.Close()
  thread = null
 #endregion
 #region methods
 public def Load(file as string, win as Control)as void:
  if(gb != null): Marshal.ReleaseComObject(gb)
  gb = FilterGraph() as IFilterGraph2
  ba = gb as IBasicAudio
  bv = gb as IBasicVideo
  mc = gb as IMediaControl
  ev = gb as IMediaEvent
  mp = gb as IMediaPosition
  vw = gb as IVideoWindow
  mc.RenderFile(file)
  vw.put_Owner(win.Handle)
  vw.put_WindowStyle(WindowStyle.Child)
  vw.SetWindowPosition(0, 0, win.Width, win.Height) 
 public def Play()as void:
  if(mc != null):
   mc.Run()
 public def Pause()as void:
  if(mc != null):
   mc.Pause()
 public def Stop()as void:
  if(mc != null):
   self.SetPosition(0.0)
   mc.Stop()
 public def Close()as void:
  try:
   if(Marshal.IsComObject(gb)):
    Marshal.ReleaseComObject(gb)
    gb = null
  except e:
    return 
 public def SetPosition(pos as double)as void:
  if(mp != null):
   mp.put_CurrentPosition(pos)
  else:
   return
 public def ResizeWindow(win as Control)as void:
  vw.SetWindowPosition(0, 0, win.Width, win.Height)
 #endregion
 #region properties
 public Status as string:
  get:
  pfs as FilterState
  mc.GetState(0, pfs)
  return pfs.ToString()
 public IsPlaying as bool:
  get:
  pfs as FilterState
  mc.GetState(0, pfs)
  if(pfs==1):
  return true
  else:
  return false
 public Duration as double:
  get: 
   try:
    pLength as double
    mp.get_Duration(pLength)
    return pLength
   except e:
    return 0.0
 public MaxPosition as double:
  get:
  return self.Duration
 public CurrentPosition as double:
  get:
  try:
  pllTime as double
  mp.get_CurrentPosition(pllTime)
  return pllTime
  except e:
  return 0.0
 #endregion
 #region event
 protected def OnPositionChanged()as void:
  while true:
   Thread.Sleep(50)
   Application.DoEvents()
   if(EventHandler != null):
    if(CurrentPosition<Duration):
     PositionChanged(object(), EventArgs())
    else:
     Stop() 
 public event PositionChanged as EventHandler
 #endregion

Example:
Code: [Select]
namespace DShowPlayer

import System
import System.Collections
import System.Drawing
import System.Windows.Forms
import DShowLib

partial class MainForm:
 private ds as DShow
 private ofd as OpenFileDialog
 public def constructor():
  self.ds = DShow()
  self.ofd = OpenFileDialog()
  ds.PositionChanged += EventHandler(ds_PositionChanged)
  InitializeComponent()

 private def btnLoad_Click(sender as object, e as EventArgs)as void:
  if(ofd.ShowDialog()==DialogResult.OK):
   ds.Load(ofd.FileName, win)
   trackPos.Maximum = ds.MaxPosition
   ds.Play()   

 private def trackPos_Scroll(sender as object, e as EventArgs)as void:
  ds.SetPosition(Convert.ToDouble(trackPos.Value))

 private def ds_PositionChanged(sender as object, e as EventArgs)as void:
  trackPos.Value = Convert.ToInt32(ds.CurrentPosition)

[STAThread]
public def Main(argv as (string)) as void:
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(false)
Application.Run(MainForm())

sak2005

  • Posts: 1007
LearnMore Python  Language ::)

Short Sample code Bass Player in the Python

Code: [Select]
import System
import System.Drawing
import System.Windows.Forms

from System import *
from System.Drawing import *
from System.Windows.Forms import *
from Un4seen.Bass import * #references Bass.Net.dll

class MainForm(Form):
  global strm #global first variable for check stream 0
  strm = 0
  sfile = ""
 
  def __init__(self):
      self.InitializeComponent()
 
  def InitializeComponent(self):
self._label1 = System.Windows.Forms.Label()
self._label2 = System.Windows.Forms.Label()
self._label3 = System.Windows.Forms.Label()
self._trackBar1 = System.Windows.Forms.TrackBar()
self._label4 = System.Windows.Forms.Label()
self._progressBar1 = System.Windows.Forms.ProgressBar()
self._progressBar2 = System.Windows.Forms.ProgressBar()
self._button1 = System.Windows.Forms.Button()
self._button2 = System.Windows.Forms.Button()
self._button3 = System.Windows.Forms.Button()
self._button4 = System.Windows.Forms.Button()
self._openFileDialog1 = System.Windows.Forms.OpenFileDialog()
self._trackBar1.BeginInit()
self.SuspendLayout()
#
# label1
#
self._label1.Location = System.Drawing.Point(12, 9)
self._label1.Name = "label1"
self._label1.Size = System.Drawing.Size(56, 14)
self._label1.TabIndex = 0
self._label1.Text = "00:00:00"
self._label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
#
# label2
#
self._label2.Location = System.Drawing.Point(224, 9)
self._label2.Name = "label2"
self._label2.Size = System.Drawing.Size(56, 14)
self._label2.TabIndex = 1
self._label2.Text = "00:00:00"
self._label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
#
# label3
#
self._label3.Location = System.Drawing.Point(112, 9)
self._label3.Name = "label3"
self._label3.Size = System.Drawing.Size(51, 14)
self._label3.TabIndex = 2
self._label3.Text = "Stopped"
self._label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
#
# trackBar1
#
self._trackBar1.AutoSize = False
self._trackBar1.Location = System.Drawing.Point(12, 26)
self._trackBar1.Name = "trackBar1"
self._trackBar1.Size = System.Drawing.Size(268, 31)
self._trackBar1.TabIndex = 3
#
# label4
#
self._label4.Location = System.Drawing.Point(119, 62)
self._label4.Name = "label4"
self._label4.Size = System.Drawing.Size(36, 16)
self._label4.TabIndex = 4
self._label4.Text = "0.00"
self._label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
#
# progressBar1
#
self._progressBar1.Location = System.Drawing.Point(9, 88)
self._progressBar1.Name = "progressBar1"
self._progressBar1.RightToLeft = System.Windows.Forms.RightToLeft.Yes
self._progressBar1.RightToLeftLayout = True
self._progressBar1.Size = System.Drawing.Size(136, 11)
self._progressBar1.TabIndex = 5
#
# progressBar2
#
self._progressBar2.Location = System.Drawing.Point(147, 89)
self._progressBar2.Name = "progressBar2"
self._progressBar2.Size = System.Drawing.Size(136, 11)
self._progressBar2.TabIndex = 6
#
# button1
#
self._button1.Location = System.Drawing.Point(16, 113)
self._button1.Name = "button1"
self._button1.Size = System.Drawing.Size(60, 23)
self._button1.TabIndex = 7
self._button1.Text = "button1"
self._button1.UseVisualStyleBackColor = True
self._button1.Click += self.Button1Click
#
# button2
#
self._button2.Location = System.Drawing.Point(82, 113)
self._button2.Name = "button2"
self._button2.Size = System.Drawing.Size(60, 23)
self._button2.TabIndex = 8
self._button2.Text = "button2"
self._button2.UseVisualStyleBackColor = True
self._button2.Click += self.Button2Click
#
# button3
#
self._button3.Location = System.Drawing.Point(148, 113)
self._button3.Name = "button3"
self._button3.Size = System.Drawing.Size(60, 23)
self._button3.TabIndex = 9
self._button3.Text = "button3"
self._button3.UseVisualStyleBackColor = True
#
# button4
#
self._button4.Location = System.Drawing.Point(214, 113)
self._button4.Name = "button4"
self._button4.Size = System.Drawing.Size(60, 23)
self._button4.TabIndex = 10
self._button4.Text = "button4"
self._button4.UseVisualStyleBackColor = True
#
# openFileDialog1
#
self._openFileDialog1.FileName = "openFileDialog1"
#
# MainForm
#
self.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink
self.ClientSize = System.Drawing.Size(292, 143)
self.Controls.Add(self._button4)
self.Controls.Add(self._button3)
self.Controls.Add(self._button2)
self.Controls.Add(self._button1)
self.Controls.Add(self._progressBar2)
self.Controls.Add(self._progressBar1)
self.Controls.Add(self._label4)
self.Controls.Add(self._trackBar1)
self.Controls.Add(self._label3)
self.Controls.Add(self._label2)
self.Controls.Add(self._label1)
self.MaximizeBox = False
self.Name = "MainForm"
self.Text = "PythonApp"
self.Load += self.MainFormLoad
self._trackBar1.EndInit()
self.ResumeLayout(False)

  def MainFormLoad(self, sender, e):
      Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, self.Handle)
     
  def Button1Click(self, sender, e):
  if(self._openFileDialog1.ShowDialog()==DialogResult.OK):
    if(strm != 0): Bass.BASS_StreamFree(strm)
    global strm #global second variable for check stream free and for playing.
    strm = 0
    sfile = self._openFileDialog1.FileName
    strm = Bass.BASS_StreamCreateFile(sfile, 0, 0, 0)
    if(strm != 0):
  self.Button2Click(sender, e)
    else:
  MessageBox.Show("Error! file not support.")

  def Button2Click(self, sender, e):
  Bass.BASS_ChannelPlay(strm, False)
« Last Edit: 8 Nov '17 - 23:00 by sak2005 »