Changeset 54 for psi

Show
Ignore:
Timestamp:
09/20/06 00:29:16 (2 years ago)
Author:
dmik
Message:

Psi: General: Changed the !beep sound functionality (recognized when assigning sound files to events): the new format is !beep[:freq:duration] that allows to assign different beep sounds to different events [OS2/Win32 only].

Location:
psi/trunk/src
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • psi/trunk/src/common.cpp

    r50 r54  
    4545#include<qlibrary.h> 
    4646#include<qstylesheet.h> 
     47 
     48#include<qthread.h> 
     49#include<qmutex.h> 
     50#include<qsemaphore.h> 
     51#include<qvaluelist.h> 
    4752 
    4853 
     
    15641569} 
    15651570 
     1571class BeepThread : public QThread 
     1572{ 
     1573public: 
     1574        BeepThread() : sem(1), terminate(false) {} 
     1575        ~BeepThread() { while (sem.available() != sem.total()) sem--; } 
     1576        void run() { 
     1577                lock.lock(); 
     1578                while (!terminate) { 
     1579                        while (!terminate && queue.count()) { 
     1580                                Beep beep = queue.front(); 
     1581                                queue.pop_front(); 
     1582                                lock.unlock(); 
     1583#if defined(Q_WS_WIN) 
     1584                                if (beep.freq && beep.dur) 
     1585                                        Beep(beep.freq, beep.dur); 
     1586                                else 
     1587#elif defined(Q_WS_PM) 
     1588                                if (beep.freq && beep.dur) 
     1589                                        DosBeep(beep.freq, beep.dur); 
     1590                                else 
     1591#endif                           
     1592                                        QApplication::beep(); 
     1593                                lock.lock(); 
     1594                        } 
     1595                        lock.unlock(); 
     1596                        sem++; 
     1597                        lock.lock(); 
     1598                } 
     1599                lock.unlock(); 
     1600        } 
     1601        void add(ulong freq, ulong dur) { 
     1602                lock.lock(); 
     1603                queue.push_back(Beep(freq, dur)); 
     1604                lock.unlock(); 
     1605                if (!sem.available()) 
     1606                        sem--; 
     1607        } 
     1608        void stop() { 
     1609                lock.lock(); 
     1610                terminate = true; 
     1611                lock.unlock(); 
     1612                if (!sem.available()) 
     1613                        sem--; 
     1614                wait(); 
     1615        } 
     1616private: 
     1617        struct Beep { 
     1618                Beep() : freq(0), dur(0) {} 
     1619                Beep(ulong f, ulong d) : freq(f), dur(d) {} 
     1620                const ulong freq; 
     1621                const ulong dur; 
     1622        }; 
     1623        QMutex lock; 
     1624        QSemaphore sem; 
     1625        QValueList<Beep> queue; 
     1626        bool terminate; 
     1627}; 
     1628 
     1629static BeepThread *beepThread = 0; 
     1630 
     1631static void cleanupBeepThread() 
     1632{ 
     1633        if (beepThread) { 
     1634                beepThread->stop(); 
     1635                delete beepThread; 
     1636                beepThread = 0; 
     1637        } 
     1638} 
    15661639 
    15671640void soundPlay(const QString &str) 
    15681641{ 
    1569         if(str == "!beep") { 
    1570                 QApplication::beep(); 
    1571                 return; 
     1642        if(str.startsWith("!beep")) { 
     1643                QStringList list = QStringList::split(':',str); 
     1644                if (list[0].length() == 5 /* strlen("!beep") */) { 
     1645                        ulong freq = 0, dur = 0; 
     1646                        if (list.count() == 3) { 
     1647                                freq = list[1].toULong(); 
     1648                                dur = list[2].toULong(); 
     1649                                if (freq < 0x25 || freq > 0x7FFF || 
     1650                                        dur == 0 || dur > 3000 /* 3s is the reasonable maximum */) 
     1651                                        freq = dur = 0; 
     1652                        } 
     1653                        if (beepThread == 0) { 
     1654                                beepThread = new BeepThread(); 
     1655                                if (beepThread) { 
     1656                                        qAddPostRoutine(cleanupBeepThread); 
     1657                                        beepThread->start(); 
     1658                                } 
     1659                        } 
     1660                        if (beepThread) 
     1661                                beepThread->add(freq, dur); 
     1662                        return; 
     1663                } 
    15721664        } 
    15731665 
  • psi/trunk/src/options/opt_sound-ui.ui

    r2 r54  
    103103                    </property> 
    104104                    <property name="toolTip" stdset="0"> 
    105                         <string>Enter a filename or !beep for a system beep</string> 
     105                        <string>Enter a filename or &lt;tt&gt;!beep[:freq:duration]&lt;/tt&gt; for a system beep</string> 
    106106                    </property> 
    107107                </widget> 
     
    119119                    </property> 
    120120                    <property name="toolTip" stdset="0"> 
    121                         <string>Enter a filename or !beep for a system beep</string> 
     121                        <string>Enter a filename or &lt;tt&gt;!beep[:freq:duration]&lt;/tt&gt; for a system beep</string> 
    122122                    </property> 
    123123                </widget> 
     
    135135                    </property> 
    136136                    <property name="toolTip" stdset="0"> 
    137                         <string>Enter a filename or !beep for a system beep</string> 
     137                        <string>Enter a filename or &lt;tt&gt;!beep[:freq:duration]&lt;/tt&gt; for a system beep</string> 
    138138                    </property> 
    139139                </widget> 
     
    159159                    </property> 
    160160                    <property name="toolTip" stdset="0"> 
    161                         <string>Enter a filename or !beep for a system beep</string> 
     161                        <string>Enter a filename or &lt;tt&gt;!beep[:freq:duration]&lt;/tt&gt; for a system beep</string> 
    162162                    </property> 
    163163                </widget> 
     
    207207                    </property> 
    208208                    <property name="toolTip" stdset="0"> 
    209                         <string>Enter a filename or !beep for a system beep</string> 
     209                        <string>Enter a filename or &lt;tt&gt;!beep[:freq:duration]&lt;/tt&gt; for a system beep</string> 
    210210                    </property> 
    211211                </widget> 
     
    239239                    </property> 
    240240                    <property name="toolTip" stdset="0"> 
    241                         <string>Enter a filename or !beep for a system beep</string> 
     241                        <string>Enter a filename or &lt;tt&gt;!beep[:freq:duration]&lt;/tt&gt; for a system beep</string> 
    242242                    </property> 
    243243                </widget> 
     
    319319                    </property> 
    320320                    <property name="toolTip" stdset="0"> 
    321                         <string>Enter a filename or !beep for a system beep</string> 
     321                        <string>Enter a filename or &lt;tt&gt;!beep[:freq:duration]&lt;/tt&gt; for a system beep</string> 
    322322                    </property> 
    323323                </widget> 
     
    343343                    </property> 
    344344                    <property name="toolTip" stdset="0"> 
    345                         <string>Enter a filename or !beep for a system beep</string> 
     345                        <string>Enter a filename or &lt;tt&gt;!beep[:freq:duration]&lt;/tt&gt; for a system beep</string> 
    346346                    </property> 
    347347                </widget> 
     
    351351                    </property> 
    352352                    <property name="toolTip" stdset="0"> 
    353                         <string>Enter a filename or !beep for a system beep</string> 
     353                        <string>Enter a filename or &lt;tt&gt;!beep[:freq:duration]&lt;/tt&gt; for a system beep</string> 
    354354                    </property> 
    355355                </widget> 
     
    367367                    </property> 
    368368                    <property name="toolTip" stdset="0"> 
    369                         <string>Enter a filename or !beep for a system beep</string> 
     369                        <string>Enter a filename or &lt;tt&gt;!beep[:freq:duration]&lt;/tt&gt; for a system beep</string> 
    370370                    </property> 
    371371                </widget> 
  • psi/trunk/src/options/opt_sound_events.ui

    r2 r54  
    6868                    </property> 
    6969                    <property name="toolTip" stdset="0"> 
    70                         <string>Enter a filename or !beep for a system beep</string> 
     70                        <string>Enter a filename or &lt;tt&gt;!beep[:freq:duration]&lt;/tt&gt; for a system beep</string> 
    7171                    </property> 
    7272                </widget> 
     
    8484                    </property> 
    8585                    <property name="toolTip" stdset="0"> 
    86                         <string>Enter a filename or !beep for a system beep</string> 
     86                        <string>Enter a filename or &lt;tt&gt;!beep[:freq:duration]&lt;/tt&gt; for a system beep</string> 
    8787                    </property> 
    8888                </widget> 
     
    140140                    </property> 
    141141                    <property name="toolTip" stdset="0"> 
    142                         <string>Enter a filename or !beep for a system beep</string> 
     142                        <string>Enter a filename or &lt;tt&gt;!beep[:freq:duration]&lt;/tt&gt; for a system beep</string> 
    143143                    </property> 
    144144                </widget> 
     
    164164                    </property> 
    165165                    <property name="toolTip" stdset="0"> 
    166                         <string>Enter a filename or !beep for a system beep</string> 
     166                        <string>Enter a filename or &lt;tt&gt;!beep[:freq:duration]&lt;/tt&gt; for a system beep</string> 
    167167                    </property> 
    168168                </widget> 
     
    212212                    </property> 
    213213                    <property name="toolTip" stdset="0"> 
    214                         <string>Enter a filename or !beep for a system beep</string> 
     214                        <string>Enter a filename or &lt;tt&gt;!beep[:freq:duration]&lt;/tt&gt; for a system beep</string> 
    215215                    </property> 
    216216                </widget> 
     
    244244                    </property> 
    245245                    <property name="toolTip" stdset="0"> 
    246                         <string>Enter a filename or !beep for a system beep</string> 
     246                        <string>Enter a filename or &lt;tt&gt;!beep[:freq:duration]&lt;/tt&gt; for a system beep</string> 
    247247                    </property> 
    248248                </widget> 
     
    252252                    </property> 
    253253                    <property name="toolTip" stdset="0"> 
    254                         <string>Enter a filename or !beep for a system beep</string> 
     254                        <string>Enter a filename or &lt;tt&gt;!beep[:freq:duration]&lt;/tt&gt; for a system beep</string> 
    255255                    </property> 
    256256                </widget> 
     
    268268                    </property> 
    269269                    <property name="toolTip" stdset="0"> 
    270                         <string>Enter a filename or !beep for a system beep</string> 
     270                        <string>Enter a filename or &lt;tt&gt;!beep[:freq:duration]&lt;/tt&gt; for a system beep</string> 
    271271                    </property> 
    272272                </widget>