Exemplo n.º 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();
}
Exemplo n.º 2
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;
}
Exemplo n.º 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();
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
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();
}
Exemplo n.º 6
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;
}
Exemplo n.º 7
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 );
}