예제 #1
0
//-----------------------------------------------------------------------------
// doTheBeat?
//-----------------------------------------------------------------------------
void doBeat(){
     g_mutex.acquire();
     vector<JGHNoteEvent *> notes; 
    for(int i = 0; i < g_tracks.size(); i++)
    {
        JGHNoteEvent *note = g_tracks[i] -> getNextNote();
        if(note)notes.push_back(note);
    }
    if(Globals::isMetronomeOn && Globals::currentBeatDivisorIndex == 0)
    {
        if(Globals::currentBeatIndex == 0)
        {
            g_metronomeNote -> velocity = 1;
        }else
        {
            g_metronomeNote -> velocity = .4;
        }
        notes.push_back(g_metronomeNote);
    }
    JGHNoteEvent *combinedNotes = connectNotes(notes);
    if (combinedNotes != NULL)
    { 
    
        g_synth-> playNotes(combinedNotes);
        SAFE_DELETE(combinedNotes);
    }

    g_mutex.release();
    calculateBeat();
}
예제 #2
0
BOOL XFilePackage::Save()
{
    m_Mutex.Lock();
    for (size_t i = 0; i < m_PakFileTable.size(); ++i)
    {
        FILE* pFile = m_PakFileTable[i];

        if (pFile)
        {
            fflush(pFile);
        }
    }
    m_Mutex.Unlock();

    return m_FileIndex.Save();
}
예제 #3
0
void addNote()
{
    g_mutex.acquire();
    JGHNoteEvent * h = new JGHNoteEvent();
    h -> pitch = getCurrentDrum();
    h -> velocity = 1;
    
    if(Globals::isRecording)
    {
        Track *currTrack = getCurrentTrack();
        currTrack->addNote(h,currTrack ->nearestBeatDivision());
    }else
    {
        g_synth->playNotes(h);
    }
    g_mutex.release();
}
예제 #4
0
BOOL XFilePackage::ReadFileData(BYTE* pbyBuffer, size_t uBufferSize, uint64_t uOffset, size_t uRequestSize)
{
    BOOL        bResult         = false;
    int         nRetCode        = 0;
    size_t      uBufferPos      = 0;

    m_Mutex.Lock();

    XYLOG_FAILED_JUMP(uRequestSize <= uBufferSize);

    while (uRequestSize > 0)
    {
        int         nPakFileIndex   = (int)(uOffset / MAX_PACK_FILE_SIZE);
        int32_t     nPakFileOffset  = (int32_t)(uOffset % MAX_PACK_FILE_SIZE);
        size_t      uRead           = Min((size_t)(MAX_PACK_FILE_SIZE - nPakFileOffset), uRequestSize);
        FILE*       pFile           = OpenPakFile(nPakFileIndex);

        assert(nPakFileOffset >= 0);
        assert(nPakFileOffset <= MAX_PACK_FILE_SIZE);

        XYLOG_FAILED_JUMP(pFile);

        nRetCode = fseek(pFile, nPakFileOffset, SEEK_SET);
        XYLOG_FAILED_JUMP(nRetCode == 0);

        nRetCode = (int)fread(pbyBuffer + uBufferPos, uRead, 1, pFile);
        // XYLOG_FAILED_JUMP(nRetCode == 1);
        if (nRetCode != 1)
        {
            Log(eLogDebug, "errno:%d \t uRead:%d \t uBufferPos:%d \t nPakFileOffset:%lld", errno, uRead, uBufferPos, nPakFileOffset);
            
            goto Exit0;
        }

        EncryptData(pbyBuffer + uBufferPos, uRead, uOffset);

        uBufferPos      += uRead;
        uOffset         += uRead;
        uRequestSize    -= uRead;
    }

    bResult = true;
Exit0:
    m_Mutex.Unlock();
    return bResult;
}
예제 #5
0
void * le_cb( void * p )
{
    char line[2048];
    map<LineEvent *, LineEvent *>::iterator iter;
    LineEvent * le = NULL;

    // loop
    while( true )
    {
        // wait
        while( g_le_wait )
            usleep( 10000 );

        // check
        if( !g_vm ) break;

        // do the prompt
        cout << g_le_what;
        cout.flush();
        if( !cin.getline( line, 2048 ) ) break;

        // lock
        g_le_mutex.acquire();
        // go through
        for( iter = g_le_map.begin(); iter != g_le_map.end(); iter++ )
        {
            // get the line event
            le = (*iter).first;
            // add to its queue
            le->enqueue( line );
            // broadcast it
            le->SELF->queue_broadcast();
        }
        // unlock
        g_le_mutex.release();

        // reset wait
        g_le_wait = TRUE;
    }
    
    return NULL;
}
예제 #6
0
LineEvent::LineEvent( Chuck_Event * SELF )
{
    // launch the cb
    if( !g_le_launched )
    {
#if !defined(__PLATFORM_WIN32__) || defined(__WINDOWS_PTHREAD__)
        pthread_create( &g_tid_whatever, NULL, le_cb, NULL );
#else
        g_tid_whatever = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)le_cb, NULL, 0, 0 );
#endif
        g_le_launched = TRUE;
    }

    // lock
    g_le_mutex.acquire();
    // add
    g_le_map[this] = this;
    this->SELF = SELF;
    // unlock
    g_le_mutex.release();
}
예제 #7
0
BOOL XFilePackage::WriteFileData(uint64_t uOffset, const BYTE* pbyData, size_t uDataLen)
{
    BOOL        bResult         = false;
    int         nRetCode        = 0;
    size_t      uBufferPos      = 0;
    BYTE*       pbyBuffer       = (BYTE*)MemDup(pbyData, uDataLen);

    EncryptData(pbyBuffer, uDataLen, uOffset);

    m_Mutex.Lock();

    while (uDataLen > 0)
    {
        int         nPakFileIndex   = (int)(uOffset / MAX_PACK_FILE_SIZE);
        int32_t     nPakFileOffset  = (int32_t)(uOffset % MAX_PACK_FILE_SIZE);
        size_t      uWrite          = Min((size_t)(MAX_PACK_FILE_SIZE - nPakFileOffset), uDataLen);
        FILE*       pFile           = OpenPakFile(nPakFileIndex, true);

        assert(nPakFileOffset >= 0);
        assert(nPakFileOffset <= MAX_PACK_FILE_SIZE);

        XYLOG_FAILED_JUMP(pFile);

        nRetCode = fseek(pFile, nPakFileOffset, SEEK_SET);
        XYLOG_FAILED_JUMP(nRetCode == 0);

        nRetCode = (int)fwrite(pbyBuffer + uBufferPos, uWrite, 1, pFile);
        XY_FAILED_JUMP(nRetCode == 1);

        uBufferPos      += uWrite;
        uOffset         += uWrite;
        uDataLen        -= uWrite;
    }

    bResult = true;
Exit0:
    m_Mutex.Unlock();
    XY_FREE(pbyBuffer);
    return bResult;
}
예제 #8
0
string LineEvent::getLine()
{
    string ret;

    // lock
    g_le_mutex.acquire();
    // get next line
    if( m_q.size() )
    {
        // get it
        ret = m_q.front();
        // dequeue it
        m_q.pop();
    }
    else
    {
        ret = "[ERROR -> getLine() called on empty Skot]";
    }
    // unlock
    g_le_mutex.release();

    return ret;
}
예제 #9
0
void * ts_start( void * data )
#endif
{
    int samples, write = 1;
    fprintf( stderr, "you are now entering the ts_start() function...\n" );
    while( !g_shutup ) {
        g_mutex.acquire();
        if( g_ts->setup() ) {
            g_ts->synth();
            // keep trying to write to file/buffer, until written or told to shut up
            while( !g_shutup && 
                   !(write = g_tsio->WriteSoundFile( g_tsio->ofilename, g_ts->outputSignal(), g_ts->tree->getSize() ) ) )
            {
                g_mutex.release();
                usleep( 10000 );
                g_mutex.acquire();
            }
        }
        g_mutex.release();
        
        // may work 
        if( g_lefttree ) {
            if( g_ts->lefttree == NULL ) {
                g_ts->lefttree = new Tree();
                g_ts->lefttree->initialize( g_ts->tree->getLevels() );
            }
            g_ts->lefttree->setValues( g_ts->tree->values(), g_ts->tree->getSize() );
        }

        // read input for next iteration
        samples = g_tsio->ReadSoundFile( g_tsio->ifilename, g_ts->tree->values(), g_ts->tree->getSize() );
    }

    g_mutex.acquire();
    ts_end();
    g_mutex.release();

    fprintf( stderr, "you are now leaving the ts_start() function..., good luck.\n" );
    return 0;
}
예제 #10
0
//-----------------------------------------------------------------------------
// name: on_event()
// desc: ...
//-----------------------------------------------------------------------------
t_TAPUINT UITreesynth::on_event( const AudicleEvent & event )
{
    static t_TAPUINT m_mouse_down = FALSE;
    static t_TAPUINT which = 0;
    static Point2D last;
    t_TAPBOOL hit = FALSE;
    Point2D diff;
    t_TAPUINT i;

    if( event.type == ae_event_INPUT )
    {
        InputEvent * ie = (InputEvent *)event.data;
        if( ie->type == ae_input_MOUSE )
        {
            ie->popStack();

            for( i = 0; i < NUM_UI_ELEMENTS; i++ )
            {
                if( ie->checkID( ui_elements[i]->id ) )
                {
                    if( ie->state == ae_input_DOWN )
                    {
                        hit = TRUE;
                        ui_elements[i]->down = TRUE;
                        
                        if( i >= SL_PERCENTAGE && i <= SL_STOPLEVEL )
                            ui_elements[i]->slide_last = (ie->pos[1]/AudicleWindow::main()->m_vsize ) / g_slider_height;
                    
                        
                        if( i == FL_ANCFIRST )
                        {
                            ui_elements[i]->slide = 1.0f - ui_elements[i]->slide;
                            if( g_ts )
                            {
                                g_mutex.acquire();
                                g_ts->ancfirst = ui_elements[FL_ANCFIRST]->fvalue() > 0.5;
                                g_mutex.release();
                            }
                        }

                        if( i == FL_RANDFLIP )
                        {
                            ui_elements[i]->slide = 1.0f - ui_elements[i]->slide;
                            if( g_ts )
                            {
                                g_mutex.acquire();
                                g_ts->randflip = ui_elements[FL_RANDFLIP]->fvalue() > 0.5;
                                g_mutex.release();
                            }
                        }

                        if( i == FL_WRITE_FILE )
                        {
                            if( g_shutup )
                            {
                                ui_elements[i]->slide = 1.0f - ui_elements[i]->slide;
                            }
                            else
                            {
                                msg_box( "bad!", "wavelet-tree already synthesizing!" );
                            } 
                        }
                    }

                    if( ie->state == ae_input_UP && ui_elements[i]->down == TRUE )
                    {

                        // ~~~~~~~~~~~~~~~~~~~~~~~~ LOAD FROM FILE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                        if( i == BT_LOAD_FILE )
                        {
                            m_audio->bus(1)->stop();
                            usleep( 100000 );
                            g_shutup = TRUE;
                            g_lib = FALSE;
                            DirScanner dScan;
                            fileData * fD = dScan.openFileDialog();
                            if ( fD )
                            {
                                fprintf(stderr, "residue file %s\n", fD->fileName.c_str() );
                                if ( fD->next ) 
                                    fprintf( stderr, "may not be opening first of multiple files...\n");
                                
                                strcpy( g_ifile, fD->fileName.c_str() );
                            }
                        }

                        
                        // ~~~~~~~~~~~~~~~~~~~~~~~~ LOAD FROM ANALYSIS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                        if( i == BT_LOAD_ANALYSIS )
                        {
                            m_audio->bus(1)->stop();
                            usleep( 100000 );
                            g_shutup = TRUE;
                            g_lib = TRUE;
                        }


                        // ~~~~~~~~~~~~~~~~~~~~~~~~ SYNTHESIZE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                        if( i == BT_SYNTHESIZE )
                        {
                            if( g_shutup )
                            {
                                ts_init( ui_elements );
                                ts_run();
                                AudioSrcEliot * ts = new AudioSrcEliot( g_tsio );
                                ts->on = &ui_elements[BT_SYNTHESIZE]->on;
                                m_audio->bus(1)->play( ts, FALSE );
                                ui_elements[BT_SYNTHESIZE]->on = TRUE;
                                ui_elements[BT_SYNTHESIZE]->on_where = 0.0;
                            }
                            else
                            {
                                msg_box( "bad!", "wavelet-tree already synthesizing!" );
                            }
                        }


                        // ~~~~~~~~~~~~~~~~~~~~~~~~ STOP ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                        if( i == BT_STOP )
                        {
                            m_audio->bus(1)->stop();
                            usleep( 100000 );
                            g_shutup = TRUE;
                        }

                    }
                }

                // button up
                if( ie->state == ae_input_UP && ui_elements[i]->down )
                    ui_elements[i]->down = FALSE;
            }   

            // background
            if( hit == FALSE )
            {
                if( ie->state == ae_input_DOWN )
                {
                    which = !!(ie->mods & ae_input_CTRL);
                    m_mouse_down = TRUE;
                    last = ie->pos;
                }
                else 
                {
                    m_mouse_down = FALSE;
                }
            }
        }
        else if( ie->type == ae_input_MOTION )
        {
            for( i = SL_PERCENTAGE; i <= SL_STOPLEVEL; i++ )
            {
                if( ui_elements[i]->down )
                {
                    ui_elements[i]->slide += (ie->pos[1]/AudicleWindow::main()->m_vsize ) 
                                            / g_slider_height - ui_elements[i]->slide_last;
                    ui_elements[i]->slide_last = (ie->pos[1]/AudicleWindow::main()->m_vsize ) / g_slider_height;
                    if( ui_elements[i]->slide > 1.0 ) ui_elements[i]->slide = ui_elements[i]->slide_last = 1.0;
                    if( ui_elements[i]->slide < 0.0 ) ui_elements[i]->slide = ui_elements[i]->slide_last = 0;
                }
            }

            if( ui_elements[SL_STARTLEVEL]->down )
            {
                if( g_ts )
                {
                    g_mutex.acquire();
                    g_ts->startlevel = ui_elements[SL_STARTLEVEL]->ivalue();
                    g_mutex.release();
                }
            }

            if( ui_elements[SL_STOPLEVEL]->down )
            {
                if( g_ts )
                {
                    g_mutex.acquire();
                    g_ts->stoplevel = ui_elements[SL_STOPLEVEL]->ivalue();
                    g_mutex.release();
                }
            }

            if( ui_elements[SL_PERCENTAGE]->down )
            {
                if( g_ts )
                {
                    g_mutex.acquire();
                    g_ts->percentage = ui_elements[SL_PERCENTAGE]->fvalue();
                    g_mutex.release();
                }
            }

            if( ui_elements[SL_K]->down )
            {
                if( g_ts )
                {
                    g_mutex.acquire();
                    g_ts->kfactor = ui_elements[SL_K]->fvalue();
                    g_mutex.release();
                }
            }

            if( ui_elements[FL_ANCFIRST]->down )
            {
                if( g_ts )
                {
                    g_mutex.acquire();
                    g_ts->ancfirst = ui_elements[FL_ANCFIRST]->fvalue() > 0.5;
                    g_mutex.release();
                }
            }

            if( ui_elements[FL_RANDFLIP]->down )
            {
                if( g_ts )
                {
                    g_mutex.acquire();
                    g_ts->randflip = ui_elements[FL_RANDFLIP]->fvalue() > 0.5;
                    g_mutex.release();
                }
            }
        }
    }

    return AudicleFace::on_event( event );
}