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

sak2005

  • Posts: 1007
Tip Sharpdevelop v4.4 : Run python form app without command window ::)
1. clicked.. to Project menu, select.. Project Options
2. clicked.. Debug  option, look at.. Start Action and choose check at.. Start project
3. clicked save and run test now.

Warning!: Must not install python command v2.7, Because  Sharpdevelop program will Error!

« Last Edit: 9 Nov '17 - 02:36 by sak2005 »

sak2005

  • Posts: 1007
Tip: Properties functions in the Python ::)

Example:
Code: [Select]
global get_number #global variable of properties function.
global set_number
global num #global variable of value.

def Button1Click(self, sender, e):
         global num #global variable of event click.
         num = 100
         numbers = num
         set_number(self, numbers) #write number.
         MessageBox.Show(str(get_number(self))) #read number.
   
#region properties get, set
def get_number(self):
      return num

def set_number(self, value): 
      num = value
#endregion
« Last Edit: 9 Nov '17 - 11:50 by sak2005 »

sak2005

  • Posts: 1007
Tip: Properties Bass Duration, MaxPosition and CurrentPosition in the python ::)

Example:
Code: [Select]
import System
import System.IO
import System.Drawing
import System.Windows.Forms
import Un4seen.Bass as Bass

from System import *
from System.IO import Path
from System.Drawing import *
from System.Windows.Forms import *
from Un4seen.Bass import *

class MainForm(Form):
  global sfile, strm, fplug, ofd, len, pos, SetPosition, state, play, restr
  strm = 0
  fplug = 0
   
  def __init__(self):
     
      self.InitializeComponent()

  def InitializeComponent(self):
self._components = System.ComponentModel.Container()
self._button1 = System.Windows.Forms.Button()
self._label1 = System.Windows.Forms.Label()
self._label2 = System.Windows.Forms.Label()
self._trackBar1 = System.Windows.Forms.TrackBar()
self._timer1 = System.Windows.Forms.Timer(self._components)
self._label3 = System.Windows.Forms.Label()
self._label4 = System.Windows.Forms.Label()
self._button2 = System.Windows.Forms.Button()
self._button3 = System.Windows.Forms.Button()
self._button4 = System.Windows.Forms.Button()
self._progressBar1 = System.Windows.Forms.ProgressBar()
self._progressBar2 = System.Windows.Forms.ProgressBar()
self._trackBar1.BeginInit()
self.SuspendLayout()
#
# button1
#
self._button1.Cursor = System.Windows.Forms.Cursors.Hand
self._button1.Location = System.Drawing.Point(8, 120)
self._button1.Name = "button1"
self._button1.Size = System.Drawing.Size(60, 23)
self._button1.TabIndex = 0
self._button1.Text = "Load"
self._button1.UseVisualStyleBackColor = True
self._button1.Click += self.Button1Click
#
# label1
#
self._label1.Location = System.Drawing.Point(8, 8)
self._label1.Name = "label1"
self._label1.Size = System.Drawing.Size(56, 16)
self._label1.TabIndex = 1
self._label1.Text = "00:00:00"
#
# label2
#
self._label2.Location = System.Drawing.Point(208, 8)
self._label2.Name = "label2"
self._label2.Size = System.Drawing.Size(56, 16)
self._label2.TabIndex = 2
self._label2.Text = "00:00:00"
#
# trackBar1
#
self._trackBar1.AutoSize = False
self._trackBar1.Location = System.Drawing.Point(8, 24)
self._trackBar1.Name = "trackBar1"
self._trackBar1.Size = System.Drawing.Size(248, 32)
self._trackBar1.TabIndex = 3
self._trackBar1.Scroll += self.TrackBar1Scroll
#
# timer1
#
self._timer1.Tick += self.Timer1Tick
#
# label3
#
self._label3.Location = System.Drawing.Point(112, 8)
self._label3.Name = "label3"
self._label3.Size = System.Drawing.Size(56, 16)
self._label3.TabIndex = 4
self._label3.Text = "Stopped"
#
# label4
#
self._label4.Location = System.Drawing.Point(120, 56)
self._label4.Name = "label4"
self._label4.Size = System.Drawing.Size(32, 16)
self._label4.TabIndex = 5
self._label4.Text = "0.00"
#
# button2
#
self._button2.Cursor = System.Windows.Forms.Cursors.Hand
self._button2.Location = System.Drawing.Point(72, 120)
self._button2.Name = "button2"
self._button2.Size = System.Drawing.Size(60, 23)
self._button2.TabIndex = 6
self._button2.Text = "Play"
self._button2.UseVisualStyleBackColor = True
self._button2.Click += self.Button2Click
#
# button3
#
self._button3.Cursor = System.Windows.Forms.Cursors.Hand
self._button3.Location = System.Drawing.Point(136, 120)
self._button3.Name = "button3"
self._button3.Size = System.Drawing.Size(60, 23)
self._button3.TabIndex = 7
self._button3.Text = "Pause"
self._button3.UseVisualStyleBackColor = True
self._button3.Click += self.Button3Click
#
# button4
#
self._button4.Cursor = System.Windows.Forms.Cursors.Hand
self._button4.Location = System.Drawing.Point(200, 120)
self._button4.Name = "button4"
self._button4.Size = System.Drawing.Size(60, 23)
self._button4.TabIndex = 8
self._button4.Text = "Stop"
self._button4.UseVisualStyleBackColor = True
self._button4.Click += self.Button4Click
#
# progressBar1
#
self._progressBar1.Location = System.Drawing.Point(8, 80)
self._progressBar1.Maximum = 32768
self._progressBar1.Name = "progressBar1"
self._progressBar1.RightToLeft = System.Windows.Forms.RightToLeft.Yes
self._progressBar1.RightToLeftLayout = True
self._progressBar1.Size = System.Drawing.Size(120, 12)
self._progressBar1.TabIndex = 9
#
# progressBar2
#
self._progressBar2.Location = System.Drawing.Point(136, 80)
self._progressBar2.Maximum = 32768
self._progressBar2.Name = "progressBar2"
self._progressBar2.Size = System.Drawing.Size(120, 12)
self._progressBar2.TabIndex = 10
#
# MainForm
#
self.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink
self.ClientSize = System.Drawing.Size(269, 148)
self.Controls.Add(self._progressBar2)
self.Controls.Add(self._progressBar1)
self.Controls.Add(self._button4)
self.Controls.Add(self._button3)
self.Controls.Add(self._button2)
self.Controls.Add(self._label4)
self.Controls.Add(self._label3)
self.Controls.Add(self._trackBar1)
self.Controls.Add(self._label2)
self.Controls.Add(self._label1)
self.Controls.Add(self._button1)
self.MaximizeBox = False
self.Name = "MainForm"
self.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
self.Text = "PythonFormApp"
self.FormClosing += self.MainFormFormClosing
self.Load += self.MainFormLoad
self._trackBar1.EndInit()
self.ResumeLayout(False)

  def MainFormLoad(self, sender, e):
  Bass.BASS_Init(-1, 44100, 0, self.Handle)
          fplug = 0
          fplug = Bass.BASS_PluginLoad("bass_aac.dll")
  def Button1Click(self, sender, e):
ofd = OpenFileDialog()
if(ofd.ShowDialog()==DialogResult.OK):
   if(strm != 0): Bass.BASS_StreamFree(strm)
   global strm
   strm = 0
   sfile = ofd.FileName
   strm = Bass.BASS_StreamCreateFile(sfile, 0, 0, 0)
   if(strm != 0):
     self.Text = Path.GetFileName(sfile)
     self._label2.Text = System.TimeSpan.FromSeconds(self.Duration).ToString()[0:8]
     self._trackBar1.Maximum = int(self.MaxPosition)
     self.Button2Click(sender, e)
     if(not self._timer1.Enabled):
        self._timer1.Interval = 50
        self._timer1.Start()
   else:
      MessageBox.Show("Error! file not support.")
         
  def Button2Click(self, sender, e):
  Bass.BASS_ChannelPlay(strm, False)

  def Button3Click(self, sender, e):
  Bass.BASS_ChannelPause(strm)

  def Button4Click(self, sender, e):
  SetPosition(0)
  Bass.BASS_ChannelStop(strm)
 
  def Timer1Tick(self, sender, e):
  if(self.CurrentPosition<self.Duration):
             self._trackBar1.Value = self.CurrentPosition
           self._label4.Text = self.CPU
           self._label3.Text = self.Status
           self._label1.Text = System.TimeSpan.FromSeconds(self.CurrentPosition).ToString()[0:8]
                   self._progressBar1.Value = self.VuLeft
                   self._progressBar2.Value = self.VuRight
          else:
               SetPosition(0)
               Bass.BASS_ChannelStop(strm)
 
  def TrackBar1Scroll(self, sender, e):
  SetPosition(self._trackBar1.Value)
 
  def MainFormFormClosing(self, sender, e):
  Bass.BASS_PluginFree(fplug)
  Bass.BASS_Free()
 
  #region Bass properties Functions
  def get_IsPlaying(self):
    state = Bass.BASS_ChannelIsActive(strm)
    play = BASSActive.BASS_ACTIVE_PLAYING
    if(state==play):
    return True
    else:
    return False
  IsPlaying = property(get_IsPlaying)  
 
  def get_CPU(self):
    return Bass.BASS_GetCPU().ToString("#0.00")
  CPU = property(get_CPU)  
 
  def get_Status(self):
      state = Bass.BASS_ChannelIsActive(strm)
      play = BASSActive.BASS_ACTIVE_PLAYING
      stall = BASSActive.BASS_ACTIVE_STALLED
      pause = BASSActive.BASS_ACTIVE_PAUSED
      restr = ""
      if(state==play):
         restr = "Playing"
      elif(state==stall):
         restr = "Stalled"
      elif(state==pause):
         restr = "Paused"     
      else:
         restr = "Stopped"
      return restr             
  Status = property(get_Status)  
 
  def get_VuLeft(self):
    if(self.IsPlaying):
    return Bass.BASS_ChannelGetLevel(strm)& 65535
    else:
    return 0
  VuLeft = property(get_VuLeft)  
   
  def get_VuRight(self):
    if(self.IsPlaying):
    return (Bass.BASS_ChannelGetLevel(strm)>> 16)& 65535
    else:
    return 0
  VuRight = property(get_VuRight)  
   
  def get_Duration(self):
  return Bass.BASS_ChannelBytes2Seconds(strm, Bass.BASS_ChannelGetLength(strm, 0))
  Duration = property(get_Duration)
 
  def get_MaxPosition(self):
  return self.Duration
  MaxPosition = property(get_MaxPosition)

  def get_CurrentPosition(self):
  return Bass.BASS_ChannelBytes2Seconds(strm, Bass.BASS_ChannelGetPosition(strm, 0))
  CurrentPosition = property(get_CurrentPosition)
 
  def SetPosition(pos):
      return Bass.BASS_ChannelSetPosition(strm, Bass.BASS_ChannelSeconds2Bytes(strm, pos), 0)
  #endregion
« Last Edit: 11 Nov '17 - 19:11 by sak2005 »

sak2005

  • Posts: 1007
Tip: How to DllImport in the Python? ::)

Example: Bass Shared Class Lib
Code: [Select]
from System import *
from System.Runtime.InteropServices import *

class Bass(Object):
def BASS_Init(device, freq, flags, win, clsid):
pass
        BASS_Init = staticmethod(BASS_Init)

def BASS_StreamCreateFile(mem, file, offset, length, flags):
pass
        BASS_StreamCreateFile = staticmethod(BASS_StreamCreateFile)

def BASS_ChannelPlay(handle, restart):
pass
        BASS_ChannelPlay = staticmethod(BASS_ChannelPlay)
« Last Edit: 11 Nov '17 - 13:12 by sak2005 »